order placement doesnt crash

This commit is contained in:
Tim Olson
2023-10-14 22:06:43 -04:00
parent 4601f39b24
commit 7c79e9f98e
7 changed files with 38 additions and 7 deletions

View File

@@ -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<order.tranches.length; t++ ) {
status.order.tranches.push();
OrderLib.Tranche memory ot = order.tranches[t]; // order tranche
@@ -172,12 +179,14 @@ library OrderLib {
st.fraction = ot.fraction;
for( uint c=0; c<ot.constraints.length; c++ )
st.constraints.push(ot.constraints[c]);
console2.log('_placeOrders G');
status.trancheFilledIn.push(0);
status.trancheFilledOut.push(0);
}
status.state = SwapOrderState.Open;
status.start = uint32(block.timestamp);
status.ocoGroup = ocoGroup;
console2.log('_placeOrders H');
}
emit DexorderSwapPlaced(startIndex,uint8(orders.length));
}

View File

@@ -6,6 +6,7 @@ import "./Constants.sol";
import "./interface/IVaultDeployer.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./OrderLib.sol";
import "forge-std/console2.sol";
contract Vault {
@@ -53,6 +54,7 @@ contract Vault {
function placeOrder(OrderLib.SwapOrder memory order) public onlyOwner {
console2.log('Vault.placeOrder()');
orderList._placeOrder(order);
}

View File

@@ -10,7 +10,7 @@ library VaultAddress {
// keccak-256 hash of the Vault's bytecode (not the deployed bytecode but the initialization bytecode)
// can paste into:
// https://emn178.github.io/online-tools/keccak_256.html
bytes32 internal constant VAULT_INIT_CODE_HASH = 0x304b4fd55dc4ea606dcf1e4085f81f376e30552a319aa43fc3e389a089f2f0ea;
bytes32 internal constant VAULT_INIT_CODE_HASH = 0x3c95480d723e6cf3e130cfb53bfa2f15bd0bfc628246f77dfabe64ff943af969;
// the contract being constructed must not have any constructor arguments or the determinism will be broken. instead, use a callback to
// get construction arguments