-
Notifications
You must be signed in to change notification settings - Fork 5
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
CP-8996 Implement support for DeBank tokens #1505
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cc9203c
Support for DeBank chains
neven-s 4899520
Bump vm-module versions
neven-s d95ea6d
Remove unused Sentry OP name
neven-s 6f025ff
Merge branch 'main' into CP-8996
neven-s 1c78e42
Fix merge conflicts
neven-s 331cf3a
Fix merge conflicts
neven-s 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -8,15 +8,18 @@ import { | |
BITCOIN_TEST_NETWORK, | ||
ChainId, | ||
Network, | ||
NetworkToken, | ||
NetworkVMType | ||
} from '@avalabs/core-chains-sdk' | ||
import SentryWrapper from 'services/sentry/SentryWrapper' | ||
import { Transaction } from '@sentry/types' | ||
import { avaxSerial } from '@avalabs/avalanchejs' | ||
import { TransactionResponse } from 'ethers' | ||
import { Networks } from 'store/network/types' | ||
import { ChainID, Networks } from 'store/network/types' | ||
import Config from 'react-native-config' | ||
import Logger from 'utils/Logger' | ||
import { DebankNetwork } from 'services/network/types' | ||
import { addIdToPromise, settleAllIdPromises } from '@avalabs/evm-module' | ||
import { getBitcoinProvider, getEvmProvider } from './utils/providerUtils' | ||
import { NETWORK_P, NETWORK_P_TEST, NETWORK_X, NETWORK_X_TEST } from './consts' | ||
|
||
|
@@ -26,11 +29,13 @@ if (!Config.PROXY_URL) | |
class NetworkService { | ||
async getNetworks(): Promise<Networks> { | ||
const erc20Networks = await this.fetchERC20Networks() | ||
const deBankNetworks = await this.fetchDeBankNetworks() | ||
|
||
delete erc20Networks[ChainId.AVALANCHE_LOCAL_ID] | ||
|
||
return { | ||
...erc20Networks, | ||
...deBankNetworks, | ||
[ChainId.BITCOIN]: BITCOIN_NETWORK, | ||
[ChainId.BITCOIN_TESTNET]: BITCOIN_TEST_NETWORK, | ||
[ChainId.AVALANCHE_P]: this.getAvalancheNetworkP(false), | ||
|
@@ -120,6 +125,7 @@ class NetworkService { | |
getAvalancheNetworkX(isDeveloperMode: boolean): Network { | ||
return isDeveloperMode ? NETWORK_X_TEST : NETWORK_X | ||
} | ||
|
||
/** | ||
* Returns the provider used by Avalanche X/P/CoreEth chains. | ||
* Using either X or P Network will result in same provider. | ||
|
@@ -138,6 +144,81 @@ class NetworkService { | |
return acc | ||
}, {} as Networks) | ||
} | ||
|
||
private async fetchDeBankNetworks(): Promise<Networks> { | ||
const response = await fetch( | ||
`${Config.PROXY_URL}/proxy/debank/v1/chain/list` | ||
) | ||
if (!response.ok) { | ||
throw Error('fetchDeBankNetworks failed: ' + response.statusText) | ||
} | ||
const deBankNetworks: DebankNetwork[] = await response.json() | ||
|
||
const networks = deBankNetworks | ||
.filter(network => | ||
['arb', 'bsc', 'op', 'matic', 'base'].includes(network.id) | ||
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. Nothing stops us from including all networks, but ticket requested only these 5 |
||
) | ||
.reduce( | ||
(acc, network) => { | ||
acc[network.community_id] = { | ||
platformChainId: network.id, | ||
chainId: network.community_id, | ||
chainName: network.name, | ||
logoUri: network.logo_url, | ||
vmName: NetworkVMType.EVM, | ||
vmId: network.id, | ||
isTestnet: false, | ||
atn4z7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
networkToken: {} as NetworkToken, | ||
nativeTokenId: network.native_token_id | ||
} as Network & { nativeTokenId: string } | ||
return acc | ||
}, | ||
{} as { | ||
[chainId: ChainID]: Network & { nativeTokenId: string } | ||
} | ||
) | ||
|
||
//fetch info about native tokens | ||
const promises = Object.keys(networks).map(chainId => { | ||
const network = networks[Number(chainId)] | ||
if (!network) { | ||
return Promise.reject('invalid chain id: ' + chainId) | ||
} | ||
return addIdToPromise( | ||
(async () => { | ||
const tokenResponse = await fetch( | ||
`${Config.PROXY_URL}/proxy/debank/v1/token?chain_id=${chainId}&id=${network.nativeTokenId}` | ||
) | ||
if (!tokenResponse.ok) { | ||
throw Error('Failed to fetch debank/v1/token') | ||
} | ||
return await tokenResponse.json() //as DeBankToken | ||
})(), | ||
chainId | ||
) | ||
}) | ||
|
||
const nativeTokenInfos = await settleAllIdPromises(promises) | ||
const networksWithToken: Networks = {} | ||
for (const chainId in nativeTokenInfos) { | ||
const nativeTokenInfo = nativeTokenInfos[chainId] | ||
if (!nativeTokenInfo || 'error' in nativeTokenInfo) { | ||
continue | ||
} | ||
const { nativeTokenId, ...networkWithToken } = { | ||
...networks[Number(chainId)], | ||
networkToken: { | ||
symbol: nativeTokenInfo.symbol, | ||
logoUri: nativeTokenInfo.logo_url, | ||
decimals: nativeTokenInfo.decimals, | ||
name: nativeTokenInfo.name | ||
} as NetworkToken | ||
} | ||
networksWithToken[Number(chainId)] = networkWithToken as Network | ||
} | ||
|
||
return networksWithToken | ||
} | ||
} | ||
|
||
export default new NetworkService() |
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,11 @@ | ||
import { Hex } from '@avalabs/vm-module-types' | ||
|
||
export type DebankNetwork = { | ||
community_id: number | ||
id: string | ||
is_support_pre_exec: boolean | ||
logo_url: string | ||
name: string | ||
native_token_id: string | ||
wrapped_token_id: Hex | ||
} |
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
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.
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.
Most of the logic in this function is because Glacier doesn't provide info about these chains, so here i'm translating deBank's chain info to our Network format.