From 7c79e9f98e6558b9b32e791e0c9de7c4d151b6ff Mon Sep 17 00:00:00 2001 From: Tim Olson <> Date: Sat, 14 Oct 2023 22:06:43 -0400 Subject: [PATCH] order placement doesnt crash --- bin/build.sh | 2 +- bin/test.sh | 4 ++-- src/OrderLib.sol | 13 +++++++++++-- src/Vault.sol | 2 ++ src/VaultAddress.sol | 2 +- test/MockEnv.sol | 2 ++ test/TestOrder.sol | 20 +++++++++++++++++++- 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/bin/build.sh b/bin/build.sh index fbeae1b..3ffb85c 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -2,7 +2,7 @@ # this script requires the jq command $(sudo apt install jq) # first-pass build -forge build --force "$@" || exit 1 +forge build "$@" || exit 1 # calculate the Vault init code hash using the bytecode generated for Vault # shellcheck disable=SC2046 diff --git a/bin/test.sh b/bin/test.sh index 281d570..5032d2a 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -1,3 +1,3 @@ #!/bin/bash -./bin/build.sh -forge test -vvvv --fork-url arbitrum_ankr +#./bin/build.sh +forge test -vvvv --fork-url arbitrum_ankr "$@" diff --git a/src/OrderLib.sol b/src/OrderLib.sol index 28858bb..34c483b 100644 --- a/src/OrderLib.sol +++ b/src/OrderLib.sol @@ -59,8 +59,8 @@ library OrderLib { uint64 ocoGroup; uint256 filledIn; // total uint256 filledOut; // total - uint256[] trancheFilledIn; // sum(tranchFilledIn) == filledIn - uint256[] trancheFilledOut; // sum(tranchFilledOut) == filledOut + uint256[] trancheFilledIn; // sum(trancheFilledIn) == filledIn + uint256[] trancheFilledOut; // sum(trancheFilledOut) == filledOut } enum ConstraintMode { @@ -131,15 +131,19 @@ library OrderLib { } function _placeOrder(OrdersInfo storage self, SwapOrder memory order) internal { + console2.log('OrderLib._placeOrder()'); SwapOrder[] memory orders = new SwapOrder[](1); orders[0] = order; return _placeOrders(self,orders,OcoMode.NO_OCO); } function _placeOrders(OrdersInfo storage self, SwapOrder[] memory orders, OcoMode ocoMode) internal { + console2.log('_placeOrders A'); require(orders.length < type(uint8).max); + console2.log('_placeOrders B'); uint64 startIndex = uint64(self.orders.length); require(startIndex < type(uint64).max); + console2.log('_placeOrders C'); uint64 ocoGroup; if( ocoMode == OcoMode.NO_OCO ) ocoGroup = NO_OCO_INDEX; @@ -149,9 +153,11 @@ library OrderLib { } else revert('OCOM'); + console2.log('_placeOrders D'); for( uint8 o = 0; o < orders.length; o++ ) { SwapOrder memory order = orders[o]; require(order.route.exchange == Exchange.UniswapV3, 'UR'); + console2.log('_placeOrders E'); // todo more order validation // we must explicitly copy into storage because Solidity doesn't implement copying the double-nested // tranches constraints array :( @@ -165,6 +171,7 @@ library OrderLib { status.order.route = order.route; status.order.chainOrder = order.chainOrder; status.order.outputDirectlyToOwner = order.outputDirectlyToOwner; + console2.log('_placeOrders F'); for( uint t=0; t