Skip to content

Commit e169da0

Browse files
author
Dev Kalra
authored
[cosmwasm] Deploy tool: Add new commands (update contract admin + get contract info) (#473)
* add terra local config * terra update admin and contract info * osmosis update admin and contract info * update deployer interface * injective update admin and contract info * refactor yargs structure * update injective sdk ts library * update readme.md * error handling for update admin code * fix typo * move logging to the calling function * comment the update admin method
1 parent 5da094f commit e169da0

File tree

12 files changed

+551
-489
lines changed

12 files changed

+551
-489
lines changed

target-chains/cosmwasm/README.md

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ This directory contains the Pyth contract for CosmWasm and utilities to deploy i
44

55
## Deployment
66

7-
Deploying the CosmWasm contract has two steps:
7+
Deploying the CosmWasm contract has three steps:
88

99
1. Upload the code. This step will give you a code id.
1010
2. Either create a new contract or migrate an existing one:
1111
1. Create a new contract that has an address with a code id as its program.
1212
2. Migrating an existing contract code id to the new code id.
13+
3. Update contract's admin to itself.
1314

14-
This directory includes a script to perform both steps. Read below for the details.
15+
This directory contains the code to perform all the steps. Read below for the details.
1516

1617
### Uploading the code
1718

18-
First, build the contracts within [the current directory](./):
19+
First, build the contracts within [the current directory](./). You must have Docker installed.
1920

2021
```sh
2122
bash build.sh
@@ -27,73 +28,102 @@ Then, to deploy the Pyth contract (`pyth_cosmwasm.wasm`), run the following comm
2728

2829
```sh
2930
npm ci # Do it only once to install the required packages
30-
npm run deploy-pyth -- --network terra_testnet --artifact ../artifacts/pyth_cosmwasm.wasm --mnemonic "..."
31+
npm run deploy-pyth -- deploy-artifact --network osmosis_local --mnemonic "online prefer ..." --artifact "../artifacts/pyth_cosmwasm.wasm"
3132
```
3233

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

3536
```sh
36-
Storing WASM: ../artifacts/pyth_cosmwasm.wasm (367689 bytes)
37-
Deploy fee: 88446uluna
38-
Code ID: 2435
37+
Deploying artifact
38+
Storing WASM: ../artifacts/pyth_cosmwasm.wasm (230813 bytes)
39+
Broadcasted transaction hash: "BBD2E5DF5046B24287E63C53852D251D4F7DDD7755E663C9EB67A9B5560DFE4C"
40+
Deployed Code ID: 11
3941
```
4042

41-
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
42-
new contract or upgrade an existing contract you should pass more arguments that are described below.
43-
4443
### Instantiating new contract
4544

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

4947
```sh
50-
npm run deploy-pyth -- --network testnet --artifact ../artifacts/pyth_cosmwasm.wasm --mnemonic "..." --instantiate
48+
npm run deploy-pyth -- instantiate --network osmosis_local --code-id 10 --mnemonic "online prefer ..."
5149
```
5250

5351
If successful, the output should look like so:
5452

5553
```
56-
Storing WASM: ../artifacts/pyth_cosmwasm.wasm (183749 bytes)
57-
Deploy fee: 44682uluna
58-
Code ID: 53199
5954
Instantiating a contract
60-
Sleeping for 10 seconds for store transaction to finalize.
61-
Instantiated Pyth at terra123456789yelw23uh22nadqlyjvtl7s5527er97 (0x0000000000000000000000001234567896267ee5479752a7d683e49317ff4294)
62-
Deployed Pyth contract at terra123456789yelw23uh22nadqlyjvtl7s5527er97
55+
Broadcasted transaction hash: "5F9689ACEB5A57868F9B305A211962DEA826B1C47900904D39D61449A095ADE1"
56+
Instantiated pyth at osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d (0xb884f83f981dda1d2f9957cd68e1f19cb49d3c04aea2ecfbe833ddc6b7cac2f7)
57+
Deployed Pyth contract at osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d
6358
```
6459

6560
### Migrating existing contract
6661

67-
If you want to upgrade an existing contract pass `--migrate --contract terra123456xyzqwe..` to the above command.
68-
This command will upload the code, and with the resulting code id, will migrate the existing contract to the new one:
62+
If you want to upgrade an existing contract pass use the `migrate` command as follows.
63+
This command will upload the code, and with the given code id, will migrate the existing contract to the new one:
6964

7065
```sh
71-
npm run deploy-pyth -- --network testnet --artifact ../artifacts/pyth_cosmwasm.wasm --mnemonic "..." --migrate --contract "terra123..."
66+
npm run deploy-pyth -- migrate --network osmosis_local --code-id 9 --contract osmo1.. --mnemonic "online prefer ..."
7267
```
7368

7469
If successful, the output should look like so:
7570

7671
```
77-
Storing WASM: ../artifacts/pyth_cosmwasm.wasm (183749 bytes)
78-
Deploy fee: 44682uluna
79-
Code ID: 53227
80-
Sleeping for 10 seconds for store transaction to finalize.
81-
Migrating contract terra1rhjej5gkyelw23uh22nadqlyjvtl7s5527er97 to 53227
82-
Contract terra1rhjej5gkyelw23uh22nadqlyjvtl7s5527er97 code_id successfully updated to 53227
72+
Migrating contract osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d to 9
73+
Broadcasted transaction hash: "8CF74A7FDBA4264DC58418289D6A256DEA3BBFB89ABD6C0D74C0CEBC29418E52"
74+
Contract osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d code_id successfully updated to 9
8375
```
8476

85-
### Common Errors
77+
### Updating contract's admin
8678

87-
While running the instantiation/migration commands you might get the following errors:
79+
Pyth contracts are owner of their own. To update a smart contract's admin use the following command.
8880

89-
- 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.
90-
- 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.
81+
```sh
82+
npm run deploy-pyth -- update-admin --network osmosis_local --new-admin osmo1.. --contract osmo1... --mnemonic "online prefer ..."
83+
```
84+
85+
The output should be like.
86+
87+
```
88+
Updating contract's admin
89+
Broadcasted transaction hash: "B8AA9E25F3AF28858464622AFABA0C0157BD0CB1814C6DB62ACDD2D240E5B973"
90+
{
91+
codeId: 9,
92+
address: 'osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d',
93+
creator: 'osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks',
94+
admin: 'osmo1hzz0s0ucrhdp6tue2lxk3c03nj6f60qy463we7lgx0wudd72ctms64096d',
95+
initMsg: undefined
96+
}
97+
Contract's admin successfully updates
98+
```
9199

92-
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
93-
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.
100+
### Getting contract's info
94101

95-
An example command using an existing code id looks like so:
102+
If you want to check a contract details, use the following command.
96103

97104
```sh
98-
npm run deploy-pyth -- --network testnet --code-id 50123 --mnemonic "..." --migrate --contract "terra123..."
105+
npm run deploy-pyth -- get-contract-info --network osmosis_local --contract osmo1... --mnemonic "online prefer ..."
99106
```
107+
108+
The output should be like:
109+
110+
```
111+
Fetching contract info for: osmo1v6qjx5smfdxnh5gr8vprswl60rstyprj3wh4gz5mg7gcl7mtl5xqkm7gje
112+
Fetched contract info for: osmo1v6qjx5smfdxnh5gr8vprswl60rstyprj3wh4gz5mg7gcl7mtl5xqkm7gje
113+
{
114+
codeId: 9,
115+
address: 'osmo1v6qjx5smfdxnh5gr8vprswl60rstyprj3wh4gz5mg7gcl7mtl5xqkm7gje',
116+
creator: 'osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks',
117+
admin: 'osmo1v6qjx5smfdxnh5gr8vprswl60rstyprj3wh4gz5mg7gcl7mtl5xqkm7gje',
118+
initMsg: undefined
119+
}
120+
```
121+
122+
### Common Errors
123+
124+
While running the instantiation/migration commands you might get the following errors:
125+
126+
- 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.
127+
- 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.
128+
129+
Sometimes the output might have some node.js warning. But if you see a similar output as mentioned above. Transaction was successful.

0 commit comments

Comments
 (0)