Pārlūkot izejas kodu

aptos/nft-bridge: Tilt integration

aptos: update Docker image
Csongor Kiss 2 gadi atpakaļ
vecāks
revīzija
fe5ca53a98

+ 2 - 2
aptos/Docker.md

@@ -1,6 +1,6 @@
 # first build the image
 # first build the image
 (cd ..; DOCKER_BUILDKIT=1 docker build -f aptos/Dockerfile.base -t aptos .)
 (cd ..; DOCKER_BUILDKIT=1 docker build -f aptos/Dockerfile.base -t aptos .)
 # tag the image with the appropriate version
 # 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
 # push to ghcr
-docker push ghcr.io/wormhole-foundation/aptos:1.1.0
+docker push ghcr.io/wormhole-foundation/aptos:1.0.4

+ 1 - 1
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
 # Support additional root CAs
 COPY cert.pem* /certs/
 COPY cert.pem* /certs/

+ 1 - 0
aptos/README.md

@@ -125,6 +125,7 @@ run the deploy script again. However, a better way is to run one of the followin
 ``` sh
 ``` sh
 scripts $ ./upgrade devnet Core # for upgrading the wormhole contract
 scripts $ ./upgrade devnet Core # for upgrading the wormhole contract
 scripts $ ./upgrade devnet TokenBridge # for upgarding the token bridge 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
 Behind the scenes, these scripts exercise the whole contract upgrade code path

+ 13 - 8
aptos/scripts/deploy

@@ -38,22 +38,27 @@ fi
 
 
 WORMHOLE_ADDR=$(worm contract "$NETWORK" aptos Core)
 WORMHOLE_ADDR=$(worm contract "$NETWORK" aptos Core)
 TOKEN_BRIDGE_ADDR=$(worm contract "$NETWORK" aptos TokenBridge)
 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"
 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"
 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"
 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
 if [ "$NETWORK" = devnet ]; then
     echo "[+1] Deploying example contract..."
     echo "[+1] Deploying example contract..."

+ 14 - 3
aptos/scripts/register_devnet

@@ -12,13 +12,24 @@ DOTENV=../.env
 # if a new VAA is added, this will automatically pick it up
 # 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)
 VAAS=$(set | grep "REGISTER_.*_TOKEN_BRIDGE_VAA" | grep -v APTOS | cut -d '=' -f1)
 
 
+# 3. use 'worm' to submit each registration VAA
+for VAA in $VAAS
+do
+    VAA=${!VAA}
+    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
 # TODO: this will not be needed when the sdk is published
-TOKEN_BRIDGE_ADDR=$(worm contract devnet aptos TokenBridge)
+NFT_BRIDGE_ADDR=$(worm contract devnet aptos NFTBridge)
 
 
-# 3. use 'worm' to submit each registration VAA
+# 5. use 'worm' to submit each registration VAA
 for VAA in $VAAS
 for VAA in $VAAS
 do
 do
     VAA=${!VAA}
     VAA=${!VAA}
-    worm submit $VAA --chain aptos --contract-address $TOKEN_BRIDGE_ADDR --network devnet
+    worm submit $VAA --chain aptos --contract-address $NFT_BRIDGE_ADDR --network devnet
 done
 done
 echo "Registrations successful."
 echo "Registrations successful."

+ 5 - 1
aptos/scripts/upgrade

@@ -30,8 +30,9 @@ fi
 
 
 WORMHOLE_ADDR=$(worm contract "$NETWORK" aptos Core)
 WORMHOLE_ADDR=$(worm contract "$NETWORK" aptos Core)
 TOKEN_BRIDGE_ADDR=$(worm contract "$NETWORK" aptos TokenBridge)
 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
 case "$MODULE" in
     Core)
     Core)
@@ -40,6 +41,9 @@ case "$MODULE" in
     TokenBridge)
     TokenBridge)
         DIR="../token_bridge"
         DIR="../token_bridge"
     ;;
     ;;
+    NFTBridge)
+        DIR="../nft_bridge"
+    ;;
     *) echo "unsupported module $MODULE" >&2
     *) echo "unsupported module $MODULE" >&2
        usage
        usage
        ;;
        ;;

+ 15 - 0
clients/js/aptos.ts

@@ -43,6 +43,21 @@ export async function execute_aptos(
       if (contract === undefined) {
       if (contract === undefined) {
         throw Error("nft bridge contract is 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
       break
     case "TokenBridge":
     case "TokenBridge":
       contract = contract ?? CONTRACTS[network][chain]["token_bridge"];
       contract = contract ?? CONTRACTS[network][chain]["token_bridge"];

+ 23 - 11
clients/js/cmds/aptos.ts

@@ -58,6 +58,9 @@ exports.command = 'aptos';
 exports.desc = 'Aptos utilities';
 exports.desc = 'Aptos utilities';
 exports.builder = function(y: typeof yargs) {
 exports.builder = function(y: typeof yargs) {
   return y
   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) => {
     .command("init-token-bridge", "Init token bridge contract", (yargs) => {
       return yargs
       return yargs
         .option("network", network_options)
         .option("network", network_options)
@@ -65,7 +68,7 @@ exports.builder = function(y: typeof yargs) {
     }, async (argv) => {
     }, async (argv) => {
       const network = argv.network.toUpperCase();
       const network = argv.network.toUpperCase();
       assertNetwork(network);
       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;
       const rpc = argv.rpc ?? NETWORKS[network]["aptos"].rpc;
       await callEntryFunc(network, rpc, `${contract_address}::token_bridge`, "init", [], []);
       await callEntryFunc(network, rpc, `${contract_address}::token_bridge`, "init", [], []);
     })
     })
@@ -91,13 +94,6 @@ exports.builder = function(y: typeof yargs) {
           default: "0x0000000000000000000000000000000000000000000000000000000000000004",
           default: "0x0000000000000000000000000000000000000000000000000000000000000004",
           required: false
           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", {
         .option("guardian-address", {
           alias: "g",
           alias: "g",
           required: true,
           required: true,
@@ -108,7 +104,7 @@ exports.builder = function(y: typeof yargs) {
       const network = argv.network.toUpperCase();
       const network = argv.network.toUpperCase();
       assertNetwork(network);
       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 guardian_addresses = argv["guardian-address"].split(",").map(address => evm_address(address).substring(24));
       const chain_id = argv["chain-id"];
       const chain_id = argv["chain-id"];
       const governance_address = evm_address(argv["governance-address"]);
       const governance_address = evm_address(argv["governance-address"]);
@@ -251,6 +247,14 @@ exports.builder = function(y: typeof yargs) {
         .positional("package-dir", {
         .positional("package-dir", {
           type: "string"
           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("network", network_options)
         .option("rpc", rpc_description)
         .option("rpc", rpc_description)
         .option("named-addresses", named_addresses)
         .option("named-addresses", named_addresses)
@@ -265,7 +269,7 @@ exports.builder = function(y: typeof yargs) {
       const hash = await callEntryFunc(
       const hash = await callEntryFunc(
         network,
         network,
         rpc,
         rpc,
-        `${CONTRACTS[network].aptos.core}::contract_upgrade`,
+        `${argv["contract-address"]}::contract_upgrade`,
         "upgrade",
         "upgrade",
         [],
         [],
         [
         [
@@ -277,6 +281,14 @@ exports.builder = function(y: typeof yargs) {
     })
     })
     .command("migrate", "Perform migration after contract upgrade", (_yargs) => {
     .command("migrate", "Perform migration after contract upgrade", (_yargs) => {
       return 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("network", network_options)
         .option("rpc", rpc_description)
         .option("rpc", rpc_description)
     }, async (argv) => {
     }, async (argv) => {
@@ -288,7 +300,7 @@ exports.builder = function(y: typeof yargs) {
       const hash = await callEntryFunc(
       const hash = await callEntryFunc(
         network,
         network,
         rpc,
         rpc,
-        `${CONTRACTS[network].aptos.core}::contract_upgrade`,
+        `${argv["contract-address"]}::contract_upgrade`,
         "migrate",
         "migrate",
         [],
         [],
         [])
         [])

+ 2 - 1
scripts/devnet-consts.json

@@ -248,7 +248,8 @@
         },
         },
         "22": {
         "22": {
             "contracts": {
             "contracts": {
-                "tokenBridgeEmitterAddress": "0000000000000000000000000000000000000000000000000000000000000001"
+                "tokenBridgeEmitterAddress": "0000000000000000000000000000000000000000000000000000000000000001",
+                "nftBridgeEmitterAddress": "0000000000000000000000000000000000000000000000000000000000000002"
             }
             }
         }
         }
     },
     },

+ 7 - 0
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)
 ethNFTBridge=$(jq --raw-output '.chains."2".contracts.nftBridgeEmitterAddress' $addressesJson)
 terraNFTBridge=$(jq --raw-output '.chains."3".contracts.nftBridgeEmitterAddress' $addressesJson)
 terraNFTBridge=$(jq --raw-output '.chains."3".contracts.nftBridgeEmitterAddress' $addressesJson)
 nearNFTBridge=$(jq --raw-output '.chains."15".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
 # 4) create token bridge registration VAAs
 # invoke CLI commands to create 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})
 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})
 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})
 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
 # 6) write the registration VAAs to env files
@@ -136,6 +138,7 @@ solNFTBridge="REGISTER_SOL_NFT_BRIDGE_VAA"
 ethNFTBridge="REGISTER_ETH_NFT_BRIDGE_VAA"
 ethNFTBridge="REGISTER_ETH_NFT_BRIDGE_VAA"
 terraNFTBridge="REGISTER_TERRA_NFT_BRIDGE_VAA"
 terraNFTBridge="REGISTER_TERRA_NFT_BRIDGE_VAA"
 nearNFTBridge="REGISTER_NEAR_NFT_BRIDGE_VAA"
 nearNFTBridge="REGISTER_NEAR_NFT_BRIDGE_VAA"
+aptosNFTBridge="REGISTER_APTOS_NFT_BRIDGE_VAA"
 
 
 
 
 # solana token bridge
 # solana token bridge
@@ -178,6 +181,10 @@ upsert_env_file $envFile $terra2TokenBridge $terra2TokenBridgeVAA
 upsert_env_file $ethFile $aptosTokenBridge $aptosTokenBridgeVAA
 upsert_env_file $ethFile $aptosTokenBridge $aptosTokenBridgeVAA
 upsert_env_file $envFile $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
 # near token bridge
 upsert_env_file $ethFile $nearTokenBridge $nearTokenBridgeVAA
 upsert_env_file $ethFile $nearTokenBridge $nearTokenBridgeVAA
 upsert_env_file $envFile $nearTokenBridge $nearTokenBridgeVAA
 upsert_env_file $envFile $nearTokenBridge $nearTokenBridgeVAA