Skip to content

Commit

Permalink
Merge pull request #1 from bobanetwork/wsdt/kyc_and_token_price_example
Browse files Browse the repository at this point in the history
feat: add kyc and token-price fetching contracts #2
  • Loading branch information
mmontour1306 authored May 28, 2024
2 parents 043363a + 187dc47 commit 3a8690e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
41 changes: 41 additions & 0 deletions contracts/test/TestKyc.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;

import "../samples/HybridAccount.sol";

contract TestKyc {
address payable immutable helperAddr;

constructor(address payable _helperAddr) {
helperAddr = _helperAddr;
}
event FunctionCall(string name);

function checkKyc(string calldata addressToCheck) internal returns (bool) {
HybridAccount ha = HybridAccount(helperAddr);

bytes memory req = abi.encodeWithSignature(
"checkkyc(string)",
addressToCheck
);
bytes32 userKey = bytes32(abi.encode(msg.sender));
(uint32 error, bytes memory ret) = ha.CallOffchain(userKey, req);

if (error != 0) {
revert(string(ret));
}

bool isKyced;
(isKyced) = abi.decode(ret, (bool));
return isKyced;
}

function openForEverybody(string calldata addressToCheck) public {
emit FunctionCall("openForEverybody");
}

function openForKyced(string calldata addressToCheck) public {
require (checkKyc(addressToCheck), "KYC check failed");
emit FunctionCall("openForKyced");
}
}
32 changes: 32 additions & 0 deletions contracts/test/TestTokenPrice.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;

import "../samples/HybridAccount.sol";

contract TestTokenPrice {
mapping(uint256 => uint256) public counters;
address payable immutable helperAddr;

constructor(address payable _helperAddr) {
helperAddr = _helperAddr;
counters[0] = 100;
}

function fetchPrice(
string calldata token
) public returns (string memory) {
HybridAccount ha = HybridAccount(payable(helperAddr));
string memory price;

bytes memory req = abi.encodeWithSignature("getprice(string)", token);
bytes32 userKey = bytes32(abi.encode(msg.sender));
(uint32 error, bytes memory ret) = ha.CallOffchain(userKey, req);

if (error != 0) {
revert(string(ret));
}

(price) = abi.decode(ret, (string));
return price;
}
}

0 comments on commit 3a8690e

Please sign in to comment.