From 331b9df337c7e93f95de6c41c01597a406ad45c7 Mon Sep 17 00:00:00 2001 From: Tim Olson <> Date: Fri, 10 Nov 2023 16:42:44 -0400 Subject: [PATCH] order cancels --- src/OrderLib.sol | 12 +++++------- src/Vault.sol | 7 +++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/OrderLib.sol b/src/OrderLib.sol index d90588d..f502107 100644 --- a/src/OrderLib.sol +++ b/src/OrderLib.sol @@ -24,9 +24,7 @@ library OrderLib { event DexorderSwapFilled (uint64 orderIndex, uint8 trancheIndex, uint256 amountIn, uint256 amountOut); - event DexorderSwapCompleted (uint64 orderIndex); // todo remove? - - event DexorderSwapError (uint64 orderIndex, string reason); + event DexorderSwapCanceled (uint64 orderIndex); enum SwapOrderState { Open, Canceled, Filled, Expired // Expired isn't ever shown on-chain. the Expired state is implied by tranche constraints. @@ -284,7 +282,7 @@ library OrderLib { status.trancheFilledIn[trancheIndex] += amountIn; status.trancheFilledOut[trancheIndex] += amountOut; emit DexorderSwapFilled(orderIndex, trancheIndex, amountIn, amountOut); - _checkCompleted(self, orderIndex, status); + _checkCompleted(self, status); } @@ -304,11 +302,11 @@ library OrderLib { } } - function _checkCompleted(OrdersInfo storage self, uint64 orderIndex, SwapOrderStatus storage status) internal { + function _checkCompleted(OrdersInfo storage self, SwapOrderStatus storage status) internal { uint256 remaining = status.order.amount - (status.order.amountIsInput ? status.filledIn : status.filledOut); if( remaining == 0 ) { // todo dust leeway? status.state = SwapOrderState.Filled; - emit DexorderSwapCompleted(orderIndex); + // we already get fill events so completion may be inferred without an extra Completion event if( status.ocoGroup != NO_OCO_INDEX) _cancelOco(self, status.ocoGroup); } @@ -327,7 +325,7 @@ library OrderLib { SwapOrderState state = self.orders[orderIndex].state; if( state == SwapOrderState.Open ) { self.orders[orderIndex].state = SwapOrderState.Canceled; - emit DexorderSwapCompleted(orderIndex); + emit DexorderSwapCanceled(orderIndex); } } } diff --git a/src/Vault.sol b/src/Vault.sol index 7e2a7d6..e533843 100644 --- a/src/Vault.sol +++ b/src/Vault.sol @@ -59,6 +59,7 @@ contract Vault { return uint64(ordersInfo.orders.length); } + // todo rename using dexorder and inform the method hash registries function placeOrder(OrderLib.SwapOrder memory order) external onlyOwner { console2.log('Vault.placeOrder()'); ordersInfo._placeOrder(order); @@ -77,6 +78,12 @@ contract Vault { ordersInfo.execute(owner, orderIndex, tranche_index, proof); } + function cancelOrder(uint64 orderIndex) external onlyOwner { + console2.log('cancelOrder'); + console2.log(orderIndex); + ordersInfo._cancelOrder(orderIndex); + } + modifier onlyOwner() { require(msg.sender == owner); _;