pyth-crosschain/cosmwasm
Stanisław Drozd a2a0f6e15b
Start depending on the upstream out-of-tree Wormhole (#258)
* Add out-of-tree dependency on wormhole v2.8.9

This lets us outsource all wormhole/solitaire code to the upstream
certusone repo

* Docker.client: Use cargo-install to install binaries from github

* p2w: fix solana-program wasm-bindgen

* pyth2wormhole: Fix code-level errors against newer solitaire

* p2w: Use upstream wormhole rust code, bump guardian to 2.8.9

* guardian: ensure solana is on, spy: bump image to 2.8.9

Co-authored-by: Reisen <reisen@morphism.org>
2022-08-29 16:18:41 +02:00
..
contracts Start depending on the upstream out-of-tree Wormhole (#258) 2022-08-29 16:18:41 +02:00
devnet Abehjati/use-cw-1-for-contracts (#240) 2022-07-20 16:35:01 +02:00
tools Abehjati/cleanup-cosmwasm (#243) 2022-07-29 09:53:21 +02:00
.dockerignore Abehjati/rename-terra-to-cw (#239) 2022-07-19 16:26:41 +02:00
.gitignore Abehjati/rename-terra-to-cw (#239) 2022-07-19 16:26:41 +02:00
Cargo.lock Start depending on the upstream out-of-tree Wormhole (#258) 2022-08-29 16:18:41 +02:00
Cargo.toml Abehjati/rename-terra-to-cw (#239) 2022-07-19 16:26:41 +02:00
Dockerfile.build Abehjati/rename-terra-to-cw (#239) 2022-07-19 16:26:41 +02:00
README.md Abehjati/cleanup-cosmwasm (#243) 2022-07-29 09:53:21 +02:00
build.sh Abehjati/rename-terra-to-cw (#239) 2022-07-19 16:26:41 +02:00
rustfmt.toml Abehjati/rename-terra-to-cw (#239) 2022-07-19 16:26:41 +02:00

README.md

Pyth CosmWasm

This directory contains The Pyth contract on CosmWasm and utilities to deploy it in CosmWasm chains.

Deployment

Deploying the CosmWasm contract has two steps:

  1. Upload the code. This step will give you a code id.
  2. Either create a new contract or migrate an existing one:
    1. Create a new contract that has an address with a code id as its program.
    2. Migrating an existing contract code id to the new code id.

This directory includes a script to perform both steps. Read below for the details.

Uploading the code

First, build the contracts within the current directory:

bash build.sh

This command will build and save the Pyth contract in the artifact directory.

Then, to deploy the Pyth contract (pyth_bridge.wasm), run the following command in the tools directory:

npm ci # Do it only once to install the required packages
npm run deploy-pyth -- --network testnet --artifact ../artifacts/pyth_bridge.wasm --mnemonic "..."

If successful, this command will print something along the lines of:

Storing WASM: ../artifacts/pyth_bridge.wasm (367689 bytes)
Deploy fee:  88446uluna
Code ID:  2435

If you do not pass any additional arguments to the script, it will only upload the code and return the code id. If you want to create a new contract or upgrade an existing contract you should pass more arguments that are described below.

Instantiating new contract

If you want to instantiate a new contract after your deployment, pass --instantiate to the above command. This command will upload the code and instantiates a new Pyth contract with the resulting code id:

npm run deploy-pyth -- --network testnet --artifact ../artifacts/pyth_bridge.wasm --mnemonic "..." --instantiate

If successful, the output should look like so:

Storing WASM: ../artifacts/pyth_bridge.wasm (183749 bytes)
Deploy fee:  44682uluna
Code ID:  53199
Instantiating a contract
Sleeping for 10 seconds for store transaction to finalize.
Instantiated Pyth Bridge at terra123456789yelw23uh22nadqlyjvtl7s5527er97 (0x0000000000000000000000001234567896267ee5479752a7d683e49317ff4294)
Deployed Pyth contract at terra123456789yelw23uh22nadqlyjvtl7s5527er97

Migrating existing contract

If you want to upgrade an existing contract pass --migrate --contract terra123456xyzqwe.. to the above command. This command will upload the code, and with the resulting code id, will migrate the existing contract to the new one:

npm run deploy-pyth -- --network testnet --artifact ../artifacts/pyth_bridge.wasm --mnemonic "..." --migrate --contract "terra123..."

If successful, the output should look like so:

Storing WASM: ../artifacts/pyth_bridge.wasm (183749 bytes)
Deploy fee:  44682uluna
Code ID:  53227
Sleeping for 10 seconds for store transaction to finalize.
Migrating contract terra1rhjej5gkyelw23uh22nadqlyjvtl7s5527er97 to 53227
Contract terra1rhjej5gkyelw23uh22nadqlyjvtl7s5527er97 code_id successfully updated to 53227

Common Errors

While running the instantiation/migration commands you might get the following errors:

  • Gateway timeout: This error means that the request timed out. It is good to double check with terra finder as sometimes transactions succeed despite being timed out.
  • Account sequence mismatch: Transactions from an account should have an increasing sequence number. This error happens when a transaction from the same sender is not fully synchronized with the terra RPC and an old sequence number is used. This is likely to happen because the deploy script sends two transactions: one to submit the code, and one to do the instantiation/migration.

You can rerun your command if you encounter any of the above errors. If an error occurs after the new code is uploaded, you can avoid re-uploading the code and use the uploaded code for instantiation/migration. You can use the printed code id in the logs by passing --code-id <codeId> instead of --artifact. If you do so, the script will skip uploading the code and instantiate/migrate the contract with the given code id.

An example command using an existing code id looks like so:

npm run deploy-pyth -- --network testnet --code-id 50123 --mnemonic "..." --migrate --contract "terra123..."