Skip to content

Commit

Permalink
Merge pull request #351 from mangata-finance/feature/councilActionsFo…
Browse files Browse the repository at this point in the history
…rCliTool

Feature/council actions for cli tool
  • Loading branch information
goncer authored Dec 1, 2023
2 parents 74c6ead + a8d445f commit 6918fc5
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 3 deletions.
48 changes: 48 additions & 0 deletions cliTool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import {
replaceByStateCall,
burnAllTokensFromPool,
createProposal,
printAllTxsDoneByUser,
vote,
close,
} from "../utils/setupsOnTheGo";
import {
findErrorMetadata,
Expand Down Expand Up @@ -56,6 +59,8 @@ async function app(): Promise<any> {
choices: [
"Setup rewards with default users",
"Create Proposal",
"Vote",
"CloseProposal",
"Setup a collator with token",
"Join as candidate",
"Fill with candidates",
Expand Down Expand Up @@ -84,6 +89,7 @@ async function app(): Promise<any> {
"testTokensForUsers",
"rpc_chops",
"Empty pool created by default users",
"Print user txs",
],
})
.then(async (answers: { option: string | string[] }) => {
Expand All @@ -109,6 +115,48 @@ async function app(): Promise<any> {
await burnAllTokensFromPool(new BN(answers.liqToken));
});
}
if (answers.option.includes("Vote")) {
return inquirer
.prompt([
{
type: "input",
name: "proposalId",
message: " id",
default: "0",
},
])
.then(async (answers: { proposalId: number }) => {
await vote(answers.proposalId);
});
}
if (answers.option.includes("CloseProposal")) {
return inquirer
.prompt([
{
type: "input",
name: "proposalId",
message: " id",
default: "0",
},
])
.then(async (answers: { proposalId: number }) => {
await close(answers.proposalId);
});
}
if (answers.option.includes("Print user txs")) {
return inquirer
.prompt([
{
type: "input",
name: "userAddress",
message: "default Alice",
default: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
},
])
.then(async (answers: { userAddress: string }) => {
await printAllTxsDoneByUser(answers.userAddress);
});
}
if (answers.option.includes("Setup a collator with token")) {
return inquirer
.prompt([
Expand Down
90 changes: 87 additions & 3 deletions utils/setupsOnTheGo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
calculate_buy_price_id_rpc,
} from "./tx";
import { User } from "./User";
import { getEnvironmentRequiredVars, getUserBalanceOfToken } from "./utils";
import {
getBlockNumber,
getEnvironmentRequiredVars,
getUserBalanceOfToken,
} from "./utils";
import { Xyk } from "./xyk";
import { getApi, api, initApi, getMangataInstance } from "./api";
import { BN_ZERO, signTx } from "@mangata-finance/sdk";
Expand All @@ -26,6 +30,8 @@ import { Staking, AggregatorOptions, tokenOriginEnum } from "./Staking";
import { hexToBn } from "@polkadot/util";
import { Bootstrap } from "./Bootstrap";
import assert from "assert";
import { testLog } from "./Logger";
import { Council } from "./Council";
const tokenOrigin = tokenOriginEnum.ActivatedUnstakedReserves;

export async function vetoMotion(motionId: number) {
Expand All @@ -51,6 +57,63 @@ export async function vetoMotion(motionId: number) {
),
);
}
export async function vote(motionId: number) {
await setupApi();
await setupUsers();
await initApi();
const api = await getApi();
const allProposals = await api.query.council.voting.entries();
const allMembers = await api.query.council.members();

const proposal = allProposals.find(
(x) =>
JSON.parse(JSON.stringify(x[1].toHuman())).index === motionId.toString(),
);
console.info("proposal " + JSON.stringify(allProposals[0][0].toHuman()));
const hash = proposal?.[0].toHuman()!.toString();
console.info("hash " + hash);
const txs: Extrinsic[] = [];
allMembers.forEach((x) => {
txs.push(
Sudo.sudoAsWithAddressString(
x.toHuman()!.toString(),
Council.vote(hash!, motionId, "aye"),
),
);
});

await Sudo.batchAsSudoFinalized(...txs);
}
export async function close(motionId: number) {
const fundAcc = "5Gc1GyxLPr1A4jE1U7u9LFYuFftDjeSYZWQXHgejQhSdEN4s";
await setupApi();
await setupUsers();
await initApi();
const api = await getApi();
const allProposals = await api.query.council.voting.entries();

const proposal = allProposals.find(
(x) =>
JSON.parse(JSON.stringify(x[1].toHuman())).index === motionId.toString(),
);
console.info("proposal " + JSON.stringify(allProposals[0][0].toHuman()));
const hash = proposal?.[0].toHuman()!.toString();
console.info("hash " + hash);
await Sudo.batchAsSudoFinalized(
Sudo.sudoAsWithAddressString(
fundAcc,
api.tx.council.close(
hash!,
motionId,
{
refTime: 97042819915,
proofSize: 100000,
},
1000000,
),
),
);
}

export async function setupACouncilWithDefaultUsers() {
await setupApi();
Expand Down Expand Up @@ -227,7 +290,28 @@ export async function setupTokenWithRewardsForDefaultUsers() {
await waitForRewards(testUser4, liqId);
return { users, liqId, sudo, token2 };
}
export async function printAllTxsDoneByUser(userAddress: string) {
await setupUsers();
await setupApi();
const api = await getApi();
let currBlock = await getBlockNumber();
while (currBlock > 0) {
const blockHash = await api.rpc.chain.getBlockHash(currBlock);
const block = await api.rpc.chain.getBlock(blockHash);

const txs = block.block.extrinsics.filter(
(x: any) => x.signer.toString() === userAddress,
) as any;
const readabaleTxs = txs.map((x: any) => x.toHuman());
// testLog.getLog().info("Block " + currBlock);
if (txs.length > 0) {
testLog.getLog().info("Block " + currBlock);
testLog.getLog().info(JSON.stringify(readabaleTxs));
testLog.getLog().info(JSON.stringify(txs));
}
currBlock--;
}
}
export async function burnAllTokensFromPool(liqToken: BN) {
await setupApi();
await setupUsers();
Expand Down Expand Up @@ -924,8 +1008,8 @@ export async function migrate() {
x[0] === "Vesting" ||
x[0] === "Bootstrap" ||
x[0] === "OrmlXcm" ||
x[0] === "Crowdloan" ||
x[0] === "System",
x[0] === "Crowdloan",
// x[0] === "System",
)
.flatMap((item: any) =>
item[1].map((element: any) => {
Expand Down

0 comments on commit 6918fc5

Please sign in to comment.