forked from Uniswap/v3-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestUniswapV3SwapPay.sol
41 lines (36 loc) · 1.18 KB
/
TestUniswapV3SwapPay.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.7.6;
import '../interfaces/IERC20Minimal.sol';
import '../interfaces/callback/IUniswapV3SwapCallback.sol';
import '../interfaces/IUniswapV3Pool.sol';
contract TestUniswapV3SwapPay is IUniswapV3SwapCallback {
function swap(
address pool,
address recipient,
bool zeroForOne,
uint160 sqrtPriceX96,
int256 amountSpecified,
uint256 pay0,
uint256 pay1
) external {
IUniswapV3Pool(pool).swap(
recipient,
zeroForOne,
amountSpecified,
sqrtPriceX96,
abi.encode(msg.sender, pay0, pay1)
);
}
function uniswapV3SwapCallback(
int256,
int256,
bytes calldata data
) external override {
(address sender, uint256 pay0, uint256 pay1) = abi.decode(data, (address, uint256, uint256));
if (pay0 > 0) {
IERC20Minimal(IUniswapV3Pool(msg.sender).token0()).transferFrom(sender, msg.sender, uint256(pay0));
} else if (pay1 > 0) {
IERC20Minimal(IUniswapV3Pool(msg.sender).token1()).transferFrom(sender, msg.sender, uint256(pay1));
}
}
}