removed PriceConstraint and implemented LineConstraint; MockDeploy copied/separated from Deploy
This commit is contained in:
@@ -77,7 +77,7 @@ contract TestOrder is MockEnv, Test {
|
||||
COIN.mint(address(vault), amount); // create COIN to sell
|
||||
OrderLib.SwapOrder memory order = OrderLib.SwapOrder(
|
||||
address(COIN), address(USD), // sell COIN for USD
|
||||
OrderLib.Route(OrderLib.Exchange.UniswapV3, 500), amount, true, false,
|
||||
OrderLib.Route(OrderLib.Exchange.UniswapV3, fee), amount, true, false,
|
||||
OrderLib.NO_CHAIN, tranches
|
||||
);
|
||||
uint64 orderIndex = vault.numSwapOrders();
|
||||
@@ -88,4 +88,38 @@ contract TestOrder is MockEnv, Test {
|
||||
console2.log('executed');
|
||||
}
|
||||
|
||||
|
||||
function testExecuteLimitOrder() public {
|
||||
// test selling token0 above a certain price
|
||||
OrderLib.Tranche[] memory tranches = new OrderLib.Tranche[](1);
|
||||
OrderLib.Constraint[] memory constraints1 = new OrderLib.Constraint[](1);
|
||||
uint160 limit = price() * 10001 / 10000; // 1bp above the current price
|
||||
bytes memory serialized = abi.encode( OrderLib.LineConstraint(true, false, 0, limit, 0) );
|
||||
constraints1[0] = OrderLib.Constraint(OrderLib.ConstraintMode.Line, serialized);
|
||||
tranches[0] = OrderLib.Tranche(type(uint16).max,constraints1);
|
||||
MockERC20 token = MockERC20(token0);
|
||||
uint256 amount = 3*10**token.decimals() / 10; // selling 0.3 token0
|
||||
token.mint(address(vault), amount);
|
||||
OrderLib.SwapOrder memory order = OrderLib.SwapOrder(
|
||||
token0, token1, // sell
|
||||
OrderLib.Route(OrderLib.Exchange.UniswapV3, fee), amount, true, false,
|
||||
OrderLib.NO_CHAIN, tranches
|
||||
);
|
||||
uint64 orderIndex = vault.numSwapOrders();
|
||||
vault.placeOrder(order);
|
||||
console2.log('placed order');
|
||||
console2.log(uint(orderIndex));
|
||||
|
||||
vm.expectRevert(bytes('L'));
|
||||
vault.execute(orderIndex, 0, OrderLib.PriceProof(0)); // should revert with code 'L'
|
||||
console2.log('successfully failed to execute below limit price');
|
||||
|
||||
swapToPrice(limit); // move price to exactly the limit
|
||||
vm.expectRevert(bytes('L')); // the limit is violated. no liquidity can be taken without moving the price.
|
||||
vault.execute(orderIndex, 0, OrderLib.PriceProof(0)); // should work now that the price is high enough
|
||||
|
||||
swapToPrice(limit*10001/10000); // move price to be 1bp abouve our limit
|
||||
console2.log('successfully executed at limit price');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user