diff --git a/.forge-snapshots/autocompound_exactUnclaimedFees.snap b/.forge-snapshots/autocompound_exactUnclaimedFees.snap index 021404a17..f3ea78cd8 100644 --- a/.forge-snapshots/autocompound_exactUnclaimedFees.snap +++ b/.forge-snapshots/autocompound_exactUnclaimedFees.snap @@ -1 +1 @@ -291244 \ No newline at end of file +291256 \ No newline at end of file diff --git a/.forge-snapshots/autocompound_exactUnclaimedFees_exactCustodiedFees.snap b/.forge-snapshots/autocompound_exactUnclaimedFees_exactCustodiedFees.snap index 10b683f25..84be2bcd5 100644 --- a/.forge-snapshots/autocompound_exactUnclaimedFees_exactCustodiedFees.snap +++ b/.forge-snapshots/autocompound_exactUnclaimedFees_exactCustodiedFees.snap @@ -1 +1 @@ -223603 \ No newline at end of file +223615 \ No newline at end of file diff --git a/.forge-snapshots/autocompound_excessFeesCredit.snap b/.forge-snapshots/autocompound_excessFeesCredit.snap index 3aa28ddf4..6975d63ad 100644 --- a/.forge-snapshots/autocompound_excessFeesCredit.snap +++ b/.forge-snapshots/autocompound_excessFeesCredit.snap @@ -1 +1 @@ -311783 \ No newline at end of file +311795 \ No newline at end of file diff --git a/.forge-snapshots/collect_erc20.snap b/.forge-snapshots/collect_erc20.snap new file mode 100644 index 000000000..27c17f0fb --- /dev/null +++ b/.forge-snapshots/collect_erc20.snap @@ -0,0 +1 @@ +236784 \ No newline at end of file diff --git a/.forge-snapshots/decreaseLiquidity_erc20.snap b/.forge-snapshots/decreaseLiquidity_erc20.snap index c2b3a62d0..a164d0002 100644 --- a/.forge-snapshots/decreaseLiquidity_erc20.snap +++ b/.forge-snapshots/decreaseLiquidity_erc20.snap @@ -1 +1 @@ -209314 \ No newline at end of file +209326 \ No newline at end of file diff --git a/.forge-snapshots/decreaseLiquidity_erc6909.snap b/.forge-snapshots/decreaseLiquidity_erc6909.snap index a164d0002..6f8ef9c6b 100644 --- a/.forge-snapshots/decreaseLiquidity_erc6909.snap +++ b/.forge-snapshots/decreaseLiquidity_erc6909.snap @@ -1 +1 @@ -209326 \ No newline at end of file +209338 \ No newline at end of file diff --git a/.forge-snapshots/increaseLiquidity_erc20.snap b/.forge-snapshots/increaseLiquidity_erc20.snap index a2041485c..553b43e9e 100644 --- a/.forge-snapshots/increaseLiquidity_erc20.snap +++ b/.forge-snapshots/increaseLiquidity_erc20.snap @@ -1 +1 @@ -194862 \ No newline at end of file +194874 \ No newline at end of file diff --git a/.forge-snapshots/increaseLiquidity_erc6909.snap b/.forge-snapshots/increaseLiquidity_erc6909.snap index 553b43e9e..e4d9ffe75 100644 --- a/.forge-snapshots/increaseLiquidity_erc6909.snap +++ b/.forge-snapshots/increaseLiquidity_erc6909.snap @@ -1 +1 @@ -194874 \ No newline at end of file +194886 \ No newline at end of file diff --git a/.forge-snapshots/mint.snap b/.forge-snapshots/mint.snap index b0807c1be..bd2905ff5 100644 --- a/.forge-snapshots/mint.snap +++ b/.forge-snapshots/mint.snap @@ -1 +1 @@ -493163 \ No newline at end of file +493199 \ No newline at end of file diff --git a/.forge-snapshots/sameRange_collect.snap b/.forge-snapshots/sameRange_collect.snap new file mode 100644 index 000000000..27c17f0fb --- /dev/null +++ b/.forge-snapshots/sameRange_collect.snap @@ -0,0 +1 @@ +236784 \ No newline at end of file diff --git a/.forge-snapshots/sameRange_decreaseAllLiquidity.snap b/.forge-snapshots/sameRange_decreaseAllLiquidity.snap new file mode 100644 index 000000000..303ab70e4 --- /dev/null +++ b/.forge-snapshots/sameRange_decreaseAllLiquidity.snap @@ -0,0 +1 @@ +231686 \ No newline at end of file diff --git a/.forge-snapshots/sameRange_mint.snap b/.forge-snapshots/sameRange_mint.snap new file mode 100644 index 000000000..dafff5324 --- /dev/null +++ b/.forge-snapshots/sameRange_mint.snap @@ -0,0 +1 @@ +345049 \ No newline at end of file diff --git a/test/position-managers/Gas.t.sol b/test/position-managers/Gas.t.sol index ce9989f06..e5cf68b8b 100644 --- a/test/position-managers/Gas.t.sol +++ b/test/position-managers/Gas.t.sol @@ -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"); + } }