Skip to content

Commit

Permalink
CCTP routes: Ensure source token is USDC (#555)
Browse files Browse the repository at this point in the history
* ensure source token is USDC

* use isSameToken
  • Loading branch information
artursapek authored May 16, 2024
1 parent 9a2ef36 commit 68ceb49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
23 changes: 17 additions & 6 deletions connect/src/routes/cctp/automatic.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Chain, Network } from "@wormhole-foundation/sdk-base";
import { amount, circle, contracts } from "@wormhole-foundation/sdk-base";
import type {
ChainAddress,
ChainContext,
CircleTransferDetails,
Signer,
TokenId,
import {
isSameToken,
type ChainAddress,
type ChainContext,
type CircleTransferDetails,
type Signer,
type TokenId,
} from "@wormhole-foundation/sdk-definitions";
import { CircleTransfer } from "../../protocols/cctp/cctpTransfer.js";
import { TransferState } from "../../types.js";
Expand Down Expand Up @@ -85,6 +86,16 @@ export class AutomaticCCTPRoute<N extends Network>
fromChain: ChainContext<N>,
toChain: ChainContext<N>,
): Promise<TokenId[]> {
// Ensure the source token is USDC
const sourceChainUsdcContract = circle.usdcContract.get(fromChain.network, fromChain.chain);
if (!sourceChainUsdcContract ) return [];
if (!isSameToken(
sourceToken,
Wormhole.tokenId(fromChain.chain, sourceChainUsdcContract),
)){
return [];
}

const { network, chain } = toChain;
if (!circle.usdcContract.has(network, chain)) return [];
return [Wormhole.chainAddress(chain, circle.usdcContract.get(network, chain)!)];
Expand Down
12 changes: 11 additions & 1 deletion connect/src/routes/cctp/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
Signer,
TokenId,
} from "@wormhole-foundation/sdk-definitions";
import { CircleBridge } from "@wormhole-foundation/sdk-definitions";
import { CircleBridge, isSameToken } from "@wormhole-foundation/sdk-definitions";
import { signSendWait } from "../../common.js";
import { CircleTransfer } from "../../protocols/cctp/cctpTransfer.js";
import type { TransferReceipt } from "../../types.js";
Expand Down Expand Up @@ -79,6 +79,16 @@ export class CCTPRoute<N extends Network>
fromChain: ChainContext<N>,
toChain: ChainContext<N>,
): Promise<TokenId[]> {
// Ensure the source token is USDC
const sourceChainUsdcContract = circle.usdcContract.get(fromChain.network, fromChain.chain);
if (!sourceChainUsdcContract ) return [];
if (!isSameToken(
sourceToken,
Wormhole.tokenId(fromChain.chain, sourceChainUsdcContract),
)){
return [];
}

const { network, chain } = toChain;
if (!circle.usdcContract.has(network, chain)) return [];
return [Wormhole.chainAddress(chain, circle.usdcContract.get(network, chain)!)];
Expand Down

0 comments on commit 68ceb49

Please sign in to comment.