From 264f33190bb8a74b2090fb775cb39c700e04b9f3 Mon Sep 17 00:00:00 2001 From: The Larry <26318510+0xlarry@users.noreply.github.com> Date: Wed, 3 Nov 2021 04:48:06 +0000 Subject: [PATCH] Some bug fixes for the scripts --- scripts/1_deploy.ts | 4 +- scripts/3_create_with_key.ts | 4 +- scripts/6_migrate_contracts.ts | 79 +++++++++++++++++++++------------- scripts/9_cosmic_explorer.ts | 4 ++ 4 files changed, 59 insertions(+), 32 deletions(-) diff --git a/scripts/1_deploy.ts b/scripts/1_deploy.ts index e5278b2..e7717d4 100644 --- a/scripts/1_deploy.ts +++ b/scripts/1_deploy.ts @@ -40,7 +40,7 @@ const argv = yargs(process.argv) hubCodeId = argv["hub-code-id"]; } else { process.stdout.write("hub code id not provided! storing code... "); - hubCodeId = await storeCode(terra, deployer, "../../artifacts/trophy_hub.wasm"); + hubCodeId = await storeCode(terra, deployer, "../artifacts/trophy_hub.wasm"); } console.log("hub code id:", hubCodeId); @@ -49,7 +49,7 @@ const argv = yargs(process.argv) nftCodeId = argv["nft-code-id"]; } else { process.stdout.write("nft code id not provided! storing code... "); - nftCodeId = await storeCode(terra, deployer, "../../artifacts/trophy_nft.wasm"); + nftCodeId = await storeCode(terra, deployer, "../artifacts/trophy_nft.wasm"); } console.log("nft code id:", nftCodeId); diff --git a/scripts/3_create_with_key.ts b/scripts/3_create_with_key.ts index 2573afe..e89160d 100644 --- a/scripts/3_create_with_key.ts +++ b/scripts/3_create_with_key.ts @@ -70,7 +70,9 @@ const argv = yargs(process.argv) by_signature: bytesToBase64(pk), }, metadata, - expiry: argv.expiry, + expiry: { + at_time: argv.expiry, + }, max_supply: argv["max-supply"], }, }); diff --git a/scripts/6_migrate_contracts.ts b/scripts/6_migrate_contracts.ts index 2f89e3d..b74bb3a 100644 --- a/scripts/6_migrate_contracts.ts +++ b/scripts/6_migrate_contracts.ts @@ -1,7 +1,13 @@ -import dotenv from "dotenv"; +// This contract uploads latest binaries and migrates and contracts +// +// Usage: +// ts-node 6_migrate_contracts --network {mainnet|testnet|localterra} \ +// --hub-address [--hub-code-id ] \ +// --nft-address [--nft-code-id ] + import yargs from "yargs/yargs"; -import { MnemonicKey, MsgMigrateContract } from "@terra-money/terra.js"; -import { Network, getLcd, sendTransaction, storeCode } from "./helpers"; +import { MsgMigrateContract } from "@terra-money/terra.js"; +import { getLcd, getWallet, sendTransaction, storeCode } from "./helpers"; const argv = yargs(process.argv) .options({ @@ -9,11 +15,19 @@ const argv = yargs(process.argv) type: "string", demandOption: true, }, + "hub-address": { + type: "string", + demandOption: true, + }, "nft-address": { type: "string", demandOption: true, }, - "code-id": { + "hub-code-id": { + type: "number", + demandOption: false, + }, + "nft-code-id": { type: "number", demandOption: false, }, @@ -21,37 +35,44 @@ const argv = yargs(process.argv) .parseSync(); (async function main() { - if (argv.network !== "mainnet" && argv.network !== "testnet") { - throw new Error("invalid network! must be `mainnet` or `testnet`"); - } - const terra = getLcd(argv.network === "mainnet" ? Network.Mainnet : Network.Testnet); - - dotenv.config(); - if (!process.env.MNEMONIC) { - throw new Error("mnemonic phrase not provided!"); - } - const deployer = terra.wallet(new MnemonicKey({ mnemonic: process.env.MNEMONIC })); - console.log("deployer address:", deployer.key.accAddress); + const terra = getLcd(argv.network); + console.log("created LCD client for", argv.network); - const nftAddress = argv["nft-address"]; - console.log("nft address:", nftAddress); - - let codeId: number; - if (argv["code-id"]) { - codeId = argv["code-id"]; - } else { - process.stdout.write("code id not provided! storing code... "); - codeId = await storeCode(terra, deployer, "../../artifacts/trophy_nft.wasm"); - } - console.log("code id:", codeId); + const deployer = getWallet(terra); + console.log("deployer address:", deployer.key.accAddress); process.stdout.write("ready to execute; press any key to continue, CTRL+C to abort..."); process.stdin.once("data", async function () { + let hubCodeId: number; + if (argv["hub-code-id"]) { + hubCodeId = argv["hub-code-id"]; + } else { + process.stdout.write("hub code id not provided! storing code... "); + hubCodeId = await storeCode(terra, deployer, "../artifacts/trophy_hub.wasm"); + } + console.log("success! hub code id:", hubCodeId); + + process.stdout.write("migrating hub contract... "); + const hubTxResult = await sendTransaction(terra, deployer, [ + new MsgMigrateContract(deployer.key.accAddress, argv["hub-address"], hubCodeId, {}), + ]); + console.log("success! txhash:", hubTxResult.txhash); + + let nftCodeId: number; + if (argv["nft-code-id"]) { + nftCodeId = argv["nft-code-id"]; + } else { + process.stdout.write("nft code id not provided! storing code... "); + nftCodeId = await storeCode(terra, deployer, "../artifacts/trophy_nft.wasm"); + } + console.log("success! nft code id:", nftCodeId); + process.stdout.write("migrating nft contract... "); - const { txhash } = await sendTransaction(terra, deployer, [ - new MsgMigrateContract(deployer.key.accAddress, nftAddress, codeId, {}), + const nftTxResult = await sendTransaction(terra, deployer, [ + new MsgMigrateContract(deployer.key.accAddress, argv["nft-address"], nftCodeId, {}), ]); - console.log("success! txhash:", txhash); + console.log("success! txhash:", nftTxResult.txhash); + process.exit(0); }); })(); diff --git a/scripts/9_cosmic_explorer.ts b/scripts/9_cosmic_explorer.ts index e7d7246..8b25ccc 100644 --- a/scripts/9_cosmic_explorer.ts +++ b/scripts/9_cosmic_explorer.ts @@ -1,6 +1,10 @@ // This scripts reads the transaction data produced by `8_fetch_ibc_msgs.ts` and compile a list of // the earliest adoptors of IBC on Terra. Used in the airdrop this trophy: // https://twitter.com/larry0x/status/1454645623123333121 +// +// Usage: +// mongod --dbpath +// ts-node 9_cosmic_explorer.ts import * as fs from "fs"; import * as path from "path";