From def6c3336449b4ef3cb73b89020dde69d3893598 Mon Sep 17 00:00:00 2001 From: Ali Behjati Date: Fri, 29 Nov 2024 11:18:50 +0100 Subject: [PATCH] aptos: upgrade to 4.5.0 (libs + toolchain) This change bumps libraries and toolchain of Aptos to the Aptos CLI v4.5.0 version. The tests are slightly changed to accommodate the recent changes in the coin library that disallows coin operations on unitialized coins. --- aptos/Docker.md | 4 +- aptos/Dockerfile | 2 +- aptos/Dockerfile.base | 3 +- aptos/coin/Move.toml | 2 +- aptos/deployer/Move.toml | 2 +- .../core_messages/sources/sender.move | 4 +- aptos/nft_bridge/Move.toml | 8 +- aptos/token_bridge/Move.toml | 8 +- aptos/wormhole/Move.toml | 8 +- aptos/wormhole/sources/wormhole.move | 15 +- clients/js/package-lock.json | 264 +++++++++--------- clients/js/package.json | 2 +- clients/js/src/aptos.ts | 63 ++++- .../js/src/chains/generic/getOriginalAsset.ts | 6 +- .../chains/generic/getWrappedAssetAddress.ts | 2 +- 15 files changed, 240 insertions(+), 153 deletions(-) diff --git a/aptos/Docker.md b/aptos/Docker.md index 5e64f8820b..a2cab12d12 100644 --- a/aptos/Docker.md +++ b/aptos/Docker.md @@ -3,7 +3,7 @@ ```bash -cd .. && docker buildx build --platform linux/amd64,linux/arm64 -f aptos/Dockerfile.base -t ghcr.io/wormhole-foundation/aptos:3.1.0 . +docker buildx build --platform linux/amd64,linux/arm64 -f Dockerfile.base -t ghcr.io/wormhole-foundation/aptos:4.5.0 . ``` @@ -11,5 +11,5 @@ cd .. && docker buildx build --platform linux/amd64,linux/arm64 -f aptos/Dockerf # push to ghcr ```bash -docker push ghcr.io/wormhole-foundation/aptos:3.1.0 +docker push ghcr.io/wormhole-foundation/aptos:4.5.0 ``` diff --git a/aptos/Dockerfile b/aptos/Dockerfile index 8216480f66..85bfba1efa 100644 --- a/aptos/Dockerfile +++ b/aptos/Dockerfile @@ -1,6 +1,6 @@ FROM cli-gen AS cli-export FROM const-gen AS const-export -FROM ghcr.io/wormhole-foundation/aptos:3.1.0@sha256:f66c2b5fea4a75050d051a5260ef643f52f5048d473877f1760be39d9e460d6b AS aptos +FROM ghcr.io/wormhole-foundation/aptos:4.5.0@sha256:27293dfbe0d5a284964c9f72a81d957abddf3b8936c060bccaa54e48db262be4 AS aptos # Install nodejs # todo(aki): move this into base image? diff --git a/aptos/Dockerfile.base b/aptos/Dockerfile.base index 4927bbb58e..41ebd71d1f 100644 --- a/aptos/Dockerfile.base +++ b/aptos/Dockerfile.base @@ -7,8 +7,7 @@ WORKDIR /tmp RUN git clone https://github.com/aptos-labs/aptos-core.git WORKDIR /tmp/aptos-core -# Build aptos 2.0.3 -RUN git reset --hard 6f83bc6d02207298b2dee91133d75538789bf582 +RUN git reset --hard 47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3 RUN cargo build -p aptos --profile cli FROM rust:1.62@sha256:2cd5c8517d0640bd287b2cfb4c0e62f1a8ed86174764d88280bc2a106d6835db AS export-stage diff --git a/aptos/coin/Move.toml b/aptos/coin/Move.toml index 87b0c047b1..7e7a49573a 100644 --- a/aptos/coin/Move.toml +++ b/aptos/coin/Move.toml @@ -4,7 +4,7 @@ version = "0.0.1" upgrade_policy = "compatible" [dependencies] -MoveStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/move-stdlib/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } +MoveStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/move-stdlib/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } [dev-addresses] wrapped_coin = "0xBEEF" diff --git a/aptos/deployer/Move.toml b/aptos/deployer/Move.toml index 31d0c3bb3d..52e42a6b5e 100644 --- a/aptos/deployer/Move.toml +++ b/aptos/deployer/Move.toml @@ -4,7 +4,7 @@ version = '1.0.0' [dependencies.AptosFramework] git = 'https://github.com/aptos-labs/aptos-core.git' -rev = '6f83bc6d02207298b2dee91133d75538789bf582' +rev = '47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3' subdir = 'aptos-move/framework/aptos-framework' [dev-addresses] diff --git a/aptos/examples/core_messages/sources/sender.move b/aptos/examples/core_messages/sources/sender.move index fb0b64844f..cd382f3939 100644 --- a/aptos/examples/core_messages/sources/sender.move +++ b/aptos/examples/core_messages/sources/sender.move @@ -60,6 +60,8 @@ module core_messages::sender_test { public fun test_send_message(aptos_framework: &signer, user: &signer) { let message_fee = 100; timestamp::set_time_has_started_for_testing(aptos_framework); + let (burn_cap, mint_cap) = aptos_coin::initialize_for_test(aptos_framework); + wormhole::init_test( 22, 1, @@ -69,8 +71,6 @@ module core_messages::sender_test { ); sender::init_module_test(); - let (burn_cap, mint_cap) = aptos_coin::initialize_for_test(aptos_framework); - // create user account and airdrop coins account::create_account_for_test(signer::address_of(user)); coin::register(user); diff --git a/aptos/nft_bridge/Move.toml b/aptos/nft_bridge/Move.toml index ef97924d1c..2c1f123020 100644 --- a/aptos/nft_bridge/Move.toml +++ b/aptos/nft_bridge/Move.toml @@ -3,10 +3,10 @@ name = "NFTBridge" version = "0.0.1" [dependencies] -AptosFramework = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-framework/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } -MoveStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/move-stdlib/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } -AptosStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-stdlib/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } -AptosToken = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-token/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } +AptosFramework = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-framework/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } +MoveStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/move-stdlib/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } +AptosStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-stdlib/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } +AptosToken = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-token/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } Wormhole = { local = "../wormhole/" } TokenBridge = { local = "../token_bridge/" } Deployer = { local = "../deployer/" } diff --git a/aptos/token_bridge/Move.toml b/aptos/token_bridge/Move.toml index 0e7e36b3e3..5dc4c280df 100644 --- a/aptos/token_bridge/Move.toml +++ b/aptos/token_bridge/Move.toml @@ -3,10 +3,10 @@ name = "TokenBridge" version = "0.0.1" [dependencies] -AptosFramework = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-framework/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } -MoveStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/move-stdlib/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } -AptosStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-stdlib/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } -AptosToken = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-token/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } +AptosFramework = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-framework/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } +MoveStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/move-stdlib/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } +AptosStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-stdlib/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } +AptosToken = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-token/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } Wormhole = { local = "../wormhole/" } Deployer = { local = "../deployer/" } diff --git a/aptos/wormhole/Move.toml b/aptos/wormhole/Move.toml index 83f24fdc40..05faea5247 100644 --- a/aptos/wormhole/Move.toml +++ b/aptos/wormhole/Move.toml @@ -4,10 +4,10 @@ version = "0.0.1" upgrade_policy = "compatible" [dependencies] -AptosFramework = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-framework/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } -MoveStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/move-stdlib/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } -AptosStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-stdlib/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } -AptosToken = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-token/", rev = "6f83bc6d02207298b2dee91133d75538789bf582" } +AptosFramework = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-framework/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } +MoveStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/move-stdlib/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } +AptosStdlib = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-stdlib/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } +AptosToken = { git = "https://github.com/aptos-labs/aptos-core.git", subdir = "aptos-move/framework/aptos-token/", rev = "47f0bf397eb5ca43257bfa775a6b28e7b7faf8b3" } Deployer = { local = "../deployer/" } # U256 = { git = "https://github.com/pontem-network/u256", rev = "main" } diff --git a/aptos/wormhole/sources/wormhole.move b/aptos/wormhole/sources/wormhole.move index 99c6bb238a..625a019ad3 100644 --- a/aptos/wormhole/sources/wormhole.move +++ b/aptos/wormhole/sources/wormhole.move @@ -128,6 +128,17 @@ module wormhole::wormhole { initial_guardian: vector, message_fee: u64, ): signer { + // Wormhole requires AptosCoin to be initialized; so we iniatilize it + // if it's not initialized already. If you need AptosCoin in the tests + // initialize it before calling this function because AptosCoin can be + // initialized only once. + if (!coin::is_coin_initialized()) { + let aptos_framework = std::account::create_account_for_test(@aptos_framework); + let (burn_cap, mint_cap) = aptos_framework::aptos_coin::initialize_for_test(&aptos_framework); + coin::destroy_mint_cap(mint_cap); + coin::destroy_burn_cap(burn_cap); + }; + let deployer = account::create_account_for_test(@deployer); let (wormhole, signer_cap) = account::create_resource_account(&deployer, b"wormhole"); init_internal( @@ -172,9 +183,9 @@ module wormhole::wormhole_test { #[test(aptos_framework = @aptos_framework)] public fun test_publish_message(aptos_framework: &signer) { - setup(100); - let (burn_cap, mint_cap) = aptos_coin::initialize_for_test(aptos_framework); + + setup(100); let fees = coin::mint(100, &mint_cap); let emitter_cap = wormhole::register_emitter(); diff --git a/clients/js/package-lock.json b/clients/js/package-lock.json index ace0d45e88..897801c2cd 100644 --- a/clients/js/package-lock.json +++ b/clients/js/package-lock.json @@ -25,7 +25,7 @@ "@wormhole-foundation/sdk": "^0.9.0", "@xpla/xpla.js": "^0.2.1", "algosdk": "^2.4.0", - "aptos": "^1.3.16", + "aptos": "1.21.0", "axios": "^0.24.0", "base-64": "^1.0.0", "bech32": "^2.0.0", @@ -834,6 +834,47 @@ "undici-types": "~5.26.4" } }, + "node_modules/@certusone/wormhole-sdk/node_modules/aptos": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/aptos/-/aptos-1.5.0.tgz", + "integrity": "sha512-N7OuRtU7IYHkDkNx+4QS3g/QQGCp+36KzYn3oXPmT7Kttfuv+UKliQVdjy3cLmwd/DCQSh9ObTovwdxnHjUn0g==", + "deprecated": "Package aptos is no longer supported, please migrate to https://www.npmjs.com/package/@aptos-labs/ts-sdk", + "license": "Apache-2.0", + "dependencies": { + "@noble/hashes": "1.1.3", + "@scure/bip39": "1.1.0", + "axios": "0.27.2", + "form-data": "4.0.0", + "tweetnacl": "1.0.3" + }, + "engines": { + "node": ">=11.0.0" + } + }, + "node_modules/@certusone/wormhole-sdk/node_modules/aptos/node_modules/axios": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" + } + }, + "node_modules/@certusone/wormhole-sdk/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/@classic-terra/terra.proto": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@classic-terra/terra.proto/-/terra.proto-1.1.0.tgz", @@ -4683,63 +4724,6 @@ "node": ">=16" } }, - "node_modules/@wormhole-foundation/sdk-aptos/node_modules/@noble/hashes": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", - "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==", - "engines": { - "node": ">= 16" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@wormhole-foundation/sdk-aptos/node_modules/@scure/bip39": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.1.tgz", - "integrity": "sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg==", - "dependencies": { - "@noble/hashes": "~1.3.0", - "@scure/base": "~1.1.0" - }, - "funding": { - "url": "https://paulmillr.com/funding/" - } - }, - "node_modules/@wormhole-foundation/sdk-aptos/node_modules/aptos": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/aptos/-/aptos-1.21.0.tgz", - "integrity": "sha512-PRKjoFgL8tVEc9+oS7eJUv8GNxx8n3+0byH2+m7CP3raYOD6yFKOecuwjVMIJmgfpjp6xH0P0HDMGZAXmSyU0Q==", - "dependencies": { - "@aptos-labs/aptos-client": "^0.1.0", - "@noble/hashes": "1.3.3", - "@scure/bip39": "1.2.1", - "eventemitter3": "^5.0.1", - "form-data": "4.0.0", - "tweetnacl": "1.0.3" - }, - "engines": { - "node": ">=11.0.0" - } - }, - "node_modules/@wormhole-foundation/sdk-aptos/node_modules/eventemitter3": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", - "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==" - }, - "node_modules/@wormhole-foundation/sdk-aptos/node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/@wormhole-foundation/sdk-base": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/@wormhole-foundation/sdk-base/-/sdk-base-0.9.0.tgz", @@ -7466,13 +7450,16 @@ } }, "node_modules/aptos": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/aptos/-/aptos-1.5.0.tgz", - "integrity": "sha512-N7OuRtU7IYHkDkNx+4QS3g/QQGCp+36KzYn3oXPmT7Kttfuv+UKliQVdjy3cLmwd/DCQSh9ObTovwdxnHjUn0g==", + "version": "1.21.0", + "resolved": "https://registry.npmjs.org/aptos/-/aptos-1.21.0.tgz", + "integrity": "sha512-PRKjoFgL8tVEc9+oS7eJUv8GNxx8n3+0byH2+m7CP3raYOD6yFKOecuwjVMIJmgfpjp6xH0P0HDMGZAXmSyU0Q==", + "deprecated": "Package aptos is no longer supported, please migrate to https://www.npmjs.com/package/@aptos-labs/ts-sdk", + "license": "Apache-2.0", "dependencies": { - "@noble/hashes": "1.1.3", - "@scure/bip39": "1.1.0", - "axios": "0.27.2", + "@aptos-labs/aptos-client": "^0.1.0", + "@noble/hashes": "1.3.3", + "@scure/bip39": "1.2.1", + "eventemitter3": "^5.0.1", "form-data": "4.0.0", "tweetnacl": "1.0.3" }, @@ -7480,19 +7467,42 @@ "node": ">=11.0.0" } }, - "node_modules/aptos/node_modules/axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "node_modules/aptos/node_modules/@noble/hashes": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==", + "license": "MIT", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/aptos/node_modules/@scure/bip39": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.1.tgz", + "integrity": "sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg==", + "license": "MIT", "dependencies": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" + "@noble/hashes": "~1.3.0", + "@scure/base": "~1.1.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" } }, + "node_modules/aptos/node_modules/eventemitter3": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", + "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==", + "license": "MIT" + }, "node_modules/aptos/node_modules/form-data": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "license": "MIT", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -15543,6 +15553,41 @@ "elliptic": "^6.5.4", "js-base64": "^3.6.1", "near-api-js": "^1.0.0" + }, + "dependencies": { + "aptos": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/aptos/-/aptos-1.5.0.tgz", + "integrity": "sha512-N7OuRtU7IYHkDkNx+4QS3g/QQGCp+36KzYn3oXPmT7Kttfuv+UKliQVdjy3cLmwd/DCQSh9ObTovwdxnHjUn0g==", + "requires": { + "@noble/hashes": "1.1.3", + "@scure/bip39": "1.1.0", + "axios": "0.27.2", + "form-data": "4.0.0", + "tweetnacl": "1.0.3" + }, + "dependencies": { + "axios": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", + "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "requires": { + "follow-redirects": "^1.14.9", + "form-data": "^4.0.0" + } + } + } + }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } } }, "@certusone/wormhole-sdk-proto-web": { @@ -18622,50 +18667,6 @@ "requires": { "@wormhole-foundation/sdk-connect": "0.9.0", "aptos": "1.21.0" - }, - "dependencies": { - "@noble/hashes": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", - "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==" - }, - "@scure/bip39": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.1.tgz", - "integrity": "sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg==", - "requires": { - "@noble/hashes": "~1.3.0", - "@scure/base": "~1.1.0" - } - }, - "aptos": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/aptos/-/aptos-1.21.0.tgz", - "integrity": "sha512-PRKjoFgL8tVEc9+oS7eJUv8GNxx8n3+0byH2+m7CP3raYOD6yFKOecuwjVMIJmgfpjp6xH0P0HDMGZAXmSyU0Q==", - "requires": { - "@aptos-labs/aptos-client": "^0.1.0", - "@noble/hashes": "1.3.3", - "@scure/bip39": "1.2.1", - "eventemitter3": "^5.0.1", - "form-data": "4.0.0", - "tweetnacl": "1.0.3" - } - }, - "eventemitter3": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", - "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==" - }, - "form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "requires": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - } - } } }, "@wormhole-foundation/sdk-aptos-core": { @@ -20925,26 +20926,37 @@ } }, "aptos": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/aptos/-/aptos-1.5.0.tgz", - "integrity": "sha512-N7OuRtU7IYHkDkNx+4QS3g/QQGCp+36KzYn3oXPmT7Kttfuv+UKliQVdjy3cLmwd/DCQSh9ObTovwdxnHjUn0g==", + "version": "1.21.0", + "resolved": "https://registry.npmjs.org/aptos/-/aptos-1.21.0.tgz", + "integrity": "sha512-PRKjoFgL8tVEc9+oS7eJUv8GNxx8n3+0byH2+m7CP3raYOD6yFKOecuwjVMIJmgfpjp6xH0P0HDMGZAXmSyU0Q==", "requires": { - "@noble/hashes": "1.1.3", - "@scure/bip39": "1.1.0", - "axios": "0.27.2", + "@aptos-labs/aptos-client": "^0.1.0", + "@noble/hashes": "1.3.3", + "@scure/bip39": "1.2.1", + "eventemitter3": "^5.0.1", "form-data": "4.0.0", "tweetnacl": "1.0.3" }, "dependencies": { - "axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "@noble/hashes": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==" + }, + "@scure/bip39": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.1.tgz", + "integrity": "sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg==", "requires": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" + "@noble/hashes": "~1.3.0", + "@scure/base": "~1.1.0" } }, + "eventemitter3": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", + "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==" + }, "form-data": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", diff --git a/clients/js/package.json b/clients/js/package.json index 5e5f672b74..5e90b22500 100644 --- a/clients/js/package.json +++ b/clients/js/package.json @@ -45,7 +45,7 @@ "@wormhole-foundation/sdk": "^0.9.0", "@xpla/xpla.js": "^0.2.1", "algosdk": "^2.4.0", - "aptos": "^1.3.16", + "aptos": "1.21.0", "axios": "^0.24.0", "base-64": "^1.0.0", "bech32": "^2.0.0", diff --git a/clients/js/src/aptos.ts b/clients/js/src/aptos.ts index 49c98fb430..2f773ed395 100644 --- a/clients/js/src/aptos.ts +++ b/clients/js/src/aptos.ts @@ -6,7 +6,6 @@ import { NETWORKS } from "./consts"; import { Payload, impossible } from "./vaa"; import { CHAINS, ensureHexPrefix } from "@certusone/wormhole-sdk"; import { TokenBridgeState } from "@certusone/wormhole-sdk/lib/esm/aptos/types"; -import { generateSignAndSubmitEntryFunction } from "@certusone/wormhole-sdk/lib/esm/utils"; import { Chain, ChainId, @@ -17,6 +16,68 @@ import { } from "@wormhole-foundation/sdk-base"; import { tryNativeToUint8Array } from "./sdk/array"; +/** + * Simulates given raw transaction and either returns the resulting transaction that was submitted + * to the mempool, or throws if it fails. + * @param client Client used to transfer data to/from Aptos node + * @param sender Account that will submit transaction + * @param rawTx Raw transaction to sign & submit + * @returns Transaction data + */ +const signAndSubmitTransaction = async ( + client: AptosClient, + sender: AptosAccount, + rawTx: TxnBuilderTypes.RawTransaction +): Promise => { + // simulate transaction + await client.simulateTransaction(sender, rawTx).then((sims) => + sims.forEach((tx) => { + if (!tx.success) { + throw new Error( + `Transaction failed: ${tx.vm_status}\n${JSON.stringify(tx, null, 2)}` + ); + } + }) + ); + + // sign & submit transaction + return client + .signTransaction(sender, rawTx) + .then((signedTx) => client.submitTransaction(signedTx)) + .then((pendingTx) => client.waitForTransactionWithResult(pendingTx.hash)); +}; + +/** + * Generate, sign, and submit a transaction calling the given entry function with the given + * arguments. Prevents transaction submission and throws if the transaction fails. + * + * This is separated from `generateSignAndSubmitScript` because it makes use of `AptosClient`'s + * `generateTransaction` which pulls ABIs from the node and uses them to encode arguments + * automatically. + * @param client Client used to transfer data to/from Aptos node + * @param sender Account that will submit transaction + * @param payload Payload containing unencoded fully qualified entry function, types, and arguments + * @param opts Override default transaction options + * @returns Data from transaction after is has been successfully submitted to mempool + */ +export const generateSignAndSubmitEntryFunction = ( + client: AptosClient, + sender: AptosAccount, + payload: Types.EntryFunctionPayload, + opts?: Partial +): Promise => { + return client + .generateTransaction(sender.address(), payload, opts) + .then( + (rawTx) => + signAndSubmitTransaction( + client, + sender, + rawTx + ) as Promise + ); +}; + export async function execute_aptos( payload: Payload, vaa: Buffer, diff --git a/clients/js/src/chains/generic/getOriginalAsset.ts b/clients/js/src/chains/generic/getOriginalAsset.ts index 51be57e9a7..687b9fec2d 100644 --- a/clients/js/src/chains/generic/getOriginalAsset.ts +++ b/clients/js/src/chains/generic/getOriginalAsset.ts @@ -111,7 +111,11 @@ export const getOriginalAsset = async ( } case "Aptos": { const provider = getProviderForChain(chainName, network, { rpc }); - return getOriginalAssetAptos(provider, tokenBridgeAddress, assetAddress); + return getOriginalAssetAptos( + provider as any, // getOriginalAssetAptos only uses provider.getAccountResource, using `as any` to get around version mismatch + tokenBridgeAddress, + assetAddress + ); } case "Sui": { const provider = getProviderForChain(chainName, network, { rpc }); diff --git a/clients/js/src/chains/generic/getWrappedAssetAddress.ts b/clients/js/src/chains/generic/getWrappedAssetAddress.ts index 0a5194def2..c8530f09f0 100644 --- a/clients/js/src/chains/generic/getWrappedAssetAddress.ts +++ b/clients/js/src/chains/generic/getWrappedAssetAddress.ts @@ -149,7 +149,7 @@ export const getWrappedAssetAddress = async ( case "Aptos": { const provider = getProviderForChain(chainName, network, { rpc }); return getForeignAssetAptos( - provider, + provider as any, // getForeignAssetAptos only uses provider.getAccountResource, using `as any` to get around version mismatch tokenBridgeAddress, toChainId(originChain), originAddress