Skip to content

Commit

Permalink
remove supportedSourceTokens function
Browse files Browse the repository at this point in the history
  • Loading branch information
kev1n-peters committed Jan 14, 2025
1 parent 8a6c265 commit af230b2
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 109 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,15 +639,6 @@ Once created, the resolver can be used to provide a list of input and possible o

<!--EXAMPLE_RESOLVER_LIST_TOKENS-->
```ts
// what tokens are available on the source chain?
const srcTokens = await resolver.supportedSourceTokens(sendChain);
console.log(
"Allowed source tokens: ",
srcTokens.map((t) => canonicalAddress(t)),
);

// Grab the first one for the example
// const sendToken = srcTokens[0]!;
const sendToken = Wormhole.tokenId(sendChain.chain, "native");

// given the send token, what can we possibly get on the destination chain?
Expand Down
4 changes: 0 additions & 4 deletions connect/__tests__/mocks/routes/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ export class AutomaticMockRoute<N extends Network>
static supportedChains(network: Network): Chain[] {
return ["Solana", "Ethereum"];
}
static async supportedSourceTokens(fromChain: ChainContext<Network>): Promise<TokenId[]> {
await delay(250);
return [nativeTokenId(fromChain.chain)];
}
static async supportedDestinationTokens<N extends Network>(
sourceToken: TokenId,
fromChain: ChainContext<N>,
Expand Down
4 changes: 0 additions & 4 deletions connect/__tests__/mocks/routes/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export class ManualMockRoute<N extends Network>
static supportedChains(network: Network): Chain[] {
return ["Solana", "Ethereum"];
}
static async supportedSourceTokens(fromChain: ChainContext<Network>): Promise<TokenId[]> {
await delay(250);
return [nativeTokenId(fromChain.chain)];
}
static async supportedDestinationTokens<N extends Network>(
sourceToken: TokenId,
fromChain: ChainContext<N>,
Expand Down
7 changes: 0 additions & 7 deletions connect/src/routes/cctp/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ export class AutomaticCCTPRoute<N extends Network>
return [];
}

// get the list of source tokens that are possible to send
static async supportedSourceTokens(fromChain: ChainContext<Network>): Promise<TokenId[]> {
const { network, chain } = fromChain;
if (!circle.usdcContract.has(network, chain)) return [];
return [Wormhole.chainAddress(chain, circle.usdcContract.get(network, chain)!)];
}

// get the list of destination tokens that may be received on the destination chain
static async supportedDestinationTokens<N extends Network>(
sourceToken: TokenId,
Expand Down
7 changes: 0 additions & 7 deletions connect/src/routes/cctp/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ export class CCTPRoute<N extends Network>
return [];
}

// get the list of source tokens that are possible to send
static async supportedSourceTokens(fromChain: ChainContext<Network>): Promise<TokenId[]> {
const { network, chain } = fromChain;
if (!circle.usdcContract.has(network, chain)) return [];
return [Wormhole.chainAddress(chain, circle.usdcContract.get(network, chain)!)];
}

// get the list of destination tokens that may be received on the destination chain
static async supportedDestinationTokens<N extends Network>(
sourceToken: TokenId,
Expand Down
21 changes: 10 additions & 11 deletions connect/src/routes/portico/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,6 @@ export class AutomaticPorticoRoute<N extends Network>
return [];
}

static async supportedSourceTokens(fromChain: ChainContext<Network>): Promise<TokenId[]> {
const pb = await fromChain.getPorticoBridge();
const { tokenMap } = fromChain.config;
return pb
.supportedTokens()
.filter((t) => !tokenMap || filters.byAddress(tokenMap, canonicalAddress(t.token)))
.map((t) => t.token);
}

static async supportedDestinationTokens<N extends Network>(
sourceToken: TokenId,
fromChain: ChainContext<N>,
Expand All @@ -113,6 +104,10 @@ export class AutomaticPorticoRoute<N extends Network>
const tokenAddress = canonicalAddress(srcTokenAddress);

const pb = await fromChain.getPorticoBridge();
// Make sure the source token is supported
if (!pb.supportedTokens().some((t) => canonicalAddress(t.token) === tokenAddress)) {
return [];
}

try {
// The highway token that will be used to bridge
Expand Down Expand Up @@ -147,8 +142,12 @@ export class AutomaticPorticoRoute<N extends Network>
async validate(request: RouteTransferRequest<N>, params: TP): Promise<VR> {
try {
if (
!AutomaticPorticoRoute.supportedChains(request.fromChain.network).includes(request.fromChain.chain) ||
!AutomaticPorticoRoute.supportedChains(request.toChain.network).includes(request.toChain.chain)
!AutomaticPorticoRoute.supportedChains(request.fromChain.network).includes(
request.fromChain.chain,
) ||
!AutomaticPorticoRoute.supportedChains(request.toChain.network).includes(
request.toChain.chain,
)
) {
throw new Error("Protocol not supported");
}
Expand Down
34 changes: 6 additions & 28 deletions connect/src/routes/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ export class RouteResolver<N extends Network> {
this.routeConstructors = routeConstructors;
}

async supportedSourceTokens(chain: ChainContext<N>): Promise<TokenId[]> {
if (this.inputTokenList) return this.inputTokenList;
const itl = await Promise.all(
this.routeConstructors.map(async (rc) => {
try {
return await rc.supportedSourceTokens(chain);
} catch (e) {
console.error(`Failed to get supported source tokens for ${rc.meta.name}: `, e);
return [];
}
}),
);
this.inputTokenList = uniqueTokens(itl.flat());
return this.inputTokenList!;
}

async supportedDestinationTokens(
inputToken: TokenId,
fromChain: ChainContext<N>,
Expand All @@ -50,7 +34,10 @@ export class RouteResolver<N extends Network> {
}

const supportedChains = rc.supportedChains(fromChain.network);
if (!supportedChains.includes(fromChain.chain) || !supportedChains.includes(toChain.chain)) {
if (
!supportedChains.includes(fromChain.chain) ||
!supportedChains.includes(toChain.chain)
) {
return [];
}

Expand All @@ -72,16 +59,7 @@ export class RouteResolver<N extends Network> {
const protocolSupported =
rc.supportedNetworks().includes(this.wh.network) &&
rc.supportedChains(this.wh.network).includes(request.toChain.chain) &&
rc.supportedChains(this.wh.network).includes(request.fromChain.chain)

const sourceTokenAddress = canonicalAddress(
isNative(request.source.id.address) ? request.source.wrapped! : request.source.id,
);

const sourceTokenSupported =
(await rc.supportedSourceTokens(request.fromChain)).filter((tokenId: TokenId) => {
return canonicalAddress(tokenId) === sourceTokenAddress;
}).length > 0;
rc.supportedChains(this.wh.network).includes(request.fromChain.chain);

const dstTokenAddress = canonicalAddress(
isNative(request.destination.id.address)
Expand All @@ -99,7 +77,7 @@ export class RouteResolver<N extends Network> {
return canonicalAddress(tokenId) === dstTokenAddress;
}).length > 0;

return protocolSupported && sourceTokenSupported && destinationTokenSupported;
return protocolSupported && destinationTokenSupported;
} catch (e) {
return false;
}
Expand Down
2 changes: 0 additions & 2 deletions connect/src/routes/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ export interface RouteConstructor<OP extends Options = Options> {
supportedNetworks(): Network[];
/** get the list of chains this route supports */
supportedChains(network: Network): Chain[];
/** get the list of source tokens that are possible to send */
supportedSourceTokens(fromChain: ChainContext<Network>): Promise<TokenId[]>;
/** get the list of destination tokens that may be received on the destination chain */
supportedDestinationTokens<N extends Network>(
token: TokenId,
Expand Down
24 changes: 10 additions & 14 deletions connect/src/routes/tokenBridge/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
TokenId,
TokenTransferDetails,
} from "@wormhole-foundation/sdk-definitions";
import { isNative, isTokenId, nativeTokenId } from "@wormhole-foundation/sdk-definitions";
import { isNative, isTokenId } from "@wormhole-foundation/sdk-definitions";
import { TokenTransfer } from "../../protocols/tokenBridge/tokenTransfer.js";
import type { AttestationReceipt, SourceInitiatedTransferReceipt } from "../../types.js";
import { TransferState } from "../../types.js";
Expand Down Expand Up @@ -73,25 +73,21 @@ export class AutomaticTokenBridgeRoute<N extends Network>
return [];
}

// get the list of source tokens that are possible to send
static async supportedSourceTokens(fromChain: ChainContext<Network>): Promise<TokenId[]> {
const atb = await fromChain.getAutomaticTokenBridge();
const registered = await atb.getRegisteredTokens();
return [
nativeTokenId(fromChain.chain),
...registered.map((v) => {
return { chain: fromChain.chain, address: v };
}),
];
}

// get the list of destination tokens that may be received on the destination chain
static async supportedDestinationTokens<N extends Network>(
sourceToken: TokenId,
fromChain: ChainContext<N>,
toChain: ChainContext<N>,
): Promise<TokenId[]> {
try {
if (!isNative(sourceToken)) {
const srcAtb = await fromChain.getAutomaticTokenBridge();
const srcIsAccepted = await srcAtb.isRegisteredToken(sourceToken.address);
if (!srcIsAccepted) {
return [];
}
}

const expectedDestinationToken = await TokenTransfer.lookupDestinationToken(
fromChain,
toChain,
Expand All @@ -101,7 +97,7 @@ export class AutomaticTokenBridgeRoute<N extends Network>
const atb = await toChain.getAutomaticTokenBridge();
const acceptable = await atb.isRegisteredToken(expectedDestinationToken.address);
if (!acceptable) {
throw new Error("Destination token is not accepted by the AutomaticTokenBridge");
return [];
}

return [expectedDestinationToken];
Expand Down
8 changes: 0 additions & 8 deletions connect/src/routes/tokenBridge/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ export class TokenBridgeRoute<N extends Network>
return contracts.tokenBridgeChains(network);
}

// get the list of source tokens that are possible to send
static async supportedSourceTokens(fromChain: ChainContext<Network>): Promise<TokenId[]> {
// Default list for the chain
return Object.values(fromChain.config.tokenMap!).map((td) =>
Wormhole.tokenId(td.chain, td.address),
);
}

// get the list of destination tokens that may be received on the destination chain
static async supportedDestinationTokens<N extends Network>(
sourceToken: TokenId,
Expand Down
9 changes: 0 additions & 9 deletions examples/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ import { getSigner } from "./helpers/index.js";
// EXAMPLE_RESOLVER_CREATE

// EXAMPLE_RESOLVER_LIST_TOKENS
// what tokens are available on the source chain?
const srcTokens = await resolver.supportedSourceTokens(sendChain);
console.log(
"Allowed source tokens: ",
srcTokens.map((t) => canonicalAddress(t)),
);

// Grab the first one for the example
// const sendToken = srcTokens[0]!;
const sendToken = Wormhole.tokenId(sendChain.chain, "native");

// given the send token, what can we possibly get on the destination chain?
Expand Down
1 change: 1 addition & 0 deletions platforms/sui/__tests__/integration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json
7 changes: 1 addition & 6 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,7 @@ Once created, the resolver can be used to provide a list of input and possible o

<!--EXAMPLE_RESOLVER_LIST_TOKENS-->
```ts
// what tokens are available on the source chain?
const srcTokens = await resolver.supportedSourceTokens(sendChain);
console.log(
"Allowed source tokens: ",
srcTokens.map((t) => canonicalAddress(t)),
);
const sendToken = Wormhole.tokenId(sendChain, "native");

// given the send token, what can we possibly get on the destination chain?
const destTokens = await resolver.supportedDestinationTokens(sendToken, sendChain, destChain);
Expand Down

0 comments on commit af230b2

Please sign in to comment.