-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmoonbeamAssetMigration.ts
More file actions
60 lines (47 loc) · 1.62 KB
/
moonbeamAssetMigration.ts
File metadata and controls
60 lines (47 loc) · 1.62 KB
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
/*
Simple script to calculate asset migration
*/
import { ApiPromise, WsProvider } from '@polkadot/api';
import yargs from 'yargs';
// This script will listen to all GLMR transfers (Substrate & Ethereum) and extract the tx hash
// It can be adapted for Moonriver or Moonbase Alpha
const args = yargs.options({
network: { type: 'string', demandOption: true, alias: 'n', default: 'moonbeam' },
}).argv;
// Create Provider
let wsProvider;
if (args['network'] === 'moonbeam') {
wsProvider = new WsProvider('wss://wss.api.moonbeam.network');
} else if (args['network'] === 'moonriver') {
wsProvider = new WsProvider('wss://wss.api.moonriver.moonbeam.network');
} else if (args['network'] === 'moonbase') {
wsProvider = new WsProvider('wss://wss.api.moonbase.moonbeam.network');
} else {
console.error('Network not supported');
process.exit();
}
const main = async () => {
// Load Provider
const api = await ApiPromise.create({
provider: wsProvider,
noInitWarn: true,
});
await api.isReady;
// Get Asset ID
let assets: bigint[] = [];
const assetId = await api.query.assets.asset.entries();
assetId.forEach(([key]) => {
key.args.map((k) => assets.push(BigInt(k.toString().replaceAll(',', ''))));
});
console.log('Assets: ', assets);
let tx = await api.tx.moonbeamLazyMigrations.approveAssetsToMigrate(assets);
console.log(`Non-sudo call: ${tx.method.toHex()}`);
if (args['network'] === 'moonbase') {
let finalTx = await api.tx.sudo.sudo(tx);
console.log('Final Tx: ', finalTx.method.toHex());
}
await api.disconnect();
};
main()
.catch(console.error)
.finally(() => process.exit());