Skip to content

Commit

Permalink
feat: use consistent decimals length
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Jul 22, 2024
1 parent 5810ae7 commit 522634e
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 203 deletions.
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,33 @@
`aave-cli` is a command line tool providing commands to automate certain tasks when interacting with the aave protocol.
For a full overview of features you can run `aave-cli --help`

## Installation

Make sure to setup your .env as most utilities rely on tenderly and will fail otherwise.
```
TENDERLY_ACCESS_TOKEN=
TENDERLY_PROJECT_SLUG=
TENDERLY_ACCOUNT=
```

Local installation
```
npm i @bgd-labs/aave-cli
```

Global installation
```
npm i -g @bgd-labs/aave-cli
```

Once installed you should be able to run commands via the `@bgd-labs/aave-cli` or the `aave-cli` binary.

Alteratively you can use `npx @bgd-labs/aave-cli` to run the cli via npx.

## Fork

`aave-cli fork --chainId <id>` can ge used to generate tenderly forks.
The cli allows executing certain proposal/actionset IDs, an address or even local payload via aave governance.
`aave-cli fork --chainId <id>` can ge used to generate tenderly forks.
The cli allows executing certain proposal/actionset IDs, an address or even local payload via aave governance.
For a full overview of commands please run `aave-cli fork --help`

## Ipfs
Expand Down
156 changes: 78 additions & 78 deletions src/govv3/__snapshots__/generatePayloadReport.spec.ts.snap

Large diffs are not rendered by default.

196 changes: 98 additions & 98 deletions src/govv3/checks/__snapshots__/state.spec.ts.snap

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions src/govv3/utils/markdownUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,32 @@ export function formatNumberString(x: string | number) {
return String(x).replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ',');
}

function limitDecimalsWithoutRounding(val: string, decimals: number) {
const parts = val.split('.');
if (parts.length != 2) return val;
return parts[0] + '.' + parts[1].substring(0, decimals);
}

export function prettifyNumber({
value,
decimals,
prefix,
suffix,
decimalsToDisplay = 4,
}: {
value: string | number | bigint;
decimals: number;
prefix?: string;
suffix?: string;
decimalsToDisplay?: number;
}) {
return `${prefix ? `${prefix}` : ''}${formatNumberString(formatUnits(BigInt(value), decimals))}${
suffix ? `${suffix}` : ''
}[${value}](${decimals} decimals)`;
const formattedNumber = limitDecimalsWithoutRounding(
formatNumberString(formatUnits(BigInt(value), decimals)),
decimalsToDisplay,
);
return `${prefix ? `${prefix} ` : ''}${formattedNumber}${
suffix ? ` ${suffix}` : ''
} [${value}, ${decimals} decimals]`;
}

export function wrapInQuotes(name: string, quotes: boolean) {
Expand Down
8 changes: 4 additions & 4 deletions src/reports/__snapshots__/report.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ exports[`report > should generate a well formatted report 1`] = `
| description | value before | value after |
| --- | --- | --- |
| reserveFactor | 20 % | 35 % |
| reserveFactor | 20 % [2000, 2 decimals] | 35 % [3500, 2 decimals] |
#### WETH ([0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619](https://polygonscan.com/address/0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619))
| description | value before | value after |
| --- | --- | --- |
| reserveFactor | 10 % | 15 % |
| reserveFactor | 10 % [1000, 2 decimals] | 15 % [1500, 2 decimals] |
| interestRateStrategy | [0x03733F4E008d36f2e37F0080fF1c8DF756622E6F](https://polygonscan.com/address/0x03733F4E008d36f2e37F0080fF1c8DF756622E6F) | [0x27eFE5db315b71753b2a38ED3d5dd7E9362ba93F](https://polygonscan.com/address/0x27eFE5db315b71753b2a38ED3d5dd7E9362ba93F) |
| stableRateSlope1 | 0 % | 4 % |
| optimalUsageRatio | 45 % | 80 % |
Expand All @@ -32,7 +32,7 @@ exports[`report > should generate a well formatted report 1`] = `
| description | value before | value after |
| --- | --- | --- |
| reserveFactor | 20 % | 35 % |
| reserveFactor | 20 % [2000, 2 decimals] | 35 % [3500, 2 decimals] |
#### agEUR ([0xE0B52e49357Fd4DAf2c15e02058DCE6BC0057db4](https://polygonscan.com/address/0xE0B52e49357Fd4DAf2c15e02058DCE6BC0057db4))
Expand Down Expand Up @@ -61,7 +61,7 @@ exports[`report > should generate a well formatted report 1`] = `
| description | value before | value after |
| --- | --- | --- |
| reserveFactor | 10 % | 20 % |
| reserveFactor | 10 % [1000, 2 decimals] | 20 % [2000, 2 decimals] |
| interestRateStrategy | [0x41B66b4b6b4c9dab039d96528D1b88f7BAF8C5A4](https://polygonscan.com/address/0x41B66b4b6b4c9dab039d96528D1b88f7BAF8C5A4) | [0xA9F3C3caE095527061e6d270DBE163693e6fda9D](https://polygonscan.com/address/0xA9F3C3caE095527061e6d270DBE163693e6fda9D) |
| variableRateSlope2 | 60 % | 75 % |
| stableRateSlope2 | 60 % | 75 % |
Expand Down
20 changes: 10 additions & 10 deletions src/reports/__snapshots__/reserve.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`reserve > renderReserve > should properly render new reserve 1`] = `
| isFrozen | false |
| supplyCap | 2,100 WBTC |
| borrowCap | 1,115 WBTC |
| debtCeiling | 1,000 $ |
| debtCeiling | 1,000 $ [100000, 2 decimals] |
| isSiloed | false |
| isFlashloanable | false |
| eModeCategory | 0 |
Expand All @@ -29,11 +29,11 @@ exports[`reserve > renderReserve > should properly render new reserve 1`] = `
| oracleName | BTC / USD |
| oracleLatestAnswer | 22519.04551524 |
| usageAsCollateralEnabled | true |
| ltv | 70 % |
| liquidationThreshold | 75.55 % |
| ltv | 70 % [7000, 2 decimals] |
| liquidationThreshold | 75.55 % [7555, 2 decimals] |
| liquidationBonus | 10 % |
| liquidationProtocolFee | 10 % |
| reserveFactor | 20 % |
| liquidationProtocolFee | 10 % [1000, 2 decimals] |
| reserveFactor | 20 % [2000, 2 decimals] |
| aToken | [0x078f358208685046a11C85e8ad32895DED33A249](https://etherscan.io/address/0x078f358208685046a11C85e8ad32895DED33A249) |
| aTokenImpl | [0xa5ba6E5EC19a1Bf23C857991c857dB62b2Aa187B](https://etherscan.io/address/0xa5ba6E5EC19a1Bf23C857991c857dB62b2Aa187B) |
| variableDebtToken | [0x92b42c66840C7AD907b4BF74879FF3eF7c529473](https://etherscan.io/address/0x92b42c66840C7AD907b4BF74879FF3eF7c529473) |
Expand All @@ -57,7 +57,7 @@ exports[`reserve > renderReserve > should properly render new reserve with local
| isFrozen | false |
| supplyCap | 2,100 WBTC |
| borrowCap | 1,115 WBTC |
| debtCeiling | 1,000 $ |
| debtCeiling | 1,000 $ [100000, 2 decimals] |
| isSiloed | false |
| isFlashloanable | false |
| eModeCategory | 0 |
Expand All @@ -67,11 +67,11 @@ exports[`reserve > renderReserve > should properly render new reserve with local
| oracleName | BTC / USD |
| oracleLatestAnswer | 22519.04551524 |
| usageAsCollateralEnabled | true |
| ltv | 70 % |
| liquidationThreshold | 75.55 % |
| ltv | 70 % [7000, 2 decimals] |
| liquidationThreshold | 75.55 % [7555, 2 decimals] |
| liquidationBonus | 10 % |
| liquidationProtocolFee | 10 % |
| reserveFactor | 20 % |
| liquidationProtocolFee | 10 % [1000, 2 decimals] |
| reserveFactor | 20 % [2000, 2 decimals] |
| aToken | 0x078f358208685046a11C85e8ad32895DED33A249 |
| aTokenImpl | 0xa5ba6E5EC19a1Bf23C857991c857dB62b2Aa187B |
| variableDebtToken | 0x92b42c66840C7AD907b4BF74879FF3eF7c529473 |
Expand Down
8 changes: 5 additions & 3 deletions src/reports/reserve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ const WBTC_MOCK = {
describe('reserve', () => {
describe('renderReserveValue', () => {
it('reserveFactor', () => {
expect(renderReserveValue('reserveFactor', WBTC_MOCK, 1)).toBe('20 %');
expect(renderReserveValue('reserveFactor', WBTC_MOCK, 1)).toBe('20 % [2000, 2 decimals]');
});
it('debtCeiling', () => {
expect(renderReserveValue('debtCeiling', WBTC_MOCK, 1)).toBe('1,000 $');
expect(renderReserveValue('debtCeiling', WBTC_MOCK, 1)).toBe('1,000 $ [100000, 2 decimals]');
});
it('lt', () => {
expect(renderReserveValue('liquidationThreshold', WBTC_MOCK, 1)).toBe('75.55 %');
expect(renderReserveValue('liquidationThreshold', WBTC_MOCK, 1)).toBe(
'75.55 % [7555, 2 decimals]',
);
});
it('address with block explorer', () => {
expect(renderReserveValue('aToken', WBTC_MOCK, 1)).toBe(
Expand Down
10 changes: 5 additions & 5 deletions src/reports/reserve.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CHAIN_ID_CLIENT_MAP} from '@bgd-labs/js-utils';
import {type Hex, formatUnits} from 'viem';
import {toAddressLink} from '../govv3/utils/markdownUtils';
import {prettifyNumber, toAddressLink} from '../govv3/utils/markdownUtils';
import type {AaveV3Reserve, CHAIN_ID} from './snapshot-types';

export function renderReserveValue<T extends keyof AaveV3Reserve>(
Expand All @@ -9,15 +9,15 @@ export function renderReserveValue<T extends keyof AaveV3Reserve>(
chainId: CHAIN_ID,
) {
if (['reserveFactor', 'liquidationProtocolFee', 'liquidationThreshold', 'ltv'].includes(key))
return `${formatUnits(BigInt(reserve[key]), 2)} %`;
return prettifyNumber({value: reserve[key] as string, decimals: 2, suffix: '%'});
if (['supplyCap', 'borrowCap'].includes(key))
return `${reserve[key].toLocaleString('en-US')} ${reserve.symbol}`;
if (key === 'debtCeiling')
return `${Number(formatUnits(BigInt(reserve[key]), 2)).toLocaleString('en-US')} $`;
return prettifyNumber({value: reserve[key] as string, decimals: 2, suffix: '$'});
if (['liquidityIndex', 'variableBorrowIndex'].includes(key))
return `${Number(formatUnits(BigInt(reserve[key]), 27)).toLocaleString('en-US')}`;
return prettifyNumber({value: reserve[key] as string, decimals: 27, suffix: '%'}); // `${Number(formatUnits(BigInt(reserve[key]), 27)).toLocaleString('en-US')}`;
if (['currentLiquidityRate', 'currentVariableBorrowRate'].includes(key))
return `${Number(formatUnits(BigInt(reserve[key]), 25)).toLocaleString('en-US')} %`;
return prettifyNumber({value: reserve[key] as string, decimals: 25, suffix: '%'}); // `${Number(formatUnits(BigInt(reserve[key]), 25)).toLocaleString('en-US')} %`;
if (key === 'liquidationBonus')
return reserve[key] === 0 ? '0 %' : `${((reserve[key] as number) - 10000) / 100} %`;
if (key === 'interestRateStrategy')
Expand Down

0 comments on commit 522634e

Please sign in to comment.