diff --git a/.forge-snapshots/Base-V3DutchOrder-BaseExecuteSingleWithFee.snap b/.forge-snapshots/Base-V3DutchOrder-BaseExecuteSingleWithFee.snap index 54347403..d96dcaba 100644 --- a/.forge-snapshots/Base-V3DutchOrder-BaseExecuteSingleWithFee.snap +++ b/.forge-snapshots/Base-V3DutchOrder-BaseExecuteSingleWithFee.snap @@ -1 +1 @@ -198780 \ No newline at end of file +198870 \ No newline at end of file diff --git a/.forge-snapshots/Base-V3DutchOrder-ExecuteBatch.snap b/.forge-snapshots/Base-V3DutchOrder-ExecuteBatch.snap index 038dfe2d..8dd69151 100644 --- a/.forge-snapshots/Base-V3DutchOrder-ExecuteBatch.snap +++ b/.forge-snapshots/Base-V3DutchOrder-ExecuteBatch.snap @@ -1 +1 @@ -231116 \ No newline at end of file +231296 \ No newline at end of file diff --git a/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchMultipleOutputs.snap b/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchMultipleOutputs.snap index 04587131..0fed4ea0 100644 --- a/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchMultipleOutputs.snap +++ b/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchMultipleOutputs.snap @@ -1 +1 @@ -244626 \ No newline at end of file +244817 \ No newline at end of file diff --git a/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchMultipleOutputsDifferentTokens.snap b/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchMultipleOutputsDifferentTokens.snap index 3f03abfb..d7065025 100644 --- a/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchMultipleOutputsDifferentTokens.snap +++ b/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchMultipleOutputsDifferentTokens.snap @@ -1 +1 @@ -302041 \ No newline at end of file +302243 \ No newline at end of file diff --git a/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchNativeOutput.snap b/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchNativeOutput.snap index 9e863299..19c71545 100644 --- a/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchNativeOutput.snap +++ b/.forge-snapshots/Base-V3DutchOrder-ExecuteBatchNativeOutput.snap @@ -1 +1 @@ -224642 \ No newline at end of file +224822 \ No newline at end of file diff --git a/.forge-snapshots/Base-V3DutchOrder-ExecuteSingle.snap b/.forge-snapshots/Base-V3DutchOrder-ExecuteSingle.snap index f90f0f91..67e0047d 100644 --- a/.forge-snapshots/Base-V3DutchOrder-ExecuteSingle.snap +++ b/.forge-snapshots/Base-V3DutchOrder-ExecuteSingle.snap @@ -1 +1 @@ -165165 \ No newline at end of file +165255 \ No newline at end of file diff --git a/.forge-snapshots/Base-V3DutchOrder-ExecuteSingleNativeOutput.snap b/.forge-snapshots/Base-V3DutchOrder-ExecuteSingleNativeOutput.snap index 9b6d35ad..b90f3684 100644 --- a/.forge-snapshots/Base-V3DutchOrder-ExecuteSingleNativeOutput.snap +++ b/.forge-snapshots/Base-V3DutchOrder-ExecuteSingleNativeOutput.snap @@ -1 +1 @@ -150727 \ No newline at end of file +150817 \ No newline at end of file diff --git a/.forge-snapshots/Base-V3DutchOrder-ExecuteSingleValidation.snap b/.forge-snapshots/Base-V3DutchOrder-ExecuteSingleValidation.snap index 692864e4..ee1fea4c 100644 --- a/.forge-snapshots/Base-V3DutchOrder-ExecuteSingleValidation.snap +++ b/.forge-snapshots/Base-V3DutchOrder-ExecuteSingleValidation.snap @@ -1 +1 @@ -174481 \ No newline at end of file +174571 \ No newline at end of file diff --git a/.forge-snapshots/Base-V3DutchOrder-RevertInvalidNonce.snap b/.forge-snapshots/Base-V3DutchOrder-RevertInvalidNonce.snap index 5abcbe4d..b1fb824b 100644 --- a/.forge-snapshots/Base-V3DutchOrder-RevertInvalidNonce.snap +++ b/.forge-snapshots/Base-V3DutchOrder-RevertInvalidNonce.snap @@ -1 +1 @@ -43785 \ No newline at end of file +43875 \ No newline at end of file diff --git a/.forge-snapshots/Base-V3DutchOrder-V3-ExclusiveFiller.snap b/.forge-snapshots/Base-V3DutchOrder-V3-ExclusiveFiller.snap index 2b02fc3b..2c159b4f 100644 --- a/.forge-snapshots/Base-V3DutchOrder-V3-ExclusiveFiller.snap +++ b/.forge-snapshots/Base-V3DutchOrder-V3-ExclusiveFiller.snap @@ -1 +1 @@ -169089 \ No newline at end of file +169179 \ No newline at end of file diff --git a/.forge-snapshots/Base-V3DutchOrder-V3-InputOverride.snap b/.forge-snapshots/Base-V3DutchOrder-V3-InputOverride.snap index 2d97ac44..9ba5284c 100644 --- a/.forge-snapshots/Base-V3DutchOrder-V3-InputOverride.snap +++ b/.forge-snapshots/Base-V3DutchOrder-V3-InputOverride.snap @@ -1 +1 @@ -169170 \ No newline at end of file +169260 \ No newline at end of file diff --git a/.forge-snapshots/Base-V3DutchOrder-V3-OutputOverride.snap b/.forge-snapshots/Base-V3DutchOrder-V3-OutputOverride.snap index b4dc2dd4..ab41702e 100644 --- a/.forge-snapshots/Base-V3DutchOrder-V3-OutputOverride.snap +++ b/.forge-snapshots/Base-V3DutchOrder-V3-OutputOverride.snap @@ -1 +1 @@ -169113 \ No newline at end of file +169203 \ No newline at end of file diff --git a/.forge-snapshots/V3-DutchDecay.snap b/.forge-snapshots/V3-DutchDecay.snap index 2b163bad..af355057 100644 --- a/.forge-snapshots/V3-DutchDecay.snap +++ b/.forge-snapshots/V3-DutchDecay.snap @@ -1 +1 @@ -13179 \ No newline at end of file +13351 \ No newline at end of file diff --git a/.forge-snapshots/V3-DutchDecayBounded.snap b/.forge-snapshots/V3-DutchDecayBounded.snap index 1f168c59..1280674f 100644 --- a/.forge-snapshots/V3-DutchDecayBounded.snap +++ b/.forge-snapshots/V3-DutchDecayBounded.snap @@ -1 +1 @@ -1199 \ No newline at end of file +1247 \ No newline at end of file diff --git a/.forge-snapshots/V3-DutchDecayFullyDecayed.snap b/.forge-snapshots/V3-DutchDecayFullyDecayed.snap index e5e37b03..b56f143c 100644 --- a/.forge-snapshots/V3-DutchDecayFullyDecayed.snap +++ b/.forge-snapshots/V3-DutchDecayFullyDecayed.snap @@ -1 +1 @@ -6677 \ No newline at end of file +6755 \ No newline at end of file diff --git a/.forge-snapshots/V3-DutchDecayFullyDecayedNegative.snap b/.forge-snapshots/V3-DutchDecayFullyDecayedNegative.snap index 50d06af6..861626b3 100644 --- a/.forge-snapshots/V3-DutchDecayFullyDecayedNegative.snap +++ b/.forge-snapshots/V3-DutchDecayFullyDecayedNegative.snap @@ -1 +1 @@ -6365 \ No newline at end of file +6443 \ No newline at end of file diff --git a/.forge-snapshots/V3-DutchDecayNegative.snap b/.forge-snapshots/V3-DutchDecayNegative.snap index 11b9a892..f699c943 100644 --- a/.forge-snapshots/V3-DutchDecayNegative.snap +++ b/.forge-snapshots/V3-DutchDecayNegative.snap @@ -1 +1 @@ -1271 \ No newline at end of file +1309 \ No newline at end of file diff --git a/.forge-snapshots/V3-DutchDecayNoDecay.snap b/.forge-snapshots/V3-DutchDecayNoDecay.snap index 4b447b70..a41d068a 100644 --- a/.forge-snapshots/V3-DutchDecayNoDecay.snap +++ b/.forge-snapshots/V3-DutchDecayNoDecay.snap @@ -1 +1 @@ -5899 \ No newline at end of file +5975 \ No newline at end of file diff --git a/.forge-snapshots/V3-DutchDecayNoDecayYet.snap b/.forge-snapshots/V3-DutchDecayNoDecayYet.snap index 9b08816d..b26d92eb 100644 --- a/.forge-snapshots/V3-DutchDecayNoDecayYet.snap +++ b/.forge-snapshots/V3-DutchDecayNoDecayYet.snap @@ -1 +1 @@ -4703 \ No newline at end of file +4779 \ No newline at end of file diff --git a/.forge-snapshots/V3-DutchDecayNoDecayYetNegative.snap b/.forge-snapshots/V3-DutchDecayNoDecayYetNegative.snap index 9b08816d..b26d92eb 100644 --- a/.forge-snapshots/V3-DutchDecayNoDecayYetNegative.snap +++ b/.forge-snapshots/V3-DutchDecayNoDecayYetNegative.snap @@ -1 +1 @@ -4703 \ No newline at end of file +4779 \ No newline at end of file diff --git a/.forge-snapshots/V3-DutchDecayRange.snap b/.forge-snapshots/V3-DutchDecayRange.snap index 11b9a892..f699c943 100644 --- a/.forge-snapshots/V3-DutchDecayRange.snap +++ b/.forge-snapshots/V3-DutchDecayRange.snap @@ -1 +1 @@ -1271 \ No newline at end of file +1309 \ No newline at end of file diff --git a/.forge-snapshots/V3-ExtendedMultiPointDutchDecay.snap b/.forge-snapshots/V3-ExtendedMultiPointDutchDecay.snap index c1250b2e..70baed8e 100644 --- a/.forge-snapshots/V3-ExtendedMultiPointDutchDecay.snap +++ b/.forge-snapshots/V3-ExtendedMultiPointDutchDecay.snap @@ -1 +1 @@ -88354 \ No newline at end of file +89192 \ No newline at end of file diff --git a/.forge-snapshots/V3-MultiPointDutchDecay.snap b/.forge-snapshots/V3-MultiPointDutchDecay.snap index 81237bad..80100ea7 100644 --- a/.forge-snapshots/V3-MultiPointDutchDecay.snap +++ b/.forge-snapshots/V3-MultiPointDutchDecay.snap @@ -1 +1 @@ -26242 \ No newline at end of file +26608 \ No newline at end of file diff --git a/src/base/BlockNumberish.sol b/src/base/BlockNumberish.sol new file mode 100644 index 00000000..15c538ab --- /dev/null +++ b/src/base/BlockNumberish.sol @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {IArbSys} from "../interfaces/IArbSys.sol"; + +/// @title BlockNumberish +/// A helper contract to get the current block number on different chains +contract BlockNumberish { + // Declare an immutable function type variable for the _getTstorish function + // based on chain support for tstore at time of deployment. + function() view returns (uint256) internal immutable _getBlockNumberish; + + constructor() { + // Set the function to use based on chainid + if (block.chainid == 42161) { + _getBlockNumberish = _getBlockNumberSyscall; + } else { + _getBlockNumberish = _getBlockNumber; + } + } + + /// @dev Private function to get the block number on arbitrum + function _getBlockNumberSyscall() private view returns (uint256) { + return IArbSys(0x0000000000000000000000000000000000000064).arbBlockNumber(); + } + + /// @dev Private function to get the block number using the opcode + function _getBlockNumber() private view returns (uint256) { + return block.number; + } +} diff --git a/src/lib/ExclusivityLib.sol b/src/lib/ExclusivityLib.sol index 2ed25d36..f27e8cc6 100644 --- a/src/lib/ExclusivityLib.sol +++ b/src/lib/ExclusivityLib.sol @@ -41,14 +41,10 @@ library ExclusivityLib { ResolvedOrder memory order, address exclusive, uint256 exclusivityEnd, - uint256 exclusivityOverrideBps + uint256 exclusivityOverrideBps, + uint256 blockNumberish ) internal view { - uint256 blockNumber = block.number; - // Arbitrum specific block numbers must be fetched from their system contracts - if (block.chainid == 42161) { - blockNumber = IArbSys(address(100)).arbBlockNumber(); - } - _handleExclusiveOverride(order, exclusive, exclusivityEnd, exclusivityOverrideBps, blockNumber); + _handleExclusiveOverride(order, exclusive, exclusivityEnd, exclusivityOverrideBps, blockNumberish); } /// @notice Applies exclusivity override to the resolved order if necessary diff --git a/src/lib/NonlinearDutchDecayLib.sol b/src/lib/NonlinearDutchDecayLib.sol index dfcec6a2..98b0b5fe 100644 --- a/src/lib/NonlinearDutchDecayLib.sol +++ b/src/lib/NonlinearDutchDecayLib.sol @@ -29,6 +29,7 @@ library NonlinearDutchDecayLib { NonlinearDutchDecay memory curve, uint256 startAmount, uint256 decayStartBlock, + uint256 blockNumberish, uint256 minAmount, uint256 maxAmount ) internal view returns (uint256 decayedAmount) { @@ -37,18 +38,12 @@ library NonlinearDutchDecayLib { revert InvalidDecayCurve(); } - uint256 blockNumber = block.number; - // Arbitrum specific block numbers must be fetched from their system contracts - if (block.chainid == 42161) { - blockNumber = IArbSys(address(100)).arbBlockNumber(); - } - // handle current block before decay or no decay - if (decayStartBlock >= blockNumber || curve.relativeAmounts.length == 0) { + if (decayStartBlock >= blockNumberish || curve.relativeAmounts.length == 0) { return startAmount.bound(minAmount, maxAmount); } - uint16 blockDelta = uint16(blockNumber - decayStartBlock); + uint16 blockDelta = uint16(blockNumberish - decayStartBlock); (uint16 startPoint, uint16 endPoint, int256 relStartAmount, int256 relEndAmount) = locateCurvePosition(curve, blockDelta); // get decay of only the relative amounts @@ -97,22 +92,25 @@ library NonlinearDutchDecayLib { /// @notice returns a decayed output using the given dutch spec and blocks /// @param output The output to decay /// @param decayStartBlock The block to start decaying + /// @param blockNumberish The block number to decay to /// @return result a decayed output - function decay(V3DutchOutput memory output, uint256 decayStartBlock) + function decay(V3DutchOutput memory output, uint256 decayStartBlock, uint256 blockNumberish) internal view returns (OutputToken memory result) { - uint256 decayedOutput = - decay(output.curve, output.startAmount, decayStartBlock, output.minAmount, type(uint256).max); + uint256 decayedOutput = decay( + output.curve, output.startAmount, decayStartBlock, blockNumberish, output.minAmount, type(uint256).max + ); result = OutputToken(output.token, decayedOutput, output.recipient); } /// @notice returns a decayed output array using the given dutch spec and blocks /// @param outputs The output array to decay /// @param decayStartBlock The block to start decaying + /// @param blockNumberish The block number to decay to /// @return result a decayed output array - function decay(V3DutchOutput[] memory outputs, uint256 decayStartBlock) + function decay(V3DutchOutput[] memory outputs, uint256 decayStartBlock, uint256 blockNumberish) internal view returns (OutputToken[] memory result) @@ -120,20 +118,22 @@ library NonlinearDutchDecayLib { uint256 outputLength = outputs.length; result = new OutputToken[](outputLength); for (uint256 i = 0; i < outputLength; i++) { - result[i] = decay(outputs[i], decayStartBlock); + result[i] = decay(outputs[i], decayStartBlock, blockNumberish); } } /// @notice returns a decayed input using the given dutch spec and times /// @param input The input to decay /// @param decayStartBlock The block to start decaying + /// @param blockNumberish The block number to decay to /// @return result a decayed input - function decay(V3DutchInput memory input, uint256 decayStartBlock) + function decay(V3DutchInput memory input, uint256 decayStartBlock, uint256 blockNumberish) internal view returns (InputToken memory result) { - uint256 decayedInput = decay(input.curve, input.startAmount, decayStartBlock, 0, input.maxAmount); + uint256 decayedInput = + decay(input.curve, input.startAmount, decayStartBlock, blockNumberish, 0, input.maxAmount); result = InputToken(input.token, decayedInput, input.maxAmount); } } diff --git a/src/reactors/V3DutchOrderReactor.sol b/src/reactors/V3DutchOrderReactor.sol index dd184237..4f3659e9 100644 --- a/src/reactors/V3DutchOrderReactor.sol +++ b/src/reactors/V3DutchOrderReactor.sol @@ -8,6 +8,7 @@ import {ExclusivityLib} from "../lib/ExclusivityLib.sol"; import {NonlinearDutchDecayLib} from "../lib/NonlinearDutchDecayLib.sol"; import {V3DutchOrderLib, V3DutchOrder, CosignerData, V3DutchOutput, V3DutchInput} from "../lib/V3DutchOrderLib.sol"; import {SignedOrder, ResolvedOrder} from "../base/ReactorStructs.sol"; +import {BlockNumberish} from "../base/BlockNumberish.sol"; import {FixedPointMathLib} from "solmate/src/utils/FixedPointMathLib.sol"; import {MathExt} from "../lib/MathExt.sol"; import {Math} from "openzeppelin-contracts/utils/math/Math.sol"; @@ -22,7 +23,7 @@ import {CosignerLib} from "../lib/CosignerLib.sol"; /// - For each outputAmount: /// - If amount is 0, then use baseOutput /// - If amount is nonzero, then ensure it is greater than specified baseOutput and replace startAmount -contract V3DutchOrderReactor is BaseReactor { +contract V3DutchOrderReactor is BaseReactor, BlockNumberish { using Permit2Lib for ResolvedOrder; using V3DutchOrderLib for V3DutchOrder; using NonlinearDutchDecayLib for V3DutchOutput[]; @@ -40,7 +41,10 @@ contract V3DutchOrderReactor is BaseReactor { /// @notice thrown when an order's cosigner output is less than the specified error InvalidCosignerOutput(); - constructor(IPermit2 _permit2, address _protocolFeeOwner) BaseReactor(_permit2, _protocolFeeOwner) {} + constructor(IPermit2 _permit2, address _protocolFeeOwner) + BaseReactor(_permit2, _protocolFeeOwner) + BlockNumberish() + {} /// @inheritdoc BaseReactor function _resolve(SignedOrder calldata signedOrder) @@ -58,17 +62,20 @@ contract V3DutchOrderReactor is BaseReactor { _updateWithCosignerAmounts(order); _updateWithGasAdjustment(order); + uint256 blockNumberish = _getBlockNumberish(); + resolvedOrder = ResolvedOrder({ info: order.info, - input: order.baseInput.decay(order.cosignerData.decayStartBlock), - outputs: order.baseOutputs.decay(order.cosignerData.decayStartBlock), + input: order.baseInput.decay(order.cosignerData.decayStartBlock, blockNumberish), + outputs: order.baseOutputs.decay(order.cosignerData.decayStartBlock, blockNumberish), sig: signedOrder.sig, hash: orderHash }); resolvedOrder.handleExclusiveOverrideBlock( order.cosignerData.exclusiveFiller, order.cosignerData.decayStartBlock, - order.cosignerData.exclusivityOverrideBps + order.cosignerData.exclusivityOverrideBps, + blockNumberish ); } diff --git a/test/base/BlockNumberish.t.sol b/test/base/BlockNumberish.t.sol new file mode 100644 index 00000000..685e954d --- /dev/null +++ b/test/base/BlockNumberish.t.sol @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +pragma solidity ^0.8.0; + +import {Test} from "forge-std/Test.sol"; +import {BlockNumberish} from "../../src/base/BlockNumberish.sol"; + +/// Mock Arbitrum syscall contract +contract MockArbSys { + uint256 _blockNumber; + + /// @dev helper function to set the block number + function setBlockNumber(uint256 blockNumber) external { + _blockNumber = blockNumber; + } + + /// @notice returns the block number + function arbBlockNumber() external view returns (uint256) { + return _blockNumber; + } +} + +contract MockBlockNumberish is BlockNumberish { + function getBlockNumberish() external view returns (uint256) { + return _getBlockNumberish(); + } +} + +contract BlockNumberishTest is Test { + MockArbSys arbSys; + MockBlockNumberish blockNumberish; + + function setUp() public { + // etch MockArbSys to address(100) + vm.etch(address(100), address(new MockArbSys()).code); + arbSys = MockArbSys(address(100)); + } + + function test_getBlockNumber() public { + blockNumberish = new MockBlockNumberish(); + + vm.roll(100); + assertEq(blockNumberish.getBlockNumberish(), 100); + } + + function test_getBlockNumberSyscall() public { + vm.chainId(42161); + blockNumberish = new MockBlockNumberish(); + + arbSys.setBlockNumber(1); + assertEq(blockNumberish.getBlockNumberish(), 1); + } +} diff --git a/test/lib/ExclusivityLib.t.sol b/test/lib/ExclusivityLib.t.sol index c6cc0e18..bf3efd5a 100644 --- a/test/lib/ExclusivityLib.t.sol +++ b/test/lib/ExclusivityLib.t.sol @@ -18,11 +18,14 @@ contract ExclusivityLibTest is Test { address token2; address recipient; + uint256 blockNumberish; + function setUp() public { exclusivity = new MockExclusivityLib(); token1 = makeAddr("token1"); token2 = makeAddr("token2"); recipient = makeAddr("recipient"); + blockNumberish = block.number; } function testTimestampExclusivity(address exclusive) public { @@ -68,7 +71,7 @@ contract ExclusivityLibTest is Test { order.outputs = OutputsBuilder.single(token1, amount, recipient); vm.prank(exclusive); ResolvedOrder memory handled = - exclusivity.handleExclusiveOverrideBlock(order, exclusive, block.number + 1, overrideAmt); + exclusivity.handleExclusiveOverrideBlock(order, exclusive, block.number + 1, overrideAmt, blockNumberish); // no changes assertEq(handled.outputs[0].amount, amount); assertEq(handled.outputs[0].recipient, recipient); @@ -96,7 +99,7 @@ contract ExclusivityLibTest is Test { order.outputs = OutputsBuilder.single(token1, amount, recipient); vm.prank(caller); ResolvedOrder memory handled = - exclusivity.handleExclusiveOverrideBlock(order, address(0), block.number + 1, overrideAmt); + exclusivity.handleExclusiveOverrideBlock(order, address(0), block.number + 1, overrideAmt, blockNumberish); // no changes assertEq(handled.outputs[0].amount, amount); assertEq(handled.outputs[0].recipient, recipient); @@ -134,7 +137,8 @@ contract ExclusivityLibTest is Test { order.outputs = OutputsBuilder.single(token1, amount, recipient); vm.roll(100); vm.prank(caller); - ResolvedOrder memory handled = exclusivity.handleExclusiveOverrideBlock(order, address(0), 99, overrideAmt); + ResolvedOrder memory handled = + exclusivity.handleExclusiveOverrideBlock(order, address(0), 99, overrideAmt, blockNumberish); // no changes assertEq(handled.outputs[0].amount, amount); assertEq(handled.outputs[0].recipient, recipient); @@ -157,7 +161,7 @@ contract ExclusivityLibTest is Test { order.outputs = OutputsBuilder.single(token1, amount, recipient); vm.prank(caller); vm.expectRevert(ExclusivityLib.NoExclusiveOverride.selector); - exclusivity.handleExclusiveOverrideBlock(order, exclusive, block.number + 1, 0); + exclusivity.handleExclusiveOverrideBlock(order, exclusive, block.number + 1, 0, blockNumberish); } function testHandleExclusiveOverrideTimestamp() public { @@ -178,7 +182,7 @@ contract ExclusivityLibTest is Test { uint256 overrideAmt = 3000; vm.prank(address(2)); ResolvedOrder memory handled = - exclusivity.handleExclusiveOverrideBlock(order, address(1), block.number + 1, overrideAmt); + exclusivity.handleExclusiveOverrideBlock(order, address(1), block.number + 1, overrideAmt, blockNumberish); // assert overrideAmt applied assertEq(handled.outputs[0].amount, 1.3 ether); assertEq(handled.outputs[0].recipient, recipient); @@ -202,7 +206,7 @@ contract ExclusivityLibTest is Test { uint256 overrideAmt = 3000; vm.prank(address(2)); ResolvedOrder memory handled = - exclusivity.handleExclusiveOverrideBlock(order, address(1), block.number + 1, overrideAmt); + exclusivity.handleExclusiveOverrideBlock(order, address(1), block.number + 1, overrideAmt, blockNumberish); // assert overrideAmt applied assertEq(handled.outputs[0].amount, 1.3 ether + 2); assertEq(handled.outputs[0].recipient, recipient); @@ -240,7 +244,7 @@ contract ExclusivityLibTest is Test { order.outputs = OutputsBuilder.single(token1, amount, recipient); vm.prank(caller); ResolvedOrder memory handled = - exclusivity.handleExclusiveOverrideBlock(order, exclusive, block.number + 1, overrideAmt); + exclusivity.handleExclusiveOverrideBlock(order, exclusive, block.number + 1, overrideAmt, blockNumberish); // assert overrideAmt applied assertEq(handled.outputs[0].amount, uint256(amount).mulDivUp(10000 + overrideAmt, 10000)); assertEq(handled.outputs[0].recipient, recipient); @@ -290,7 +294,7 @@ contract ExclusivityLibTest is Test { order.outputs = OutputsBuilder.multiple(token1, amounts, recipient); vm.prank(caller); ResolvedOrder memory handled = - exclusivity.handleExclusiveOverrideBlock(order, exclusive, block.number + 1, overrideAmt); + exclusivity.handleExclusiveOverrideBlock(order, exclusive, block.number + 1, overrideAmt, blockNumberish); // assert overrideAmt applied for (uint256 i = 0; i < amounts.length; i++) { assertEq(handled.outputs[i].amount, uint256(amounts[i]).mulDivUp(10000 + overrideAmt, 10000)); diff --git a/test/lib/NonLinearDutchDecayLib.t.sol b/test/lib/NonLinearDutchDecayLib.t.sol index c4217418..68661475 100644 --- a/test/lib/NonLinearDutchDecayLib.t.sol +++ b/test/lib/NonLinearDutchDecayLib.t.sol @@ -10,6 +10,7 @@ import {V3DutchOutput, V3DutchInput, NonlinearDutchDecay} from "../../src/lib/V3 import {Uint16Array, toUint256} from "../../src/types/Uint16Array.sol"; import {ArrayBuilder} from "../util/ArrayBuilder.sol"; import {CurveBuilder} from "../util/CurveBuilder.sol"; +import {BlockNumberish} from "../../src/base/BlockNumberish.sol"; /// @notice mock contract to test NonlinearDutchDecayLib functionality contract MockNonlinearDutchDecayLibContract { @@ -17,14 +18,15 @@ contract MockNonlinearDutchDecayLibContract { NonlinearDutchDecay memory curve, uint256 startAmount, uint256 decayStartBlock, + uint256 blockNumberish, uint256 minAmount, uint256 maxAmount ) public view { - NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, minAmount, maxAmount); + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, blockNumberish, minAmount, maxAmount); } } -contract NonlinearDutchDecayLibTest is Test, GasSnapshot { +contract NonlinearDutchDecayLibTest is Test, GasSnapshot, BlockNumberish { MockNonlinearDutchDecayLibContract mockNonlinearDutchDecayLibContract = new MockNonlinearDutchDecayLibContract(); function testLocateCurvePositionSingle() public { @@ -110,7 +112,7 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { snapStart("V3-DutchDecayNoDecay"); assertEq( NonlinearDutchDecayLib.decay( - CurveBuilder.emptyCurve(), startAmount, decayStartBlock, startAmount, startAmount + CurveBuilder.emptyCurve(), startAmount, decayStartBlock, _getBlockNumberish(), startAmount, startAmount ), startAmount ); @@ -118,7 +120,12 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { // Single value with 0 amount change assertEq( NonlinearDutchDecayLib.decay( - CurveBuilder.singlePointCurve(1, 0), startAmount, decayStartBlock, startAmount, startAmount + CurveBuilder.singlePointCurve(1, 0), + startAmount, + decayStartBlock, + _getBlockNumberish(), + startAmount, + startAmount ), startAmount ); @@ -133,11 +140,21 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { snapStart("V3-DutchDecayNoDecayYet"); vm.roll(100); // at decayStartBlock - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, startAmount, 2 ether), startAmount); + assertEq( + NonlinearDutchDecayLib.decay( + curve, startAmount, decayStartBlock, _getBlockNumberish(), startAmount, 2 ether + ), + startAmount + ); vm.roll(80); // before decayStartBlock - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, startAmount, 2 ether), startAmount); + assertEq( + NonlinearDutchDecayLib.decay( + curve, startAmount, decayStartBlock, _getBlockNumberish(), startAmount, 2 ether + ), + startAmount + ); snapEnd(); } @@ -149,11 +166,17 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { snapStart("V3-DutchDecayNoDecayYetNegative"); vm.roll(100); // at decayStartBlock - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0, 1 ether), startAmount); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0, 1 ether), + startAmount + ); vm.roll(80); // before decayStartBlock - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0, 1 ether), startAmount); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0, 1 ether), + startAmount + ); snapEnd(); } @@ -164,16 +187,28 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { NonlinearDutchDecay memory curve = CurveBuilder.singlePointCurve(100, decayAmount); snapStart("V3-DutchDecay"); vm.roll(150); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.5 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.5 ether + ); vm.roll(180); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.8 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.8 ether + ); vm.roll(110); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.1 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.1 ether + ); vm.roll(190); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.9 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.9 ether + ); snapEnd(); } @@ -184,16 +219,28 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { NonlinearDutchDecay memory curve = CurveBuilder.singlePointCurve(100, decayAmount); snapStart("V3-DutchDecayNegative"); vm.roll(150); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.5 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.5 ether + ); vm.roll(180); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.2 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.2 ether + ); vm.roll(110); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.9 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.9 ether + ); vm.roll(190); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.1 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.1 ether + ); snapEnd(); } @@ -204,10 +251,16 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { NonlinearDutchDecay memory curve = CurveBuilder.singlePointCurve(100, decayAmount); snapStart("V3-DutchDecayFullyDecayed"); vm.roll(200); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 2 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 2 ether + ); vm.warp(250); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 2 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 2 ether + ); snapEnd(); } @@ -218,10 +271,16 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { NonlinearDutchDecay memory curve = CurveBuilder.singlePointCurve(100, decayAmount); snapStart("V3-DutchDecayFullyDecayedNegative"); vm.roll(200); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1 ether + ); vm.warp(250); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1 ether + ); snapEnd(); } @@ -233,7 +292,9 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { NonlinearDutchDecay memory curve = CurveBuilder.singlePointCurve(decayDuration, 0 - int256(decayAmount)); snapStart("V3-DutchDecayRange"); - uint256 decayed = NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0, type(uint256).max); + uint256 decayed = NonlinearDutchDecayLib.decay( + curve, startAmount, decayStartBlock, _getBlockNumberish(), 0, type(uint256).max + ); assertGe(decayed, startAmount); assertLe(decayed, startAmount + uint256(decayAmount)); snapEnd(); @@ -253,7 +314,9 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { NonlinearDutchDecay memory curve = CurveBuilder.singlePointCurve(decayDuration, 0 - int256(decayAmount)); snapStart("V3-DutchDecayBounded"); - uint256 decayed = NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, minAmount, maxAmount); + uint256 decayed = NonlinearDutchDecayLib.decay( + curve, startAmount, decayStartBlock, _getBlockNumberish(), minAmount, maxAmount + ); assertGe(decayed, minAmount); assertLe(decayed, maxAmount); snapEnd(); @@ -273,7 +336,9 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { NonlinearDutchDecay memory curve = CurveBuilder.singlePointCurve(decayDuration, int256(decayAmount)); snapStart("V3-DutchDecayNegative"); - uint256 decayed = NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0, type(uint256).max); + uint256 decayed = NonlinearDutchDecayLib.decay( + curve, startAmount, decayStartBlock, _getBlockNumberish(), 0, type(uint256).max + ); assertLe(decayed, startAmount); assertGe(decayed, startAmount - decayAmount); snapEnd(); @@ -293,31 +358,58 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { NonlinearDutchDecay memory curve = CurveBuilder.multiPointCurve(blocks, decayAmounts); snapStart("V3-MultiPointDutchDecay"); vm.roll(50); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0 ether, 2 ether), 1 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 2 ether), + 1 ether + ); vm.roll(150); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0 ether, 2 ether), 1.5 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 2 ether), + 1.5 ether + ); vm.roll(200); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0 ether, 2 ether), 2 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 2 ether), + 2 ether + ); vm.roll(210); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0 ether, 2 ether), 1.9 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 2 ether), + 1.9 ether + ); vm.roll(290); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0 ether, 2 ether), 1.1 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 2 ether), + 1.1 ether + ); vm.roll(300); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0 ether, 2 ether), 1 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 2 ether), + 1 ether + ); vm.roll(350); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0 ether, 2 ether), 0.5 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 2 ether), + 0.5 ether + ); vm.roll(400); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0 ether, 2 ether), 0 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 2 ether), + 0 ether + ); vm.roll(500); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0 ether, 2 ether), 0 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 2 ether), + 0 ether + ); snapEnd(); } @@ -364,67 +456,130 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { snapStart("V3-ExtendedMultiPointDutchDecay"); vm.roll(50); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1 ether + ); vm.roll(150); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.05 ether); // halfway between 100 (1 ether) and 200 (1.1 ether) + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.05 ether + ); // halfway between 100 (1 ether) and 200 (1.1 ether) vm.roll(200); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.1 ether); // 1 + 0.1 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.1 ether + ); // 1 + 0.1 ether vm.roll(250); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.15 ether); // halfway between 200 (1.1 ether) and 300 (1.2 ether) + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.15 ether + ); // halfway between 200 (1.1 ether) and 300 (1.2 ether) vm.roll(300); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.2 ether); // 1 + 0.2 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.2 ether + ); // 1 + 0.2 ether vm.roll(350); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.25 ether); // halfway between 300 (1.2 ether) and 400 (1.3 ether) + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.25 ether + ); // halfway between 300 (1.2 ether) and 400 (1.3 ether) vm.roll(400); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.3 ether); // 1 + 0.3 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.3 ether + ); // 1 + 0.3 ether vm.roll(450); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.35 ether); // halfway between 400 (1.3 ether) and 500 (1.4 ether) + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.35 ether + ); // halfway between 400 (1.3 ether) and 500 (1.4 ether) vm.roll(500); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.4 ether); // 1 + 0.4 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.4 ether + ); // 1 + 0.4 ether vm.roll(600); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.5 ether); // 1 + 0.5 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.5 ether + ); // 1 + 0.5 ether vm.roll(700); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.6 ether); // 1 + 0.6 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.6 ether + ); // 1 + 0.6 ether vm.roll(800); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.7 ether); // 1 + 0.7 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.7 ether + ); // 1 + 0.7 ether vm.roll(900); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.8 ether); // 1 + 0.8 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.8 ether + ); // 1 + 0.8 ether vm.roll(1000); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.9 ether); // 1 + 0.9 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.9 ether + ); // 1 + 0.9 ether vm.roll(1100); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 2 ether); // 1 + 1 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 2 ether + ); // 1 + 1 ether vm.roll(1200); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.9 ether); // 1 + 0.9 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.9 ether + ); // 1 + 0.9 ether vm.roll(1300); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.8 ether); // 1 + 0.8 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.8 ether + ); // 1 + 0.8 ether vm.roll(1400); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.7 ether); // 1 + 0.7 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.7 ether + ); // 1 + 0.7 ether vm.roll(1500); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.6 ether); // 1 + 0.6 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.6 ether + ); // 1 + 0.6 ether vm.roll(1600); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.5 ether); // 1 + 0.5 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.5 ether + ); // 1 + 0.5 ether vm.roll(1650); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 1 ether, 2 ether), 1.45 ether); // 1 + 0.45 ether + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 2 ether), + 1.45 ether + ); // 1 + 0.45 ether snapEnd(); } @@ -444,7 +599,10 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { decayAmounts[2] = 1 ether; // 0 ether NonlinearDutchDecay memory curve = CurveBuilder.multiPointCurve(blocks, decayAmounts); vm.roll(350); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0 ether, 2 ether), 0.25 ether); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 2 ether), + 0.25 ether + ); } function testDutchDecayToNegative() public { @@ -453,7 +611,9 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { int256 decayAmount = 2 ether; NonlinearDutchDecay memory curve = CurveBuilder.singlePointCurve(100, decayAmount); vm.roll(150); - assertEq(NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, 0 ether, 1 ether), 0); + assertEq( + NonlinearDutchDecayLib.decay(curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 1 ether), 0 + ); } function testDutchOverflowDecay() public { @@ -463,7 +623,9 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { NonlinearDutchDecay memory curve = CurveBuilder.singlePointCurve(100, decayAmount); vm.roll(150); vm.expectRevert(); - mockNonlinearDutchDecayLibContract.decay(curve, startAmount, decayStartBlock, 0 ether, 1 ether); + mockNonlinearDutchDecayLibContract.decay( + curve, startAmount, decayStartBlock, _getBlockNumberish(), 0 ether, 1 ether + ); } function testDutchMismatchedDecay() public { @@ -472,6 +634,8 @@ contract NonlinearDutchDecayLibTest is Test, GasSnapshot { NonlinearDutchDecay memory curve = CurveBuilder.multiPointCurve(ArrayBuilder.fillUint16(16, 1), ArrayBuilder.fillInt(17, 0)); vm.expectRevert(NonlinearDutchDecayLib.InvalidDecayCurve.selector); - mockNonlinearDutchDecayLibContract.decay(curve, startAmount, decayStartBlock, 1 ether, 1 ether); + mockNonlinearDutchDecayLibContract.decay( + curve, startAmount, decayStartBlock, _getBlockNumberish(), 1 ether, 1 ether + ); } } diff --git a/test/util/mock/MockExclusivityLib.sol b/test/util/mock/MockExclusivityLib.sol index ee6f860d..20e23208 100644 --- a/test/util/mock/MockExclusivityLib.sol +++ b/test/util/mock/MockExclusivityLib.sol @@ -19,9 +19,12 @@ contract MockExclusivityLib { ResolvedOrder memory order, address exclusive, uint256 exclusivityEnd, - uint256 exclusivityOverrideBps + uint256 exclusivityOverrideBps, + uint256 blockNumberish ) external view returns (ResolvedOrder memory) { - ExclusivityLib.handleExclusiveOverrideBlock(order, exclusive, exclusivityEnd, exclusivityOverrideBps); + ExclusivityLib.handleExclusiveOverrideBlock( + order, exclusive, exclusivityEnd, exclusivityOverrideBps, blockNumberish + ); return order; }