Skip to content

Commit

Permalink
fix: update tooling to support virtual balance and new ir (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra authored Jul 24, 2024
1 parent e627c74 commit f0e26a6
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ out/
.env
.env.bk
.assets

# artifacts
reports/
diffs/
downloads/
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"prettier-plugin-solidity": "^1.1.1"
},
"dependencies": {
"@bgd-labs/aave-cli": "^0.7.2",
"catapulta-verify": "^1.0.6-b4e4af767ca0ef6644d50aeca57aae1a560fe40d.0"
"@bgd-labs/aave-cli": "^0.16.2",
"catapulta-verify": "^1.1.1"
}
}
2 changes: 1 addition & 1 deletion tests/mocks/AaveV3TestListing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'aave-v3-periphery/contracts/v3-config-engine/AaveV3Payload.sol';
import {TestnetERC20} from 'aave-v3-periphery/contracts/mocks/testnet-helpers/TestnetERC20.sol';
import {MockAggregator} from 'aave-v3-core/contracts/mocks/oracle/CLAggregators/MockAggregator.sol';
import {ACLManager} from 'aave-v3-core/contracts/protocol/configuration/ACLManager.sol';
import {MarketReport} from 'src/deployments/interfaces/IMarketReportTypes.sol';
import {MarketReport} from '../../src/deployments/interfaces/IMarketReportTypes.sol';

/**
* @dev Smart contract for token listing, for testing purposes
Expand Down
10 changes: 8 additions & 2 deletions tests/periphery/v3-config-engine/AaveV3ConfigEngineTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ contract AaveV3ConfigEngineTest is TestnetProcedures, ProtocolV3TestBase {
supplyCap: 85_000,
borrowCap: 60_000,
debtCeiling: 0,
eModeCategory: 0
eModeCategory: 0,
virtualAccActive: true,
virtualBalance: 0,
aTokenUnderlyingBalance: 0
});

_validateReserveConfig(expectedAssetConfig, allConfigsAfter);
Expand Down Expand Up @@ -200,7 +203,10 @@ contract AaveV3ConfigEngineTest is TestnetProcedures, ProtocolV3TestBase {
supplyCap: 85_000,
borrowCap: 60_000,
debtCeiling: 0,
eModeCategory: 0
eModeCategory: 0,
virtualAccActive: true,
virtualBalance: 0,
aTokenUnderlyingBalance: 0
});

_validateReserveConfig(expectedAssetConfig, allConfigsAfter);
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/DiffUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract DiffUtils is Test {

string[] memory inputs = new string[](7);
inputs[0] = 'npx';
inputs[1] = '@bgd-labs/aave-cli@^0.7.2';
inputs[1] = '@bgd-labs/aave-cli@^0.16.2';
inputs[2] = 'diff-snapshots';
inputs[3] = beforePath;
inputs[4] = afterPath;
Expand Down
92 changes: 57 additions & 35 deletions tests/utils/ProtocolV3TestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ struct ReserveConfig {
uint256 borrowCap;
uint256 debtCeiling;
uint256 eModeCategory;
bool virtualAccActive;
uint256 virtualBalance;
uint256 aTokenUnderlyingBalance;
}

struct LocalVars {
Expand Down Expand Up @@ -187,42 +190,43 @@ contract ProtocolV3TestBase is DiffUtils {
// keys for json stringification
string memory strategiesKey = 'stategies';
string memory content = '{}';
vm.serializeJson(strategiesKey, '{}');

address[] memory usedStrategies = new address[](configs.length);
for (uint256 i = 0; i < configs.length; i++) {
if (!_isInAddressArray(usedStrategies, configs[i].interestRateStrategy)) {
usedStrategies[i] = configs[i].interestRateStrategy;
IDefaultInterestRateStrategyV2 strategy = IDefaultInterestRateStrategyV2(
configs[i].interestRateStrategy
);
string memory key = vm.toString(address(strategy));
vm.serializeString(
key,
'baseVariableBorrowRate',
vm.toString(strategy.getBaseVariableBorrowRate(configs[i].underlying))
);
vm.serializeString(
key,
'variableRateSlope1',
vm.toString(strategy.getVariableRateSlope1(configs[i].underlying))
);
vm.serializeString(
key,
'variableRateSlope2',
vm.toString(strategy.getVariableRateSlope2(configs[i].underlying))
);
vm.serializeString(
key,
'maxVariableBorrowRate',
vm.toString(strategy.getMaxVariableBorrowRate(configs[i].underlying))
);
string memory object = vm.serializeString(
key,
'optimalUsageRatio',
vm.toString(strategy.getOptimalUsageRatio(configs[i].underlying))
);
content = vm.serializeString(strategiesKey, key, object);
}
address asset = configs[i].underlying;
string memory key = vm.toString(asset);
vm.serializeJson(key, '{}');
vm.serializeString(key, 'address', vm.toString(configs[i].interestRateStrategy));
IDefaultInterestRateStrategyV2 strategy = IDefaultInterestRateStrategyV2(
configs[i].interestRateStrategy
);
vm.serializeString(
key,
'baseVariableBorrowRate',
vm.toString(strategy.getBaseVariableBorrowRate(asset))
);
vm.serializeString(
key,
'variableRateSlope1',
vm.toString(strategy.getVariableRateSlope1(asset))
);
vm.serializeString(
key,
'variableRateSlope2',
vm.toString(strategy.getVariableRateSlope2(asset))
);
vm.serializeString(
key,
'maxVariableBorrowRate',
vm.toString(strategy.getMaxVariableBorrowRate(asset))
);
string memory object = vm.serializeString(
key,
'optimalUsageRatio',
vm.toString(strategy.getOptimalUsageRatio(asset))
);

content = vm.serializeString(strategiesKey, key, object);
}
string memory output = vm.serializeString('root', 'strategies', content);
vm.writeJson(output, path);
Expand Down Expand Up @@ -327,6 +331,11 @@ contract ProtocolV3TestBase is DiffUtils {
} catch {}
}
}

vm.serializeBool(key, 'virtualAccountingActive', config.virtualAccActive);
vm.serializeUint(key, 'virtualBalance', config.virtualBalance);
vm.serializeUint(key, 'aTokenUnderlyingBalance', config.aTokenUnderlyingBalance);

string memory out = vm.serializeUint(
key,
'oracleLatestAnswer',
Expand Down Expand Up @@ -450,6 +459,16 @@ contract ProtocolV3TestBase is DiffUtils {

localConfig.isFlashloanable = configuration.getFlashLoanEnabled();

// 3.1 configurations
localConfig.virtualAccActive = configuration.getIsVirtualAccActive();

if (localConfig.virtualAccActive) {
localConfig.virtualBalance = pool.getVirtualUnderlyingBalance(reserve.tokenAddress);
localConfig.aTokenUnderlyingBalance = IERC20Detailed(reserve.tokenAddress).balanceOf(
localConfig.aToken
);
}

return localConfig;
}

Expand Down Expand Up @@ -481,7 +500,10 @@ contract ProtocolV3TestBase is DiffUtils {
supplyCap: config.supplyCap,
borrowCap: config.borrowCap,
debtCeiling: config.debtCeiling,
eModeCategory: config.eModeCategory
eModeCategory: config.eModeCategory,
virtualAccActive: config.virtualAccActive,
virtualBalance: config.virtualBalance,
aTokenUnderlyingBalance: config.aTokenUnderlyingBalance
});
}

Expand Down

0 comments on commit f0e26a6

Please sign in to comment.