Skip to content

Commit

Permalink
fix: remove unchanged eModes from report (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra authored Nov 21, 2024
1 parent 8dffd25 commit 8fc773f
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 74 deletions.
Binary file modified bun.lockb
Binary file not shown.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"@types/object-hash": "^3.0.6",
"prettier": "^3.2.5",
"prettier-plugin-solidity": "^1.4.1",
"tsup": "^8.0.2",
"tsup": "^8.3.5",
"typescript": "^5.4.5",
"vitest": "^2.1.3"
"vitest": "^2.1.5"
},
"type": "module",
"main": "./dist/index.js",
Expand All @@ -57,9 +57,10 @@
"access": "public"
},
"dependencies": {
"@bgd-labs/aave-address-book": "^4.4.0",
"@bgd-labs/aave-address-book": "^4.5.1",
"@bgd-labs/aave-v3-governance-cache": "^1.0.8",
"@bgd-labs/js-utils": "^1.4.6",
"@bgd-labs/rpc-env": "^2.1.1",
"@commander-js/extra-typings": "^12.1.0",
"@inquirer/prompts": "^7.1.0",
"blockstore-core": "^5.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/fork.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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';
import {getClient} from '../utils/getClient';

export function addCommand(program: Command) {
program
Expand Down Expand Up @@ -97,7 +97,7 @@ export function addCommand(program: Command) {
if (payloadId) {
const payloadsController = getPayloadsController(
payloadsControllerAddress as Hex,
CHAIN_ID_CLIENT_MAP[Number(chainId)],
getClient(Number(chainId)),
);
const payload = await payloadsController.getSimulationPayloadForExecution(
Number(payloadId),
Expand Down
29 changes: 7 additions & 22 deletions src/commands/governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
IVotingMachineWithProofs_ABI,
IVotingPortal_ABI,
} from '@bgd-labs/aave-address-book/abis';
import {CHAIN_ID_CLIENT_MAP} from '@bgd-labs/js-utils';
import type {Command} from '@commander-js/extra-typings';
import {confirm, input, select} from '@inquirer/prompts';
import {type Hex, encodeAbiParameters, encodeFunctionData, getContract} from 'viem';
Expand All @@ -23,6 +22,7 @@ import {fileSystemStorageAdapter} from '@bgd-labs/aave-v3-governance-cache/fileS
const localCacheAdapter = customStorageProvider(fileSystemStorageAdapter);

import {refreshCache} from '@bgd-labs/aave-v3-governance-cache/refreshCache';
import {getClient} from '../utils/getClient';

enum DialogOptions {
DETAILS = 0,
Expand Down Expand Up @@ -53,7 +53,7 @@ export function addCommand(program: Command) {
.action(async ({payloadId: _payloadId, chainId}, options) => {
await refreshCache(localCacheAdapter);
const payloadId = Number(_payloadId);
const client = CHAIN_ID_CLIENT_MAP[Number(chainId) as keyof typeof CHAIN_ID_CLIENT_MAP];
const client = getClient(Number(chainId));
const payloadsControllerAddress = findPayloadsController(Number(chainId));
const payloadsController = getPayloadsController(payloadsControllerAddress as Hex, client);
const cache = await localCacheAdapter.getPayload({
Expand Down Expand Up @@ -162,7 +162,7 @@ export function addCommand(program: Command) {
);
if (cache.logs.votingActivatedLog)
logInfo(
'VotingActicated',
'VotingActivated',
toTxLink(
cache.logs.votingActivatedLog.transactionHash,
false,
Expand All @@ -189,11 +189,7 @@ export function addCommand(program: Command) {
logInfo('VotingPortal', cache.proposal.votingPortal);
cache.proposal.payloads.map((payload, ix) => {
logInfo(`Payload.${ix}.accessLevel`, payload.accessLevel);
logInfo(
`Payload.${ix}.chain`,
CHAIN_ID_CLIENT_MAP[Number(payload.chain) as keyof typeof CHAIN_ID_CLIENT_MAP].chain!
.name,
);
logInfo(`Payload.${ix}.chain`, getClient(Number(payload.chain)).chain!.name);
logInfo(`Payload.${ix}.payloadId`, payload.payloadId);
logInfo(`Payload.${ix}.payloadsController`, payload.payloadsController);
});
Expand All @@ -218,14 +214,7 @@ export function addCommand(program: Command) {
const proofs = await governance.getVotingProofs(selectedProposalId, address, chainId);
if (proofs.length === 0) logError('Voting Error', 'You need voting power to vote');
else {
logSuccess(
'VotingMachine',
toAddressLink(
machine,
false,
CHAIN_ID_CLIENT_MAP[Number(chainId) as keyof typeof CHAIN_ID_CLIENT_MAP],
),
);
logSuccess('VotingMachine', toAddressLink(machine, false, getClient(Number(chainId))));
if (FORMAT === 'raw') {
logSuccess('Method', 'submitVote');
logSuccess('parameter proposalId', selectedProposalId);
Expand Down Expand Up @@ -260,17 +249,13 @@ export function addCommand(program: Command) {
const machineContract = getContract({
address: machine,
abi: IVotingMachineWithProofs_ABI,
client: CHAIN_ID_CLIENT_MAP[Number(chainId) as keyof typeof CHAIN_ID_CLIENT_MAP],
client: getClient(Number(chainId)),
});
const dataWarehouse = await machineContract.read.DATA_WAREHOUSE();
const roots = await governance.getStorageRoots(selectedProposalId);
logSuccess(
'DataWarehouse',
toAddressLink(
dataWarehouse,
false,
CHAIN_ID_CLIENT_MAP[Number(chainId) as keyof typeof CHAIN_ID_CLIENT_MAP],
),
toAddressLink(dataWarehouse, false, getClient(Number(chainId))),
);
const block = await getBlock(DEFAULT_GOVERNANCE_CLIENT, {
blockHash: cache.proposal.snapshotBlockHash,
Expand Down
26 changes: 11 additions & 15 deletions src/govv3/checks/state.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import {CHAIN_ID_CLIENT_MAP} from '@bgd-labs/js-utils';
import {describe, expect, it} from 'vitest';
import {CONFIG_CHANGE_PAYLOAD} from '../mocks/configChangePayload';
import {MOCK_PAYLOAD} from '../mocks/payload';
import {checkStateChanges} from './state';
import {getClient} from '../../utils/getClient';

describe('state check', () => {
describe('state check', {timeout: 60000}, () => {
it('should correctly render state diff for', async () => {
const result = await checkStateChanges.checkProposal(
null as any,
MOCK_PAYLOAD.simulation,
CHAIN_ID_CLIENT_MAP[MOCK_PAYLOAD.simulation.transaction.network_id],
getClient(Number(MOCK_PAYLOAD.simulation.transaction.network_id)),
);
expect(result).toMatchSnapshot();
});
it('should correctly render state diff for config change', async () => {
const result = await checkStateChanges.checkProposal(
null as any,
CONFIG_CHANGE_PAYLOAD.simulation,
getClient(Number(MOCK_PAYLOAD.simulation.transaction.network_id)),
);
expect(result).toMatchSnapshot();
});
it(
'should correctly render state diff for config change',
async () => {
const result = await checkStateChanges.checkProposal(
null as any,
CONFIG_CHANGE_PAYLOAD.simulation,
CHAIN_ID_CLIENT_MAP[1],
);
expect(result).toMatchSnapshot();
},
{timeout: 60000},
);
});
10 changes: 5 additions & 5 deletions src/govv3/generatePayloadReport.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {CHAIN_ID_CLIENT_MAP} from '@bgd-labs/js-utils';
import {writeFileSync} from 'fs';
import {describe, expect, it} from 'vitest';
import {generateReport} from './generatePayloadReport';
Expand All @@ -11,6 +10,7 @@ import {getPayloadsController} from './payloadsController';
import {Address} from 'viem';
import {customStorageProvider} from '@bgd-labs/aave-v3-governance-cache/customStorageProvider';
import {fileSystemStorageAdapter} from '@bgd-labs/aave-v3-governance-cache/fileSystemStorageAdapter';
import {getClient} from '../utils/getClient';

const localCacheAdapter = customStorageProvider(fileSystemStorageAdapter);
/**
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('generatePayloadReport', () => {
async () => {
const payloadId = 33;
const chainId = 100;
const client = CHAIN_ID_CLIENT_MAP[chainId];
const client = getClient(chainId);
const payloadsControllerAddress = findPayloadsController(Number(chainId));
const payloadsController = getPayloadsController(
payloadsControllerAddress as Address,
Expand All @@ -67,7 +67,7 @@ describe('generatePayloadReport', () => {
async () => {
const report = await generateReport({
...(MOCK_PAYLOAD as any),
client: CHAIN_ID_CLIENT_MAP[Number(MOCK_PAYLOAD.simulation.transaction.network_id)],
client: getClient(Number(MOCK_PAYLOAD.simulation.transaction.network_id)),
});
expect(report).toMatchSnapshot();
},
Expand All @@ -79,7 +79,7 @@ describe('generatePayloadReport', () => {
async () => {
const report = await generateReport({
...(STREAM_PAYLOAD as any),
client: CHAIN_ID_CLIENT_MAP[Number(MOCK_PAYLOAD.simulation.transaction.network_id)],
client: getClient(Number(MOCK_PAYLOAD.simulation.transaction.network_id)),
});
expect(report).toMatchSnapshot();
},
Expand All @@ -91,7 +91,7 @@ describe('generatePayloadReport', () => {
async () => {
const report = await generateReport({
...(EMODES_SIMULATION as any),
client: CHAIN_ID_CLIENT_MAP[Number(EMODES_SIMULATION.simulation.transaction.network_id)],
client: getClient(Number(EMODES_SIMULATION.simulation.transaction.network_id)),
});
expect(report).toMatchSnapshot();
},
Expand Down
6 changes: 3 additions & 3 deletions src/govv3/simulate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {CHAIN_ID_CLIENT_MAP} from '@bgd-labs/js-utils';
import type {Client, Hex} from 'viem';
import {logInfo} from '../utils/logger';
import type {TenderlySimulationResponse} from '../utils/tenderlyClient';
Expand All @@ -10,6 +9,7 @@ import {refreshCache} from '@bgd-labs/aave-v3-governance-cache/refreshCache';
import {GetPayloadReturnType} from '@bgd-labs/aave-v3-governance-cache';
import {customStorageProvider} from '@bgd-labs/aave-v3-governance-cache/customStorageProvider';
import {fileSystemStorageAdapter} from '@bgd-labs/aave-v3-governance-cache/fileSystemStorageAdapter';
import {getClient} from '../utils/getClient';

const localCacheAdapter = customStorageProvider(fileSystemStorageAdapter);
/**
Expand Down Expand Up @@ -42,7 +42,7 @@ export async function simulateProposal(governanceAddress: Hex, client: Client, p
simulation: TenderlySimulationResponse;
}[] = [];
for (const payload of proposal.proposal.payloads) {
const client = CHAIN_ID_CLIENT_MAP[Number(payload.chain)];
const client = getClient(Number(payload.chain))!;
const controllerContract = getPayloadsController(payload.payloadsController, client);
const cache = await localCacheAdapter.getPayload({
payloadId: payload.payloadId,
Expand All @@ -59,7 +59,7 @@ export async function simulateProposal(governanceAddress: Hex, client: Client, p
simulation: result,
payloadId: payload.payloadId,
payloadInfo: cache,
client: CHAIN_ID_CLIENT_MAP[Number(payload.chain) as keyof typeof CHAIN_ID_CLIENT_MAP],
client: getClient(Number(payload.chain))!,
}),
);
payloads.push({payload: cache, simulation: result});
Expand Down
2 changes: 1 addition & 1 deletion src/govv3/utils/checkAddress.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {GovernanceV3Ethereum} from '@bgd-labs/aave-address-book';
import {ChainId} from '@bgd-labs/js-utils';
import {ChainId} from '@bgd-labs/rpc-env';
import {describe, expect, it} from 'vitest';
import {isKnownAddress} from './checkAddress';

Expand Down
10 changes: 0 additions & 10 deletions src/reports/__snapshots__/diff-report.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,6 @@ exports[`report > should generate a well formatted report 1`] = `
| maxExcessUsageRatio | 10 % | 20 % |
| interestRate | ![before](https://dash.onaave.com/api/static?variableRateSlope1=40000000000000000000000000&variableRateSlope2=600000000000000000000000000&optimalUsageRatio=900000000000000000000000000&baseVariableBorrowRate=0&maxVariableBorrowRate=undefined) | ![after](https://dash.onaave.com/api/static?variableRateSlope1=40000000000000000000000000&variableRateSlope2=750000000000000000000000000&optimalUsageRatio=800000000000000000000000000&baseVariableBorrowRate=0&maxVariableBorrowRate=undefined) |
## Emodes changed
### EMode: Stablecoins(id: 1)
### EMode: MATIC correlated(id: 2)
## Raw diff
\`\`\`json
Expand Down
7 changes: 4 additions & 3 deletions src/reports/diff-reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function diffReports<A extends AaveV3Snapshot, B extends AaveV3Snap
) {
const chainId = pre.chainId;
const diffResult = diff(pre, post);
const diffResultWithoutUnchanged = diff(pre, post, true);

// create report
let content = '';
Expand Down Expand Up @@ -91,7 +92,7 @@ export async function diffReports<A extends AaveV3Snapshot, B extends AaveV3Snap
}
}

if (diffResult.eModes) {
if (diffResultWithoutUnchanged.eModes) {
content += '## Emodes changed\n\n';
for (const eMode of Object.keys(diffResult.eModes)) {
const hasChanges = hasDiff(diffResult.eModes?.[eMode]);
Expand All @@ -114,7 +115,7 @@ export async function diffReports<A extends AaveV3Snapshot, B extends AaveV3Snap
}

try {
if (hasDiff(diffResult.poolConfig)) {
if (diffResultWithoutUnchanged.poolConfig) {
for (const key of Object.keys(diffResult.poolConfig)) {
if (
typeof (diffResult as any).poolConfig[key] === 'object' &&
Expand All @@ -131,6 +132,6 @@ export async function diffReports<A extends AaveV3Snapshot, B extends AaveV3Snap
}
} catch (e) {}

content += `## Raw diff\n\n\`\`\`json\n${JSON.stringify(diff(pre, post, true), null, 2)}\n\`\`\``;
content += `## Raw diff\n\n\`\`\`json\n${JSON.stringify(diffResultWithoutUnchanged, null, 2)}\n\`\`\``;
return content;
}
3 changes: 0 additions & 3 deletions src/reports/reserve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ describe('reserve', () => {
`[${WBTC_MOCK.aToken}](https://etherscan.io/address/${WBTC_MOCK.aToken})`,
);
});
it('address without block explorer', () => {
expect(renderReserveValue('aToken', WBTC_MOCK, 31337 as CHAIN_ID)).toBe(WBTC_MOCK.aToken);
});
});
describe('renderReserve', () => {
it('should properly render new reserve', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/reports/reserve.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {CHAIN_ID_CLIENT_MAP} from '@bgd-labs/js-utils';
import {type Hex, formatUnits} from 'viem';
import {prettifyNumber, toAddressLink} from '../govv3/utils/markdownUtils';
import type {AaveV3Reserve, CHAIN_ID} from './snapshot-types';
import {getClient} from '../utils/getClient';

export function renderReserveValue<T extends keyof AaveV3Reserve>(
key: T,
Expand All @@ -27,17 +27,17 @@ export function renderReserveValue<T extends keyof AaveV3Reserve>(
if (key === 'liquidationBonus')
return reserve[key] === 0 ? '0 %' : `${((reserve[key] as number) - 10000) / 100} %`;
if (key === 'interestRateStrategy')
return toAddressLink(reserve[key] as Hex, true, CHAIN_ID_CLIENT_MAP[chainId]);
return toAddressLink(reserve[key] as Hex, true, getClient(chainId));
if (key === 'oracleLatestAnswer' && reserve.oracleDecimals)
return formatUnits(BigInt(reserve[key]), reserve.oracleDecimals);
if (typeof reserve[key] === 'number') return reserve[key].toLocaleString('en-US');
if (typeof reserve[key] === 'string' && /0x.+/.test(reserve[key] as string))
return toAddressLink(reserve[key] as Hex, true, CHAIN_ID_CLIENT_MAP[chainId]);
return toAddressLink(reserve[key] as Hex, true, getClient(chainId));
return reserve[key];
}

function renderReserveHeadline(reserve: AaveV3Reserve, chainId: CHAIN_ID) {
return `#### ${reserve.symbol} (${toAddressLink(reserve.underlying as Hex, true, CHAIN_ID_CLIENT_MAP[chainId])})\n\n`;
return `#### ${reserve.symbol} (${toAddressLink(reserve.underlying as Hex, true, getClient(chainId))})\n\n`;
}

const ORDER: (keyof AaveV3Reserve)[] = [
Expand Down
5 changes: 2 additions & 3 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {GovernanceV3Ethereum} from '@bgd-labs/aave-address-book';
import {mainnetClient} from '@bgd-labs/js-utils';
import {Client} from 'viem';
import {getClient} from './getClient';

// arbitrary from EOA for proposal executions
export const EOA = '0xD73a92Be73EfbFcF3854433A5FcbAbF9c1316073' as const;
Expand All @@ -13,4 +12,4 @@ export const VERBOSE = process.env.VERBOSE;
export const FORMAT = (process.env.FORMAT || 'raw') as 'raw' | 'encoded';

export const DEFAULT_GOVERNANCE = GovernanceV3Ethereum.GOVERNANCE;
export const DEFAULT_GOVERNANCE_CLIENT = mainnetClient as Client;
export const DEFAULT_GOVERNANCE_CLIENT = getClient(1);
16 changes: 16 additions & 0 deletions src/utils/getClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'dotenv/config';
import {ChainId, ChainList, getRPCUrl} from '@bgd-labs/rpc-env';
import {createClient, http} from 'viem';

export function getClient(chainId: number) {
const chain = ChainList[chainId as keyof typeof ChainList];
if (!chain) return;
return createClient({
transport: http(
getRPCUrl(chainId as any, {
alchemyKey: process.env.ALCHEMY_API_KEY,
})!,
),
chain,
});
}

0 comments on commit 8fc773f

Please sign in to comment.