735546619e
Signed-off-by: T-Hax <>
63 lines
2.0 KiB
Solidity
63 lines
2.0 KiB
Solidity
// SPDX-License-Identifier: UNLICENSED
|
|
pragma solidity =0.7.6;
|
|
|
|
import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';
|
|
import '@uniswap/v3-core/contracts/libraries/SafeCast.sol';
|
|
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';
|
|
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
|
|
|
|
contract TestUniswapV3Callee is IUniswapV3SwapCallback {
|
|
using SafeCast for uint256;
|
|
|
|
function swapExact0For1(
|
|
address pool,
|
|
uint256 amount0In,
|
|
address recipient,
|
|
uint160 sqrtPriceLimitX96
|
|
) external {
|
|
IUniswapV3Pool(pool).swap(recipient, true, amount0In.toInt256(), sqrtPriceLimitX96, abi.encode(msg.sender));
|
|
}
|
|
|
|
function swap0ForExact1(
|
|
address pool,
|
|
uint256 amount1Out,
|
|
address recipient,
|
|
uint160 sqrtPriceLimitX96
|
|
) external {
|
|
IUniswapV3Pool(pool).swap(recipient, true, -amount1Out.toInt256(), sqrtPriceLimitX96, abi.encode(msg.sender));
|
|
}
|
|
|
|
function swapExact1For0(
|
|
address pool,
|
|
uint256 amount1In,
|
|
address recipient,
|
|
uint160 sqrtPriceLimitX96
|
|
) external {
|
|
IUniswapV3Pool(pool).swap(recipient, false, amount1In.toInt256(), sqrtPriceLimitX96, abi.encode(msg.sender));
|
|
}
|
|
|
|
function swap1ForExact0(
|
|
address pool,
|
|
uint256 amount0Out,
|
|
address recipient,
|
|
uint160 sqrtPriceLimitX96
|
|
) external {
|
|
IUniswapV3Pool(pool).swap(recipient, false, -amount0Out.toInt256(), sqrtPriceLimitX96, abi.encode(msg.sender));
|
|
}
|
|
|
|
function uniswapV3SwapCallback(
|
|
int256 amount0Delta,
|
|
int256 amount1Delta,
|
|
bytes calldata data
|
|
) external override {
|
|
address sender = abi.decode(data, (address));
|
|
|
|
if (amount0Delta > 0) {
|
|
IERC20(IUniswapV3Pool(msg.sender).token0()).transferFrom(sender, msg.sender, uint256(amount0Delta));
|
|
} else {
|
|
assert(amount1Delta > 0);
|
|
IERC20(IUniswapV3Pool(msg.sender).token1()).transferFrom(sender, msg.sender, uint256(amount1Delta));
|
|
}
|
|
}
|
|
}
|