-
Notifications
You must be signed in to change notification settings - Fork 2
/
instantiate.js
executable file
·87 lines (78 loc) · 2.23 KB
/
instantiate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env -S yarn node
const { calculateFee, GasPrice } = require("@cosmjs/stargate");
const fs = require("fs");
const utils = require('./utils');
const getManagerMsg = (coinConfig, managerAddress) => ({
denom: coinConfig.gas,
owner_id: managerAddress,
})
const inits = [
{
catnym: utils.catnyms[0],
label: "Croncat Manager",
msg: null,
contractFile: 'cw_croncat',
uploadFee: 4_500_000,
initFee: 1_500_000,
},
{
catnym: utils.catnyms[1],
label: "IFTTT Simple",
msg: {
count: 1,
},
contractFile: 'ifttt_simple',
uploadFee: 10_500_000,
initFee: 1_500_000,
},
];
async function initContract(initMsg, config) {
const coinConfig = await utils.getChainCoinConfig(config)
const managerWallet = await utils.getLabelledWallet(config, initMsg.catnym)
const managerAddress = `${managerWallet.accounts[0].address}`
const manager = await utils.getClient(managerWallet.mnemonic, config)
const wasm = fs.readFileSync(__dirname + `/res/${initMsg.contractFile}.wasm`)
const gasPrice = GasPrice.fromString(`0.00000${coinConfig.gas}`)
const uploadFee = calculateFee(initMsg.uploadFee, gasPrice)
const uploadReceipt = await manager.upload(
managerAddress,
wasm,
uploadFee,
"Upload cw_croncat contract",
);
console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`);
const instantiateFee = calculateFee(initMsg.initFee, gasPrice);
let { label, msg } = initMsg
if (!msg) msg = getManagerMsg(coinConfig, managerAddress)
const { contractAddress } = await manager.instantiate(
managerAddress,
uploadReceipt.codeId,
msg,
label,
instantiateFee,
"auto",
{
memo: `MEOW! Cron.cat`,
admin: managerAddress,
},
);
console.info(`Contract instantiated at ${contractAddress}`);
// update the wallet to use the contract address later
await utils.updateContractWallet(config, initMsg.catnym, { contractAddress })
}
async function main() {
const config = await utils.getChainConfig()
for (const init of inits) {
await initContract(init, config)
}
}
main().then(
() => {
console.info("All done, purr time.");
process.exit(0);
},
(error) => {
console.error(error);
process.exit(1);
},
);