From 3fc065846e27b67714b49f98a6b8dc5f41c27f78 Mon Sep 17 00:00:00 2001 From: Csongor Kiss Date: Tue, 25 Jan 2022 18:43:34 +0000 Subject: [PATCH] Add terra migrate instructions --- clients/token_bridge/main.ts | 7 +++- terra/README.md | 22 ++++++++++ terra/tools/migrate_testnet.js | 73 ++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 terra/tools/migrate_testnet.js diff --git a/clients/token_bridge/main.ts b/clients/token_bridge/main.ts index b31a53a7f..905bf3a27 100644 --- a/clients/token_bridge/main.ts +++ b/clients/token_bridge/main.ts @@ -130,6 +130,11 @@ yargs(hideBin(process.argv)) type: "string", required: true }) + .option('guardian_secret', { + describe: 'Guardian\'s secret key', + type: "string", + default: "cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0" + }) }, async (argv: any) => { let data = [ "0x", @@ -147,7 +152,7 @@ yargs(hideBin(process.argv)) Math.floor(Math.random() * 100000000), data, [ - "cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0" + argv.guardian_secret ], 0, 0 diff --git a/terra/README.md b/terra/README.md index 67f028263..6b5f72c88 100644 --- a/terra/README.md +++ b/terra/README.md @@ -21,3 +21,25 @@ Storing WASM: ../artifacts/token_bridge.wasm (367689 bytes) Deploy fee: 88446uluna Code ID: 2435 ``` + +# Migrate + +## Mainnet + +Migrations on mainnet have to go through governance. Once the guardians sign the +upgrade VAA, the contract can be upgraded by submitting the signed VAA to the +appropriate contract. For example, to upgrade the token bridge on mainnet, +in `wormhole/clients/token_bridge/`: + +``` sh +node main.js terra execute_governance_vaa --rpc "https://lcd.terra.dev" --chain_id "columbus-5" --mnemonic "..." --token_bridge "terra10nmmwe8r3g99a9newtqa7a75xfgs2e8z87r2sf" +``` + +## Testnet + + +For example, to migrate the token bridge to 37262, run in `tools/`: + +``` sh +node migrate_testnet.js --code_id 37262 --contract terra1pseddrv0yfsn76u4zxrjmtf45kdlmalswdv39a --mnemonic "..." +``` diff --git a/terra/tools/migrate_testnet.js b/terra/tools/migrate_testnet.js new file mode 100644 index 000000000..edf7d30fa --- /dev/null +++ b/terra/tools/migrate_testnet.js @@ -0,0 +1,73 @@ +import { LCDClient, MnemonicKey } from "@terra-money/terra.js"; +import { + MsgMigrateContract, +} from "@terra-money/terra.js"; +import axios from "axios"; +import yargs from "yargs"; +import { hideBin } from "yargs/helpers"; + +export const TERRA_GAS_PRICES_URL = "https://fcd.terra.dev/v1/txs/gas_prices"; + +const argv = yargs(hideBin(process.argv)) + .option('code_id', { + description: 'Which code id to upgrade to', + type: 'number', + }) + .option('mnemonic', { + description: 'Mnemonic (private key)', + type: 'string', + required: true + }) + .option('contract', { + description: 'Contract to upgrade', + type: 'string', + required: true + }) + .help() + .alias('help', 'h').argv; + +/* Set up terra client & wallet */ + +const terra_host = { + URL: "https://bombay-lcd.terra.dev", + chainID: "bombay-12", + name: "testnet", +}; + +const lcd = new LCDClient(terra_host); + +const feeDenoms = ["uluna"]; + +const gasPrices = await axios + .get(TERRA_GAS_PRICES_URL) + .then((result) => result.data); + +const wallet = lcd.wallet( + new MnemonicKey({ + mnemonic: argv.mnemonic + }) +); + +await wallet.sequence(); + +/* Do upgrade */ + +const tx = await wallet.createAndSignTx({ + msgs: [ + new MsgMigrateContract( + wallet.key.accAddress, + argv.contract, + argv.code_id, + { + "action": "" + }, + { uluna: 1000 } + ), + ], + memo: "", + feeDenoms, + gasPrices, +}); + +const rs = await lcd.tx.broadcast(tx); +console.log(rs);