Skip to content

Commit

Permalink
feat: show address if missing block explorer (#61)
Browse files Browse the repository at this point in the history
* feat: expose tenderly setCode

* fix: work around concat bug

* chore(release): Release v0.0.26 🚀 🎉 (#58)

Co-authored-by: Release bot :robot <gitbot@bgdlabs.com>

* chore: upgrade ci to use release-please (#60)

* feat: show address if missing block explorer, to prevent errors when using a chain id different than CHAIN_ID, in local networks or new networks

---------

Co-authored-by: sakulstra <lukasstrassel@googlemail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Release bot :robot <gitbot@bgdlabs.com>
  • Loading branch information
4 people committed Oct 11, 2023
1 parent 5552e3d commit 38cb1db
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 60 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/dispatch-draft-release.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

name: release-please
jobs:
test-node:
uses: bgd-labs/github-workflows/.github/workflows/test-node.yml@main

release-please:
runs-on: ubuntu-latest
outputs:
releaseCreated: ${{ steps.release.outputs.release_created }}
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: aave-cli
pull-request-header: 'I have created a release'

release-node:
uses: bgd-labs/github-workflows/.github/workflows/release-node.yml@main
if: ${{ needs.release-please.outputs.releaseCreated }}
needs:
- test-node
- release-please
secrets:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
22 changes: 0 additions & 22 deletions .github/workflows/test-release.yml

This file was deleted.

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.0.26](https://github.com/bgd-labs/report-engine/compare/v0.0.25...v0.0.26) (2023-10-03)


### Features

* expose tenderly setCode ([e45aff4](https://github.com/bgd-labs/report-engine/commit/e45aff413ef831434b38e330d1bbe451fa84509e))


### Bug Fixes

* work around concat bug ([6bfb027](https://github.com/bgd-labs/report-engine/commit/6bfb0275b59a19cbe944b2976ae5c3e7167e96b5))

### [0.0.25](https://github.com/bgd-labs/report-engine/compare/v0.0.24...v0.0.25) (2023-09-25)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bgd-labs/aave-cli",
"version": "0.0.25",
"version": "0.0.26",
"description": "A cli to perform various aave governance related tasks",
"private": false,
"scripts": {
Expand Down
38 changes: 38 additions & 0 deletions src/reports/__snapshots__/reserve.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,41 @@ exports[`reserve > renderReserve > should properly render new reserve 1`] = `
| interestRateStrategy | [0x9b34E3e183c9b0d1a08fF57a8fb59c821616295f](https://etherscan.io/address/0x9b34E3e183c9b0d1a08fF57a8fb59c821616295f) |
"
`;

exports[`reserve > renderReserve > should properly render new reserve with local chain id 1`] = `
"#### WBTC (0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f)
| description | value |
| --- | --- |
| decimals | 8 |
| isActive | true |
| isFrozen | false |
| supplyCap | 2,100 WBTC |
| borrowCap | 1,115 WBTC |
| debtCeiling | 1,000 $ |
| isSiloed | false |
| isFlashloanable | false |
| eModeCategory | 0 |
| oracle | 0x6ce185860a4963106506C203335A2910413708e9 |
| oracleDecimals | 8 |
| oracleDescription | BTC / USD |
| oracleName | BTC / USD |
| oracleLatestAnswer | 22519.04551524 |
| usageAsCollateralEnabled | true |
| ltv | 70 % |
| liquidationThreshold | 75.55 % |
| liquidationBonus | 10 % |
| liquidationProtocolFee | 10 % |
| reserveFactor | 20 % |
| aToken | 0x078f358208685046a11C85e8ad32895DED33A249 |
| aTokenImpl | 0xa5ba6E5EC19a1Bf23C857991c857dB62b2Aa187B |
| variableDebtToken | 0x92b42c66840C7AD907b4BF74879FF3eF7c529473 |
| variableDebtTokenImpl | 0x81387c40EB75acB02757C1Ae55D5936E78c9dEd3 |
| stableDebtToken | 0x633b207Dd676331c413D4C013a6294B0FE47cD0e |
| stableDebtTokenImpl | 0x52A1CeB68Ee6b7B5D13E0376A1E0E4423A8cE26e |
| borrowingEnabled | true |
| stableBorrowRateEnabled | false |
| isBorrowableInIsolation | false |
| interestRateStrategy | 0x9b34E3e183c9b0d1a08fF57a8fb59c821616295f |
"
`;
12 changes: 11 additions & 1 deletion src/reports/reserve.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';
import { diff } from './diff';
import { AaveV3Reserve } from './snapshot-types';
import { AaveV3Reserve, CHAIN_ID } from './snapshot-types';
import { renderReserve, renderReserveDiff, renderReserveValue } from './reserve';

const WBTC_MOCK = {
Expand Down Expand Up @@ -49,12 +49,22 @@ describe('reserve', () => {
it('lt', () => {
expect(renderReserveValue('liquidationThreshold', WBTC_MOCK, 1)).toBe('75.55 %');
});
it('address with block explorer', () => {
expect(renderReserveValue('aToken', WBTC_MOCK, 1)).toBe(`[${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', () => {
const out = renderReserve(WBTC_MOCK, 1);
expect(out).toMatchSnapshot();
});
it('should properly render new reserve with local chain id', () => {
const out = renderReserve(WBTC_MOCK, 31337 as CHAIN_ID);
expect(out).toMatchSnapshot();
});
it('should properly render altered reserve', () => {
const input: AaveV3Reserve = { ...WBTC_MOCK, borrowCap: 100 };
const out = diff(WBTC_MOCK, { ...input });
Expand Down
39 changes: 16 additions & 23 deletions src/reports/reserve.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import { formatUnits } from 'viem';
import { AaveV3Reserve, CHAIN_ID } from './snapshot-types';

export const getBlockExplorerLink: {
[key in CHAIN_ID]: (address: string) => string;
} = {
[CHAIN_ID.MAINNET]: (address) =>
`[${address}](https://etherscan.io/address/${address})`,
[CHAIN_ID.OPTIMISM]: (address) =>
`[${address}](https://optimistic.etherscan.io/address/${address})`,
[CHAIN_ID.POLYGON]: (address) =>
`[${address}](https://polygonscan.com/address/${address})`,
[CHAIN_ID.FANTOM]: (address) =>
`[${address}](https://ftmscan.com/address/${address})`,
[CHAIN_ID.ARBITRUM]: (address) =>
`[${address}](https://arbiscan.io/address/${address})`,
[CHAIN_ID.AVALANCHE]: (address) =>
`[${address}](https://snowtrace.io/address/${address})`,
[CHAIN_ID.METIS]: (address) =>
`[${address}](https://andromeda-explorer.metis.io/address/${address})`,
[CHAIN_ID.BASE]: (address) =>
`[${address}](https://basescan.org/address/${address})`,
};
export const getBlockExplorerLink = (chain: number, address: string): string => {
switch (chain) {
case CHAIN_ID.MAINNET: return `[${address}](https://etherscan.io/address/${address})`;
case CHAIN_ID.OPTIMISM: return `[${address}](https://optimistic.etherscan.io/address/${address})`;
case CHAIN_ID.POLYGON: return `[${address}](https://polygonscan.com/address/${address})`;
case CHAIN_ID.FANTOM: return `[${address}](https://ftmscan.com/address/${address})`;
case CHAIN_ID.ARBITRUM: return `[${address}](https://arbiscan.io/address/${address})`;
case CHAIN_ID.AVALANCHE: return `[${address}](https://snowtrace.io/address/${address})`;
case CHAIN_ID.METIS: return `[${address}](https://andromeda-explorer.metis.io/address/${address})`;
case CHAIN_ID.BASE: return `[${address}](https://basescan.org/address/${address})`;
default: return address;
};
}

export function renderReserveValue<T extends keyof AaveV3Reserve>(
key: T,
Expand All @@ -47,18 +40,18 @@ export function renderReserveValue<T extends keyof AaveV3Reserve>(
? '0 %'
: `${((reserve[key] as number) - 10000) / 100} %`;
if (key === 'interestRateStrategy')
return getBlockExplorerLink[chainId](reserve[key] as string);
return getBlockExplorerLink(chainId, reserve[key] as string);
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 getBlockExplorerLink[chainId](reserve[key] as string);
return getBlockExplorerLink(chainId, reserve[key] as string);
return reserve[key];
}

function renderReserveHeadline(reserve: AaveV3Reserve, chainId: CHAIN_ID) {
return `#### ${reserve.symbol} (${getBlockExplorerLink[chainId](
return `#### ${reserve.symbol} (${getBlockExplorerLink(chainId,
reserve.underlying
)})\n\n`;
}
Expand Down
5 changes: 4 additions & 1 deletion src/utils/storageSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ export function getDynamicArraySlot(baseSlot: bigint, arrayIndex: number, itemSi
export function getBytesValue(value: string | Hex) {
const bytesString = toBytes(value);
if (bytesString.length > 31) throw new Error('Error: strings > 31 bytes are not implemented');
return concat([toHex(pad(bytesString, { size: 31, dir: 'right' })), toHex(bytesString.length * 2, { size: 1 })]);
return pad(
concat([toHex(pad(bytesString, { size: 31, dir: 'right' })), toHex(bytesString.length * 2, { size: 1 })]),
{ size: 32 }
);
}

/**
Expand Down

0 comments on commit 38cb1db

Please sign in to comment.