Skip to content

Commit

Permalink
test: add more gas snapshots for relevant contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Dec 14, 2024
1 parent 3f70474 commit e9951e0
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
17 changes: 17 additions & 0 deletions snapshots/ProtocolDataProvider.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"getATokenTotalSupply": "57882",
"getFlashLoanEnabled": "16717",
"getInterestRateStrategyAddress": "43034",
"getIsVirtualAccActive": "16767",
"getLiquidationProtocolFee": "16766",
"getPaused": "16855",
"getReserveCaps": "16767",
"getReserveConfigurationData": "17181",
"getReserveData": "74487",
"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"
}
98 changes: 98 additions & 0 deletions tests/gas/ProtocolDataProvider.gas.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// 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_getReserveData() external {
contracts.protocolDataProvider.getReserveData(tokenList.usdx);
vm.snapshotGasLastCall('ProtocolDataProvider', 'getReserveData');
}

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');
}
}
45 changes: 45 additions & 0 deletions tests/gas/WrappedTokenGatewayV3.gas.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 e9951e0

Please sign in to comment.