deterministic addr & test bugfixes
This commit is contained in:
@@ -4,20 +4,22 @@ pragma abicoder v2;
|
||||
|
||||
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
|
||||
import "./UniswapSwapper.sol";
|
||||
import "forge-std/console2.sol";
|
||||
|
||||
|
||||
library OrderLib {
|
||||
// todo safe math and/or bounds checking
|
||||
|
||||
uint64 internal constant NO_CHAIN = type(uint64).max;
|
||||
uint64 internal constant NO_OCO = type(uint64).max;
|
||||
|
||||
event DexorderPlaced (uint64 startOrderIndex, uint8 numOrders);
|
||||
event DexorderSwapPlaced (uint64 startOrderIndex, uint8 numOrders);
|
||||
|
||||
event DexorderSwapFilled (uint64 orderIndex, uint8 trancheIndex, uint256 amountIn, uint256 amountOut);
|
||||
|
||||
event DexorderCompleted (uint64 orderIndex); // todo remove?
|
||||
event DexorderSwapCompleted (uint64 orderIndex); // todo remove?
|
||||
|
||||
event DexorderError (uint64 orderIndex, string reason);
|
||||
event DexorderSwapError (uint64 orderIndex, string reason);
|
||||
|
||||
// todo If a tranche fails to fill, an order can stay Open forever without any active tranches. maybe replace state with a simple canceled flag
|
||||
enum SwapOrderState {
|
||||
@@ -127,7 +129,6 @@ library OrderLib {
|
||||
OcoGroup[] ocoGroups; // each indexed OCO group is an array of orderIndexes of orders in the oco group.
|
||||
}
|
||||
|
||||
|
||||
function _placeOrder(OrdersInfo storage self, SwapOrder memory order) internal {
|
||||
SwapOrder[] memory orders = new SwapOrder[](1);
|
||||
orders[0] = order;
|
||||
@@ -175,7 +176,7 @@ library OrderLib {
|
||||
status.start = uint32(block.timestamp);
|
||||
status.ocoGroup = ocoGroup;
|
||||
}
|
||||
emit DexorderPlaced(startIndex,uint8(orders.length));
|
||||
emit DexorderSwapPlaced(startIndex,uint8(orders.length));
|
||||
}
|
||||
|
||||
|
||||
@@ -279,7 +280,7 @@ library OrderLib {
|
||||
uint256 remaining = status.order.amount - (status.order.amountIsInput ? status.filledIn : status.filledOut);
|
||||
if( remaining == 0 ) { // todo dust leeway?
|
||||
status.state = SwapOrderState.Filled;
|
||||
emit DexorderCompleted(orderIndex);
|
||||
emit DexorderSwapCompleted(orderIndex);
|
||||
if( status.ocoGroup != NO_OCO )
|
||||
_cancelOco(self, status.ocoGroup);
|
||||
}
|
||||
@@ -298,7 +299,7 @@ library OrderLib {
|
||||
SwapOrderState state = self.orders[orderIndex].state;
|
||||
if( state == SwapOrderState.Open || state == SwapOrderState.Template ) {
|
||||
self.orders[orderIndex].state = SwapOrderState.Canceled;
|
||||
emit DexorderCompleted(orderIndex);
|
||||
emit DexorderSwapCompleted(orderIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,10 @@ contract Vault {
|
||||
orderList._placeOrders(orders, ocoMode);
|
||||
}
|
||||
|
||||
function swapOrderStatus(uint64 orderIndex) public view returns (OrderLib.SwapOrderStatus memory status) {
|
||||
return orderList.orders[orderIndex];
|
||||
}
|
||||
|
||||
function execute(uint64 orderIndex, uint8 tranche_index, OrderLib.PriceProof memory proof) public
|
||||
returns (string memory error)
|
||||
{
|
||||
|
||||
@@ -3,13 +3,14 @@ pragma solidity =0.7.6;
|
||||
pragma abicoder v2;
|
||||
|
||||
import "./Constants.sol";
|
||||
import "forge-std/console2.sol";
|
||||
|
||||
|
||||
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 = 0xdc7f6d1305b2c9951dc98f6a745290e4f2b92bf65d346db11dd284dcfcd67aef;
|
||||
bytes32 internal constant VAULT_INIT_CODE_HASH = 0x40d5f4d1aa2f505a4b156599c452d0e7df5003430246ca5798a932dc031a9127;
|
||||
|
||||
// the contract being constructed must not have any constructor arguments or the determinism will be broken. instead, use a callback to
|
||||
// get construction arguments
|
||||
@@ -20,13 +21,14 @@ library VaultAddress {
|
||||
}
|
||||
|
||||
function computeAddress(address factory, address owner, uint8 num) internal pure returns (address vault) {
|
||||
bytes32 salt = keccak256(abi.encodePacked(owner,num));
|
||||
vault = address(
|
||||
uint256(
|
||||
keccak256(
|
||||
abi.encodePacked(
|
||||
hex'ff',
|
||||
factory,
|
||||
keccak256(abi.encode(owner,num)),
|
||||
salt,
|
||||
VAULT_INIT_CODE_HASH
|
||||
)
|
||||
)
|
||||
|
||||
@@ -32,7 +32,7 @@ contract VaultDeployer {
|
||||
|
||||
function _deployVault(address owner, uint8 num) internal returns (address payable vault) {
|
||||
parameters = Parameters(owner);
|
||||
vault = address(new Vault{salt: keccak256(abi.encode(owner,num))}());
|
||||
vault = address(new Vault{salt: keccak256(abi.encodePacked(owner,num))}());
|
||||
delete parameters;
|
||||
emit VaultCreated( owner, num );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user