-
Notifications
You must be signed in to change notification settings - Fork 316
feat: integrate Conflux eSpace #5750
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
d32b385
feat: integrate Conflux eSpace
Pana 5bdd564
feat: update token logo
Pana 6cd8ba6
feat: fix lint
Pana 447dde5
feat: fix lint
Pana 0870548
feat(wip): add smart contract
hanszhoou e434014
Merge branch 'develop' into develop
Pana 6083ded
Merge branch 'develop' into feat/add-smart-contract-address
hanszhoou 62640cb
feat: integrate smart contract
hanszhoou b1602f1
chore: remove debug code
hanszhoou 892e8e5
Merge pull request #1 from conflux-fans/feat/add-smart-contract-address
Pana 890f25a
chore: add contract address
hanszhoou ad9d446
chore: rpc address
hanszhoou b809500
chore: send conflux popup dashboard
hanszhoou 126d880
chore: add token list
hanszhoou 23c0489
chore: remove debug code
hanszhoou 02dea06
chore: modify comment
hanszhoou bfdb17f
fix: asset list
hanszhoou f3578ec
chore: add empty config
hanszhoou e3fde8a
Merge pull request #3 from conflux-fans/add-config
hanszhoou 4208831
Merge remote-tracking branch 'upstream/develop' into develop
hanszhoou 1934c73
chore: solve conflict
hanszhoou 5ec9514
chore: hiden gas option
hanszhoou 943f891
fix: explorer url
hanszhoou 6c84752
chore: conflux usd price
hanszhoou 510e8d8
chore: conflux price
hanszhoou 92185d5
chore: miss config
hanszhoou a062732
fix: conflux default gas price
hanszhoou 598b9ab
chore: conflux disable swap
hanszhoou 143e9ec
chore: remove debug code
hanszhoou 69d8b0e
chore: get balance
hanszhoou eae37b5
chore: reply code review
hanszhoou 1f7a7df
chore: simple syntax
hanszhoou 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
10 changes: 10 additions & 0 deletions
10
packages/mask/src/plugins/EVM/UI/Web3State/createGetLatestBalance.ts
This file contains hidden or 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,10 @@ | ||
| import { ChainId, Web3ProviderType, createWeb3 } from '@masknet/web3-shared-evm' | ||
|
|
||
| export function createGetLatestBalance(context: Web3ProviderType) { | ||
| return (chainId: ChainId, account: string) => { | ||
| const web3 = createWeb3(context.request, () => ({ | ||
| chainId, | ||
| })) | ||
| return web3.eth.getBalance(account) | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -11,15 +11,27 @@ import { | |
| Web3ProviderType, | ||
| FungibleAssetProvider, | ||
| createExternalProvider, | ||
| getCoinGeckoCoinId, | ||
| CurrencyType, | ||
| PriceRecord, | ||
| ChainId, | ||
| } from '@masknet/web3-shared-evm' | ||
| import BigNumber from 'bignumber.js' | ||
| import { Pageable, Pagination, TokenType, Web3Plugin } from '@masknet/plugin-infra' | ||
| import BalanceCheckerABI from '@masknet/web3-contracts/abis/BalanceChecker.json' | ||
| import ERC721ABI from '@masknet/web3-contracts/abis/ERC721.json' | ||
| import type { AbiItem } from 'web3-utils' | ||
| import { uniqBy } from 'lodash-unified' | ||
| import { PLUGIN_NETWORKS } from '../../constants' | ||
| import { makeSortAssertWithoutChainFn } from '../../utils/token' | ||
| import { createGetLatestBalance } from './createGetLatestBalance' | ||
| import type { ERC721 } from '@masknet/web3-contracts/types/ERC721' | ||
| import { pow10 } from '@masknet/web3-shared-base' | ||
| import { TokenPrice } from '@masknet/web3-providers' | ||
|
|
||
| // tokens unavailable neither from api or balance checker. | ||
| // https://forum.conflux.fun/t/how-to-upvote-debank-proposal-for-conflux-espace-integration/13935 | ||
| const TokenUnavailableFromDebankList = [ChainId.Conflux] | ||
|
|
||
| export const getFungibleAssetsFn = | ||
| (context: Web3ProviderType) => | ||
|
|
@@ -28,9 +40,12 @@ export const getFungibleAssetsFn = | |
| const wallet = context.wallets.getCurrentValue().find((x) => isSameAddress(x.address, address)) | ||
| const socket = await context.providerSocket | ||
| const networks = PLUGIN_NETWORKS | ||
| const trustedTokens = context.erc20Tokens | ||
| .getCurrentValue() | ||
| .filter((x) => wallet?.erc20_token_whitelist.has(formatEthereumAddress(x.address))) | ||
| const trustedTokens = uniqBy( | ||
| context.erc20Tokens | ||
| .getCurrentValue() | ||
| .filter((x) => wallet?.erc20_token_whitelist.has(formatEthereumAddress(x.address))), | ||
| (x) => `${x.chainId}_${formatEthereumAddress(x.address)}`, | ||
| ) | ||
|
|
||
| const web3 = new Web3( | ||
| createExternalProvider(context.request, context.getSendOverrides, context.getRequestOptions), | ||
|
|
@@ -66,22 +81,28 @@ export const getFungibleAssetsFn = | |
| }, | ||
| })) | ||
|
|
||
| if (!BALANCE_CHECKER_ADDRESS) return assetsFromProvider | ||
| const balanceCheckerContract = createContract(web3, BALANCE_CHECKER_ADDRESS, BalanceCheckerABI as AbiItem[]) | ||
| if (!balanceCheckerContract) return assetsFromProvider | ||
| let balanceList: string[] | ||
| try { | ||
| balanceList = await balanceCheckerContract?.methods | ||
| .balances( | ||
| [address], | ||
| trustedTokens.map((x) => x.address), | ||
| ) | ||
| .call({ | ||
| from: undefined, | ||
| }) | ||
| if (balanceList.length !== trustedTokens?.length) return assetsFromProvider | ||
| } catch { | ||
| balanceList = [] | ||
| const balanceCheckerContract = createContract( | ||
| web3, | ||
| BALANCE_CHECKER_ADDRESS ?? '', | ||
| BalanceCheckerABI as AbiItem[], | ||
| ) | ||
|
|
||
| let balanceList: string[] = [] | ||
|
|
||
| if (BALANCE_CHECKER_ADDRESS && balanceCheckerContract) { | ||
| try { | ||
| balanceList = await balanceCheckerContract?.methods | ||
| .balances( | ||
| [address], | ||
| trustedTokens.map((x) => x.address), | ||
| ) | ||
| .call({ | ||
| from: address, | ||
| }) | ||
| if (balanceList.length !== trustedTokens?.length) return assetsFromProvider | ||
| } catch { | ||
| balanceList = [] | ||
| } | ||
| } | ||
|
|
||
| const assetFromChain = balanceList.map( | ||
|
|
@@ -101,6 +122,27 @@ export const getFungibleAssetsFn = | |
|
|
||
| const allTokens = [...assetsFromProvider, ...assetFromChain] | ||
|
|
||
| const getBalance = createGetLatestBalance(context) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it impossible to use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cycle import |
||
| const allRequest = TokenUnavailableFromDebankList.map(async (x) => { | ||
| const balance = await getBalance(x, address) | ||
| const coinId = getCoinGeckoCoinId(x) | ||
| const price = (await TokenPrice.getNativeTokenPrice([coinId], CurrencyType.USD))[coinId] | ||
|
|
||
| return { | ||
| chainId: x, | ||
| price: price, | ||
| balance, | ||
| } | ||
| }) | ||
|
|
||
| const tokenUnavailableFromDebankResults = (await Promise.allSettled(allRequest)) | ||
| .map((x) => (x.status === 'fulfilled' ? x.value : null)) | ||
| .filter((x) => Boolean(x)) as { | ||
| chainId: ChainId | ||
| balance: string | ||
| price: PriceRecord | ||
| }[] | ||
|
|
||
| const nativeTokens: Web3Plugin.Asset<Web3Plugin.FungibleToken>[] = networks | ||
| .filter( | ||
| (t) => | ||
|
|
@@ -113,11 +155,19 @@ export const getFungibleAssetsFn = | |
| ) | ||
| .map((x) => { | ||
| const nativeToken = createNativeToken(x.chainId) | ||
| const result = tokenUnavailableFromDebankResults.find((y) => y.chainId === x.chainId) | ||
| return { | ||
| id: nativeToken.address, | ||
| chainId: x.chainId, | ||
| token: { ...nativeToken, id: nativeToken.address!, type: TokenType.Fungible }, | ||
| balance: '0', | ||
| balance: result?.balance ?? '0', | ||
| price: result?.price, | ||
| value: { | ||
| [CurrencyType.USD]: new BigNumber(result?.balance ?? '0') | ||
| .dividedBy(pow10(nativeToken.decimals)) | ||
| .multipliedBy(result ? result.price[CurrencyType.USD] : '0') | ||
| .toFixed(), | ||
| }, | ||
| } | ||
| }) | ||
|
|
||
|
|
||
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.