Skip to content

Commit

Permalink
feat: early return dutch decay if none
Browse files Browse the repository at this point in the history
If startAmount == endAmount, early return. This is always true for
either the inputs or outputs of an order, so saves the decay calculation
half the time
  • Loading branch information
marktoda committed Apr 5, 2024
1 parent a23f3a3 commit 7cdd074
Show file tree
Hide file tree
Showing 53 changed files with 82 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
181935
181847
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-DutchOrder-ExecuteBatch.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
196793
196617
Original file line number Diff line number Diff line change
@@ -1 +1 @@
206561
206341
Original file line number Diff line number Diff line change
@@ -1 +1 @@
260215
259951
Original file line number Diff line number Diff line change
@@ -1 +1 @@
190325
190149
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-DutchOrder-ExecuteSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
148151
148063
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133713
133625
Original file line number Diff line number Diff line change
@@ -1 +1 @@
157462
157374
Original file line number Diff line number Diff line change
@@ -1 +1 @@
182099
182011
Original file line number Diff line number Diff line change
@@ -1 +1 @@
197099
196923
Original file line number Diff line number Diff line change
@@ -1 +1 @@
206862
206642
Original file line number Diff line number Diff line change
@@ -1 +1 @@
260530
260266
Original file line number Diff line number Diff line change
@@ -1 +1 @@
190625
190449
Original file line number Diff line number Diff line change
@@ -1 +1 @@
148314
148226
Original file line number Diff line number Diff line change
@@ -1 +1 @@
133881
133793
Original file line number Diff line number Diff line change
@@ -1 +1 @@
157629
157541
Original file line number Diff line number Diff line change
@@ -1 +1 @@
189053
188965
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-V2DutchOrder-ExclusiveFiller.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
158962
158941
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-V2DutchOrder-ExecuteBatch.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
211110
210934
Original file line number Diff line number Diff line change
@@ -1 +1 @@
221518
221298
Original file line number Diff line number Diff line change
@@ -1 +1 @@
275828
275564
Original file line number Diff line number Diff line change
@@ -1 +1 @@
204636
204460
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-V2DutchOrder-ExecuteSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
155265
155177
Original file line number Diff line number Diff line change
@@ -1 +1 @@
140827
140739
Original file line number Diff line number Diff line change
@@ -1 +1 @@
164576
164488
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-V2DutchOrder-InputOverride.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
159319
159298
2 changes: 1 addition & 1 deletion .forge-snapshots/Base-V2DutchOrder-OutputOverride.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
158989
158968
2 changes: 1 addition & 1 deletion .forge-snapshots/DirectFillerFillMacroSingleOrder.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
136170
136082
Original file line number Diff line number Diff line change
@@ -1 +1 @@
175018
174886
2 changes: 1 addition & 1 deletion .forge-snapshots/DirectFillerFillMacroTestEth1Output.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
147347
147259
2 changes: 1 addition & 1 deletion .forge-snapshots/DirectFillerFillMacroTestEth2Outputs.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170518
170342
Original file line number Diff line number Diff line change
@@ -1 +1 @@
435049
434653
2 changes: 1 addition & 1 deletion .forge-snapshots/DirectFillerFillMacroTwoOrders.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
255883
255663
Original file line number Diff line number Diff line change
@@ -1 +1 @@
363346
363038
2 changes: 1 addition & 1 deletion .forge-snapshots/EthOutputTestEthOutput.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
156180
156002
Original file line number Diff line number Diff line change
@@ -1 +1 @@
176825
176693
Original file line number Diff line number Diff line change
@@ -1 +1 @@
162817
162685
Original file line number Diff line number Diff line change
@@ -1 +1 @@
165956
165824
Original file line number Diff line number Diff line change
@@ -1 +1 @@
146783
146651
2 changes: 1 addition & 1 deletion .forge-snapshots/ProtocolFeesGasComparisonTest-NoFees.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
149180
149092
Original file line number Diff line number Diff line change
@@ -1 +1 @@
124842
124754
2 changes: 1 addition & 1 deletion .forge-snapshots/SwapRouter02ExecutorExecute.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
262930
262752
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118049
117871
2 changes: 1 addition & 1 deletion .forge-snapshots/testExclusiveFillerSucceeds.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
174023
173935
4 changes: 3 additions & 1 deletion src/lib/DutchDecayLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ library DutchDecayLib {
view
returns (uint256 decayedAmount)
{
if (decayEndTime <= decayStartTime) {
if (startAmount == endAmount) {
return startAmount;
} else if (decayEndTime <= decayStartTime) {
revert EndTimeBeforeStartTime();
} else if (decayEndTime <= block.timestamp) {
decayedAmount = endAmount;
Expand Down
28 changes: 14 additions & 14 deletions test/base/BaseReactor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
ResolvedOrder memory order = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(deadline).withValidationContract(
additionalValidationContract
),
),
input: InputToken(tokenIn, inputAmount, inputAmount),
outputs: OutputsBuilder.single(address(tokenOut), outputAmount, swapper),
sig: hex"00",
Expand Down Expand Up @@ -274,7 +274,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
orders[0] = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 100).withNonce(
0
),
),
input: InputToken(tokenIn, inputAmount, inputAmount),
outputs: OutputsBuilder.single(address(tokenOut), outputAmount, swapper),
sig: hex"00",
Expand All @@ -284,7 +284,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
orders[1] = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 100).withNonce(
1
),
),
input: InputToken(tokenIn, 2 * inputAmount, 2 * inputAmount),
outputs: OutputsBuilder.single(address(tokenOut), 2 * outputAmount, swapper),
sig: hex"00",
Expand Down Expand Up @@ -322,7 +322,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
orders[0] = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 100).withNonce(
0
),
),
input: InputToken(tokenIn, inputAmount, inputAmount),
outputs: OutputsBuilder.single(NATIVE, outputAmount, swapper),
sig: hex"00",
Expand All @@ -332,7 +332,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
orders[1] = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 100).withNonce(
1
),
),
input: InputToken(tokenIn, 2 * inputAmount, 2 * inputAmount),
outputs: OutputsBuilder.single(NATIVE, 2 * outputAmount, swapper),
sig: hex"00",
Expand Down Expand Up @@ -374,7 +374,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
orders[0] = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 100).withNonce(
0
),
),
input: InputToken(tokenIn, ONE, ONE),
outputs: OutputsBuilder.multiple(address(tokenOut), output1, swapper),
sig: hex"00",
Expand All @@ -384,7 +384,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
orders[1] = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 100).withNonce(
1
),
),
input: InputToken(tokenIn, ONE * 2, ONE * 2),
outputs: OutputsBuilder.multiple(address(tokenOut), output2, swapper),
sig: hex"00",
Expand Down Expand Up @@ -431,7 +431,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
orders[0] = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 100).withNonce(
0
),
),
input: InputToken(tokenIn, ONE, ONE),
outputs: outputs1,
sig: hex"00",
Expand All @@ -441,7 +441,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
orders[1] = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 100).withNonce(
1
),
),
input: InputToken(tokenIn, ONE * 2, ONE * 2),
outputs: outputs2,
sig: hex"00",
Expand Down Expand Up @@ -523,7 +523,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
ResolvedOrder memory order = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 100).withNonce(
123
),
),
input: InputToken(tokenIn, inputAmount, inputAmount),
outputs: OutputsBuilder.single(address(tokenOut), outputAmount, swapper),
sig: hex"00",
Expand Down Expand Up @@ -691,7 +691,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
ResolvedOrder memory order = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(deadline).withValidationContract(
additionalValidationContract
),
),
input: InputToken(tokenIn, inputAmount, inputAmount),
outputs: OutputsBuilder.single(address(tokenOut), outputAmount, swapper),
sig: hex"00",
Expand Down Expand Up @@ -733,7 +733,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
ResolvedOrder memory order = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(deadline).withValidationContract(
additionalValidationContract
),
),
input: InputToken(tokenIn, inputAmount, inputAmount),
outputs: OutputsBuilder.single(address(tokenOut), outputAmount, swapper),
sig: hex"00",
Expand Down Expand Up @@ -763,7 +763,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
ResolvedOrder memory order = ResolvedOrder({
info: OrderInfoBuilder.init(orderReactor).withSwapper(swapper).withDeadline(deadline).withValidationContract(
additionalValidationContract
),
),
input: InputToken(tokenIn, inputAmount, inputAmount),
outputs: OutputsBuilder.single(address(tokenOut), outputAmount, swapper),
sig: hex"00",
Expand All @@ -787,7 +787,7 @@ abstract contract BaseReactorTest is GasSnapshot, ReactorEvents, Test, DeployPer
ResolvedOrder memory order = ResolvedOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(deadline).withValidationContract(
additionalValidationContract
),
),
input: InputToken(tokenIn, inputAmount, inputAmount),
outputs: OutputsBuilder.single(address(tokenOut), outputAmount, swapper),
sig: hex"00",
Expand Down
4 changes: 2 additions & 2 deletions test/executors/SwapRouter02Executor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ contract SwapRouter02ExecutorTest is Test, PermitSignature, GasSnapshot, DeployP
DutchOrder memory order2 = DutchOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 100).withNonce(
1234
),
),
decayStartTime: block.timestamp - 100,
decayEndTime: block.timestamp + 100,
input: DutchInput(tokenIn, ONE, ONE),
Expand Down Expand Up @@ -270,7 +270,7 @@ contract SwapRouter02ExecutorTest is Test, PermitSignature, GasSnapshot, DeployP
DutchOrder memory order2 = DutchOrder({
info: OrderInfoBuilder.init(address(reactor)).withSwapper(swapper).withDeadline(block.timestamp + 100).withNonce(
1
),
),
decayStartTime: block.timestamp,
decayEndTime: block.timestamp + 100,
input: DutchInput(tokenIn, inputAmount * 3, inputAmount * 3),
Expand Down
1 change: 1 addition & 0 deletions test/lib/DutchDecayLib.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ contract DutchDecayLibTest is Test {
uint256 decayStartTime,
uint256 decayEndTime
) public {
vm.assume(startAmount != endAmount);
vm.assume(decayEndTime < decayStartTime);
vm.expectRevert(DutchDecayLib.EndTimeBeforeStartTime.selector);
DutchDecayLib.decay(startAmount, endAmount, decayStartTime, decayEndTime);
Expand Down
Loading

0 comments on commit 7cdd074

Please sign in to comment.