Skip to content

Commit

Permalink
test: add more gas snapshots for relevant contracts (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra authored Dec 16, 2024
1 parent 3f70474 commit 50a3206
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 3 deletions.
16 changes: 16 additions & 0 deletions snapshots/ProtocolDataProvider.json
Original file line number Diff line number Diff line change
@@ -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"
}
6 changes: 6 additions & 0 deletions snapshots/WrappedTokenGatewayV3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"borrowETH": "250143",
"depositETH": "222665",
"repayETH": "205774",
"withdrawETH": "269647"
}
6 changes: 3 additions & 3 deletions src/contracts/helpers/AaveProtocolDataProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
93 changes: 93 additions & 0 deletions tests/gas/ProtocolDataProvider.gas.t.sol
Original file line number Diff line number Diff line change
@@ -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');
}
}
48 changes: 48 additions & 0 deletions tests/gas/WrappedTokenGatewayV3.gas.t.sol
Original file line number Diff line number Diff line change
@@ -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');
}
}

0 comments on commit 50a3206

Please sign in to comment.