正在載入此比較的其餘部分。

univ3diff

建立於 差異永不過期
0 刪除
638 行
0 新增
638 行
contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
using LowGasSafeMath for uint256;
using LowGasSafeMath for uint256;
using LowGasSafeMath for int256;
using LowGasSafeMath for int256;
using SafeCast for uint256;
using SafeCast for uint256;
using SafeCast for int256;
using SafeCast for int256;
using Tick for mapping(int24 => Tick.Info);
using Tick for mapping(int24 => Tick.Info);
using TickBitmap for mapping(int16 => uint256);
using TickBitmap for mapping(int16 => uint256);
using Position for mapping(bytes32 => Position.Info);
using Position for mapping(bytes32 => Position.Info);
using Position for Position.Info;
using Position for Position.Info;
using Oracle for Oracle.Observation[65535];
using Oracle for Oracle.Observation[65535];


/// @inheritdoc IUniswapV3PoolImmutables
/// @inheritdoc IUniswapV3PoolImmutables
address public immutable override factory;
address public immutable override factory;
/// @inheritdoc IUniswapV3PoolImmutables
/// @inheritdoc IUniswapV3PoolImmutables
address public immutable override token0;
address public immutable override token0;
/// @inheritdoc IUniswapV3PoolImmutables
/// @inheritdoc IUniswapV3PoolImmutables
address public immutable override token1;
address public immutable override token1;
/// @inheritdoc IUniswapV3PoolImmutables
/// @inheritdoc IUniswapV3PoolImmutables
uint24 public immutable override fee;
uint24 public immutable override fee;


/// @inheritdoc IUniswapV3PoolImmutables
/// @inheritdoc IUniswapV3PoolImmutables
int24 public immutable override tickSpacing;
int24 public immutable override tickSpacing;


/// @inheritdoc IUniswapV3PoolImmutables
/// @inheritdoc IUniswapV3PoolImmutables
uint128 public immutable override maxLiquidityPerTick;
uint128 public immutable override maxLiquidityPerTick;


struct Slot0 {
struct Slot0 {
// the current price
// the current price
uint160 sqrtPriceX96;
uint160 sqrtPriceX96;
// the current tick
// the current tick
int24 tick;
int24 tick;
// the most-recently updated index of the observations array
// the most-recently updated index of the observations array
uint16 observationIndex;
uint16 observationIndex;
// the current maximum number of observations that are being stored
// the current maximum number of observations that are being stored
uint16 observationCardinality;
uint16 observationCardinality;
// the next maximum number of observations to store, triggered in observations.write
// the next maximum number of observations to store, triggered in observations.write
uint16 observationCardinalityNext;
uint16 observationCardinalityNext;
// the current protocol fee as a percentage of the swap fee taken on withdrawal
// the current protocol fee as a percentage of the swap fee taken on withdrawal
// represented as an integer denominator (1/x)%
// represented as an integer denominator (1/x)%
uint8 feeProtocol;
uint8 feeProtocol;
// whether the pool is locked
// whether the pool is locked
bool unlocked;
bool unlocked;
}
}
/// @inheritdoc IUniswapV3PoolState
/// @inheritdoc IUniswapV3PoolState
Slot0 public override slot0;
Slot0 public override slot0;


/// @inheritdoc IUniswapV3PoolState
/// @inheritdoc IUniswapV3PoolState
uint256 public override feeGrowthGlobal0X128;
uint256 public override feeGrowthGlobal0X128;
/// @inheritdoc IUniswapV3PoolState
/// @inheritdoc IUniswapV3PoolState
uint256 public override feeGrowthGlobal1X128;
uint256 public override feeGrowthGlobal1X128;


// accumulated protocol fees in token0/token1 units
// accumulated protocol fees in token0/token1 units
struct ProtocolFees {
struct ProtocolFees {
uint128 token0;
uint128 token0;
uint128 token1;
uint128 token1;
}
}
/// @inheritdoc IUniswapV3PoolState
/// @inheritdoc IUniswapV3PoolState
ProtocolFees public override protocolFees;
ProtocolFees public override protocolFees;


/// @inheritdoc IUniswapV3PoolState
/// @inheritdoc IUniswapV3PoolState
uint128 public override liquidity;
uint128 public override liquidity;


/// @inheritdoc IUniswapV3PoolState
/// @inheritdoc IUniswapV3PoolState
mapping(int24 => Tick.Info) public override ticks;
mapping(int24 => Tick.Info) public override ticks;
/// @inheritdoc IUniswapV3PoolState
/// @inheritdoc IUniswapV3PoolState
mapping(int16 => uint256) public override tickBitmap;
mapping(int16 => uint256) public override tickBitmap;
/// @inheritdoc IUniswapV3PoolState
/// @inheritdoc IUniswapV3PoolState
mapping(bytes32 => Position.Info) public override positions;
mapping(bytes32 => Position.Info) public override positions;
/// @inheritdoc IUniswapV3PoolState
/// @inheritdoc IUniswapV3PoolState
Oracle.Observation[65535] public override observations;
Oracle.Observation[65535] public override observations;


/// @dev Mutually exclusive reentrancy protection into the pool to/from a method. This method also prevents entrance
/// @dev Mutually exclusive reentrancy protection into the pool to/from a method. This method also prevents entrance
/// to a function before the pool is initialized. The reentrancy guard is required throughout the contract because
/// to a function before the pool is initialized. The reentrancy guard is required throughout the contract because
/// we use balance checks to determine the payment status of interactions such as mint, swap and flash.
/// we use balance checks to determine the payment status of interactions such as mint, swap and flash.
modifier lock() {
modifier lock() {
require(slot0.unlocked, 'LOK');
require(slot0.unlocked, 'LOK');
slot0.unlocked = false;
slot0.unlocked = false;
_;
_;
slot0.unlocked = true;
slot0.unlocked = true;
}
}


/// @dev Prevents calling a function from anyone except the address returned by IUniswapV3Factory#owner()
/// @dev Prevents calling a function from anyone except the address returned by IUniswapV3Factory#owner()
modifier onlyFactoryOwner() {
modifier onlyFactoryOwner() {
require(msg.sender == IUniswapV3Factory(factory).owner());
require(msg.sender == IUniswapV3Factory(factory).owner());
_;
_;
}
}


constructor() {
constructor() {
int24 _tickSpacing;
int24 _tickSpacing;
(factory, token0, token1, fee, _tickSpacing) = IUniswapV3PoolDeployer(msg.sender).parameters();
(factory, token0, token1, fee, _tickSpacing) = IUniswapV3PoolDeployer(msg.sender).parameters();
tickSpacing = _tickSpacing;
tickSpacing = _tickSpacing;


maxLiquidityPerTick = Tick.tickSpacingToMaxLiquidityPerTick(_tickSpacing);
maxLiquidityPerTick = Tick.tickSpacingToMaxLiquidityPerTick(_tickSpacing);
}
}


/// @dev Common checks for valid tick inputs.
/// @dev Common checks for valid tick inputs.
function checkTicks(int24 tickLower, int24 tickUpper) private pure {
function checkTicks(int24 tickLower, int24 tickUpper) private pure {
require(tickLower < tickUpper, 'TLU');
require(tickLower < tickUpper, 'TLU');
require(tickLower >= TickMath.MIN_TICK, 'TLM');
require(tickLower >= TickMath.MIN_TICK, 'TLM');
require(tickUpper <= TickMath.MAX_TICK, 'TUM');
require(tickUpper <= TickMath.MAX_TICK, 'TUM');