-
Notifications
You must be signed in to change notification settings - Fork 2
/
purrbox.js
76 lines (70 loc) · 2.11 KB
/
purrbox.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
#!/usr/bin/env -S yarn node
const { calculateFee, GasPrice } = require("@cosmjs/stargate");
const utils = require('./utils');
async function main() {
// 0. Load agent
const config = await utils.getChainConfig()
const coinConfig = await utils.getChainCoinConfig(config)
const agentWallet = await utils.getLabelledWallet(config, utils.agentnyms[0])
const agent = await utils.getAgentClient(config, utils.agentnyms[0])
const managerWallet = await utils.getLabelledWallet(config, utils.catnyms[0])
const managerContract = `${managerWallet.contractAddress}`
const gasPrice = GasPrice.fromString(`0.025${coinConfig.gas}`)
const fee = calculateFee(280_000, gasPrice)
const memo = `Purrrrrrrr...`;
const agentAddress = `${agentWallet.accounts[0].address}`
// TODO: re-enable once contract impl complete
// // 1. Check active tasks in loop until find some
// // GetAgentTasks { account_id: Addr }
// try {
// const q_tx = await agent.queryContractSmart(
// managerContract,
// { get_agent_tasks: { account_id: agentAddress } },
// );
// console.log('get agent tasks', q_tx);
// } catch (e) {
// console.log('GET AGENT FAILED', e);
// return;
// }
// // SIMULATE?!
// try {
// const s_tx = await agent.simulate(
// agentAddress,
// // NOTE: Needs fully formed messages (cosmwasm version, etc)
// [{ proxy_call: {} }],
// memo
// );
// console.log('simulate tx hash', JSON.stringify(s_tx));
// } catch (e) {
// console.log('PROXY_CALL FAILED', e);
// return;
// }
// 2. Execute proxy_call
// ProxyCall {}
try {
const r_tx = await agent.execute(
agentAddress,
managerContract,
{ proxy_call: {} },
fee,
memo
);
console.log('proxy_call tx hash', r_tx.transactionHash, JSON.stringify(r_tx));
} catch (e) {
console.log('PROXY_CALL FAILED', e);
return;
}
// TODO:
// 3. Let it repeat and run 3+ task executions then exit
//
}
main().then(
() => {
console.info("All purring complete.");
process.exit(0);
},
(error) => {
console.error(error);
process.exit(1);
},
);