Skip to content

Commit

Permalink
feat: migrate to commander
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Sep 7, 2023
1 parent 35cee9f commit 42526f7
Show file tree
Hide file tree
Showing 8 changed files with 2,908 additions and 29 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@
},
"dependencies": {
"@bgd-labs/aave-address-book": "2.3.0",
"@commander-js/extra-typings": "^11.0.0",
"bs58": "^5.0.0",
"chalk": "^4.1.2",
"commander": "^11.0.0",
"dotenv": "^16.3.1",
"gray-matter": "^4.0.3",
"ipfs-only-hash": "^4.0.0",
Expand Down
24 changes: 16 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
#!/usr/bin/env node
import 'dotenv/config';
import { Command } from '@commander-js/extra-typings';
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
import * as ipfsCmd from './commands/ipfs-upload';
import * as diffSnapshot from './commands/diff-snaphots';
import * as simulateProposal from './commands/simulate-proposal';
import * as simulateProposalV3 from './commands/simulate-proposal-v3';
import { addCommand as addGovernanceV3 } from './commands/governance-v3';
import * as fork from './commands/fork';

yargs(hideBin(process.argv))
.command(ipfsCmd)
.command(diffSnapshot)
.command(simulateProposal)
.command(fork)
.command(simulateProposalV3)
.demandCommand().argv;
// yargs(hideBin(process.argv))
// .command(ipfsCmd)
// .command(diffSnapshot)
// .command(simulateProposal)
// .command(fork)
// .command(governanceV3)
// .demandCommand().argv;

const program = new Command();

program.name('aave-cli').description('CLI to interact with the aave ecosystem').version('0.0.0').showHelpAfterError();
addGovernanceV3(program);

program.parse();
100 changes: 100 additions & 0 deletions src/commands/governance-v3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { Command } from '@commander-js/extra-typings';
import { simulateProposal } from '../simulate/govv3/simulate';
import { GovernanceV3Sepolia } from '@bgd-labs/aave-address-book';
import { getGovernance } from '../simulate/govv3/governance';
import { createPublicClient } from 'viem';
import { sepoliaClient } from '../utils/rpcClients';
import { logInfo } from '../utils/logger';

export const command = 'governance-v3 [proposalId]';

export const describe = 'interact with governance v3';

export const builder = (yargs) =>
yargs
.option('chainId', {
type: 'number',
describe: 'the chainId to fork',
})
.option('blockNumber', {
type: 'number',
describe: 'the blocknumber to fork (latest if omitted)',
})
.option('alias', {
type: 'string',
describe: 'custom alias',
})
.option('proposalId', {
type: 'number',
describe: 'Proposal or actionSetId',
})
.option('payloadAddress', {
type: 'string',
describe: 'address of the payload to execute',
})
.option('executor', {
type: 'string',
describe: '(optional) address of the executor',
});

export const handler = async function (argv) {
if (argv.proposalId == undefined) throw new Error('proposalId is required');
const proposalId = BigInt(argv.proposalId);
const result = await simulateProposal(GovernanceV3Sepolia.GOVERNANCE, proposalId);
// console.log(result);
};

export function addCommand(program: Command) {
const govV3 = program.command('governanceV3').description('interact with governance v3 contracts');

govV3
.command('simulate')
.description('simulates a proposal on tenderly')
.requiredOption('--proposalId <number>', 'proposalId to simulate via tenderly')
.action(async (name, options) => {
const proposalId = BigInt(options.getOptionValue('proposalId'));
await simulateProposal(GovernanceV3Sepolia.GOVERNANCE, proposalId);
});

govV3
.command('view')
.description('shows all the proposals & state')
.action(async () => {
const governance = getGovernance(GovernanceV3Sepolia.GOVERNANCE, sepoliaClient, 3962575n);
const logs = await governance.cacheLogs();
const count = await governance.governanceContract.read.getProposalsCount();
const proposalIds = [...Array(Number(count)).keys()];
for (const proposalId of proposalIds) {
const { createdLog, executedLog, payloadSentLog, queuedLog, proposal } = await governance.getProposal(
BigInt(proposalId),
logs
);
logInfo(
`Proposal ${proposalId}`,
`Proposal created on ${new Date(createdLog.timestamp * 1000).toLocaleString()}`
);
if (queuedLog) {
logInfo(
`Proposal ${proposalId}`,
`Proposal was queued with final votes of ${queuedLog.args.votesFor} to ${
queuedLog.args.votesAgainst
} on ${new Date(queuedLog.timestamp * 1000).toLocaleString()}`
);
}
if (executedLog) {
logInfo(
`Proposal ${proposalId}`,
`Proposal was executed on ${new Date(executedLog.timestamp * 1000).toLocaleString()}`
);
}
}
});

govV3
.command('generateProof')
.description('generates the proof etc')
.requiredOption('--proposalId <number>', 'proposalId to generate the proof for')
.action((name, options) => {
console.log('simulate', options);
});
}
13 changes: 0 additions & 13 deletions src/commands/simulate-proposal-v3.ts

This file was deleted.

10 changes: 3 additions & 7 deletions src/simulate/govv3/simulate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AaveV3Sepolia } from '@bgd-labs/aave-address-book';
import { logError, logInfo, logSuccess } from '../../utils/logger';
import { logInfo } from '../../utils/logger';
import { TenderlySimulationResponse } from '../../utils/tenderlyClient';
import { getGovernance } from './governance';
import { Hex, createPublicClient, http } from 'viem';
import { sepolia, polygonMumbai, bscTestnet, avalancheFuji } from 'viem/chains';
import { PayloadsController, getPayloadsController } from './payloadsController';
import { generateReport } from './generatePayloadReport';
import { sepoliaClient } from '../../utils/rpcClients';

const CHAIN_ID_CLIENT_MAP = {
[sepolia.id]: {
Expand All @@ -28,11 +28,7 @@ const CHAIN_ID_CLIENT_MAP = {

export async function simulateProposal(governanceAddress: Hex, proposalId: bigint) {
logInfo('General', `Running simulation for ${proposalId}`);
const governance = getGovernance(
governanceAddress,
createPublicClient({ chain: sepolia, transport: http(process.env.RPC_SEPOLIA) }),
3962575n
);
const governance = getGovernance(governanceAddress, sepoliaClient, 3962575n);
const logs = await governance.cacheLogs();
const proposal = await governance.getProposal(proposalId, logs);
const payloads: {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/rpcClients.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import 'dotenv/config';
import { createPublicClient, http, fallback } from 'viem';
import { mainnet, arbitrum, polygon, optimism, metis, base } from 'viem/chains';
import { mainnet, arbitrum, polygon, optimism, metis, base, sepolia } from 'viem/chains';

export const mainnetClient = createPublicClient({
chain: mainnet,
Expand Down Expand Up @@ -31,3 +31,5 @@ export const baseClient = createPublicClient({
chain: base,
transport: http(process.env.RPC_BASE),
});

export const sepoliaClient = createPublicClient({ chain: sepolia, transport: http() });
Loading

0 comments on commit 42526f7

Please sign in to comment.