From 9a828103dd44589ca0e7f14950fa129c3433a8c0 Mon Sep 17 00:00:00 2001 From: Lim Jet <57783762+daoauth@users.noreply.github.com> Date: Tue, 27 Aug 2024 19:12:46 +0900 Subject: [PATCH 1/4] run prettier --- connect/src/protocols/cctp/cctpTransfer.ts | 3 ++- connect/src/protocols/tokenBridge/tokenTransfer.ts | 8 +++++++- connect/src/routes/route.ts | 5 ++++- connect/src/routes/tokenBridge/manual.ts | 2 +- core/definitions/src/testing/mocks/guardian.ts | 10 ++-------- core/icons/src/constants/chainIcons.ts | 2 +- sdk/src/index.ts | 6 ++---- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/connect/src/protocols/cctp/cctpTransfer.ts b/connect/src/protocols/cctp/cctpTransfer.ts index 63f3d7533..a34ea58d6 100644 --- a/connect/src/protocols/cctp/cctpTransfer.ts +++ b/connect/src/protocols/cctp/cctpTransfer.ts @@ -592,7 +592,8 @@ export namespace CircleTransfer { // https://developers.circle.com/stablecoins/docs/required-block-confirmations const eta = - (srcChain.chain === "Polygon" ? 2_000 * 200 : finality.estimateFinalityTime(srcChain.chain)) + guardians.guardianAttestationEta; + (srcChain.chain === "Polygon" ? 2_000 * 200 : finality.estimateFinalityTime(srcChain.chain)) + + guardians.guardianAttestationEta; if (!transfer.automatic) { return { sourceToken: { token: srcToken, amount: transfer.amount }, diff --git a/connect/src/protocols/tokenBridge/tokenTransfer.ts b/connect/src/protocols/tokenBridge/tokenTransfer.ts index 0677dd513..17f9069d1 100644 --- a/connect/src/protocols/tokenBridge/tokenTransfer.ts +++ b/connect/src/protocols/tokenBridge/tokenTransfer.ts @@ -1,5 +1,11 @@ import type { Chain, Network } from "@wormhole-foundation/sdk-base"; -import { amount, encoding, finality, guardians, toChain as toChainName } from "@wormhole-foundation/sdk-base"; +import { + amount, + encoding, + finality, + guardians, + toChain as toChainName, +} from "@wormhole-foundation/sdk-base"; import type { AttestationId, AutomaticTokenBridge, diff --git a/connect/src/routes/route.ts b/connect/src/routes/route.ts index 04528f075..9070056d4 100644 --- a/connect/src/routes/route.ts +++ b/connect/src/routes/route.ts @@ -118,7 +118,10 @@ export abstract class AutomaticRoute< } export function isAutomatic(route: Route): route is AutomaticRoute { - return (route as AutomaticRoute).isAvailable !== undefined && (route.constructor as RouteConstructor).IS_AUTOMATIC; + return ( + (route as AutomaticRoute).isAvailable !== undefined && + (route.constructor as RouteConstructor).IS_AUTOMATIC + ); } /** diff --git a/connect/src/routes/tokenBridge/manual.ts b/connect/src/routes/tokenBridge/manual.ts index 672ad5280..e5c7134cc 100644 --- a/connect/src/routes/tokenBridge/manual.ts +++ b/connect/src/routes/tokenBridge/manual.ts @@ -169,7 +169,7 @@ export class TokenBridgeRoute destinationTxs: dstTxIds, }; } - + async resume(txid: TransactionId): Promise { const xfer = await TokenTransfer.from(this.wh, txid, 10 * 1000); return TokenTransfer.getReceipt(xfer); diff --git a/core/definitions/src/testing/mocks/guardian.ts b/core/definitions/src/testing/mocks/guardian.ts index 9d8e93bb3..da0e01019 100644 --- a/core/definitions/src/testing/mocks/guardian.ts +++ b/core/definitions/src/testing/mocks/guardian.ts @@ -1,13 +1,7 @@ -import type { Chain} from "@wormhole-foundation/sdk-base"; +import type { Chain } from "@wormhole-foundation/sdk-base"; import { guardians } from "@wormhole-foundation/sdk-base"; import type { PayloadLiteral, VAA } from "../../index.js"; -import { - Signature, - SignatureUtils, - createVAA, - deserialize, - serialize, -} from "../../index.js"; +import { Signature, SignatureUtils, createVAA, deserialize, serialize } from "../../index.js"; import type { UniversalAddress } from "../../universalAddress.js"; import { keccak256 } from "../../utils.js"; diff --git a/core/icons/src/constants/chainIcons.ts b/core/icons/src/constants/chainIcons.ts index cce58c355..c85261a60 100644 --- a/core/icons/src/constants/chainIcons.ts +++ b/core/icons/src/constants/chainIcons.ts @@ -1,6 +1,6 @@ // THIS FILE IS AUTO-GENERATED WITH `npm run gen` -import { Chain } from "@wormhole-foundation/sdk-base"; +import type { Chain } from "@wormhole-foundation/sdk-base"; const PREFIX = "data:image/svg+xml;base64,"; diff --git a/sdk/src/index.ts b/sdk/src/index.ts index 16e0d49db..93854392e 100644 --- a/sdk/src/index.ts +++ b/sdk/src/index.ts @@ -4,16 +4,14 @@ import type { Platform, ProtocolName, ChainConfigOverrides, - ChainContext, NativeAddressCtr, PlatformToChains, PlatformUtils, RpcConnection, - Signer} from "@wormhole-foundation/sdk-connect"; -import { - Wormhole, + Signer, } from "@wormhole-foundation/sdk-connect"; +import { Wormhole } from "@wormhole-foundation/sdk-connect"; /** * PlatformDefinition is a type that contains the types necessary to From 10ef944312740b314f9469b44c1dc54271e44309 Mon Sep 17 00:00:00 2001 From: Lim Jet <57783762+daoauth@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:23:25 +0900 Subject: [PATCH 2/4] update sui package --- package-lock.json | 225 ++++++++++++++---- platforms/sui/__tests__/unit/platform.test.ts | 2 +- platforms/sui/package.json | 6 +- platforms/sui/protocols/core/package.json | 4 +- platforms/sui/protocols/core/src/core.ts | 2 +- .../sui/protocols/tokenBridge/package.json | 4 +- .../tokenBridge/src/automaticTokenBridge.ts | 39 +-- .../protocols/tokenBridge/src/tokenBridge.ts | 44 ++-- .../sui/protocols/tokenBridge/src/utils.ts | 2 +- platforms/sui/src/address.ts | 2 +- platforms/sui/src/platform.ts | 5 +- platforms/sui/src/signer.ts | 8 +- platforms/sui/src/types.ts | 6 +- platforms/sui/src/unsignedTransaction.ts | 4 +- platforms/sui/src/utils.ts | 22 +- 15 files changed, 253 insertions(+), 122 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1c377f015..878e0f27e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -134,7 +134,9 @@ } }, "node_modules/@0no-co/graphql.web": { - "version": "1.0.4", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@0no-co/graphql.web/-/graphql.web-1.0.8.tgz", + "integrity": "sha512-8BG6woLtDMvXB9Ajb/uE+Zr/U7y4qJ3upXi0JQHZmsKUJa7HjF/gFvmL2f3/mSmfZoQGRr9VoY97LCX2uaFMzA==", "license": "MIT", "peerDependencies": { "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" @@ -145,6 +147,20 @@ } } }, + "node_modules/@0no-co/graphqlsp": { + "version": "1.12.13", + "resolved": "https://registry.npmjs.org/@0no-co/graphqlsp/-/graphqlsp-1.12.13.tgz", + "integrity": "sha512-/C9yXft+mq+VdoniBgWvA+iK5X6cB50KKThg1je4bFIhhBNccLJlNbWFxOglXseKuisq+h5oIY4ELTVKs6GhRQ==", + "license": "MIT", + "dependencies": { + "@gql.tada/internal": "^1.0.0", + "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0" + }, + "peerDependencies": { + "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0", + "typescript": "^5.0.0" + } + }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "dev": true, @@ -1163,6 +1179,45 @@ } ] }, + "node_modules/@gql.tada/cli-utils": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@gql.tada/cli-utils/-/cli-utils-1.6.1.tgz", + "integrity": "sha512-ZfYa5+rbK51c6ociTUL66qW1lyB9dXoAKNZMEAp2pWgPp16qZVBwopUaYxSKq4BML9eSiv0ocoJ7H6VW51ud7w==", + "license": "MIT", + "dependencies": { + "@0no-co/graphqlsp": "^1.12.13", + "@gql.tada/internal": "1.0.7", + "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0" + }, + "peerDependencies": { + "@0no-co/graphqlsp": "^1.12.13", + "@gql.tada/svelte-support": "1.0.1", + "@gql.tada/vue-support": "1.0.1", + "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0", + "typescript": "^5.0.0" + }, + "peerDependenciesMeta": { + "@gql.tada/svelte-support": { + "optional": true + }, + "@gql.tada/vue-support": { + "optional": true + } + } + }, + "node_modules/@gql.tada/internal": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@gql.tada/internal/-/internal-1.0.7.tgz", + "integrity": "sha512-mI/7l7If7YR4rBlgnkXihh1qxD7eO41o8nf5ZYjwYl4s6FGFQFZY1E1reV3AgRy8tDXbiuMz1bIVLpnxPXxKIQ==", + "license": "MIT", + "dependencies": { + "@0no-co/graphql.web": "^1.0.5" + }, + "peerDependencies": { + "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0", + "typescript": "^5.0.0" + } + }, "node_modules/@graphql-typed-document-node/core": { "version": "3.2.0", "license": "MIT", @@ -1993,54 +2048,81 @@ "rlp": "^2.2.3" } }, - "node_modules/@mysten/bcs": { - "version": "0.11.1", + "node_modules/@mysten/sui": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@mysten/sui/-/sui-1.7.0.tgz", + "integrity": "sha512-g88beCeYH7WVZbNW541j+Vusdxn1yd9X9TiQ8kGHbXKNIPFmc0Pf26kPwlAVnCbXslFflUgN6q4CWpAsBUIA3A==", "license": "Apache-2.0", "dependencies": { - "bs58": "^5.0.0" + "@graphql-typed-document-node/core": "^3.2.0", + "@mysten/bcs": "1.0.4", + "@noble/curves": "^1.4.2", + "@noble/hashes": "^1.4.0", + "@scure/bip32": "^1.4.0", + "@scure/bip39": "^1.3.0", + "@suchipi/femver": "^1.0.0", + "bech32": "^2.0.0", + "gql.tada": "^1.8.2", + "graphql": "^16.9.0", + "tweetnacl": "^1.0.3", + "valibot": "^0.36.0" + }, + "engines": { + "node": ">=18" } }, - "node_modules/@mysten/bcs/node_modules/base-x": { - "version": "4.0.0", - "license": "MIT" - }, - "node_modules/@mysten/bcs/node_modules/bs58": { - "version": "5.0.0", - "license": "MIT", + "node_modules/@mysten/sui/node_modules/@mysten/bcs": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@mysten/bcs/-/bcs-1.0.4.tgz", + "integrity": "sha512-6JoQi59GN/dVEBCNq8Rj4uOR0niDrJqDx/2gNQWXANwJakHIGH0AMniHrXP41B2dF+mZ3HVmh9Hi3otiEVQTrQ==", + "license": "Apache-2.0", "dependencies": { - "base-x": "^4.0.0" + "bs58": "^6.0.0" } }, - "node_modules/@mysten/sui.js": { - "version": "0.50.1", - "license": "Apache-2.0", + "node_modules/@mysten/sui/node_modules/@noble/curves": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.5.0.tgz", + "integrity": "sha512-J5EKamIHnKPyClwVrzmaf5wSdQXgdHcPZIZLu3bwnbeCx8/7NPK5q2ZBWF+5FvYGByjiQQsJYX6jfgB2wDPn3A==", + "license": "MIT", "dependencies": { - "@graphql-typed-document-node/core": "^3.2.0", - "@mysten/bcs": "0.11.1", - "@noble/curves": "^1.1.0", - "@noble/hashes": "^1.3.1", - "@scure/bip32": "^1.3.1", - "@scure/bip39": "^1.2.1", - "@suchipi/femver": "^1.0.0", - "bech32": "^2.0.0", - "gql.tada": "^1.2.0", - "graphql": "^16.8.1", - "superstruct": "^1.0.3", - "tweetnacl": "^1.0.3" + "@noble/hashes": "1.4.0" }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@mysten/sui/node_modules/@noble/hashes": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.4.0.tgz", + "integrity": "sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==", + "license": "MIT", "engines": { - "node": ">=16" + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" } }, - "node_modules/@mysten/sui.js/node_modules/bech32": { + "node_modules/@mysten/sui/node_modules/base-x": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-5.0.0.tgz", + "integrity": "sha512-sMW3VGSX1QWVFA6l8U62MLKz29rRfpTlYdCqLdpLo1/Yd4zZwSbnUaDfciIAowAqvq7YFnWq9hrhdg1KYgc1lQ==", + "license": "MIT" + }, + "node_modules/@mysten/sui/node_modules/bech32": { "version": "2.0.0", + "resolved": "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz", + "integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==", "license": "MIT" }, - "node_modules/@mysten/sui.js/node_modules/superstruct": { - "version": "1.0.3", + "node_modules/@mysten/sui/node_modules/bs58": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-6.0.0.tgz", + "integrity": "sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw==", "license": "MIT", - "engines": { - "node": ">=14.0.0" + "dependencies": { + "base-x": "^5.0.0" } }, "node_modules/@noble/curves": { @@ -2140,36 +2222,44 @@ "license": "BSD-3-Clause" }, "node_modules/@scure/base": { - "version": "1.1.5", + "version": "1.1.7", + "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.7.tgz", + "integrity": "sha512-PPNYBslrLNNUQ/Yad37MHYsNQtK67EhWb6WtSvNLLPo7SdVZgkUjD6Dg+5On7zNwmskf8OX7I7Nx5oN+MIWE0g==", "license": "MIT", "funding": { "url": "https://paulmillr.com/funding/" } }, "node_modules/@scure/bip32": { - "version": "1.3.3", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.4.0.tgz", + "integrity": "sha512-sVUpc0Vq3tXCkDGYVWGIZTRfnvu8LoTDaev7vbwh0omSvVORONr960MQWdKqJDCReIEmTj3PAr73O3aoxz7OPg==", "license": "MIT", "dependencies": { - "@noble/curves": "~1.3.0", - "@noble/hashes": "~1.3.2", - "@scure/base": "~1.1.4" + "@noble/curves": "~1.4.0", + "@noble/hashes": "~1.4.0", + "@scure/base": "~1.1.6" }, "funding": { "url": "https://paulmillr.com/funding/" } }, "node_modules/@scure/bip32/node_modules/@noble/curves": { - "version": "1.3.0", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.4.2.tgz", + "integrity": "sha512-TavHr8qycMChk8UwMld0ZDRvatedkzWfH8IiaeGCfymOP5i0hSCozz9vHOL0nkwk7HRMlFnAiKpS2jrUmSybcw==", "license": "MIT", "dependencies": { - "@noble/hashes": "1.3.3" + "@noble/hashes": "1.4.0" }, "funding": { "url": "https://paulmillr.com/funding/" } }, "node_modules/@scure/bip32/node_modules/@noble/hashes": { - "version": "1.3.3", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.4.0.tgz", + "integrity": "sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==", "license": "MIT", "engines": { "node": ">= 16" @@ -2179,11 +2269,25 @@ } }, "node_modules/@scure/bip39": { - "version": "1.2.2", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.3.0.tgz", + "integrity": "sha512-disdg7gHuTDZtY+ZdkmLpPCk7fxZSu3gBiEGuoC1XYxv9cGx3Z6cpTggCgW6odSOOIXCiDjuGejW+aJKCY/pIQ==", "license": "MIT", "dependencies": { - "@noble/hashes": "~1.3.2", - "@scure/base": "~1.1.4" + "@noble/hashes": "~1.4.0", + "@scure/base": "~1.1.6" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@scure/bip39/node_modules/@noble/hashes": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.4.0.tgz", + "integrity": "sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==", + "license": "MIT", + "engines": { + "node": ">= 16" }, "funding": { "url": "https://paulmillr.com/funding/" @@ -5041,10 +5145,22 @@ } }, "node_modules/gql.tada": { - "version": "1.2.1", + "version": "1.8.6", + "resolved": "https://registry.npmjs.org/gql.tada/-/gql.tada-1.8.6.tgz", + "integrity": "sha512-XyN/BkZVEJ5kxgK8oDjHluLwXBLdlUO6P4+u/AmYfknFDj5M5AnaZMm3pntMDO9tpaaEczy9pfXDEJ6tYuTlyA==", "license": "MIT", "dependencies": { - "@0no-co/graphql.web": "^1.0.4" + "@0no-co/graphql.web": "^1.0.5", + "@0no-co/graphqlsp": "^1.12.13", + "@gql.tada/cli-utils": "1.6.1", + "@gql.tada/internal": "1.0.7" + }, + "bin": { + "gql-tada": "bin/cli.js", + "gql.tada": "bin/cli.js" + }, + "peerDependencies": { + "typescript": "^5.0.0" } }, "node_modules/graceful-fs": { @@ -5058,7 +5174,9 @@ "license": "MIT" }, "node_modules/graphql": { - "version": "16.8.1", + "version": "16.9.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.9.0.tgz", + "integrity": "sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==", "license": "MIT", "engines": { "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" @@ -8651,7 +8769,6 @@ }, "node_modules/typescript": { "version": "5.4.5", - "dev": true, "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", @@ -8740,6 +8857,12 @@ "node": ">=10.12.0" } }, + "node_modules/valibot": { + "version": "0.36.0", + "resolved": "https://registry.npmjs.org/valibot/-/valibot-0.36.0.tgz", + "integrity": "sha512-CjF1XN4sUce8sBK9TixrDqFM7RwNkuXdJu174/AwmQUB62QbCQADg5lLe8ldBalFgtj1uKj+pKwDJiNo4Mn+eQ==", + "license": "MIT" + }, "node_modules/validate-npm-package-license": { "version": "3.0.4", "dev": true, @@ -9245,7 +9368,7 @@ "version": "0.10.2", "license": "Apache-2.0", "dependencies": { - "@mysten/sui.js": "^0.50.1", + "@mysten/sui": "^1.7.0", "@wormhole-foundation/sdk-connect": "0.10.2" }, "engines": { @@ -9257,7 +9380,7 @@ "version": "0.10.2", "license": "Apache-2.0", "dependencies": { - "@mysten/sui.js": "^0.50.1", + "@mysten/sui": "^1.7.0", "@wormhole-foundation/sdk-connect": "0.10.2", "@wormhole-foundation/sdk-sui": "0.10.2" }, @@ -9270,7 +9393,7 @@ "version": "0.10.2", "license": "Apache-2.0", "dependencies": { - "@mysten/sui.js": "^0.50.1", + "@mysten/sui": "^1.7.0", "@wormhole-foundation/sdk-connect": "0.10.2", "@wormhole-foundation/sdk-sui": "0.10.2", "@wormhole-foundation/sdk-sui-core": "0.10.2" diff --git a/platforms/sui/__tests__/unit/platform.test.ts b/platforms/sui/__tests__/unit/platform.test.ts index abbb73fb5..25a92bef1 100644 --- a/platforms/sui/__tests__/unit/platform.test.ts +++ b/platforms/sui/__tests__/unit/platform.test.ts @@ -6,7 +6,7 @@ import { SuiChains, SuiPlatform } from "./../../src/index.js"; import "@wormhole-foundation/sdk-sui-core"; import "@wormhole-foundation/sdk-sui-tokenbridge"; -import { SuiClient } from "@mysten/sui.js/client"; +import { SuiClient } from "@mysten/sui/client"; const network = DEFAULT_NETWORK; diff --git a/platforms/sui/package.json b/platforms/sui/package.json index ead320e26..3dd387e52 100644 --- a/platforms/sui/package.json +++ b/platforms/sui/package.json @@ -46,8 +46,8 @@ "test": "jest --config ./jest.config.ts" }, "dependencies": { - "@wormhole-foundation/sdk-connect": "0.10.2", - "@mysten/sui.js": "^0.50.1" + "@mysten/sui": "^1.7.0", + "@wormhole-foundation/sdk-connect": "0.10.2" }, "type": "module", "typesVersions": { @@ -99,4 +99,4 @@ } } } -} \ No newline at end of file +} diff --git a/platforms/sui/protocols/core/package.json b/platforms/sui/protocols/core/package.json index baa5b5a32..111c663ae 100644 --- a/platforms/sui/protocols/core/package.json +++ b/platforms/sui/protocols/core/package.json @@ -45,7 +45,7 @@ "prettier": "prettier --write ./src" }, "dependencies": { - "@mysten/sui.js": "^0.50.1", + "@mysten/sui": "^1.7.0", "@wormhole-foundation/sdk-connect": "0.10.2", "@wormhole-foundation/sdk-sui": "0.10.2" }, @@ -72,4 +72,4 @@ } } } -} \ No newline at end of file +} diff --git a/platforms/sui/protocols/core/src/core.ts b/platforms/sui/protocols/core/src/core.ts index 0df054fda..92d79f370 100644 --- a/platforms/sui/protocols/core/src/core.ts +++ b/platforms/sui/protocols/core/src/core.ts @@ -1,4 +1,4 @@ -import type { SuiClient } from "@mysten/sui.js/client"; +import type { SuiClient } from "@mysten/sui/client"; import type { AccountAddress, ChainId, diff --git a/platforms/sui/protocols/tokenBridge/package.json b/platforms/sui/protocols/tokenBridge/package.json index 80e386d3f..a3f75ebb5 100644 --- a/platforms/sui/protocols/tokenBridge/package.json +++ b/platforms/sui/protocols/tokenBridge/package.json @@ -45,7 +45,7 @@ "prettier": "prettier --write ./src" }, "dependencies": { - "@mysten/sui.js": "^0.50.1", + "@mysten/sui": "^1.7.0", "@wormhole-foundation/sdk-connect": "0.10.2", "@wormhole-foundation/sdk-sui": "0.10.2", "@wormhole-foundation/sdk-sui-core": "0.10.2" @@ -73,4 +73,4 @@ } } } -} \ No newline at end of file +} diff --git a/platforms/sui/protocols/tokenBridge/src/automaticTokenBridge.ts b/platforms/sui/protocols/tokenBridge/src/automaticTokenBridge.ts index d49091371..73234395a 100644 --- a/platforms/sui/protocols/tokenBridge/src/automaticTokenBridge.ts +++ b/platforms/sui/protocols/tokenBridge/src/automaticTokenBridge.ts @@ -1,7 +1,6 @@ -import { StructTag } from "@mysten/sui.js/bcs"; -import type { SuiClient } from "@mysten/sui.js/client"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; -import { parseStructTag, SUI_CLOCK_OBJECT_ID } from "@mysten/sui.js/utils"; +import type { SuiClient } from "@mysten/sui/client"; +import { Transaction } from "@mysten/sui/transactions"; +import { parseStructTag, SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils"; import { encoding, isNative, @@ -17,6 +16,7 @@ import { type Platform, type TokenAddress, } from "@wormhole-foundation/sdk-connect"; +import type { SuiChains } from "@wormhole-foundation/sdk-sui"; import { getObjectFields, getPackageId, @@ -26,7 +26,6 @@ import { SUI_COIN, SUI_SEPARATOR, SuiAddress, - SuiChains, SuiPlatform, SuiUnsignedTransaction, uint8ArrayToBCS, @@ -34,6 +33,14 @@ import { import "@wormhole-foundation/sdk-sui-core"; import { getTokenCoinType } from "./utils.js"; +// https://github.com/MystenLabs/sui/blob/0bffebae576c63de6af21ff8ba07705275b24d94/sdk/typescript/src/utils/sui-types.ts#L33 +type StructTag = { + address: string; + module: string; + name: string; + typeParams: (string | StructTag)[]; +}; + export interface TokenInfo { max_native_swap_amount: string; swap_enabled: boolean; @@ -90,12 +97,12 @@ export class SuiAutomaticTokenBridge const { coreBridge: coreBridgePackageId, tokenBridge: tokenBridgePackageId } = await this.getPackageIds(); - const tx = new TransactionBlock(); + const tx = new Transaction(); const feeAmount = BigInt(0); // TODO: wormhole fee - const [feeCoin] = tx.splitCoins(tx.gas, [tx.pure(feeAmount)]); + const [feeCoin] = tx.splitCoins(tx.gas, [tx.pure.u64(feeAmount)]); const [transferCoin] = await (async () => { if (isNative(token)) { - return tx.splitCoins(tx.gas, [tx.pure(amount)]); + return tx.splitCoins(tx.gas, [tx.pure.u64(amount)]); } else { const coins = await SuiPlatform.getCoins(this.connection, sender, coinType); const [primaryCoin, ...mergeCoins] = coins.filter((coin) => coin.coinType === coinType); @@ -109,7 +116,7 @@ export class SuiAutomaticTokenBridge mergeCoins.map((coin) => tx.object(coin.coinObjectId)), ); } - return tx.splitCoins(primaryCoinInput, [tx.pure(amount)]); + return tx.splitCoins(primaryCoinInput, [tx.pure.u64(amount)]); } })(); @@ -168,7 +175,7 @@ export class SuiAutomaticTokenBridge throw new Error("Unable to fetch token coinType"); } - const tx = new TransactionBlock(); + const tx = new Transaction(); const [verifiedVAA] = tx.moveCall({ target: `${coreBridgePackageId}::vaa::parse_and_verify`, arguments: [ @@ -264,13 +271,13 @@ export class SuiAutomaticTokenBridge const packageId = await this.getPackageId(); - const tx = new TransactionBlock(); + const tx = new Transaction(); tx.moveCall({ // Calculates the max number of tokens the recipient can convert to native // Sui. The max amount of native assets the contract will swap with the // recipient is governed by the `max_native_swap_amount` variable. target: `${packageId}::redeem::calculate_max_swap_amount_in`, - arguments: [tx.object(this.tokenBridgeRelayerObjectId), tx.pure(metadata.decimals)], + arguments: [tx.object(this.tokenBridgeRelayerObjectId), tx.pure.u8(metadata.decimals)], typeArguments: [coinType], }); @@ -304,15 +311,15 @@ export class SuiAutomaticTokenBridge const packageId = await this.getPackageId(); - const tx = new TransactionBlock(); + const tx = new Transaction(); tx.moveCall({ // Calculates the amount of native Sui that the recipient will receive // for swapping the `to_native_amount` of tokens. target: `${packageId}::redeem::calculate_native_swap_amount_out`, arguments: [ tx.object(this.tokenBridgeRelayerObjectId), - tx.pure(amount), - tx.pure(metadata.decimals), + tx.pure.u64(amount), + tx.pure.u8(metadata.decimals), ], typeArguments: [coinType], }); @@ -426,7 +433,7 @@ export class SuiAutomaticTokenBridge } private createUnsignedTx( - txReq: TransactionBlock, + txReq: Transaction, description: string, parallelizable: boolean = false, ): SuiUnsignedTransaction { diff --git a/platforms/sui/protocols/tokenBridge/src/tokenBridge.ts b/platforms/sui/protocols/tokenBridge/src/tokenBridge.ts index 14dff4dd2..d53c76281 100644 --- a/platforms/sui/protocols/tokenBridge/src/tokenBridge.ts +++ b/platforms/sui/protocols/tokenBridge/src/tokenBridge.ts @@ -1,6 +1,6 @@ -import type { SuiClient } from "@mysten/sui.js/client"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; -import { SUI_CLOCK_OBJECT_ID, SUI_TYPE_ARG, normalizeSuiObjectId } from "@mysten/sui.js/utils"; +import type { SuiClient } from "@mysten/sui/client"; +import { Transaction } from "@mysten/sui/transactions"; +import { SUI_CLOCK_OBJECT_ID, SUI_TYPE_ARG, normalizeSuiObjectId } from "@mysten/sui/utils"; import type { AccountAddress, @@ -274,13 +274,17 @@ export class SuiTokenBridge implements T const [coreBridgePackageId, tokenBridgePackageId] = await this.getPackageIds(); - const tx = new TransactionBlock(); + const tx = new Transaction(); - const [feeCoin] = tx.splitCoins(tx.gas, [tx.pure(feeAmount)]); + const [feeCoin] = tx.splitCoins(tx.gas, [tx.pure.u64(feeAmount)]); const [messageTicket] = tx.moveCall({ target: `${tokenBridgePackageId}::attest_token::attest_token`, - arguments: [tx.object(this.tokenBridgeObjectId), tx.object(metadata.id!), tx.pure(nonce)], + arguments: [ + tx.object(this.tokenBridgeObjectId), + tx.object(metadata.id!), + tx.pure.u256(nonce.toString()), + ], typeArguments: [coinType], }); @@ -368,7 +372,7 @@ export class SuiTokenBridge implements T const coinType = getCoinTypeFromPackageId(coinPackageId); - const createTx = new TransactionBlock(); + const createTx = new Transaction(); const [txVaa] = createTx.moveCall({ target: `${coreBridgePackageId}::vaa::parse_and_verify`, arguments: [ @@ -420,10 +424,10 @@ export class SuiTokenBridge implements T const [coreBridgePackageId, tokenBridgePackageId] = await this.getPackageIds(); - const tx = new TransactionBlock(); + const tx = new Transaction(); const [transferCoin] = (() => { if (coinType === SUI_TYPE_ARG) { - return tx.splitCoins(tx.gas, [tx.pure(amount)]); + return tx.splitCoins(tx.gas, [tx.pure.u64(amount)]); } else { const primaryCoinInput = tx.object(primaryCoin.coinObjectId); if (mergeCoins.length) { @@ -432,11 +436,11 @@ export class SuiTokenBridge implements T mergeCoins.map((coin) => tx.object(coin.coinObjectId)), ); } - return tx.splitCoins(primaryCoinInput, [tx.pure(amount)]); + return tx.splitCoins(primaryCoinInput, [tx.pure.u64(amount)]); } })(); - const [feeCoin] = tx.splitCoins(tx.gas, [tx.pure(feeAmount)]); + const [feeCoin] = tx.splitCoins(tx.gas, [tx.pure.u64(feeAmount)]); const [assetInfo] = tx.moveCall({ target: `${tokenBridgePackageId}::state::verified_asset`, arguments: [tx.object(this.tokenBridgeObjectId)], @@ -449,10 +453,10 @@ export class SuiTokenBridge implements T arguments: [ assetInfo!, transferCoin!, - tx.pure(toChainId(recipient.chain)), + tx.pure.u16(toChainId(recipient.chain)), tx.pure(uint8ArrayToBCS(recipient.address.toUint8Array())), - tx.pure(relayerFee), - tx.pure(nonce), + tx.pure.u64(relayerFee), + tx.pure.u32(nonce), ], typeArguments: [coinType], }); @@ -509,10 +513,10 @@ export class SuiTokenBridge implements T emitterCap!, assetInfo!, transferCoin!, - tx.pure(toChainId(recipient.chain)), + tx.pure.u16(toChainId(recipient.chain)), tx.pure(recipient.address.toUint8Array()), - tx.pure([...payload!]), - tx.pure(nonce), + tx.pure.vector("u8", [...payload!]), + tx.pure.u32(nonce), ], typeArguments: [coinType], }); @@ -540,7 +544,7 @@ export class SuiTokenBridge implements T }); if (isNewEmitterCap) { - tx.transferObjects([emitterCap!], tx.pure(senderAddress)); + tx.transferObjects([emitterCap!], tx.pure.address(senderAddress)); } yield this.createUnsignedTx(tx, "Sui.TokenBridge.TransferWithPayload"); @@ -564,7 +568,7 @@ export class SuiTokenBridge implements T const [coreBridgePackageId, tokenBridgePackageId] = await this.getPackageIds(); - const tx = new TransactionBlock(); + const tx = new Transaction(); const [verifiedVAA] = tx.moveCall({ target: `${coreBridgePackageId}::vaa::parse_and_verify`, arguments: [ @@ -646,7 +650,7 @@ export class SuiTokenBridge implements T } private createUnsignedTx( - txReq: TransactionBlock, + txReq: Transaction, description: string, parallelizable: boolean = false, ): SuiUnsignedTransaction { diff --git a/platforms/sui/protocols/tokenBridge/src/utils.ts b/platforms/sui/protocols/tokenBridge/src/utils.ts index 268d866f8..f1b27415c 100644 --- a/platforms/sui/protocols/tokenBridge/src/utils.ts +++ b/platforms/sui/protocols/tokenBridge/src/utils.ts @@ -1,4 +1,4 @@ -import type { SuiClient, SuiObjectResponse } from "@mysten/sui.js/client"; +import type { SuiClient, SuiObjectResponse } from "@mysten/sui/client"; import { getFieldsFromObjectResponse, getObjectFields, diff --git a/platforms/sui/src/address.ts b/platforms/sui/src/address.ts index 00ab2fb42..b3c17ae82 100644 --- a/platforms/sui/src/address.ts +++ b/platforms/sui/src/address.ts @@ -1,4 +1,4 @@ -import { normalizeSuiAddress } from "@mysten/sui.js/utils"; +import { normalizeSuiAddress } from "@mysten/sui/utils"; import type { Address } from "@wormhole-foundation/sdk-connect"; import { UniversalAddress, encoding, registerNative } from "@wormhole-foundation/sdk-connect"; diff --git a/platforms/sui/src/platform.ts b/platforms/sui/src/platform.ts index 1d9594638..de3c3aed0 100644 --- a/platforms/sui/src/platform.ts +++ b/platforms/sui/src/platform.ts @@ -18,7 +18,8 @@ import { networkPlatformConfigs, } from "@wormhole-foundation/sdk-connect"; -import { PaginatedCoins, SuiClient } from "@mysten/sui.js/client"; +import type { PaginatedCoins } from "@mysten/sui/client"; +import { SuiClient } from "@mysten/sui/client"; import { SuiAddress } from "./address.js"; import { SuiChain } from "./chain.js"; import { SUI_COIN } from "./constants.js"; @@ -145,7 +146,7 @@ export class SuiPlatform const txhashes = []; for (const stxn of stxns) { const pendingTx = await rpc.executeTransactionBlock(stxn); - await rpc.waitForTransactionBlock({ digest: pendingTx.digest }); + await rpc.waitForTransaction({ digest: pendingTx.digest }); txhashes.push(pendingTx.digest); } return txhashes; diff --git a/platforms/sui/src/signer.ts b/platforms/sui/src/signer.ts index 183f1f6ea..29ac41451 100644 --- a/platforms/sui/src/signer.ts +++ b/platforms/sui/src/signer.ts @@ -1,5 +1,5 @@ -import type { SuiClient } from "@mysten/sui.js/client"; -import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519"; +import type { SuiClient } from "@mysten/sui/client"; +import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"; import type { Network, SignAndSendSigner, @@ -40,8 +40,8 @@ export class SuiSigner implements SignAn if (this._debug) console.log(`Signing ${description} for ${this.address()}`); try { - const result = await this._client.signAndExecuteTransactionBlock({ - transactionBlock: transaction, + const result = await this._client.signAndExecuteTransaction({ + transaction: transaction, signer: this._signer, }); txids.push(result.digest); diff --git a/platforms/sui/src/types.ts b/platforms/sui/src/types.ts index aef13787c..c341d8cea 100644 --- a/platforms/sui/src/types.ts +++ b/platforms/sui/src/types.ts @@ -1,8 +1,4 @@ -import type { - MoveValue, - SuiObjectResponse, - SuiTransactionBlockResponse, -} from "@mysten/sui.js/client"; +import type { MoveValue, SuiObjectResponse, SuiTransactionBlockResponse } from "@mysten/sui/client"; import type { PlatformToChains, UniversalOrNative } from "@wormhole-foundation/sdk-connect"; import { normalizeSuiType } from "./address.js"; diff --git a/platforms/sui/src/unsignedTransaction.ts b/platforms/sui/src/unsignedTransaction.ts index d103b9d7f..d284e9f82 100644 --- a/platforms/sui/src/unsignedTransaction.ts +++ b/platforms/sui/src/unsignedTransaction.ts @@ -1,4 +1,4 @@ -import type { TransactionBlock } from "@mysten/sui.js/transactions"; +import type { Transaction } from "@mysten/sui/transactions"; import type { Network, UnsignedTransaction } from "@wormhole-foundation/sdk-connect"; import type { SuiChains } from "./types.js"; @@ -6,7 +6,7 @@ export class SuiUnsignedTransaction implements UnsignedTransaction { constructor( - readonly transaction: TransactionBlock, + readonly transaction: Transaction, readonly network: N, readonly chain: C, readonly description: string, diff --git a/platforms/sui/src/utils.ts b/platforms/sui/src/utils.ts index 4811680d3..f6a9fbdd2 100644 --- a/platforms/sui/src/utils.ts +++ b/platforms/sui/src/utils.ts @@ -1,7 +1,7 @@ -import { bcs } from "@mysten/sui.js/bcs"; -import type { PaginatedObjectsResponse, SuiClient } from "@mysten/sui.js/client"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; -import { isValidSuiAddress, normalizeSuiAddress, normalizeSuiObjectId } from "@mysten/sui.js/utils"; +import { bcs } from "@mysten/sui/bcs"; +import type { PaginatedObjectsResponse, SuiClient } from "@mysten/sui/client"; +import { Transaction } from "@mysten/sui/transactions"; +import { isValidSuiAddress, normalizeSuiAddress, normalizeSuiObjectId } from "@mysten/sui/utils"; import { encoding } from "@wormhole-foundation/sdk-connect"; import type { SuiBuildOutput } from "./types.js"; @@ -17,7 +17,7 @@ export const UPGRADE_CAP_TYPE = "0x2::package::UpgradeCap"; const MAX_PURE_ARGUMENT_SIZE = 16 * 1024; export const uint8ArrayToBCS = (arr: Uint8Array) => - bcs.ser("vector", arr, { maxSize: MAX_PURE_ARGUMENT_SIZE }).toBytes(); + bcs.vector(bcs.u8()).serialize(arr, { maxSize: MAX_PURE_ARGUMENT_SIZE }).toBytes(); // // Utils to fetch data from Sui @@ -238,14 +238,14 @@ export const getUpgradeCapObjectId = async ( export const publishPackage = async ( buildOutput: SuiBuildOutput, signerAddress: string, -): Promise => { - const tx = new TransactionBlock(); +): Promise => { + const tx = new Transaction(); const [upgradeCap] = tx.publish({ modules: buildOutput.modules.map((m) => Array.from(encoding.b64.decode(m))), dependencies: buildOutput.dependencies.map((d) => normalizeSuiObjectId(d)), }); // Transfer upgrade capability to recipient - tx.transferObjects([upgradeCap!], tx.pure(signerAddress)); + tx.transferObjects([upgradeCap!], tx.pure.address(signerAddress)); return tx; }; @@ -253,12 +253,12 @@ export const newEmitterCap = ( coreBridgePackageId: string, coreBridgeStateObjectId: string, owner: string, -): TransactionBlock => { - const tx = new TransactionBlock(); +): Transaction => { + const tx = new Transaction(); const [emitterCap] = tx.moveCall({ target: `${coreBridgePackageId}::emitter::new`, arguments: [tx.object(coreBridgeStateObjectId)], }); - tx.transferObjects([emitterCap!], tx.pure(owner)); + tx.transferObjects([emitterCap!], tx.pure.address(owner)); return tx; }; From 83e903976afdb7d539e8af313e71487e1c20ab80 Mon Sep 17 00:00:00 2001 From: Lim Jet <57783762+daoauth@users.noreply.github.com> Date: Wed, 28 Aug 2024 11:13:30 +0900 Subject: [PATCH 3/4] Update helpers.ts --- examples/src/helpers/helpers.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/src/helpers/helpers.ts b/examples/src/helpers/helpers.ts index e973985d4..61d8f502c 100644 --- a/examples/src/helpers/helpers.ts +++ b/examples/src/helpers/helpers.ts @@ -21,6 +21,7 @@ import cosmwasm from "../../../sdk/dist/esm/platforms/cosmwasm.js"; import evm from "../../../sdk/dist/esm/platforms/evm.js"; import solana from "../../../sdk/dist/esm/platforms/solana.js"; import sui from "../../../sdk/dist/esm/platforms/sui.js"; +import aptos from "../../../sdk/dist/esm/platforms/aptos.js"; // Use .env.example as a template for your .env file and populate it with secrets // for funded accounts on the relevant chain+network combos to run the example @@ -87,6 +88,9 @@ export async function getSigner( case "Sui": signer = await sui.getSigner(await chain.getRpc(), getEnv("SUI_PRIVATE_KEY")); break; + case "Aptos": + signer = await aptos.getSigner(await chain.getRpc(), getEnv("APTOS_PRIVATE_KEY")); + break; default: throw new Error("Unrecognized platform: " + platform); } From 8538512540232bdd9ab7562387477d6f32d99934 Mon Sep 17 00:00:00 2001 From: Lim Jet <57783762+daoauth@users.noreply.github.com> Date: Wed, 28 Aug 2024 11:13:35 +0900 Subject: [PATCH 4/4] Update index.ts --- examples/src/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/src/index.ts b/examples/src/index.ts index 290c17ea1..f4767247e 100644 --- a/examples/src/index.ts +++ b/examples/src/index.ts @@ -11,6 +11,10 @@ import solana from "@wormhole-foundation/sdk/solana"; import sui from "@wormhole-foundation/sdk/sui"; import { getSigner } from "./helpers/index.js"; +function delay(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + (async function () { // EXAMPLE_WORMHOLE_INIT const wh = await wormhole("Testnet", [evm, solana, aptos, algorand, cosmwasm, sui]); @@ -59,6 +63,8 @@ import { getSigner } from "./helpers/index.js"; const txids = await signSendWait(ctx, transfer, sender.signer); console.log("Sent: ", txids); + await delay(1000); + // Get the wormhole message id from the transaction const [whm] = await ctx.parseTransaction(txids[txids.length - 1]!.txid); console.log("Wormhole Messages: ", whm);