Skip to content

Commit

Permalink
snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
massun-onibakuchi committed Jun 3, 2024
1 parent 6e0081e commit bba39bc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
24 changes: 4 additions & 20 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
GrimReaperHuffTest:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 390235, ~: 390503)
GrimReaperHuffTest:testLiquidate() (gas: 390412)
GrimReaperHuffTest:testOnlyOwner(address) (runs: 257, μ: 20235, ~: 20235)
GrimReaperHuffTest:testRecoverERC20() (gas: 330912)
GrimReaperHuffTest:testRevertIfLiquidationFail() (gas: 52407)
GrimReaperSolTest:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 390396, ~: 390912)
GrimReaperSolTest:testLiquidate() (gas: 390820)
GrimReaperSolTest:testOnlyOwner(address) (runs: 257, μ: 18922, ~: 18922)
GrimReaperSolTest:testRecoverERC20() (gas: 331740)
GrimReaperSolTest:testRevertIfLiquidationFail() (gas: 51145)
OptimizedGrimReaperSolTest:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 390301, ~: 390568)
OptimizedGrimReaperSolTest:testLiquidate() (gas: 390477)
OptimizedGrimReaperSolTest:testOnlyOwner(address) (runs: 257, μ: 20388, ~: 20388)
OptimizedGrimReaperSolTest:testRecoverERC20() (gas: 330873)
OptimizedGrimReaperSolTest:testRevertIfLiquidationFail() (gas: 52467)
OptimizedGrimReaperSolV2Test:testFuzz_Liquidate(uint256,address) (runs: 257, μ: 390417, ~: 390685)
OptimizedGrimReaperSolV2Test:testLiquidate() (gas: 390594)
OptimizedGrimReaperSolV2Test:testOnlyOwner(address) (runs: 257, μ: 20498, ~: 20498)
OptimizedGrimReaperSolV2Test:testRecoverERC20() (gas: 330873)
OptimizedGrimReaperSolV2Test:testRevertIfLiquidationFail() (gas: 52613)
GrimReaperHuffTest:testLiquidate() (gas: 390453)
GrimReaperSolTest:testLiquidate() (gas: 391254)
OptimizedGrimReaperSolTest:testLiquidate() (gas: 390518)
OptimizedGrimReaperSolV2Test:testLiquidate() (gas: 390635)
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ For more information on how to use Foundry, check out the [Foundry Github Reposi

| Single Liquidation (Optimizer runs: 200) | Gas Used | Bytecode Size (kB) |
| ---------------------------------------- | -------- | ------------------ |
| Solidity Contract | 97933 | 1.005 |
| Assembly | 97295 | 0.303 |
| Assembly (GrimReaper V2) | 97264 | 0.317 |
| Huff Contract | 97234 | 0.245 |
| Solidity Contract | 98783 | 1.005 |
| Assembly | 97688 | 0.303 |
| Assembly (GrimReaper V2) | 97657 | 0.317 |
| Huff Contract | 97627 | 0.245 |

| Single Liquidation (Optimizer runs: 10_000_000) | Gas Used | Bytecode Size (kB) |
| ----------------------------------------------- | -------- | ------------------ |
| Solidity Contract | 97339 | 1.308 |
| Assembly | 96755 | 0.330 |
| Assembly (GrimReaper V2) | 96724 | 0.344 |
| Huff Contract | 96706 | 0.245 |
| Solidity Contract | 98127 | 1.308 |
| Assembly | 97098 | 0.330 |
| Assembly (GrimReaper V2) | 97067 | 0.344 |
| Huff Contract | 97049 | 0.245 |

> `66270` gas is used for the liquidation logic itself on mock Aave v3 pool.
Expand Down
23 changes: 14 additions & 9 deletions test/GrimReaper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,19 @@ abstract contract GrimReaperBaseTest is Test {
vm.expectCall(
POOL, abi.encodeWithSelector(MockPool.liquidationCall.selector, collateral, debt, user, amount, false)
);
vm.prank(owner);
_callLiquidate(address(collateral), address(debt), user, amount);
_callLiquidate(owner, address(collateral), address(debt), user, amount);

assertEq(debt.balanceOf(address(reaper)), 0);
assertEq(collateral.balanceOf(address(reaper)), liquidationBonus);
}

function _callLiquidate(address _col, address _debt, address _user, uint256 _debtToCover) public virtual {
function _callLiquidate(address caller, address _col, address _debt, address _user, uint256 _debtToCover)
public
virtual
{
uint256 _before = gasleft();
(bool s, ) = address(reaper).call(abi.encodeCall(reaper.execute,(_col, _debt, _user, _debtToCover)));
vm.prank(caller);
(bool s,) = address(reaper).call(abi.encodeCall(reaper.execute, (_col, _debt, _user, _debtToCover)));
uint256 _after = gasleft();
console2.log("Gas used: ", (_before - _after));
require(s, "ExpectRevert: liquidation failed");
Expand All @@ -76,8 +79,7 @@ abstract contract GrimReaperBaseTest is Test {
function testRevertIfLiquidationFail() public {
pool.setLiquidation(false);
vm.expectRevert("ExpectRevert: liquidation failed");
vm.prank(owner);
this._callLiquidate(address(collateral), address(debt), address(0xcafe), 1000);
this._callLiquidate(owner, address(collateral), address(debt), address(0xcafe), 1000);
}

function testRecoverERC20() public virtual {
Expand All @@ -97,8 +99,7 @@ abstract contract GrimReaperBaseTest is Test {
vm.assume(non_user != owner);

vm.expectRevert();
vm.prank(non_user);
_callLiquidate(address(collateral), address(debt), address(0xcafe), 1000);
_callLiquidate(non_user, address(collateral), address(debt), address(0xcafe), 1000);

vm.expectRevert();
vm.prank(non_user);
Expand All @@ -117,10 +118,14 @@ contract OptimizedGrimReaperSolTest is GrimReaperBaseTest {
reaper = GrimReaper(address(new OptimizedGrimReaper()));
}

function _callLiquidate(address _col, address _debt, address _user, uint256 _debtToCover) public override {
function _callLiquidate(address caller, address _col, address _debt, address _user, uint256 _debtToCover)
public
override
{
bytes memory payload = getLiquidationPayload(_col, _debt, _user, _debtToCover);

uint256 _before = gasleft();
vm.prank(caller);
(bool success,) = address(reaper).call(payload);
uint256 _after = gasleft();
console2.log("Gas used: ", (_before - _after));
Expand Down

0 comments on commit bba39bc

Please sign in to comment.