Skip to content

Commit

Permalink
Some bug fixes for the scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
larry0x committed Nov 3, 2021
1 parent 6067da0 commit 264f331
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 32 deletions.
4 changes: 2 additions & 2 deletions scripts/1_deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion scripts/3_create_with_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
},
});
Expand Down
79 changes: 50 additions & 29 deletions scripts/6_migrate_contracts.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,78 @@
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 <string> [--hub-code-id <int>] \
// --nft-address <string> [--nft-code-id <int>]

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({
network: {
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,
},
})
.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);
});
})();
4 changes: 4 additions & 0 deletions scripts/9_cosmic_explorer.ts
Original file line number Diff line number Diff line change
@@ -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 <string>
// ts-node 9_cosmic_explorer.ts

import * as fs from "fs";
import * as path from "path";
Expand Down

0 comments on commit 264f331

Please sign in to comment.