Skip to content

Commit

Permalink
return early for amount=0 (#383)
Browse files Browse the repository at this point in the history
* return early for amount=0

* add back natspec

* update snapshots

* optimize close
  • Loading branch information
snreynolds authored Oct 24, 2024
1 parent d084d9b commit 1b50ca2
Show file tree
Hide file tree
Showing 60 changed files with 63 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129601
129642
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131664
131705
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123869
123910
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124011
124052
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125584
125624
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125031
125106
Original file line number Diff line number Diff line change
@@ -1 +1 @@
132446
132486
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131893
131968
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
146294
146344
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154872
154922
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154872
154922
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_collect_withTakePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154193
154287
Original file line number Diff line number Diff line change
@@ -1 +1 @@
111980
112020
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119753
119803
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119074
119168
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_burnEmpty.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135243
135283
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128380
128420
Original file line number Diff line number Diff line change
@@ -1 +1 @@
132440
132490
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_decrease_take_take.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120329
120423
Original file line number Diff line number Diff line change
@@ -1 +1 @@
159057
159083
Original file line number Diff line number Diff line change
@@ -1 +1 @@
157997
158035
Original file line number Diff line number Diff line change
@@ -1 +1 @@
140872
140898
Original file line number Diff line number Diff line change
@@ -1 +1 @@
177364
177414
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
364745
364771
Original file line number Diff line number Diff line change
@@ -1 +1 @@
373268
373294
Original file line number Diff line number Diff line change
@@ -1 +1 @@
372491
372529
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickLower.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
317617
317643
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
318287
318313
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
243856
243882
Original file line number Diff line number Diff line change
@@ -1 +1 @@
419060
419098
Original file line number Diff line number Diff line change
@@ -1 +1 @@
323648
323674
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withClose.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
420170
420196
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_withSettlePair.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
419228
419266
Original file line number Diff line number Diff line change
@@ -1 +1 @@
455975
456001
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_Bytecode.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7037
7063
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115708
115753
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
116029
116070
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124847
124888
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130570
130611
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185411
185452
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170549
170594
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
240255
240296
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
225393
225438
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129601
129642
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
114739
114784
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
115028
115069
Original file line number Diff line number Diff line change
@@ -1 +1 @@
121971
122016
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
117093
117134
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125911
125952
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129856
129897
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
183759
183800
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
175874
175919
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
237693
237734
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
229808
229853
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
217048
217089
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128884
128925
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120999
121044
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
116195
116236
2 changes: 1 addition & 1 deletion src/PositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ contract PositionManager is
if (currencyDelta < 0) {
// Casting is safe due to limits on the total supply of a pool
_settle(currency, caller, uint256(-currencyDelta));
} else if (currencyDelta > 0) {
} else {
_take(currency, caller, uint256(currencyDelta));
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/base/DeltaResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ abstract contract DeltaResolver is ImmutableState {
/// @param currency Currency to take
/// @param recipient Address to receive the currency
/// @param amount Amount to take
/// @dev Returns early if the amount is 0
function _take(Currency currency, address recipient, uint256 amount) internal {
if (amount == 0) return;
poolManager.take(currency, recipient, amount);
}

Expand All @@ -30,7 +32,9 @@ abstract contract DeltaResolver is ImmutableState {
/// @param currency Currency to settle
/// @param payer Address of the payer
/// @param amount Amount to send
/// @dev Returns early if the amount is 0
function _settle(Currency currency, address payer, uint256 amount) internal {
if (amount == 0) return;
if (currency.isAddressZero()) {
poolManager.settle{value: amount}();
} else {
Expand Down

0 comments on commit 1b50ca2

Please sign in to comment.