-
Notifications
You must be signed in to change notification settings - Fork 5
/
PALTxGenerator.ts
171 lines (142 loc) · 5.3 KB
/
PALTxGenerator.ts
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import { ApiPromise, WsProvider } from '@polkadot/api';
import { cryptoWaitReady, sortAddresses, decodeAddress } from '@polkadot/util-crypto';
import { u8aToHex } from '@polkadot/util';
import { signFakeWithApi } from '@acala-network/chopsticks-utils';
import yargs from 'yargs';
// Get input arguments
const args = yargs.options({
sender: { type: 'string', demandOption: true, alias: 's' },
propose: { type: 'array', demandOption: false, coerce: (arg) => (arg ? [arg[0], arg[1]] : []) }, // [Child Bounty, fee]
accept: { type: 'array', demandOption: false, coerce: (arg) => (arg ? [arg[0]] : []) }, // Child Bounty
award: { type: 'array', demandOption: false, coerce: (arg) => (arg ? [arg[0], arg[1]] : []) }, // [Child Bounty, Beneficiary]
claim: { type: 'array', demandOption: false, coerce: (arg) => (arg ? [arg[0]] : []) }, // Child Bounty
network: { type: 'string', demandOption: false, default: 'polkadot', alias: 'n' },
chopsticks: { type: 'bolean', demandOption: false, nargs: 0 }, // Run Chopsticks Test at ws://localhost:8000
}).argv;
// PAL Config
const threshold = 4;
const signatories = sortAddresses([
'14DsLzVyTUTDMm2eP3czwPbH53KgqnQRp3CJJZS9GR7yxGDP',
'14Pn8sUxdEMgFRDgZ5J2VfcUVMLaMQhst9XuvCj9mKJYUAN2',
'1brScQ9KDuFB2EsBc93smHY5T464gjWzzvtnJbBwKofTqad',
'15BERoWxrWC61cAb4JjpUdM7sy8FAS9uduismDbZ7PURZLto',
'15aSnCUARuwBoLYn6nkFj5ap2DUfRmKcXJaAotfVwvVQxNK3',
'13zU1pipCuijDA1eWdHPnDgEHh3BvDJ9GsPMMFFvE5p6GF4D',
'16AhqStFQa8GrffE7WapHrUQ29dmioZHuwFTn4z9fQ7WBGBZ',
]);
const parentBounty = 22;
const palCurator = '167dwA1UDmWSBRrFd9dXqXjdk1NRhqVjenT2FbHGDyy44GjS';
const palReftime = 300000000;
const palProofSize = 10000;
// Create Provider
let wsProvider;
switch (args['network']) {
case 'polkadot':
wsProvider = new WsProvider('wss://polkadot-rpc.dwellir.com');
break;
case 'kusama':
wsProvider = new WsProvider('wss://kusama-rpc.dwellir.com');
break;
}
const main = async () => {
// Initialize WASM
await cryptoWaitReady();
// Wait for Provider
const api = await ApiPromise.create({ provider: wsProvider, noInitWarn: true });
await api.isReady;
// Batch Tx
let batchArgs = [];
// Split the string inputs by commas into arrays
const proposeBountiesID = args['propose'] ? [args['propose'][0]] : [];
const proposeBountiesFees = args['propose'] ? [args['propose'][1]] : [];
const acceptBounties = args['accept'] ? [args['accept'][0]] : [];
const awardBounties = args['award'] ? [args['award'][0]] : [];
const awardBeneficiary = args['award'] ? [args['award'][1]] : [];
const claimBounties = args['claim'] ? [args['claim'][0]] : [];
// Check lengths
if (
proposeBountiesID.length !== proposeBountiesFees.length ||
awardBounties.length !== awardBeneficiary.length
) {
throw new Error(
'The size of propose bounties and fees, or award bounties and award beneficiaries must be the same.'
);
}
// Propose Curator
let proposeTx;
for (let i = 0; i < proposeBountiesID.length; i++) {
proposeTx = await api.tx.childBounties.proposeCurator(
parentBounty,
proposeBountiesID[i], // Child Bounty
palCurator,
proposeBountiesFees[i] // Fee
);
batchArgs.push(proposeTx);
}
// Accept Curator
let acceptTx;
for (let i = 0; i < acceptBounties.length; i++) {
acceptTx = await api.tx.childBounties.acceptCurator(
parentBounty,
acceptBounties[i] // Child Bounty
);
batchArgs.push(acceptTx);
}
// Award Child Bounty
let awardTx;
for (let i = 0; i < awardBounties.length; i++) {
awardTx = await api.tx.childBounties.awardChildBounty(
parentBounty,
awardBounties[i], // Child Bounty
awardBeneficiary[i] // Beneficiary
);
batchArgs.push(awardTx);
}
// Claim Child Bounty
let claimTx;
for (let i = 0; i < claimBounties.length; i++) {
claimTx = await api.tx.childBounties.claimChildBounty(
parentBounty,
awardBounties[i] // Child Bounty
);
batchArgs.push(claimTx);
}
// Batch Calls
let batchTx = await api.tx.utility.batch(batchArgs);
console.log(`\nBatch Tx for Chopsticks Test ${batchTx.toHex()}\n`);
console.log(`Batch Tx for Multix Submission ${batchTx.method.toHex()}\n`);
// Proxy call
let proxyTx = await api.tx.proxy.proxy(palCurator, null, batchTx);
//console.log(`Proxy Tx ${proxyTx.method.toHex()}`);
//console.log(`Proxy Tx hash ${blake2AsHex(proxyTx.method.toHex())}\n`);
// Multisig Call
let multisigTx = await api.tx.multisig.asMulti(
threshold,
signatories.filter(
(input) => u8aToHex(decodeAddress(input)) !== u8aToHex(decodeAddress(args['sender']))
),
null,
proxyTx,
{
refTime: palReftime,
proofSize: palProofSize,
}
);
console.log(`Multisig Tx ${multisigTx.toHex()}`);
if (args['chopsticks']) {
console.log('\n--- Chopsticks Testing ---');
const chopsticksWS = 'ws://127.0.0.1:8000';
const chopsticksProvider = new WsProvider(chopsticksWS);
const chopsticksAPI = await ApiPromise.create({
provider: chopsticksProvider,
noInitWarn: true,
});
let chopsticksTx = await chopsticksAPI.tx(batchTx.toHex());
await signFakeWithApi(chopsticksAPI, chopsticksTx, palCurator);
await chopsticksTx.send();
console.log('--- Chopsticks Test Done ---');
await chopsticksAPI.disconnect();
}
await api.disconnect();
};
main();