order placement doesnt crash
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 "$@"
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -37,8 +37,10 @@ contract MockEnv {
|
||||
token0 = inverted ? address(USD) : address(COIN);
|
||||
token1 = inverted ? address(COIN) : address(USD);
|
||||
uint160 initialPrice = uint160(79228162514264337593543); // price 1e-12 = sqrt price 1e-6 = 2**96 / 10**6
|
||||
console2.log('if this is the last line before a revert then make sure to run forge with --rpc-url');
|
||||
// if this reverts here make sure Anvil is started and you are running forge with --rpc-url
|
||||
pool = IUniswapV3Pool(nfpm.createAndInitializePoolIfNecessary(token0, token1, fee, initialPrice));
|
||||
console2.log('created v3 pool successfully');
|
||||
int24 ts = pool.tickSpacing();
|
||||
(, int24 lower, , , , ,) = pool.slot0();
|
||||
int24 upper = lower;
|
||||
|
||||
@@ -4,7 +4,9 @@ pragma abicoder v2;
|
||||
|
||||
import "./MockEnv.sol";
|
||||
import "forge-std/Test.sol";
|
||||
import "forge-std/console2.sol";
|
||||
import "../src/Factory.sol";
|
||||
import "../src/OrderLib.sol";
|
||||
|
||||
contract TestOrder is MockEnv, Test {
|
||||
Factory public factory;
|
||||
@@ -23,7 +25,23 @@ contract TestOrder is MockEnv, Test {
|
||||
|
||||
|
||||
function testOrder() public {
|
||||
|
||||
OrderLib.Tranche[] memory tranches = new OrderLib.Tranche[](3);
|
||||
OrderLib.Constraint[] memory constraints1 = new OrderLib.Constraint[](1);
|
||||
constraints1[0] = OrderLib.Constraint(OrderLib.ConstraintMode.Time, bytes(hex"0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000046500"));
|
||||
OrderLib.Constraint[] memory constraints2 = new OrderLib.Constraint[](1);
|
||||
constraints2[0] = OrderLib.Constraint(OrderLib.ConstraintMode.Time, bytes(hex"000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000464fb0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000008c9fb"));
|
||||
OrderLib.Constraint[] memory constraints3 = new OrderLib.Constraint[](1);
|
||||
constraints3[0] = OrderLib.Constraint(OrderLib.ConstraintMode.Time, bytes(hex"0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000008c9f6000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000d2ef6"));
|
||||
tranches[0] = OrderLib.Tranche(21845,constraints1);
|
||||
tranches[1] = OrderLib.Tranche(21845,constraints2);
|
||||
tranches[2] = OrderLib.Tranche(21845,constraints3);
|
||||
OrderLib.SwapOrder memory order = OrderLib.SwapOrder(
|
||||
0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9, 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1,
|
||||
OrderLib.Route(OrderLib.Exchange.UniswapV3, 500), 100000000000000000000, true, false,
|
||||
18446744073709551615, tranches
|
||||
);
|
||||
console2.logBytes(abi.encode(order));
|
||||
vault.placeOrder(order);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user