Skip to content

Commit cfc6922

Browse files
committed
added ntt token group id
1 parent c87d93b commit cfc6922

File tree

8 files changed

+48
-18
lines changed

8 files changed

+48
-18
lines changed

wormhole-connect/src/config/testnet/tokens.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,7 @@ export const TESTNET_TOKENS: TokensConfig = {
22482248
default: 8,
22492249
},
22502250
ntt: {
2251+
groupId: 'test_ntt',
22512252
nttManager: '0xB231aD95f2301bc82eA44c515001F0F746D637e0',
22522253
wormholeTransceiver: '0x1fDC902e30b188FD2BA976B421Cb179943F57896',
22532254
},
@@ -2268,6 +2269,7 @@ export const TESTNET_TOKENS: TokensConfig = {
22682269
default: 8,
22692270
},
22702271
ntt: {
2272+
groupId: 'test_ntt',
22712273
nttManager: '0xEec94CD3083e067398256a79CcA7e740C5c8ef81',
22722274
wormholeTransceiver: '0x0E24D17D7467467b39Bf64A9DFf88776Bd6c74d7',
22732275
},
@@ -2288,6 +2290,7 @@ export const TESTNET_TOKENS: TokensConfig = {
22882290
default: 8,
22892291
},
22902292
ntt: {
2293+
groupId: 'test_ntt',
22912294
nttManager: '0xB03b030b2f5B40819Df76467d67eD1C85Ff66fAD',
22922295
wormholeTransceiver: '0x1e072169541f1171e427Aa44B5fd8924BEE71b0e',
22932296
},
@@ -2308,6 +2311,7 @@ export const TESTNET_TOKENS: TokensConfig = {
23082311
default: 8,
23092312
},
23102313
ntt: {
2314+
groupId: 'test_ntt',
23112315
nttManager: '0x7f430D4e7939D994C0955A01FC75D9DE33F12D11',
23122316
wormholeTransceiver: '0x41265eb2863bf0238081F6AeefeF73549C82C3DD',
23132317
},
@@ -2328,6 +2332,7 @@ export const TESTNET_TOKENS: TokensConfig = {
23282332
default: 8,
23292333
},
23302334
ntt: {
2335+
groupId: 'test_ntt',
23312336
nttManager: 'nTTh3bZ5Aer6xboWZe39RDEft4MeVxSQ8D1EYAVLZw9',
23322337
// The wormhole transceiver is baked into the Solana NTT contract.
23332338
// If the transceiver is split into a separate contract, this address

wormhole-connect/src/config/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export type TokenConfig = {
234234
};
235235
};
236236
ntt?: {
237+
groupId: string;
237238
nttManager: string;
238239
wormholeTransceiver: string;
239240
solanaQuoter?: string;

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
removeDust,
2929
toNormalizedDecimals,
3030
} from 'utils';
31-
import { getNativeVersionOfToken } from 'store/transferInput';
31+
import { getNttToken } from 'store/transferInput';
3232
import { getNttManager } from './platforms';
3333
import { InboundQueuedTransfer } from './types';
3434
import {
@@ -340,10 +340,10 @@ export abstract class NttBase extends BaseRoute {
340340
chain: ChainName | ChainId,
341341
): Promise<string | null> {
342342
const tokenConfig = getTokenById(token);
343-
if (!tokenConfig) {
343+
if (!tokenConfig?.ntt) {
344344
throw new Error('invalid token');
345345
}
346-
const key = getNativeVersionOfToken(tokenConfig.symbol, toChainName(chain));
346+
const key = getNttToken(tokenConfig.ntt.groupId, chain);
347347
return config.tokens[key]?.tokenId?.address || null;
348348
}
349349

wormhole-connect/src/routes/ntt/platforms/evm/getMessage.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { ethers } from 'ethers';
99
import { hexlify } from 'ethers/lib/utils';
1010
import { NttRelayingType, UnsignedNttMessage } from 'routes/types';
11-
import { getNativeVersionOfToken } from 'store/transferInput';
11+
import { getNttToken } from 'store/transferInput';
1212
import { getTokenById, getTokenDecimals } from 'utils';
1313
import { getWormholeLogEvm } from 'utils/vaa';
1414
import { NttManager__factory } from './abis';
@@ -45,7 +45,7 @@ export const getMessageEvm = async (
4545
address: tokenAddress,
4646
};
4747
const token = getTokenById(tokenId);
48-
if (!token) {
48+
if (!token?.ntt) {
4949
throw new Error(`Token ${tokenId} not found`);
5050
}
5151
const wormholeLog = await getWormholeLogEvm(fromChain, receipt);
@@ -79,6 +79,10 @@ export const getMessageEvm = async (
7979
const toChain = toChainName(
8080
nttManagerMessage.payload.recipientChain as ChainId,
8181
);
82+
const receivedTokenKey = getNttToken(token.ntt.groupId, toChain);
83+
if (!receivedTokenKey) {
84+
throw new Error(`Received token key not found for ${tokenId}`);
85+
}
8286
return {
8387
sendTx: receipt.transactionHash,
8488
sender: receipt.from,
@@ -95,7 +99,7 @@ export const getMessageEvm = async (
9599
tokenId,
96100
tokenKey: token.key,
97101
tokenDecimals: getTokenDecimals(toChainId(fromChain), tokenId),
98-
receivedTokenKey: getNativeVersionOfToken(token.symbol, toChain),
102+
receivedTokenKey,
99103
emitterAddress: hexlify(
100104
config.wh.formatAddress(parsedWormholeLog.args.sender, fromChain),
101105
),

wormhole-connect/src/routes/ntt/platforms/solana/getMessage.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { solanaContext } from 'utils/sdk';
22
import { PostedMessageData } from '@certusone/wormhole-sdk/lib/esm/solana/wormhole';
33
import { hexlify } from 'ethers/lib/utils';
44
import { NttRelayingType, UnsignedNttMessage } from 'routes/types';
5-
import { getNativeVersionOfToken } from 'store/transferInput';
5+
import { getNttToken } from 'store/transferInput';
66
import { getTokenById, getTokenDecimals } from 'utils';
77
import {
88
getNttManagerMessageDigest,
@@ -54,9 +54,13 @@ export const getMessageSolana = async (
5454
address: tokenAddress,
5555
};
5656
const token = getTokenById(tokenId);
57-
if (!token) {
57+
if (!token?.ntt) {
5858
throw new Error(`Token ${tokenId} not found`);
5959
}
60+
const receivedTokenKey = getNttToken(token.ntt.groupId, toChain);
61+
if (!receivedTokenKey) {
62+
throw new Error(`Received token key not found for ${tokenId}`);
63+
}
6064
const logMsgs = response.meta?.logMessages || [];
6165
const regex = /total fee in lamports: (\d+)/;
6266
const relayerFeeMsg = logMsgs.find((msg) => regex.test(msg));
@@ -83,7 +87,7 @@ export const getMessageSolana = async (
8387
tokenId,
8488
tokenKey: token.key,
8589
tokenDecimals: getTokenDecimals(config.wh.toChainId(fromChain), tokenId),
86-
receivedTokenKey: getNativeVersionOfToken(token.symbol, toChain),
90+
receivedTokenKey,
8791
emitterAddress: hexlify(
8892
context.formatAddress(messageData.message.emitterAddress),
8993
),

wormhole-connect/src/routes/ntt/platforms/solana/nttManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export class NttManagerSolana {
363363
const signatures = await this.connection.getSignaturesForAddress(address, {
364364
limit: 1,
365365
});
366-
return signatures ? signatures[0].signature : undefined;
366+
return signatures?.[0]?.signature;
367367
}
368368

369369
// Account addresses

wormhole-connect/src/store/transferInput.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2-
import { ChainName, Context } from '@wormhole-foundation/wormhole-connect-sdk';
2+
import {
3+
ChainName,
4+
ChainId,
5+
Context,
6+
} from '@wormhole-foundation/wormhole-connect-sdk';
37
import { BigNumber } from 'ethers';
48
import config from 'config';
59
import { Route, TokenConfig } from 'config/types';
@@ -55,6 +59,19 @@ export const getNativeVersionOfToken = (
5559
);
5660
};
5761

62+
// get the token key for the NTT token for a given group and chain
63+
export const getNttToken = (
64+
groupId: string,
65+
chain: ChainName | ChainId,
66+
): string => {
67+
return (
68+
Object.entries(config.tokens)
69+
.map(([key, t]) => t)
70+
.find((t) => t.ntt?.groupId === groupId && t.nativeChain === chain)
71+
?.key || ''
72+
);
73+
};
74+
5875
export const accessChainBalances = (
5976
balances: WalletBalances | undefined,
6077
walletAddress: WalletAddress | undefined,
@@ -200,7 +217,7 @@ const performModificationsIfFromChainChanged = (state: TransferInputState) => {
200217
state.token = getNativeVersionOfToken(tokenConfig.symbol, fromChain!);
201218
}
202219
} else if (tokenConfig.ntt && tokenConfig.nativeChain !== fromChain) {
203-
state.token = getNativeVersionOfToken(tokenConfig.symbol, fromChain!);
220+
state.token = getNttToken(tokenConfig.ntt.groupId, fromChain!);
204221
}
205222
}
206223
};
@@ -228,7 +245,7 @@ const performModificationsIfToChainChanged = (state: TransferInputState) => {
228245
state.destToken = getNativeVersionOfToken(tokenConfig.symbol, toChain!);
229246
}
230247
} else if (tokenConfig.ntt && tokenConfig.nativeChain !== toChain) {
231-
state.destToken = getNativeVersionOfToken(tokenConfig.symbol, toChain!);
248+
state.destToken = getNttToken(tokenConfig.ntt.groupId, toChain!);
232249
}
233250
}
234251
};

wormhole-connect/src/views/Bridge/NttInboundCapacityWarning.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { NttManual } from 'routes/ntt';
44
import { parseUnits } from 'ethers/lib/utils';
55
import { getTokenDecimals } from 'utils';
66
import { BigNumber } from 'ethers';
7-
import { getNativeVersionOfToken } from 'store/transferInput';
7+
import { getNttToken } from 'store/transferInput';
88
import { useSelector } from 'react-redux';
99
import { RootState } from 'store';
1010
import config from 'config';
@@ -81,10 +81,9 @@ const NttInboundCapacityWarning = () => {
8181
!fromChain
8282
)
8383
return false;
84-
const destTokenKey = getNativeVersionOfToken(
85-
config.tokens[destToken].symbol,
86-
toChain,
87-
);
84+
const groupId = config.tokens[destToken]?.ntt?.groupId;
85+
if (!groupId) return false;
86+
const destTokenKey = getNttToken(groupId, toChain);
8887
const destTokenConfig = config.tokens[destTokenKey];
8988
if (!destTokenConfig) return false;
9089
// capacity is in destination token decimals, so we need to convert the amount to the same decimals

0 commit comments

Comments
 (0)