Skip to content

Commit

Permalink
some more gas snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Jul 15, 2024
1 parent 4cec450 commit 6e4ce61
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/autocompound_exactUnclaimedFees.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
291244
291256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
223603
223615
2 changes: 1 addition & 1 deletion .forge-snapshots/autocompound_excessFeesCredit.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
311783
311795
1 change: 1 addition & 0 deletions .forge-snapshots/collect_erc20.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
236784
2 changes: 1 addition & 1 deletion .forge-snapshots/decreaseLiquidity_erc20.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
209314
209326
2 changes: 1 addition & 1 deletion .forge-snapshots/decreaseLiquidity_erc6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
209326
209338
2 changes: 1 addition & 1 deletion .forge-snapshots/increaseLiquidity_erc20.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
194862
194874
2 changes: 1 addition & 1 deletion .forge-snapshots/increaseLiquidity_erc6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
194874
194886
2 changes: 1 addition & 1 deletion .forge-snapshots/mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
493163
493199
1 change: 1 addition & 0 deletions .forge-snapshots/sameRange_collect.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
236784
1 change: 1 addition & 0 deletions .forge-snapshots/sameRange_decreaseAllLiquidity.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
231686
1 change: 1 addition & 0 deletions .forge-snapshots/sameRange_mint.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
345049
77 changes: 76 additions & 1 deletion test/position-managers/Gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -297,5 +297,80 @@ contract GasTest is Test, Deployers, GasSnapshot, LiquidityOperations {

function test_gas_burn() public {}
function test_gas_burnEmpty() public {}
function test_gas_collect() public {}

function test_gas_collect_erc20() public {
_mint(range, 10_000 ether, block.timestamp + 1, address(this), ZERO_BYTES);
uint256 tokenId = lpm.nextTokenId() - 1;

// donate to create fee revenue
donateRouter.donate(range.poolKey, 0.2e18, 0.2e18, ZERO_BYTES);

Planner.Plan memory planner =
Planner.init().add(Actions.COLLECT, abi.encode(tokenId, address(this), ZERO_BYTES, false));

Currency[] memory currencies = new Currency[](2);
currencies[0] = currency0;
currencies[1] = currency1;

lpm.modifyLiquidities(abi.encode(planner.actions, planner.params, currencies));
snapLastCall("collect_erc20");
}

// same-range gas tests
function test_gas_sameRange_mint() public {
_mint(range, 10_000 ether, block.timestamp + 1, address(this), ZERO_BYTES);

Planner.Plan memory plan = Planner.init().add(
Actions.MINT, abi.encode(range, 10_001 ether, block.timestamp + 1, address(this), ZERO_BYTES)
);
Currency[] memory currencies = new Currency[](2);
currencies[0] = currency0;
currencies[1] = currency1;
vm.prank(alice);
lpm.modifyLiquidities(abi.encode(plan.actions, plan.params, currencies, currencies));
snapLastCall("sameRange_mint");
}

function test_gas_sameRange_decrease() public {
// two positions of the same range, one of them decreases the entirety of the liquidity
vm.startPrank(alice);
_mint(range, 10_000 ether, block.timestamp + 1, address(this), ZERO_BYTES);
vm.stopPrank();

_mint(range, 10_000 ether, block.timestamp + 1, address(this), ZERO_BYTES);
uint256 tokenId = lpm.nextTokenId() - 1;

Planner.Plan memory planner =
Planner.init().add(Actions.DECREASE, abi.encode(tokenId, 10_000 ether, ZERO_BYTES, false));

Currency[] memory currencies = new Currency[](2);
currencies[0] = currency0;
currencies[1] = currency1;

lpm.modifyLiquidities(abi.encode(planner.actions, planner.params, currencies));
snapLastCall("sameRange_decreaseAllLiquidity");
}

function test_gas_sameRange_collect() public {
// two positions of the same range, one of them collects all their fees
vm.startPrank(alice);
_mint(range, 10_000 ether, block.timestamp + 1, address(this), ZERO_BYTES);
vm.stopPrank();

_mint(range, 10_000 ether, block.timestamp + 1, address(this), ZERO_BYTES);
uint256 tokenId = lpm.nextTokenId() - 1;

// donate to create fee revenue
donateRouter.donate(range.poolKey, 0.2e18, 0.2e18, ZERO_BYTES);

Planner.Plan memory planner =
Planner.init().add(Actions.COLLECT, abi.encode(tokenId, address(this), ZERO_BYTES, false));

Currency[] memory currencies = new Currency[](2);
currencies[0] = currency0;
currencies[1] = currency1;

lpm.modifyLiquidities(abi.encode(planner.actions, planner.params, currencies));
snapLastCall("sameRange_collect");
}
}

0 comments on commit 6e4ce61

Please sign in to comment.