Skip to content

Commit

Permalink
Update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
larry0x committed Oct 28, 2021
1 parent 04be050 commit 8fb240a
Show file tree
Hide file tree
Showing 7 changed files with 409 additions and 55 deletions.
3 changes: 1 addition & 2 deletions scripts/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
MNEMONIC=''
CONTRACT_ADDR=''
MNEMONIC=''
58 changes: 58 additions & 0 deletions scripts/1_deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import dotenv from "dotenv";
import yargs from "yargs/yargs";
import { MnemonicKey } from "@terra-money/terra.js";
import { Network, getLcd, storeCode, instantiateContract } from "./helpers";

const argv = yargs(process.argv)
.options({
network: {
type: "string",
demandOption: true,
},
"hub-code-id": {
type: "number",
demandOption: false,
},
"nft-code-id": {
type: "number",
demandOption: false,
},
})
.parseSync();

(async function main() {
dotenv.config();
const network = Network.Testnet;
const terra = getLcd(network);
const deployer = terra.wallet(new MnemonicKey({ mnemonic: process.env.MNEMONIC }));
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("hub code id:", hubCodeId);

let nftCodeId: number;
if (argv["nft-code-id"]) {
nftCodeId = argv["nft-code-id"];
} else {
process.stdout.write("hub code id not provided! storing code... ");
nftCodeId = await storeCode(terra, deployer, "../artifacts/trophy_nft.wasm");
}
console.log("nft code id:", nftCodeId);

process.stdout.write("instantiating hub contract... ");
const hubAddress = await instantiateContract(terra, deployer, hubCodeId, {
nft_code_id: nftCodeId,
});
console.log("success! contract address:", hubAddress);

process.exit(0);
});
})();
52 changes: 39 additions & 13 deletions scripts/mint_trophy.ts → scripts/2_mint_trophy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Wallet, MnemonicKey, MsgExecuteContract } from "@terra-money/terra.js";
import dotenv from "dotenv";
import yargs from "yargs/yargs";
import { Wallet, MnemonicKey, MsgExecuteContract } from "@terra-money/terra.js";
import { Network, getLcd, sendTransaction, fetchDelegators } from "./helpers";
import { Metadata } from "./metadata";

Expand Down Expand Up @@ -29,29 +30,55 @@ function createMintMessages(
return msgs;
}

const argv = yargs(process.argv)
.options({
network: {
type: "string",
demandOption: true,
},
"hub-address": {
type: "string",
demandOption: true,
},
})
.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();
const network = Network.Testnet;
const terra = getLcd(network);
const minter = terra.wallet(new MnemonicKey({ mnemonic: process.env.MNEMONIC }));
console.log("minter address:", minter.key.accAddress);

const hubAddress = process.env.CONTRACT_ADDR;
if (!hubAddress) {
throw new Error("ERR: contract address not provided!");
} else {
console.log("contract address:", hubAddress);
}
const hubAddress = argv["hub-address"];
console.log("hub address:", hubAddress);

const metadata: Metadata = {
name: "Test",
description: "This is a test",
image: "Qmbywr7uHvupdbD6h9tx6vPu3zWY4iskPjYBhSVNreKWFy",
animation_url: "QmVovSXPF4WVKeJJZ4hQ5xxWME1EybVw216JZuXma6tWmF",
image: "ipfs://Qmbywr7uHvupdbD6h9tx6vPu3zWY4iskPjYBhSVNreKWFy",
animation_url: "ipfs://QmVovSXPF4WVKeJJZ4hQ5xxWME1EybVw216JZuXma6tWmF",
};
console.log("metadata:", metadata);

const owners = await fetchDelegators("terravaloper1d3fv2cjukt0e6lrzd8d857jatlkht7wcp85zar");
// option 1. drop NFT to all delegators of a validator. this was used in my "thank you" NFT drop
// const owners = await fetchDelegators("terravaloper1d3fv2cjukt0e6lrzd8d857jatlkht7wcp85zar");
// option 2. drop to 10 random addresses, for testing. these are the 10 test accounts in LocalTerra
const owners = [
"terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v",
"terra17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp",
"terra1757tkx08n0cqrw7p86ny9lnxsqeth0wgp0em95",
"terra199vw7724lzkwz6lf2hsx04lrxfkz09tg8dlp6r",
"terra18wlvftxzj6zt0xugy2lr9nxzu402690ltaf4ss",
"terra1e8ryd9ezefuucd4mje33zdms9m2s90m57878v9",
"terra17tv2hvwpg0ukqgd2y5ct2w54fyan7z0zxrm2f9",
"terra1lkccuqgj6sjwjn8gsa9xlklqv4pmrqg9dx2fxc",
"terra1333veey879eeqcff8j3gfcgwt8cfrg9mq20v6f",
"terra1fmcjjt6yc9wqup2r06urnrd928jhrde6gcld6n",
];
console.log("number of eligible owners:", owners.length);

const createMsg = new MsgExecuteContract(minter.key.accAddress, hubAddress, {
Expand All @@ -62,7 +89,6 @@ function createMintMessages(
const mintMsgs = createMintMessages(minter, hubAddress, 1, owners);
const msgs = [createMsg, ...mintMsgs];
console.log("successfully created execute msgs!");
// console.log(msgs);

process.stdout.write("ready to execute; press any key to continue, CTRL+C to abort...");
process.stdin.once("data", async function () {
Expand Down
55 changes: 55 additions & 0 deletions scripts/3_migrate_nft_contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import dotenv from "dotenv";
import yargs from "yargs/yargs";
import { MnemonicKey, MsgMigrateContract } from "@terra-money/terra.js";
import { Network, getLcd, sendTransaction, storeCode } from "./helpers";
import { number } from "yargs";

const argv = yargs(process.argv)
.options({
network: {
type: "string",
demandOption: true,
},
"nft-address": {
type: "string",
demandOption: true,
},
"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();
const deployer = terra.wallet(new MnemonicKey({ mnemonic: process.env.MNEMONIC }));
console.log("deployer address:", deployer.key.accAddress);

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);

process.stdout.write("ready to execute; press any key to continue, CTRL+C to abort...");
process.stdin.once("data", async function () {
process.stdout.write("migrating nft contract... ");
const { txhash } = await sendTransaction(terra, deployer, [
new MsgMigrateContract(deployer.key.accAddress, nftAddress, codeId, {}),
]);
console.log("success! txhash:", txhash);
process.exit(0);
});
})();
38 changes: 0 additions & 38 deletions scripts/deploy.ts

This file was deleted.

Loading

0 comments on commit 8fb240a

Please sign in to comment.