diff --git a/snapshots/ProtocolDataProvider.json b/snapshots/ProtocolDataProvider.json new file mode 100644 index 00000000..16bac373 --- /dev/null +++ b/snapshots/ProtocolDataProvider.json @@ -0,0 +1,16 @@ +{ + "getATokenTotalSupply": "57882", + "getFlashLoanEnabled": "16717", + "getInterestRateStrategyAddress": "43034", + "getIsVirtualAccActive": "16767", + "getLiquidationProtocolFee": "16766", + "getPaused": "16855", + "getReserveCaps": "16767", + "getReserveConfigurationData": "17181", + "getReserveTokensAddresses": "43054", + "getSiloedBorrowing": "16770", + "getTotalDebt": "57882", + "getUnbackedMintCap": "16721", + "getUserReserveData": "32363", + "getVirtualUnderlyingBalance": "16533" +} \ No newline at end of file diff --git a/snapshots/WrappedTokenGatewayV3.json b/snapshots/WrappedTokenGatewayV3.json new file mode 100644 index 00000000..33cb2e7c --- /dev/null +++ b/snapshots/WrappedTokenGatewayV3.json @@ -0,0 +1,6 @@ +{ + "borrowETH": "250143", + "depositETH": "222665", + "repayETH": "205774", + "withdrawETH": "269647" +} \ No newline at end of file diff --git a/src/contracts/helpers/AaveProtocolDataProvider.sol b/src/contracts/helpers/AaveProtocolDataProvider.sol index 671b658b..b8b97581 100644 --- a/src/contracts/helpers/AaveProtocolDataProvider.sol +++ b/src/contracts/helpers/AaveProtocolDataProvider.sol @@ -154,12 +154,12 @@ contract AaveProtocolDataProvider is IPoolDataProvider { uint256 unbacked, uint256 accruedToTreasuryScaled, uint256 totalAToken, - uint256 totalStableDebt, + uint256, uint256 totalVariableDebt, uint256 liquidityRate, uint256 variableBorrowRate, - uint256 stableBorrowRate, - uint256 averageStableBorrowRate, + uint256, + uint256, uint256 liquidityIndex, uint256 variableBorrowIndex, uint40 lastUpdateTimestamp diff --git a/tests/gas/ProtocolDataProvider.gas.t.sol b/tests/gas/ProtocolDataProvider.gas.t.sol new file mode 100644 index 00000000..c537cd1a --- /dev/null +++ b/tests/gas/ProtocolDataProvider.gas.t.sol @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity ^0.8.0; + +import 'forge-std/Test.sol'; + +import {Errors} from '../../src/contracts/protocol/libraries/helpers/Errors.sol'; +import {UserConfiguration} from '../../src/contracts/protocol/libraries/configuration/UserConfiguration.sol'; +import {Testhelpers, IERC20} from './Testhelpers.sol'; + +/** + * Scenario suite for PDP getters. + */ +contract ProtocolDataProvider_gas_Tests is Testhelpers { + // mock users to supply and borrow liquidity + address user = makeAddr('user'); + + function test_getReserveConfigurationData() external { + contracts.protocolDataProvider.getReserveConfigurationData(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getReserveConfigurationData'); + } + + function test_getReserveCaps() external { + contracts.protocolDataProvider.getReserveCaps(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getReserveCaps'); + } + + function test_getPaused() external { + contracts.protocolDataProvider.getPaused(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getPaused'); + } + + function test_getSiloedBorrowing() external { + contracts.protocolDataProvider.getSiloedBorrowing(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getSiloedBorrowing'); + } + + function test_getLiquidationProtocolFee() external { + contracts.protocolDataProvider.getLiquidationProtocolFee(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getLiquidationProtocolFee'); + } + + function test_getUnbackedMintCap() external { + contracts.protocolDataProvider.getUnbackedMintCap(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getUnbackedMintCap'); + } + + function test_getDebtCeiling() external { + contracts.protocolDataProvider.getDebtCeiling(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getPaused'); + } + + function test_getATokenTotalSupply() external { + contracts.protocolDataProvider.getATokenTotalSupply(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getATokenTotalSupply'); + } + + function test_getTotalDebt() external { + contracts.protocolDataProvider.getATokenTotalSupply(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getTotalDebt'); + } + + function test_getUserReserveData() external { + _supplyOnReserve(user, 1e6, tokenList.usdx); + + contracts.protocolDataProvider.getUserReserveData(tokenList.usdx, user); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getUserReserveData'); + } + + function test_getReserveTokensAddresses() external { + contracts.protocolDataProvider.getReserveTokensAddresses(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getReserveTokensAddresses'); + } + + function test_getInterestRateStrategyAddress() external { + contracts.protocolDataProvider.getInterestRateStrategyAddress(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getInterestRateStrategyAddress'); + } + + function test_getFlashLoanEnabled() external { + contracts.protocolDataProvider.getFlashLoanEnabled(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getFlashLoanEnabled'); + } + + function test_getIsVirtualAccActive() external { + contracts.protocolDataProvider.getIsVirtualAccActive(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getIsVirtualAccActive'); + } + + function test_getVirtualUnderlyingBalance() external { + contracts.protocolDataProvider.getVirtualUnderlyingBalance(tokenList.usdx); + vm.snapshotGasLastCall('ProtocolDataProvider', 'getVirtualUnderlyingBalance'); + } +} diff --git a/tests/gas/WrappedTokenGatewayV3.gas.t.sol b/tests/gas/WrappedTokenGatewayV3.gas.t.sol new file mode 100644 index 00000000..b7eef065 --- /dev/null +++ b/tests/gas/WrappedTokenGatewayV3.gas.t.sol @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity ^0.8.0; + +import 'forge-std/Test.sol'; + +import {Errors} from '../../src/contracts/protocol/libraries/helpers/Errors.sol'; +import {UserConfiguration} from '../../src/contracts/protocol/libraries/configuration/UserConfiguration.sol'; +import {Testhelpers, IERC20} from './Testhelpers.sol'; +import {VariableDebtToken} from '../../src/contracts/protocol/tokenization/VariableDebtToken.sol'; + +/** + * Scenario suite for PDP getters. + */ +contract WrappedTokenGatewayV3_gas_Tests is Testhelpers { + // mock users to supply and borrow liquidity + address user = makeAddr('user'); + + function test_flow() external { + vm.startPrank(user); + deal(user, 2 ether); + (address aEthToken, , address wEthVariableDebt) = contracts + .protocolDataProvider + .getReserveTokensAddresses(tokenList.weth); + + contracts.wrappedTokenGateway.depositETH{value: 1 ether}(address(0), user, 0); + vm.snapshotGasLastCall('WrappedTokenGatewayV3', 'depositETH'); + + _skip(100); + + VariableDebtToken(wEthVariableDebt).approveDelegation( + report.wrappedTokenGateway, + type(uint256).max + ); + contracts.wrappedTokenGateway.borrowETH(address(0), 0.1 ether, 0); + vm.snapshotGasLastCall('WrappedTokenGatewayV3', 'borrowETH'); + + _skip(100); + + contracts.wrappedTokenGateway.repayETH{value: 0.2 ether}(address(0), type(uint256).max, user); + vm.snapshotGasLastCall('WrappedTokenGatewayV3', 'repayETH'); + + _skip(100); + + IERC20(aEthToken).approve(report.wrappedTokenGateway, type(uint256).max); + contracts.wrappedTokenGateway.withdrawETH(address(0), type(uint256).max, user); + vm.snapshotGasLastCall('WrappedTokenGatewayV3', 'withdrawETH'); + } +}