Skip to content

Commit 79a314b

Browse files
committed
config refactor changes
1 parent 2bfeb4e commit 79a314b

17 files changed

+150
-134
lines changed

wormhole-connect/src/AppRouter.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { clearWallets } from './store/wallet';
2020
import { clearPorticoBridge } from 'store/porticoBridge';
2121
import { useExternalSearch } from 'hooks/useExternalSearch';
2222
import { clearNtt } from 'store/ntt';
23-
import { wh } from 'utils/sdk';
23+
import internalConfig from 'config';
2424

2525
const useStyles = makeStyles()((theme: any) => ({
2626
appContent: {
@@ -74,7 +74,7 @@ function AppRouter({ config }: Props) {
7474
dispatch(clearRedeem());
7575
dispatch(clearWallets());
7676
dispatch(clearNtt());
77-
wh.registerProviders(); // reset providers that may have been set during transfer
77+
internalConfig.wh.registerProviders(); // reset providers that may have been set during transfer
7878
}
7979
// reset transfer state on leave
8080
if (prevRoute === bridgeRoute && route !== bridgeRoute) {

wormhole-connect/src/hooks/useDeliveryStatus.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { DeliveryStatus } from '@certusone/wormhole-sdk/lib/esm/relayer';
22
import axios from 'axios';
3-
import { isMainnet } from 'config';
43
import { Route } from 'config/types';
54
import { useEffect } from 'react';
65
import { useDispatch, useSelector } from 'react-redux';
@@ -9,10 +8,7 @@ import { setRedeemTx, setDeliveryStatus } from 'store/redeem';
98
import { sleep } from 'utils';
109
import { isEvmChain } from 'utils/sdk';
1110
import { getEmitterAndSequence } from 'utils/vaa';
12-
13-
const BASE_URL = `https://api.${
14-
isMainnet ? '' : 'testnet.'
15-
}wormholescan.io/api/v1/relays`;
11+
import config from 'config';
1612

1713
const RETRY_DELAY = 15_000;
1814

@@ -44,12 +40,15 @@ const useDeliveryStatus = (): void => {
4440
}
4541
const { emitterChain, emitterAddress, sequence } =
4642
getEmitterAndSequence(signedMessage);
43+
const baseUrl = `https://api.${
44+
config.isMainnet ? '' : 'testnet.'
45+
}wormholescan.io/api/v1/relays`;
4746
let active = true;
4847
const fetchData = async () => {
4948
while (active) {
5049
try {
5150
const response = await axios.get<RelayResponse>(
52-
`${BASE_URL}/${emitterChain}/${emitterAddress}/${sequence}`,
51+
`${baseUrl}/${emitterChain}/${emitterAddress}/${sequence}`,
5352
);
5453
if (active) {
5554
const { delivery, toTxHash } = response.data?.data || {};

wormhole-connect/src/routes/ntt/nttBase.ts

+25-26
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import {
1818
import { fetchVaa } from 'utils/vaa';
1919
import { hexlify, parseUnits } from 'ethers/lib/utils.js';
2020
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';
2322
import {
2423
MAX_DECIMALS,
2524
calculateUSDPrice,
@@ -41,6 +40,7 @@ import { NttManagerSolana, getMessageSolana } from './platforms/solana';
4140
import { formatGasFee } from 'routes/utils';
4241
import { NO_INPUT } from 'utils/style';
4342
import { estimateAverageGasFee } from 'utils/gas';
43+
import config from 'config';
4444

4545
export abstract class NttBase extends BaseRoute {
4646
isSupportedChain(chain: ChainName): boolean {
@@ -103,17 +103,17 @@ export abstract class NttBase extends BaseRoute {
103103
destChain: ChainName | ChainId,
104104
): Promise<boolean> {
105105
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)),
108108
this.isSupportedSourceToken(
109-
TOKENS[sourceToken],
110-
TOKENS[destToken],
109+
config.tokens[sourceToken],
110+
config.tokens[destToken],
111111
sourceChain,
112112
destChain,
113113
),
114114
this.isSupportedDestToken(
115-
TOKENS[destToken],
116-
TOKENS[sourceToken],
115+
config.tokens[destToken],
116+
config.tokens[sourceToken],
117117
sourceChain,
118118
destChain,
119119
),
@@ -164,7 +164,7 @@ export abstract class NttBase extends BaseRoute {
164164
if (isEvmChain(sendingChain)) {
165165
const gasLimit = this.TYPE === Route.NttManual ? 200_000 : 250_000;
166166
return await estimateAverageGasFee(sendingChain, gasLimit);
167-
} else if (wh.toChainName(sendingChain) === 'solana') {
167+
} else if (toChainName(sendingChain) === 'solana') {
168168
return BigNumber.from(10_000);
169169
}
170170
throw new Error('Unsupported chain');
@@ -181,7 +181,7 @@ export abstract class NttBase extends BaseRoute {
181181
if (isEvmChain(destChain)) {
182182
const gasLimit = 300_000;
183183
return await estimateAverageGasFee(destChain, gasLimit);
184-
} else if (wh.toChainName(destChain) === 'solana') {
184+
} else if (toChainName(destChain) === 'solana') {
185185
return BigNumber.from(65_000); // TODO: check this
186186
}
187187
throw new Error('Unsupported chain');
@@ -204,7 +204,7 @@ export abstract class NttBase extends BaseRoute {
204204
if (!tokenConfig?.ntt) {
205205
throw new Error('invalid token');
206206
}
207-
const destTokenConfig = TOKENS[destToken];
207+
const destTokenConfig = config.tokens[destToken];
208208
if (!destTokenConfig?.ntt) {
209209
throw new Error('invalid dest token');
210210
}
@@ -221,7 +221,7 @@ export abstract class NttBase extends BaseRoute {
221221
throw new ContractIsPausedError();
222222
}
223223
const decimals = getTokenDecimals(
224-
wh.toChainId(sendingChain),
224+
toChainId(sendingChain),
225225
tokenConfig.tokenId,
226226
);
227227
const sendAmount = removeDust(parseUnits(amount, decimals), decimals);
@@ -252,7 +252,7 @@ export abstract class NttBase extends BaseRoute {
252252
if (await nttManager.isPaused()) {
253253
throw new ContractIsPausedError();
254254
}
255-
const nttConfig = TOKENS[receivedTokenKey]?.ntt;
255+
const nttConfig = config.tokens[receivedTokenKey]?.ntt;
256256
if (!nttConfig) {
257257
throw new Error('ntt config not found');
258258
}
@@ -263,7 +263,7 @@ export abstract class NttBase extends BaseRoute {
263263
);
264264
return await transceiver.receiveMessage(vaa, payer);
265265
}
266-
if (wh.toChainName(chain) === 'solana') {
266+
if (toChainName(chain) === 'solana') {
267267
return await (nttManager as NttManagerSolana).receiveMessage(vaa, payer);
268268
}
269269
throw new Error('Unsupported chain');
@@ -343,11 +343,8 @@ export abstract class NttBase extends BaseRoute {
343343
if (!tokenConfig) {
344344
throw new Error('invalid token');
345345
}
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;
351348
}
352349

353350
async getMessage(
@@ -357,7 +354,7 @@ export abstract class NttBase extends BaseRoute {
357354
if (isEvmChain(chain)) {
358355
return await getMessageEvm(tx, chain);
359356
}
360-
if (wh.toChainName(chain) === 'solana') {
357+
if (toChainName(chain) === 'solana') {
361358
return await getMessageSolana(tx);
362359
}
363360
throw new Error('Unsupported chain');
@@ -403,7 +400,7 @@ export abstract class NttBase extends BaseRoute {
403400
gasEstimate,
404401
receiveTx,
405402
} = params;
406-
const token = TOKENS[receivedTokenKey];
403+
const token = config.tokens[receivedTokenKey];
407404
const formattedAmt = toNormalizedDecimals(
408405
amount,
409406
tokenDecimals,
@@ -420,15 +417,15 @@ export abstract class NttBase extends BaseRoute {
420417
],
421418
};
422419
if (this.TYPE === Route.NttManual) {
423-
const { gasToken } = CHAINS[toChain]!;
420+
const { gasToken } = config.chains[toChain]!;
424421
let gas = gasEstimate;
425422
if (receiveTx) {
426423
if (isEvmChain(toChain)) {
427-
const gasFee = await wh.getTxGasFee(toChain, receiveTx);
424+
const gasFee = await config.wh.getTxGasFee(toChain, receiveTx);
428425
if (gasFee) {
429426
gas = formatGasFee(toChain, gasFee);
430427
}
431-
} else if (wh.toChainName(toChain) === 'solana') {
428+
} else if (toChainName(toChain) === 'solana') {
432429
const connection = solanaContext().connection;
433430
if (!connection) throw new Error('Connection not found');
434431
const tx = await connection.getParsedTransaction(receiveTx);
@@ -439,8 +436,10 @@ export abstract class NttBase extends BaseRoute {
439436
}
440437
result.displayData.push({
441438
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]),
444443
});
445444
}
446445
return result;

wormhole-connect/src/routes/ntt/nttRelay.ts

+20-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { BigNumber } from 'ethers';
33
import { getNttManager } from './platforms';
44
import { ChainName, ChainId } from '@wormhole-foundation/wormhole-connect-sdk';
55
import { NttBase } from './nttBase';
6-
import { CHAINS, TOKENS } from 'config';
76
import {
87
RelayerFee,
98
TransferDisplayData,
@@ -18,12 +17,18 @@ import {
1817
getTokenDecimals,
1918
toNormalizedDecimals,
2019
} from 'utils';
21-
import { ParsedRelayerMessage, isEvmChain, toChainId, wh } from 'utils/sdk';
20+
import {
21+
ParsedRelayerMessage,
22+
isEvmChain,
23+
toChainId,
24+
toChainName,
25+
} from 'utils/sdk';
2226
import { NO_INPUT } from 'utils/style';
2327
import { TokenPrices } from 'store/tokenPrices';
2428
import { toDecimals, toFixedDecimals } from 'utils/balance';
2529
import { NttManagerEvm, WormholeTransceiver } from './platforms/evm';
2630
import { NttQuoter } from './platforms/solana/nttQuoter';
31+
import config from 'config';
2732

2833
export class NttRelay extends NttBase {
2934
readonly NATIVE_GAS_DROPOFF_SUPPORTED: boolean = false;
@@ -37,7 +42,7 @@ export class NttRelay extends NttBase {
3742
sourceChain: ChainName | ChainId,
3843
destChain: ChainName | ChainId,
3944
): Promise<boolean> {
40-
const nttConfig = TOKENS[sourceToken]?.ntt;
45+
const nttConfig = config.tokens[sourceToken]?.ntt;
4146
if (!nttConfig) {
4247
return false;
4348
}
@@ -62,7 +67,7 @@ export class NttRelay extends NttBase {
6267
transceiver.isSpecialRelayingEnabled(destChain),
6368
]).then((results) => results.some((r) => r));
6469
}
65-
if (wh.toChainName(sourceChain) === 'solana') {
70+
if (toChainName(sourceChain) === 'solana') {
6671
if (!nttConfig.solanaQuoter) return false;
6772
const quoter = new NttQuoter(nttConfig.solanaQuoter);
6873
return await quoter.isRelayEnabled(destChain);
@@ -76,7 +81,7 @@ export class NttRelay extends NttBase {
7681
token: string,
7782
destToken: string,
7883
): Promise<RelayerFee | null> {
79-
const nttConfig = TOKENS[token]?.ntt;
84+
const nttConfig = config.tokens[token]?.ntt;
8085
if (!nttConfig) {
8186
throw new Error('invalid token');
8287
}
@@ -88,7 +93,7 @@ export class NttRelay extends NttBase {
8893
);
8994
return { fee: BigNumber.from(deliveryPrice), feeToken: 'native' };
9095
}
91-
if (wh.toChainName(sourceChain) === 'solana') {
96+
if (toChainName(sourceChain) === 'solana') {
9297
if (!nttConfig.solanaQuoter) throw new Error('no solana quoter');
9398
const quoter = new NttQuoter(nttConfig.solanaQuoter);
9499
const relayCost = await quoter.calcRelayCost(destChain);
@@ -109,21 +114,21 @@ export class NttRelay extends NttBase {
109114
tokenPrices: TokenPrices,
110115
routeOptions: { relayerFee: number },
111116
): Promise<TransferDisplayData> {
112-
const sendingChainName = wh.toChainName(sendingChain);
113-
const sourceGasToken = CHAINS[sendingChainName]?.gasToken;
117+
const sendingChainName = toChainName(sendingChain);
118+
const sourceGasToken = config.chains[sendingChainName]?.gasToken;
114119
const sourceGasTokenSymbol = sourceGasToken
115-
? getDisplayName(TOKENS[sourceGasToken])
120+
? getDisplayName(config.tokens[sourceGasToken])
116121
: '';
117122
// Calculate the USD value of the gas
118123
const sendingGasEstPrice = calculateUSDPrice(
119124
sendingGasEst,
120125
tokenPrices,
121-
TOKENS[sourceGasToken || ''],
126+
config.tokens[sourceGasToken || ''],
122127
);
123128
const relayerFeePrice = calculateUSDPrice(
124129
routeOptions.relayerFee,
125130
tokenPrices,
126-
TOKENS[sourceGasToken || ''],
131+
config.tokens[sourceGasToken || ''],
127132
);
128133
let totalFeesText = '';
129134
let totalFeesPrice = '';
@@ -138,7 +143,7 @@ export class NttRelay extends NttBase {
138143
totalFeesPrice = calculateUSDPrice(
139144
feeValue,
140145
tokenPrices,
141-
TOKENS[sourceGasToken],
146+
config.tokens[sourceGasToken],
142147
);
143148
}
144149
return [
@@ -183,16 +188,16 @@ export class NttRelay extends NttBase {
183188
tokenDecimals,
184189
MAX_DECIMALS,
185190
);
186-
const { gasToken: sourceGasTokenKey } = CHAINS[fromChain]!;
187-
const sourceGasToken = TOKENS[sourceGasTokenKey];
191+
const { gasToken: sourceGasTokenKey } = config.chains[fromChain]!;
192+
const sourceGasToken = config.tokens[sourceGasTokenKey];
188193
const decimals = getTokenDecimals(
189194
toChainId(sourceGasToken.nativeChain),
190195
'native',
191196
);
192197
const formattedGas = gasFee && toDecimals(gasFee, decimals, MAX_DECIMALS);
193198
const formattedFee =
194199
relayerFee && toDecimals(relayerFee, decimals, MAX_DECIMALS);
195-
const token = TOKENS[tokenKey];
200+
const token = config.tokens[tokenKey];
196201

197202
return [
198203
{

0 commit comments

Comments
 (0)