Skip to content

Commit

Permalink
feat: add risk steward (#83)
Browse files Browse the repository at this point in the history
* feat: add risk steward

* fix: update all comments

* fix: add risk steward

* fix: remove error log

* fix: remove scripts

* fix: make external/ calldata/storage

* fix: add docs

* fix: use interface

* fix: add natspec

* feat: add blocknumber to snapshot

* fix: remove changes

* fix: add interface
  • Loading branch information
sakulstra authored Apr 26, 2023
1 parent 8b407ff commit 1d973c4
Show file tree
Hide file tree
Showing 10 changed files with 577 additions and 161 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ out/
broadcast
node_modules
package-lock.json
.DS_Store
.DS_Store

yarn-error.log
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@
},
"homepage": "https://github.com/bgd-labs/aave-helpers#readme",
"devDependencies": {
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-beta.19"
"prettier": "^2.8.3",
"prettier-plugin-solidity": "^1.1.3"
},
"dependencies": {
"@bgd-labs/report-engine": "^0.0.9",
"diffler": "^2.0.4",
"isomorphic-unfetch": "^4.0.2",
"node-fetch": "^3.3.1",
"zod": "^3.21.4"
"@bgd-labs/report-engine": "^0.0.9"
}
}
18 changes: 9 additions & 9 deletions reports/postTestEngineOptV3.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"oracle": "0x698B585CbC4407e2D54aa898B2600B53C68958f7",
"oracleDecimals": 8,
"oracleDescription": "WSTETH / USD",
"oracleLatestAnswer": 174300712435,
"oracleLatestAnswer": 172290174000,
"reserveFactor": 1500,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0x78246294a4c6fBf614Ed73CcC9F8b875ca8eE841",
Expand Down Expand Up @@ -74,7 +74,7 @@
"oracle": "0xCc232dcFAAE6354cE191Bd574108c1aD03f86450",
"oracleDecimals": 8,
"oracleDescription": "LINK / USD",
"oracleLatestAnswer": 691711677,
"oracleLatestAnswer": 671559920,
"reserveFactor": 2000,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0x89D976629b7055ff1ca02b927BA3e020F22A44e4",
Expand Down Expand Up @@ -107,7 +107,7 @@
"oracle": "0x13e3Ee699D1909E989722E753853AE30b17e08c5",
"oracleDecimals": 8,
"oracleDescription": "ETH / USD",
"oracleLatestAnswer": 157141000000,
"oracleLatestAnswer": 154457000000,
"reserveFactor": 1500,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0xD8Ad37849950903571df17049516a5CD4cbE55F6",
Expand Down Expand Up @@ -140,7 +140,7 @@
"oracle": "0x0D276FC14719f9292D5C1eA2198673d1f4269246",
"oracleDecimals": 8,
"oracleDescription": "OP / USD",
"oracleLatestAnswer": 254511663,
"oracleLatestAnswer": 236454140,
"reserveFactor": 2000,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0x08Cb71192985E936C7Cd166A8b268035e400c3c3",
Expand Down Expand Up @@ -173,7 +173,7 @@
"oracle": "0xD702DD976Fb76Fffc2D3963D037dfDae5b04E593",
"oracleDecimals": 8,
"oracleDescription": "BTC / USD",
"oracleLatestAnswer": 2245475153319,
"oracleLatestAnswer": 2205261790595,
"reserveFactor": 2000,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0x633b207Dd676331c413D4C013a6294B0FE47cD0e",
Expand Down Expand Up @@ -206,7 +206,7 @@
"oracle": "0x338ed6787f463394D24813b297401B9F05a8C9d1",
"oracleDecimals": 8,
"oracleDescription": "AAVE / USD",
"oracleLatestAnswer": 7665000000,
"oracleLatestAnswer": 7425000000,
"reserveFactor": 0,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0xfAeF6A702D15428E588d4C0614AEFb4348D83D48",
Expand Down Expand Up @@ -272,7 +272,7 @@
"oracle": "0x7f99817d87baD03ea21E05112Ca799d715730efe",
"oracleDecimals": 8,
"oracleDescription": "SUSD / USD",
"oracleLatestAnswer": 100164737,
"oracleLatestAnswer": 100241227,
"reserveFactor": 1000,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0xF15F26710c827DDe8ACBA678682F3Ce24f2Fb56E",
Expand Down Expand Up @@ -305,7 +305,7 @@
"oracle": "0xECef79E109e997bCA29c1c0897ec9d7b03647F5E",
"oracleDecimals": 8,
"oracleDescription": "USDT / USD",
"oracleLatestAnswer": 99995128,
"oracleLatestAnswer": 99991000,
"reserveFactor": 1000,
"stableBorrowRateEnabled": true,
"stableDebtToken": "0x70eFfc565DB6EEf7B927610155602d31b670e802",
Expand Down Expand Up @@ -338,7 +338,7 @@
"oracle": "0x8dBa75e83DA73cc766A7e5a0ee71F656BAb470d6",
"oracleDecimals": 8,
"oracleDescription": "DAI / USD",
"oracleLatestAnswer": 99979000,
"oracleLatestAnswer": 99990000,
"reserveFactor": 1000,
"stableBorrowRateEnabled": true,
"stableDebtToken": "0xd94112B5B62d53C9402e7A60289c6810dEF1dC9B",
Expand Down
18 changes: 9 additions & 9 deletions reports/preTestEngineOptV3.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"oracle": "0x698B585CbC4407e2D54aa898B2600B53C68958f7",
"oracleDecimals": 8,
"oracleDescription": "WSTETH / USD",
"oracleLatestAnswer": 174300712435,
"oracleLatestAnswer": 172290174000,
"reserveFactor": 1500,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0x78246294a4c6fBf614Ed73CcC9F8b875ca8eE841",
Expand Down Expand Up @@ -74,7 +74,7 @@
"oracle": "0xCc232dcFAAE6354cE191Bd574108c1aD03f86450",
"oracleDecimals": 8,
"oracleDescription": "LINK / USD",
"oracleLatestAnswer": 691711677,
"oracleLatestAnswer": 671559920,
"reserveFactor": 2000,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0x89D976629b7055ff1ca02b927BA3e020F22A44e4",
Expand Down Expand Up @@ -107,7 +107,7 @@
"oracle": "0x13e3Ee699D1909E989722E753853AE30b17e08c5",
"oracleDecimals": 8,
"oracleDescription": "ETH / USD",
"oracleLatestAnswer": 157141000000,
"oracleLatestAnswer": 154457000000,
"reserveFactor": 1000,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0xD8Ad37849950903571df17049516a5CD4cbE55F6",
Expand Down Expand Up @@ -140,7 +140,7 @@
"oracle": "0x0D276FC14719f9292D5C1eA2198673d1f4269246",
"oracleDecimals": 8,
"oracleDescription": "OP / USD",
"oracleLatestAnswer": 254511663,
"oracleLatestAnswer": 236454140,
"reserveFactor": 2000,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0x08Cb71192985E936C7Cd166A8b268035e400c3c3",
Expand Down Expand Up @@ -173,7 +173,7 @@
"oracle": "0xD702DD976Fb76Fffc2D3963D037dfDae5b04E593",
"oracleDecimals": 8,
"oracleDescription": "BTC / USD",
"oracleLatestAnswer": 2245475153319,
"oracleLatestAnswer": 2205261790595,
"reserveFactor": 2000,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0x633b207Dd676331c413D4C013a6294B0FE47cD0e",
Expand Down Expand Up @@ -206,7 +206,7 @@
"oracle": "0x338ed6787f463394D24813b297401B9F05a8C9d1",
"oracleDecimals": 8,
"oracleDescription": "AAVE / USD",
"oracleLatestAnswer": 7665000000,
"oracleLatestAnswer": 7425000000,
"reserveFactor": 0,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0xfAeF6A702D15428E588d4C0614AEFb4348D83D48",
Expand Down Expand Up @@ -272,7 +272,7 @@
"oracle": "0x7f99817d87baD03ea21E05112Ca799d715730efe",
"oracleDecimals": 8,
"oracleDescription": "SUSD / USD",
"oracleLatestAnswer": 100164737,
"oracleLatestAnswer": 100241227,
"reserveFactor": 1000,
"stableBorrowRateEnabled": false,
"stableDebtToken": "0xF15F26710c827DDe8ACBA678682F3Ce24f2Fb56E",
Expand Down Expand Up @@ -305,7 +305,7 @@
"oracle": "0xECef79E109e997bCA29c1c0897ec9d7b03647F5E",
"oracleDecimals": 8,
"oracleDescription": "USDT / USD",
"oracleLatestAnswer": 99995128,
"oracleLatestAnswer": 99991000,
"reserveFactor": 1000,
"stableBorrowRateEnabled": true,
"stableDebtToken": "0x70eFfc565DB6EEf7B927610155602d31b670e802",
Expand Down Expand Up @@ -338,7 +338,7 @@
"oracle": "0x8dBa75e83DA73cc766A7e5a0ee71F656BAb470d6",
"oracleDecimals": 8,
"oracleDescription": "DAI / USD",
"oracleLatestAnswer": 99979000,
"oracleLatestAnswer": 99990000,
"reserveFactor": 1000,
"stableBorrowRateEnabled": true,
"stableDebtToken": "0xd94112B5B62d53C9402e7A60289c6810dEF1dC9B",
Expand Down
48 changes: 26 additions & 22 deletions src/ProtocolV2TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ contract ProtocolV2TestBase is CommonTestBase {
* @param pool the pool to be snapshotted
* @return ReserveConfig[] list of configs
*/
function createConfigurationSnapshot(
string memory reportName,
ILendingPool pool
) public returns (ReserveConfig[] memory) {
function createConfigurationSnapshot(string memory reportName, ILendingPool pool)
public
returns (ReserveConfig[] memory)
{
string memory path = string(abi.encodePacked('./reports/', reportName, '.json'));
vm.writeFile(path, '{ "reserves": {}, "strategies": {}, "poolConfiguration": {} }');
vm.serializeUint('root', 'chainId', block.chainid);
Expand Down Expand Up @@ -89,9 +89,11 @@ contract ProtocolV2TestBase is CommonTestBase {
/**
* @dev returns the first collateral in the list that cannot be borrowed in stable mode
*/
function _getFirstCollateral(
ReserveConfig[] memory configs
) private pure returns (ReserveConfig memory config) {
function _getFirstCollateral(ReserveConfig[] memory configs)
private
pure
returns (ReserveConfig memory config)
{
for (uint256 i = 0; i < configs.length; i++) {
if (configs[i].usageAsCollateralEnabled && !configs[i].stableBorrowRateEnabled)
return configs[i];
Expand All @@ -109,7 +111,7 @@ contract ProtocolV2TestBase is CommonTestBase {
) internal {
// test all basic interactions
for (uint256 i = 0; i < configs.length; i++) {
uint256 amount = 100 * 10 ** configs[i].decimals;
uint256 amount = 100 * 10**configs[i].decimals;
if (!configs[i].isFrozen) {
_deposit(configs[i], pool, user, amount);
_skipBlocks(1000);
Expand All @@ -135,7 +137,7 @@ contract ProtocolV2TestBase is CommonTestBase {
ReserveConfig memory collateralConfig = _getFirstCollateral(configs);
_deposit(collateralConfig, pool, user, 1000000 ether);
for (uint256 i = 0; i < configs.length; i++) {
uint256 amount = 10 ** configs[i].decimals;
uint256 amount = 10**configs[i].decimals;
if (configs[i].borrowingEnabled) {
_deposit(configs[i], pool, EOA, amount * 2);
this._borrow(configs[i], pool, user, amount, false);
Expand All @@ -157,7 +159,7 @@ contract ProtocolV2TestBase is CommonTestBase {
ReserveConfig memory collateralConfig = _getFirstCollateral(configs);
_deposit(collateralConfig, pool, user, 1000000 ether);
for (uint256 i = 0; i < configs.length; i++) {
uint256 amount = 10 ** configs[i].decimals;
uint256 amount = 10**configs[i].decimals;
if (configs[i].borrowingEnabled && configs[i].stableBorrowRateEnabled) {
_deposit(configs[i], pool, EOA, amount * 2);
this._borrow(configs[i], pool, user, amount, true);
Expand Down Expand Up @@ -441,10 +443,11 @@ contract ProtocolV2TestBase is CommonTestBase {
return vars.configs;
}

function _getStructReserveTokens(
IAaveProtocolDataProvider pdp,
address underlyingAddress
) internal view returns (ReserveTokens memory) {
function _getStructReserveTokens(IAaveProtocolDataProvider pdp, address underlyingAddress)
internal
view
returns (ReserveTokens memory)
{
ReserveTokens memory reserveTokens;
(reserveTokens.aToken, reserveTokens.stableDebtToken, reserveTokens.variableDebtToken) = pdp
.getReserveTokensAddresses(underlyingAddress);
Expand Down Expand Up @@ -512,10 +515,11 @@ contract ProtocolV2TestBase is CommonTestBase {
});
}

function _findReserveConfig(
ReserveConfig[] memory configs,
address underlying
) internal pure returns (ReserveConfig memory) {
function _findReserveConfig(ReserveConfig[] memory configs, address underlying)
internal
pure
returns (ReserveConfig memory)
{
for (uint256 i = 0; i < configs.length; i++) {
if (configs[i].underlying == underlying) {
// Important to clone the struct, to avoid unexpected side effect if modifying the returned config
Expand Down Expand Up @@ -704,10 +708,10 @@ contract ProtocolV2TestBase is CommonTestBase {
}
}

function _requireNoChangeInConfigs(
ReserveConfig memory config1,
ReserveConfig memory config2
) internal pure {
function _requireNoChangeInConfigs(ReserveConfig memory config1, ReserveConfig memory config2)
internal
pure
{
require(
keccak256(abi.encodePacked(config1.symbol)) == keccak256(abi.encodePacked(config2.symbol)),
'_noReservesConfigsChangesApartNewListings() : UNEXPECTED_SYMBOL_CHANGED'
Expand Down
Loading

0 comments on commit 1d973c4

Please sign in to comment.