-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add Erc20 contracts #2811
Merged
Merged
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
0e923ee
ERC20 && NativeToken
0xverin 4a6574a
Token
0xverin 07df037
unit tests
0xverin 28376c4
fmt
0xverin ca7a9be
add erc20(trx) test
0xverin 7349753
update mock server
0xverin ff90125
add decimals_factor constant
0xverin b94a2e8
add decimals_factor
0xverin e6c9a79
native token && erc20 unit tests
0xverin 1ea7f9d
erc20 abstract contract
0xverin e125635
Add nodereal token (missing)
0xverin fab3e6b
fix url
0xverin a4e25f7
add decimals_factor
0xverin fffeade
Merge branch 'dev' into token-holding-amount
0xverin 0f4d676
fmt && remove unuse code
0xverin 2e72a6c
fix url
0xverin 1c59a5b
Merge branch 'dev' into token-holding-amount
0xverin 6f5fd79
refactor erc20
0xverin ca99ccd
Merge branch 'token-holding-amount' of https://github.com/litentry/li…
0xverin 6643efe
Fix duplicate loop
0xverin 5ce760b
fix noderal_json_rpc mock server
0xverin b3111c0
Separate directories
0xverin 05dcb15
fix networkTokenAddresses map
0xverin bfaeabd
add all tokens
0xverin c0bc886
add all tokens
0xverin 4e7201c
remove unused imports
0xverin 30b5431
rename Wbtc contract
0xverin 224926a
Merge branch 'dev' into token-holding-amount
0xverin 40915e9
remove unused tests
0xverin ed158fa
one more
0xverin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
...worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/ERC20.sol
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,99 @@ | ||
// Copyright 2020-2024 Trust Computing GmbH. | ||
// This file is part of Litentry. | ||
// | ||
// Litentry is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Litentry is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Litentry. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.8; | ||
import "../libraries/Identities.sol"; | ||
import "../libraries/Utils.sol"; | ||
import { TokenHoldingAmount } from "./TokenHoldingAmount.sol"; | ||
import { NoderealClient } from "./NoderealClient.sol"; | ||
abstract contract ERC20 is TokenHoldingAmount { | ||
mapping(uint32 => string) internal networkTokenAddresses; | ||
|
||
mapping(uint32 => string) internal networkUrls; | ||
mapping(uint32 => bool) private queriedNetworks; | ||
constructor() { | ||
networkUrls[Web3Networks.Bsc] = "https://bsc-mainnet.nodereal.io/v1/"; | ||
networkUrls[ | ||
Web3Networks.Ethereum | ||
] = "https://eth-mainnet.nodereal.io/v1"; | ||
// Add more networks as needed | ||
|
||
// below url is used for test against mock server | ||
// "http://localhost:19530/nodereal_jsonrpc/v1/", | ||
} | ||
function getTokenDecimals() internal pure override returns (uint8) { | ||
return 18; | ||
} | ||
|
||
function queryBalance( | ||
Identity memory identity, | ||
uint32 network, | ||
string[] memory secrets | ||
) internal virtual override returns (uint256) { | ||
(bool identityToStringSuccess, string memory identityString) = Utils | ||
.identityToString(network, identity.value); | ||
|
||
if (identityToStringSuccess) { | ||
string memory url; | ||
uint32[] memory networks = getTokenNetworks(); | ||
uint256 totalBalance = 0; | ||
|
||
for (uint32 i = 0; i < networks.length; i++) { | ||
// Check if this network has been queried | ||
if (!queriedNetworks[network]) { | ||
string memory _tokenContractAddress = networkTokenAddresses[ | ||
network | ||
]; | ||
|
||
url = string( | ||
abi.encodePacked(networkUrls[networks[i]], secrets[0]) | ||
); | ||
|
||
(bool success, uint256 balance) = NoderealClient | ||
.getTokenBalance( | ||
url, | ||
_tokenContractAddress, | ||
identityString | ||
); | ||
|
||
if (success) { | ||
totalBalance += balance; | ||
} | ||
// Mark this network as queried | ||
queriedNetworks[network] = true; | ||
} | ||
} | ||
return totalBalance; | ||
} | ||
return 0; | ||
} | ||
|
||
function getTokenNetworks() internal pure returns (uint32[] memory) { | ||
uint32[] memory networks = new uint32[](2); | ||
networks[0] = Web3Networks.Ethereum; | ||
networks[1] = Web3Networks.Bsc; | ||
// Add more networks as needed | ||
return networks; | ||
} | ||
|
||
function isSupportedNetwork( | ||
uint32 network | ||
) internal pure override returns (bool) { | ||
return network == Web3Networks.Bsc || network == Web3Networks.Ethereum; | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted it to have 1 function per 1 rpc method but that's fine too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not very convenient to use externally, and requires a lot of if statements, so I merged them here.