-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
59 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters