pyth-crosschain/target_chains/cosmwasm
Dev Kalra 3b03f9eddc
[cosmwasm] instantiate contracts on multiple chains (#799)
* instantiate contracts on multiple chains

* deploy to neurtron

* function not being used anymore

* rename file dir

* better logs

* wormhole guardian upgrade

* set default wormhole contract

* add all to stages to one file

* add extended chain config

* bug fix

* juno deployment

* removed unused parameter

* resolve bug add comments

* typo

* rename to vaa mainnet

* comment

* remove T

* hardcode checksum

* update download method comment

* update package-lock

* update package-json
2023-05-16 13:13:43 +05:30
..
contracts [cosmwasm] osmosis release (#767) 2023-04-17 18:25:09 +05:30
devnet [refactor] Convert hyphen to underscore in the directory tree (#524) 2023-01-24 19:06:22 +01:00
examples/cw-contract [cosmwasm] pyth-sdk-cw update version v1.0.0 (#595) 2023-02-14 20:22:14 +05:30
sdk Fix axios bug by downgrading, bump all dependents (#786) 2023-04-28 10:19:40 -05:00
tools [cosmwasm] instantiate contracts on multiple chains (#799) 2023-05-16 13:13:43 +05:30
wormhole-stub [cosmwasm] instantiate contracts on multiple chains (#799) 2023-05-16 13:13:43 +05:30
.gitignore Wormhole stub (#789) 2023-05-03 20:48:00 +05:30
Cargo.lock [cosmwasm] osmosis release (#767) 2023-04-17 18:25:09 +05:30
Cargo.toml Move cosmwasm sdk into standard tree structure (#761) 2023-04-13 12:27:34 -07:00
README.md [cosmwasm] wormhole stub (#770) 2023-04-20 16:22:06 +05:30

README.md

Pyth CosmWasm

This directory contains the Pyth contract for CosmWasm and utilities to deploy it on CosmWasm chains.

Deployment

Deploying the CosmWasm contract has three 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.
  3. Update contract's admin to itself.

This directory contains the code to perform all the steps. Read below for the details.

Uploading the code

First, build the contracts within the current directory. You must have Docker installed.

cd ./tools
npm ci

# if you want to build specifically for injective
npm run build-contract -- --injective

# else a generic cosmwasm contract can be build using
npm run build-contract -- --cosmwasm

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

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

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

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

Deploying artifact
Storing WASM: ../artifacts/pyth_cosmwasm.wasm (230813 bytes)
Broadcasted transaction hash: "BBD2E5DF5046B24287E63C53852D251D4F7DDD7755E663C9EB67A9B5560DFE4C"
Deployed Code ID:  11

Instantiating new contract

Pyth contract needs the Wormhole core contract deployed on the same chain. Some chains won't have it deployed. In that case, you have to deploy wormhole contract yourself. You can build the contract using the scripts given in wormhole-stub. Run and you will get the compiled contract code in wormhole-stub/artifacts

./build.sh

This command will upload the code and instantiates a new Pyth contract with the given code id:

npm run deploy-pyth -- instantiate --network osmosis_local --code-id 10 --mnemonic "online prefer ..."

If successful, the output should look like so:

Instantiating a contract
Broadcasted transaction hash: "5F9689ACEB5A57868F9B305A211962DEA826B1C47900904D39D61449A095ADE1"
Instantiated pyth at osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d (0xb884f83f981dda1d2f9957cd68e1f19cb49d3c04aea2ecfbe833ddc6b7cac2f7)
Deployed Pyth contract at osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d

Migrating existing contract

If you want to upgrade an existing contract pass use the migrate command as follows. This command will upload the code, and with the given code id, will migrate the existing contract to the new one:

npm run deploy-pyth -- migrate --network osmosis_local --code-id 9 --contract osmo1.. --mnemonic "online prefer ..."

If successful, the output should look like so:

Migrating contract osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d to 9
Broadcasted transaction hash: "8CF74A7FDBA4264DC58418289D6A256DEA3BBFB89ABD6C0D74C0CEBC29418E52"
Contract osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d code_id successfully updated to 9

Updating contract's admin

Pyth contracts are owner of their own. To update a smart contract's admin use the following command.

npm run deploy-pyth -- update-admin --network osmosis_local --new-admin osmo1.. --contract osmo1... --mnemonic "online prefer ..."

The output should be like.

Updating contract's admin
Broadcasted transaction hash: "B8AA9E25F3AF28858464622AFABA0C0157BD0CB1814C6DB62ACDD2D240E5B973"
{
  codeId: 9,
  address: 'osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d',
  creator: 'osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks',
  admin: 'osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d',
  initMsg: undefined
}
Contract's admin successfully updates

Getting contract's info

If you want to check a contract details, use the following command.

npm run deploy-pyth -- get-contract-info --network osmosis_local --contract osmo1... --mnemonic "online prefer ..."

The output should be like:

Fetching contract info for: osmo1v6qjx5smfdxnh5gr8vprswl60rstyprj3wh4gz5mg7gcl7mtl5xqkm7gje
Fetched contract info for: osmo1v6qjx5smfdxnh5gr8vprswl60rstyprj3wh4gz5mg7gcl7mtl5xqkm7gje
{
  codeId: 9,
  address: 'osmo1v6qjx5smfdxnh5gr8vprswl60rstyprj3wh4gz5mg7gcl7mtl5xqkm7gje',
  creator: 'osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks',
  admin: 'osmo1v6qjx5smfdxnh5gr8vprswl60rstyprj3wh4gz5mg7gcl7mtl5xqkm7gje',
  initMsg: undefined
}

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.

Sometimes the output might have some node.js warning. But if you see a similar output as mentioned above. Transaction was successful.