uniswap execution fixes, logs, and tests
This commit is contained in:
@@ -44,18 +44,20 @@ library UniswapSwapper {
|
|||||||
console2.log(uint(params.sqrtPriceLimitX96));
|
console2.log(uint(params.sqrtPriceLimitX96));
|
||||||
console2.log(address(Constants.uniswapV3SwapRouter));
|
console2.log(address(Constants.uniswapV3SwapRouter));
|
||||||
|
|
||||||
if (params.sqrtPriceLimitX96 == 0)
|
|
||||||
params.sqrtPriceLimitX96 = params.tokenIn < params.tokenOut ? TickMath.MIN_SQRT_RATIO+1 : TickMath.MAX_SQRT_RATIO-1;
|
|
||||||
TransferHelper.safeApprove(params.tokenIn, address(Constants.uniswapV3SwapRouter), params.amount);
|
TransferHelper.safeApprove(params.tokenIn, address(Constants.uniswapV3SwapRouter), params.amount);
|
||||||
|
// if (params.sqrtPriceLimitX96 == 0)
|
||||||
|
// params.sqrtPriceLimitX96 = params.tokenIn < params.tokenOut ? TickMath.MIN_SQRT_RATIO+1 : TickMath.MAX_SQRT_RATIO-1;
|
||||||
|
|
||||||
console2.log('splx96');
|
console2.log('splx96');
|
||||||
console2.log(uint(params.sqrtPriceLimitX96));
|
console2.log(uint(params.sqrtPriceLimitX96));
|
||||||
|
|
||||||
amountOut = Constants.uniswapV3SwapRouter.exactInputSingle(ISwapRouter.ExactInputSingleParams({
|
amountOut = Constants.uniswapV3SwapRouter.exactInputSingle(ISwapRouter.ExactInputSingleParams({
|
||||||
tokenIn: params.tokenIn, tokenOut: params.tokenOut, fee: params.fee, recipient: params.recipient,
|
tokenIn: params.tokenIn, tokenOut: params.tokenOut, fee: params.fee, recipient: params.recipient,
|
||||||
deadline: block.timestamp, amountIn: params.amount, amountOutMinimum: 0, sqrtPriceLimitX96: params.sqrtPriceLimitX96
|
deadline: block.timestamp, amountIn: params.amount, amountOutMinimum: 1, sqrtPriceLimitX96: params.sqrtPriceLimitX96
|
||||||
}));
|
}));
|
||||||
console2.log('swapped');
|
console2.log('swapped');
|
||||||
console2.log(amountOut);
|
console2.log(amountOut);
|
||||||
IERC20(params.tokenIn).approve(address(Constants.uniswapV3SwapRouter), 0);
|
TransferHelper.safeApprove(params.tokenIn, address(Constants.uniswapV3SwapRouter), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function swapExactOutput(SwapParams memory params) internal returns (uint256 amountIn)
|
function swapExactOutput(SwapParams memory params) internal returns (uint256 amountIn)
|
||||||
@@ -79,19 +81,34 @@ library UniswapSwapper {
|
|||||||
revert('IIA');
|
revert('IIA');
|
||||||
}
|
}
|
||||||
uint256 maxAmountIn = balance;
|
uint256 maxAmountIn = balance;
|
||||||
|
|
||||||
console2.log('swapExactOutput approve...');
|
console2.log('swapExactOutput approve...');
|
||||||
TransferHelper.safeApprove(params.tokenIn, address(Constants.uniswapV3SwapRouter), maxAmountIn);
|
console2.log(address(this));
|
||||||
console2.log(params.tokenIn);
|
console2.log(params.tokenIn);
|
||||||
|
console2.log(params.tokenOut);
|
||||||
|
console2.log(uint(params.fee));
|
||||||
|
console2.log(address(params.recipient));
|
||||||
|
console2.log(params.amount);
|
||||||
|
console2.log(uint(params.sqrtPriceLimitX96));
|
||||||
console2.log(address(Constants.uniswapV3SwapRouter));
|
console2.log(address(Constants.uniswapV3SwapRouter));
|
||||||
|
console2.log('approve');
|
||||||
console2.log(maxAmountIn);
|
console2.log(maxAmountIn);
|
||||||
|
|
||||||
|
TransferHelper.safeApprove(params.tokenIn, address(Constants.uniswapV3SwapRouter), maxAmountIn);
|
||||||
|
|
||||||
|
// if (params.sqrtPriceLimitX96 == 0)
|
||||||
|
// params.sqrtPriceLimitX96 = params.tokenIn < params.tokenOut ? TickMath.MIN_SQRT_RATIO+1 : TickMath.MAX_SQRT_RATIO-1;
|
||||||
|
|
||||||
amountIn = Constants.uniswapV3SwapRouter.exactOutputSingle(ISwapRouter.ExactOutputSingleParams({
|
amountIn = Constants.uniswapV3SwapRouter.exactOutputSingle(ISwapRouter.ExactOutputSingleParams({
|
||||||
tokenIn: params.tokenIn, tokenOut: params.tokenOut, fee: params.fee, recipient: params.recipient,
|
tokenIn: params.tokenIn, tokenOut: params.tokenOut, fee: params.fee, recipient: params.recipient,
|
||||||
deadline: block.timestamp, amountOut: params.amount, amountInMaximum: maxAmountIn,
|
deadline: block.timestamp, amountOut: params.amount, amountInMaximum: maxAmountIn,
|
||||||
sqrtPriceLimitX96: params.sqrtPriceLimitX96
|
sqrtPriceLimitX96: params.sqrtPriceLimitX96
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console2.log('swapped');
|
console2.log('swapped');
|
||||||
console2.log(amountIn);
|
console2.log(amountIn);
|
||||||
IERC20(params.tokenIn).approve(address(Constants.uniswapV3SwapRouter), 0);
|
|
||||||
|
TransferHelper.safeApprove(params.tokenIn, address(Constants.uniswapV3SwapRouter), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ library VaultAddress {
|
|||||||
// keccak-256 hash of the Vault's bytecode (not the deployed bytecode but the initialization bytecode)
|
// keccak-256 hash of the Vault's bytecode (not the deployed bytecode but the initialization bytecode)
|
||||||
// can paste into:
|
// can paste into:
|
||||||
// https://emn178.github.io/online-tools/keccak_256.html
|
// https://emn178.github.io/online-tools/keccak_256.html
|
||||||
bytes32 public constant VAULT_INIT_CODE_HASH = 0xaa3457854b70ea8d66f3b73269f0cf34c7e2212e4b4bd8176e8388ff223a2bd0;
|
bytes32 public constant VAULT_INIT_CODE_HASH = 0x5548eccbb8c4c38711944ab3e79a6f320ae2eb4a6bb16c64215f13e7732f182c;
|
||||||
|
|
||||||
// the contract being constructed must not have any constructor arguments or the determinism will be broken. instead, use a callback to
|
// the contract being constructed must not have any constructor arguments or the determinism will be broken. instead, use a callback to
|
||||||
// get construction arguments
|
// get construction arguments
|
||||||
|
|||||||
@@ -47,7 +47,29 @@ contract TestOrder is MockEnv, Test {
|
|||||||
vault.placeOrder(order);
|
vault.placeOrder(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testExecuteOrder() public {
|
function testExecuteOrderExactOutput() public {
|
||||||
|
OrderLib.Tranche[] memory tranches = new OrderLib.Tranche[](1);
|
||||||
|
OrderLib.Constraint[] memory constraints1 = new OrderLib.Constraint[](1);
|
||||||
|
constraints1[0] = OrderLib.Constraint(OrderLib.ConstraintMode.Time, bytes(hex"0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000046500"));
|
||||||
|
tranches[0] = OrderLib.Tranche(type(uint16).max,constraints1);
|
||||||
|
uint256 amount = 3*10**USD.decimals() / 10; // 0.3 USD
|
||||||
|
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, false, false,
|
||||||
|
OrderLib.NO_CHAIN, tranches
|
||||||
|
);
|
||||||
|
uint64 orderIndex = vault.numSwapOrders();
|
||||||
|
vault.placeOrder(order);
|
||||||
|
console2.log('placed order');
|
||||||
|
console2.log(uint(orderIndex));
|
||||||
|
string memory result;
|
||||||
|
vault.execute(orderIndex, 0, OrderLib.PriceProof(0));
|
||||||
|
console2.log('executed');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function testExecuteOrderExactInput() public {
|
||||||
OrderLib.Tranche[] memory tranches = new OrderLib.Tranche[](1);
|
OrderLib.Tranche[] memory tranches = new OrderLib.Tranche[](1);
|
||||||
OrderLib.Constraint[] memory constraints1 = new OrderLib.Constraint[](1);
|
OrderLib.Constraint[] memory constraints1 = new OrderLib.Constraint[](1);
|
||||||
constraints1[0] = OrderLib.Constraint(OrderLib.ConstraintMode.Time, bytes(hex"0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000046500"));
|
constraints1[0] = OrderLib.Constraint(OrderLib.ConstraintMode.Time, bytes(hex"0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000046500"));
|
||||||
|
|||||||
Reference in New Issue
Block a user