Skip to content

Commit

Permalink
fix: patch ir diff (#153)
Browse files Browse the repository at this point in the history
* fix: patch ir diff

* fix: always print ir changes

* fix: patch utils

* fix: cleanup
  • Loading branch information
sakulstra authored Aug 14, 2024
1 parent 4673167 commit bd6f8bb
Show file tree
Hide file tree
Showing 25 changed files with 3,577 additions and 12 deletions.
1 change: 1 addition & 0 deletions .assets/0d62f0b0c1bf55e0693fd4e1b0116731fd62a430.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/15265298aa7a998c6931ace04e7860b8b360a5ba.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/221c424012f6b8f7d49339c1ad1f6d8be7814e8f.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/2493d3ef35333192ec820f1bc848b5189674555c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/32f0ae5f67532a528e6b3d83623f49f7646148c3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/3a6b85c50b6d8a3cac78bba7acc69af991e8b359.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/5d6681206ba1647c8da5212801c687932059c1c3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/63ce7a55ac04d754c31aada64a733b5a0ecd6dd5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/6554df8148ba17f5ffc961aea7512567c91e2a3d.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/6c89ad3b3ce52cc75ae008e02f0902e656628a29.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/6e4db5711739fa231386033bdb64a3cceb8462a8.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/794e0d79fec49d4d84b9250e643f1773f16214a5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/7fd6d26d5c1caf9a8735a932555ad64bcb400031.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/8748d80179d57144859fe9a7186b742ec3e9387c.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/a1a7ab1f1b9fcdf6ffa41ac7a8b4daf2daf98328.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/a8fcef60b1dfb35de994f96040b1b43df9719d28.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/c1690b11066430bfb069e06227cc53f8654a7b5a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/e03975867d1c729d1a52bbec364211baff2dab5a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/e231a10768e2145bf6969b6e65d7c875df780821.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions .assets/e3cd41bda67a1fc3ece7a4100d0a7455722f244a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 91 additions & 1 deletion src/reports/__snapshots__/report.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ exports[`report > should generate a well formatted report 1`] = `
\`\`\`"
`;

exports[`report > should generate a well formatted report for 3.1 1`] = `
exports[`report > should generate a well formatted report for 3.0 to 3.1 1`] = `
"## Reserve changes
### Reserve altered
Expand Down Expand Up @@ -439,3 +439,93 @@ exports[`report > should generate a well formatted report for 3.1 1`] = `
}
\`\`\`"
`;

exports[`report > should generate a well formatted report for 3.1 1`] = `
"## Reserve changes
### Reserve altered
#### GHO ([0x40D16FC0246aD3160Ccc09B8D0D3A2cD28aE6C2f](https://etherscan.io/address/0x40D16FC0246aD3160Ccc09B8D0D3A2cD28aE6C2f))
| description | value before | value after |
| --- | --- | --- |
| maxVariableBorrowRate | 7 % | 6 % |
| baseVariableBorrowRate | 7 % | 6 % |
| interestRate | ![before](/.assets/e03975867d1c729d1a52bbec364211baff2dab5a.svg) | ![after](/.assets/a1a7ab1f1b9fcdf6ffa41ac7a8b4daf2daf98328.svg) |
#### wstETH ([0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0](https://etherscan.io/address/0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0))
| description | value before | value after |
| --- | --- | --- |
| eMode.liquidationBonus | 1 % | 2 % |
#### ETHx ([0xA35b1B31Ce002FBF2058D22F30f95D405200A15b](https://etherscan.io/address/0xA35b1B31Ce002FBF2058D22F30f95D405200A15b))
| description | value before | value after |
| --- | --- | --- |
| eMode.liquidationBonus | 1 % | 2 % |
#### cbETH ([0xBe9895146f7AF43049ca1c1AE358B0541Ea49704](https://etherscan.io/address/0xBe9895146f7AF43049ca1c1AE358B0541Ea49704))
| description | value before | value after |
| --- | --- | --- |
| eMode.liquidationBonus | 1 % | 2 % |
#### WETH ([0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2](https://etherscan.io/address/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2))
| description | value before | value after |
| --- | --- | --- |
| eMode.liquidationBonus | 1 % | 2 % |
#### weETH ([0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee](https://etherscan.io/address/0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee))
| description | value before | value after |
| --- | --- | --- |
| eMode.liquidationBonus | 1 % | 2 % |
#### rETH ([0xae78736Cd615f374D3085123A210448E74Fc6393](https://etherscan.io/address/0xae78736Cd615f374D3085123A210448E74Fc6393))
| description | value before | value after |
| --- | --- | --- |
| eMode.liquidationBonus | 1 % | 2 % |
#### osETH ([0xf1C9acDc66974dFB6dEcB12aA385b9cD01190E38](https://etherscan.io/address/0xf1C9acDc66974dFB6dEcB12aA385b9cD01190E38))
| description | value before | value after |
| --- | --- | --- |
| eMode.liquidationBonus | 1 % | 2 % |
## Raw diff
\`\`\`json
{
"eModes": {
"1": {
"liquidationBonus": {
"from": 10100,
"to": 10200
}
}
},
"strategies": {
"0x40D16FC0246aD3160Ccc09B8D0D3A2cD28aE6C2f": {
"baseVariableBorrowRate": {
"from": "70000000000000000000000000",
"to": "60000000000000000000000000"
},
"maxVariableBorrowRate": {
"from": "70000000000000000000000000",
"to": "60000000000000000000000000"
}
}
}
}
\`\`\`"
`;
48 changes: 38 additions & 10 deletions src/reports/diff-reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import {renderReserve, renderReserveDiff} from './reserve';
import {AaveV3Reserve, type AaveV3Snapshot} from './snapshot-types';
import {renderStrategy, renderStrategyDiff} from './strategy';

function hasDiff(input: Record<string, any>): boolean {
if (!input) return false;
return !!Object.keys(input).find(
(key) =>
typeof input[key as keyof typeof input] === 'object' &&
(input[key as keyof typeof input].hasOwnProperty('from') ||
input[key as keyof typeof input].hasOwnProperty('to')),
);
}

export async function diffReports<A extends AaveV3Snapshot, B extends AaveV3Snapshot>(
pre: A,
post: B,
Expand Down Expand Up @@ -53,26 +63,35 @@ export async function diffReports<A extends AaveV3Snapshot, B extends AaveV3Snap
.filter((i) => i);
const reservesAltered = Object.keys(diffResult.reserves)
.map((reserveKey) => {
// from being present on key means reserve was removed
if (
!(diffResult.reserves[reserveKey] as any).hasOwnProperty('from') &&
Object.keys(diffResult.reserves[reserveKey]).find(
(fieldKey) => typeof (diffResult.reserves as any)[reserveKey][fieldKey] === 'object',
// "from" being present on reserses key means reserve was removed
if (!(diffResult.reserves[reserveKey] as any).hasOwnProperty('from')) {
const hasChangedReserveProperties = hasDiff(diffResult.reserves[reserveKey]);
const preIrHash = hash(pre.strategies[reserveKey]);
const postIrHash = hash(post.strategies[reserveKey]);
const hasChangedIr = preIrHash !== postIrHash;
const eModeCategoryChanged =
diffResult.reserves[reserveKey].eModeCategory?.hasOwnProperty('from');
const eModeParamsChanged =
!eModeCategoryChanged &&
hasDiff(diffResult.eModes?.[diffResult.reserves[reserveKey].eModeCategory as any]);
if (
!hasChangedReserveProperties &&
!hasChangedIr &&
!eModeCategoryChanged &&
!eModeParamsChanged
)
) {
return;
// diff reserve
let report = renderReserveDiff(diffResult.reserves[reserveKey] as any, chainId);
// diff irs
const preIrHash = hash(pre.strategies[reserveKey]);
const postIrHash = hash(post.strategies[reserveKey]);
if (preIrHash !== postIrHash) {
if (hasChangedIr) {
report += renderStrategyDiff(
diff(pre.strategies[reserveKey], post.strategies[reserveKey]) as any,
);
report += `| interestRate | ![before](/.assets/${preIrHash}.svg) | ![after](/.assets/${postIrHash}.svg) |`;
}
// diff eModes
if (diffResult.reserves[reserveKey].eModeCategory?.hasOwnProperty('from')) {
if (eModeCategoryChanged) {
report += renderEmodeDiff(
diff(
pre.eModes[(diffResult.reserves[reserveKey].eModeCategory as any).from] || {},
Expand All @@ -81,6 +100,15 @@ export async function diffReports<A extends AaveV3Snapshot, B extends AaveV3Snap
);
}

if (eModeParamsChanged && !eModeCategoryChanged) {
report += renderEmodeDiff(
diff(
pre.eModes[diffResult.reserves[reserveKey].eModeCategory as any] || {},
post.eModes[diffResult.reserves[reserveKey].eModeCategory as any],
) as any,
);
}

return report;
}
})
Expand Down
Loading

0 comments on commit bd6f8bb

Please sign in to comment.