-
Notifications
You must be signed in to change notification settings - Fork 5
/
calculateMoonbeamRefundPinkNCTR.ts
107 lines (97 loc) · 2.47 KB
/
calculateMoonbeamRefundPinkNCTR.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
import { ApiPromise, WsProvider } from '@polkadot/api';
// Create Provider
let wsMBProvider = new WsProvider('wss://wss.api.moonbeam.network');
let wsAHprovider = new WsProvider('wss://asset-hub-polkadot-rpc.dwellir.com');
// Tx Fee Items
let feeAmount = BigInt(1000000000);
let refTime = BigInt(3000000000);
let proofSize = BigInt(50000);
// Transfer Details:
const transferDetails = [
{
token: 23,
name: 'PINK',
amount: BigInt('1212613720000000'),
target: '1yLH66VzPHcJz2uAtBrsL7cXtxZkSRTdHErVy1TWEnSs2wz',
},
{
token: 23,
name: 'PINK',
amount: BigInt('10000000000'),
target: '15BFZxNM6vGErqqkXTmXAkQeifXvFeu9o2CuDVDerjAQbdLK',
},
{
token: 23,
name: 'PINK',
amount: BigInt('6967790000000'),
target: '12UAm1E7fqzZTSeo1GEjxCfWxGBNHUmfVY5XjSAxe4M5i7EY',
},
{
token: 1024,
name: 'NCTR',
amount: BigInt('4187000000000000000000'),
target: '14QYrwn9eVYwRLMzLfoZ3MSw68rTvEYBjMBVCAHeQ1aTig2F',
},
];
const main = async () => {
// Load Provider
const apiMB = await ApiPromise.create({
provider: wsMBProvider,
noInitWarn: true,
});
const apiAH = await ApiPromise.create({
provider: wsAHprovider,
noInitWarn: true,
});
await apiMB.isReady;
await apiAH.isReady;
// Construct AH Call
let batchCall = [];
// Loop to go through Tranfer Details
for (let transfer of transferDetails) {
batchCall.push(
await apiAH.tx.assets.transfer(transfer.token, { Id: transfer.target }, transfer.amount)
);
}
let AHTX = await apiAH.tx.utility.batchAll(batchCall);
console.log(
(await AHTX.paymentInfo('13cKp89NgPL56sRoVRpBcjkGZPrk4Vf4tS6ePUD96XhAXozG')).toHuman()
);
// Build Moonbeam/Moonriver Call
const destAH = {
V4: {
parents: 1,
interior: {
X1: [
{
Parachain: 1000,
},
],
},
},
};
let paraTx = await apiMB.tx.xcmTransactor.transactThroughSovereign(
destAH,
null,
{
currency: {
AsCurrencyId: { ForeignAsset: '42259045809535163221576417993425387648' },
},
feeAmount: feeAmount,
},
AHTX.method.toHex(),
'SovereignAccount',
{
transactRequiredWeightAtMost: { refTime: refTime, proofSize: proofSize },
overallWeight: 'Unlimited',
},
true
);
console.log(`Call to refund users`);
console.log(paraTx.method.toHex());
await apiMB.disconnect();
await apiAH.disconnect();
};
main()
.catch(console.error)
.finally(() => process.exit());