Skip to content

Commit

Permalink
fix: specific for markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
sendra committed Jul 18, 2024
1 parent b0ca215 commit ccd77b8
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
20 changes: 19 additions & 1 deletion src/govv3/utils/markdownUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ export function prettifyNumber({
prefix,
suffix,
decimalsToDisplay,
}: {
value: string | number | bigint;
decimals: number;
prefix?: string;
suffix?: string;
}) {
return `${prefix ? `${prefix}` : ''}${
formatNumberString(formatUnits(BigInt(value), decimals))}${
suffix ? `${suffix}` : ''
} [${value}](${decimals}decimals)`;
}

export function prettifyNumberForMarkdown({
value,
decimals,
prefix,
suffix,
decimalsToDisplay,
}: {
value: string | number | bigint;
decimals: number;
Expand All @@ -85,7 +103,7 @@ export function prettifyNumber({
limitDecimalsWithoutRounding(formatNumberString(formatUnits(BigInt(value), decimals)), decimalsToDisplay)
: formatNumberString(formatUnits(BigInt(value), decimals))}${
suffix ? `${suffix}` : ''
}[${value}](${decimals} decimals)`;
} [${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%[2000](2 decimals) | 35%[3500](2 decimals) |
| reserveFactor | 20% [2000] (2 decimals) | 35% [3500] (2 decimals) |
#### WETH ([0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619](https://polygonscan.com/address/0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619))
| description | value before | value after |
| --- | --- | --- |
| reserveFactor | 10%[1000](2 decimals) | 15%[1500](2 decimals) |
| 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%[2000](2 decimals) | 35%[3500](2 decimals) |
| 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%[1000](2 decimals) | 20%[2000](2 decimals) |
| 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
24 changes: 12 additions & 12 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$[100000](2 decimals) |
| 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%[7000](2 decimals) |
| liquidationThreshold | 75.55%[7555](2 decimals) |
| ltv | 70% [7000] (2 decimals) |
| liquidationThreshold | 75.55% [7555] (2 decimals) |
| liquidationBonus | 10 % |
| liquidationProtocolFee | 10%[1000](2 decimals) |
| reserveFactor | 20%[2000](2 decimals) |
| 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 @@ -44,7 +44,7 @@ exports[`reserve > renderReserve > should properly render new reserve 1`] = `
| stableBorrowRateEnabled | false |
| isBorrowableInIsolation | false |
| interestRateStrategy | [0x9b34E3e183c9b0d1a08fF57a8fb59c821616295f](https://etherscan.io/address/0x9b34E3e183c9b0d1a08fF57a8fb59c821616295f) |
| liquidityIndex | 1.001[1001688262989374224491143837](27 decimals) |
| liquidityIndex | 1.001 [1001688262989374224491143837] (27 decimals) |
"
`;

Expand All @@ -58,7 +58,7 @@ exports[`reserve > renderReserve > should properly render new reserve with local
| isFrozen | false |
| supplyCap | 2,100 WBTC |
| borrowCap | 1,115 WBTC |
| debtCeiling | 1,000$[100000](2 decimals) |
| debtCeiling | 1,000$ [100000] (2 decimals) |
| isSiloed | false |
| isFlashloanable | false |
| eModeCategory | 0 |
Expand All @@ -68,11 +68,11 @@ exports[`reserve > renderReserve > should properly render new reserve with local
| oracleName | BTC / USD |
| oracleLatestAnswer | 22519.04551524 |
| usageAsCollateralEnabled | true |
| ltv | 70%[7000](2 decimals) |
| liquidationThreshold | 75.55%[7555](2 decimals) |
| ltv | 70% [7000] (2 decimals) |
| liquidationThreshold | 75.55% [7555] (2 decimals) |
| liquidationBonus | 10 % |
| liquidationProtocolFee | 10%[1000](2 decimals) |
| reserveFactor | 20%[2000](2 decimals) |
| liquidationProtocolFee | 10% [1000] (2 decimals) |
| reserveFactor | 20% [2000] (2 decimals) |
| aToken | 0x078f358208685046a11C85e8ad32895DED33A249 |
| aTokenImpl | 0xa5ba6E5EC19a1Bf23C857991c857dB62b2Aa187B |
| variableDebtToken | 0x92b42c66840C7AD907b4BF74879FF3eF7c529473 |
Expand All @@ -83,7 +83,7 @@ exports[`reserve > renderReserve > should properly render new reserve with local
| stableBorrowRateEnabled | false |
| isBorrowableInIsolation | false |
| interestRateStrategy | 0x9b34E3e183c9b0d1a08fF57a8fb59c821616295f |
| liquidityIndex | 1.001[1001688262989374224491143837](27 decimals) |
| liquidityIndex | 1.001 [1001688262989374224491143837] (27 decimals) |
"
`;

Expand Down
8 changes: 4 additions & 4 deletions src/reports/reserve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ const WBTC_MOCK = {
describe('reserve', () => {
describe('renderReserveValue', () => {
it('liquidityIndex', () => {
expect(renderReserveValue('liquidityIndex', WBTC_MOCK, 1)).toBe('1.001[1001688262989374224491143837](27 decimals)');
expect(renderReserveValue('liquidityIndex', WBTC_MOCK, 1)).toBe('1.001 [1001688262989374224491143837] (27 decimals)');
});
it('reserveFactor', () => {
expect(renderReserveValue('reserveFactor', WBTC_MOCK, 1)).toBe('20%[2000](2 decimals)');
expect(renderReserveValue('reserveFactor', WBTC_MOCK, 1)).toBe('20% [2000] (2 decimals)');
});
it('debtCeiling', () => {
expect(renderReserveValue('debtCeiling', WBTC_MOCK, 1)).toBe('1,000$[100000](2 decimals)');
expect(renderReserveValue('debtCeiling', WBTC_MOCK, 1)).toBe('1,000$ [100000] (2 decimals)');
});
it('lt', () => {
expect(renderReserveValue('liquidationThreshold', WBTC_MOCK, 1)).toBe('75.55%[7555](2 decimals)');
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 { prettifyNumber, toAddressLink } from '../govv3/utils/markdownUtils';
import { prettifyNumberForMarkdown, 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 prettifyNumber({decimals: 2, value:BigInt(reserve[key]), suffix: '%'});
return prettifyNumberForMarkdown({decimals: 2, value:BigInt(reserve[key]), suffix: '%'});
if (['supplyCap', 'borrowCap'].includes(key))
return `${reserve[key].toLocaleString('en-US')} ${reserve.symbol}`;
if (key === 'debtCeiling')
return prettifyNumber({decimals: 2, value:BigInt(reserve[key]), suffix: '$'});
return prettifyNumberForMarkdown({decimals: 2, value:BigInt(reserve[key]), suffix: '$'});
if (['liquidityIndex', 'variableBorrowIndex'].includes(key))
return prettifyNumber({decimals: 27, value:BigInt(reserve[key]), decimalsToDisplay: 3});
return prettifyNumberForMarkdown({decimals: 27, value:BigInt(reserve[key]), decimalsToDisplay: 3});
if (['currentLiquidityRate', 'currentVariableBorrowRate'].includes(key))
return prettifyNumber({decimals: 25, value:BigInt(reserve[key]), suffix: '%', decimalsToDisplay: 3});
return prettifyNumberForMarkdown({decimals: 25, value:BigInt(reserve[key]), suffix: '%', decimalsToDisplay: 3});
if (key === 'liquidationBonus')
return reserve[key] === 0 ? '0 %' : `${((reserve[key] as number) - 10000) / 100} %`;
if (key === 'interestRateStrategy')
Expand Down

0 comments on commit ccd77b8

Please sign in to comment.