Skip to content

Commit 6603424

Browse files
Stop using supportedSourceTokens method (#3198)
* stop using supportedSourceTokens method * bump wh sdk to 1.11.0 for route.supportedSourceTokens removal * remove param --------- Co-authored-by: Kevin Peters <kevin@wormholelabs.xyz>
1 parent fe6c771 commit 6603424

File tree

7 files changed

+418
-425
lines changed

7 files changed

+418
-425
lines changed

wormhole-connect/package-lock.json

+395-250
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wormhole-connect/package.json

+16-16
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"@solana/spl-token": "^0.3.9",
4040
"@solana/wallet-adapter-wallets": "^0.19.25",
4141
"@solana/web3.js": "^1.95.8",
42-
"@wormhole-foundation/sdk": "1.10.1-beta.0",
43-
"@wormhole-foundation/sdk-definitions": "1.10.1-beta.0",
42+
"@wormhole-foundation/sdk": "1.11.0",
43+
"@wormhole-foundation/sdk-definitions": "1.11.0",
4444
"@wormhole-foundation/sdk-definitions-ntt": "^0.6.1",
4545
"@wormhole-foundation/sdk-evm-ntt": "^0.6.1",
4646
"@wormhole-foundation/sdk-icons": "^1.0.0",
@@ -168,28 +168,28 @@
168168
"axios": "1.4.0"
169169
},
170170
"@mayanfinance/wormhole-sdk-route": {
171-
"@wormhole-foundation/sdk-connect": "1.10.1-beta.0",
172-
"@wormhole-foundation/sdk-evm": "1.10.1-beta.0",
173-
"@wormhole-foundation/sdk-solana": "1.10.1-beta.0"
171+
"@wormhole-foundation/sdk-connect": "1.11.0",
172+
"@wormhole-foundation/sdk-evm": "1.11.0",
173+
"@wormhole-foundation/sdk-solana": "1.11.0"
174174
},
175175
"@wormhole-foundation/sdk-definitions-ntt": {
176-
"@wormhole-foundation/sdk-base": "1.10.1-beta.0",
177-
"@wormhole-foundation/sdk-definitions": "1.10.1-beta.0"
176+
"@wormhole-foundation/sdk-base": "1.11.0",
177+
"@wormhole-foundation/sdk-definitions": "1.11.0"
178178
},
179179
"@wormhole-foundation/sdk-evm-ntt": {
180-
"@wormhole-foundation/sdk-base": "1.10.1-beta.0",
181-
"@wormhole-foundation/sdk-definitions": "1.10.1-beta.0",
182-
"@wormhole-foundation/sdk-evm": "1.10.1-beta.0",
183-
"@wormhole-foundation/sdk-evm-core": "1.10.1-beta.0"
180+
"@wormhole-foundation/sdk-base": "1.11.0",
181+
"@wormhole-foundation/sdk-definitions": "1.11.0",
182+
"@wormhole-foundation/sdk-evm": "1.11.0",
183+
"@wormhole-foundation/sdk-evm-core": "1.11.0"
184184
},
185185
"@wormhole-foundation/sdk-route-ntt": {
186-
"@wormhole-foundation/sdk-connect": "1.10.1-beta.0"
186+
"@wormhole-foundation/sdk-connect": "1.11.0"
187187
},
188188
"@wormhole-foundation/sdk-solana-ntt": {
189-
"@wormhole-foundation/sdk-base": "1.10.1-beta.0",
190-
"@wormhole-foundation/sdk-definitions": "1.10.1-beta.0",
191-
"@wormhole-foundation/sdk-solana": "1.10.1-beta.0",
192-
"@wormhole-foundation/sdk-solana-core": "1.10.1-beta.0"
189+
"@wormhole-foundation/sdk-base": "1.11.0",
190+
"@wormhole-foundation/sdk-definitions": "1.11.0",
191+
"@wormhole-foundation/sdk-solana": "1.11.0",
192+
"@wormhole-foundation/sdk-solana-core": "1.11.0"
193193
},
194194
"@wormhole-foundation/wormhole-connect": {
195195
"aptos": "1.5.2"

wormhole-connect/src/hooks/useComputeSourceTokens.ts

-88
This file was deleted.

wormhole-connect/src/routes/operator.ts

-17
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
import '@wormhole-foundation/sdk-definitions-ntt';
2121
import '@wormhole-foundation/sdk-evm-ntt';
2222
import '@wormhole-foundation/sdk-solana-ntt';
23-
import { maybeLogSdkError } from 'utils/errors';
2423

2524
export interface TxInfo {
2625
route: string;
@@ -155,22 +154,6 @@ export default class RouteOperator {
155154
return Array.from(supported);
156155
}
157156

158-
async allSupportedSourceTokens(sourceChain?: Chain): Promise<Token[]> {
159-
const supported: { [key: string]: Token } = {};
160-
await this.forEach(async (_name, route) => {
161-
try {
162-
const sourceTokens = await route.supportedSourceTokens(sourceChain);
163-
164-
for (const token of sourceTokens) {
165-
supported[token.key] = token;
166-
}
167-
} catch (e) {
168-
maybeLogSdkError(e);
169-
}
170-
});
171-
return Object.values(supported);
172-
}
173-
174157
async allSupportedDestTokens(
175158
sourceToken: Token | undefined,
176159
sourceChain: Chain,

wormhole-connect/src/routes/sdkv2/route.ts

+6-27
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ export class SDKv2Route {
7070
const fromChainSupported = supportedChains.includes(fromContext.chain);
7171
const toChainSupported = supportedChains.includes(toContext.chain);
7272

73-
const fromTokenSupported = !!(
74-
await this.rc.supportedSourceTokens(fromContext.context)
75-
).find((tokenId) => {
76-
return isSameToken(tokenId, sourceToken);
77-
});
78-
7973
if (
8074
this.IS_TOKEN_BRIDGE_ROUTE &&
8175
(await isNttSupportedToken(
@@ -98,10 +92,7 @@ export class SDKv2Route {
9892
});
9993

10094
const isSupported =
101-
fromChainSupported &&
102-
toChainSupported &&
103-
fromTokenSupported &&
104-
toTokenSupported;
95+
fromChainSupported && toChainSupported && toTokenSupported;
10596

10697
return isSupported;
10798
}
@@ -110,15 +101,6 @@ export class SDKv2Route {
110101
return this.rc.supportedChains(config.network).includes(chain);
111102
}
112103

113-
async supportedSourceTokens(fromChain?: Chain | undefined): Promise<Token[]> {
114-
if (!fromChain) return [];
115-
116-
const fromContext = await this.getV2ChainContext(fromChain);
117-
return (await this.rc.supportedSourceTokens(fromContext.context))
118-
.map((t: TokenId) => config.tokens.get(t))
119-
.filter((tc) => tc != undefined) as Token[];
120-
}
121-
122104
async supportedDestTokens(
123105
sourceToken: Token | undefined,
124106
fromChain?: Chain | undefined,
@@ -375,16 +357,13 @@ const isNttSupportedToken = async (
375357
const route: SDKv2Route | undefined = config.routes.get(routeName);
376358
if (!route) return false;
377359

378-
const [sourceTokens, destTokens] = await Promise.all([
379-
route.rc.supportedSourceTokens(fromContext),
380-
route.rc.supportedDestinationTokens(token, fromContext, toContext),
381-
]);
382-
383-
const isSourceTokenSupported = sourceTokens.some((t) =>
384-
isSameToken(t, token),
360+
const destTokens = await route.rc.supportedDestinationTokens(
361+
token,
362+
fromContext,
363+
toContext,
385364
);
386365

387-
return isSourceTokenSupported && destTokens.length > 0;
366+
return destTokens.length > 0;
388367
};
389368

390369
const [isManualSupported, isAutomaticSupported, isM0Supported] =

wormhole-connect/src/store/transferInput.ts

-9
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export interface TransferInputState {
8181
};
8282
isTransactionInProgress: boolean;
8383
receiverNativeBalance: string | undefined;
84-
supportedSourceTokens: TokenTuple[];
8584
}
8685

8786
// This is a function because config might have changed since we last cleared this store
@@ -127,7 +126,6 @@ function getInitialState(): TransferInputState {
127126
},
128127
isTransactionInProgress: false,
129128
receiverNativeBalance: '',
130-
supportedSourceTokens: [],
131129
};
132130
}
133131

@@ -303,12 +301,6 @@ export const transferInputSlice = createSlice({
303301
) => {
304302
state.isTransactionInProgress = payload;
305303
},
306-
setSupportedSourceTokens: (
307-
state: TransferInputState,
308-
{ payload }: PayloadAction<TokenTuple[]>,
309-
) => {
310-
state.supportedSourceTokens = payload;
311-
},
312304
swapInputs: (state: TransferInputState) => {
313305
const tmpChain = state.fromChain;
314306
state.fromChain = state.toChain;
@@ -386,7 +378,6 @@ export const {
386378
updateBalances,
387379
clearTransfer,
388380
setIsTransactionInProgress,
389-
setSupportedSourceTokens,
390381
swapInputs,
391382
} = transferInputSlice.actions;
392383

wormhole-connect/src/views/v2/Bridge/index.tsx

+1-18
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import Button from 'components/v2/Button';
2121
import config from 'config';
2222
import useFetchSupportedRoutes from 'hooks/useFetchSupportedRoutes';
2323
import useComputeDestinationTokens from 'hooks/useComputeDestinationTokens';
24-
import useComputeSourceTokens from 'hooks/useComputeSourceTokens';
2524
import { useSortedRoutesWithQuotes } from 'hooks/useSortedRoutesWithQuotes';
2625
import { useAmountValidation } from 'hooks/useAmountValidation';
2726
import useConfirmTransaction from 'hooks/useConfirmTransaction';
@@ -128,7 +127,6 @@ const Bridge = () => {
128127
toChain: destChain,
129128
route,
130129
preferredRouteName,
131-
supportedSourceTokens,
132130
amount,
133131
validations,
134132
isTransactionInProgress,
@@ -144,16 +142,6 @@ const Bridge = () => {
144142
isFetching: isFetchingQuotes,
145143
} = useSortedRoutesWithQuotes();
146144

147-
// Compute and set source tokens
148-
const { isFetching: isFetchingSupportedSourceTokens } =
149-
useComputeSourceTokens({
150-
sourceChain,
151-
destChain,
152-
sourceToken,
153-
destToken,
154-
route,
155-
});
156-
157145
// Compute and set destination tokens
158146
const { isFetching: isFetchingSupportedDestTokens, supportedDestTokens } =
159147
useComputeDestinationTokens({
@@ -311,9 +299,6 @@ const Bridge = () => {
311299
chainList={supportedSourceChains}
312300
token={sourceToken}
313301
tokenList={sourceTokens}
314-
isFetching={
315-
sourceTokens.length === 0 && isFetchingSupportedSourceTokens
316-
}
317302
setChain={(value: Chain) => {
318303
selectFromChain(dispatch, value, sendingWallet);
319304
}}
@@ -335,8 +320,6 @@ const Bridge = () => {
335320
sourceToken,
336321
sourceTokens,
337322
lastTokenCacheUpdate,
338-
supportedSourceTokens,
339-
isFetchingSupportedSourceTokens,
340323
isTransactionInProgress,
341324
sendingWallet,
342325
dispatch,
@@ -594,7 +577,7 @@ const Bridge = () => {
594577
{destAssetPicker}
595578
<AmountInput
596579
sourceChain={sourceChain}
597-
supportedSourceTokens={config.tokens.getList(supportedSourceTokens)}
580+
supportedSourceTokens={sourceTokens}
598581
tokenBalance={sourceToken ? balances[sourceToken.key]?.balance : null}
599582
isFetchingTokenBalance={isFetchingBalances}
600583
error={amountValidation.error}

0 commit comments

Comments
 (0)