Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- PointsFarming
- Optimization enabled
- true
- Compiler version
- v0.8.20+commit.a1b79de6
- Optimization runs
- 10
- EVM Version
- paris
- Verified at
- 2025-04-14T15:00:01.130508Z
Constructor Arguments
0x0000000000000000000000001d0a515902f69db560eec32ed1dc2154cb882c9800000000000000000000000037b70f2212fb8036ce11f00596386c921ee94713
Arg [0] (address) : 0x1d0a515902f69db560eec32ed1dc2154cb882c98
Arg [1] (address) : 0x37b70f2212fb8036ce11f00596386c921ee94713
contracts/PointsFarming.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "./Ownable.sol";
import "./ReentrancyGuard.sol";
import "./Enumerable.sol";
import "./utils/SafeERC20.sol";
import "./interfaces/INonfungiblePositionManager.sol";
import "./interfaces/INonfungiblePositionManagerStruct.sol";
import "./interfaces/IPoolV3.sol";
import "./interfaces/IERC721.sol";
import "./libraries/PriceOracle.sol";
import "./Multicall.sol";
/**
* @title PointsFarming
* @dev Contract for staking NFT V3 positions to earn points
*/
contract PointsFarming is
INonfungiblePositionManagerStruct,
Ownable,
ReentrancyGuard,
Enumerable,
Multicall
{
using SafeERC20 for IERC20;
// Constants
address public immutable WPLS_DAI_POOL;
INonfungiblePositionManager public immutable nonfungiblePositionManager;
// Configuration
uint256 public pointsThreshold = 10 * 1e18; // $10 USD threshold for 1 point
// Structs
struct PoolInfo {
IPoolV3 v3Pool; // V3 pool address
address token0; // V3 pool token0 address
address token1; // V3 pool token1 address
uint24 fee; // V3 pool fee
}
struct UserPositionInfo {
uint128 liquidity; // Position liquidity
int24 tickLower; // Position tick lower
int24 tickUpper; // Position tick upper
address user; // Position owner
uint256 pid; // Pool ID
address poolAddress; // Pool address
uint256 points; // Accumulated points
uint256 tokenId; // NFT token ID
uint256 lastUpdateBlock; // Last block when points were updated
}
// State variables
uint256 public poolLength;
// Mappings
mapping(uint256 => UserPositionInfo) public userPositionInfos;
mapping(uint256 => PoolInfo) public poolInfo;
mapping(address => mapping(address => mapping(uint24 => uint256)))
private v3PoolPid;
mapping(address => uint256) public v3PoolAddressPid;
// Errors
error NotPDexNFT();
error NoLiquidity();
error InvalidNFT();
error InvalidPool();
error DuplicatedPool(uint256 pid);
error NotPositionOwner();
error NoRewardsAvailable();
// Events
event AddPool(uint256 indexed pid, IPoolV3 indexed v3Pool);
event PositionDeposited(
address indexed user,
uint256 indexed tokenId,
address indexed poolAddress
);
event PositionWithdrawn(
address indexed user,
uint256 indexed tokenId,
address indexed poolAddress
);
event PointsUpdated(uint256 indexed tokenId, uint256 newPoints);
event PointsThresholdUpdated(uint256 oldThreshold, uint256 newThreshold);
/**
* @dev Constructor sets initial values
* @param _nonfungiblePositionManager Address of the NFT Position Manager contract
* @param _wplsDaiPool Address of the WPLS/DAI pool for price calculations
*/
constructor(address _nonfungiblePositionManager, address _wplsDaiPool) {
require(
_nonfungiblePositionManager != address(0),
"Invalid NFT Manager address"
);
require(_wplsDaiPool != address(0), "Invalid WPLS/DAI pool address");
nonfungiblePositionManager = INonfungiblePositionManager(
_nonfungiblePositionManager
);
WPLS_DAI_POOL = _wplsDaiPool;
}
/**
* @dev Required function to receive ERC721 tokens
*/
function onERC721Received(
address,
address _from,
uint256 _tokenId,
bytes calldata
) external nonReentrant returns (bytes4) {
if (msg.sender != address(nonfungiblePositionManager))
revert NotPDexNFT();
// Get position data from the NFT position manager
(
,
,
address token0,
address token1,
uint24 fee,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
,
,
,
) = nonfungiblePositionManager.positions(_tokenId);
if (liquidity == 0) revert NoLiquidity();
uint256 pid = v3PoolPid[token0][token1][fee];
if (pid == 0) revert InvalidNFT();
// Store position info
UserPositionInfo storage positionInfo = userPositionInfos[_tokenId];
if (positionInfo.user == address(0)) {
positionInfo.user = _from;
positionInfo.pid = pid;
positionInfo.poolAddress = address(poolInfo[pid].v3Pool);
positionInfo.points = 0;
positionInfo.liquidity = liquidity;
positionInfo.tickLower = tickLower;
positionInfo.tickUpper = tickUpper;
positionInfo.lastUpdateBlock = block.number;
positionInfo.tokenId = _tokenId;
} else {
// Update existing position info
positionInfo.liquidity = liquidity;
positionInfo.tickLower = tickLower;
positionInfo.tickUpper = tickUpper;
positionInfo.lastUpdateBlock = block.number;
}
// Track token ownership
addToken(_from, _tokenId);
emit PositionDeposited(_from, _tokenId, address(poolInfo[pid].v3Pool));
return this.onERC721Received.selector;
}
/**
* @dev Add a pool to the valid pools list
* @param poolAddress Address of the pool to add
*/
function add(address poolAddress) external onlyOwner {
require(poolAddress != address(0), "InvalidPool");
IPoolV3 v3Pool = IPoolV3(poolAddress);
address token0 = v3Pool.token0();
address token1 = v3Pool.token1();
uint24 fee = v3Pool.fee();
// Check if pool already exists
if (v3PoolPid[token0][token1][fee] != 0)
revert DuplicatedPool(v3PoolPid[token0][token1][fee]);
// Approve tokens for the NFT position manager if needed
_approveTokenIfNeeded(token0);
_approveTokenIfNeeded(token1);
// Increment pool count and store pool info
unchecked {
poolLength++;
}
poolInfo[poolLength] = PoolInfo({
v3Pool: v3Pool,
token0: token0,
token1: token1,
fee: fee
});
// Update pool mappings
v3PoolPid[token0][token1][fee] = poolLength;
v3PoolAddressPid[address(v3Pool)] = poolLength;
emit AddPool(poolLength, v3Pool);
}
/**
* @dev Helper to approve tokens for position manager
*/
function _approveTokenIfNeeded(address token) private {
if (
IERC20(token).allowance(
address(this),
address(nonfungiblePositionManager)
) == 0
) {
IERC20(token).safeApprove(
address(nonfungiblePositionManager),
type(uint256).max
);
}
}
/**
* @dev Deposit an NFT V3 position
* @param _tokenId Token ID of the NFT position
*/
function deposit(uint256 _tokenId) external {
nonfungiblePositionManager.safeTransferFrom(
msg.sender,
address(this),
_tokenId
);
}
/**
* @dev Withdraw an NFT V3 position
* @param _tokenId Token ID of the NFT position to withdraw
*/
function withdraw(uint256 _tokenId) external nonReentrant {
address positionOwner = userPositionInfos[_tokenId].user;
if (positionOwner != msg.sender) revert NotPositionOwner();
// Update points before withdrawal
updatePoints(_tokenId);
// Store position info for events
UserPositionInfo storage positionInfo = userPositionInfos[_tokenId];
uint256 pid = positionInfo.pid;
address poolAddress = address(poolInfo[pid].v3Pool);
// Transfer NFT back to owner
nonfungiblePositionManager.safeTransferFrom(
address(this),
positionOwner,
_tokenId
);
// Clean up
removeToken(positionOwner, _tokenId);
// delete userPositionInfos[_tokenId];
emit PositionWithdrawn(positionOwner, _tokenId, poolAddress);
}
/**
* @notice Calculate the total USD value of a staked position
* @param tokenId The NFT position ID to evaluate
* @return usdValue The total USD value of the position (18 decimals)
*/
function getPositionValueInUSD(
uint256 tokenId
) public view returns (uint256 usdValue) {
UserPositionInfo memory position = userPositionInfos[tokenId];
require(position.user != address(0), "Position does not exist");
// Get pool info
PoolInfo memory pool = poolInfo[position.pid];
// Prepare position data for the value calculator
PriceOracle.PositionData memory posData = PriceOracle.PositionData({
liquidity: position.liquidity,
tickLower: position.tickLower,
tickUpper: position.tickUpper,
token0: pool.token0,
token1: pool.token1,
poolAddress: address(pool.v3Pool)
});
// Calculate position value
return PriceOracle.getPositionValueInUSD(posData, WPLS_DAI_POOL);
}
/**
* @notice Get the current ETH price in DAI
* @return price The current price of 1 ETH in DAI (with 18 decimals)
*/
function getEthPriceInUSD() public view returns (uint256 price) {
// Get the current ETH price in DAI
uint256 ethPriceInUSD = PriceOracle.getEthPriceInUSD(WPLS_DAI_POOL);
return ethPriceInUSD;
}
function getTokenPriceInUSD(
address token,
address poolAddress
) public view returns (uint256 price) {
// Get the current token price in DAI
uint256 tokenPriceInUSD = PriceOracle.getTokenPriceInUSD(
token,
poolAddress,
WPLS_DAI_POOL
);
return tokenPriceInUSD;
}
/**
* @notice Updates a position's points based on its USD value
* @param tokenId The NFT position ID to update
*/
function updatePoints(uint256 tokenId) internal {
UserPositionInfo storage position = userPositionInfos[tokenId];
require(position.user != address(0), "Position does not exist");
// Calculate points accrued since last update
uint256 newPoints = pendingPoints(tokenId);
// Update position info
position.points += newPoints;
position.lastUpdateBlock = block.number;
emit PointsUpdated(tokenId, position.points);
}
/**
* @notice Calculate points earned based on position value with precision
* @param positionValueUSD The USD value of position (18 decimals)
* @param _pointsThreshold Amount of USD value required for 1 point (18 decimals)
* @param blocksElapsed Number of blocks since last update
* @return points The number of points earned (with 18 decimals precision)
*/
function calculatePoints(
uint256 positionValueUSD,
uint256 _pointsThreshold,
uint256 blocksElapsed
) internal pure returns (uint256 points) {
// Using 18 decimals precision to avoid truncation
uint256 PRECISION = 1e18;
// Calculate points per block with precision
// For example, 20.778663922805105214 * 1e18 / 10 = 2.0778663922805105 * 1e18
uint256 pointsPerBlock = (positionValueUSD * PRECISION) /
_pointsThreshold;
// Calculate total points by multiplying by blocks elapsed
// This maintains the precision (18 decimals)
points = pointsPerBlock * blocksElapsed;
return points;
}
/**
* @notice Calculate pending points for a position based on its USD value
* @param tokenId The NFT position ID to check
* @return points The pending points to be awarded
*/
function pendingPoints(
uint256 tokenId
) public view returns (uint256 points) {
UserPositionInfo memory position = userPositionInfos[tokenId];
if (position.user == address(0)) return 0;
// If this is the first block, no points earned yet
if (block.number <= position.lastUpdateBlock) return 0;
// Get the position value in USD
uint256 positionValueUSD = getPositionValueInUSD(tokenId);
// Calculate blocks elapsed since last update
uint256 blocksElapsed = block.number - position.lastUpdateBlock;
// Calculate points using the library
return
calculatePoints(positionValueUSD, pointsThreshold, blocksElapsed);
}
/**
* @notice Set the USD value threshold required to earn 1 point per block
* @param _newThreshold New threshold value (with 18 decimals)
*/
function setPointsThreshold(uint256 _newThreshold) external onlyOwner {
require(_newThreshold > 0, "Threshold cannot be zero");
uint256 oldThreshold = pointsThreshold;
pointsThreshold = _newThreshold;
emit PointsThresholdUpdated(oldThreshold, _newThreshold);
}
/**
* @notice Get all token IDs staked by a user
* @param user Address of the user
* @return tokenIds Array of token IDs owned by the user
*/
function getUserTokens(
address user
) public view returns (uint256[] memory tokenIds) {
uint256 balance = balanceOf(user);
tokenIds = new uint256[](balance);
for (uint256 i = 0; i < balance; i++) {
tokenIds[i] = tokenOfOwnerByIndex(user, i);
}
return tokenIds;
}
/**
* @notice Get total points for a user across all their staked positions
* @param user Address of the user to check
* @return totalPoints The total points earned by the user
*/
function getUserTotalPoints(
address user
) external view returns (uint256 totalPoints) {
uint256[] memory tokenIds = getUserTokens(user);
for (uint256 i = 0; i < tokenIds.length; i++) {
// Add already earned points
totalPoints += userPositionInfos[tokenIds[i]].points;
// Add pending points
totalPoints += pendingPoints(tokenIds[i]);
}
return totalPoints;
}
/**
* @dev Emergency function to recover wrongly sent ERC721 tokens
* @param _tokenId Token ID to recover
* @param _to Address to send the recovered token to
*/
function recoverERC721(uint256 _tokenId, address _to) external onlyOwner {
UserPositionInfo storage positionInfo = userPositionInfos[_tokenId];
if (positionInfo.user != address(0)) {
delete userPositionInfos[_tokenId];
}
nonfungiblePositionManager.safeTransferFrom(
address(this),
_to,
_tokenId
);
}
function getUserPositions(
address user,
uint256 offset,
uint256 limit
) external view returns (UserPositionInfo[] memory) {
uint256[] memory tokenIds = getUserTokens(user);
uint256 total = tokenIds.length;
// Calculate how many positions to return in this batch
uint256 batchSize = limit;
if (offset >= total) {
// Return empty array if offset is beyond available tokens
return (new UserPositionInfo[](0));
}
if (offset + limit > total) {
// Adjust batch size if it would exceed total positions
batchSize = total - offset;
}
// Create array for batch of positions
UserPositionInfo[] memory positions = new UserPositionInfo[](batchSize);
// Fill the positions array with the current batch
for (uint256 i = 0; i < batchSize; i++) {
UserPositionInfo memory position = userPositionInfos[
tokenIds[offset + i]
];
position.points = pendingPoints(tokenIds[offset + i]);
positions[i] = position;
}
return positions;
}
}
@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import {IUniswapV3PoolImmutables} from './pool/IUniswapV3PoolImmutables.sol';
import {IUniswapV3PoolState} from './pool/IUniswapV3PoolState.sol';
import {IUniswapV3PoolDerivedState} from './pool/IUniswapV3PoolDerivedState.sol';
import {IUniswapV3PoolActions} from './pool/IUniswapV3PoolActions.sol';
import {IUniswapV3PoolOwnerActions} from './pool/IUniswapV3PoolOwnerActions.sol';
import {IUniswapV3PoolErrors} from './pool/IUniswapV3PoolErrors.sol';
import {IUniswapV3PoolEvents} from './pool/IUniswapV3PoolEvents.sol';
/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
IUniswapV3PoolImmutables,
IUniswapV3PoolState,
IUniswapV3PoolDerivedState,
IUniswapV3PoolActions,
IUniswapV3PoolOwnerActions,
IUniswapV3PoolErrors,
IUniswapV3PoolEvents
{
}
@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}
@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
/// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
/// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
/// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
/// you must call it with secondsAgos = [3600, 0].
/// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
/// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
/// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
/// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
/// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
/// timestamp
function observe(uint32[] calldata secondsAgos)
external
view
returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);
/// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
/// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
/// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
/// snapshot is taken and the second snapshot is taken.
/// @param tickLower The lower tick of the range
/// @param tickUpper The upper tick of the range
/// @return tickCumulativeInside The snapshot of the tick accumulator for the range
/// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
/// @return secondsInside The snapshot of seconds per liquidity for the range
function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
external
view
returns (
int56 tickCumulativeInside,
uint160 secondsPerLiquidityInsideX128,
uint32 secondsInside
);
}
@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolErrors.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Errors emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolErrors {
error LOK();
error TLU();
error TLM();
error TUM();
error AI();
error M0();
error M1();
error AS();
error IIA();
error L();
error F0();
error F1();
}
@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
/// @notice Emitted exactly once by a pool when #initialize is first called on the pool
/// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
/// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
/// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
event Initialize(uint160 sqrtPriceX96, int24 tick);
/// @notice Emitted when liquidity is minted for a given position
/// @param sender The address that minted the liquidity
/// @param owner The owner of the position and recipient of any minted liquidity
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity minted to the position range
/// @param amount0 How much token0 was required for the minted liquidity
/// @param amount1 How much token1 was required for the minted liquidity
event Mint(
address sender,
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted when fees are collected by the owner of a position
/// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
/// @param owner The owner of the position for which fees are collected
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount0 The amount of token0 fees collected
/// @param amount1 The amount of token1 fees collected
event Collect(
address indexed owner,
address recipient,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount0,
uint128 amount1
);
/// @notice Emitted when a position's liquidity is removed
/// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
/// @param owner The owner of the position for which liquidity is removed
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity to remove
/// @param amount0 The amount of token0 withdrawn
/// @param amount1 The amount of token1 withdrawn
event Burn(
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted by the pool for any swaps between token0 and token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the output of the swap
/// @param amount0 The delta of the token0 balance of the pool
/// @param amount1 The delta of the token1 balance of the pool
/// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
/// @param liquidity The liquidity of the pool after the swap
/// @param tick The log base 1.0001 of price of the pool after the swap
event Swap(
address indexed sender,
address indexed recipient,
int256 amount0,
int256 amount1,
uint160 sqrtPriceX96,
uint128 liquidity,
int24 tick
);
/// @notice Emitted by the pool for any flashes of token0/token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the tokens from flash
/// @param amount0 The amount of token0 that was flashed
/// @param amount1 The amount of token1 that was flashed
/// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
/// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
event Flash(
address indexed sender,
address indexed recipient,
uint256 amount0,
uint256 amount1,
uint256 paid0,
uint256 paid1
);
/// @notice Emitted by the pool for increases to the number of observations that can be stored
/// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
/// just before a mint/swap/burn.
/// @param observationCardinalityNextOld The previous value of the next observation cardinality
/// @param observationCardinalityNextNew The updated value of the next observation cardinality
event IncreaseObservationCardinalityNext(
uint16 observationCardinalityNextOld,
uint16 observationCardinalityNextNew
);
/// @notice Emitted when the protocol fee is changed by the pool
/// @param feeProtocol0Old The previous value of the token0 protocol fee
/// @param feeProtocol1Old The previous value of the token1 protocol fee
/// @param feeProtocol0New The updated value of the token0 protocol fee
/// @param feeProtocol1New The updated value of the token1 protocol fee
event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);
/// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
/// @param sender The address that collects the protocol fees
/// @param recipient The address that receives the collected protocol fees
/// @param amount0 The amount of token0 protocol fees that is withdrawn
/// @param amount0 The amount of token1 protocol fees that is withdrawn
event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}
@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
/// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
/// @return The contract address
function factory() external view returns (address);
/// @notice The first of the two tokens of the pool, sorted by address
/// @return The token contract address
function token0() external view returns (address);
/// @notice The second of the two tokens of the pool, sorted by address
/// @return The token contract address
function token1() external view returns (address);
/// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
/// @return The fee
function fee() external view returns (uint24);
/// @notice The pool tick spacing
/// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
/// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
/// This value is an int24 to avoid casting even though it is always positive.
/// @return The tick spacing
function tickSpacing() external view returns (int24);
/// @notice The maximum amount of position liquidity that can use any tick in the range
/// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
/// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
/// @return The max amount of liquidity per tick
function maxLiquidityPerTick() external view returns (uint128);
}
@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
/// @notice Set the denominator of the protocol's % share of the fees
/// @param feeProtocol0 new protocol fee for token0 of the pool
/// @param feeProtocol1 new protocol fee for token1 of the pool
function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;
/// @notice Collect the protocol fee accrued to the pool
/// @param recipient The address to which collected protocol fees should be sent
/// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
/// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
/// @return amount0 The protocol fee collected in token0
/// @return amount1 The protocol fee collected in token1
function collectProtocol(
address recipient,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
}
@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
/// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
/// when accessed externally.
/// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
/// @return tick The current tick of the pool, i.e. according to the last tick transition that was run.
/// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
/// boundary.
/// @return observationIndex The index of the last oracle observation that was written,
/// @return observationCardinality The current maximum number of observations stored in the pool,
/// @return observationCardinalityNext The next maximum number of observations, to be updated when the observation.
/// @return feeProtocol The protocol fee for both tokens of the pool.
/// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
/// 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.
/// unlocked Whether the pool is currently locked to reentrancy
function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint8 feeProtocol,
bool unlocked
);
/// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal0X128() external view returns (uint256);
/// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal1X128() external view returns (uint256);
/// @notice The amounts of token0 and token1 that are owed to the protocol
/// @dev Protocol fees will never exceed uint128 max in either token
function protocolFees() external view returns (uint128 token0, uint128 token1);
/// @notice The currently in range liquidity available to the pool
/// @dev This value has no relationship to the total liquidity across all ticks
/// @return The liquidity at the current price of the pool
function liquidity() external view returns (uint128);
/// @notice Look up information about a specific tick in the pool
/// @param tick The tick to look up
/// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
/// tick upper
/// @return liquidityNet how much liquidity changes when the pool price crosses the tick,
/// @return feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
/// @return feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
/// @return tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
/// @return secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
/// @return secondsOutside the seconds spent on the other side of the tick from the current tick,
/// @return initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
/// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
/// In addition, these values are only relative and must be used only in comparison to previous snapshots for
/// a specific position.
function ticks(int24 tick)
external
view
returns (
uint128 liquidityGross,
int128 liquidityNet,
uint256 feeGrowthOutside0X128,
uint256 feeGrowthOutside1X128,
int56 tickCumulativeOutside,
uint160 secondsPerLiquidityOutsideX128,
uint32 secondsOutside,
bool initialized
);
/// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
function tickBitmap(int16 wordPosition) external view returns (uint256);
/// @notice Returns the information about a position by the position's key
/// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
/// @return liquidity The amount of liquidity in the position,
/// @return feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
/// @return feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
/// @return tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
/// @return tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
function positions(bytes32 key)
external
view
returns (
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
/// @notice Returns data about a specific observation index
/// @param index The element of the observations array to fetch
/// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
/// ago, rather than at a specific index in the array.
/// @return blockTimestamp The timestamp of the observation,
/// @return tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
/// @return secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
/// @return initialized whether the observation has been initialized and the values are safe to use
function observations(uint256 index)
external
view
returns (
uint32 blockTimestamp,
int56 tickCumulative,
uint160 secondsPerLiquidityCumulativeX128,
bool initialized
);
}
@uniswap/v3-core/contracts/libraries/FixedPoint96.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.4.0;
/// @title FixedPoint96
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
/// @dev Used in SqrtPriceMath.sol
library FixedPoint96 {
uint8 internal constant RESOLUTION = 96;
uint256 internal constant Q96 = 0x1000000000000000000000000;
}
@uniswap/v3-core/contracts/libraries/FullMath.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
/// @notice Calculates floor(aĂ—bĂ·denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
/// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
function mulDiv(
uint256 a,
uint256 b,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = a * b
// Compute the product mod 2**256 and mod 2**256 - 1
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2**256 + prod0
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(a, b, not(0))
prod0 := mul(a, b)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division
if (prod1 == 0) {
require(denominator > 0);
assembly {
result := div(prod0, denominator)
}
return result;
}
// Make sure the result is less than 2**256.
// Also prevents denominator == 0
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0]
// Compute remainder using mulmod
uint256 remainder;
assembly {
remainder := mulmod(a, b, denominator)
}
// Subtract 256 bit number from 512 bit number
assembly {
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator
// Compute largest power of two divisor of denominator.
// Always >= 1.
uint256 twos = (0 - denominator) & denominator;
// Divide denominator by power of two
assembly {
denominator := div(denominator, twos)
}
// Divide [prod1 prod0] by the factors of two
assembly {
prod0 := div(prod0, twos)
}
// Shift in bits from prod1 into prod0. For this we need
// to flip `twos` such that it is 2**256 / twos.
// If twos is zero, then it becomes one
assembly {
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
// Invert denominator mod 2**256
// Now that denominator is an odd number, it has an inverse
// modulo 2**256 such that denominator * inv = 1 mod 2**256.
// Compute the inverse by starting with a seed that is correct
// correct for four bits. That is, denominator * inv = 1 mod 2**4
uint256 inv = (3 * denominator) ^ 2;
// Now use Newton-Raphson iteration to improve the precision.
// Thanks to Hensel's lifting lemma, this also works in modular
// arithmetic, doubling the correct bits in each step.
inv *= 2 - denominator * inv; // inverse mod 2**8
inv *= 2 - denominator * inv; // inverse mod 2**16
inv *= 2 - denominator * inv; // inverse mod 2**32
inv *= 2 - denominator * inv; // inverse mod 2**64
inv *= 2 - denominator * inv; // inverse mod 2**128
inv *= 2 - denominator * inv; // inverse mod 2**256
// Because the division is now exact we can divide by multiplying
// with the modular inverse of denominator. This will give us the
// correct result modulo 2**256. Since the precoditions guarantee
// that the outcome is less than 2**256, this is the final result.
// We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inv;
return result;
}
}
/// @notice Calculates ceil(aĂ—bĂ·denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
function mulDivRoundingUp(
uint256 a,
uint256 b,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
result = mulDiv(a, b, denominator);
if (mulmod(a, b, denominator) > 0) {
require(result < type(uint256).max);
result++;
}
}
}
}
@uniswap/v3-core/contracts/libraries/TickMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
error T();
error R();
/// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
int24 internal constant MIN_TICK = -887272;
/// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
int24 internal constant MAX_TICK = -MIN_TICK;
/// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
uint160 internal constant MIN_SQRT_RATIO = 4295128739;
/// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;
/// @notice Calculates sqrt(1.0001^tick) * 2^96
/// @dev Throws if |tick| > max tick
/// @param tick The input tick for the above formula
/// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
/// at the given tick
function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
unchecked {
uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
if (absTick > uint256(int256(MAX_TICK))) revert T();
uint256 ratio = absTick & 0x1 != 0
? 0xfffcb933bd6fad37aa2d162d1a594001
: 0x100000000000000000000000000000000;
if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;
if (tick > 0) ratio = type(uint256).max / ratio;
// this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
// we then downcast because we know the result always fits within 160 bits due to our tick input constraint
// we round up in the division so getTickAtSqrtRatio of the output price is always consistent
sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
}
}
/// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
/// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
/// ever return.
/// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
/// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
unchecked {
// second inequality must be < because the price can never reach the price at the max tick
if (!(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO)) revert R();
uint256 ratio = uint256(sqrtPriceX96) << 32;
uint256 r = ratio;
uint256 msb = 0;
assembly {
let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(5, gt(r, 0xFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(4, gt(r, 0xFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(3, gt(r, 0xFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(2, gt(r, 0xF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(1, gt(r, 0x3))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := gt(r, 0x1)
msb := or(msb, f)
}
if (msb >= 128) r = ratio >> (msb - 127);
else r = ratio << (127 - msb);
int256 log_2 = (int256(msb) - 128) << 64;
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(63, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(62, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(61, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(60, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(59, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(58, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(57, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(56, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(55, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(54, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(53, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(52, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(51, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(50, f))
}
int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number
int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);
tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
}
}
}
@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import '@uniswap/v3-core/contracts/libraries/FullMath.sol';
import '@uniswap/v3-core/contracts/libraries/FixedPoint96.sol';
/// @title Liquidity amount functions
/// @notice Provides functions for computing liquidity amounts from token amounts and prices
library LiquidityAmounts {
/// @notice Downcasts uint256 to uint128
/// @param x The uint258 to be downcasted
/// @return y The passed value, downcasted to uint128
function toUint128(uint256 x) private pure returns (uint128 y) {
require((y = uint128(x)) == x);
}
/// @notice Computes the amount of liquidity received for a given amount of token0 and price range
/// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount0 The amount0 being sent in
/// @return liquidity The amount of returned liquidity
function getLiquidityForAmount0(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint256 amount0
) internal pure returns (uint128 liquidity) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96);
unchecked {
return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96));
}
}
/// @notice Computes the amount of liquidity received for a given amount of token1 and price range
/// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)).
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount1 The amount1 being sent in
/// @return liquidity The amount of returned liquidity
function getLiquidityForAmount1(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint256 amount1
) internal pure returns (uint128 liquidity) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
unchecked {
return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96));
}
}
/// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current
/// pool prices and the prices at the tick boundaries
/// @param sqrtRatioX96 A sqrt price representing the current pool prices
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount0 The amount of token0 being sent in
/// @param amount1 The amount of token1 being sent in
/// @return liquidity The maximum amount of liquidity received
function getLiquidityForAmounts(
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint256 amount0,
uint256 amount1
) internal pure returns (uint128 liquidity) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
if (sqrtRatioX96 <= sqrtRatioAX96) {
liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);
} else if (sqrtRatioX96 < sqrtRatioBX96) {
uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);
uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);
liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;
} else {
liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1);
}
}
/// @notice Computes the amount of token0 for a given amount of liquidity and a price range
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param liquidity The liquidity being valued
/// @return amount0 The amount of token0
function getAmount0ForLiquidity(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) internal pure returns (uint256 amount0) {
unchecked {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
return
FullMath.mulDiv(
uint256(liquidity) << FixedPoint96.RESOLUTION,
sqrtRatioBX96 - sqrtRatioAX96,
sqrtRatioBX96
) / sqrtRatioAX96;
}
}
/// @notice Computes the amount of token1 for a given amount of liquidity and a price range
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param liquidity The liquidity being valued
/// @return amount1 The amount of token1
function getAmount1ForLiquidity(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) internal pure returns (uint256 amount1) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
unchecked {
return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);
}
}
/// @notice Computes the token0 and token1 value for a given amount of liquidity, the current
/// pool prices and the prices at the tick boundaries
/// @param sqrtRatioX96 A sqrt price representing the current pool prices
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param liquidity The liquidity being valued
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function getAmountsForLiquidity(
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) internal pure returns (uint256 amount0, uint256 amount1) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
if (sqrtRatioX96 <= sqrtRatioAX96) {
amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
} else if (sqrtRatioX96 < sqrtRatioBX96) {
amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity);
amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity);
} else {
amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
}
}
}
@uniswap/v3-periphery/contracts/libraries/OracleLibrary.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0 <0.9.0;
import '@uniswap/v3-core/contracts/libraries/FullMath.sol';
import '@uniswap/v3-core/contracts/libraries/TickMath.sol';
import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol';
/// @title Oracle library
/// @notice Provides functions to integrate with V3 pool oracle
library OracleLibrary {
/// @notice Calculates time-weighted means of tick and liquidity for a given Uniswap V3 pool
/// @param pool Address of the pool that we want to observe
/// @param secondsAgo Number of seconds in the past from which to calculate the time-weighted means
/// @return arithmeticMeanTick The arithmetic mean tick from (block.timestamp - secondsAgo) to block.timestamp
/// @return harmonicMeanLiquidity The harmonic mean liquidity from (block.timestamp - secondsAgo) to block.timestamp
function consult(address pool, uint32 secondsAgo)
internal
view
returns (int24 arithmeticMeanTick, uint128 harmonicMeanLiquidity)
{
require(secondsAgo != 0, 'BP');
uint32[] memory secondsAgos = new uint32[](2);
secondsAgos[0] = secondsAgo;
secondsAgos[1] = 0;
(int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) = IUniswapV3Pool(pool)
.observe(secondsAgos);
int56 tickCumulativesDelta = tickCumulatives[1] - tickCumulatives[0];
uint160 secondsPerLiquidityCumulativesDelta = secondsPerLiquidityCumulativeX128s[1] -
secondsPerLiquidityCumulativeX128s[0];
arithmeticMeanTick = int24(tickCumulativesDelta / int56(uint56(secondsAgo)));
// Always round to negative infinity
if (tickCumulativesDelta < 0 && (tickCumulativesDelta % int56(uint56(secondsAgo)) != 0)) arithmeticMeanTick--;
// We are multiplying here instead of shifting to ensure that harmonicMeanLiquidity doesn't overflow uint128
uint192 secondsAgoX160 = uint192(secondsAgo) * type(uint160).max;
harmonicMeanLiquidity = uint128(secondsAgoX160 / (uint192(secondsPerLiquidityCumulativesDelta) << 32));
}
/// @notice Given a tick and a token amount, calculates the amount of token received in exchange
/// @param tick Tick value used to calculate the quote
/// @param baseAmount Amount of token to be converted
/// @param baseToken Address of an ERC20 token contract used as the baseAmount denomination
/// @param quoteToken Address of an ERC20 token contract used as the quoteAmount denomination
/// @return quoteAmount Amount of quoteToken received for baseAmount of baseToken
function getQuoteAtTick(
int24 tick,
uint128 baseAmount,
address baseToken,
address quoteToken
) internal pure returns (uint256 quoteAmount) {
uint160 sqrtRatioX96 = TickMath.getSqrtRatioAtTick(tick);
// Calculate quoteAmount with better precision if it doesn't overflow when multiplied by itself
if (sqrtRatioX96 <= type(uint128).max) {
uint256 ratioX192 = uint256(sqrtRatioX96) * sqrtRatioX96;
quoteAmount = baseToken < quoteToken
? FullMath.mulDiv(ratioX192, baseAmount, 1 << 192)
: FullMath.mulDiv(1 << 192, baseAmount, ratioX192);
} else {
uint256 ratioX128 = FullMath.mulDiv(sqrtRatioX96, sqrtRatioX96, 1 << 64);
quoteAmount = baseToken < quoteToken
? FullMath.mulDiv(ratioX128, baseAmount, 1 << 128)
: FullMath.mulDiv(1 << 128, baseAmount, ratioX128);
}
}
/// @notice Given a pool, it returns the number of seconds ago of the oldest stored observation
/// @param pool Address of Uniswap V3 pool that we want to observe
/// @return secondsAgo The number of seconds ago of the oldest observation stored for the pool
function getOldestObservationSecondsAgo(address pool) internal view returns (uint32 secondsAgo) {
(, , uint16 observationIndex, uint16 observationCardinality, , , ) = IUniswapV3Pool(pool).slot0();
require(observationCardinality > 0, 'NI');
(uint32 observationTimestamp, , , bool initialized) = IUniswapV3Pool(pool).observations(
(observationIndex + 1) % observationCardinality
);
// The next index might not be initialized if the cardinality is in the process of increasing
// In this case the oldest observation is always in index 0
if (!initialized) {
(observationTimestamp, , , ) = IUniswapV3Pool(pool).observations(0);
}
unchecked {
secondsAgo = uint32(block.timestamp) - observationTimestamp;
}
}
/// @notice Given a pool, it returns the tick value as of the start of the current block
/// @param pool Address of Uniswap V3 pool
/// @return The tick that the pool was in at the start of the current block
function getBlockStartingTickAndLiquidity(address pool) internal view returns (int24, uint128) {
(, int24 tick, uint16 observationIndex, uint16 observationCardinality, , , ) = IUniswapV3Pool(pool).slot0();
// 2 observations are needed to reliably calculate the block starting tick
require(observationCardinality > 1, 'NEO');
// If the latest observation occurred in the past, then no tick-changing trades have happened in this block
// therefore the tick in `slot0` is the same as at the beginning of the current block.
// We don't need to check if this observation is initialized - it is guaranteed to be.
(
uint32 observationTimestamp,
int56 tickCumulative,
uint160 secondsPerLiquidityCumulativeX128,
) = IUniswapV3Pool(pool).observations(observationIndex);
if (observationTimestamp != uint32(block.timestamp)) {
return (tick, IUniswapV3Pool(pool).liquidity());
}
uint256 prevIndex = (uint256(observationIndex) + observationCardinality - 1) % observationCardinality;
(
uint32 prevObservationTimestamp,
int56 prevTickCumulative,
uint160 prevSecondsPerLiquidityCumulativeX128,
bool prevInitialized
) = IUniswapV3Pool(pool).observations(prevIndex);
require(prevInitialized, 'ONI');
uint32 delta = observationTimestamp - prevObservationTimestamp;
tick = int24((tickCumulative - int56(uint56(prevTickCumulative))) / int56(uint56(delta)));
uint128 liquidity = uint128(
(uint192(delta) * type(uint160).max) /
(uint192(secondsPerLiquidityCumulativeX128 - prevSecondsPerLiquidityCumulativeX128) << 32)
);
return (tick, liquidity);
}
/// @notice Information for calculating a weighted arithmetic mean tick
struct WeightedTickData {
int24 tick;
uint128 weight;
}
/// @notice Given an array of ticks and weights, calculates the weighted arithmetic mean tick
/// @param weightedTickData An array of ticks and weights
/// @return weightedArithmeticMeanTick The weighted arithmetic mean tick
/// @dev Each entry of `weightedTickData` should represents ticks from pools with the same underlying pool tokens. If they do not,
/// extreme care must be taken to ensure that ticks are comparable (including decimal differences).
/// @dev Note that the weighted arithmetic mean tick corresponds to the weighted geometric mean price.
function getWeightedArithmeticMeanTick(WeightedTickData[] memory weightedTickData)
internal
pure
returns (int24 weightedArithmeticMeanTick)
{
// Accumulates the sum of products between each tick and its weight
int256 numerator;
// Accumulates the sum of the weights
uint256 denominator;
// Products fit in 152 bits, so it would take an array of length ~2**104 to overflow this logic
for (uint256 i; i < weightedTickData.length; i++) {
numerator += weightedTickData[i].tick * int256(uint256(weightedTickData[i].weight));
denominator += weightedTickData[i].weight;
}
weightedArithmeticMeanTick = int24(numerator / int256(denominator));
// Always round to negative infinity
if (numerator < 0 && (numerator % int256(denominator) != 0)) weightedArithmeticMeanTick--;
}
/// @notice Returns the "synthetic" tick which represents the price of the first entry in `tokens` in terms of the last
/// @dev Useful for calculating relative prices along routes.
/// @dev There must be one tick for each pairwise set of tokens.
/// @param tokens The token contract addresses
/// @param ticks The ticks, representing the price of each token pair in `tokens`
/// @return syntheticTick The synthetic tick, representing the relative price of the outermost tokens in `tokens`
function getChainedPrice(address[] memory tokens, int24[] memory ticks)
internal
pure
returns (int256 syntheticTick)
{
require(tokens.length - 1 == ticks.length, 'DL');
for (uint256 i = 1; i <= ticks.length; i++) {
// check the tokens for address sort order, then accumulate the
// ticks into the running synthetic tick, ensuring that intermediate tokens "cancel out"
tokens[i - 1] < tokens[i] ? syntheticTick += ticks[i - 1] : syntheticTick -= ticks[i - 1];
}
}
}
contracts/Enumerable.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.10;
/**
* @notice This codes were copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Enumerable.sol, and did some changes.
* @dev This implements an optional extension of defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract Enumerable {
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256) {
require(index < _balances[owner], "Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
function balanceOf(address owner) public view returns (uint256) {
require(owner != address(0), "Enumerable: address zero is not a valid owner");
return _balances[owner];
}
function addToken(address from, uint256 tokenId) internal {
_addTokenToOwnerEnumeration(from, tokenId);
unchecked {
_balances[from] += 1;
}
}
function removeToken(address from, uint256 tokenId) internal {
_removeTokenFromOwnerEnumeration(from, tokenId);
unchecked {
_balances[from] -= 1;
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = _balances[to];
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _balances[from] - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
require(tokenId == _ownedTokens[from][tokenIndex], "Invalid tokenId");
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
}
contracts/Multicall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.10;
pragma abicoder v2;
import './interfaces/IMulticall.sol';
/// @title Multicall
/// @notice Enables calling multiple methods in a single call to the contract
abstract contract Multicall is IMulticall {
/// @inheritdoc IMulticall
function multicall(bytes[] calldata data) public payable override returns (bytes[] memory results) {
results = new bytes[](data.length);
for (uint256 i = 0; i < data.length; i++) {
(bool success, bytes memory result) = address(this).delegatecall(data[i]);
if (!success) {
// Next 5 lines from https://ethereum.stackexchange.com/a/83577
if (result.length < 68) revert();
assembly {
result := add(result, 0x04)
}
revert(abi.decode(result, (string)));
}
results[i] = result;
}
}
}
contracts/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "./utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
contracts/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
contracts/extensions/draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
contracts/interfaces/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
contracts/interfaces/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(
address owner,
address spender
) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
contracts/interfaces/IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
contracts/interfaces/IMulticall.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.10;
pragma abicoder v2;
/// @title Multicall interface
/// @notice Enables calling multiple methods in a single call to the contract
interface IMulticall {
/// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
/// @dev The `msg.value` should not be trusted for any method callable from multicall.
/// @param data The encoded function data for each of the calls to make to this contract
/// @return results The results from each of the calls passed in via data
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}
contracts/interfaces/INonfungiblePositionManager.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.10;
import "./IERC721.sol";
import "./INonfungiblePositionManagerStruct.sol";
interface INonfungiblePositionManager is INonfungiblePositionManagerStruct, IERC721 {
/// @notice Returns the position information associated with a given token ID.
/// @dev Throws if the token ID is not valid.
/// @param tokenId The ID of the token that represents the position
/// @return nonce The nonce for permits
/// @return operator The address that is approved for spending
/// @return token0 The address of the token0 for a specific pool
/// @return token1 The address of the token1 for a specific pool
/// @return fee The fee associated with the pool
/// @return tickLower The lower end of the tick range for the position
/// @return tickUpper The higher end of the tick range for the position
/// @return liquidity The liquidity of the position
/// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
/// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
/// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
/// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
function positions(
uint256 tokenId
)
external
view
returns (
uint96 nonce,
address operator,
address token0,
address token1,
uint24 fee,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
/// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
/// @param params tokenId The ID of the token for which liquidity is being increased,
/// amount0Desired The desired amount of token0 to be spent,
/// amount1Desired The desired amount of token1 to be spent,
/// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
/// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
/// deadline The time by which the transaction must be included to effect the change
/// @return liquidity The new liquidity amount as a result of the increase
/// @return amount0 The amount of token0 to acheive resulting liquidity
/// @return amount1 The amount of token1 to acheive resulting liquidity
function increaseLiquidity(
IncreaseLiquidityParams calldata params
) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1);
/// @notice Decreases the amount of liquidity in a position and accounts it to the position
/// @param params tokenId The ID of the token for which liquidity is being decreased,
/// amount The amount by which liquidity will be decreased,
/// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
/// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
/// deadline The time by which the transaction must be included to effect the change
/// @return amount0 The amount of token0 accounted to the position's tokens owed
/// @return amount1 The amount of token1 accounted to the position's tokens owed
function decreaseLiquidity(
DecreaseLiquidityParams calldata params
) external payable returns (uint256 amount0, uint256 amount1);
/// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
/// @param params tokenId The ID of the NFT for which tokens are being collected,
/// recipient The account that should receive the tokens,
/// amount0Max The maximum amount of token0 to collect,
/// amount1Max The maximum amount of token1 to collect
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);
/// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
/// must be collected first.
/// @param tokenId The ID of the token that is being burned
function burn(uint256 tokenId) external payable;
function refundETH() external payable;
}
contracts/interfaces/INonfungiblePositionManagerStruct.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.10;
interface INonfungiblePositionManagerStruct {
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
}
contracts/interfaces/IPoolV3.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.10;
interface IPoolV3 {
function token0() external view returns (address);
function token1() external view returns (address);
function fee() external view returns (uint24);
function liquidity() external view returns (uint128);
function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint32 feeProtocol,
bool unlocked
);
}
contracts/libraries/PriceOracle.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import "../interfaces/IPoolV3.sol";
import "@uniswap/v3-periphery/contracts/libraries/OracleLibrary.sol";
import "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import "@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol";
import "../interfaces/IERC20.sol";
/**
* @title PriceOracle
* @dev Library for handling price calculations for V3 positions
*/
library PriceOracle {
struct PositionData {
uint128 liquidity;
int24 tickLower;
int24 tickUpper;
address token0;
address token1;
address poolAddress;
}
/**
* @notice Get the current ETH price in DAI
* @param ethDaiPool Address of the ETH/DAI pool
* @return price The current price of 1 ETH in DAI (with 18 decimals)
*/
function getEthPriceInUSD(
address ethDaiPool
) internal view returns (uint256 price) {
IPoolV3 pool = IPoolV3(ethDaiPool);
int24 tick;
// Get the current tick from the pool
(, tick, , , , , ) = pool.slot0();
// Get the quote for 1 ETH (10^18 wei) in terms of DAI
// ETH is token0, DAI is token1 in this pool
uint256 amountIn = 1 ether;
price = OracleLibrary.getQuoteAtTick(
tick,
uint128(amountIn),
pool.token0(),
pool.token1()
);
return price;
}
/**
* @notice Get token price in USD based on ETH price and token pool
* @param tokenAddress The address of the token to price
* @param tokenPoolAddress The Uniswap V3 pool address for the token/ETH pair
* @param ethDaiPool The ETH/DAI pool address
* @return price The price of 1 token in USD (scaled to 18 decimals)
*/
function getTokenPriceInUSD(
address tokenAddress,
address tokenPoolAddress,
address ethDaiPool
) internal view returns (uint256 price) {
// 1. Get ETH price in USD (DAI)
uint256 ethPriceInUSD = getEthPriceInUSD(ethDaiPool);
// 2. Get token pool info
IPoolV3 tokenPool = IPoolV3(tokenPoolAddress);
address token0 = tokenPool.token0();
address token1 = tokenPool.token1();
uint8 tokenDecimals = IERC20(tokenAddress).decimals();
// 3. Determine token position in pool and get price
(, int24 tick, , , , , ) = tokenPool.slot0();
uint256 amountIn = 10 ** tokenDecimals; // 1 whole token
if (tokenAddress == token0) {
// Token is token0, calculate token -> ETH price
uint256 tokenPriceInETH = OracleLibrary.getQuoteAtTick(
tick,
uint128(amountIn),
token0, // token
token1 // ETH
);
price = (tokenPriceInETH * ethPriceInUSD) / 1e18;
} else if (tokenAddress == token1) {
// Token is token1, calculate ETH -> token price and invert
uint256 ethPerToken = OracleLibrary.getQuoteAtTick(
tick,
uint128(amountIn),
token1, // token
token0 // ETH
);
price = (1e36 * ethPriceInUSD) / (ethPerToken * 1e18);
} else {
revert("Invalid token for pool");
}
return price;
}
/**
* @notice Calculate the total USD value of a position
* @param position The position data
* @param ethDaiPool The ETH/DAI pool address
* @return usdValue The total USD value of the position (18 decimals)
*/
function getPositionValueInUSD(
PositionData memory position,
address ethDaiPool
) internal view returns (uint256 usdValue) {
// 1. Get ETH price in USD
uint256 ethPriceInUSD = PriceOracle.getEthPriceInUSD(ethDaiPool);
// 2. Get token amounts in position
(uint256 amount0, uint256 amount1) = LiquidityAmounts
.getAmountsForLiquidity(
PriceOracle.getSqrtRatioX96(position.poolAddress),
TickMath.getSqrtRatioAtTick(position.tickLower),
TickMath.getSqrtRatioAtTick(position.tickUpper),
position.liquidity
);
// 3. Calculate token prices in USD
uint256 token0PriceInUSD;
uint256 token1PriceInUSD;
// Get reference token from ETH/DAI pool for comparison
// address ethToken = IPoolV3(ethDaiPool).token0();
address ethToken = 0x70499adEBB11Efd915E3b69E700c331778628707; // WPLS
// If token0 is ETH
if (position.token0 == ethToken) {
token0PriceInUSD = ethPriceInUSD;
token1PriceInUSD = PriceOracle.getTokenPriceInUSD(
position.token1,
position.poolAddress,
ethDaiPool
);
}
// If token1 is ETH
else if (position.token1 == ethToken) {
token0PriceInUSD = PriceOracle.getTokenPriceInUSD(
position.token0,
position.poolAddress,
ethDaiPool
);
token1PriceInUSD = ethPriceInUSD;
}
// If neither token is ETH
else {
token0PriceInUSD = PriceOracle.getTokenPriceInUSD(
position.token0,
position.poolAddress,
ethDaiPool
);
token1PriceInUSD = PriceOracle.getTokenPriceInUSD(
position.token1,
position.poolAddress,
ethDaiPool
);
}
// 4. Calculate total USD value (adjusting for token decimals)
usdValue =
((amount0 * token0PriceInUSD) /
(10 ** IERC20(position.token0).decimals())) +
((amount1 * token1PriceInUSD) /
(10 ** IERC20(position.token1).decimals()));
return usdValue;
}
/**
* @notice Get the sqrt ratio from pool
* @param pool Address of the pool
* @return sqrtPriceX96 The pool's current sqrt price
*/
function getSqrtRatioX96(
address pool
) internal view returns (uint160 sqrtPriceX96) {
(sqrtPriceX96, , , , , , ) = IPoolV3(pool).slot0();
return sqrtPriceX96;
}
}
contracts/utils/Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
contracts/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../interfaces/IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "./Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
Compiler Settings
{"outputSelection":{"*":{"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","metadata"],"":["ast"]}},"optimizer":{"runs":10,"enabled":true},"libraries":{},"evmVersion":"paris"}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_nonfungiblePositionManager","internalType":"address"},{"type":"address","name":"_wplsDaiPool","internalType":"address"}]},{"type":"error","name":"DuplicatedPool","inputs":[{"type":"uint256","name":"pid","internalType":"uint256"}]},{"type":"error","name":"InvalidNFT","inputs":[]},{"type":"error","name":"InvalidPool","inputs":[]},{"type":"error","name":"NoLiquidity","inputs":[]},{"type":"error","name":"NoRewardsAvailable","inputs":[]},{"type":"error","name":"NotPDexNFT","inputs":[]},{"type":"error","name":"NotPositionOwner","inputs":[]},{"type":"error","name":"T","inputs":[]},{"type":"event","name":"AddPool","inputs":[{"type":"uint256","name":"pid","internalType":"uint256","indexed":true},{"type":"address","name":"v3Pool","internalType":"contract IPoolV3","indexed":true}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"PointsThresholdUpdated","inputs":[{"type":"uint256","name":"oldThreshold","internalType":"uint256","indexed":false},{"type":"uint256","name":"newThreshold","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"PointsUpdated","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true},{"type":"uint256","name":"newPoints","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"PositionDeposited","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true},{"type":"address","name":"poolAddress","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"PositionWithdrawn","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"tokenId","internalType":"uint256","indexed":true},{"type":"address","name":"poolAddress","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"WPLS_DAI_POOL","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"add","inputs":[{"type":"address","name":"poolAddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOf","inputs":[{"type":"address","name":"owner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"deposit","inputs":[{"type":"uint256","name":"_tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"price","internalType":"uint256"}],"name":"getEthPriceInUSD","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"usdValue","internalType":"uint256"}],"name":"getPositionValueInUSD","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"price","internalType":"uint256"}],"name":"getTokenPriceInUSD","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"address","name":"poolAddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"","internalType":"struct PointsFarming.UserPositionInfo[]","components":[{"type":"uint128","name":"liquidity","internalType":"uint128"},{"type":"int24","name":"tickLower","internalType":"int24"},{"type":"int24","name":"tickUpper","internalType":"int24"},{"type":"address","name":"user","internalType":"address"},{"type":"uint256","name":"pid","internalType":"uint256"},{"type":"address","name":"poolAddress","internalType":"address"},{"type":"uint256","name":"points","internalType":"uint256"},{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"lastUpdateBlock","internalType":"uint256"}]}],"name":"getUserPositions","inputs":[{"type":"address","name":"user","internalType":"address"},{"type":"uint256","name":"offset","internalType":"uint256"},{"type":"uint256","name":"limit","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256[]","name":"tokenIds","internalType":"uint256[]"}],"name":"getUserTokens","inputs":[{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"totalPoints","internalType":"uint256"}],"name":"getUserTotalPoints","inputs":[{"type":"address","name":"user","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[{"type":"bytes[]","name":"results","internalType":"bytes[]"}],"name":"multicall","inputs":[{"type":"bytes[]","name":"data","internalType":"bytes[]"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract INonfungiblePositionManager"}],"name":"nonfungiblePositionManager","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bytes4","name":"","internalType":"bytes4"}],"name":"onERC721Received","inputs":[{"type":"address","name":"","internalType":"address"},{"type":"address","name":"_from","internalType":"address"},{"type":"uint256","name":"_tokenId","internalType":"uint256"},{"type":"bytes","name":"","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"points","internalType":"uint256"}],"name":"pendingPoints","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"pointsThreshold","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"v3Pool","internalType":"contract IPoolV3"},{"type":"address","name":"token0","internalType":"address"},{"type":"address","name":"token1","internalType":"address"},{"type":"uint24","name":"fee","internalType":"uint24"}],"name":"poolInfo","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"poolLength","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"recoverERC721","inputs":[{"type":"uint256","name":"_tokenId","internalType":"uint256"},{"type":"address","name":"_to","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setPointsThreshold","inputs":[{"type":"uint256","name":"_newThreshold","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"tokenOfOwnerByIndex","inputs":[{"type":"address","name":"owner","internalType":"address"},{"type":"uint256","name":"index","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint128","name":"liquidity","internalType":"uint128"},{"type":"int24","name":"tickLower","internalType":"int24"},{"type":"int24","name":"tickUpper","internalType":"int24"},{"type":"address","name":"user","internalType":"address"},{"type":"uint256","name":"pid","internalType":"uint256"},{"type":"address","name":"poolAddress","internalType":"address"},{"type":"uint256","name":"points","internalType":"uint256"},{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"lastUpdateBlock","internalType":"uint256"}],"name":"userPositionInfos","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"v3PoolAddressPid","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdraw","inputs":[{"type":"uint256","name":"_tokenId","internalType":"uint256"}]}]
Contract Creation Code
0x60c0604052678ac7230489e800006005553480156200001d57600080fd5b50604051620039cc380380620039cc833981016040819052620000409162000188565b6200004b336200011b565b600180556001600160a01b038216620000ab5760405162461bcd60e51b815260206004820152601b60248201527f496e76616c6964204e4654204d616e616765722061646472657373000000000060448201526064015b60405180910390fd5b6001600160a01b038116620001035760405162461bcd60e51b815260206004820152601d60248201527f496e76616c69642057504c532f44414920706f6f6c20616464726573730000006044820152606401620000a2565b6001600160a01b0391821660a05216608052620001c0565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80516001600160a01b03811681146200018357600080fd5b919050565b600080604083850312156200019c57600080fd5b620001a7836200016b565b9150620001b7602084016200016b565b90509250929050565b60805160a0516137a06200022c600039600081816105480152818161097b015281816109c401528181610dca015281816112c60152818161174801528181611a210152611aa0015260008181610445015281816109380152818161113301526111fd01526137a06000f3fe6080604052600436106101315760003560e01c80630743384d14610136578063081e3eda146101765780630a3b0a4f1461018c57806313df14a7146101ae578063150b7a02146101ce5780631526fe27146102075780632e1a7d4d146102935780632f745c59146102b35780633b1acf74146102d3578063519dc8d2146103b157806363304b2f146103de57806370a08231146103fe578063715018a61461041e57806374a85ceb14610433578063787beb341461047f5780638da5cb5b1461049457806391384715146104a957806393324cc0146104c9578063945f0c2f146104f6578063ac9650d814610516578063b44a272214610536578063b6b55f251461056a578063da2e9dcf1461058a578063def9c5d6146105aa578063f2fde38b146105ca578063fa4ffb63146105ea575b600080fd5b34801561014257600080fd5b50610163610151366004612dc7565b600a6020526000908152604090205481565b6040519081526020015b60405180910390f35b34801561018257600080fd5b5061016360065481565b34801561019857600080fd5b506101ac6101a7366004612dc7565b610600565b005b3480156101ba57600080fd5b506101636101c9366004612de4565b61092e565b3480156101da57600080fd5b506101ee6101e9366004612e1d565b610966565b6040516001600160e01b0319909116815260200161016d565b34801561021357600080fd5b5061025e610222366004612ebb565b6008602052600090815260409020805460018201546002909201546001600160a01b0391821692821691811690600160a01b900462ffffff1684565b604080516001600160a01b0395861681529385166020850152919093169082015262ffffff909116606082015260800161016d565b34801561029f57600080fd5b506101ac6102ae366004612ebb565b610d41565b3480156102bf57600080fd5b506101636102ce366004612ee1565b610e90565b3480156102df57600080fd5b506103516102ee366004612ebb565b6007602052600090815260409020805460018201546002808401546003850154600486015460058701546006909701546001600160801b03871697600160801b8804860b97600160981b900490950b956001600160a01b03908116959316929089565b604080516001600160801b03909a168a52600298890b60208b01529690970b958801959095526001600160a01b03938416606088015260808701929092529190911660a085015260c084015260e08301526101008201526101200161016d565b3480156103bd57600080fd5b506103d16103cc366004612dc7565b610f2e565b60405161016d9190612f0d565b3480156103ea57600080fd5b506101636103f9366004612ebb565b610fcc565b34801561040a57600080fd5b50610163610419366004612dc7565b611157565b34801561042a57600080fd5b506101ac6111e1565b34801561043f57600080fd5b506104677f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161016d565b34801561048b57600080fd5b506101636111f5565b3480156104a057600080fd5b50610467611221565b3480156104b557600080fd5b506101ac6104c4366004612f51565b611230565b3480156104d557600080fd5b506104e96104e4366004612f76565b611336565b60405161016d9190612fab565b34801561050257600080fd5b506101ac610511366004612ebb565b611542565b61052961052436600461306e565b6115da565b60405161016d9190613132565b34801561054257600080fd5b506104677f000000000000000000000000000000000000000000000000000000000000000081565b34801561057657600080fd5b506101ac610585366004612ebb565b611731565b34801561059657600080fd5b506101636105a5366004612ebb565b6117b6565b3480156105b657600080fd5b506101636105c5366004612dc7565b61189c565b3480156105d657600080fd5b506101ac6105e5366004612dc7565b611926565b3480156105f657600080fd5b5061016360055481565b61060861199c565b6001600160a01b0381166106515760405162461bcd60e51b815260206004820152600b60248201526a125b9d985b1a59141bdbdb60aa1b60448201526064015b60405180910390fd5b60008190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610696573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ba91906131a4565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106fc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072091906131a4565b90506000836001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015610762573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078691906131d4565b6001600160a01b038085166000908152600960209081526040808320938716835292815282822062ffffff851683529052205490915015610812576001600160a01b038381166000908152600960209081526040808320938616835292815282822062ffffff851683529052819020549051637d38f65f60e01b81526004810191909152602401610648565b61081b836119fb565b610824826119fb565b600680546001908101808355604080516080810182526001600160a01b03808a1680835289821660208085018281528b851686880181815262ffffff808e1660608a0181815260009c8d52600887528b8d209a518b54908b166001600160a01b0319918216178c5595519d8b0180549e8b169e9096169d909d179094559051600290980180549b51909116600160a01b026001600160b81b0319909b16979096169690961798909817909355965496855260098252838520928552918152828420948452938452818320859055808352600a909352808220849055519192917fdc467816be4ae0fb24482b03c7fcaebabc217fa013c4d51e500dc79c5ad5e2ba9190a35050505050565b60008061095c84847f0000000000000000000000000000000000000000000000000000000000000000611ac7565b9150505b92915050565b6000610970611d79565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146109b95760405163b302ad3760e01b815260040160405180910390fd5b6000806000806000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166399fbab888b6040518263ffffffff1660e01b8152600401610a1091815260200190565b61018060405180830381865afa158015610a2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a529190613218565b505050509750975097509750975097505050806001600160801b0316600003610a8e57604051636180f03f60e11b815260040160405180910390fd5b6001600160a01b038087166000908152600960209081526040808320938916835292815282822062ffffff8816835290529081205490819003610ae45760405163079f151f60e11b815260040160405180910390fd5b60008b815260076020526040902060018101546001600160a01b0316610c1a578c8160010160006101000a8154816001600160a01b0302191690836001600160a01b031602179055508181600201819055506008600083815260200190815260200160002060000160009054906101000a90046001600160a01b03168160030160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060008160040181905550828160000160006101000a8154816001600160801b0302191690836001600160801b03160217905550848160000160106101000a81548162ffffff021916908360020b62ffffff160217905550838160000160136101000a81548162ffffff021916908360020b62ffffff1602179055504381600601819055508b8160050181905550610c60565b805462ffffff858116600160981b0262ffffff60981b19918816600160801b026001600160981b03199093166001600160801b0387161792909217161781554360068201555b610cb38d8d6001600160a01b039190911660008181526002602081815260408084208054600384528286208187528452828620889055968552600483529084209590955592909152905280546001019055565b6008600083815260200190815260200160002060000160009054906101000a90046001600160a01b03166001600160a01b03168c8e6001600160a01b03167f520940434c792159e5211d2c1211a4bccd932a1c1fbf8a453190c9a8e957d71d60405160405180910390a450630a85bd0160e11b975050505050505050610d3860018055565b95945050505050565b610d49611d79565b6000818152600760205260409020600101546001600160a01b0316338114610d84576040516370d645e360e01b815260040160405180910390fd5b610d8d82611dd2565b60008281526007602090815260408083206002810154808552600890935292819020549051632142170760e11b81526001600160a01b03918216917f000000000000000000000000000000000000000000000000000000000000000016906342842e0e90610e0390309088908a906004016132f4565b600060405180830381600087803b158015610e1d57600080fd5b505af1158015610e31573d6000803e3d6000fd5b50505050610e3f8486611e75565b806001600160a01b031685856001600160a01b03167f119d930f8a790cc06b4421b32d0bf3093c05fc6e0dd49435f3e89db43bafaa1160405160405180910390a450505050610e8d60018055565b50565b6001600160a01b0382166000908152600260205260408120548210610f055760405162461bcd60e51b815260206004820152602560248201527f456e756d657261626c653a206f776e657220696e646578206f7574206f6620626044820152646f756e647360d81b6064820152608401610648565b506001600160a01b03919091166000908152600360209081526040808320938352929052205490565b60606000610f3b83611157565b9050806001600160401b03811115610f5557610f55613318565b604051908082528060200260200182016040528015610f7e578160200160208202803683370190505b50915060005b81811015610fc557610f968482610e90565b838281518110610fa857610fa861332e565b602090810291909101015280610fbd8161335a565b915050610f84565b5050919050565b600081815260076020908152604080832081516101208101835281546001600160801b0381168252600160801b8104600290810b95830195909552600160981b9004840b9281019290925260018101546001600160a01b039081166060840181905293820154608084015260038201541660a0830152600481015460c0830152600581015460e0830152600601546101008201529061107d5760405162461bcd60e51b815260040161064890613373565b6080818101516000908152600860209081526040918290208251808501845281546001600160a01b03908116825260018301548116828501908152600293840154808316848801908152600160a01b90910462ffffff16606080860191909152875160c0810189528a516001600160801b03168152878b0151870b97810197909752878a015190950b96860196909652518116928401929092529251811693820193909352815190921660a083015290610d38817f0000000000000000000000000000000000000000000000000000000000000000611ea1565b60006001600160a01b0382166111c55760405162461bcd60e51b815260206004820152602d60248201527f456e756d657261626c653a2061646472657373207a65726f206973206e6f742060448201526c30903b30b634b21037bbb732b960991b6064820152608401610648565b506001600160a01b031660009081526002602052604090205490565b6111e961199c565b6111f360006120c3565b565b6000806109607f0000000000000000000000000000000000000000000000000000000000000000612113565b6000546001600160a01b031690565b61123861199c565b600082815260076020526040902060018101546001600160a01b0316156112af57600083815260076020526040812080546001600160b01b03191681556001810180546001600160a01b03199081169091556002820183905560038201805490911690556004810182905560058101829055600601555b604051632142170760e11b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906342842e0e906112ff903090869088906004016132f4565b600060405180830381600087803b15801561131957600080fd5b505af115801561132d573d6000803e3d6000fd5b50505050505050565b6060600061134385610f2e565b80519091508381861061138c576040805160008082526020820190925290611381565b61136e612d66565b8152602001906001900390816113665790505b50935050505061153b565b8161139786886133a4565b11156113aa576113a786836133b7565b90505b6000816001600160401b038111156113c4576113c4613318565b6040519080825280602002602001820160405280156113fd57816020015b6113ea612d66565b8152602001906001900390816113e25790505b50905060005b828110156115345760006007818761141b858d6133a4565b8151811061142b5761142b61332e565b602090810291909101810151825281810192909252604090810160002081516101208101835281546001600160801b0381168252600160801b8104600290810b95830195909552600160981b9004840b9281019290925260018101546001600160a01b039081166060840152928101546080830152600381015490921660a0820152600482015460c0820152600582015460e082015260069091015461010082015290506114fa866114dd848c6133a4565b815181106114ed576114ed61332e565b60200260200101516117b6565b60c0820152825181908490849081106115155761151561332e565b602002602001018190525050808061152c9061335a565b915050611403565b5093505050505b9392505050565b61154a61199c565b600081116115955760405162461bcd60e51b81526020600482015260186024820152775468726573686f6c642063616e6e6f74206265207a65726f60401b6044820152606401610648565b600580549082905560408051828152602081018490527f2669b7d90b0477ab6fb6ab93303768fc1bac99619ab67505d74cadb0e3247e09910160405180910390a15050565b6060816001600160401b038111156115f4576115f4613318565b60405190808252806020026020018201604052801561162757816020015b60608152602001906001900390816116125790505b50905060005b8281101561172a576000803086868581811061164b5761164b61332e565b905060200281019061165d91906133ca565b60405161166b929190613417565b600060405180830381855af49150503d80600081146116a6576040519150601f19603f3d011682016040523d82523d6000602084013e6116ab565b606091505b5091509150816116f7576044815110156116c457600080fd5b600481019050808060200190518101906116de9190613427565b60405162461bcd60e51b815260040161064891906134d3565b8084848151811061170a5761170a61332e565b6020026020010181905250505080806117229061335a565b91505061162d565b5092915050565b604051632142170760e11b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906342842e0e90611781903390309086906004016132f4565b600060405180830381600087803b15801561179b57600080fd5b505af11580156117af573d6000803e3d6000fd5b5050505050565b600081815260076020908152604080832081516101208101835281546001600160801b0381168252600160801b8104600290810b95830195909552600160981b9004840b9281019290925260018101546001600160a01b039081166060840181905293820154608084015260038201541660a0830152600481015460c0830152600581015460e083015260060154610100820152906118585750600092915050565b806101000151431161186d5750600092915050565b600061187884610fcc565b905060008261010001514361188d91906133b7565b9050610d388260055483612269565b6000806118a883610f2e565b905060005b8151811015610fc557600760008383815181106118cc576118cc61332e565b6020026020010151815260200190815260200160002060040154836118f191906133a4565b92506119088282815181106114ed576114ed61332e565b61191290846133a4565b92508061191e8161335a565b9150506118ad565b61192e61199c565b6001600160a01b0381166119935760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610648565b610e8d816120c3565b336119a5611221565b6001600160a01b0316146111f35760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610648565b604051636eb1769f60e11b81526001600160a01b0382169063dd62ed3e90611a499030907f0000000000000000000000000000000000000000000000000000000000000000906004016134e6565b602060405180830381865afa158015611a66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a8a9190613500565b600003610e8d57610e8d6001600160a01b0382167f00000000000000000000000000000000000000000000000000000000000000006000196122a0565b600080611ad383612113565b905060008490506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b3e91906131a4565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ba491906131a4565b90506000886001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611be6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c0a9190613519565b90506000846001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015611c4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c70919061355e565b5050505050915050600082600a611c8791906136d5565b9050846001600160a01b03168b6001600160a01b031603611cd7576000611cb0838388886123db565b9050670de0b6b3a7640000611cc589836136e4565b611ccf9190613711565b985050611d6b565b836001600160a01b03168b6001600160a01b031603611d2a576000611cfe838387896123db565b9050611d1281670de0b6b3a76400006136e4565b611cc5896a0c097ce7bc90715b34b9f160241b6136e4565b60405162461bcd60e51b8152602060048201526016602482015275125b9d985b1a59081d1bdad95b88199bdc881c1bdbdb60521b6044820152606401610648565b505050505050509392505050565b600260015403611dcb5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610648565b6002600155565b600081815260076020526040902060018101546001600160a01b0316611e0a5760405162461bcd60e51b815260040161064890613373565b6000611e15836117b6565b905080826004016000828254611e2b91906133a4565b9091555050436006830155600482015460405190815283907f2a4f386dacbb02a5d478d3fc1d2dbc487b69ed735b8d629e99d905680db927eb9060200160405180910390a2505050565b611e7f82826124e4565b506001600160a01b031660009081526002602052604090208054600019019055565b600080611ead83612113565b9050600080611ee3611ec28760a001516125f0565b611ecf8860200151612661565b611edc8960400151612661565b8951612979565b9150915060008060007370499adebb11efd915e3b69e700c3317786287079050806001600160a01b031689606001516001600160a01b031603611f3d57859250611f3689608001518a60a001518a611ac7565b9150611fa2565b806001600160a01b031689608001516001600160a01b031603611f7757611f6d89606001518a60a001518a611ac7565b9250859150611fa2565b611f8a89606001518a60a001518a611ac7565b9250611f9f89608001518a60a001518a611ac7565b91505b88608001516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611fe4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120089190613519565b61201390600a6136d5565b61201d83866136e4565b6120279190613711565b89606001516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612069573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061208d9190613519565b61209890600a6136d5565b6120a285886136e4565b6120ac9190613711565b6120b691906133a4565b9998505050505050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000808290506000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015612159573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061217d919061355e565b505060408051630dfe168160e01b81529051949650670de0b6b3a76400009550610d38948794508693506001600160a01b0389169250630dfe1681916004808201926020929091908290030181865afa1580156121de573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061220291906131a4565b866001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015612240573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061226491906131a4565b6123db565b6000670de0b6b3a7640000818461228083886136e4565b61228a9190613711565b905061229684826136e4565b9695505050505050565b8015806123195750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e906122d690309086906004016134e6565b602060405180830381865afa1580156122f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123179190613500565b155b6123845760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610648565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526123d6908490612a15565b505050565b6000806123e786612661565b90506001600160801b036001600160a01b0382161161246d5760006124156001600160a01b038316806136e4565b9050836001600160a01b0316856001600160a01b03161061244d57612448600160c01b876001600160801b031683612ae7565b612465565b61246581876001600160801b0316600160c01b612ae7565b9250506124db565b60006124876001600160a01b03831680600160401b612ae7565b9050836001600160a01b0316856001600160a01b0316106124bf576124ba600160801b876001600160801b031683612ae7565b6124d7565b6124d781876001600160801b0316600160801b612ae7565b9250505b50949350505050565b6001600160a01b038216600090815260026020526040812054612509906001906133b7565b6000838152600460209081526040808320546001600160a01b0388168452600383528184208185529092529091205491925090831461257c5760405162461bcd60e51b815260206004820152600f60248201526e125b9d985b1a59081d1bdad95b9259608a1b6044820152606401610648565b8181146125bd576001600160a01b03841660009081526003602090815260408083208584528252808320548484528184208190558352600490915290208190555b5060009182526004602090815260408084208490556001600160a01b039094168352600381528383209183525290812055565b6000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015612630573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612654919061355e565b5094979650505050505050565b60008060008360020b12612678578260020b612680565b8260020b6000035b9050620d89e88111156126a6576040516315e4079d60e11b815260040160405180910390fd5b6000816001166000036126bd57600160801b6126cf565b6ffffcb933bd6fad37aa2d162d1a5940015b6001600160881b0316905060028216156126f9576ffff97272373d413259a46990580e213a0260801c5b6004821615612718576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615612737576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b6010821615612756576fffcb9843d60f6159c9db58835c9266440260801c5b6020821615612775576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615612794576fff2ea16466c96a3843ec78b326b528610260801c5b60808216156127b3576ffe5dee046a99a2a811c461f1969c30530260801c5b6101008216156127d3576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b6102008216156127f3576ff987a7253ac413176f2b074cf7815e540260801c5b610400821615612813576ff3392b0822b70005940c7a398e4b70f30260801c5b610800821615612833576fe7159475a2c29b7443b29c7fa6e889d90260801c5b611000821615612853576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615612873576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615612893576f70d869a156d2a1b890bb3df62baf32f70260801c5b6180008216156128b3576f31be135f97d08fd981231505542fcfa60260801c5b620100008216156128d4576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b620200008216156128f4576e5d6af8dedb81196699c329225ee6040260801c5b62040000821615612913576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615612930576b048a170391f7dc42444e8fa20260801c5b60008460020b131561295157806000198161294d5761294d6136fb565b0490505b600160201b810615612964576001612967565b60005b60ff16602082901c0192505050919050565b600080836001600160a01b0316856001600160a01b0316111561299a579293925b846001600160a01b0316866001600160a01b0316116129c5576129be858585612b99565b9150612a0c565b836001600160a01b0316866001600160a01b031610156129fe576129ea868585612b99565b91506129f7858785612c08565b9050612a0c565b612a09858585612c08565b90505b94509492505050565b6000612a6a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612c539092919063ffffffff16565b8051909150156123d65780806020019051810190612a889190613733565b6123d65760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610648565b6000808060001985870985870292508281108382030391505080600003612b205760008411612b1557600080fd5b50829004905061153b565b808411612b2c57600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000826001600160a01b0316846001600160a01b03161115612bb9579192915b836001600160a01b0316612bf2606060ff16846001600160801b0316901b8686036001600160a01b0316866001600160a01b0316612ae7565b81612bff57612bff6136fb565b04949350505050565b6000826001600160a01b0316846001600160a01b03161115612c28579192915b612c4b826001600160801b03168585036001600160a01b0316600160601b612ae7565b949350505050565b6060612c4b848460008585600080866001600160a01b03168587604051612c7a919061374e565b60006040518083038185875af1925050503d8060008114612cb7576040519150601f19603f3d011682016040523d82523d6000602084013e612cbc565b606091505b50915091506124d78783838760608315612d37578251600003612d30576001600160a01b0385163b612d305760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610648565b5081612c4b565b612c4b8383815115612d4c5781518083602001fd5b8060405162461bcd60e51b815260040161064891906134d3565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915290565b6001600160a01b0381168114610e8d57600080fd5b600060208284031215612dd957600080fd5b813561153b81612db2565b60008060408385031215612df757600080fd5b8235612e0281612db2565b91506020830135612e1281612db2565b809150509250929050565b600080600080600060808688031215612e3557600080fd5b8535612e4081612db2565b94506020860135612e5081612db2565b93506040860135925060608601356001600160401b0380821115612e7357600080fd5b818801915088601f830112612e8757600080fd5b813581811115612e9657600080fd5b896020828501011115612ea857600080fd5b9699959850939650602001949392505050565b600060208284031215612ecd57600080fd5b5035919050565b6001600160a01b03169052565b60008060408385031215612ef457600080fd5b8235612eff81612db2565b946020939093013593505050565b6020808252825182820181905260009190848201906040850190845b81811015612f4557835183529284019291840191600101612f29565b50909695505050505050565b60008060408385031215612f6457600080fd5b823591506020830135612e1281612db2565b600080600060608486031215612f8b57600080fd5b8335612f9681612db2565b95602085013595506040909401359392505050565b602080825282518282018190526000919060409081850190868401855b8281101561306157815180516001600160801b031685528681015160020b8786015285810151612ffc8787018260020b9052565b5060608082015161300f82880182612ed4565b50506080818101519086015260a08082015161302d82880182612ed4565b505060c0818101519086015260e0808201519086015261010090810151908501526101209093019290850190600101612fc8565b5091979650505050505050565b6000806020838503121561308157600080fd5b82356001600160401b038082111561309857600080fd5b818501915085601f8301126130ac57600080fd5b8135818111156130bb57600080fd5b8660208260051b85010111156130d057600080fd5b60209290920196919550909350505050565b60005b838110156130fd5781810151838201526020016130e5565b50506000910152565b6000815180845261311e8160208601602086016130e2565b601f01601f19169290920160200192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561318757603f19888603018452613175858351613106565b94509285019290850190600101613159565b5092979650505050505050565b805161319f81612db2565b919050565b6000602082840312156131b657600080fd5b815161153b81612db2565b805162ffffff8116811461319f57600080fd5b6000602082840312156131e657600080fd5b61153b826131c1565b8051600281900b811461319f57600080fd5b80516001600160801b038116811461319f57600080fd5b6000806000806000806000806000806000806101808d8f03121561323b57600080fd5b8c516001600160601b038116811461325257600080fd5b9b5061326060208e01613194565b9a5061326e60408e01613194565b995061327c60608e01613194565b985061328a60808e016131c1565b975061329860a08e016131ef565b96506132a660c08e016131ef565b95506132b460e08e01613201565b94506101008d015193506101208d015192506132d36101408e01613201565b91506132e26101608e01613201565b90509295989b509295989b509295989b565b6001600160a01b039384168152919092166020820152604081019190915260600190565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161336c5761336c613344565b5060010190565b602080825260179082015276141bdcda5d1a5bdb88191bd95cc81b9bdd08195e1a5cdd604a1b604082015260600190565b8082018082111561096057610960613344565b8181038181111561096057610960613344565b6000808335601e198436030181126133e157600080fd5b8301803591506001600160401b038211156133fb57600080fd5b60200191503681900382131561341057600080fd5b9250929050565b8183823760009101908152919050565b60006020828403121561343957600080fd5b81516001600160401b038082111561345057600080fd5b818401915084601f83011261346457600080fd5b81518181111561347657613476613318565b604051601f8201601f19908116603f0116810190838211818310171561349e5761349e613318565b816040528281528760208487010111156134b757600080fd5b6134c88360208301602088016130e2565b979650505050505050565b60208152600061153b6020830184613106565b6001600160a01b0392831681529116602082015260400190565b60006020828403121561351257600080fd5b5051919050565b60006020828403121561352b57600080fd5b815160ff8116811461153b57600080fd5b805161ffff8116811461319f57600080fd5b8051801515811461319f57600080fd5b600080600080600080600060e0888a03121561357957600080fd5b875161358481612db2565b9650613592602089016131ef565b95506135a06040890161353c565b94506135ae6060890161353c565b93506135bc6080890161353c565b925060a088015163ffffffff811681146135d557600080fd5b91506135e360c0890161354e565b905092959891949750929550565b600181815b8085111561362c57816000190482111561361257613612613344565b8085161561361f57918102915b93841c93908002906135f6565b509250929050565b60008261364357506001610960565b8161365057506000610960565b816001811461366657600281146136705761368c565b6001915050610960565b60ff84111561368157613681613344565b50506001821b610960565b5060208310610133831016604e8410600b84101617156136af575081810a610960565b6136b983836135f1565b80600019048211156136cd576136cd613344565b029392505050565b600061153b60ff841683613634565b808202811582820484141761096057610960613344565b634e487b7160e01b600052601260045260246000fd5b60008261372e57634e487b7160e01b600052601260045260246000fd5b500490565b60006020828403121561374557600080fd5b61153b8261354e565b600082516137608184602087016130e2565b919091019291505056fea26469706673582212206e9f4e362448e7b6f48b2bbc6daae317a83c59f8a1ddee8c02a2a1e563910fc564736f6c634300081400330000000000000000000000001d0a515902f69db560eec32ed1dc2154cb882c9800000000000000000000000037b70f2212fb8036ce11f00596386c921ee94713
Deployed ByteCode
0x6080604052600436106101315760003560e01c80630743384d14610136578063081e3eda146101765780630a3b0a4f1461018c57806313df14a7146101ae578063150b7a02146101ce5780631526fe27146102075780632e1a7d4d146102935780632f745c59146102b35780633b1acf74146102d3578063519dc8d2146103b157806363304b2f146103de57806370a08231146103fe578063715018a61461041e57806374a85ceb14610433578063787beb341461047f5780638da5cb5b1461049457806391384715146104a957806393324cc0146104c9578063945f0c2f146104f6578063ac9650d814610516578063b44a272214610536578063b6b55f251461056a578063da2e9dcf1461058a578063def9c5d6146105aa578063f2fde38b146105ca578063fa4ffb63146105ea575b600080fd5b34801561014257600080fd5b50610163610151366004612dc7565b600a6020526000908152604090205481565b6040519081526020015b60405180910390f35b34801561018257600080fd5b5061016360065481565b34801561019857600080fd5b506101ac6101a7366004612dc7565b610600565b005b3480156101ba57600080fd5b506101636101c9366004612de4565b61092e565b3480156101da57600080fd5b506101ee6101e9366004612e1d565b610966565b6040516001600160e01b0319909116815260200161016d565b34801561021357600080fd5b5061025e610222366004612ebb565b6008602052600090815260409020805460018201546002909201546001600160a01b0391821692821691811690600160a01b900462ffffff1684565b604080516001600160a01b0395861681529385166020850152919093169082015262ffffff909116606082015260800161016d565b34801561029f57600080fd5b506101ac6102ae366004612ebb565b610d41565b3480156102bf57600080fd5b506101636102ce366004612ee1565b610e90565b3480156102df57600080fd5b506103516102ee366004612ebb565b6007602052600090815260409020805460018201546002808401546003850154600486015460058701546006909701546001600160801b03871697600160801b8804860b97600160981b900490950b956001600160a01b03908116959316929089565b604080516001600160801b03909a168a52600298890b60208b01529690970b958801959095526001600160a01b03938416606088015260808701929092529190911660a085015260c084015260e08301526101008201526101200161016d565b3480156103bd57600080fd5b506103d16103cc366004612dc7565b610f2e565b60405161016d9190612f0d565b3480156103ea57600080fd5b506101636103f9366004612ebb565b610fcc565b34801561040a57600080fd5b50610163610419366004612dc7565b611157565b34801561042a57600080fd5b506101ac6111e1565b34801561043f57600080fd5b506104677f00000000000000000000000037b70f2212fb8036ce11f00596386c921ee9471381565b6040516001600160a01b03909116815260200161016d565b34801561048b57600080fd5b506101636111f5565b3480156104a057600080fd5b50610467611221565b3480156104b557600080fd5b506101ac6104c4366004612f51565b611230565b3480156104d557600080fd5b506104e96104e4366004612f76565b611336565b60405161016d9190612fab565b34801561050257600080fd5b506101ac610511366004612ebb565b611542565b61052961052436600461306e565b6115da565b60405161016d9190613132565b34801561054257600080fd5b506104677f0000000000000000000000001d0a515902f69db560eec32ed1dc2154cb882c9881565b34801561057657600080fd5b506101ac610585366004612ebb565b611731565b34801561059657600080fd5b506101636105a5366004612ebb565b6117b6565b3480156105b657600080fd5b506101636105c5366004612dc7565b61189c565b3480156105d657600080fd5b506101ac6105e5366004612dc7565b611926565b3480156105f657600080fd5b5061016360055481565b61060861199c565b6001600160a01b0381166106515760405162461bcd60e51b815260206004820152600b60248201526a125b9d985b1a59141bdbdb60aa1b60448201526064015b60405180910390fd5b60008190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610696573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106ba91906131a4565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106fc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072091906131a4565b90506000836001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015610762573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078691906131d4565b6001600160a01b038085166000908152600960209081526040808320938716835292815282822062ffffff851683529052205490915015610812576001600160a01b038381166000908152600960209081526040808320938616835292815282822062ffffff851683529052819020549051637d38f65f60e01b81526004810191909152602401610648565b61081b836119fb565b610824826119fb565b600680546001908101808355604080516080810182526001600160a01b03808a1680835289821660208085018281528b851686880181815262ffffff808e1660608a0181815260009c8d52600887528b8d209a518b54908b166001600160a01b0319918216178c5595519d8b0180549e8b169e9096169d909d179094559051600290980180549b51909116600160a01b026001600160b81b0319909b16979096169690961798909817909355965496855260098252838520928552918152828420948452938452818320859055808352600a909352808220849055519192917fdc467816be4ae0fb24482b03c7fcaebabc217fa013c4d51e500dc79c5ad5e2ba9190a35050505050565b60008061095c84847f00000000000000000000000037b70f2212fb8036ce11f00596386c921ee94713611ac7565b9150505b92915050565b6000610970611d79565b336001600160a01b037f0000000000000000000000001d0a515902f69db560eec32ed1dc2154cb882c9816146109b95760405163b302ad3760e01b815260040160405180910390fd5b6000806000806000807f0000000000000000000000001d0a515902f69db560eec32ed1dc2154cb882c986001600160a01b03166399fbab888b6040518263ffffffff1660e01b8152600401610a1091815260200190565b61018060405180830381865afa158015610a2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a529190613218565b505050509750975097509750975097505050806001600160801b0316600003610a8e57604051636180f03f60e11b815260040160405180910390fd5b6001600160a01b038087166000908152600960209081526040808320938916835292815282822062ffffff8816835290529081205490819003610ae45760405163079f151f60e11b815260040160405180910390fd5b60008b815260076020526040902060018101546001600160a01b0316610c1a578c8160010160006101000a8154816001600160a01b0302191690836001600160a01b031602179055508181600201819055506008600083815260200190815260200160002060000160009054906101000a90046001600160a01b03168160030160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060008160040181905550828160000160006101000a8154816001600160801b0302191690836001600160801b03160217905550848160000160106101000a81548162ffffff021916908360020b62ffffff160217905550838160000160136101000a81548162ffffff021916908360020b62ffffff1602179055504381600601819055508b8160050181905550610c60565b805462ffffff858116600160981b0262ffffff60981b19918816600160801b026001600160981b03199093166001600160801b0387161792909217161781554360068201555b610cb38d8d6001600160a01b039190911660008181526002602081815260408084208054600384528286208187528452828620889055968552600483529084209590955592909152905280546001019055565b6008600083815260200190815260200160002060000160009054906101000a90046001600160a01b03166001600160a01b03168c8e6001600160a01b03167f520940434c792159e5211d2c1211a4bccd932a1c1fbf8a453190c9a8e957d71d60405160405180910390a450630a85bd0160e11b975050505050505050610d3860018055565b95945050505050565b610d49611d79565b6000818152600760205260409020600101546001600160a01b0316338114610d84576040516370d645e360e01b815260040160405180910390fd5b610d8d82611dd2565b60008281526007602090815260408083206002810154808552600890935292819020549051632142170760e11b81526001600160a01b03918216917f0000000000000000000000001d0a515902f69db560eec32ed1dc2154cb882c9816906342842e0e90610e0390309088908a906004016132f4565b600060405180830381600087803b158015610e1d57600080fd5b505af1158015610e31573d6000803e3d6000fd5b50505050610e3f8486611e75565b806001600160a01b031685856001600160a01b03167f119d930f8a790cc06b4421b32d0bf3093c05fc6e0dd49435f3e89db43bafaa1160405160405180910390a450505050610e8d60018055565b50565b6001600160a01b0382166000908152600260205260408120548210610f055760405162461bcd60e51b815260206004820152602560248201527f456e756d657261626c653a206f776e657220696e646578206f7574206f6620626044820152646f756e647360d81b6064820152608401610648565b506001600160a01b03919091166000908152600360209081526040808320938352929052205490565b60606000610f3b83611157565b9050806001600160401b03811115610f5557610f55613318565b604051908082528060200260200182016040528015610f7e578160200160208202803683370190505b50915060005b81811015610fc557610f968482610e90565b838281518110610fa857610fa861332e565b602090810291909101015280610fbd8161335a565b915050610f84565b5050919050565b600081815260076020908152604080832081516101208101835281546001600160801b0381168252600160801b8104600290810b95830195909552600160981b9004840b9281019290925260018101546001600160a01b039081166060840181905293820154608084015260038201541660a0830152600481015460c0830152600581015460e0830152600601546101008201529061107d5760405162461bcd60e51b815260040161064890613373565b6080818101516000908152600860209081526040918290208251808501845281546001600160a01b03908116825260018301548116828501908152600293840154808316848801908152600160a01b90910462ffffff16606080860191909152875160c0810189528a516001600160801b03168152878b0151870b97810197909752878a015190950b96860196909652518116928401929092529251811693820193909352815190921660a083015290610d38817f00000000000000000000000037b70f2212fb8036ce11f00596386c921ee94713611ea1565b60006001600160a01b0382166111c55760405162461bcd60e51b815260206004820152602d60248201527f456e756d657261626c653a2061646472657373207a65726f206973206e6f742060448201526c30903b30b634b21037bbb732b960991b6064820152608401610648565b506001600160a01b031660009081526002602052604090205490565b6111e961199c565b6111f360006120c3565b565b6000806109607f00000000000000000000000037b70f2212fb8036ce11f00596386c921ee94713612113565b6000546001600160a01b031690565b61123861199c565b600082815260076020526040902060018101546001600160a01b0316156112af57600083815260076020526040812080546001600160b01b03191681556001810180546001600160a01b03199081169091556002820183905560038201805490911690556004810182905560058101829055600601555b604051632142170760e11b81526001600160a01b037f0000000000000000000000001d0a515902f69db560eec32ed1dc2154cb882c9816906342842e0e906112ff903090869088906004016132f4565b600060405180830381600087803b15801561131957600080fd5b505af115801561132d573d6000803e3d6000fd5b50505050505050565b6060600061134385610f2e565b80519091508381861061138c576040805160008082526020820190925290611381565b61136e612d66565b8152602001906001900390816113665790505b50935050505061153b565b8161139786886133a4565b11156113aa576113a786836133b7565b90505b6000816001600160401b038111156113c4576113c4613318565b6040519080825280602002602001820160405280156113fd57816020015b6113ea612d66565b8152602001906001900390816113e25790505b50905060005b828110156115345760006007818761141b858d6133a4565b8151811061142b5761142b61332e565b602090810291909101810151825281810192909252604090810160002081516101208101835281546001600160801b0381168252600160801b8104600290810b95830195909552600160981b9004840b9281019290925260018101546001600160a01b039081166060840152928101546080830152600381015490921660a0820152600482015460c0820152600582015460e082015260069091015461010082015290506114fa866114dd848c6133a4565b815181106114ed576114ed61332e565b60200260200101516117b6565b60c0820152825181908490849081106115155761151561332e565b602002602001018190525050808061152c9061335a565b915050611403565b5093505050505b9392505050565b61154a61199c565b600081116115955760405162461bcd60e51b81526020600482015260186024820152775468726573686f6c642063616e6e6f74206265207a65726f60401b6044820152606401610648565b600580549082905560408051828152602081018490527f2669b7d90b0477ab6fb6ab93303768fc1bac99619ab67505d74cadb0e3247e09910160405180910390a15050565b6060816001600160401b038111156115f4576115f4613318565b60405190808252806020026020018201604052801561162757816020015b60608152602001906001900390816116125790505b50905060005b8281101561172a576000803086868581811061164b5761164b61332e565b905060200281019061165d91906133ca565b60405161166b929190613417565b600060405180830381855af49150503d80600081146116a6576040519150601f19603f3d011682016040523d82523d6000602084013e6116ab565b606091505b5091509150816116f7576044815110156116c457600080fd5b600481019050808060200190518101906116de9190613427565b60405162461bcd60e51b815260040161064891906134d3565b8084848151811061170a5761170a61332e565b6020026020010181905250505080806117229061335a565b91505061162d565b5092915050565b604051632142170760e11b81526001600160a01b037f0000000000000000000000001d0a515902f69db560eec32ed1dc2154cb882c9816906342842e0e90611781903390309086906004016132f4565b600060405180830381600087803b15801561179b57600080fd5b505af11580156117af573d6000803e3d6000fd5b5050505050565b600081815260076020908152604080832081516101208101835281546001600160801b0381168252600160801b8104600290810b95830195909552600160981b9004840b9281019290925260018101546001600160a01b039081166060840181905293820154608084015260038201541660a0830152600481015460c0830152600581015460e083015260060154610100820152906118585750600092915050565b806101000151431161186d5750600092915050565b600061187884610fcc565b905060008261010001514361188d91906133b7565b9050610d388260055483612269565b6000806118a883610f2e565b905060005b8151811015610fc557600760008383815181106118cc576118cc61332e565b6020026020010151815260200190815260200160002060040154836118f191906133a4565b92506119088282815181106114ed576114ed61332e565b61191290846133a4565b92508061191e8161335a565b9150506118ad565b61192e61199c565b6001600160a01b0381166119935760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610648565b610e8d816120c3565b336119a5611221565b6001600160a01b0316146111f35760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610648565b604051636eb1769f60e11b81526001600160a01b0382169063dd62ed3e90611a499030907f0000000000000000000000001d0a515902f69db560eec32ed1dc2154cb882c98906004016134e6565b602060405180830381865afa158015611a66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a8a9190613500565b600003610e8d57610e8d6001600160a01b0382167f0000000000000000000000001d0a515902f69db560eec32ed1dc2154cb882c986000196122a0565b600080611ad383612113565b905060008490506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b1a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b3e91906131a4565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b80573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ba491906131a4565b90506000886001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611be6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c0a9190613519565b90506000846001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015611c4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c70919061355e565b5050505050915050600082600a611c8791906136d5565b9050846001600160a01b03168b6001600160a01b031603611cd7576000611cb0838388886123db565b9050670de0b6b3a7640000611cc589836136e4565b611ccf9190613711565b985050611d6b565b836001600160a01b03168b6001600160a01b031603611d2a576000611cfe838387896123db565b9050611d1281670de0b6b3a76400006136e4565b611cc5896a0c097ce7bc90715b34b9f160241b6136e4565b60405162461bcd60e51b8152602060048201526016602482015275125b9d985b1a59081d1bdad95b88199bdc881c1bdbdb60521b6044820152606401610648565b505050505050509392505050565b600260015403611dcb5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610648565b6002600155565b600081815260076020526040902060018101546001600160a01b0316611e0a5760405162461bcd60e51b815260040161064890613373565b6000611e15836117b6565b905080826004016000828254611e2b91906133a4565b9091555050436006830155600482015460405190815283907f2a4f386dacbb02a5d478d3fc1d2dbc487b69ed735b8d629e99d905680db927eb9060200160405180910390a2505050565b611e7f82826124e4565b506001600160a01b031660009081526002602052604090208054600019019055565b600080611ead83612113565b9050600080611ee3611ec28760a001516125f0565b611ecf8860200151612661565b611edc8960400151612661565b8951612979565b9150915060008060007370499adebb11efd915e3b69e700c3317786287079050806001600160a01b031689606001516001600160a01b031603611f3d57859250611f3689608001518a60a001518a611ac7565b9150611fa2565b806001600160a01b031689608001516001600160a01b031603611f7757611f6d89606001518a60a001518a611ac7565b9250859150611fa2565b611f8a89606001518a60a001518a611ac7565b9250611f9f89608001518a60a001518a611ac7565b91505b88608001516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611fe4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120089190613519565b61201390600a6136d5565b61201d83866136e4565b6120279190613711565b89606001516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015612069573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061208d9190613519565b61209890600a6136d5565b6120a285886136e4565b6120ac9190613711565b6120b691906133a4565b9998505050505050505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000808290506000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015612159573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061217d919061355e565b505060408051630dfe168160e01b81529051949650670de0b6b3a76400009550610d38948794508693506001600160a01b0389169250630dfe1681916004808201926020929091908290030181865afa1580156121de573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061220291906131a4565b866001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015612240573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061226491906131a4565b6123db565b6000670de0b6b3a7640000818461228083886136e4565b61228a9190613711565b905061229684826136e4565b9695505050505050565b8015806123195750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e906122d690309086906004016134e6565b602060405180830381865afa1580156122f3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123179190613500565b155b6123845760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610648565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526123d6908490612a15565b505050565b6000806123e786612661565b90506001600160801b036001600160a01b0382161161246d5760006124156001600160a01b038316806136e4565b9050836001600160a01b0316856001600160a01b03161061244d57612448600160c01b876001600160801b031683612ae7565b612465565b61246581876001600160801b0316600160c01b612ae7565b9250506124db565b60006124876001600160a01b03831680600160401b612ae7565b9050836001600160a01b0316856001600160a01b0316106124bf576124ba600160801b876001600160801b031683612ae7565b6124d7565b6124d781876001600160801b0316600160801b612ae7565b9250505b50949350505050565b6001600160a01b038216600090815260026020526040812054612509906001906133b7565b6000838152600460209081526040808320546001600160a01b0388168452600383528184208185529092529091205491925090831461257c5760405162461bcd60e51b815260206004820152600f60248201526e125b9d985b1a59081d1bdad95b9259608a1b6044820152606401610648565b8181146125bd576001600160a01b03841660009081526003602090815260408083208584528252808320548484528184208190558352600490915290208190555b5060009182526004602090815260408084208490556001600160a01b039094168352600381528383209183525290812055565b6000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015612630573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612654919061355e565b5094979650505050505050565b60008060008360020b12612678578260020b612680565b8260020b6000035b9050620d89e88111156126a6576040516315e4079d60e11b815260040160405180910390fd5b6000816001166000036126bd57600160801b6126cf565b6ffffcb933bd6fad37aa2d162d1a5940015b6001600160881b0316905060028216156126f9576ffff97272373d413259a46990580e213a0260801c5b6004821615612718576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615612737576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b6010821615612756576fffcb9843d60f6159c9db58835c9266440260801c5b6020821615612775576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615612794576fff2ea16466c96a3843ec78b326b528610260801c5b60808216156127b3576ffe5dee046a99a2a811c461f1969c30530260801c5b6101008216156127d3576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b6102008216156127f3576ff987a7253ac413176f2b074cf7815e540260801c5b610400821615612813576ff3392b0822b70005940c7a398e4b70f30260801c5b610800821615612833576fe7159475a2c29b7443b29c7fa6e889d90260801c5b611000821615612853576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615612873576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615612893576f70d869a156d2a1b890bb3df62baf32f70260801c5b6180008216156128b3576f31be135f97d08fd981231505542fcfa60260801c5b620100008216156128d4576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b620200008216156128f4576e5d6af8dedb81196699c329225ee6040260801c5b62040000821615612913576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615612930576b048a170391f7dc42444e8fa20260801c5b60008460020b131561295157806000198161294d5761294d6136fb565b0490505b600160201b810615612964576001612967565b60005b60ff16602082901c0192505050919050565b600080836001600160a01b0316856001600160a01b0316111561299a579293925b846001600160a01b0316866001600160a01b0316116129c5576129be858585612b99565b9150612a0c565b836001600160a01b0316866001600160a01b031610156129fe576129ea868585612b99565b91506129f7858785612c08565b9050612a0c565b612a09858585612c08565b90505b94509492505050565b6000612a6a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612c539092919063ffffffff16565b8051909150156123d65780806020019051810190612a889190613733565b6123d65760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610648565b6000808060001985870985870292508281108382030391505080600003612b205760008411612b1557600080fd5b50829004905061153b565b808411612b2c57600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000826001600160a01b0316846001600160a01b03161115612bb9579192915b836001600160a01b0316612bf2606060ff16846001600160801b0316901b8686036001600160a01b0316866001600160a01b0316612ae7565b81612bff57612bff6136fb565b04949350505050565b6000826001600160a01b0316846001600160a01b03161115612c28579192915b612c4b826001600160801b03168585036001600160a01b0316600160601b612ae7565b949350505050565b6060612c4b848460008585600080866001600160a01b03168587604051612c7a919061374e565b60006040518083038185875af1925050503d8060008114612cb7576040519150601f19603f3d011682016040523d82523d6000602084013e612cbc565b606091505b50915091506124d78783838760608315612d37578251600003612d30576001600160a01b0385163b612d305760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610648565b5081612c4b565b612c4b8383815115612d4c5781518083602001fd5b8060405162461bcd60e51b815260040161064891906134d3565b6040805161012081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081019190915290565b6001600160a01b0381168114610e8d57600080fd5b600060208284031215612dd957600080fd5b813561153b81612db2565b60008060408385031215612df757600080fd5b8235612e0281612db2565b91506020830135612e1281612db2565b809150509250929050565b600080600080600060808688031215612e3557600080fd5b8535612e4081612db2565b94506020860135612e5081612db2565b93506040860135925060608601356001600160401b0380821115612e7357600080fd5b818801915088601f830112612e8757600080fd5b813581811115612e9657600080fd5b896020828501011115612ea857600080fd5b9699959850939650602001949392505050565b600060208284031215612ecd57600080fd5b5035919050565b6001600160a01b03169052565b60008060408385031215612ef457600080fd5b8235612eff81612db2565b946020939093013593505050565b6020808252825182820181905260009190848201906040850190845b81811015612f4557835183529284019291840191600101612f29565b50909695505050505050565b60008060408385031215612f6457600080fd5b823591506020830135612e1281612db2565b600080600060608486031215612f8b57600080fd5b8335612f9681612db2565b95602085013595506040909401359392505050565b602080825282518282018190526000919060409081850190868401855b8281101561306157815180516001600160801b031685528681015160020b8786015285810151612ffc8787018260020b9052565b5060608082015161300f82880182612ed4565b50506080818101519086015260a08082015161302d82880182612ed4565b505060c0818101519086015260e0808201519086015261010090810151908501526101209093019290850190600101612fc8565b5091979650505050505050565b6000806020838503121561308157600080fd5b82356001600160401b038082111561309857600080fd5b818501915085601f8301126130ac57600080fd5b8135818111156130bb57600080fd5b8660208260051b85010111156130d057600080fd5b60209290920196919550909350505050565b60005b838110156130fd5781810151838201526020016130e5565b50506000910152565b6000815180845261311e8160208601602086016130e2565b601f01601f19169290920160200192915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b8281101561318757603f19888603018452613175858351613106565b94509285019290850190600101613159565b5092979650505050505050565b805161319f81612db2565b919050565b6000602082840312156131b657600080fd5b815161153b81612db2565b805162ffffff8116811461319f57600080fd5b6000602082840312156131e657600080fd5b61153b826131c1565b8051600281900b811461319f57600080fd5b80516001600160801b038116811461319f57600080fd5b6000806000806000806000806000806000806101808d8f03121561323b57600080fd5b8c516001600160601b038116811461325257600080fd5b9b5061326060208e01613194565b9a5061326e60408e01613194565b995061327c60608e01613194565b985061328a60808e016131c1565b975061329860a08e016131ef565b96506132a660c08e016131ef565b95506132b460e08e01613201565b94506101008d015193506101208d015192506132d36101408e01613201565b91506132e26101608e01613201565b90509295989b509295989b509295989b565b6001600160a01b039384168152919092166020820152604081019190915260600190565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001820161336c5761336c613344565b5060010190565b602080825260179082015276141bdcda5d1a5bdb88191bd95cc81b9bdd08195e1a5cdd604a1b604082015260600190565b8082018082111561096057610960613344565b8181038181111561096057610960613344565b6000808335601e198436030181126133e157600080fd5b8301803591506001600160401b038211156133fb57600080fd5b60200191503681900382131561341057600080fd5b9250929050565b8183823760009101908152919050565b60006020828403121561343957600080fd5b81516001600160401b038082111561345057600080fd5b818401915084601f83011261346457600080fd5b81518181111561347657613476613318565b604051601f8201601f19908116603f0116810190838211818310171561349e5761349e613318565b816040528281528760208487010111156134b757600080fd5b6134c88360208301602088016130e2565b979650505050505050565b60208152600061153b6020830184613106565b6001600160a01b0392831681529116602082015260400190565b60006020828403121561351257600080fd5b5051919050565b60006020828403121561352b57600080fd5b815160ff8116811461153b57600080fd5b805161ffff8116811461319f57600080fd5b8051801515811461319f57600080fd5b600080600080600080600060e0888a03121561357957600080fd5b875161358481612db2565b9650613592602089016131ef565b95506135a06040890161353c565b94506135ae6060890161353c565b93506135bc6080890161353c565b925060a088015163ffffffff811681146135d557600080fd5b91506135e360c0890161354e565b905092959891949750929550565b600181815b8085111561362c57816000190482111561361257613612613344565b8085161561361f57918102915b93841c93908002906135f6565b509250929050565b60008261364357506001610960565b8161365057506000610960565b816001811461366657600281146136705761368c565b6001915050610960565b60ff84111561368157613681613344565b50506001821b610960565b5060208310610133831016604e8410600b84101617156136af575081810a610960565b6136b983836135f1565b80600019048211156136cd576136cd613344565b029392505050565b600061153b60ff841683613634565b808202811582820484141761096057610960613344565b634e487b7160e01b600052601260045260246000fd5b60008261372e57634e487b7160e01b600052601260045260246000fd5b500490565b60006020828403121561374557600080fd5b61153b8261354e565b600082516137608184602087016130e2565b919091019291505056fea26469706673582212206e9f4e362448e7b6f48b2bbc6daae317a83c59f8a1ddee8c02a2a1e563910fc564736f6c63430008140033