-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from bobanetwork/wsdt/kyc_and_token_price_example
feat: add kyc and token-price fetching contracts #2
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |