|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +pragma solidity 0.6.10; |
| 3 | +pragma experimental ABIEncoderV2; |
| 4 | + |
| 5 | +/// @title Permissionless pool actions |
| 6 | +/// @notice Contains pool methods that can be called by anyone |
| 7 | +/// https://github.com/Uniswap/v3-core/blob/main/contracts/interfaces/pool/IUniswapV3PoolActions.sol |
| 8 | +interface IUniswapV3Pool { |
| 9 | + /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas |
| 10 | + /// when accessed externally. |
| 11 | + /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value |
| 12 | + /// tick The current tick of the pool, i.e. according to the last tick transition that was run. |
| 13 | + /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick |
| 14 | + /// boundary. |
| 15 | + /// observationIndex The index of the last oracle observation that was written, |
| 16 | + /// observationCardinality The current maximum number of observations stored in the pool, |
| 17 | + /// observationCardinalityNext The next maximum number of observations, to be updated when the observation. |
| 18 | + /// feeProtocol The protocol fee for both tokens of the pool. |
| 19 | + /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0 |
| 20 | + /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee. |
| 21 | + /// unlocked Whether the pool is currently locked to reentrancy |
| 22 | + function slot0() |
| 23 | + external |
| 24 | + view |
| 25 | + returns ( |
| 26 | + uint160 sqrtPriceX96, |
| 27 | + int24 tick, |
| 28 | + uint16 observationIndex, |
| 29 | + uint16 observationCardinality, |
| 30 | + uint16 observationCardinalityNext, |
| 31 | + uint8 feeProtocol, |
| 32 | + bool unlocked |
| 33 | + ); |
| 34 | + |
| 35 | + /// @notice Sets the initial price for the pool |
| 36 | + /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value |
| 37 | + /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96 |
| 38 | + function initialize(uint160 sqrtPriceX96) external; |
| 39 | + |
| 40 | + /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position |
| 41 | + /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback |
| 42 | + /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends |
| 43 | + /// on tickLower, tickUpper, the amount of liquidity, and the current price. |
| 44 | + /// @param recipient The address for which the liquidity will be created |
| 45 | + /// @param tickLower The lower tick of the position in which to add liquidity |
| 46 | + /// @param tickUpper The upper tick of the position in which to add liquidity |
| 47 | + /// @param amount The amount of liquidity to mint |
| 48 | + /// @param data Any data that should be passed through to the callback |
| 49 | + /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback |
| 50 | + /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback |
| 51 | + function mint( |
| 52 | + address recipient, |
| 53 | + int24 tickLower, |
| 54 | + int24 tickUpper, |
| 55 | + uint128 amount, |
| 56 | + bytes calldata data |
| 57 | + ) external returns (uint256 amount0, uint256 amount1); |
| 58 | + |
| 59 | + /// @notice Collects tokens owed to a position |
| 60 | + /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. |
| 61 | + /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or |
| 62 | + /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the |
| 63 | + /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity. |
| 64 | + /// @param recipient The address which should receive the fees collected |
| 65 | + /// @param tickLower The lower tick of the position for which to collect fees |
| 66 | + /// @param tickUpper The upper tick of the position for which to collect fees |
| 67 | + /// @param amount0Requested How much token0 should be withdrawn from the fees owed |
| 68 | + /// @param amount1Requested How much token1 should be withdrawn from the fees owed |
| 69 | + /// @return amount0 The amount of fees collected in token0 |
| 70 | + /// @return amount1 The amount of fees collected in token1 |
| 71 | + function collect( |
| 72 | + address recipient, |
| 73 | + int24 tickLower, |
| 74 | + int24 tickUpper, |
| 75 | + uint128 amount0Requested, |
| 76 | + uint128 amount1Requested |
| 77 | + ) external returns (uint128 amount0, uint128 amount1); |
| 78 | + |
| 79 | + /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position |
| 80 | + /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0 |
| 81 | + /// @dev Fees must be collected separately via a call to #collect |
| 82 | + /// @param tickLower The lower tick of the position for which to burn liquidity |
| 83 | + /// @param tickUpper The upper tick of the position for which to burn liquidity |
| 84 | + /// @param amount How much liquidity to burn |
| 85 | + /// @return amount0 The amount of token0 sent to the recipient |
| 86 | + /// @return amount1 The amount of token1 sent to the recipient |
| 87 | + function burn( |
| 88 | + int24 tickLower, |
| 89 | + int24 tickUpper, |
| 90 | + uint128 amount |
| 91 | + ) external returns (uint256 amount0, uint256 amount1); |
| 92 | + |
| 93 | + /// @notice Swap token0 for token1, or token1 for token0 |
| 94 | + /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback |
| 95 | + /// @param recipient The address to receive the output of the swap |
| 96 | + /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0 |
| 97 | + /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) |
| 98 | + /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this |
| 99 | + /// value after the swap. If one for zero, the price cannot be greater than this value after the swap |
| 100 | + /// @param data Any data to be passed through to the callback |
| 101 | + /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive |
| 102 | + /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive |
| 103 | + function swap( |
| 104 | + address recipient, |
| 105 | + bool zeroForOne, |
| 106 | + int256 amountSpecified, |
| 107 | + uint160 sqrtPriceLimitX96, |
| 108 | + bytes calldata data |
| 109 | + ) external returns (int256 amount0, int256 amount1); |
| 110 | + |
| 111 | + /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback |
| 112 | + /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback |
| 113 | + /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling |
| 114 | + /// with 0 amount{0,1} and sending the donation amount(s) from the callback |
| 115 | + /// @param recipient The address which will receive the token0 and token1 amounts |
| 116 | + /// @param amount0 The amount of token0 to send |
| 117 | + /// @param amount1 The amount of token1 to send |
| 118 | + /// @param data Any data to be passed through to the callback |
| 119 | + function flash( |
| 120 | + address recipient, |
| 121 | + uint256 amount0, |
| 122 | + uint256 amount1, |
| 123 | + bytes calldata data |
| 124 | + ) external; |
| 125 | + |
| 126 | + /// @notice Increase the maximum number of price and liquidity observations that this pool will store |
| 127 | + /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to |
| 128 | + /// the input observationCardinalityNext. |
| 129 | + /// @param observationCardinalityNext The desired minimum number of observations for the pool to store |
| 130 | + function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external; |
| 131 | +} |
0 commit comments