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

Feat/seatbelt improvements #128

Merged
merged 12 commits into from
Apr 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
release-type: node
package-name: aave-cli
pull-request-header: 'I have created a release'
pull-request-header: "I have created a release"

release-node:
uses: bgd-labs/github-workflows/.github/workflows/release-node.yml@main
Expand Down
14 changes: 12 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"singleQuote": true,
"printWidth": 120
"overrides": [
{
"files": "*.ts",
"options": {
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false
}
}
]
}
316 changes: 129 additions & 187 deletions CHANGELOG.md

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"dist"
],
"scripts": {
"start": "tsx src/cli.ts",
"start": "node dist/cli.js",
"build": "tsup",
"test": "vitest",
"lint:fix": "bunx prettier . --write",
"lint": "bunx prettier . --check",
"ci:publish": "npm run build && npm publish --access=public"
},
"repository": {
Expand All @@ -25,13 +27,14 @@
"homepage": "https://github.com/bgd-labs/report-engine#readme",
"devDependencies": {
"@types/object-hash": "^3.0.6",
"prettier": "^3.2.5",
"tsup": "^8.0.2",
"tsx": "^4.7.1",
"typescript": "^5.4.2",
"vitest": "^1.3.1"
"tsx": "^4.7.2",
"typescript": "^5.4.5",
"vitest": "^1.5.0"
},
"type": "module",
"main": "./dist/index.cjs",
"main": "./dist/index.js",
"module": "./dist/index.js",
"exports": {
".": {
Expand All @@ -48,13 +51,14 @@
}
},
"bin": {
"aave-cli": "dist/cli.cjs"
"aave-cli": "dist/cli.js"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@bgd-labs/aave-address-book": "^2.24.1",
"@bgd-labs/aave-address-book": "^2.25.1",
"@bgd-labs/aave-v3-governance-cache": "^0.0.8",
"@bgd-labs/js-utils": "^1.3.0",
"@commander-js/extra-typings": "^11.1.0",
"@inquirer/prompts": "^3.3.2",
Expand All @@ -67,7 +71,7 @@
"ipfs-only-hash": "^4.0.0",
"json-bigint": "^1.0.0",
"object-hash": "^3.0.0",
"viem": "^2.8.6",
"viem": "^2.9.20",
"zod": "^3.22.4"
}
}
18 changes: 10 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
#!/usr/bin/env node
import {Command, Option} from '@commander-js/extra-typings';
import 'dotenv/config';
import { Command, Option } from '@commander-js/extra-typings';
import { addCommand as addIpfsCommand } from './commands/ipfsUpload';
import { addCommand as addDiffSnapshots } from './commands/diffSnaphots';
import { addCommand as addGovernance } from './commands/governance';
import { addCommand as addFork } from './commands/fork';
import packageJson from '../package.json';
import {addCommand as addDiffSnapshots} from './commands/diffSnaphots';
import {addCommand as addFork} from './commands/fork';
import {addCommand as addGovernance} from './commands/governance';
import {addCommand as addIpfsCommand} from './commands/ipfsUpload';

const program = new Command();

program
.name('aave-cli')
.description('CLI to interact with the aave ecosystem')
.option('-v, --verbose', 'Showing logs for all the taken steps')
.on('option:verbose', function () {
.on('option:verbose', () => {
process.env.VERBOSE = 'true';
})
.addOption(
new Option('--format <format>', 'Set preferred output format').default('raw').choices(['raw', 'encoded'] as const)
new Option('--format <format>', 'Set preferred output format')
.default('raw')
.choices(['raw', 'encoded'] as const),
)
.on('option:format', function (format) {
.on('option:format', (format) => {
process.env.FORMAT = format;
})
.version(packageJson.version)
Expand Down
12 changes: 6 additions & 6 deletions src/commands/diffSnaphots.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command } from '@commander-js/extra-typings';
import { adiDiffReports } from '../reports/adi-diff-reports';
import { diffReports } from '../reports/diff-reports';
import { readJsonString, readJsonFile } from '../utils/json';
import fs from 'fs';
import { compareStorageLayouts } from '@bgd-labs/js-utils';
import fs from 'node:fs';
import {compareStorageLayouts} from '@bgd-labs/js-utils';
import type {Command} from '@commander-js/extra-typings';
import {adiDiffReports} from '../reports/adi-diff-reports';
import {diffReports} from '../reports/diff-reports';
import {readJsonFile, readJsonString} from '../utils/json';

export function addCommand(program: Command) {
program
Expand Down
65 changes: 39 additions & 26 deletions src/commands/fork.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Command } from '@commander-js/extra-typings';
import { tenderly } from '../utils/tenderlyClient';
import { getGovernance } from '../govv3/governance';
import { getPayloadsController } from '../govv3/payloadsController';
import { Hex, createWalletClient, getContract, http } from 'viem';
import { DEFAULT_GOVERNANCE, DEFAULT_GOVERNANCE_CLIENT, EOA } from '../utils/constants';
import { CHAIN_ID_CLIENT_MAP } from '@bgd-labs/js-utils';
import { findPayloadsController } from '../govv3/utils/checkAddress';
import path from 'path';
import { IPayloadsControllerCore_ABI } from '@bgd-labs/aave-address-book';
import { getTransactionReceipt } from 'viem/actions';
import path from 'node:path';
import {CHAIN_ID_CLIENT_MAP} from '@bgd-labs/js-utils';
import type {Command} from '@commander-js/extra-typings';
import {http, type Hex, createWalletClient} from 'viem';
import {getGovernance} from '../govv3/governance';
import {getPayloadsController} from '../govv3/payloadsController';
import {findPayloadsController} from '../govv3/utils/checkAddress';
import {DEFAULT_GOVERNANCE, DEFAULT_GOVERNANCE_CLIENT, EOA} from '../utils/constants';
import {tenderly} from '../utils/tenderlyClient';

export function addCommand(program: Command) {
program
Expand All @@ -22,14 +20,17 @@ export function addCommand(program: Command) {
.option('--payloadAddress <string>', 'Payload address')
.option('--artifactPath <string>', 'path to the local payload')
.action(async (options) => {
const { chainId, blockNumber, alias, payloadId, proposalId, artifactPath, payloadAddress } = options;
const {chainId, blockNumber, alias, payloadId, proposalId, artifactPath, payloadAddress} =
options;
function getAlias() {
const unix = Math.floor(new Date().getTime() / 1000);
if (alias) {
return `${unix}-${alias}`;
} else if (options.proposalId) {
}
if (options.proposalId) {
return `${unix}-proposalId-${options.proposalId}`;
} else if (options.payloadId) {
}
if (options.payloadId) {
return `${unix}-payloadId-${options.payloadId}`;
}
return 'vanilla-fork';
Expand All @@ -41,7 +42,10 @@ export function addCommand(program: Command) {
blockNumber: Number(blockNumber),
};
if (proposalId) {
const governance = getGovernance({ address: DEFAULT_GOVERNANCE, client: DEFAULT_GOVERNANCE_CLIENT });
const governance = getGovernance({
address: DEFAULT_GOVERNANCE,
client: DEFAULT_GOVERNANCE_CLIENT,
});
const payload = await governance.getSimulationPayloadForExecution(BigInt(proposalId));
const fork = await tenderly.fork({
...forkConfig,
Expand All @@ -51,7 +55,8 @@ export function addCommand(program: Command) {
return;
}
const payloadsControllerAddress = findPayloadsController(forkConfig.chainId);
if (!payloadsControllerAddress) throw new Error('payloadscontroller not found on specified chain');
if (!payloadsControllerAddress)
throw new Error('payloadscontroller not found on specified chain');

if (artifactPath) {
const fork = await tenderly.fork({
Expand All @@ -61,10 +66,13 @@ export function addCommand(program: Command) {
const payload = await tenderly.deployCode(fork, path.join(process.cwd(), artifactPath!));
const walletProvider = createWalletClient({
account: EOA,
chain: { id: fork.forkNetworkId, name: 'tenderly' } as any,
chain: {id: fork.forkNetworkId, name: 'tenderly'} as any,
transport: http(fork.forkUrl),
});
const payloadsController = getPayloadsController(payloadsControllerAddress as Hex, walletProvider);
const payloadsController = getPayloadsController(
payloadsControllerAddress as Hex,
walletProvider,
);
await payloadsController.controllerContract.write.createPayload(
[
[
Expand All @@ -78,20 +86,22 @@ export function addCommand(program: Command) {
},
],
],
{} as any
{} as any,
);
const tenderlyPayload = await payloadsController.getSimulationPayloadForExecution(
Number((await payloadsController.controllerContract.read.getPayloadsCount()) - 1)
Number((await payloadsController.controllerContract.read.getPayloadsCount()) - 1),
);
await tenderly.unwrapAndExecuteSimulationPayloadOnFork(fork, tenderlyPayload);
return;
}
if (payloadId) {
const payloadsController = getPayloadsController(
payloadsControllerAddress as Hex,
CHAIN_ID_CLIENT_MAP[chainId]
CHAIN_ID_CLIENT_MAP[Number(chainId)],
);
const payload = await payloadsController.getSimulationPayloadForExecution(
Number(payloadId),
);
const payload = await payloadsController.getSimulationPayloadForExecution(Number(payloadId));
const fork = await tenderly.fork({
...forkConfig,
blockNumber: forkConfig.blockNumber || payload.block_number,
Expand All @@ -106,10 +116,13 @@ export function addCommand(program: Command) {
});
const walletProvider = createWalletClient({
account: EOA,
chain: { id: fork.forkNetworkId, name: 'tenderly' } as any,
chain: {id: fork.forkNetworkId, name: 'tenderly'} as any,
transport: http(fork.forkUrl),
});
const payloadsController = getPayloadsController(payloadsControllerAddress as Hex, walletProvider);
const payloadsController = getPayloadsController(
payloadsControllerAddress as Hex,
walletProvider,
);
await payloadsController.controllerContract.write.createPayload(
[
[
Expand All @@ -123,10 +136,10 @@ export function addCommand(program: Command) {
},
],
],
{} as any
{} as any,
);
const tenderlyPayload = await payloadsController.getSimulationPayloadForExecution(
Number((await payloadsController.controllerContract.read.getPayloadsCount()) - 1)
Number((await payloadsController.controllerContract.read.getPayloadsCount()) - 1),
);
await tenderly.unwrapAndExecuteSimulationPayloadOnFork(fork, tenderlyPayload);
}
Expand Down
Loading
Loading