Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Governance scripts signed-off #18

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
674 changes: 674 additions & 0 deletions governance-scripts/LICENSE

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions governance-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# A tool to perform a runtime upgrade using a sudo account.

## Build
```shell
git clone [email protected]:Manta-Network/dev-tools.git
cd dev-tools/governance-scripts
yarn
```

## Configure
Update the mnemonic and the node endpoint in any of the scripts to a real account and endpoint, before running them.
120 changes: 120 additions & 0 deletions governance-scripts/accept-and-request-parallel-hrmp-channel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api');
const { blake2AsHex } = require("@polkadot/util-crypto");
const { XcmVersionedMultiLocation } = require("@polkadot/types/lookup");

const keyring = new Keyring({ type: 'sr25519' });

const fs = require('fs');

// Create a promise API instance of the passed in node address.
async function createPromiseApi(nodeAddress) {
const wsProvider = new WsProvider(nodeAddress);
const api = await new ApiPromise({ provider: wsProvider });
await api.isReady;
return api;
}

async function main() {
const nodeAddress = 'ws://127.0.0.1:9801';
const api = await createPromiseApi(nodeAddress);
const aliceKey = keyring.addFromMnemonic("bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice");

const xcmFee = "1000000000000";
const transactWeight = "3000000000";
const transact = "0x1800083c01250800003c0025080000e803000000900100";
const calamariSovereignAddress = "0x7061726124080000000000000000000000000000000000000000000000000000";

const withdrawAssetInstruction = api.createType("XcmV2Instruction", {
withdrawAsset: api.createType("XcmV1MultiassetMultiAssets", [{
id: api.createType("XcmV1MultiassetAssetId", {
concrete: api.createType("XcmV1MultiLocation", {
parents: 0,
interior: api.createType("XcmV1MultilocationJunctions", {
here: true
})
})
}),
fun: api.createType("XcmV1MultiassetFungibility", {
fungible: xcmFee
})
}])
});
const buyExecutionInstruction = api.createType("XcmV2Instruction", {
buyExecution: {
fees: api.createType("XcmV1MultiAsset", {
id: api.createType("XcmV1MultiassetAssetId", {
concrete: api.createType("XcmV1MultiLocation", {
parents: 0,
interior: api.createType("XcmV1MultilocationJunctions", {
here: true,
}),
}),
}),
fun: api.createType("XcmV1MultiassetFungibility", {
fungible: xcmFee
})
}),
weightLimit: api.createType("XcmV2WeightLimit", {
unlimited: true,
}),
},
});
const transactInstruction = api.createType("XcmV2Instruction", {
transact: {
originType: api.createType("XcmV0OriginKind", { native: true }),
requireWeightAtMost: transactWeight,
call: api.createType("XcmDoubleEncoded", {
encoded: transact,
}),
},
});
const refundSurplusInstruction = api.createType("XcmV2Instruction", {
refundSurplus: true,
});
const depositAssetsInstruction = api.createType("XcmV2Instruction", {
depositAsset: {
assets: api.createType("XcmV1MultiassetMultiAssetFilter", { wild: true }),
maxAssets: 1,
beneficiary: api.createType("XcmV1MultiLocation", {
parents: 0,
interior: api.createType("XcmV1MultilocationJunctions", {
x1: api.createType("XcmV1Junction", {
accountId32: {
network: api.createType("XcmV0JunctionNetworkId", { any: true }),
id: calamariSovereignAddress,
},
}),
}),
}),
},
});

const xcmV2 = api.createType("XcmV2Xcm", [
withdrawAssetInstruction,
buyExecutionInstruction,
transactInstruction,
refundSurplusInstruction,
depositAssetsInstruction,
]);
const message = api.createType("XcmVersionedXcm", {
v2: xcmV2,
});

const dest = {
"V1": {
"parents": 1,
"interior": {
"Here": null
}
}
};

const sendXcmTx = await api.tx.polkadotXcm.send(dest, message);
console.log(sendXcmTx);
const encodedCallData = sendXcmTx.method.toHex();
await api.tx.democracy.notePreimage(encodedCallData).signAndSend(aliceKey, {nonce: -1});
let encodedCallDataHash = blake2AsHex(encodedCallData);
console.log("preimage_hash: ", encodedCallDataHash);
}

main().catch(console.error);
20 changes: 20 additions & 0 deletions governance-scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "runtime-upgrade-test",
"version": "1.0.0",
"main": "update-bnb-cost.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "yarn build && polkadot-dev-build-ts"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"@polkadot/api": "^8.11.3",
"@polkadot/types": "^8.11.3",
"minimist": "^1.2.5"
}
}



48 changes: 48 additions & 0 deletions governance-scripts/register-bsx-asset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api');
const { blake2AsHex } = require("@polkadot/util-crypto");

const keyring = new Keyring({ type: 'sr25519' });

const fs = require('fs');

// Create a promise API instance of the passed in node address.
async function createPromiseApi(nodeAddress) {
const wsProvider = new WsProvider(nodeAddress);
const api = await new ApiPromise({ provider: wsProvider });
await api.isReady;
return api;
}

async function main() {
const nodeAddress = 'ws://127.0.0.1:9801';
const api = await createPromiseApi(nodeAddress);
const aliceKey = keyring.addFromMnemonic("bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice");

const location = {
parents: 1,
interior: {
X2: [
{
parachain: 2090
},
{
generalIndex: 0
}
]
}
};
const metadata = { metadata: { name: "Basillisk", symbol: "BSX", decimals: 12, isFrozen: false }, minBalance: 1, isSufficient: true };
const asset_id = await api.query.assetManager.nextAssetId();
const unitsPerSec = "68493150684931506";

const registerAssetTx = await api.tx.assetManager.registerAsset({V1: location}, metadata);
const setUnitsPerSecTx = await api.tx.assetManager.setUnitsPerSecond(asset_id, unitsPerSec);
const batchTx = await api.tx.utility.batch([registerAssetTx, setUnitsPerSecTx]);

const encodedCallData = batchTx.method.toHex();
await api.tx.democracy.notePreimage(encodedCallData).signAndSend(aliceKey, {nonce: -1});
let encodedCallDataHash = blake2AsHex(encodedCallData);
console.log("preimage_hash: ", encodedCallDataHash);
}

main().catch(console.error);
120 changes: 120 additions & 0 deletions governance-scripts/request-basillisk-hrmp-channel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api');
const { blake2AsHex } = require("@polkadot/util-crypto");
const { XcmVersionedMultiLocation } = require("@polkadot/types/lookup");

const keyring = new Keyring({ type: 'sr25519' });

const fs = require('fs');

// Create a promise API instance of the passed in node address.
async function createPromiseApi(nodeAddress) {
const wsProvider = new WsProvider(nodeAddress);
const api = await new ApiPromise({ provider: wsProvider });
await api.isReady;
return api;
}

async function main() {
const nodeAddress = 'ws://127.0.0.1:9801';
const api = await createPromiseApi(nodeAddress);
const aliceKey = keyring.addFromMnemonic("bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice");

const xcmFee = "1000000000000";
const transactWeight = "3000000000";
const transact = "0x3c002a080000e803000000900100";
const calamariSovereignAddress = "0x7061726124080000000000000000000000000000000000000000000000000000";

const withdrawAssetInstruction = api.createType("XcmV2Instruction", {
withdrawAsset: api.createType("XcmV1MultiassetMultiAssets", [{
id: api.createType("XcmV1MultiassetAssetId", {
concrete: api.createType("XcmV1MultiLocation", {
parents: 0,
interior: api.createType("XcmV1MultilocationJunctions", {
here: true
})
})
}),
fun: api.createType("XcmV1MultiassetFungibility", {
fungible: xcmFee
})
}])
});
const buyExecutionInstruction = api.createType("XcmV2Instruction", {
buyExecution: {
fees: api.createType("XcmV1MultiAsset", {
id: api.createType("XcmV1MultiassetAssetId", {
concrete: api.createType("XcmV1MultiLocation", {
parents: 0,
interior: api.createType("XcmV1MultilocationJunctions", {
here: true,
}),
}),
}),
fun: api.createType("XcmV1MultiassetFungibility", {
fungible: xcmFee
})
}),
weightLimit: api.createType("XcmV2WeightLimit", {
unlimited: true,
}),
},
});
const transactInstruction = api.createType("XcmV2Instruction", {
transact: {
originType: api.createType("XcmV0OriginKind", { native: true }),
requireWeightAtMost: transactWeight,
call: api.createType("XcmDoubleEncoded", {
encoded: transact,
}),
},
});
const refundSurplusInstruction = api.createType("XcmV2Instruction", {
refundSurplus: true,
});
const depositAssetsInstruction = api.createType("XcmV2Instruction", {
depositAsset: {
assets: api.createType("XcmV1MultiassetMultiAssetFilter", { wild: true }),
maxAssets: 1,
beneficiary: api.createType("XcmV1MultiLocation", {
parents: 0,
interior: api.createType("XcmV1MultilocationJunctions", {
x1: api.createType("XcmV1Junction", {
accountId32: {
network: api.createType("XcmV0JunctionNetworkId", { any: true }),
id: calamariSovereignAddress,
},
}),
}),
}),
},
});

const xcmV2 = api.createType("XcmV2Xcm", [
withdrawAssetInstruction,
buyExecutionInstruction,
transactInstruction,
refundSurplusInstruction,
depositAssetsInstruction,
]);
const message = api.createType("XcmVersionedXcm", {
v2: xcmV2,
});

const dest = {
"V1": {
"parents": 1,
"interior": {
"Here": null
}
}
};

const sendXcmTx = await api.tx.polkadotXcm.send(dest, message);
console.log(sendXcmTx);
const encodedCallData = sendXcmTx.method.toHex();
await api.tx.democracy.notePreimage(encodedCallData).signAndSend(aliceKey, {nonce: -1});
let encodedCallDataHash = blake2AsHex(encodedCallData);
console.log("preimage_hash: ", encodedCallDataHash);
}

main().catch(console.error);
28 changes: 28 additions & 0 deletions governance-scripts/runtime-upgrade-manta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api');
const { blake2AsHex } = require("@polkadot/util-crypto");

const keyring = new Keyring({ type: 'sr25519' });

const fs = require('fs');

// Create a promise API instance of the passed in node address.
async function createPromiseApi(nodeAddress) {
const wsProvider = new WsProvider(nodeAddress);
const api = await new ApiPromise({ provider: wsProvider });
await api.isReady;
return api;
}

async function main() {
const nodeAddress = 'ws://127.0.0.1:9801';
const api = await createPromiseApi(nodeAddress);
const aliceKey = keyring.addFromMnemonic("bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice");
const code = fs.readFileSync('manta.wasm').toString('hex');
const authorizeUpgradeTx = await api.tx.parachainSystem.authorizeUpgrade(`0x${code}`);
const encodedCallData = authorizeUpgradeTx.method.toHex();
await api.tx.democracy.notePreimage(encodedCallData).signAndSend(aliceKey, {nonce: -1});
let encodedCallDataHash = blake2AsHex(encodedCallData);
console.log("preimage_hash: ", encodedCallDataHash);
}

main().catch(console.error);
29 changes: 29 additions & 0 deletions governance-scripts/update-bnb-cost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { ApiPromise, WsProvider, Keyring } = require('@polkadot/api');
const { blake2AsHex } = require("@polkadot/util-crypto");

const keyring = new Keyring({ type: 'sr25519' });

const fs = require('fs');

// Create a promise API instance of the passed in node address.
async function createPromiseApi(nodeAddress) {
const wsProvider = new WsProvider(nodeAddress);
const api = await new ApiPromise({ provider: wsProvider });
await api.isReady;
return api;
}

async function main() {
const nodeAddress = 'ws://127.0.0.1:9801';
const api = await createPromiseApi(nodeAddress);
const aliceKey = keyring.addFromMnemonic("bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice");
const newUnitsPerSec = "80590567679958737";
const bnbAssetId = 21;
const updateUnitsSecTx = await api.tx.assetManager.setUnitsPerSecond(bnbAssetId, newUnitsPerSec);
const encodedCallData = updateUnitsSecTx.method.toHex();
await api.tx.democracy.notePreimage(encodedCallData).signAndSend(aliceKey, {nonce: -1});
let encodedCallDataHash = blake2AsHex(encodedCallData);
console.log("preimage_hash: ", encodedCallDataHash);
}

main().catch(console.error);
Loading