order execution bugfixes
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
// SPDX-License-Identifier: UNLICENSED
|
// SPDX-License-Identifier: UNLICENSED
|
||||||
pragma solidity =0.7.6;
|
pragma solidity =0.7.6;
|
||||||
|
|
||||||
import "v3-core/contracts/UniswapV3Factory.sol";
|
|
||||||
import "./VaultDeployer.sol";
|
import "./VaultDeployer.sol";
|
||||||
pragma abicoder v2;
|
pragma abicoder v2;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ pragma abicoder v2;
|
|||||||
|
|
||||||
import "./Constants.sol";
|
import "./Constants.sol";
|
||||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
|
import "v3-periphery/libraries/TransferHelper.sol";
|
||||||
|
import "forge-std/console2.sol";
|
||||||
|
|
||||||
|
|
||||||
library UniswapSwapper {
|
library UniswapSwapper {
|
||||||
@@ -30,10 +32,20 @@ library UniswapSwapper {
|
|||||||
// uint256 amountOutMinimum;
|
// uint256 amountOutMinimum;
|
||||||
// uint160 sqrtPriceLimitX96;
|
// uint160 sqrtPriceLimitX96;
|
||||||
// }
|
// }
|
||||||
return Constants.uniswapV3SwapRouter.exactInputSingle(ISwapRouter.ExactInputSingleParams({
|
console2.log('swapExactInput approve...');
|
||||||
|
TransferHelper.safeApprove(params.tokenIn, address(Constants.uniswapV3SwapRouter), params.amount);
|
||||||
|
console2.log(params.tokenIn);
|
||||||
|
console2.log(params.tokenOut);
|
||||||
|
console2.log(uint(params.fee));
|
||||||
|
console2.log(address(Constants.uniswapV3SwapRouter));
|
||||||
|
console2.log(params.amount);
|
||||||
|
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: 0, sqrtPriceLimitX96: params.sqrtPriceLimitX96
|
||||||
}));
|
}));
|
||||||
|
console2.log('swapped');
|
||||||
|
console2.log(amountOut);
|
||||||
|
IERC20(params.tokenIn).approve(address(Constants.uniswapV3SwapRouter), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function swapExactOutput(SwapParams memory params) internal returns (uint256 amountIn)
|
function swapExactOutput(SwapParams memory params) internal returns (uint256 amountIn)
|
||||||
@@ -54,11 +66,20 @@ library UniswapSwapper {
|
|||||||
// todo dust?
|
// todo dust?
|
||||||
revert('IIA');
|
revert('IIA');
|
||||||
}
|
}
|
||||||
return Constants.uniswapV3SwapRouter.exactOutputSingle(ISwapRouter.ExactOutputSingleParams({
|
uint256 maxAmountIn = balance;
|
||||||
|
console2.log('swapExactOutput approve...');
|
||||||
|
TransferHelper.safeApprove(params.tokenIn, address(Constants.uniswapV3SwapRouter), maxAmountIn);
|
||||||
|
console2.log(params.tokenIn);
|
||||||
|
console2.log(address(Constants.uniswapV3SwapRouter));
|
||||||
|
console2.log(maxAmountIn);
|
||||||
|
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: balance, // todo use only the committed allocation?
|
deadline: block.timestamp, amountOut: params.amount, amountInMaximum: maxAmountIn,
|
||||||
sqrtPriceLimitX96: params.sqrtPriceLimitX96
|
sqrtPriceLimitX96: params.sqrtPriceLimitX96
|
||||||
}));
|
}));
|
||||||
|
console2.log('swapped');
|
||||||
|
console2.log(amountIn);
|
||||||
|
IERC20(params.tokenIn).approve(address(Constants.uniswapV3SwapRouter), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,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 internal constant VAULT_INIT_CODE_HASH = 0xbf7fa358e7e01c60966db5f8298feffb8b7e2aa494a6ba4a0f94a17a817f93ff;
|
bytes32 internal constant VAULT_INIT_CODE_HASH = 0x72f8226a3666abba278cd472062b776a74be697e53a365b69f0e9bfbcfabc1b9;
|
||||||
|
|
||||||
// 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
|
||||||
|
|||||||
Reference in New Issue
Block a user