pyth-crosschain/target_chains/aptos/cli
Amin Moghaddam cee5da93d8
Movement move (#1211)
* [contract manager] Implement WormholeAptosContract and integrate aptos cli with the manager

* Add getChainId for wormhole contracts

* Add movement contracts

* Simplify aptos cli
2024-01-11 12:35:52 +01:00
..
src Movement move (#1211) 2024-01-11 12:35:52 +01:00
README.md Movement move (#1211) 2024-01-11 12:35:52 +01:00
package-lock.json [refactor] Convert hyphen to underscore in the directory tree (#524) 2023-01-24 19:06:22 +01:00
package.json [aptos] Aptos cleanup (#994) 2023-07-31 11:43:58 +01:00
tsconfig.json [refactor] Convert hyphen to underscore in the directory tree (#524) 2023-01-24 19:06:22 +01:00

README.md

Pre-requisites

Install aptos cli with the same version specified in the ci workflows.

All the commands which submit transactions require an environment variable APTOS_PRIVATE_KEY for the private key to be set.

Deploying from scratch

In addition to the wormhole dependency we depend on the deployer contract that facilitates the ownership of package upgrade capability. You can read more about it here.

Assuming the wormhole and deployer contracts are already deployed, we can deploy the pyth oracle with the following command:

npm run cli deploy-pyth -- ../contracts <seed> \
-n aptos_testnet \
--deployer <deployer-address> \
--wormhole <wormhole-address>

seed can be any random string that is used for determining a specific contract address based on the seed value and the signer address.

You can manually specify the address of wormhole and deployer contracts with --wormhole and --deployer flags. This requires the addresses to be empty in the Move.toml file for the pyth package:

[addresses]
pyth = "_"
deployer = "_"
wormhole = "_"

Initializing pyth

You can run the following to initialize the pyth contract:

npm run cli init-pyth -- <seed> -n <network> \
--stale-price-threshold 60 \
--update-fee 1 \
--channel <stable-or-beta>

Upgrade process:

The following steps are needed to upgrade our aptos contracts:

  • Generate the hash for the new contract build
  • Create a governance proposal, proposing the aptos package to be upgraded to this specific hash
  • Approve and execute the governance proposal
  • Submit the created wormhole VAA to the contract to allow an upgrade with the specified hash.
  • Run the upgrade transaction and publish the new package

Generating the new contract hash:

Run the following command to generate the new hash, this will assume the default deployed addresses of deployer, wormhole, and pyth, but you can override them if necessary.

npm run cli hash-contracts -- ../contracts

Creating a proposal

Here are sample steps you can take to create a proposal via the contract manager shell (npm run shell in contract manager package):

let wallet = await loadHotWallet("/path/to/solana/wallet.json");
let vault =
  DefaultStore.vaults.devnet_6baWtW1zTUVMSJHJQVxDUXWzqrQeYBr6mu31j3bTKwY3;
await vault.connect(wallet);
let payload =
  DefaultStore.chains.aptos_testnet.generateGovernanceUpgradePayload(
    "CONTRACT_HASH_TO_USE"
  );
await vault.proposeWormholeMessage([payload]);

VAA submission

After the approval process, you can fetch the VAA for the transaction and execute it by running:

import { SubmittedWormholeMessage } from "./src/governance";
let msg = await SubmittedWormholeMessage.fromTransactionSignature(
  "tx_signature",
  "devnet or mainnet-beta"
);
let vaa = await msg.fetchVaa();
let contract =
  DefaultStore.contracts
    .aptos_testnet_0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387;
await contract.executeGovernanceInstruction(
  "private-key-of-account-inaptos",
  vaa
);

Upgrading the contract

To upgrade the contract after the governance vaa was executed run:

npm run cli upgrade -- ../contracts