@@ -18,8 +18,7 @@ import {
18
18
import { fetchVaa } from 'utils/vaa' ;
19
19
import { hexlify , parseUnits } from 'ethers/lib/utils.js' ;
20
20
import { BaseRoute } from '../bridge' ;
21
- import { isEvmChain , solanaContext , toChainName , wh } from 'utils/sdk' ;
22
- import { CHAINS , TOKENS } from 'config' ;
21
+ import { isEvmChain , solanaContext , toChainId , toChainName } from 'utils/sdk' ;
23
22
import {
24
23
MAX_DECIMALS ,
25
24
calculateUSDPrice ,
@@ -41,6 +40,7 @@ import { NttManagerSolana, getMessageSolana } from './platforms/solana';
41
40
import { formatGasFee } from 'routes/utils' ;
42
41
import { NO_INPUT } from 'utils/style' ;
43
42
import { estimateAverageGasFee } from 'utils/gas' ;
43
+ import config from 'config' ;
44
44
45
45
export abstract class NttBase extends BaseRoute {
46
46
isSupportedChain ( chain : ChainName ) : boolean {
@@ -103,17 +103,17 @@ export abstract class NttBase extends BaseRoute {
103
103
destChain : ChainName | ChainId ,
104
104
) : Promise < boolean > {
105
105
return await Promise . all ( [
106
- this . isSupportedChain ( wh . toChainName ( sourceChain ) ) ,
107
- this . isSupportedChain ( wh . toChainName ( destChain ) ) ,
106
+ this . isSupportedChain ( toChainName ( sourceChain ) ) ,
107
+ this . isSupportedChain ( toChainName ( destChain ) ) ,
108
108
this . isSupportedSourceToken (
109
- TOKENS [ sourceToken ] ,
110
- TOKENS [ destToken ] ,
109
+ config . tokens [ sourceToken ] ,
110
+ config . tokens [ destToken ] ,
111
111
sourceChain ,
112
112
destChain ,
113
113
) ,
114
114
this . isSupportedDestToken (
115
- TOKENS [ destToken ] ,
116
- TOKENS [ sourceToken ] ,
115
+ config . tokens [ destToken ] ,
116
+ config . tokens [ sourceToken ] ,
117
117
sourceChain ,
118
118
destChain ,
119
119
) ,
@@ -164,7 +164,7 @@ export abstract class NttBase extends BaseRoute {
164
164
if ( isEvmChain ( sendingChain ) ) {
165
165
const gasLimit = this . TYPE === Route . NttManual ? 200_000 : 250_000 ;
166
166
return await estimateAverageGasFee ( sendingChain , gasLimit ) ;
167
- } else if ( wh . toChainName ( sendingChain ) === 'solana' ) {
167
+ } else if ( toChainName ( sendingChain ) === 'solana' ) {
168
168
return BigNumber . from ( 10_000 ) ;
169
169
}
170
170
throw new Error ( 'Unsupported chain' ) ;
@@ -181,7 +181,7 @@ export abstract class NttBase extends BaseRoute {
181
181
if ( isEvmChain ( destChain ) ) {
182
182
const gasLimit = 300_000 ;
183
183
return await estimateAverageGasFee ( destChain , gasLimit ) ;
184
- } else if ( wh . toChainName ( destChain ) === 'solana' ) {
184
+ } else if ( toChainName ( destChain ) === 'solana' ) {
185
185
return BigNumber . from ( 65_000 ) ; // TODO: check this
186
186
}
187
187
throw new Error ( 'Unsupported chain' ) ;
@@ -204,7 +204,7 @@ export abstract class NttBase extends BaseRoute {
204
204
if ( ! tokenConfig ?. ntt ) {
205
205
throw new Error ( 'invalid token' ) ;
206
206
}
207
- const destTokenConfig = TOKENS [ destToken ] ;
207
+ const destTokenConfig = config . tokens [ destToken ] ;
208
208
if ( ! destTokenConfig ?. ntt ) {
209
209
throw new Error ( 'invalid dest token' ) ;
210
210
}
@@ -221,7 +221,7 @@ export abstract class NttBase extends BaseRoute {
221
221
throw new ContractIsPausedError ( ) ;
222
222
}
223
223
const decimals = getTokenDecimals (
224
- wh . toChainId ( sendingChain ) ,
224
+ toChainId ( sendingChain ) ,
225
225
tokenConfig . tokenId ,
226
226
) ;
227
227
const sendAmount = removeDust ( parseUnits ( amount , decimals ) , decimals ) ;
@@ -252,7 +252,7 @@ export abstract class NttBase extends BaseRoute {
252
252
if ( await nttManager . isPaused ( ) ) {
253
253
throw new ContractIsPausedError ( ) ;
254
254
}
255
- const nttConfig = TOKENS [ receivedTokenKey ] ?. ntt ;
255
+ const nttConfig = config . tokens [ receivedTokenKey ] ?. ntt ;
256
256
if ( ! nttConfig ) {
257
257
throw new Error ( 'ntt config not found' ) ;
258
258
}
@@ -263,7 +263,7 @@ export abstract class NttBase extends BaseRoute {
263
263
) ;
264
264
return await transceiver . receiveMessage ( vaa , payer ) ;
265
265
}
266
- if ( wh . toChainName ( chain ) === 'solana' ) {
266
+ if ( toChainName ( chain ) === 'solana' ) {
267
267
return await ( nttManager as NttManagerSolana ) . receiveMessage ( vaa , payer ) ;
268
268
}
269
269
throw new Error ( 'Unsupported chain' ) ;
@@ -343,11 +343,8 @@ export abstract class NttBase extends BaseRoute {
343
343
if ( ! tokenConfig ) {
344
344
throw new Error ( 'invalid token' ) ;
345
345
}
346
- const key = getNativeVersionOfToken (
347
- tokenConfig . symbol ,
348
- wh . toChainName ( chain ) ,
349
- ) ;
350
- return TOKENS [ key ] ?. tokenId ?. address || null ;
346
+ const key = getNativeVersionOfToken ( tokenConfig . symbol , toChainName ( chain ) ) ;
347
+ return config . tokens [ key ] ?. tokenId ?. address || null ;
351
348
}
352
349
353
350
async getMessage (
@@ -357,7 +354,7 @@ export abstract class NttBase extends BaseRoute {
357
354
if ( isEvmChain ( chain ) ) {
358
355
return await getMessageEvm ( tx , chain ) ;
359
356
}
360
- if ( wh . toChainName ( chain ) === 'solana' ) {
357
+ if ( toChainName ( chain ) === 'solana' ) {
361
358
return await getMessageSolana ( tx ) ;
362
359
}
363
360
throw new Error ( 'Unsupported chain' ) ;
@@ -403,7 +400,7 @@ export abstract class NttBase extends BaseRoute {
403
400
gasEstimate,
404
401
receiveTx,
405
402
} = params ;
406
- const token = TOKENS [ receivedTokenKey ] ;
403
+ const token = config . tokens [ receivedTokenKey ] ;
407
404
const formattedAmt = toNormalizedDecimals (
408
405
amount ,
409
406
tokenDecimals ,
@@ -420,15 +417,15 @@ export abstract class NttBase extends BaseRoute {
420
417
] ,
421
418
} ;
422
419
if ( this . TYPE === Route . NttManual ) {
423
- const { gasToken } = CHAINS [ toChain ] ! ;
420
+ const { gasToken } = config . chains [ toChain ] ! ;
424
421
let gas = gasEstimate ;
425
422
if ( receiveTx ) {
426
423
if ( isEvmChain ( toChain ) ) {
427
- const gasFee = await wh . getTxGasFee ( toChain , receiveTx ) ;
424
+ const gasFee = await config . wh . getTxGasFee ( toChain , receiveTx ) ;
428
425
if ( gasFee ) {
429
426
gas = formatGasFee ( toChain , gasFee ) ;
430
427
}
431
- } else if ( wh . toChainName ( toChain ) === 'solana' ) {
428
+ } else if ( toChainName ( toChain ) === 'solana' ) {
432
429
const connection = solanaContext ( ) . connection ;
433
430
if ( ! connection ) throw new Error ( 'Connection not found' ) ;
434
431
const tx = await connection . getParsedTransaction ( receiveTx ) ;
@@ -439,8 +436,10 @@ export abstract class NttBase extends BaseRoute {
439
436
}
440
437
result . displayData . push ( {
441
438
title : receiveTx ? 'Gas fee' : 'Gas estimate' ,
442
- value : gas ? `${ gas } ${ getDisplayName ( TOKENS [ gasToken ] ) } ` : NO_INPUT ,
443
- valueUSD : calculateUSDPrice ( gas , tokenPrices , TOKENS [ gasToken ] ) ,
439
+ value : gas
440
+ ? `${ gas } ${ getDisplayName ( config . tokens [ gasToken ] ) } `
441
+ : NO_INPUT ,
442
+ valueUSD : calculateUSDPrice ( gas , tokenPrices , config . tokens [ gasToken ] ) ,
444
443
} ) ;
445
444
}
446
445
return result ;
0 commit comments