@@ -4,149 +4,22 @@ import {
4
4
assertEnvironmentVariable ,
5
5
chunkArray ,
6
6
} from '@wormhole-foundation/wormhole-monitor-common' ;
7
+ import { ChainId , assertChain , toChainName } from '@certusone/wormhole-sdk' ;
7
8
import {
8
- CHAIN_ID_ALGORAND ,
9
- CHAIN_ID_APTOS ,
10
- CHAIN_ID_INJECTIVE ,
11
- CHAIN_ID_NEAR ,
12
- CHAIN_ID_SOLANA ,
13
- CHAIN_ID_SUI ,
14
- CHAIN_ID_TERRA ,
15
- CHAIN_ID_TERRA2 ,
16
- CHAIN_ID_XPLA ,
17
- CONTRACTS ,
18
- ChainId ,
19
- ChainName ,
20
- assertChain ,
21
- getTypeFromExternalAddress ,
22
- hexToUint8Array ,
23
- isEVMChain ,
24
- queryExternalId ,
25
- queryExternalIdInjective ,
26
- toChainName ,
27
- tryHexToNativeAssetString ,
28
- tryHexToNativeStringNear ,
29
- } from '@certusone/wormhole-sdk' ;
30
- import { CoinGeckoCoin , TokenMetadata , fetchCoins } from '../src' ;
9
+ COINGECKO_PLATFORM_BY_CHAIN ,
10
+ CoinGeckoCoin ,
11
+ TokenMetadata ,
12
+ fetchCoins ,
13
+ getNativeAddress ,
14
+ } from '../src' ;
31
15
import knex from 'knex' ;
32
- import { ChainGrpcWasmApi } from '@injectivelabs/sdk-ts' ;
33
- import { Network , getNetworkInfo } from '@injectivelabs/networks' ;
34
- import { LCDClient } from '@xpla/xpla.js' ;
35
- import { connect } from 'near-api-js' ;
36
- import { AptosClient } from 'aptos' ;
37
- import { Connection , JsonRpcProvider } from '@mysten/sui.js' ;
38
- import { getTokenCoinType } from '@certusone/wormhole-sdk/lib/cjs/sui' ;
39
16
40
17
const PG_USER = assertEnvironmentVariable ( 'PG_USER' ) ;
41
18
const PG_PASSWORD = assertEnvironmentVariable ( 'PG_PASSWORD' ) ;
42
19
const PG_DATABASE = assertEnvironmentVariable ( 'PG_DATABASE' ) ;
43
20
const PG_HOST = assertEnvironmentVariable ( 'PG_HOST' ) ;
44
21
const TOKEN_METADATA_TABLE = assertEnvironmentVariable ( 'PG_TOKEN_METADATA_TABLE' ) ;
45
22
46
- const getNativeAddress = async (
47
- tokenChain : ChainId ,
48
- tokenAddress : string
49
- ) : Promise < string | null > => {
50
- try {
51
- if (
52
- isEVMChain ( tokenChain ) ||
53
- tokenChain === CHAIN_ID_SOLANA ||
54
- tokenChain === CHAIN_ID_ALGORAND ||
55
- tokenChain === CHAIN_ID_TERRA
56
- ) {
57
- return tryHexToNativeAssetString ( tokenAddress , tokenChain ) ;
58
- } else if ( tokenChain === CHAIN_ID_XPLA ) {
59
- const client = new LCDClient ( {
60
- URL : 'https://dimension-lcd.xpla.dev' ,
61
- chainID : 'dimension_37-1' ,
62
- } ) ;
63
- return (
64
- ( await queryExternalId ( client , CONTRACTS . MAINNET . xpla . token_bridge , tokenAddress ) ) || null
65
- ) ;
66
- } else if ( tokenChain === CHAIN_ID_TERRA2 ) {
67
- const client = new LCDClient ( {
68
- URL : 'https://phoenix-lcd.terra.dev' ,
69
- chainID : 'phoenix-1' ,
70
- } ) ;
71
- return (
72
- ( await queryExternalId ( client , CONTRACTS . MAINNET . terra2 . token_bridge , tokenAddress ) ) || null
73
- ) ;
74
- } else if ( tokenChain === CHAIN_ID_INJECTIVE ) {
75
- const client = new ChainGrpcWasmApi ( getNetworkInfo ( Network . MainnetK8s ) . grpc ) ;
76
- return await queryExternalIdInjective (
77
- client ,
78
- CONTRACTS . MAINNET . injective . token_bridge ,
79
- tokenAddress
80
- ) ;
81
- } else if ( tokenChain === CHAIN_ID_APTOS ) {
82
- const client = new AptosClient ( 'https://fullnode.mainnet.aptoslabs.com' ) ;
83
- return await getTypeFromExternalAddress (
84
- client ,
85
- CONTRACTS . MAINNET . aptos . token_bridge ,
86
- tokenAddress
87
- ) ;
88
- } else if ( tokenChain === CHAIN_ID_NEAR ) {
89
- const NATIVE_NEAR_WH_ADDRESS =
90
- '0000000000000000000000000000000000000000000000000000000000000000' ;
91
- const NATIVE_NEAR_PLACEHOLDER = 'near' ;
92
- if ( tokenAddress === NATIVE_NEAR_WH_ADDRESS ) {
93
- return NATIVE_NEAR_PLACEHOLDER ;
94
- } else {
95
- const connection = await connect ( {
96
- nodeUrl : 'https://rpc.mainnet.near.org' ,
97
- networkId : 'mainnet' ,
98
- } ) ;
99
- return await tryHexToNativeStringNear (
100
- connection . connection . provider ,
101
- CONTRACTS . MAINNET . near . token_bridge ,
102
- tokenAddress
103
- ) ;
104
- }
105
- } else if ( tokenChain === CHAIN_ID_SUI ) {
106
- const provider = new JsonRpcProvider (
107
- new Connection ( { fullnode : 'https://fullnode.mainnet.sui.io' } )
108
- ) ;
109
- return await getTokenCoinType (
110
- provider ,
111
- CONTRACTS . MAINNET . sui . token_bridge ,
112
- hexToUint8Array ( tokenAddress ) ,
113
- CHAIN_ID_SUI
114
- ) ;
115
- }
116
- } catch ( e ) {
117
- console . error ( e ) ;
118
- }
119
- return null ;
120
- } ;
121
-
122
- // https://api.coingecko.com/api/v3/asset_platforms
123
- const COINGECKO_PLATFORM_BY_CHAIN : { [ key in ChainName ] ?: string } = {
124
- solana : 'solana' ,
125
- ethereum : 'ethereum' ,
126
- terra : 'terra' ,
127
- terra2 : 'terra-2' ,
128
- bsc : 'binance-smart-chain' ,
129
- polygon : 'polygon-pos' ,
130
- avalanche : 'avalanche' ,
131
- oasis : 'oasis' ,
132
- algorand : 'algorand' ,
133
- aptos : 'aptos' ,
134
- aurora : 'aurora' ,
135
- fantom : 'fantom' ,
136
- karura : 'karura' ,
137
- acala : 'acala' ,
138
- klaytn : 'klay-token' ,
139
- celo : 'celo' ,
140
- near : 'near-protocol' ,
141
- moonbeam : 'moonbeam' ,
142
- arbitrum : 'arbitrum-one' ,
143
- optimism : 'optimistic-ethereum' ,
144
- xpla : undefined ,
145
- injective : undefined ,
146
- sui : 'sui' ,
147
- base : 'base' ,
148
- } ;
149
-
150
23
const coinGeckoCoinIdCache = new Map < string , string > ( ) ;
151
24
152
25
const findCoinGeckoCoinId = (
0 commit comments