Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using supportedSourceTokens method #3198

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
645 changes: 395 additions & 250 deletions wormhole-connect/package-lock.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions wormhole-connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"@solana/spl-token": "^0.3.9",
"@solana/wallet-adapter-wallets": "^0.19.25",
"@solana/web3.js": "^1.95.8",
"@wormhole-foundation/sdk": "1.10.1-beta.0",
"@wormhole-foundation/sdk-definitions": "1.10.1-beta.0",
"@wormhole-foundation/sdk": "1.11.0",
"@wormhole-foundation/sdk-definitions": "1.11.0",
"@wormhole-foundation/sdk-definitions-ntt": "^0.6.1",
"@wormhole-foundation/sdk-evm-ntt": "^0.6.1",
"@wormhole-foundation/sdk-icons": "^1.0.0",
Expand Down Expand Up @@ -168,28 +168,28 @@
"axios": "1.4.0"
},
"@mayanfinance/wormhole-sdk-route": {
"@wormhole-foundation/sdk-connect": "1.10.1-beta.0",
"@wormhole-foundation/sdk-evm": "1.10.1-beta.0",
"@wormhole-foundation/sdk-solana": "1.10.1-beta.0"
"@wormhole-foundation/sdk-connect": "1.11.0",
"@wormhole-foundation/sdk-evm": "1.11.0",
"@wormhole-foundation/sdk-solana": "1.11.0"
},
"@wormhole-foundation/sdk-definitions-ntt": {
"@wormhole-foundation/sdk-base": "1.10.1-beta.0",
"@wormhole-foundation/sdk-definitions": "1.10.1-beta.0"
"@wormhole-foundation/sdk-base": "1.11.0",
"@wormhole-foundation/sdk-definitions": "1.11.0"
},
"@wormhole-foundation/sdk-evm-ntt": {
"@wormhole-foundation/sdk-base": "1.10.1-beta.0",
"@wormhole-foundation/sdk-definitions": "1.10.1-beta.0",
"@wormhole-foundation/sdk-evm": "1.10.1-beta.0",
"@wormhole-foundation/sdk-evm-core": "1.10.1-beta.0"
"@wormhole-foundation/sdk-base": "1.11.0",
"@wormhole-foundation/sdk-definitions": "1.11.0",
"@wormhole-foundation/sdk-evm": "1.11.0",
"@wormhole-foundation/sdk-evm-core": "1.11.0"
},
"@wormhole-foundation/sdk-route-ntt": {
"@wormhole-foundation/sdk-connect": "1.10.1-beta.0"
"@wormhole-foundation/sdk-connect": "1.11.0"
},
"@wormhole-foundation/sdk-solana-ntt": {
"@wormhole-foundation/sdk-base": "1.10.1-beta.0",
"@wormhole-foundation/sdk-definitions": "1.10.1-beta.0",
"@wormhole-foundation/sdk-solana": "1.10.1-beta.0",
"@wormhole-foundation/sdk-solana-core": "1.10.1-beta.0"
"@wormhole-foundation/sdk-base": "1.11.0",
"@wormhole-foundation/sdk-definitions": "1.11.0",
"@wormhole-foundation/sdk-solana": "1.11.0",
"@wormhole-foundation/sdk-solana-core": "1.11.0"
},
"@wormhole-foundation/wormhole-connect": {
"aptos": "1.5.2"
Expand Down
88 changes: 0 additions & 88 deletions wormhole-connect/src/hooks/useComputeSourceTokens.ts

This file was deleted.

17 changes: 0 additions & 17 deletions wormhole-connect/src/routes/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import '@wormhole-foundation/sdk-definitions-ntt';
import '@wormhole-foundation/sdk-evm-ntt';
import '@wormhole-foundation/sdk-solana-ntt';
import { maybeLogSdkError } from 'utils/errors';

export interface TxInfo {
route: string;
Expand Down Expand Up @@ -155,22 +154,6 @@ export default class RouteOperator {
return Array.from(supported);
}

async allSupportedSourceTokens(sourceChain?: Chain): Promise<Token[]> {
const supported: { [key: string]: Token } = {};
await this.forEach(async (_name, route) => {
try {
const sourceTokens = await route.supportedSourceTokens(sourceChain);

for (const token of sourceTokens) {
supported[token.key] = token;
}
} catch (e) {
maybeLogSdkError(e);
}
});
return Object.values(supported);
}

async allSupportedDestTokens(
sourceToken: Token | undefined,
sourceChain: Chain,
Expand Down
33 changes: 6 additions & 27 deletions wormhole-connect/src/routes/sdkv2/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ export class SDKv2Route {
const fromChainSupported = supportedChains.includes(fromContext.chain);
const toChainSupported = supportedChains.includes(toContext.chain);

const fromTokenSupported = !!(
await this.rc.supportedSourceTokens(fromContext.context)
).find((tokenId) => {
return isSameToken(tokenId, sourceToken);
});

if (
this.IS_TOKEN_BRIDGE_ROUTE &&
(await isNttSupportedToken(
Expand All @@ -98,10 +92,7 @@ export class SDKv2Route {
});

const isSupported =
fromChainSupported &&
toChainSupported &&
fromTokenSupported &&
toTokenSupported;
fromChainSupported && toChainSupported && toTokenSupported;

return isSupported;
}
Expand All @@ -110,15 +101,6 @@ export class SDKv2Route {
return this.rc.supportedChains(config.network).includes(chain);
}

async supportedSourceTokens(fromChain?: Chain | undefined): Promise<Token[]> {
if (!fromChain) return [];

const fromContext = await this.getV2ChainContext(fromChain);
return (await this.rc.supportedSourceTokens(fromContext.context))
.map((t: TokenId) => config.tokens.get(t))
.filter((tc) => tc != undefined) as Token[];
}

async supportedDestTokens(
sourceToken: Token | undefined,
fromChain?: Chain | undefined,
Expand Down Expand Up @@ -375,16 +357,13 @@ const isNttSupportedToken = async (
const route: SDKv2Route | undefined = config.routes.get(routeName);
if (!route) return false;

const [sourceTokens, destTokens] = await Promise.all([
route.rc.supportedSourceTokens(fromContext),
route.rc.supportedDestinationTokens(token, fromContext, toContext),
]);

const isSourceTokenSupported = sourceTokens.some((t) =>
isSameToken(t, token),
const destTokens = await route.rc.supportedDestinationTokens(
token,
fromContext,
toContext,
);

return isSourceTokenSupported && destTokens.length > 0;
return destTokens.length > 0;
};

const [isManualSupported, isAutomaticSupported, isM0Supported] =
Expand Down
9 changes: 0 additions & 9 deletions wormhole-connect/src/store/transferInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export interface TransferInputState {
};
isTransactionInProgress: boolean;
receiverNativeBalance: string | undefined;
supportedSourceTokens: TokenTuple[];
}

// This is a function because config might have changed since we last cleared this store
Expand Down Expand Up @@ -127,7 +126,6 @@ function getInitialState(): TransferInputState {
},
isTransactionInProgress: false,
receiverNativeBalance: '',
supportedSourceTokens: [],
};
}

Expand Down Expand Up @@ -303,12 +301,6 @@ export const transferInputSlice = createSlice({
) => {
state.isTransactionInProgress = payload;
},
setSupportedSourceTokens: (
state: TransferInputState,
{ payload }: PayloadAction<TokenTuple[]>,
) => {
state.supportedSourceTokens = payload;
},
swapInputs: (state: TransferInputState) => {
const tmpChain = state.fromChain;
state.fromChain = state.toChain;
Expand Down Expand Up @@ -386,7 +378,6 @@ export const {
updateBalances,
clearTransfer,
setIsTransactionInProgress,
setSupportedSourceTokens,
swapInputs,
} = transferInputSlice.actions;

Expand Down
19 changes: 1 addition & 18 deletions wormhole-connect/src/views/v2/Bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Button from 'components/v2/Button';
import config from 'config';
import useFetchSupportedRoutes from 'hooks/useFetchSupportedRoutes';
import useComputeDestinationTokens from 'hooks/useComputeDestinationTokens';
import useComputeSourceTokens from 'hooks/useComputeSourceTokens';
import { useSortedRoutesWithQuotes } from 'hooks/useSortedRoutesWithQuotes';
import { useAmountValidation } from 'hooks/useAmountValidation';
import useConfirmTransaction from 'hooks/useConfirmTransaction';
Expand Down Expand Up @@ -128,7 +127,6 @@ const Bridge = () => {
toChain: destChain,
route,
preferredRouteName,
supportedSourceTokens,
amount,
validations,
isTransactionInProgress,
Expand All @@ -144,16 +142,6 @@ const Bridge = () => {
isFetching: isFetchingQuotes,
} = useSortedRoutesWithQuotes();

// Compute and set source tokens
const { isFetching: isFetchingSupportedSourceTokens } =
useComputeSourceTokens({
sourceChain,
destChain,
sourceToken,
destToken,
route,
});

// Compute and set destination tokens
const { isFetching: isFetchingSupportedDestTokens, supportedDestTokens } =
useComputeDestinationTokens({
Expand Down Expand Up @@ -311,9 +299,6 @@ const Bridge = () => {
chainList={supportedSourceChains}
token={sourceToken}
tokenList={sourceTokens}
isFetching={
sourceTokens.length === 0 && isFetchingSupportedSourceTokens
}
setChain={(value: Chain) => {
selectFromChain(dispatch, value, sendingWallet);
}}
Expand All @@ -335,8 +320,6 @@ const Bridge = () => {
sourceToken,
sourceTokens,
lastTokenCacheUpdate,
supportedSourceTokens,
isFetchingSupportedSourceTokens,
isTransactionInProgress,
sendingWallet,
dispatch,
Expand Down Expand Up @@ -594,7 +577,7 @@ const Bridge = () => {
{destAssetPicker}
<AmountInput
sourceChain={sourceChain}
supportedSourceTokens={config.tokens.getList(supportedSourceTokens)}
supportedSourceTokens={sourceTokens}
tokenBalance={sourceToken ? balances[sourceToken.key]?.balance : null}
isFetchingTokenBalance={isFetchingBalances}
error={amountValidation.error}
Expand Down
Loading