Skip to content

Commit f0e8884

Browse files
authored
Abehjati/cleanup-cosmwasm (#243)
* Remove unneeded stuff and warnings * Remove old readme and replaye pyth readme with it * Fix build issue * Revert wormhole contract.rs change * Address review comments * Address review comments * Make Readme more clear
1 parent bf02101 commit f0e8884

32 files changed

+67
-2349
lines changed

Dockerfile.cosmwasm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ FROM cosmwasm/workspace-optimizer:0.12.6@sha256:e6565a5e87c830ef3e8775a9035006b3
55
COPY cosmwasm/Cargo.lock /code/
66
COPY cosmwasm/Cargo.toml /code/
77
COPY cosmwasm/contracts /code/contracts
8-
COPY cosmwasm/packages /code/packages
98
COPY third_party/pyth/p2w-sdk/rust /third_party/pyth/p2w-sdk/rust
109
RUN --mount=type=cache,target=/code/target,id=cosmwasm_target --mount=type=cache,target=/usr/local/cargo/registry optimize_workspace.sh
1110

cosmwasm/README.md

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,93 @@
1-
# Deploy
1+
# Pyth CosmWasm
22

3-
First build the contracts
3+
This directory contains The Pyth contract on CosmWasm and utilities to deploy it in CosmWasm chains.
44

5+
## Deployment
6+
7+
Deploying the CosmWasm contract has two steps:
8+
1. Upload the code. This step will give you a code id.
9+
2. Either create a new contract or migrate an existing one:
10+
1. Create a new contract that has an address with a code id as its program.
11+
2. Migrating an existing contract code id to the new code id.
12+
13+
This directory includes a script to perform both steps. Read below for the details.
14+
15+
### Uploading the code
16+
17+
First, build the contracts within [the current directory](./):
518

619
``` sh
7-
docker build -f Dockerfile.build -o artifacts .
20+
bash build.sh
821
```
922

10-
Then, for example, to deploy `token_bridge.wasm`, run in the `tools` directory
23+
This command will build and save the Pyth contract in the `artifact` directory.
24+
25+
Then, to deploy the Pyth contract (`pyth_bridge.wasm`), run the following command in the `tools` directory:
1126

1227
``` sh
13-
npm ci
14-
node deploy_single.js --network mainnet --artifact ../artifacts/token_bridge.wasm --mnemonic "..."
28+
npm ci # Do it only once to install the required packages
29+
npm run deploy-pyth -- --network testnet --artifact ../artifacts/pyth_bridge.wasm --mnemonic "..."
1530
```
1631

17-
which will print something along the lines of
32+
If successful, this command will print something along the lines of:
1833

1934
``` sh
20-
Storing WASM: ../artifacts/token_bridge.wasm (367689 bytes)
35+
Storing WASM: ../artifacts/pyth_bridge.wasm (367689 bytes)
2136
Deploy fee: 88446uluna
2237
Code ID: 2435
2338
```
2439

25-
# Migrate
40+
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
41+
new contract or upgrade an existing contract you should pass more arguments that are described below.
2642

27-
## Mainnet
43+
### Instantiating new contract
44+
If you want to instantiate a new contract after your deployment, pass `--instantiate` to the above command.
45+
This command will upload the code and instantiates a new Pyth contract with the resulting code id:
2846

29-
Migrations on mainnet have to go through governance. Once the guardians sign the
30-
upgrade VAA, the contract can be upgraded by submitting the signed VAA to the
31-
appropriate contract. For example, to upgrade the token bridge on mainnet,
32-
in `wormhole/clients/token_bridge/`:
47+
``` sh
48+
npm run deploy-pyth -- --network testnet --artifact ../artifacts/pyth_bridge.wasm --mnemonic "..." --instantiate
49+
```
50+
51+
If successful, the output should look like so:
52+
```
53+
Storing WASM: ../artifacts/pyth_bridge.wasm (183749 bytes)
54+
Deploy fee: 44682uluna
55+
Code ID: 53199
56+
Instantiating a contract
57+
Sleeping for 10 seconds for store transaction to finalize.
58+
Instantiated Pyth Bridge at terra123456789yelw23uh22nadqlyjvtl7s5527er97 (0x0000000000000000000000001234567896267ee5479752a7d683e49317ff4294)
59+
Deployed Pyth contract at terra123456789yelw23uh22nadqlyjvtl7s5527er97
60+
```
61+
62+
### Migrating existing contract
63+
If you want to upgrade an existing contract pass `--migrate --contract terra123456xyzqwe..` to the above command.
64+
This command will upload the code, and with the resulting code id, will migrate the existing contract to the new one:
3365

3466
``` sh
35-
node main.js terra execute_governance_vaa <signed VAA (hex)> --rpc "https://lcd.terra.dev" --chain_id "columbus-5" --mnemonic "..." --token_bridge "terra10nmmwe8r3g99a9newtqa7a75xfgs2e8z87r2sf"
67+
npm run deploy-pyth -- --network testnet --artifact ../artifacts/pyth_bridge.wasm --mnemonic "..." --migrate --contract "terra123..."
3668
```
3769

38-
## Testnet
70+
If successful, the output should look like so:
71+
```
72+
Storing WASM: ../artifacts/pyth_bridge.wasm (183749 bytes)
73+
Deploy fee: 44682uluna
74+
Code ID: 53227
75+
Sleeping for 10 seconds for store transaction to finalize.
76+
Migrating contract terra1rhjej5gkyelw23uh22nadqlyjvtl7s5527er97 to 53227
77+
Contract terra1rhjej5gkyelw23uh22nadqlyjvtl7s5527er97 code_id successfully updated to 53227
78+
```
79+
80+
### Common Errors
81+
82+
While running the instantiation/migration commands you might get the following errors:
83+
- 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.
84+
- 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.
3985

86+
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
87+
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.
4088

41-
For example, to migrate the token bridge to 37262, run in `tools/`:
89+
An example command using an existing code id looks like so:
4290

4391
``` sh
44-
node migrate_testnet.js --code_id 37262 --contract terra1pseddrv0yfsn76u4zxrjmtf45kdlmalswdv39a --mnemonic "..."
92+
npm run deploy-pyth -- --network testnet --code-id 50123 --mnemonic "..." --migrate --contract "terra123..."
4593
```

cosmwasm/README.pyth.md

Lines changed: 0 additions & 88 deletions
This file was deleted.

cosmwasm/contracts/wormhole/src/state.rs

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -391,69 +391,3 @@ impl TransferFee {
391391
Ok(TransferFee { amount, recipient })
392392
}
393393
}
394-
395-
#[cfg(test)]
396-
mod tests {
397-
use super::*;
398-
399-
fn build_guardian_set(length: usize) -> GuardianSetInfo {
400-
let mut addresses: Vec<GuardianAddress> = Vec::with_capacity(length);
401-
for _ in 0..length {
402-
addresses.push(GuardianAddress {
403-
bytes: vec![].into(),
404-
});
405-
}
406-
407-
GuardianSetInfo {
408-
addresses,
409-
expiration_time: 0,
410-
}
411-
}
412-
413-
#[test]
414-
fn quardian_set_quorum() {
415-
assert_eq!(build_guardian_set(1).quorum(), 1);
416-
assert_eq!(build_guardian_set(2).quorum(), 2);
417-
assert_eq!(build_guardian_set(3).quorum(), 3);
418-
assert_eq!(build_guardian_set(4).quorum(), 3);
419-
assert_eq!(build_guardian_set(5).quorum(), 4);
420-
assert_eq!(build_guardian_set(6).quorum(), 5);
421-
assert_eq!(build_guardian_set(7).quorum(), 5);
422-
assert_eq!(build_guardian_set(8).quorum(), 6);
423-
assert_eq!(build_guardian_set(9).quorum(), 7);
424-
assert_eq!(build_guardian_set(10).quorum(), 7);
425-
assert_eq!(build_guardian_set(11).quorum(), 8);
426-
assert_eq!(build_guardian_set(12).quorum(), 9);
427-
assert_eq!(build_guardian_set(20).quorum(), 14);
428-
assert_eq!(build_guardian_set(25).quorum(), 17);
429-
assert_eq!(build_guardian_set(100).quorum(), 67);
430-
}
431-
432-
#[test]
433-
fn test_deserialize() {
434-
let x = hex::decode("080000000901007bfa71192f886ab6819fa4862e34b4d178962958d9b2e3d9437338c9e5fde1443b809d2886eaa69e0f0158ea517675d96243c9209c3fe1d94d5b19866654c6980000000b150000000500020001020304000000000000000000000000000000000000000000000000000000000000000000000a0261626364").unwrap();
435-
let v = ParsedVAA::deserialize(x.as_slice()).unwrap();
436-
assert_eq!(
437-
v,
438-
ParsedVAA {
439-
version: 8,
440-
guardian_set_index: 9,
441-
timestamp: 2837,
442-
nonce: 5,
443-
len_signers: 1,
444-
emitter_chain: 2,
445-
emitter_address: vec![
446-
0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
447-
0, 0, 0, 0, 0, 0
448-
],
449-
sequence: 10,
450-
consistency_level: 2,
451-
payload: vec![97, 98, 99, 100],
452-
hash: vec![
453-
195, 10, 19, 96, 8, 61, 218, 69, 160, 238, 165, 142, 105, 119, 139, 121, 212,
454-
73, 238, 179, 13, 80, 245, 224, 75, 110, 163, 8, 185, 132, 55, 34
455-
]
456-
}
457-
);
458-
}
459-
}

cosmwasm/packages/cw721/.cargo/config

Lines changed: 0 additions & 4 deletions
This file was deleted.

cosmwasm/packages/cw721/Cargo.toml

Lines changed: 0 additions & 19 deletions
This file was deleted.

cosmwasm/packages/cw721/NOTICE

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)