Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@ The script accepts these inputs fields:

`yarn register-asset -w ws://127.0.0.1:34102 --asset '{ "parents": 1, "interior": "Here" }' -u 1 --name "Parent" --sym "DOT" -d 12 --ed 1 --sufficient true --account-priv-key "0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b" -h true -s council-external -c 2`

## Remove-asset script

Script that allows to remove an asset in a Moonbeam runtime. It particulary does three things:

- Removes the asset from pallet-assets
- Removes asset-mapping in pallet-asset-manager
- Removes the revert code in the asset precompile

The script accepts these inputs fields:
- `--ws-provider or -w`, which specifies the websocket provider to which we will be issuing our requests
- `--asset or -a`, the MultiLocation identifier of the asset to be removed
- `--account-priv-key or -a`, which specifies the account that will submit the proposal
- `--send-preimage-hash or -h`, boolean specifying whether we want to send the preimage hash
- `--send-proposal-as or -s`, optional, but if providede needs to be "democracy" or "council-external" specifying whether we want to send the proposal through regular democracy or as an external proposal that will be voted by the council
- `--collective-threshold or -c`, Optional, number specifying the number of council votes that need to aprove the proposal. If not provided defautls to 1.
- `--at-block`, Optional, number specifying the block number at which the call should get executed.

### Examples to note Pre-Image and propose

`yarn remove-asset -w ws://127.0.0.1:34102 --asset '{ "parents": 1, "interior": "Here" }' --account-priv-key "0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133" -h true -s democracy`

`yarn remove-asset -w ws://127.0.0.1:34102 --asset '{ "parents": 1, "interior": {"X2": [ { "Parachain": 1001 }, { "GeneralIndex": 8 }]}}' --account-priv-key "0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133" -h true -s democracy`

`yarn remove-asset -w ws://127.0.0.1:34102 --asset '{ "parents": 1, "interior": {"X1": { "Parachain": 1001 }}}' --account-priv-key "0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133" -h true -s democracy`

`yarn remove-asset -w ws://127.0.0.1:34102 --asset '{ "parents": 1, "interior": {"X2": [ { "Parachain": 1002 }, { "GeneralKey": "0x000b" }]}}' --account-priv-key "0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133" -h true -s democracy`

### Example to note Pre-Image and propose through council

`yarn register-asset -w ws://127.0.0.1:34102 --asset '{ "parents": 1, "interior": "Here" }' -u 1 --name "Parent" --sym "DOT" -d 12 --ed 1 --sufficient true --account-priv-key "0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b" -h true -s council-external -c 2`


## XCM-initializer script

Script that allows to initialize XCM in a Moonbeam runtime. It particularly does:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"license": "ISC",
"scripts": {
"register-asset": "ts-node 'scripts/xcm-asset-registrator.ts'",
"remove-asset": "ts-node 'scripts/xcm-asset-remover.ts'",
"initialize-xcm": "ts-node 'scripts/xcm-initializer.ts'",
"hrmp-manipulator": "ts-node 'scripts/hrmp-channel-manipulator.ts'",
"set-transact-info": "ts-node 'scripts/xcm-transactor-info-setter.ts'",
Expand Down
2 changes: 1 addition & 1 deletion scripts/xcm-asset-registrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function main () {
const sourceLocation = { XCM: asset };

registerTxs.push(
api.tx.assetManager.registerAsset(
api.tx.assetManager.registerForeignAsset(
sourceLocation,
assetMetadata,
args["existential-deposit"],
Expand Down
93 changes: 93 additions & 0 deletions scripts/xcm-asset-remover.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Import
import { ApiPromise, WsProvider } from '@polkadot/api';
import {u8aToHex, hexToU8a} from '@polkadot/util';

import {blake2AsHex, xxhashAsU8a, blake2AsU8a} from '@polkadot/util-crypto';
import yargs from 'yargs';
import { Keyring } from "@polkadot/api";
import { MultiLocation } from '@polkadot/types/interfaces';
import type { SubmittableExtrinsic } from "@polkadot/api/promise/types";

const args = yargs.options({
'ws-provider': {type: 'string', demandOption: true, alias: 'w'},
'asset': {type: 'string', demandOption: true, alias: 'a'},
'account-priv-key': {type: 'string', demandOption: false, alias: 'account'},
'send-preimage-hash': {type: 'boolean', demandOption: false, alias: 'h'},
'send-proposal-as': {choices: ['democracy', 'council-external'], demandOption: false, alias: 's'},
'collective-threshold': {type: 'number', demandOption: false, alias: 'c'},
'at-block': {type: 'number', demandOption: false},
}).argv;

const PROPOSAL_AMOUNT = 10000000000000000000n
// Construct
const wsProvider = new WsProvider(args['ws-provider']);

async function main () {
const api = await ApiPromise.create({ provider: wsProvider });
const collectiveThreshold = (args['collective-threshold']) ? args['collective-threshold'] :1;

const keyring = new Keyring({ type: "ethereum" });

const registerTxs = [];
const asset: MultiLocation = api.createType("MultiLocation", JSON.parse(args["asset"]));

const assetId = u8aToHex(api.registry.hash(asset.toU8a()).slice(0,16).reverse());
const sourceLocation = { XCM: asset };

let assetDetails = ((await api.query.assets.asset(assetId)) as any).unwrap();

let witness = api.createType("PalletAssetsDestroyWitness", {
accounts: assetDetails.accounts,
sufficients: assetDetails.sufficients,
approvals: assetDetails.approvals,
});

let numSupportedAssets = ((await api.query.assetManager.supportedFeePaymentAssets()) as any).length;

// This removes from every pallet, including the EVM side of things
registerTxs.push(
api.tx.assetManager.destroyForeignAsset(
assetId,
witness,
numSupportedAssets
)
);

const batchCall = api.tx.utility.batchAll(registerTxs);

const toPropose = args['at-block'] ?
api.tx.scheduler.schedule(args["at-block"], null, 0, {Value: batchCall}) :
batchCall;

const account = await keyring.addFromUri(args['account-priv-key'], null, "ethereum");
const { nonce: rawNonce, data: balance } = await api.query.system.account(account.address) as any;
let nonce = BigInt(rawNonce.toString());

// We just prepare the proposals
let encodedProposal = toPropose?.method.toHex() || "";
let encodedHash = blake2AsHex(encodedProposal);
console.log("Encoded proposal hash for complete is %s", encodedHash);
console.log("Encoded length %d", encodedProposal.length);

if (args["send-preimage-hash"]) {
await api.tx.democracy
.notePreimage(encodedProposal)
.signAndSend(account, { nonce: nonce++ });
}

if (args["send-proposal-as"] == 'democracy') {
await api.tx.democracy
.propose(encodedHash, PROPOSAL_AMOUNT)
.signAndSend(account, { nonce: nonce++ });
}
else if (args["send-proposal-as"] == 'council-external') {
let external = api.tx.democracy.externalProposeMajority(encodedHash)

await api.tx.councilCollective
.propose(collectiveThreshold, external, external.length)
.signAndSend(account, { nonce: nonce++ });
}
}


main().catch(console.error).finally(() => process.exit());