From fe5ca53a98eb6c044fc1751f275dcab5c6e788e2 Mon Sep 17 00:00:00 2001 From: Csongor Kiss Date: Wed, 11 Jan 2023 15:30:13 +0000 Subject: [PATCH] aptos/nft-bridge: Tilt integration aptos: update Docker image --- aptos/Docker.md | 4 ++-- aptos/Dockerfile | 2 +- aptos/README.md | 1 + aptos/scripts/deploy | 21 +++++++++++++-------- aptos/scripts/register_devnet | 19 +++++++++++++++---- aptos/scripts/upgrade | 6 +++++- clients/js/aptos.ts | 15 +++++++++++++++ clients/js/cmds/aptos.ts | 34 +++++++++++++++++++++++----------- scripts/devnet-consts.json | 3 ++- scripts/guardian-set-init.sh | 7 +++++++ 10 files changed, 84 insertions(+), 28 deletions(-) diff --git a/aptos/Docker.md b/aptos/Docker.md index 26d1cf4ed..11739ce95 100644 --- a/aptos/Docker.md +++ b/aptos/Docker.md @@ -1,6 +1,6 @@ # first build the image (cd ..; DOCKER_BUILDKIT=1 docker build -f aptos/Dockerfile.base -t aptos .) # tag the image with the appropriate version -docker tag aptos:latest ghcr.io/wormhole-foundation/aptos:1.1.0 +docker tag aptos:latest ghcr.io/wormhole-foundation/aptos:1.0.4 # push to ghcr -docker push ghcr.io/wormhole-foundation/aptos:1.1.0 +docker push ghcr.io/wormhole-foundation/aptos:1.0.4 diff --git a/aptos/Dockerfile b/aptos/Dockerfile index 62fba9615..c2914ca41 100644 --- a/aptos/Dockerfile +++ b/aptos/Dockerfile @@ -1,4 +1,4 @@ -FROM ghcr.io/wormhole-foundation/aptos:1.1.0@sha256:9240135c950207e0bbe70d188999343b59d50d506dcc67c1b5586c1dd57b443c as aptos +FROM ghcr.io/wormhole-foundation/aptos:1.0.4@sha256:0610c97ba32aab7113765b05a0c71d75b3842f7ee11ff8d7f75bd0ea03ad95b2 as aptos # Support additional root CAs COPY cert.pem* /certs/ diff --git a/aptos/README.md b/aptos/README.md index 21a67b696..c9061d0c2 100644 --- a/aptos/README.md +++ b/aptos/README.md @@ -125,6 +125,7 @@ run the deploy script again. However, a better way is to run one of the followin ``` sh scripts $ ./upgrade devnet Core # for upgrading the wormhole contract scripts $ ./upgrade devnet TokenBridge # for upgarding the token bridge contract +scripts $ ./upgrade devnet NFTBridge # for upgarding the NFT bridge contract ``` Behind the scenes, these scripts exercise the whole contract upgrade code path diff --git a/aptos/scripts/deploy b/aptos/scripts/deploy index 162aecff3..a21837b51 100755 --- a/aptos/scripts/deploy +++ b/aptos/scripts/deploy @@ -38,22 +38,27 @@ fi WORMHOLE_ADDR=$(worm contract "$NETWORK" aptos Core) TOKEN_BRIDGE_ADDR=$(worm contract "$NETWORK" aptos TokenBridge) +NFT_BRIDGE_ADDR=$(worm contract "$NETWORK" aptos NFTBridge) -NAMED_ADDRS="wormhole=$WORMHOLE_ADDR,deployer=$DEPLOYER_ADDR,token_bridge=$TOKEN_BRIDGE_ADDR" +NAMED_ADDRS="wormhole=$WORMHOLE_ADDR,deployer=$DEPLOYER_ADDR,token_bridge=$TOKEN_BRIDGE_ADDR,nft_bridge=$NFT_BRIDGE_ADDR" -echo "[1/5] Deploying deployer contract for creating resource accounts..." +echo "[1/6] Deploying deployer contract for creating resource accounts..." worm aptos deploy --network "$NETWORK" ../deployer --named-addresses "$NAMED_ADDRS" -echo "[2/5] Deploying wormhole contract at $WORMHOLE_ADDR..." +echo "[2/6] Deploying wormhole contract at $WORMHOLE_ADDR..." worm aptos deploy-resource wormhole --network "$NETWORK" ../wormhole --named-addresses "$NAMED_ADDRS" -echo "[3/5] Initialising wormhole with guardian(s) $GUARDIAN_ADDR..." -worm aptos init-wormhole --network "$NETWORK" -g $GUARDIAN_ADDR --contract-address "$WORMHOLE_ADDR" +echo "[3/6] Initialising wormhole with guardian(s) $GUARDIAN_ADDR..." +worm aptos init-wormhole --network "$NETWORK" -g $GUARDIAN_ADDR -echo "[4/5] Deploying token bridge contract at $TOKEN_BRIDGE_ADDR..." +echo "[4/6] Deploying token bridge contract at $TOKEN_BRIDGE_ADDR..." worm aptos deploy-resource token_bridge --network "$NETWORK" ../token_bridge --named-addresses "$NAMED_ADDRS" -echo "[5/5] Initialising token bridge..." -worm aptos init-token-bridge --network "$NETWORK" --contract-address "$TOKEN_BRIDGE_ADDR" + +echo "[5/6] Initialising token bridge..." +worm aptos init-token-bridge --network "$NETWORK" + +echo "[6/6] Deploying (& initialising) NFT bridge contract at $NFT_BRIDGE_ADDR..." +worm aptos deploy-resource nft_bridge --network "$NETWORK" ../nft_bridge --named-addresses "$NAMED_ADDRS" if [ "$NETWORK" = devnet ]; then echo "[+1] Deploying example contract..." diff --git a/aptos/scripts/register_devnet b/aptos/scripts/register_devnet index 1535ba2df..eea804a7a 100755 --- a/aptos/scripts/register_devnet +++ b/aptos/scripts/register_devnet @@ -12,13 +12,24 @@ DOTENV=../.env # if a new VAA is added, this will automatically pick it up VAAS=$(set | grep "REGISTER_.*_TOKEN_BRIDGE_VAA" | grep -v APTOS | cut -d '=' -f1) -# TODO: this will not be needed when the sdk is published -TOKEN_BRIDGE_ADDR=$(worm contract devnet aptos TokenBridge) - # 3. use 'worm' to submit each registration VAA for VAA in $VAAS do VAA=${!VAA} - worm submit $VAA --chain aptos --contract-address $TOKEN_BRIDGE_ADDR --network devnet + worm submit $VAA --chain aptos --network devnet +done + +# 4. next we get all the NFT bridge registration VAAs from the environment +# if a new VAA is added, this will automatically pick it up +VAAS=$(set | grep "REGISTER_.*_NFT_BRIDGE_VAA" | grep -v APTOS | cut -d '=' -f1) + +# TODO: this will not be needed when the sdk is published +NFT_BRIDGE_ADDR=$(worm contract devnet aptos NFTBridge) + +# 5. use 'worm' to submit each registration VAA +for VAA in $VAAS +do + VAA=${!VAA} + worm submit $VAA --chain aptos --contract-address $NFT_BRIDGE_ADDR --network devnet done echo "Registrations successful." diff --git a/aptos/scripts/upgrade b/aptos/scripts/upgrade index 5eb8502a5..7cd9dfba9 100755 --- a/aptos/scripts/upgrade +++ b/aptos/scripts/upgrade @@ -30,8 +30,9 @@ fi WORMHOLE_ADDR=$(worm contract "$NETWORK" aptos Core) TOKEN_BRIDGE_ADDR=$(worm contract "$NETWORK" aptos TokenBridge) +NFT_BRIDGE_ADDR=$(worm contract "$NETWORK" aptos NFTBridge) -NAMED_ADDRS="wormhole=$WORMHOLE_ADDR,deployer=$DEPLOYER_ADDR,token_bridge=$TOKEN_BRIDGE_ADDR" +NAMED_ADDRS="wormhole=$WORMHOLE_ADDR,deployer=$DEPLOYER_ADDR,token_bridge=$TOKEN_BRIDGE_ADDR,nft_bridge=$NFT_BRIDGE_ADDR" case "$MODULE" in Core) @@ -40,6 +41,9 @@ case "$MODULE" in TokenBridge) DIR="../token_bridge" ;; + NFTBridge) + DIR="../nft_bridge" + ;; *) echo "unsupported module $MODULE" >&2 usage ;; diff --git a/clients/js/aptos.ts b/clients/js/aptos.ts index fd391975f..0be87b17a 100644 --- a/clients/js/aptos.ts +++ b/clients/js/aptos.ts @@ -43,6 +43,21 @@ export async function execute_aptos( if (contract === undefined) { throw Error("nft bridge contract is undefined") } + switch (payload.type) { + case "ContractUpgrade": + console.log("Upgrading contract") + await callEntryFunc(network, rpc, `${contract}::contract_upgrade`, "submit_vaa_entry", [], [bcsVAA]); + break + case "RegisterChain": + console.log("Registering chain") + await callEntryFunc(network, rpc, `${contract}::register_chain`, "submit_vaa_entry", [], [bcsVAA]); + break + case "Transfer": { + console.log("Completing transfer") + await callEntryFunc(network, rpc, `${contract}::complete_transfer`, "submit_vaa_entry", [], [bcsVAA]); + break + } + } break case "TokenBridge": contract = contract ?? CONTRACTS[network][chain]["token_bridge"]; diff --git a/clients/js/cmds/aptos.ts b/clients/js/cmds/aptos.ts index 271eadbf9..b235b1fca 100644 --- a/clients/js/cmds/aptos.ts +++ b/clients/js/cmds/aptos.ts @@ -58,6 +58,9 @@ exports.command = 'aptos'; exports.desc = 'Aptos utilities'; exports.builder = function(y: typeof yargs) { return y + // NOTE: there's no init-nft-bridge, because the native module initialiser + // functionality has stabilised on mainnet, so we just use that one (which + // gets called automatically) .command("init-token-bridge", "Init token bridge contract", (yargs) => { return yargs .option("network", network_options) @@ -65,7 +68,7 @@ exports.builder = function(y: typeof yargs) { }, async (argv) => { const network = argv.network.toUpperCase(); assertNetwork(network); - const contract_address = evm_address(CONTRACTS[network].aptos.core); + const contract_address = evm_address(CONTRACTS[network].aptos.token_bridge); const rpc = argv.rpc ?? NETWORKS[network]["aptos"].rpc; await callEntryFunc(network, rpc, `${contract_address}::token_bridge`, "init", [], []); }) @@ -91,13 +94,6 @@ exports.builder = function(y: typeof yargs) { default: "0x0000000000000000000000000000000000000000000000000000000000000004", required: false }) - // TODO(csongor): once the sdk has this, just use it from there - .option("contract-address", { - alias: "a", - required: true, - describe: "Address where the wormhole module is deployed", - type: "string", - }) .option("guardian-address", { alias: "g", required: true, @@ -108,7 +104,7 @@ exports.builder = function(y: typeof yargs) { const network = argv.network.toUpperCase(); assertNetwork(network); - const contract_address = evm_address(argv["contract-address"]); + const contract_address = evm_address(CONTRACTS[network].aptos.core); const guardian_addresses = argv["guardian-address"].split(",").map(address => evm_address(address).substring(24)); const chain_id = argv["chain-id"]; const governance_address = evm_address(argv["governance-address"]); @@ -251,6 +247,14 @@ exports.builder = function(y: typeof yargs) { .positional("package-dir", { type: "string" }) + // TODO(csongor): once the sdk has the addresses, just look that up + // based on the module + .option("contract-address", { + alias: "a", + required: true, + describe: "Address where the wormhole module is deployed", + type: "string", + }) .option("network", network_options) .option("rpc", rpc_description) .option("named-addresses", named_addresses) @@ -265,7 +269,7 @@ exports.builder = function(y: typeof yargs) { const hash = await callEntryFunc( network, rpc, - `${CONTRACTS[network].aptos.core}::contract_upgrade`, + `${argv["contract-address"]}::contract_upgrade`, "upgrade", [], [ @@ -277,6 +281,14 @@ exports.builder = function(y: typeof yargs) { }) .command("migrate", "Perform migration after contract upgrade", (_yargs) => { return yargs + // TODO(csongor): once the sdk has the addresses, just look that up + // based on the module + .option("contract-address", { + alias: "a", + required: true, + describe: "Address where the wormhole module is deployed", + type: "string", + }) .option("network", network_options) .option("rpc", rpc_description) }, async (argv) => { @@ -288,7 +300,7 @@ exports.builder = function(y: typeof yargs) { const hash = await callEntryFunc( network, rpc, - `${CONTRACTS[network].aptos.core}::contract_upgrade`, + `${argv["contract-address"]}::contract_upgrade`, "migrate", [], []) diff --git a/scripts/devnet-consts.json b/scripts/devnet-consts.json index 7ce20ccfc..802649644 100644 --- a/scripts/devnet-consts.json +++ b/scripts/devnet-consts.json @@ -248,7 +248,8 @@ }, "22": { "contracts": { - "tokenBridgeEmitterAddress": "0000000000000000000000000000000000000000000000000000000000000001" + "tokenBridgeEmitterAddress": "0000000000000000000000000000000000000000000000000000000000000001", + "nftBridgeEmitterAddress": "0000000000000000000000000000000000000000000000000000000000000002" } } }, diff --git a/scripts/guardian-set-init.sh b/scripts/guardian-set-init.sh index e14ae895d..63d4af3cb 100755 --- a/scripts/guardian-set-init.sh +++ b/scripts/guardian-set-init.sh @@ -97,6 +97,7 @@ solNFTBridge=$(jq --raw-output '.chains."1".contracts.nftBridgeEmitterAddress' $ ethNFTBridge=$(jq --raw-output '.chains."2".contracts.nftBridgeEmitterAddress' $addressesJson) terraNFTBridge=$(jq --raw-output '.chains."3".contracts.nftBridgeEmitterAddress' $addressesJson) nearNFTBridge=$(jq --raw-output '.chains."15".contracts.nftBridgeEmitterAddress' $addressesJson) +aptosNFTBridge=$(jq --raw-output '.chains."22".contracts.nftBridgeEmitterAddress' $addressesJson) # 4) create token bridge registration VAAs # invoke CLI commands to create registration VAAs @@ -117,6 +118,7 @@ solNFTBridgeVAA=$(node ./clients/js/build/main.js generate registration -m NFTBr ethNFTBridgeVAA=$(node ./clients/js/build/main.js generate registration -m NFTBridge -c ethereum -a ${ethNFTBridge} -g ${guardiansPrivateCSV}) terraNFTBridgeVAA=$(node ./clients/js/build/main.js generate registration -m NFTBridge -c terra -a ${terraNFTBridge} -g ${guardiansPrivateCSV}) nearNFTBridgeVAA=$(node ./clients/js/build/main.js generate registration -m NFTBridge -c near -a ${nearNFTBridge} -g ${guardiansPrivateCSV}) +aptosNFTBridgeVAA=$(node ./clients/js/build/main.js generate registration -m NFTBridge -c aptos -a ${aptosNFTBridge} -g ${guardiansPrivateCSV}) # 6) write the registration VAAs to env files @@ -136,6 +138,7 @@ solNFTBridge="REGISTER_SOL_NFT_BRIDGE_VAA" ethNFTBridge="REGISTER_ETH_NFT_BRIDGE_VAA" terraNFTBridge="REGISTER_TERRA_NFT_BRIDGE_VAA" nearNFTBridge="REGISTER_NEAR_NFT_BRIDGE_VAA" +aptosNFTBridge="REGISTER_APTOS_NFT_BRIDGE_VAA" # solana token bridge @@ -178,6 +181,10 @@ upsert_env_file $envFile $terra2TokenBridge $terra2TokenBridgeVAA upsert_env_file $ethFile $aptosTokenBridge $aptosTokenBridgeVAA upsert_env_file $envFile $aptosTokenBridge $aptosTokenBridgeVAA +# aptos nft bridge +upsert_env_file $ethFile $aptosNFTBridge $aptosNFTBridgeVAA +upsert_env_file $envFile $aptosNFTBridge $aptosNFTBridgeVAA + # near token bridge upsert_env_file $ethFile $nearTokenBridge $nearTokenBridgeVAA upsert_env_file $envFile $nearTokenBridge $nearTokenBridgeVAA