forked from Uniswap/v3-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UniswapV3PoolSwapTest.sol
50 lines (43 loc) · 1.43 KB
/
UniswapV3PoolSwapTest.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
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.7.6;
import '../interfaces/IERC20Minimal.sol';
import '../interfaces/callback/IUniswapV3SwapCallback.sol';
import '../interfaces/IUniswapV3Pool.sol';
contract UniswapV3PoolSwapTest is IUniswapV3SwapCallback {
int256 private _amount0Delta;
int256 private _amount1Delta;
function getSwapResult(
address pool,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96
)
external
returns (
int256 amount0Delta,
int256 amount1Delta,
uint160 nextSqrtRatio
)
{
(amount0Delta, amount1Delta) = IUniswapV3Pool(pool).swap(
address(0),
zeroForOne,
amountSpecified,
sqrtPriceLimitX96,
abi.encode(msg.sender)
);
(nextSqrtRatio, , , , , , ) = IUniswapV3Pool(pool).slot0();
}
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external override {
address sender = abi.decode(data, (address));
if (amount0Delta > 0) {
IERC20Minimal(IUniswapV3Pool(msg.sender).token0()).transferFrom(sender, msg.sender, uint256(amount0Delta));
} else if (amount1Delta > 0) {
IERC20Minimal(IUniswapV3Pool(msg.sender).token1()).transferFrom(sender, msg.sender, uint256(amount1Delta));
}
}
}