Skip to content

Commit

Permalink
Merge branch 'main' into rq/script-for-removing-corrupted-suicided-co…
Browse files Browse the repository at this point in the history
…ntracts
  • Loading branch information
RomarQ committed May 8, 2024
2 parents b2460e2 + a4629c0 commit 0c80dd6
Show file tree
Hide file tree
Showing 19 changed files with 2,256 additions and 1,327 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
/test
/bins
/build
/docker
/binaries
/_private

.vscode
.github
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Options:
<html>
<head>
<title>Monitoring</title>
<script src="https://unpkg.com/[email protected].49/dist/index.umd.js" charset="UTF-8" integrity="sha384-cZWwBlX0VaNDJ0oOYvE2KSkFHkJIYSgPqjJX3gCuOvwyTvzNs07mjn3q2RzkBurB" crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected].50/dist/index.umd.js" charset="UTF-8" integrity="sha384-I1Ylzk/C47xfrZ2U0Ca/Lxm7J8Q9uQeoshUEGLT9HKjo0lWPLocZodgx1hjd6jjB" crossorigin="anonymous"></script>
<style>
body {
padding: 2rem;
Expand Down
3,439 changes: 2,172 additions & 1,267 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "moonbeam-tools",
"version": "0.0.49",
"version": "0.0.50",
"description": "Set of tools for Moonbeam blockchain",
"exports": {
".": {
Expand All @@ -13,11 +13,11 @@
"browser": "dist/index.umd.js",
"types": "dist/index.d.ts",
"dependencies": {
"@moonbeam-network/api-augment": "^0.2302.0",
"@polkadot/api": "^10.7.2",
"@polkadot/apps-config": "^0.131.3",
"@polkadot/util": "^12.2.1",
"@polkadot/util-crypto": "^12.2.1",
"@moonbeam-network/api-augment": "^0.2902.0",
"@polkadot/api": "^11.0.2",
"@polkadot/apps-config": "^0.137.1",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"chalk": "^4.1.2",
"cli-progress": "^3.11.2",
"debug": "^4.3.4",
Expand Down
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export default [
{
input: "src/index.ts",
output: [
{ file: pkg.main, format: "cjs" },
{ file: pkg.module, format: "es" },
{ file: pkg.main, sourcemap: true, format: "cjs" },
{ file: pkg.module, sourcemap: true, format: "es" },
],
plugins: [
commonjs({
Expand All @@ -57,7 +57,7 @@ export default [
},
{
input: "./build/src/index.d.ts",
output: [{ file: "dist/index.d.ts", format: "es" }],
output: [{ file: "dist/index.d.ts", sourcemap: true, format: "es" }],
plugins: [dts()],
},
];
5 changes: 2 additions & 3 deletions src/libs/helpers/state-manipulator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ await processState(stateFile, stateFile.replace(/.json$/, ".mod.json"), [
relayChain: `rococo-local`,
}),

// Make the Council & Technical committee governed by Alith
new CollectiveManipulator("TechCommitteeCollective", [ALITH_ADDRESS]),
new CollectiveManipulator("CouncilCollective", [ALITH_ADDRESS]),
// Make the Open Technical committee governed by Alith
new CollectiveManipulator("OpenTechCommitteeCollective", [ALITH_ADDRESS]),

// Reset the validation data
new ValidationManipulator(),
Expand Down
6 changes: 2 additions & 4 deletions src/libs/helpers/state-manipulator/state-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ export async function neutralizeExportedState(
name: `Fork Network`,
relayChain: `rococo-local`,
}),
new CollectiveManipulator("TechCommitteeCollective", [ALITH_ADDRESS]),
new CollectiveManipulator("CouncilCollective", [ALITH_ADDRESS]),
new CollectiveManipulator("OpenTechCommitteeCollective", [ALITH_ADDRESS]),
new ValidationManipulator(),
new XCMPManipulator(),
new BalancesManipulator([
Expand Down Expand Up @@ -259,8 +258,7 @@ export async function insertParachainCodeIntoRelay(inFile: string, outFile: stri
name: `Fork Network`,
relayChain: `rococo-local`,
}),
new CollectiveManipulator("TechCommitteeCollective", [ALITH_ADDRESS]),
new CollectiveManipulator("CouncilCollective", [ALITH_ADDRESS]),
new CollectiveManipulator("OpenTechCommitteeCollective", [ALITH_ADDRESS]),
new ValidationManipulator(),
new XCMPManipulator(),
new BalancesManipulator([{ account: ALITH_ADDRESS, amount: 10_000n * 10n ** 18n }]),
Expand Down
18 changes: 13 additions & 5 deletions src/tools/check-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ const main = async () => {

const account = await apiAt.query.system.account(argv.address);

console.log(
`#${blockNumber} - ${
argv.address
} [free: ${account.data.free.toBigInt()}, reserved: ${account.data.reserved.toBigInt()}, miscFrozen: ${account.data.miscFrozen.toBigInt()}, feeFrozen: ${account.data.feeFrozen.toBigInt()}]`,
);
if ("miscFrozen" in account.data) {
console.log(
`#${blockNumber} - ${
argv.address
} [free: ${account.data.free.toBigInt()}, reserved: ${account.data.reserved.toBigInt()}, miscFrozen: ${account.data["miscFrozen"].toBigInt()}, feeFrozen: ${account.data["feeFrozen"].toBigInt()}]`,
);
} else {
console.log(
`#${blockNumber} - ${
argv.address
} [free: ${account.data.free.toBigInt()}, reserved: ${account.data.reserved.toBigInt()}, frozen: ${account.data.frozen.toBigInt()}]`,
);
}
api.disconnect();
};

Expand Down
8 changes: 4 additions & 4 deletions src/tools/fast-execute-chopstick-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ const main = async () => {
const callHash = ongoingData.proposal.isLookup
? ongoingData.proposal.asLookup.toHex()
: ongoingData.proposal.isInline
? blake2AsHex(ongoingData.proposal.asInline.toHex())
: ongoingData.proposal.asLegacy.toHex();
? blake2AsHex(ongoingData.proposal.asInline.toHex())
: ongoingData.proposal.asLegacy.toHex();

const proposalBlockTarget = (await api.rpc.chain.getHeader()).number.toNumber();
const fastProposalData = {
Expand Down Expand Up @@ -219,8 +219,8 @@ const main = async () => {
call.isLookup
? call.asLookup.toHex() == callHash
: call.isInline
? blake2AsHex(call.asInline.toHex()) == callHash
: call.asLegacy.toHex() == callHash
? blake2AsHex(call.asInline.toHex()) == callHash
: call.asLegacy.toHex() == callHash,
);

console.log(
Expand Down
2 changes: 1 addition & 1 deletion src/tools/fast-track-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async function main() {
try {
const collectiveThreshold =
argv["collective-threshold"] ||
Math.ceil(((await api.query.councilCollective.members()).length * 3) / 5);
Math.ceil(((await api.query.openTechCommitteeCollective.members()).length * 3) / 5);

const privKey = argv["alith"] ? ALITH_PRIVATE_KEY : argv["account-priv-key"];
if (!privKey) {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/list-limbo-balance-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const main = async () => {
affectedAccounts.push([
addressesToCheck[idx],
identities[idx],
Web3.utils.fromWei(free),
Web3.utils.fromWei(reserved),
Web3.utils.fromWei(frozen),
Web3.utils.fromWei(free.toString()),
Web3.utils.fromWei(reserved.toString()),
Web3.utils.fromWei(frozen.toString()),
Web3.utils.fromWei(frozen.sub(free).toString()),
]);
}
Expand Down
4 changes: 3 additions & 1 deletion src/tools/list-referendum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const main = async () => {
moonriver: "moonriver",
"Moonbase Alpha": "moonbase",
}[await api.runtimeChain.toString().toLocaleLowerCase()];
for (const referendum of await api.derive.democracy.referendums()) {

const demoReferendum = "democracy" in api.derive ? await api.derive.democracy.referendums() : [];
for (const referendum of demoReferendum) {
let imageText = ""; // TODO refactor
let subText = null; // TODO refactor
if (referendum.image && referendum.image.proposal && referendum.image.proposal) {
Expand Down
4 changes: 2 additions & 2 deletions src/tools/propose-motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function main() {
try {
const collectiveThreshold =
argv["collective-threshold"] ||
Math.ceil(((await api.query.councilCollective.members()).length * 3) / 5);
Math.ceil(((await api.query.openTechCommitteeCollective.members()).length * 3) / 5);

let account: KeyringPair;
let nonce;
Expand All @@ -85,7 +85,7 @@ async function main() {

const external = api.tx.democracy.externalProposeMajority(argv["proposal"]);
await tryProxy(
api.tx.councilCollective.propose(collectiveThreshold, external, external.length),
api.tx.openTechCommitteeCollective.propose(collectiveThreshold, external, external.length),
).signAndSend(account, { nonce: nonce++ }, monitorSubmittedExtrinsic(api, { id: "motion" }));
} finally {
await waitForAllMonitoredExtrinsics();
Expand Down
4 changes: 2 additions & 2 deletions src/tools/upgrade-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function main() {

const collectiveThreshold =
argv["collective-threshold"] ||
Math.ceil(((await api.query.councilCollective.members()).length * 3) / 5);
Math.ceil(((await api.query.openTechCommitteeCollective.members()).length * 3) / 5);
const proposalAmount = api.consts.democracy.minimumDeposit;

let account: KeyringPair;
Expand Down Expand Up @@ -124,7 +124,7 @@ async function main() {
monitorSubmittedExtrinsic(api, { id: "sudo" }),
);
} else {
const proposal = api.tx.parachainSystem.authorizeUpgrade(codeHash);
const proposal = api.tx.parachainSystem.authorizeUpgrade(codeHash, true);

const encodedProposal = proposal.method.toHex();
const encodedHash = blake2AsHex(encodedProposal);
Expand Down
4 changes: 2 additions & 2 deletions src/tools/vote-motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function main() {
try {
const collectiveThreshold =
argv["collective-threshold"] ||
Math.ceil(((await api.query.councilCollective.members()).length * 3) / 5);
Math.ceil(((await api.query.openTechCommitteeCollective.members()).length * 3) / 5);

let account: KeyringPair;
let nonce;
Expand All @@ -85,7 +85,7 @@ async function main() {

const external = api.tx.democracy.externalProposeMajority(argv["proposal"]);
await tryProxy(
api.tx.councilCollective.propose(collectiveThreshold, external, external.length),
api.tx.openTechCommitteeCollective.propose(collectiveThreshold, external, external.length),
).signAndSend(account, { nonce: nonce++ }, monitorSubmittedExtrinsic(api, { id: "motion" }));
} finally {
await waitForAllMonitoredExtrinsics();
Expand Down
5 changes: 3 additions & 2 deletions src/utils/monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ export const getAccountIdentity = async (
: [null, null];
identityCache[account] = {
lastUpdate: Date.now(),
identity,
superOf: superOfIdentity,
identity: identity && ("info" in identity ? identity : identity[0]),
superOf:
superOfIdentity && ("info" in superOfIdentity ? superOfIdentity : superOfIdentity[0]),
};
}

Expand Down
21 changes: 16 additions & 5 deletions src/utils/referenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@ function parseImage(
}

const [proposer, balance] = status.isUnrequested
? status.asUnrequested.deposit
: status.asRequested.deposit.unwrapOrDefault();
? "deposit" in status.asUnrequested
? status.asUnrequested["deposit"]
: status.asUnrequested.ticket
: ("deposit" in status.asRequested
? status.asRequested["deposit"]
: status.asRequested.maybeTicket
).unwrapOrDefault();
let proposal: Call | undefined;

if (bytes) {
Expand All @@ -197,19 +202,25 @@ function parseImage(
}

async function getImageProposal(api: ApiPromise | ApiDecoration<"promise">, hash: string) {
const optStatus = await api.query.preimage.statusFor(hash);
const optStatus =
"requestStatusFor" in api.query.preimage
? await api.query.preimage["requestStatusFor"](hash)
: await api.query.preimage.statusFor(hash);
const status = optStatus.unwrapOr(null) as PalletPreimageRequestStatus;
if (!status) {
return null;
}
const len = status.isRequested
? status.asRequested.len.unwrapOr(0)
? "maybeLen" in status.asRequested
? status.asRequested.maybeLen.unwrapOr(0)
: (status.asRequested["len"] as any).unwrapOr(0)
: status.asUnrequested.len || 0;

const h256Hash = api.registry.createType("H256", hash);

try {
const preImage = await api.query.preimage.preimageFor([h256Hash, len]);
return parseImage(api, [status, preImage.unwrap()]);
return parseImage(api, [status, (preImage as any).unwrap()]);
} catch (e) {
debug(e);
}
Expand Down
32 changes: 18 additions & 14 deletions src/utils/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ApiPromise } from "@polkadot/api";
import { SubmittableExtrinsic } from "@polkadot/api/promise/types";
import { GenericCall } from "@polkadot/types/generic";
import { PalletPreimageRequestStatus } from "@polkadot/types/lookup";
import { Option } from "@polkadot/types";

export const sendAllAndWaitLast = async (extrinsics: SubmittableExtrinsic[]) => {
return new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -156,22 +158,24 @@ export async function callInterpreter(
subCalls: subCallsData,
};
}
const imageStatusFn =
"requestStatusFor" in api.query.preimage
? api.query.preimage["requestStatusFor"]
: api.query.preimage.statusFor;
const callData = nested.inlined
? call.args[nested.argumentPosition]
: await api.query.preimage
.statusFor(call.args[nested.argumentPosition].toHex())
.then((optStatus) => {
if (optStatus.isNone) {
return null;
}
const status = optStatus.unwrap();
const len = status.isRequested
? status.asRequested.len.unwrapOr(0)
: status.asUnrequested.len || 0;
return api.query.preimage
.preimageFor([call.args[nested.argumentPosition].toHex(), len])
.then((preimage) => preimage.unwrap().toHex());
});
: await imageStatusFn(call.args[nested.argumentPosition].toHex()).then((optStatus) => {
if (optStatus.isNone) {
return null;
}
const status = optStatus.unwrap();
const len = status.isRequested
? status.asRequested.len.unwrapOr(0)
: status.asUnrequested.len || 0;
return api.query.preimage
.preimageFor([call.args[nested.argumentPosition].toHex(), len])
.then((preimage: Option<PalletPreimageRequestStatus>) => preimage.unwrap().toHex());
});
if (callData) {
const subCall = await api.registry.createType("Call", callData);
return { text, call, depth: 1, subCalls: [await callInterpreter(api, subCall)] };
Expand Down
3 changes: 1 addition & 2 deletions test/state-manipulation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ describe("State Manipulation", () => {
),
new CollatorManipulator(CHARLETH_ADDRESS, CHARLETH_SESSION_ADDRESS),
new HRMPManipulator(),
new CollectiveManipulator("TechCommitteeCollective", [CHARLETH_ADDRESS, HEATH_ADDRESS]),
new CollectiveManipulator("CouncilCollective", [JUDITH_ADDRESS]),
new CollectiveManipulator("OpenTechCommitteeCollective", [CHARLETH_ADDRESS, HEATH_ADDRESS]),
new ValidationManipulator(),
new XCMPManipulator(),
new SpecManipulator({
Expand Down

0 comments on commit 0c80dd6

Please sign in to comment.