Skip to content

Commit

Permalink
Sui CCTP support (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
artursapek authored Oct 28, 2024
1 parent b44cd1a commit 8d3a680
Show file tree
Hide file tree
Showing 16 changed files with 435 additions and 8 deletions.
4 changes: 4 additions & 0 deletions core/base/src/constants/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const usdcContracts = [[
["Solana", "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"],
["Base", "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"],
["Polygon", "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359"],
["Sui", "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"],
]], [
"Testnet", [
["Sepolia", "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"],
Expand All @@ -28,6 +29,7 @@ const usdcContracts = [[
["Solana", "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"],
["BaseSepolia", "0x036CbD53842c5426634e7929541eC2318f3dCF7e"],
["Polygon", "0x9999f7fea5938fd3b1e26a12c3f2fb024e194f97"],
["Sui", "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC"],
]],
] as const satisfies MapLevel<Network, MapLevel<Chain, string>>;
export const usdcContract = constMap(usdcContracts);
Expand All @@ -43,6 +45,7 @@ const circleDomains = [[
["Solana", 5],
["Base", 6],
["Polygon", 7],
["Sui", 8],
]], [
"Testnet", [
["Sepolia", 0],
Expand All @@ -52,6 +55,7 @@ const circleDomains = [[
["Solana", 5],
["BaseSepolia", 6],
["Polygon", 7],
["Sui", 8],
]],
] as const satisfies MapLevel<Network, MapLevel<Chain, number>>;

Expand Down
12 changes: 12 additions & 0 deletions core/base/src/constants/contracts/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export const circleContracts = [[
messageTransmitter: "0xF3be9355363857F3e001be68856A2f96b4C39Ba9",
wormholeRelayer: "0x4cb69FaE7e7Af841e44E1A1c30Af640739378bb2",
wormhole: "0x0FF28217dCc90372345954563486528aa865cDd6",
}], [
"Sui", {
tokenMessenger: "0x410d70c8baad60f310f45c13b9656ecbfed46fdf970e051f0cac42891a848856",
messageTransmitter: "0x34c884874be4cb4b84e79fa280d7b041f186f4d1ef08be1dc74b20e94376951a",
wormholeRelayer: "",
wormhole: "",
}],
]], [
"Testnet", [[
Expand Down Expand Up @@ -97,6 +103,12 @@ export const circleContracts = [[
messageTransmitter: "0xe09A679F56207EF33F5b9d8fb4499Ec00792eA73",
wormholeRelayer: "0x4cb69FaE7e7Af841e44E1A1c30Af640739378bb2",
wormhole: "0x2703483B1a5a7c577e8680de9Df8Be03c6f30e3c",
}], [
"Sui", {
tokenMessenger: "0x4e16078afc5ebfc244a8107ded4044970df5d84db384e7194b7fc444090683fd",
messageTransmitter: "0x4741a96a5903c80613f2d013492a47741cf10c6246ea38a724d354a09895cf8f",
wormholeRelayer: "",
wormhole: "",
}],
]],
] as const satisfies MapLevels<[Network, Chain, CircleContracts]>;
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@
"dependencies": {
"@wormhole-foundation/sdk": "0.12.0"
}
}
}
21 changes: 17 additions & 4 deletions examples/src/cctp.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { Network, Signer, TransactionId, Wormhole } from "@wormhole-foundation/sdk";
import { CircleTransfer, amount, wormhole } from "@wormhole-foundation/sdk";
import { CircleTransfer, TransferState, amount, wormhole } from "@wormhole-foundation/sdk";
import evm from "@wormhole-foundation/sdk/evm";
import solana from "@wormhole-foundation/sdk/solana";
import sui from "@wormhole-foundation/sdk/sui";
import type { SignerStuff } from "./helpers/index.js";
import { getSigner } from "./helpers/index.js";

Expand All @@ -16,19 +17,19 @@ AutoRelayer takes a 0.1usdc fee when xfering to any chain beside goerli, which i
(async function () {
// init Wormhole object, passing config for which network
// to use (e.g. Mainnet/Testnet) and what Platforms to support
const wh = await wormhole("Testnet", [evm, solana]);
const wh = await wormhole("Testnet", [evm, solana, sui]);

// Grab chain Contexts
const sendChain = wh.getChain("Avalanche");
const rcvChain = wh.getChain("Solana");
const rcvChain = wh.getChain("Sui");

// Get signer from local key but anything that implements
// Signer interface (e.g. wrapper around web wallet) should work
const source = await getSigner(sendChain);
const destination = await getSigner(rcvChain);

// 6 decimals for USDC (except for bsc, so check decimals before using this)
const amt = amount.units(amount.parse("0.2", 6));
const amt = amount.units(amount.parse("0.01", 6));

// Choose whether or not to have the attestation delivered for you
const automatic = false;
Expand Down Expand Up @@ -105,6 +106,18 @@ async function cctpTransfer<N extends Network>(
console.log("Completing Transfer");
const dstTxids = await xfer.completeTransfer(dst.signer);
console.log(`Completed Transfer: `, dstTxids);

console.log("Tracking Transfer Progress");
let receipt = CircleTransfer.getReceipt(xfer);

for await (receipt of CircleTransfer.track(wh, receipt)) {
console.log("Receipt State:", receipt.state);
if (receipt.state === TransferState.DestinationFinalized) {
console.log("Transfer Confirmed Complete");
break;
}
}

// EXAMPLE_CCTP_TRANSFER
}

Expand Down
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"platforms/sui",
"platforms/sui/protocols/core",
"platforms/sui/protocols/tokenBridge",
"platforms/sui/protocols/cctp",
"platforms/aptos",
"platforms/aptos/protocols/core",
"platforms/aptos/protocols/tokenBridge",
Expand All @@ -67,4 +68,4 @@
"unreleased": [
"tokenRegistry"
]
}
}
2 changes: 1 addition & 1 deletion platforms/evm/protocols/cctp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@
}
}
}
}
}
75 changes: 75 additions & 0 deletions platforms/sui/protocols/cctp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"name": "@wormhole-foundation/sdk-sui-cctp",
"version": "0.12.0",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/wormhole-sdk-ts.git"
},
"bugs": {
"url": "https://github.com/wormhole-foundation/wormhole-sdk-ts/issues"
},
"homepage": "https://github.com/wormhole-foundation/wormhole-sdk-ts#readme",
"directories": {
"test": "tests"
},
"license": "Apache-2.0",
"main": "./dist/cjs/index.js",
"types": "./dist/cjs/index.d.ts",
"module": "./dist/esm/index.js",
"description": "SDK for Sui chains, used in conjunction with @wormhole-foundation/sdk",
"files": [
"dist/esm",
"dist/cjs"
],
"keywords": [
"wormhole",
"sdk",
"typescript",
"connect",
"sui"
],
"engines": {
"node": ">=16"
},
"sideEffects": [
"./dist/cjs/index.js",
"./dist/esm/index.js"
],
"scripts": {
"build:cjs": "tsc -p ./tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
"build:esm": "tsc -p ./tsconfig.esm.json",
"build": "npm run build:esm && npm run build:cjs",
"rebuild": "npm run clean && npm run build",
"clean": "rm -rf ./dist && rm -rf ./.turbo",
"lint": "npm run prettier && eslint --fix ./src --ext .ts",
"prettier": "prettier --write ./src"
},
"dependencies": {
"@mysten/sui.js": "^0.50.1",
"@wormhole-foundation/sdk-connect": "0.12.0",
"@wormhole-foundation/sdk-sui": "0.12.0"
},
"type": "module",
"exports": {
".": {
"react-native": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
},
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
},
"default": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
}
}
}
Loading

0 comments on commit 8d3a680

Please sign in to comment.