Skip to content

Commit

Permalink
feat: governance scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mrshiposha committed Oct 17, 2023
1 parent 1f26742 commit 881f1b1
Show file tree
Hide file tree
Showing 5 changed files with 681 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gov/scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules/
.yarn/cache
.yarn/install-state.gz
16 changes: 16 additions & 0 deletions gov/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "gov-scripts",
"version": "1.0.0",
"description": "Governance Scripts",
"license": "MIT",
"type": "module",
"scripts": {
"propose-upgrade": "ts-node --esm ./src/proposeupgrade.ts"
},
"dependencies": {
"@polkadot/api": "^10.10.1",
"@types/node": "^20.4.2",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
}
39 changes: 39 additions & 0 deletions gov/scripts/src/proposeupgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { blake2AsHex } from '@polkadot/util-crypto';
import { readFileSync } from 'fs';

async function main() {
const networkUrl = process.argv[2];
const wasmFile = process.argv[3];

const wsProvider = new WsProvider(networkUrl);
const api = await ApiPromise.create({ provider: wsProvider });

const wasmFileBytes = readFileSync(wasmFile);
const wasmFileHash = blake2AsHex(wasmFileBytes, 256);

const authorizeUpgrade = api.tx.parachainSystem.authorizeUpgrade(wasmFileHash, true);

const councilMembers = (await api.query.council.members()).toJSON() as any[];
const councilProposalThreshold = Math.floor(councilMembers.length / 2) + 1;

const democracyProposal = api.tx.democracy.externalProposeDefault({
Inline: authorizeUpgrade.method.toHex(),
});

const councilProposal = api.tx.council.propose(
councilProposalThreshold,
democracyProposal,
democracyProposal.method.encodedLength,
);

const encodedCall = councilProposal.method.toHex();

console.log('-----------------');
console.log('Upgrade Proposal: ', `https://polkadot.js.org/apps/?rpc=${networkUrl}#/extrinsics/decode/${encodedCall}`);
console.log('-----------------');

await api.disconnect();
}

await main();
17 changes: 17 additions & 0 deletions gov/scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES2020",
"moduleResolution": "node",
"esModuleInterop": true,
"resolveJsonModule": true,
"module": "ESNext",
"sourceMap": true,
"outDir": "dist",
"strict": true
},
"include": ["./src/**/*"],
"lib": ["es2017"],
"ts-node": {
"experimentalSpecifierResolution": "node"
}
}
Loading

0 comments on commit 881f1b1

Please sign in to comment.