Source Code
Overview
ETH Balance
ETH Value
$0.00| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
Latest 25 internal transactions (View All)
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 28271051 | 45 hrs ago | 0 ETH | ||||
| 28271051 | 45 hrs ago | 0 ETH | ||||
| 28254266 | 2 days ago | 0 ETH | ||||
| 28254266 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238914 | 2 days ago | 0 ETH | ||||
| 28238903 | 2 days ago | 0 ETH | ||||
| 28238903 | 2 days ago | 0 ETH | ||||
| 28178215 | 4 days ago | 0 ETH | ||||
| 28178215 | 4 days ago | 0 ETH | ||||
| 28178215 | 4 days ago | 0 ETH |
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xF6a59f69...3f5033fb1 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
PHyperLPoolSwapInside
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 1 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import {IERC20Metadata} from "../deps/OpenZeppelinV5/IERC20Metadata.sol";
import {SafeERC20} from "../deps/OpenZeppelinV5/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "../interfaces/pancake/IPancakeV3Pool.sol";
import "../interfaces/pancake/IPancakeV3PositionManager.sol";
import "../interfaces/pancake/IMasterChefV3.sol";
import "../interfaces/pancake/IPV3PoolHelper.sol";
import "../lib/pancake/SafePancakeV3Pool.sol";
import "../lib/pancake/TickMath.sol";
import "../lib/pancake/FullMath.sol";
import "../lib/pancake/FixedPoint96.sol";
import "../lib/pancake/LiquidityAmounts.sol";
import "./abstract/PHyperLPoolStorageSwapInside.sol";
contract PHyperLPoolSwapInside is PHyperLPoolStorageSwapInside {
using SafeERC20 for IERC20Metadata;
using SafePancakeV3Pool for IPancakeV3Pool;
using TickMath for int24;
using SafeCast for uint256;
using Address for address;
constructor(
address _registry,
address _farm,
string memory _poolName
) PHyperLPoolStorageSwapInside(_registry, _farm, _poolName) {} // solhint-disable-line no-empty-blocks
// User functions => Should be called via a Strategy
/// @notice mint PHyperLP shares, fractional shares of a Pancakeswap V3 position
/// @dev see getMintAmounts
/// @param amount0 amount of token0 approved from msg.sender
/// @param amount1 amount of token1 approved from msg.sender
/// @param receiver The account to receive the minted shares
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return mintAmount The number of PHyperLP shares to mint
/// @return liquidityMinted amount of liquidity added to the underlying Pancakeswap V3 position
// solhint-disable-next-line function-max-lines, code-complexity
function mint(
uint256 amount0Max,
uint256 amount1Max,
address receiver
) external onlyStrategy returns (uint256 amount0, uint256 amount1, uint256 mintAmount, uint128 liquidityMinted) {
if (amount0Max == 0 && amount1Max == 0) revert InvalidAmount();
// sync fee
syncFee();
(amount0, amount1, mintAmount, ) = getMintAmounts(amount0Max, amount1Max);
// check if nft is allocated to farming
(, , , bool allocatedToFarming) = getPositionNftData();
address positionManagerAddress = allocatedToFarming ? farmingContract : address(positionManager);
// transfer amounts owned to contract
if (amount0 > 0) {
token0.safeTransferFrom(msg.sender, address(this), amount0);
token0.forceApprove(positionManagerAddress, amount0);
}
if (amount1 > 0) {
token1.safeTransferFrom(msg.sender, address(this), amount1);
token1.forceApprove(positionManagerAddress, amount1);
}
(amount0, amount1, liquidityMinted) = _mint(amount0, amount1);
// add minted shares amount
totalSupply += mintAmount;
emit Minted(receiver, mintAmount, amount0, amount1, liquidityMinted);
}
/// @notice burn PHyperLP shares (fractional shares of a Pancakeswap V3 position) and receive tokens
/// @param burnAmount The number of PHyperLP shares to burn
/// @param receiver The account to receive the underlying amounts of token0 and token1
/// @return amount0 amount of token0 transferred to receiver for burning `burnAmount`
/// @return amount1 amount of token1 transferred to receiver for burning `burnAmount`
/// @return liquidityBurned amount of liquidity removed from the underlying Pancakeswap V3 position
// solhint-disable-next-line function-max-lines
function burn(
uint256 burnAmount,
address receiver
) external onlyStrategy returns (uint256 amount0, uint256 amount1, uint128 liquidityBurned) {
if (burnAmount == 0 || burnAmount > totalSupply) revert InvalidAmount();
// sync fee
syncFee();
uint256 _totalSupply = totalSupply;
uint128 liquidity = getLiquidity();
// remove burn amount
totalSupply -= burnAmount;
liquidityBurned = FullMath.mulDiv(burnAmount, liquidity, _totalSupply).toUint128();
if (liquidityBurned == 0) revert InvalidAmount();
(uint256 nftId, , , bool allocatedToFarming) = getPositionNftData();
(uint256 burn0, uint256 burn1) = _withdraw(nftId, allocatedToFarming, liquidityBurned);
amount0 = burn0 + FullMath.mulDiv(token0.balanceOf(address(this)) - burn0, burnAmount, _totalSupply);
amount1 = burn1 + FullMath.mulDiv(token1.balanceOf(address(this)) - burn1, burnAmount, _totalSupply);
if (amount0 > 0) {
token0.safeTransfer(receiver, amount0);
}
if (amount1 > 0) {
token1.safeTransfer(receiver, amount1);
}
emit Burned(receiver, burnAmount, amount0, amount1, liquidityBurned);
}
function harvest() external onlyStrategy {
_harvest();
}
// Manager Functions => Called by Pool Manager
function depositNftToFarm() external onlyManager returns (bool _allocatedToFarming) {
bytes32 positionID = getPositionID();
(uint256 nftId, , , bool allocatedToFarming) = _getPositionNftData(positionID);
if (allocatedToFarming) revert();
// try to allocate to farming
_allocatedToFarming = _depositNftToFarm(nftId);
// update position data
positionsNftData[positionID].allocatedToFarming = _allocatedToFarming;
}
/// @notice Change the range of underlying Pancakeswap V3 position, only manager can call
/// @dev Use the inRatioSwap function to swap tokens in the position to match the new range
/// @param newLowerTick The new lower bound of the position's range
/// @param newUpperTick The new upper bound of the position's range
/// @param customSlippagePriceThreshold Custom slippage price threshold to use in the swap
/// @param exchangeData Data to be used in the swap
// solhint-disable-next-line function-max-lines
function rebalance(
int24 newLowerTick,
int24 newUpperTick,
uint256 customSlippagePriceThreshold,
bytes calldata exchangeData,
bool simulate
) external {
if (!simulate && registry.getAddressByIdentifier(manager) != msg.sender) revert NoPermission();
if (newLowerTick >= newUpperTick || newLowerTick % tickSpacing != 0 || newUpperTick % tickSpacing != 0)
revert InvalidTick();
uint128 liquidity;
uint128 newLiquidity;
if (totalSupply > 0) {
// save liquidity before rebalance
liquidity = getLiquidity();
// if there is any liquidity, withdraw it all
if (liquidity > 0) {
// sync fee
syncFee();
(
uint256 nftId,
int24 currentLowerTick,
int24 currentUpperTick,
bool allocatedToFarming
) = getPositionNftData();
// harvest rewards if allocatedToFarming
if (allocatedToFarming) {
_harvest();
}
// withdraw all liquidity
_withdraw(nftId, allocatedToFarming, liquidity);
// if allocated to farming, withdraw nft from farm
if (allocatedToFarming) {
_withdrawNftFromFarm(currentLowerTick, currentUpperTick);
}
}
// set new position range
lowerTick = newLowerTick;
upperTick = newUpperTick;
_rebalance(
token0.balanceOf(address(this)),
token1.balanceOf(address(this)),
customSlippagePriceThreshold,
exchangeData,
simulate
);
newLiquidity = getLiquidity();
if (newLiquidity == 0) revert ZeroAmount();
} else {
lowerTick = newLowerTick;
upperTick = newUpperTick;
}
if (simulate) _revertWithSimulationData(abi.encode(lowerTick, upperTick));
emit Rebalance(newLowerTick, newUpperTick, liquidity, newLiquidity);
}
function compound() external onlyManager {
// sync fee for compound
syncFee();
uint256 balance0 = token0.balanceOf(address(this));
uint256 balance1 = token1.balanceOf(address(this));
// don't compound if there is nothing to compound
if (balance0 == 0 && balance1 == 0) return;
(uint256 amount0ToCompound, uint256 amount1ToCompound, , ) = getMintAmounts(balance0, balance1);
// don't mint new liquidity if there is nothing to compound
if (amount0ToCompound == 0 && amount1ToCompound == 0) {
return;
}
// check if nft is allocated to farming
(, , , bool allocatedToFarming) = getPositionNftData();
address positionManagerAddress = allocatedToFarming ? farmingContract : address(positionManager);
if (amount0ToCompound > 0) {
token0.forceApprove(positionManagerAddress, amount0ToCompound);
}
if (amount1ToCompound > 0) {
token1.forceApprove(positionManagerAddress, amount1ToCompound);
}
_mint(amount0ToCompound, amount1ToCompound);
}
// View functions
function getInRatioSwap(
uint256 amount0Desired,
uint256 amount1Desired
) external view returns (uint256 amountIn, uint256 amountOut, bool zeroForOne, uint160 sqrtPriceX96) {
IPV3PoolHelper ph = IPV3PoolHelper(registry.getAddressByIdentifier(poolHelper));
return ph.getInRatioSwap(address(pool), lowerTick, upperTick, amount0Desired, amount1Desired);
}
function checkPriceManipulation(uint256 customPriceThreshold) external view {
uint256 _priceTreashold = customPriceThreshold == 0 ? priceThreshold : customPriceThreshold;
_checkPriceManipulation(_priceTreashold, twapInterval);
}
function _checkPriceManipulation(uint256 _priceThreshold, uint32 _twapInterval) internal view {
IPV3PoolHelper ph = IPV3PoolHelper(registry.getAddressByIdentifier(poolHelper));
ph.checkPriceManipulation(address(pool), _priceThreshold, _twapInterval);
}
/// @notice compute maximum amount of shares to mint for given amounts of max amounts of token0 and token1
/// @param amount0Max The maximum amount of token0 to forward on mint
/// @param amount0Max The maximum amount of token1 to forward on mint
/// @return amount0 actual amount of token0 to forward when minting `mintAmount`
/// @return amount1 actual amount of token1 to forward when minting `mintAmount`
/// @return mintAmount maximum number of PHyperLP shares to mint
/// @return sqrtPriceX96 from pool price
// solhint-disable-next-line function-max-lines
function getMintAmounts(
uint256 amount0Max,
uint256 amount1Max
) public view returns (uint256 amount0, uint256 amount1, uint256 mintAmount, uint160 sqrtPriceX96) {
(sqrtPriceX96, ) = pool.sqrtPriceX96AndTick();
uint256 price = getLpPrice(sqrtPriceX96);
(amount0, amount1) = _getMaxAmountsFromAmounts(
amount0Max,
amount1Max,
sqrtPriceX96,
lowerTick.getSqrtRatioAtTick(),
upperTick.getSqrtRatioAtTick()
);
mintAmount = FullMath.mulDiv(amount0, price, LP_PRICE_PRECISION) + amount1;
if (totalSupply != 0) {
(uint256 total0, uint256 total1, ) = getTotalAmounts();
uint256 total0In1 = FullMath.mulDiv(total0, price, LP_PRICE_PRECISION);
// adjust mint amount based on current holdings
mintAmount = FullMath.mulDiv(mintAmount, totalSupply, total0In1 + total1);
}
}
function getLiquidity() public view returns (uint128 liquidity) {
(uint256 nftId, , , ) = getPositionNftData();
liquidity = _getLiquidity(nftId);
}
function getLpPrice(uint160 sqrtPriceX96) public pure returns (uint256 lpPrice) {
// calculation with a check to avoid uint256 overflow
if (sqrtPriceX96 <= type(uint128).max) {
uint256 priceX192 = uint256(sqrtPriceX96) * sqrtPriceX96;
lpPrice = FullMath.mulDiv(priceX192, LP_PRICE_PRECISION, 1 << 192);
} else {
uint256 priceX128 = FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, 1 << 64);
lpPrice = FullMath.mulDiv(priceX128, LP_PRICE_PRECISION, 1 << 128);
}
}
function getTotalAmounts() public view returns (uint256 total0, uint256 total1, uint128 liquidity) {
(total0, total1, liquidity) = _getPositionAmounts();
// add current holdings
unchecked {
total0 += token0.balanceOf(address(this));
total1 += token1.balanceOf(address(this));
}
}
function getPendingReward() public view returns (uint256 pendingReward) {
(uint256 nftId, , , ) = getPositionNftData();
if (nftId == 0) {
return 0;
}
IMasterChefV3 farm = IMasterChefV3(farmingContract);
pendingReward = farm.pendingCake(nftId);
}
// Private functions
function _mint(
uint256 amount0ToMint,
uint256 amount1ToMint
) private returns (uint256 amount0Minted, uint256 amount1Minted, uint128 liquidityMinted) {
bytes32 positionID = _getPositionID(lowerTick, upperTick);
(uint256 nftId, , , bool allocatedToFarming) = _getPositionNftData(positionID);
if (_isMintAmountsZero(amount0ToMint, amount1ToMint)) return (0, 0, 0);
if (nftId == 0) {
// Create new position
(nftId, liquidityMinted, amount0Minted, amount1Minted) = positionManager.mint(
IPancakeV3PositionManager.MintParams({
token0: address(token0),
token1: address(token1),
fee: poolFee,
tickLower: lowerTick,
tickUpper: upperTick,
amount0Desired: amount0ToMint,
amount1Desired: amount1ToMint,
amount0Min: 0,
amount1Min: 0,
recipient: address(this),
deadline: block.timestamp
})
);
// create new position
positionsNftData[positionID] = PositionNftData({
nftId: nftId,
lowerTick: lowerTick,
upperTick: upperTick,
allocatedToFarming: false
});
} else {
IPancakeV3PositionManager _positionManager = allocatedToFarming
? IPancakeV3PositionManager(farmingContract)
: positionManager;
// Add liquidity to existing position
(liquidityMinted, amount0Minted, amount1Minted) = _positionManager.increaseLiquidity(
IPancakeV3PositionManager.IncreaseLiquidityParams({
tokenId: nftId,
amount0Desired: amount0ToMint,
amount1Desired: amount1ToMint,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
})
);
}
// try to allocate to farming if not already allocated
if (!allocatedToFarming) {
allocatedToFarming = _depositNftToFarm(nftId);
positionsNftData[positionID].allocatedToFarming = allocatedToFarming;
}
}
function withdrawNftFromFarm(int24 _lowerTick, int24 _upperTick) external onlyManager {
_withdrawNftFromFarm(_lowerTick, _upperTick);
}
function _withdrawNftFromFarm(int24 _lowerTick, int24 _upperTick) private {
bytes32 positionID = _getPositionID(_lowerTick, _upperTick);
(uint256 nftId, , , bool allocatedToFarming) = _getPositionNftData(positionID);
if (nftId == 0) {
return;
}
IMasterChefV3 farm = IMasterChefV3(farmingContract);
// withdraw nft from farm
uint256 reward = farm.withdraw(nftId, address(this));
if (reward > 0) {
// send reward to strategy
rewardToken.safeTransfer(registry.getAddressByIdentifier(strategy), reward);
}
// remove allocatedToFarming flag
if (allocatedToFarming) {
positionsNftData[positionID].allocatedToFarming = false;
}
}
function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
// only accept nft from farming contract
return this.onERC721Received.selector;
}
// solhint-disable-next-line function-max-lines
function _withdraw(
uint256 nftId,
bool allocatedToFarming,
uint128 liquidity
) private returns (uint256 burn0, uint256 burn1) {
IPancakeV3PositionManager _positionManager = allocatedToFarming
? IPancakeV3PositionManager(farmingContract)
: positionManager;
// decrease liquiditys
(burn0, burn1) = _positionManager.decreaseLiquidity(
IPancakeV3PositionManager.DecreaseLiquidityParams({
tokenId: nftId,
liquidity: liquidity,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
})
);
// claim tokens from position manager
_positionManager.collect(
IPancakeV3PositionManager.CollectParams({
tokenId: nftId,
recipient: address(this),
amount0Max: type(uint128).max,
amount1Max: type(uint128).max
})
);
}
function _depositNftToFarm(uint256 _nftId) private returns (bool _allocatedToFarming) {
if (_nftId == 0) {
return false;
}
// nft will deposit to farm with nftTransfer callback (check onERC721Received in MasterChefV3 contract)
try positionManager.safeTransferFrom(address(this), farmingContract, _nftId) {
return true;
} catch {
// it should not break flow if some error happens
return false;
}
}
// this function is used to revert with simulation data
function getPricePerShareSnapshot() external {
(uint256 total0, uint256 total1, ) = getTotalAmounts();
(, uint256 fee0, uint256 fee1) = syncFee();
uint256 reward = _harvest();
_revertWithSimulationData(abi.encode(total0, total1, totalSupply, fee0, fee1, reward));
}
function _harvest() private returns (uint256) {
(uint256 nftId, , , ) = getPositionNftData();
IMasterChefV3 farm = IMasterChefV3(farmingContract);
return farm.harvest(nftId, registry.getAddressByIdentifier(strategy));
}
// solhint-disable-next-line function-max-lines
function _rebalance(
uint256 balance0,
uint256 balance1,
uint256 customSlippagePriceThreshold,
bytes calldata exchangeData,
bool simulate
) private {
// Check price manipulation before the swap to prevent sandwich attacks
_checkPriceManipulation(priceThreshold, twapInterval);
if (exchangeData.length == 0) {
(balance0, balance1) = _inRatioSwap(balance0, balance1, simulate);
} else {
(balance0, balance1) = _swapWithCustomData(exchangeData, simulate);
}
// Check price manipulation after our swap to prevent big price changes
uint256 slippagePriceThreshold = customSlippagePriceThreshold == 0
? priceThreshold
: customSlippagePriceThreshold;
_checkPriceManipulation(slippagePriceThreshold, twapInterval);
// check if nft is allocated to farming
(, , , bool allocatedToFarming) = getPositionNftData();
address positionManagerAddress = allocatedToFarming ? farmingContract : address(positionManager);
if (balance0 > 0) {
token0.forceApprove(positionManagerAddress, balance0);
}
if (balance1 > 0) {
token1.forceApprove(positionManagerAddress, balance1);
}
_mint(balance0, balance1);
}
function _getMaxAmountsFromAmounts(
uint256 amount0,
uint256 amount1,
uint160 sqrtPriceX96,
uint160 lowerSqrtP,
uint160 upperSqrtP
) private pure returns (uint256 amount0ToDeposit, uint256 amount1ToDeposit) {
uint128 newLiquidity = LiquidityAmounts.getLiquidityForAmounts(
sqrtPriceX96,
lowerSqrtP,
upperSqrtP,
amount0,
amount1
);
(amount0ToDeposit, amount1ToDeposit) = LiquidityAmounts.getAmountsForLiquidity(
sqrtPriceX96,
lowerSqrtP,
upperSqrtP,
newLiquidity
);
}
function _swap(uint256 swapAmount, bool zeroForOne) private returns (uint256 amountOut) {
uint160 swapThresholdPrice = zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1;
(int256 amount0Delta, int256 amount1Delta) = pool.swap(
address(this),
zeroForOne,
swapAmount.toInt256(),
swapThresholdPrice,
""
);
unchecked {
amountOut = 0 - (zeroForOne ? uint256(amount1Delta) : uint256(amount0Delta));
}
}
function _inRatioSwap(
uint256 amount0Desired,
uint256 amount1Desired,
bool simulate
) internal returns (uint256 amount0, uint256 amount1) {
IPV3PoolHelper ph = IPV3PoolHelper(registry.getAddressByIdentifier(poolHelper));
(uint256 amountIn, , bool zeroForOne, uint160 sqrtPriceX96) = ph.getInRatioSwap(
address(pool),
lowerTick,
upperTick,
amount0Desired,
amount1Desired
);
uint256 swapThreshold = zeroForOne ? swapThreshold0 : swapThreshold1;
uint256 amountOut;
if (amountIn > swapThreshold) {
amountOut = _swap(amountIn, zeroForOne);
unchecked {
(amount0, amount1) = zeroForOne ? (0 - amountIn, amountOut) : (amountOut, 0 - amountIn);
amount0 += amount0Desired;
amount1 += amount1Desired;
}
} else {
// if swap amount is less than threshold, we don't swap
amount0 = amount0Desired;
amount1 = amount1Desired;
// we need to return revert with correct simulation data
amountIn = 0;
amountOut = 0;
(sqrtPriceX96, ) = pool.sqrtPriceX96AndTick();
}
if (simulate)
_revertWithSimulationData(abi.encode(amount0, amount1, amountIn, amountOut, zeroForOne, sqrtPriceX96));
}
function _swapWithCustomData(
bytes calldata swapData,
bool simulate
) internal returns (uint256 amount0, uint256 amount1) {
(address router, bool zeroForOne, bytes memory data) = abi.decode(swapData, (address, bool, bytes));
IERC20Metadata tokenIn = zeroForOne ? token0 : token1;
// Approve `router` to spend `tokenIn`
tokenIn.forceApprove(router, type(uint256).max);
// Call the external router
router.functionCall(data);
// Reset approval
tokenIn.forceApprove(router, 0);
amount0 = token0.balanceOf(address(this));
amount1 = token1.balanceOf(address(this));
if (simulate) {
(uint160 sqrtPriceX96, ) = pool.sqrtPriceX96AndTick();
_revertWithSimulationData(abi.encode(amount0, amount1, sqrtPriceX96));
}
}
function syncFee() private returns (uint128 liquidity, uint256 fee0, uint256 fee1) {
return _syncFee();
}
function _syncFee() private returns (uint128 liquidity, uint256 fee0, uint256 fee1) {
/// sync fees for inclusion
(uint256 nftId, int24 lowerTick, int24 upperTick, bool allocatedToFarming) = getPositionNftData();
if (nftId == 0) {
return (0, 0, 0);
}
liquidity = _getLiquidity(nftId);
if (liquidity > 0) {
uint256 preBalance0 = token0.balanceOf(address(this));
uint256 preBalance1 = token1.balanceOf(address(this));
IPancakeV3PositionManager _positionManager = allocatedToFarming
? IPancakeV3PositionManager(farmingContract)
: positionManager;
_positionManager.collect(
IPancakeV3PositionManager.CollectParams({
tokenId: nftId,
recipient: address(this),
amount0Max: type(uint128).max,
amount1Max: type(uint128).max
})
);
fee0 = token0.balanceOf(address(this)) - preBalance0;
fee1 = token1.balanceOf(address(this)) - preBalance1;
// transfer fees to treasury if any
_applyFees(fee0, fee1);
(fee0, fee1) = _subtractAdminFees(fee0, fee1); // subtract admin fees from earned fees
emit FeesEarned(fee0, fee1, lowerTick, upperTick);
}
}
function _applyFees(uint256 _fee0, uint256 _fee1) private {
uint256 managerFee0 = FullMath.mulDiv(_fee0, managerFeeBPS, 10000);
uint256 managerFee1 = FullMath.mulDiv(_fee1, managerFeeBPS, 10000);
if (managerFee0 > 0) {
token0.safeTransfer(managerTreasury, managerFee0);
}
if (managerFee1 > 0) {
token1.safeTransfer(managerTreasury, managerFee1);
}
}
function _subtractAdminFees(uint256 rawFee0, uint256 rawFee1) private view returns (uint256 fee0, uint256 fee1) {
unchecked {
fee0 = rawFee0 - FullMath.mulDiv(rawFee0, managerFeeBPS, 10000);
fee1 = rawFee1 - FullMath.mulDiv(rawFee1, managerFeeBPS, 10000);
}
}
function _getPositionAmounts() private view returns (uint256 amount0, uint256 amount1, uint128 liquidity) {
(uint256 nftId, int24 lowerTick, int24 upperTick, ) = getPositionNftData();
// if nftId is 0, then there is no position
if (nftId == 0) {
return (0, 0, 0);
}
liquidity = _getLiquidity(nftId);
if (liquidity > 0) {
(uint160 sqrtPriceX96, ) = pool.sqrtPriceX96AndTick();
// compute current holdings from liquidity
(amount0, amount1) = LiquidityAmounts.getAmountsForLiquidity(
sqrtPriceX96,
lowerTick.getSqrtRatioAtTick(),
upperTick.getSqrtRatioAtTick(),
liquidity
);
}
}
/// @dev Equivalent to `(, , , , , , , liquidity, , , , ) = positionManager.positions(nftId)`
function _getLiquidity(uint256 nftId) private view returns (uint128 liquidity) {
if (nftId == 0) {
return 0;
}
bytes memory position = address(positionManager).functionStaticCall(
abi.encodeWithSelector(IPancakeV3PositionManager.positions.selector, nftId),
"PHyperLPoolSwapInside: getLiquidity failed"
);
assembly ("memory-safe") {
liquidity := mload(add(position, 0x100))
}
}
function _isMintAmountsZero(uint256 amount0, uint256 amount1) private view returns (bool) {
(uint160 sqrtPriceX96, ) = pool.sqrtPriceX96AndTick();
(amount0, amount1) = _getMaxAmountsFromAmounts(
amount0,
amount1,
sqrtPriceX96,
lowerTick.getSqrtRatioAtTick(),
upperTick.getSqrtRatioAtTick()
);
return amount0 == 0 && amount1 == 0;
}
/// @notice Pancake v3 callback fn, called back on pool.swap
function pancakeV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata /*data*/) external {
require(msg.sender == address(pool), "callback caller");
if (amount0Delta > 0) token0.safeTransfer(msg.sender, uint256(amount0Delta));
else if (amount1Delta > 0) token1.safeTransfer(msg.sender, uint256(amount1Delta));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822ProxiableUpgradeable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeaconUpgradeable {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/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);
}// 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);
}
}
}// 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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}// SPDX-License-Identifier: UNLICENSED
// (c) SphereX 2023 Terms&Conditions
pragma solidity ^0.8.0;
/**
* @title Interface for SphereXEngine - definitions of core functionality
* @author SphereX Technologies ltd
* @notice This interface is imported by SphereXProtected, so that SphereXProtected can call functions from SphereXEngine
* @dev Full docs of these functions can be found in SphereXEngine
*/
interface ISphereXEngine {
function sphereXValidatePre(int256 num, address sender, bytes calldata data) external returns (bytes32[] memory);
function sphereXValidatePost(
int256 num,
uint256 gas,
bytes32[] calldata valuesBefore,
bytes32[] calldata valuesAfter
) external;
function sphereXValidateInternalPre(int256 num) external returns (bytes32[] memory);
function sphereXValidateInternalPost(
int256 num,
uint256 gas,
bytes32[] calldata valuesBefore,
bytes32[] calldata valuesAfter
) external;
function addAllowedSenderOnChain(address sender) external;
/**
* This function is taken as is from OZ IERC165, we don't inherit from OZ
* to avoid collisions with the customer OZ version.
*
* @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);
}
/**
* @dev this struct is used to reduce the stack usage of the modifiers.
*/
struct ModifierLocals {
bytes32[] storageSlots;
bytes32[] valuesBefore;
uint256 gas;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
enum ErrorCodes {
unknown,
functionCall,
functionCallWithValue,
functionStaticCall,
functionDelegateCall
}
/**
* @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");
if (!(address(this).balance >= amount)) revert Address__InsufficientBalance();
(bool success, ) = recipient.call{value: amount}("");
// require(success, "Address: unable to send value, recipient may have reverted");
if (!success) revert Address__UnableToSendValue();
}
/**
* @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 functionCall(target, data, "Address: low-level call failed");
return functionCall(target, data, uint(ErrorCodes.functionCall));
}
/**
* @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, uint errorCode) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorCode);
}
/**
* @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");
return functionCallWithValue(target, data, value, uint(ErrorCodes.functionCallWithValue));
}
/**
* @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,
uint errorCode
) internal returns (bytes memory) {
// require(address(this).balance >= value, "Address: insufficient balance for call");
// require(isContract(target), "Address: call to non-contract");
if (!(address(this).balance >= value)) revert Address__InsufficientBalanceForCall();
if (!(isContract(target))) revert Address__CallToNonContract();
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorCode);
}
/**
* @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");
return functionStaticCall(target, data, uint(ErrorCodes.functionStaticCall));
}
/**
* @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,
uint errorCode
) internal view returns (bytes memory) {
// require(isContract(target), "Address: static call to non-contract");
if (!(isContract(target))) revert Address__StaticCallToNonContract();
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorCode);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
uint errorCode
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// 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);
if (errorCode == uint(ErrorCodes.functionCall)) revert Address__LowLevelCallFailed();
else if (errorCode == uint(ErrorCodes.functionCallWithValue))
revert Address__LowLevelCallWithValueFailed();
else if (errorCode == uint(ErrorCodes.functionStaticCall)) revert Address__LowLevelStaticCallFailed();
else revert Address__LowLevelCallFailedWithCustomErrorCode(uint(errorCode));
}
}
}
/* ERRORS */
error Address__InsufficientBalance();
error Address__UnableToSendValue();
error Address__InsufficientBalanceForCall();
error Address__CallToNonContract();
error Address__StaticCallToNonContract();
error Address__LowLevelCallFailedWithCustomErrorCode(uint errorCode);
error Address__LowLevelCallFailed();
error Address__LowLevelCallWithValueFailed();
error Address__LowLevelStaticCallFailed();
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol";
import "./AddressUpgradeable.sol";
import "./StorageSlotUpgradeable.sol";
import "./Initializable.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*
* @custom:oz-upgrades-unsafe-allow delegatecall
*/
abstract contract ERC1967UpgradeUpgradeable is Initializable {
function __ERC1967Upgrade_init() internal onlyInitializing {}
function __ERC1967Upgrade_init_unchained() internal onlyInitializing {}
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
// require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
if (!(AddressUpgradeable.isContract(newImplementation))) revert ERC1967_NewImplementationIsNotAContract();
StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
_functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
// require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
if (!(slot == _IMPLEMENTATION_SLOT)) revert ERC1967Upgrade_UnsupportedProxiableUUID();
} catch {
// revert("ERC1967Upgrade: new implementation is not UUPS");
revert ERC1967Upgrade_NewImplementationIsNotUUPS();
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
// require(newAdmin != address(0), "ERC1967: new admin is the zero address");
if (!(newAdmin != address(0))) revert ERC1967_NewAdminIsZeroAddress();
StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Emitted when the beacon is upgraded.
*/
event BeaconUpgraded(address indexed beacon);
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
// require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
// require(
// AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
// "ERC1967: beacon implementation is not a contract"
// );
if (!(AddressUpgradeable.isContract(newBeacon))) revert ERC1967_NewBeaconIsNotAContract();
if (!(AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()))) {
revert ERC1967_BeaconImplementationIsNotAContract();
}
StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
_functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);
}
}
/**
* @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) private returns (bytes memory) {
// require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract");
if (!(AddressUpgradeable.isContract(target))) revert Address_DelegateCallToNonContract();
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.delegatecall(data);
return
AddressUpgradeable.verifyCallResult(
success,
returndata,
uint256(AddressUpgradeable.ErrorCodes.functionDelegateCall)
);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
/* ERRORS */
error ERC1967_NewImplementationIsNotAContract();
error ERC1967Upgrade_UnsupportedProxiableUUID();
error ERC1967Upgrade_NewImplementationIsNotUUPS();
error ERC1967_NewAdminIsZeroAddress();
error ERC1967_NewBeaconIsNotAContract();
error ERC1967_BeaconImplementationIsNotAContract();
error Address_DelegateCallToNonContract();
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "./AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() rereinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
// require(
// (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
// "Initializable: contract is already initialized"
// );
if (
!((isTopLevelCall && _initialized < 1) ||
(!AddressUpgradeable.isContract(address(this)) && _initialized == 1))
) {
revert Initializable__ContractIsAlreadyInitialized();
}
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
* initialization step. This is essential to configure modules that are added through upgrades and that require
* initialization.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*/
modifier reinitializer(uint8 version) {
// require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
if (!(!_initializing && _initialized < version)) revert Initializable__ContractIsAlreadyInitialized();
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
// require(_initializing, "Initializable: contract is not initializing");
if (!(_initializing)) revert Initializable__ContractIsNotInitializing();
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*/
function _disableInitializers() internal virtual {
// require(!_initializing, "Initializable: contract is initializing");
if (!(!_initializing)) revert Initializable_ContractIsInitializing();
if (_initialized < type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/* ERRORS */
error Initializable__ContractIsAlreadyInitialized();
error Initializable__ContractIsNotInitializing();
error Initializable_ContractIsInitializing();
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @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://consensys.net/diligence/blog/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.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @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 or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* 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.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @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`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) 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 FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC-20 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.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
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].
*
* CAUTION: See Security Considerations above.
*/
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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Permit} from "./IERC20Permit.sol";
import {Address} from "./Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 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;
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @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);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// 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 cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlotUpgradeable {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol";
import "./ERC1967UpgradeUpgradeable.sol";
import "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*
* _Available since v4.1._
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
function __UUPSUpgradeable_init() internal onlyInitializing {}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {}
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
address private immutable __self = address(this);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
// require(address(this) != __self, "Function must be called through delegatecall");
// require(_getImplementation() == __self, "Function must be called through active proxy");
if (!(address(this) != __self)) revert FunctionMustBeCalledThroughDelegatecall();
if (!(_getImplementation() == __self)) revert FunctionMustBeCalledThroughActiveProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
// require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
if (!(address(this) == __self)) revert UUPSUpgradeable__MustNotBeCalledThroughDelegatecall();
_;
}
/**
* @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate that the this implementation remains valid after an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
return _IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*/
function upgradeTo(address newImplementation) external virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data, true);
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeTo} and {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal override onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
/* ERRORS */
error FunctionMustBeCalledThroughDelegatecall();
error FunctionMustBeCalledThroughActiveProxy();
error UUPSUpgradeable__MustNotBeCalledThroughDelegatecall();
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IRegistry {
function getBytes32Identifier(string calldata identifierString) external pure returns (bytes32);
function registerAddress(bytes32 bytes32Identifier, address contractAddress) external;
function getAddressByIdentifier(bytes32 bytes32Identifier) external view returns (address identifierAddress);
function getAllRegisteredIdentifiers() external view returns (bytes32[] memory);
function getRegisteredIdentifierById(uint256 id) external view returns (bytes32 registeredIdentifier);
function getRegisteredIdentifierCount() external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
interface IMasterChefV3 {
function harvest(uint256 _tokenId, address _to) external returns (uint256 reward);
function pendingCake(uint256 _tokenId) external view returns (uint256 reward);
function withdraw(uint256 _tokenId, address _to) external returns (uint256 reward);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import "./pool/IPancakeV3PoolImmutables.sol";
import "./pool/IPancakeV3PoolState.sol";
import "./pool/IPancakeV3PoolDerivedState.sol";
import "./pool/IPancakeV3PoolActions.sol";
/// @title The interface for a PancakeSwap V3 Pool
/// @notice A PancakeSwap 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 IPancakeV3Pool is
IPancakeV3PoolImmutables,
IPancakeV3PoolState,
IPancakeV3PoolDerivedState,
IPancakeV3PoolActions
{
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
/// @title Non-fungible token for positions
/// @notice Wraps PancakeSwap V3 positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
interface IPancakeV3PositionManager is IERC721Metadata, IERC721Enumerable {
/// @notice Emitted when liquidity is increased for a position NFT
/// @dev Also emitted when a token is minted
/// @param tokenId The ID of the token for which liquidity was increased
/// @param liquidity The amount by which liquidity for the NFT position was increased
/// @param amount0 The amount of token0 that was paid for the increase in liquidity
/// @param amount1 The amount of token1 that was paid for the increase in liquidity
event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
/// @notice Emitted when liquidity is decreased for a position NFT
/// @param tokenId The ID of the token for which liquidity was decreased
/// @param liquidity The amount by which liquidity for the NFT position was decreased
/// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
/// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
/// @notice Emitted when tokens are collected for a position NFT
/// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
/// @param tokenId The ID of the token for which underlying tokens were collected
/// @param recipient The address of the account that received the collected tokens
/// @param amount0 The amount of token0 owed to the position that was collected
/// @param amount1 The amount of token1 owed to the position that was collected
event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);
/// @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
);
struct MintParams {
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
uint256 deadline;
}
/// @notice Creates a new position wrapped in a NFT
/// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
/// a method does not exist, i.e. the pool is assumed to be initialized.
/// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
/// @return tokenId The ID of the token that represents the minted position
/// @return liquidity The amount of liquidity for this position
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function mint(
MintParams calldata params
) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @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);
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @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);
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
/// @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;
/// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH.
/// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
/// @param amountMinimum The minimum amount of WETH9 to unwrap
/// @param recipient The address receiving ETH
function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;
/// @notice Refunds any ETH balance held by this contract to the `msg.sender`
/// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps
/// that use ether for the input amount. And in PancakeSwap Router, this would be called
/// at the very end of swap
function refundETH() external payable;
/// @notice Transfers the full amount of a token held by this contract to recipient
/// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
/// @param token The contract address of the token which will be transferred to `recipient`
/// @param amountMinimum The minimum amount of token required for a transfer
/// @param recipient The destination address of the token
function sweepToken(address token, uint256 amountMinimum, address recipient) external payable;
/// @return Returns the address of the PancakeSwap V3 deployer
function deployer() external view returns (address);
/// @return Returns the address of the PancakeSwap V3 factory
function factory() external view returns (address);
/// @return Returns the address of WETH9
function WETH9() external view returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
interface IPV3PoolHelper {
function getInRatioSwap(
address poolAddress,
int24 lowerTick,
int24 upperTick,
uint256 amount0Desired,
uint256 amount1Desired
) external view returns (uint256 amountIn, uint256 amountOut, bool zeroForOne, uint160 sqrtPriceX96);
function checkPriceManipulation(address poolAddress, uint256 priceThreshold, uint32 twapInterval) external view;
}// 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 IPancakeV3PoolActions {
/// @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 IPancakeV3MintCallback#pancakeV3MintCallback
/// 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 IPancakeV3SwapCallback#pancakeV3SwapCallback
/// @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 IPancakeV3FlashCallback#pancakeV3FlashCallback
/// @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;
}// 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 IPancakeV3PoolDerivedState {
/// @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);
}// 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 IPancakeV3PoolImmutables {
/// @notice The contract that deployed the pool, which must adhere to the IPancakeV3Factory 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);
}// 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 IPancakeV3PoolState {
/// @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
/// 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.
/// observationIndex The index of the last oracle observation that was written,
/// observationCardinality The current maximum number of observations stored in the pool,
/// observationCardinalityNext The next maximum number of observations, to be updated when the observation.
/// 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,
uint32 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
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,
/// liquidityNet how much liquidity changes when the pool price crosses the tick,
/// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
/// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
/// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
/// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
/// secondsOutside the seconds spent on the other side of the tick from the current tick,
/// 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,
/// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
/// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
/// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
/// Returns 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,
/// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
/// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
/// Returns 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
);
}// 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;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.4.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.
// https://ethereum.stackexchange.com/a/96646
uint256 twos = denominator & (~denominator + 1);
// 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) {
result = mulDiv(a, b, denominator);
if (mulmod(a, b, denominator) > 0) {
require(result < type(uint256).max);
result++;
}
}
/// @notice Calculates x * y / 2^96 with full precision.
function mulDiv96(uint256 x, uint256 y) internal pure returns (uint256 result) {
assembly ("memory-safe") {
// 512-bit multiply `[prod1 prod0] = x * y`.
// 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`.
// Least significant 256 bits of the product.
let prod0 := mul(x, y)
let mm := mulmod(x, y, not(0))
// Most significant 256 bits of the product.
let prod1 := sub(mm, add(prod0, lt(mm, prod0)))
// Make sure the result is less than `2**256`.
if iszero(gt(0x1000000000000000000000000, prod1)) {
// Store the function selector of `FullMulDivFailed()`.
mstore(0x00, 0xae47f702)
// Revert with (offset, size).
revert(0x1c, 0x04)
}
// Divide [prod1 prod0] by 2^96.
result := or(shr(96, prod0), shl(160, prod1))
}
}
/// @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
function sqrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.
z := 181 // The "correct" value is 1, but this saves a multiplication later.
// This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
// start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
// Let `y = x / 2**r`. We check `y >= 2**(k + 8)`
// but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`.
let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffffff, shr(r, x))))
z := shl(shr(1, r), z)
// Goal was to get `z*z*y` within a small factor of `x`. More iterations could
// get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.
// We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.
// That's not possible if `x < 256` but we can just verify those cases exhaustively.
// Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.
// Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.
// Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.
// For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`
// is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,
// with largest error when `s = 1` and when `s = 256` or `1/256`.
// Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.
// Then we can estimate `sqrt(y)` using
// `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.
// There is no overflow risk here since `y < 2**136` after the first branch above.
z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.
// Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
// If `x+1` is a perfect square, the Babylonian method cycles between
// `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.
// See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
z := sub(z, lt(div(x, z), z))
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import "./FullMath.sol";
import "./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);
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);
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) {
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);
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);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "../../interfaces/pancake/IPancakeV3Pool.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import {ISphereXEngine} from "@spherex-xyz/contracts/src/ISphereXEngine.sol";
type V3PancakePool is address;
using SafePancakeV3Pool for V3PancakePool global;
/**
* @title SafePancakeV3Pool
* @dev Wrappers around IPancakeV3Pool 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 SafePancakeV3Pool for
* IPancakeV3Pool;` statement to your contract, which allows you
* to call the safe operations as `token.observe(...)`, etc.
*/
library SafePancakeV3Pool {
using Address for address;
bytes32 private constant SPHEREX_ADMIN_STORAGE_SLOT = bytes32(uint256(keccak256("eip1967.spherex.spherex")) - 1);
bytes32 private constant SPHEREX_OPERATOR_STORAGE_SLOT =
bytes32(uint256(keccak256("eip1967.spherex.operator")) - 1);
bytes32 private constant SPHEREX_ENGINE_STORAGE_SLOT =
bytes32(uint256(keccak256("eip1967.spherex.spherex_engine")) - 1);
struct ModifierLocals {
bytes32[] storageSlots;
bytes32[] valuesBefore;
uint256 gas;
}
function _sphereXEngine() private view returns (ISphereXEngine) {
return ISphereXEngine(_getAddress(SPHEREX_ENGINE_STORAGE_SLOT));
}
function _getAddress(bytes32 slot) private view returns (address addr) {
// solhint-disable-next-line no-inline-assembly
// slither-disable-next-line assembly
assembly {
addr := sload(slot)
}
}
modifier returnsIfNotActivated() {
if (address(_sphereXEngine()) == address(0)) {
return;
}
_;
}
// ============ Hooks ============
/**
* @dev internal function for engine communication. We use it to reduce contract size.
* Should be called before the code of a function.
* @param num function identifier
* @param isExternalCall set to true if this was called externally
* or a 'public' function from another address
*/
function _sphereXValidatePre(
int256 num,
bool isExternalCall
) private returnsIfNotActivated returns (ModifierLocals memory locals) {
ISphereXEngine sphereXEngine = _sphereXEngine();
if (isExternalCall) {
locals.storageSlots = sphereXEngine.sphereXValidatePre(num, msg.sender, msg.data);
} else {
locals.storageSlots = sphereXEngine.sphereXValidateInternalPre(num);
}
locals.valuesBefore = _readStorage(locals.storageSlots);
locals.gas = gasleft();
return locals;
}
/**
* @dev internal function for engine communication. We use it to reduce contract size.
* Should be called after the code of a function.
* @param num function identifier
* @param isExternalCall set to true if this was called externally
* or a 'public' function from another address
*/
function _sphereXValidatePost(
int256 num,
bool isExternalCall,
ModifierLocals memory locals
) private returnsIfNotActivated {
uint256 gas = locals.gas - gasleft();
ISphereXEngine sphereXEngine = _sphereXEngine();
bytes32[] memory valuesAfter;
valuesAfter = _readStorage(locals.storageSlots);
if (isExternalCall) {
sphereXEngine.sphereXValidatePost(num, gas, locals.valuesBefore, valuesAfter);
} else {
sphereXEngine.sphereXValidateInternalPost(num, gas, locals.valuesBefore, valuesAfter);
}
}
/**
* @dev internal function for engine communication. We use it to reduce contract size.
* Should be called before the code of a function.
* @param num function identifier
* @return locals ModifierLocals
*/
function _sphereXValidateInternalPre(
int256 num
) internal returnsIfNotActivated returns (ModifierLocals memory locals) {
locals.storageSlots = _sphereXEngine().sphereXValidateInternalPre(num);
locals.valuesBefore = _readStorage(locals.storageSlots);
locals.gas = gasleft();
return locals;
}
/**
* @dev internal function for engine communication. We use it to reduce contract size.
* Should be called after the code of a function.
* @param num function identifier
* @param locals ModifierLocals
*/
function _sphereXValidateInternalPost(int256 num, ModifierLocals memory locals) internal returnsIfNotActivated {
bytes32[] memory valuesAfter;
valuesAfter = _readStorage(locals.storageSlots);
_sphereXEngine().sphereXValidateInternalPost(num, locals.gas - gasleft(), locals.valuesBefore, valuesAfter);
}
/**
* @dev Modifier to be incorporated in all internal protected non-view functions
*/
modifier sphereXGuardInternal(int256 num) {
ModifierLocals memory locals = _sphereXValidateInternalPre(num);
_;
_sphereXValidateInternalPost(-num, locals);
}
/**
* @dev Modifier to be incorporated in all external protected non-view functions
*/
modifier sphereXGuardExternal(int256 num) {
ModifierLocals memory locals = _sphereXValidatePre(num, true);
_;
_sphereXValidatePost(-num, true, locals);
}
/**
* @dev Modifier to be incorporated in all public protected non-view functions
*/
modifier sphereXGuardPublic(int256 num, bytes4 selector) {
ModifierLocals memory locals = _sphereXValidatePre(num, msg.sig == selector);
_;
_sphereXValidatePost(-num, msg.sig == selector, locals);
}
// ============ Internal Storage logic ============
/**
* Internal function that reads values from given storage slots and returns them
* @param storageSlots list of storage slots to read
* @return list of values read from the various storage slots
*/
function _readStorage(bytes32[] memory storageSlots) internal view returns (bytes32[] memory) {
uint256 arrayLength = storageSlots.length;
bytes32[] memory values = new bytes32[](arrayLength);
// create the return array data
for (uint256 i = 0; i < arrayLength; i++) {
bytes32 slot = storageSlots[i];
bytes32 temp_value;
// solhint-disable-next-line no-inline-assembly
// slither-disable-next-line assembly
assembly {
temp_value := sload(slot)
}
values[i] = temp_value;
}
return values;
}
function safeTicks(
IPancakeV3Pool pool,
int24 tick
)
internal
view
returns (
uint128 liquidityGross,
int128 liquidityNet,
uint256 feeGrowthOutside0X128,
uint256 feeGrowthOutside1X128,
int56 tickCumulativeOutside,
uint160 secondsPerLiquidityOutsideX128,
uint32 secondsOutside,
bool initialized
)
{
bytes memory returndata = address(pool).functionStaticCall(
abi.encodeWithSelector(pool.ticks.selector, tick),
"SafePancakeV3Pool: low-level call failed"
);
return abi.decode(returndata, (uint128, int128, uint256, uint256, int56, uint160, uint32, bool));
}
function safePositions(
IPancakeV3Pool pool,
bytes32 key
)
internal
view
returns (
uint128 _liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
)
{
bytes memory returndata = address(pool).functionStaticCall(
abi.encodeWithSelector(pool.positions.selector, key),
"SafePancakeV3Pool: low-level call failed"
);
return abi.decode(returndata, (uint128, uint256, uint256, uint128, uint128));
}
function safeSlot0(
IPancakeV3Pool pool
)
internal
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint32 feeProtocol,
bool unlocked
)
{
bytes memory returndata = address(pool).functionStaticCall(
abi.encodeWithSelector(pool.slot0.selector),
"SafePancakeV3Pool: low-level call failed"
);
return abi.decode(returndata, (uint160, int24, uint16, uint16, uint16, uint32, bool));
}
function safeMint(
IPancakeV3Pool pool,
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes memory data
) internal sphereXGuardInternal(1006) returns (uint256 amount0, uint256 amount1) {
bytes memory returndata = address(pool).functionCall(
abi.encodeWithSelector(pool.mint.selector, recipient, tickLower, tickUpper, amount, data),
"SafePancakeV3Pool: low-level call failed"
);
return abi.decode(returndata, (uint256, uint256));
}
function observe(
V3PancakePool pool,
uint32[] memory secondsAgos
) internal view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) {
bytes memory returndata = V3PancakePool.unwrap(pool).functionStaticCall(
abi.encodeWithSelector(IPancakeV3PoolDerivedState.observe.selector, secondsAgos),
"SafePancakeV3Pool: low-level call failed"
);
return abi.decode(returndata, (int56[], uint160[]));
}
/// @dev Equivalent to `IPancakeV3Pool.tickBitmap`
/// @param pool Pancake v3 pool
/// @param wordPos The key in the mapping containing the word in which the bit is stored
function tickBitmap(V3PancakePool pool, int16 wordPos) internal view returns (uint256 tickWord) {
uint256 _wordPos;
assembly {
// Pad int16 to 32 bytes.
_wordPos := signextend(1, wordPos)
}
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
staticcallWithOneArgument(pool, IPancakeV3PoolState.tickBitmap.selector, _wordPos, 0, 0x20);
assembly ("memory-safe") {
tickWord := mload(0)
}
}
/// @dev Equivalent to `(uint160 sqrtPriceX96, int24 tick, , , , , ) = pool.slot0()`
/// @param pool Pancake v3 pool
function sqrtPriceX96AndTick(IPancakeV3Pool pool) internal view returns (uint160 sqrtPriceX96, int24 tick) {
(uint256 res0, uint256 res1) = staticcallWithTwoOutputs(
V3PancakePool.wrap(address(pool)),
IPancakeV3PoolState.slot0.selector
);
assembly {
sqrtPriceX96 := res0
tick := res1
}
}
/// @dev Equivalent to `(uint160 sqrtPriceX96, int24 tick, , , , , ) = pool.slot0()`
/// @param pool Pancake v3 pool
function sqrtPriceX96AndTick(V3PancakePool pool) internal view returns (uint160 sqrtPriceX96, int24 tick) {
(uint256 res0, uint256 res1) = staticcallWithTwoOutputs(pool, IPancakeV3PoolState.slot0.selector);
assembly {
sqrtPriceX96 := res0
tick := res1
}
}
/// @dev Equivalent to `IPancakeV3Pool.liquidity`
/// @param pool Pancake v3 pool
function liquidity(V3PancakePool pool) internal view returns (uint128 l) {
uint256 res = staticcallWithOneOutput(pool, IPancakeV3PoolState.liquidity.selector);
assembly {
l := res
}
}
/// @dev Equivalent to `IPancakeV3Pool.fee`
/// @param pool Pancake v3 pool
function fee(V3PancakePool pool) internal view returns (uint24 f) {
uint256 res = staticcallWithOneOutput(pool, IPancakeV3PoolImmutables.fee.selector);
assembly {
f := res
}
}
/// @dev Equivalent to `IPancakeV3Pool.tickSpacing`
/// @param pool Pancake v3 pool
function tickSpacing(V3PancakePool pool) internal view returns (int24 ts) {
uint256 res = staticcallWithOneOutput(pool, IPancakeV3PoolImmutables.tickSpacing.selector);
assembly {
ts := res
}
}
/// @dev Equivalent to `( , int128 liquidityNet, , , , , , ) = pool.ticks(tick)`
/// @param pool Pancake v3 pool
function liquidityNet(V3PancakePool pool, int24 tick) internal view returns (int128 ln) {
uint256 _tick;
assembly {
// Pad int24 to 32 bytes.
_tick := signextend(2, tick)
}
// We use 0 and 64 to copy up to 64 bytes of return data into the scratch space.
staticcallWithOneArgument(pool, IPancakeV3PoolState.ticks.selector, _tick, 0, 0x40);
assembly ("memory-safe") {
ln := mload(0x20)
}
}
function staticcallWithOneOutput(V3PancakePool pool, bytes4 selector) internal view returns (uint256 res) {
assembly ("memory-safe") {
// Write the function selector into memory.
mstore(0, selector)
// We use 4 because of the length of our calldata.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
if iszero(staticcall(gas(), pool, 0, 4, 0, 0x20)) {
revert(0, 0)
}
res := mload(0)
}
}
function staticcallWithTwoOutputs(
V3PancakePool pool,
bytes4 selector
) internal view returns (uint256 res0, uint256 res1) {
assembly ("memory-safe") {
// Write the function selector into memory.
mstore(0, selector)
// We use 4 because of the length of our calldata.
// We use 0 and 64 to copy up to 64 bytes of return data into the scratch space.
if iszero(staticcall(gas(), pool, 0, 4, 0, 0x40)) {
revert(0, 0)
}
res0 := mload(0)
res1 := mload(0x20)
}
}
function staticcallWithOneArgument(
V3PancakePool pool,
bytes4 selector,
uint256 arg,
uint256 out,
uint256 outsize
) internal view {
assembly ("memory-safe") {
// Write the abi-encoded calldata into memory.
mstore(0, selector)
mstore(4, arg)
// We use 36 because of the length of our calldata.
if iszero(staticcall(gas(), pool, 0, 0x24, out, outsize)) {
revert(0, 0)
}
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.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 {
/// @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) {
uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
require(absTick <= uint256(uint24(MAX_TICK)), "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) {
// second inequality must be < because the price can never reach the price at the max tick
require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, "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;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import {IERC20Metadata} from "../../deps/OpenZeppelinV5/IERC20Metadata.sol";
import "../../deps/UUPSUpgradeable.sol";
import "../../interfaces/IRegistry.sol";
import "../../interfaces/pancake/IPancakeV3PositionManager.sol";
import "../../interfaces/pancake/IPancakeV3Pool.sol";
/// @dev Single Global upgradeable state var storage base: APPEND ONLY
/// @dev Add all inherited contracts with state vars here: APPEND ONLY
// solhint-disable-next-line max-states-count
abstract contract PHyperLPoolStorageSwapInside is UUPSUpgradeable {
address internal immutable farmingContract;
IRegistry internal immutable registry;
bytes32 internal constant governance = keccak256("PHyperLPoolGovernance V0.1");
bytes32 internal immutable manager;
bytes32 internal immutable strategy;
bytes32 internal constant poolHelper = keccak256("PV3PoolHelper V0.1");
uint256 internal constant LP_PRICE_PRECISION = 10 ** 36;
// XXXXXXXX DO NOT MODIFY ORDERING XXXXXXXX
int24 internal lowerTick;
int24 internal upperTick;
uint16 internal managerFeeBPS;
uint24 internal poolFee;
address internal managerTreasury;
IPancakeV3Pool internal pool;
IERC20Metadata internal token0;
IERC20Metadata internal token1;
uint256 internal totalSupply;
IERC20Metadata internal rewardToken;
IPancakeV3PositionManager internal positionManager;
mapping(bytes32 => PositionNftData) internal positionsNftData;
int24 internal tickSpacing;
// Swap Thresholds are used to prevent swapping small amounts of tokens (see _swap function)
uint256 internal swapThreshold0;
uint256 internal swapThreshold1;
// Price manipulation check variables
uint256 internal priceThreshold;
uint32 internal twapInterval;
struct PositionNftData {
uint256 nftId;
int24 lowerTick;
int24 upperTick;
bool allocatedToFarming;
}
// solhint-disable-next-line max-line-length
modifier onlyGovernance() {
if (registry.getAddressByIdentifier(governance) != msg.sender) revert NoPermission();
_;
}
modifier onlyManager() {
if (registry.getAddressByIdentifier(manager) != msg.sender) revert NoPermission();
_;
}
modifier onlyStrategy() {
if (registry.getAddressByIdentifier(strategy) != msg.sender) revert NoPermission();
_;
}
constructor(address _registry, address _farm, string memory poolName) {
registry = IRegistry(_registry);
manager = keccak256(abi.encodePacked(poolName, "Manager V0.1"));
strategy = keccak256(abi.encodePacked(poolName, "Strategy V0.1"));
if (_farm.code.length == 0) revert("Invalid Farming Contract");
farmingContract = _farm;
// lock implementation
_disableInitializers();
} // solhint-disable-line no-empty-blocks
function _authorizeUpgrade(address newImplementation) internal override onlyGovernance {}
/// @notice initialize storage variables on a new PHyperLP pool, only called once
function initialize(bytes memory initializeData) external initializer {
// decode initialize data
__UUPSUpgradeable_init();
(
address _pool,
uint16 _managerFeeBPS,
int24 _lowerTick,
int24 _upperTick,
address _managerTreasury,
address _positionManager,
address _rewardToken,
uint256 _swapThreshold0,
uint256 _swapThreshold1,
uint256 _priceThreshold,
uint32 _twapInterval
) = abi.decode(
initializeData,
(address, uint16, int24, int24, address, address, address, uint256, uint256, uint256, uint32)
);
// these variables are immutable after initialization
pool = IPancakeV3Pool(_pool);
poolFee = pool.fee();
tickSpacing = pool.tickSpacing();
token0 = IERC20Metadata(pool.token0());
token1 = IERC20Metadata(pool.token1());
positionManager = IPancakeV3PositionManager(_positionManager);
rewardToken = IERC20Metadata(_rewardToken);
swapThreshold0 = _swapThreshold0;
swapThreshold1 = _swapThreshold1;
// these variables can be updated by the manager
if (_managerFeeBPS > 10000) revert MBPS();
managerFeeBPS = _managerFeeBPS; // if set to 0 here manager can still initialize later
managerTreasury = _managerTreasury;
if (_lowerTick >= _upperTick || _lowerTick % tickSpacing != 0 || _upperTick % tickSpacing != 0)
revert InvalidTick();
lowerTick = _lowerTick;
upperTick = _upperTick;
if (_priceThreshold > 10000) revert MBPS();
priceThreshold = _priceThreshold;
twapInterval = _twapInterval;
}
/// @notice change configurable manager parameters, only manager can call
/// @param newManagerFeeBPS Basis Points of fees earned credited to manager (negative to ignore)
/// @param newManagerTreasury address that collects manager fees (Zero address to ignore)
// solhint-disable-next-line code-complexity
function updateManagerParams(int16 newManagerFeeBPS, address newManagerTreasury) external onlyManager {
if (newManagerFeeBPS > 10000) revert MBPS();
if (newManagerFeeBPS >= 0) managerFeeBPS = uint16(newManagerFeeBPS);
if (address(0) != newManagerTreasury) managerTreasury = newManagerTreasury;
emit UpdateManagerParams(managerFeeBPS, managerTreasury);
}
function setPriceManipulationParams(uint256 _priceThreshold, uint32 _twapInterval) external onlyManager {
if (_priceThreshold > 10000) revert MBPS();
priceThreshold = _priceThreshold;
twapInterval = _twapInterval;
}
function setSwapThresholds(uint256 _swapThreshold0, uint256 _swapThreshold1) external onlyManager {
swapThreshold0 = _swapThreshold0;
swapThreshold1 = _swapThreshold1;
}
function _getPositionID(int24 _lowerTick, int24 _upperTick) internal view returns (bytes32 positionID) {
return keccak256(abi.encodePacked(address(this), _lowerTick, _upperTick));
}
function getPositionID() public view returns (bytes32 positionID) {
return _getPositionID(lowerTick, upperTick);
}
function getPositionID(int24 _lowerTick, int24 _upperTick) public view returns (bytes32 positionID) {
return _getPositionID(_lowerTick, _upperTick);
}
function _getPositionNftData(
bytes32 positionId
) internal view returns (uint256 nftId, int24 lowerTick_, int24 upperTick_, bool allocatedToFarming) {
return (
positionsNftData[positionId].nftId,
positionsNftData[positionId].lowerTick,
positionsNftData[positionId].upperTick,
positionsNftData[positionId].allocatedToFarming
);
}
function getPositionNftData()
public
view
returns (uint256 nftId, int24 lowerTick_, int24 upperTick_, bool allocatedToFarming)
{
return _getPositionNftData(_getPositionID(lowerTick, upperTick));
}
function getPositionNftData(
int24 _lowerTick,
int24 _upperTick
) public view returns (uint256 nftId, int24 lowerTick_, int24 upperTick_, bool allocatedToFarming) {
return _getPositionNftData(_getPositionID(_lowerTick, _upperTick));
}
function getIdentifiers() public view returns (bytes32, bytes32, bytes32, bytes32) {
return (governance, manager, strategy, poolHelper);
}
function totalSharesIssued() public view returns (uint256) {
return totalSupply;
}
function rewardTokenAddress() external view returns (address) {
return address(rewardToken);
}
function _revertWithSimulationData(bytes memory simulationData) internal pure {
bytes memory errorData = abi.encodeWithSelector(bytes4(keccak256("SimulationData(bytes)")), simulationData);
assembly ("memory-safe") {
revert(add(errorData, 0x20), mload(errorData))
}
}
event Minted(address receiver, uint256 mintAmount, uint256 amount0In, uint256 amount1In, uint128 liquidityMinted);
event Burned(address receiver, uint256 burnAmount, uint256 amount0Out, uint256 amount1Out, uint128 liquidityBurned);
event Rebalance(int24 lowerTick_, int24 upperTick_, uint128 liquidityBefore, uint128 liquidityAfter);
event FeesEarned(uint256 feesEarned0, uint256 feesEarned1, int24 lowerTick_, int24 upperTick_);
event UpdateManagerParams(uint16 managerFeeBPS, address managerTreasury);
/* ERRORS */
error InvalidAmount();
error Manipulation();
error ZeroAmount();
error NoPermission();
error MBPS();
error InvalidTick();
}{
"viaIR": true,
"optimizer": {
"enabled": true,
"runs": 1,
"details": {
"peephole": true,
"yulDetails": {
"stackAllocation": true,
"optimizerSteps": "dhfoD[xarrscLMcCTU]uljmul"
}
}
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_registry","type":"address"},{"internalType":"address","name":"_farm","type":"address"},{"internalType":"string","name":"_poolName","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"Address_DelegateCallToNonContract","type":"error"},{"inputs":[],"name":"Address__LowLevelCallFailed","type":"error"},{"inputs":[{"internalType":"uint256","name":"errorCode","type":"uint256"}],"name":"Address__LowLevelCallFailedWithCustomErrorCode","type":"error"},{"inputs":[],"name":"Address__LowLevelCallWithValueFailed","type":"error"},{"inputs":[],"name":"Address__LowLevelStaticCallFailed","type":"error"},{"inputs":[],"name":"ERC1967Upgrade_NewImplementationIsNotUUPS","type":"error"},{"inputs":[],"name":"ERC1967Upgrade_UnsupportedProxiableUUID","type":"error"},{"inputs":[],"name":"ERC1967_BeaconImplementationIsNotAContract","type":"error"},{"inputs":[],"name":"ERC1967_NewAdminIsZeroAddress","type":"error"},{"inputs":[],"name":"ERC1967_NewBeaconIsNotAContract","type":"error"},{"inputs":[],"name":"ERC1967_NewImplementationIsNotAContract","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"FunctionMustBeCalledThroughActiveProxy","type":"error"},{"inputs":[],"name":"FunctionMustBeCalledThroughDelegatecall","type":"error"},{"inputs":[],"name":"Initializable_ContractIsInitializing","type":"error"},{"inputs":[],"name":"Initializable__ContractIsAlreadyInitialized","type":"error"},{"inputs":[],"name":"Initializable__ContractIsNotInitializing","type":"error"},{"inputs":[],"name":"InvalidAmount","type":"error"},{"inputs":[],"name":"InvalidTick","type":"error"},{"inputs":[],"name":"MBPS","type":"error"},{"inputs":[],"name":"Manipulation","type":"error"},{"inputs":[],"name":"NoPermission","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"UUPSUpgradeable__MustNotBeCalledThroughDelegatecall","type":"error"},{"inputs":[],"name":"ZeroAmount","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"burnAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0Out","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1Out","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityBurned","type":"uint128"}],"name":"Burned","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feesEarned0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feesEarned1","type":"uint256"},{"indexed":false,"internalType":"int24","name":"lowerTick_","type":"int24"},{"indexed":false,"internalType":"int24","name":"upperTick_","type":"int24"}],"name":"FeesEarned","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"mintAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1In","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityMinted","type":"uint128"}],"name":"Minted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"lowerTick_","type":"int24"},{"indexed":false,"internalType":"int24","name":"upperTick_","type":"int24"},{"indexed":false,"internalType":"uint128","name":"liquidityBefore","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"liquidityAfter","type":"uint128"}],"name":"Rebalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"managerFeeBPS","type":"uint16"},{"indexed":false,"internalType":"address","name":"managerTreasury","type":"address"}],"name":"UpdateManagerParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[{"internalType":"uint256","name":"burnAmount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"burn","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint128","name":"liquidityBurned","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"customPriceThreshold","type":"uint256"}],"name":"checkPriceManipulation","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[],"name":"compound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositNftToFarm","outputs":[{"internalType":"bool","name":"_allocatedToFarming","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getIdentifiers","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0Desired","type":"uint256"},{"internalType":"uint256","name":"amount1Desired","type":"uint256"}],"name":"getInRatioSwap","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"bool","name":"zeroForOne","type":"bool"},{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLiquidity","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"name":"getLpPrice","outputs":[{"internalType":"uint256","name":"lpPrice","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0Max","type":"uint256"},{"internalType":"uint256","name":"amount1Max","type":"uint256"}],"name":"getMintAmounts","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"mintAmount","type":"uint256"},{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPendingReward","outputs":[{"internalType":"uint256","name":"pendingReward","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"_lowerTick","type":"int24"},{"internalType":"int24","name":"_upperTick","type":"int24"}],"name":"getPositionID","outputs":[{"internalType":"bytes32","name":"positionID","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPositionID","outputs":[{"internalType":"bytes32","name":"positionID","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPositionNftData","outputs":[{"internalType":"uint256","name":"nftId","type":"uint256"},{"internalType":"int24","name":"lowerTick_","type":"int24"},{"internalType":"int24","name":"upperTick_","type":"int24"},{"internalType":"bool","name":"allocatedToFarming","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"_lowerTick","type":"int24"},{"internalType":"int24","name":"_upperTick","type":"int24"}],"name":"getPositionNftData","outputs":[{"internalType":"uint256","name":"nftId","type":"uint256"},{"internalType":"int24","name":"lowerTick_","type":"int24"},{"internalType":"int24","name":"upperTick_","type":"int24"},{"internalType":"bool","name":"allocatedToFarming","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPricePerShareSnapshot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getTotalAmounts","outputs":[{"internalType":"uint256","name":"total0","type":"uint256"},{"internalType":"uint256","name":"total1","type":"uint256"},{"internalType":"uint128","name":"liquidity","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"initializeData","type":"bytes"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0Max","type":"uint256"},{"internalType":"uint256","name":"amount1Max","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"mintAmount","type":"uint256"},{"internalType":"uint128","name":"liquidityMinted","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"pancakeV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"newLowerTick","type":"int24"},{"internalType":"int24","name":"newUpperTick","type":"int24"},{"internalType":"uint256","name":"customSlippagePriceThreshold","type":"uint256"},{"internalType":"bytes","name":"exchangeData","type":"bytes"},{"internalType":"bool","name":"simulate","type":"bool"}],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardTokenAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_priceThreshold","type":"uint256"},{"internalType":"uint32","name":"_twapInterval","type":"uint32"}],"name":"setPriceManipulationParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_swapThreshold0","type":"uint256"},{"internalType":"uint256","name":"_swapThreshold1","type":"uint256"}],"name":"setSwapThresholds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalSharesIssued","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int16","name":"newManagerFeeBPS","type":"int16"},{"internalType":"address","name":"newManagerTreasury","type":"address"}],"name":"updateManagerParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"int24","name":"_lowerTick","type":"int24"},{"internalType":"int24","name":"_upperTick","type":"int24"}],"name":"withdrawNftFromFarm","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
0x6101206040523462000161576200002062000019620002d3565b91620002fd565b604051615e8c9081620005b48239608051818181610bad0152610c5c015260a05181818161134801528181612518015281816132e5015281816137b7015281816139c901528181613c2b01528181613e0c01528181613efa015281816140620152614c45015260c051818181611175015281816117eb01528181611cbf01528181611d84015281816122c401528181612373015281816126970152818161284c015281816138b601528181613a6801528181613f23015281816143e5015281816151b50152818161591601528181615add0152615baa015260e051818181611dbf015281816122ff015281816123ae015281816138f10152818161595101528181615b1801528181615be50152615daa0152610100518181816111b00152818161182601528181611cfa01528181613aa401528181613f5f0152615dcc0152f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b90601f01601f191681019081106001600160401b038211176200019e57604052565b62000166565b90620001bb620001b360405190565b92836200017c565b565b6001600160a01b031690565b90565b620001d781620001bd565b036200016157565b90505190620001bb82620001cc565b6001600160401b0381116200019e57602090601f01601f19160190565b0190565b60005b838110620002235750506000910152565b818101518382015260200162000212565b909291926200024d6200024782620001ee565b620001a4565b9182948284528282011162000161576020620001bb9301906200020f565b9080601f8301121562000161578151620001c99260200162000234565b916060838303126200016157620002a08284620001df565b92620002b08360208301620001df565b60408201519093906001600160401b0381116200016157620001c992016200026b565b620002f66200644080380380620002ea81620001a4565b92833981019062000288565b9192909190565b90620001bb9291620003bc565b620001c990620001bd906001600160a01b031682565b620001c9906200030a565b620001c99062000320565b6200020b62000351926020926200034b815190565b94859290565b938491016200020f565b6200036b90620001c99262000336565b6b4d616e616765722056302e3160a01b8152600c0190565b6200039390620001c99262000336565b6c53747261746567792056302e3160981b8152600d0190565b620001c9620001c9620001c99290565b620003f59192620003db6200042c92620003d5620004ac565b6200032b565b60c0526040516200040481620003f584602083016200035b565b03601f1981018352826200017c565b6200041862000411825190565b9160200190565b2060e0526040519283916020830162000383565b6200043962000411825190565b2061010052803b62000454620004506000620003ac565b9190565b14620004675760a052620001bb62000528565b60405162461bcd60e51b815260206004820152601860248201527f496e76616c6964204661726d696e6720436f6e747261637400000000000000006044820152606490fd5b620004b7306200032b565b608052565b620001c99060081c5b60ff1690565b620001c99054620004bc565b620001c990620004c5565b620001c99054620004d7565b620004c5620001c9620001c99260ff1690565b9062000515620001c96200052492620004ee565b825460ff191660ff9091161790565b9055565b620005406200053c6200053c6000620004cb565b1590565b620005a157620005516000620004e2565b60ff908116106200055e57565b6200056c60ff600062000501565b7f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024986200059760405190565b60ff8152602090a1565b604051630e02e8e160e21b8152600490fdfe6080604052600436101561001257600080fd5b60003560e01c80630910a510146102025780630e20622c146101fd578063125f9e33146101f8578063150b7a02146101f357806319903c81146101ee57806323a69e75146101e957806324ea6a19146101e45780633659cfe6146101df578063439fab91146101da5780634641257d146101d557806347243a32146101d05780634f1ef286146101cb57806352d1902d146101c657806353c9d830146101c15780635a23248d146101bc57806360e7ff04146101b75780637708c2ae146101b257806381c7e089146101ad5780639894f21a146101a8578063a4770a88146101a3578063a86aa9271461019e578063b50157ca14610199578063bbfad5b514610194578063bdc9e4101461018f578063c4a7761e1461018a578063c948660914610185578063df28408a14610180578063e7d3fe6b1461017b578063f69e204614610176578063fab2cb36146101715763fcd3533c0361021257610b57565b610b20565b610b08565b610ad6565b610a75565b610a59565b610a2f565b6109f1565b6109d8565b6109a6565b610964565b610933565b6108e0565b610855565b61083a565b6107f1565b61075f565b610747565b610708565b6106f4565b61068e565b61063d565b610625565b610521565b6104f4565b61049e565b610444565b6103ce565b6102fd565b6102b1565b610242565b600091031261021257565b600080fd5b6001600160801b031690565b61022c90610217565b9052565b6020810192916102409190610223565b565b3461021257610252366004610207565b61026961025d613142565b60405191829182610230565b0390f35b6102778160020b90565b0361021257565b905035906102408261026d565b9190604083820312610212578060206102a76102ae938661027e565b940161027e565b90565b34610212576102ca6102c436600461028b565b90613971565b604051005b6001600160a01b031690565b6102ae906102cf565b61022c906102db565b60208101929161024091906102e4565b346102125761030d366004610207565b610269610318615df9565b604051918291826102ed565b610277816102db565b9050359061024082610324565b80610277565b905035906102408261033a565b9181601f8401121561021257823591826001600160401b038111610212576020908186019501011161021257565b9060808282031261021257610390818361032d565b9261039e826020850161032d565b926103ac8360408301610340565b9260608201356001600160401b038111610212576103ca920161034d565b9091565b34610212576102696103ed6103e436600461037b565b93929092613b31565b604051918291826001600160e01b0319909116815260200190565b63ffffffff8116610277565b9050359061024082610408565b91906040838203126102125780602061043d6102ae9386610340565b9401610414565b34610212576102ca610457366004610421565b90615b9a565b91606083830312610212576104728284610340565b926104808360208301610340565b9260408201356001600160401b038111610212576103ca920161034d565b34610212576102ca6104b136600461045d565b9291909161510b565b6102778160010b90565b90503590610240826104ba565b9190604083820312610212578060206104ed6102ae93866104c4565b940161032d565b34610212576102ca6105073660046104d1565b90615acd565b90602082820312610212576102ae9161032d565b34610212576102ca61053436600461050d565b610d37565b634e487b7160e01b600052604160045260246000fd5b90601f01601f191681019081106001600160401b0382111761057057604052565b610539565b9061024061058260405190565b928361054f565b6001600160401b03811161057057602090601f01601f19160190565b0190565b90826000939282370152565b909291926105ca6105c582610589565b610575565b918294828452828201116102125760206102409301906105a9565b9080601f83011215610212578160206102ae933591016105b5565b906020828203126102125781356001600160401b038111610212576102ae92016105e5565b34610212576102ca610638366004610600565b6158da565b346102125761064d366004610207565b6102ca611d77565b6106866102409461067c60609498979561067285608081019b9052565b60020b6020850152565b60020b6040830152565b019015159052565b346102125761069e366004610207565b6102696106a9615d75565b906106b694929460405190565b94859485610655565b919091604081840312610212576106d6838261032d565b9260208201356001600160401b038111610212576102ae92016105e5565b6102ca6107023660046106bf565b9061113f565b3461021257610718366004610207565b610269610723610c3e565b6040519182918290815260200190565b90602082820312610212576102ae91610340565b34610212576102ca61075a366004610733565b6127e2565b346102125761076f366004610207565b6102696107236132ba565b801515610277565b905035906102408261077a565b909160a082840312610212576107a5838361027e565b926107b3816020850161027e565b926107c18260408301610340565b9260608201356001600160401b03811161021257836107e76080956102ae93860161034d565b9590959401610782565b34610212576102ca61080436600461078f565b94939093929192611fcc565b610277816102cf565b9050359061024082610810565b90602082820312610212576102ae91610819565b3461021257610269610723610850366004610826565b613173565b3461021257610865366004610207565b610269610870611ea9565b60405191829182901515815260200190565b91906040838203126102125780602061089e6102ae9386610340565b9401610340565b61022c906102cf565b6108d9610240946108d26060949897956108cb85608081019b9052565b6020850152565b6040830152565b01906108a5565b34610212576102696108fc6108f6366004610882565b90612936565b9061090994929460405190565b948594856108ae565b61092f610240946108d26060949897956108cb85608081019b9052565b0152565b3461021257610943366004610207565b61026961094e615d97565b9061095b94929460405190565b94859485610912565b34610212576102696106a961097a36600461028b565b90615d8a565b6108d96102409461099d6060949897956108cb85608081019b9052565b15156040830152565b34610212576102696109c26109bc366004610882565b9061268b565b906109cf94929460405190565b94859485610980565b34610212576102ca6109eb366004610882565b90615c6a565b3461021257610a01366004610207565b613ea9565b604090610a286102409496959396610a218360608101999052565b6020830152565b0190610223565b3461021257610a3f366004610207565b610269610a4a6131f3565b60405191939193849384610a06565b3461021257610269610723610a6f36600461028b565b90615cf9565b3461021257610a85366004610207565b610269610723615cec565b9091606082840312610212576102ae610aa98484610340565b9360406104ed8260208701610340565b610a28610240946108d26060949897956108cb85608081019b9052565b3461021257610269610af2610aec366004610a90565b9161144f565b90610aff94929460405190565b94859485610ab9565b3461021257610b18366004610207565b6102ca6125df565b3461021257610b30366004610207565b610269610723615def565b9190604083820312610212578060206104ed6102ae9386610340565b3461021257610269610a4a610b6d366004610b3b565b90611af9565b610b826102ae6102ae926102cf565b6102cf565b6102ae90610b73565b6102ae90610b87565b610bdc610ba530610b90565b610bd7610bd17f00000000000000000000000000000000000000000000000000000000000000006102db565b916102db565b141590565b610be9576102ae90610c35565b604051632e4771e760e21b8152600490fd5b0390fd5b6102ae6102ae6102ae9290565b6102ae7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc610bff565b506102ae610c0c565b6102ae6000610b99565b610c88610c8c610c5730610b90565b610c807f00000000000000000000000000000000000000000000000000000000000000006102db565b9283916102db565b1490565b610cc357610ca490610bd7610c9f610d4a565b6102db565b610cb15761024090610d11565b604051631b50ae3760e11b8152600490fd5b604051637170f3db60e01b8152600490fd5b90610ce26105c583610589565b918252565b369037565b90610240610cf983610cd5565b60208194610d09601f1991610589565b019101610ce7565b600061024091610d2081615226565b610d31610d2c83610bff565b610cec565b90610dc8565b61024090610c48565b6102ae90546102db565b6102ae610d586102ae610c0c565b610d40565b6102ae7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143610bff565b6102ae905b60ff1690565b6102ae9054610d86565b905051906102408261033a565b90602082820312610212576102ae91610d9b565b6040513d6000823e3d90fd5b9190610ddd610dd86102ae610d5d565b610d91565b15610ded57505061024090610ed3565b610dfe610df984610b90565b610b90565b6020610e0960405190565b6352d1902d60e01b815291829060049082905afa60009181610e73575b50610e3e5750604051636f5837f160e01b8152600490fd5b610e5490610bd7610e506102ae610c0c565b9190565b610e615761024092610f1f565b6040516304e7393f60e41b8152600490fd5b610e9591925060203d8111610e9c575b610e8d818361054f565b810190610da8565b9038610e26565b503d610e83565b90610eb36102ae610ecf92610b90565b82546001600160a01b0319166001600160a01b03919091161790565b9055565b610ee3610edf82610f0d565b1590565b610efb5761024090610ef66102ae610c0c565b610ea3565b60405163075de2d760e51b8152600490fd5b3b610f1b610e506000610bff565b1190565b91610f2983610f5e565b8151610f38610e506000610bff565b11908115610f56575b50610f4a575050565b610f5391610ff2565b50565b905038610f41565b610f6b90610df981610ed3565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b610f9560405190565b600090a2565b3d15610fb557610faa3d610cd5565b903d6000602084013e565b606090565b634e487b7160e01b600052602160045260246000fd5b60051115610fda57565b610fba565b9061024082610fd0565b6102ae90610fdf565b90610fff610edf83610f0d565b61102c576000816102ae9360208394519201905af461101c610f9b565b6110266004610fe9565b9161103e565b60405163ae931db960e01b8152600490fd5b9091901561104a575090565b8151611059610e506000610bff565b11156110685750805190602001fd5b6110756102ae6001610fe9565b8190810361108f5760405163014bd73d60e21b8152600490fd5b61109c6102ae6002610fe9565b81036110b457604051630a4d4fd160e01b8152600490fd5b6110c16102ae6003610fe9565b036110d85760405163166c491f60e11b8152600490fd5b610bfb906110e560405190565b632638bfdb60e11b81529182916004830190815260200190565b90610c8861110f610c5730610b90565b610cc35761112290610bd7610c9f610d4a565b610cb157610240916102409160019161113a81615226565b610dc8565b90610240916110ff565b9050519061024082610324565b90602082820312610212576102ae91611149565b9594939291906111997f0000000000000000000000000000000000000000000000000000000000000000610b90565b60206111a460405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015291829060249082905afa90811561125057600091611222575b506111fa610bd1336102db565b0361121057611208966112d6565b929391929091565b604051639d7b369d60e01b8152600490fd5b611243915060203d8111611249575b61123b818361054f565b810190611156565b386111ed565b503d611231565b610dbc565b6102ae9081565b6102ae9054611255565b634e487b7160e01b600052601160045260246000fd5b9190820180921161128957565b611266565b906102ae6102ae610ecf92610bff565b90959492610240946112cf610a28926112c86080966112c18760a081019d6102e4565b6020870152565b6040850152565b6060830152565b5050505092906112e66000610bff565b9182851480611446575b6114345761132d7f55801cfe493000b734571da1694b21e7f66b11e8ce9fdaa0524ecb59105e73e79261137f96611325614b2d565b505050612936565b509691879561133a615d75565b9250505060001461142057827f0000000000000000000000000000000000000000000000000000000000000000915b8084116113f8575b81116113b9575b5050613588565b93919690956113b485888a6113a76113a08761139b606961125c565b61127c565b606961128e565b6040515b9586958661129e565b0390a1565b6113f1916113df826113ce610df96068610d40565b6113d730610b90565b9033906114ab565b6113ec610df96068610d40565b611531565b3882611378565b611409846113ce610df96067610d40565b61141b84846113ec610df96067610d40565b611371565b8261142e610df9606b610d40565b91611369565b60405163162908e360e11b8152600490fd5b508282146112f0565b611208929190600080808061116a565b6114786114726102ae9263ffffffff1690565b60e01b90565b6001600160e01b03191690565b60409061092f61024094969593966114a18360608101996102e4565b60208301906102e4565b90916114ee906114e0610240956114c56323b872dd61145f565b926114cf60405190565b968794602086015260248501611485565b03601f19810184528361054f565b6115f1565b91602061024092949361092f8160408101976102e4565b61022c90610bff565b91602061024092949361152a8160408101976102e4565b019061150a565b611563919261157161154663095ea7b361145f565b9161155060405190565b94859184602084015287602484016114f3565b03601f19810185528461054f565b61157e610edf8484611763565b611589575b50505050565b6115c7936115c16114ee926115b360006115a260405190565b948593602085015260248401611513565b03601f19810183528261054f565b826115f1565b38808080611583565b905051906102408261077a565b90602082820312610212576102ae916115d0565b6115fd61160491610b90565b918261166b565b8051611613610e506000610bff565b14159081611647575b506116245750565b610bfb9061163160405190565b635274afe760e01b8152918291600483016102ed565b61166591508060208061165b610edf945190565b83010191016115dd565b3861161c565b6102ae916116796000610bff565b61168230610b90565b818131106116ac5750600082819260206102ae969551920190855af16116a6610f9b565b916116cf565b610bfb906116b960405190565b63cd78605960e01b8152918291600483016102ed565b906116da5750611734565b6116f56116e5835190565b6116ef6000610bff565b91829190565b149081611729575b50611706575090565b610bfb9061171360405190565b639996b31560e01b8152918291600483016102ed565b9050813b14386116fd565b8051611743610e506000610bff565b111561175157805190602001fd5b604051630a12f52160e11b8152600490fd5b600061176f8192610b90565b9260208151910182855af190611783610f9b565b826117a3575b5081611793575090565b90503b610f1b610e506000610bff565b9091506117ae815190565b6117bb610e506000610bff565b149081156117cc575b509038611789565b6117dc915060208061165b835190565b386117c4565b9392919061180f7f0000000000000000000000000000000000000000000000000000000000000000610b90565b602061181a60405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015291829060249082905afa90811561125057600091611885575b50611870610bd1336102db565b036112105761187e946118d1565b9192909190565b61189d915060203d81116112495761123b818361054f565b38611863565b9190820391821161128957565b6102ae6102ae6102ae92610217565b6118cc6102ae6102ae9290565b610217565b50505091906118e06000610bff565b91838314848115611ae3575b50611434576118f9614b2d565b505050611906606961125c565b61193e61193982611933611918613142565b61192e6113a08b611929606961125c565b6118a3565b6118b0565b88611bc0565b611b63565b94859361194b60006118bf565b61195488610217565b146114345761196e87611965615d75565b92915050613c15565b93909761197e610df96067610d40565b9861198830610b90565b9061199260405190565b6020816370a0823160e01b9d8e825281806119b088600483016102ed565b03915afa801561125057826119e1878a6119dc611a12976119e796602098600091611acc575b506118a3565b611bc0565b9061127c565b92839c6119f7610df96068610d40565b90611a0160405190565b8095819482938352600483016102ed565b03915afa968715611250576119e16113b495886119dc847f7239dff1718b550db7f36cbf69c665cfeb56d0e96b4fb76a5cba712961b655099c611a5c97600091611aae57506118a3565b90819980611a678390565b11611a97575b8211611a7b576040516113ab565b611a928286611a8d610df96068610d40565b611b87565b6113a7565b611aa98287611a8d610df96067610d40565b611a6d565b611ac6915060203d8111610e9c57610e8d818361054f565b386119d6565b611ac69150893d8111610e9c57610e8d818361054f565b9050611af26102ae606961125c565b10386118ec565b61187e9190600080806117e2565b15611b0e57565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608490fd5b6102ae90611b82611b7a6001600160801b036118b0565b821115611b07565b6118bf565b6114ee610240936114e0611b9e63a9059cbb61145f565b91611ba860405190565b9586936020850152602484016114f3565b1561021257565b90919060001983820991838202928380821091030391611be06000610bff565b8390808214611ca55750948291611c016102ae97611bfb8590565b11611bb9565b09611c9d611c30611c1784196105a56001610bff565b8416809404946001858060000304019087851190030290565b93611c42611c4682611c426003610bff565b0290565b611c98611c92611c89611c80611c77611c6e611c626002610bff565b96871889810288030290565b80890287030290565b80880286030290565b80870285030290565b80860284030290565b80940290565b900390565b930304170290565b9295505050611cb69150611bfb8490565b0490565b611ce37f0000000000000000000000000000000000000000000000000000000000000000610b90565b6020611cee60405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015291829060249082905afa90811561125057600091611d51575b50611d44610bd1336102db565b0361121057610240611d6f565b611d69915060203d81116112495761123b818361054f565b38611d37565b610f53613ee7565b610240611cba565b611da87f0000000000000000000000000000000000000000000000000000000000000000610b90565b6020611db360405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015291829060249082905afa90811561125057600091611e17575b50611e09610bd1336102db565b03611210576102ae90611e6f565b611e2f915060203d81116112495761123b818361054f565b38611dfc565b90600052602052604060002090565b90611e546102ae610ecf92151590565b82549060ff60301b9060301b60ff60301b1990921691161790565b50611e78615cec565b90611e8282615d19565b91505061021257611e9561024091613db0565b6001611ea38295606c611e35565b01611e44565b6102ae6000611d7f565b6102ae905b60020b90565b6102ae9054611eb3565b634e487b7160e01b600052601260045260246000fd5b611eed9060020b5b9160020b90565b908115611ef8570790565b611ec8565b611eb86102ae6102ae9290565b611eb86102ae6102ae9260020b90565b90611f2a6102ae610ecf92611f0a565b825462ffffff191662ffffff9091161790565b90611f4d6102ae610ecf92611f0a565b825465ffffff000000191660189190911b65ffffff000000161790565b6102ae9060181c611eb8565b6102ae9054611f6a565b916020610240929493611f9981604081019760020b9052565b019060020b9052565b610a2861024094611fc260609498979561067285608081019b60020b9052565b6040830190610223565b9194909391928115806122be575b61121057611fe88560020b90565b611ff28560020b90565b12801590612296575b801561226e575b61225c57600080612013606961125c565b612020610e506000610bff565b111561223c575050612030613142565b95869361203d60006118bf565b978861204882610217565b116121e8575b5061205a866065611f1a565b612065876065611f3d565b612072610df96067610d40565b9261207c30610b90565b9261208660405190565b936020856370a0823160e01b9788825281806120a586600483016102ed565b03915afa948515611250576000956121c2575b506020906120e995966120ce610df96068610d40565b906120d860405190565b8098819482938352600483016102ed565b03915afa8015611250576121079587956000926121a2575b50613ff8565b61210f613142565b9461211986610217565b14612190575b61215b577fc749f9ae947d4734cf1569606a8a347391ae94a063478aa853aeff48ac5f99e8936113b49161215260405190565b94859485611fa2565b6121656065611ebe565b61218b6121726065611f76565b916115b361217f60405190565b93849260208401611f80565b615e06565b604051631f2a200560e01b8152600490fd5b6121bb91925060203d8111610e9c57610e8d818361054f565b9038612101565b6120e99550906121e0602092833d8111610e9c57610e8d818361054f565b9550906120b8565b612211906121f4614b2d565b5050506121ff615d75565b80938196939695929561222e57613c15565b505061221e575b5061204e565b61222791613993565b3880612218565b612236613ee7565b50613c15565b935095505061224c836065611f1a565b612257846065611f3d565b61211f565b6040516333a3bdff60e21b8152600490fd5b5061228261227c606d611ebe565b86611ede565b61228f611ee66000611efd565b1415612002565b506122aa6122a4606d611ebe565b85611ede565b6122b7611ee66000611efd565b1415611ffb565b506122e87f0000000000000000000000000000000000000000000000000000000000000000610b90565b60206122f360405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015291829060249082905afa90811561125057600091612350575b50612349610bd1336102db565b1415611fda565b612368915060203d81116112495761123b818361054f565b3861233c565b6123977f0000000000000000000000000000000000000000000000000000000000000000610b90565b60206123a260405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015291829060249082905afa90811561125057600091612405575b506123f8610bd1336102db565b0361121057610240612423565b61241d915060203d81116112495761123b818361054f565b386123eb565b61242b614b2d565b50505061243b610df96067610d40565b61244430610b90565b9061244e60405190565b916020836370a0823160e01b93848252818061246d86600483016102ed565b03915afa908115611250576124b1936000926125bf575b5060209192612496610df96068610d40565b906124a060405190565b8096819482938352600483016102ed565b03915afa9182156112505760009261259f575b506124cf6000610bff565b9182821480612596575b61254c576124e691612936565b5050906124f08190565b8381148061258d575b611583578261254c9461250a615d75565b9250505060001461257957807f0000000000000000000000000000000000000000000000000000000000000000935b11612562575b8111612551575050613588565b505050565b6113f1916113ec610df96068610d40565b61257484846113ec610df96067610d40565b61253f565b80612587610df9606b610d40565b93612539565b508383146124f9565b508281146124d9565b6125b891925060203d8111610e9c57610e8d818361054f565b90386124c4565b602092506125d990833d8111610e9c57610e8d818361054f565b91612484565b61024061236e565b7ff98f8de0e40e1ae544b53961cd5e87fbc36fdc8ea99f85e11da8da2e496d48ce90565b9050519061024082610810565b6080818303126102125761262c8282610d9b565b926102ae61263d8460208501610d9b565b93606061264d82604087016115d0565b940161260b565b90959492610240946112cf61092f926126816080966126778760a081019d6102e4565b60020b6020870152565b60020b6040850152565b906126eb9060206126bb7f0000000000000000000000000000000000000000000000000000000000000000610b90565b6126c36125e7565b906126cd60405190565b94859283918291636f7a8bad60e01b5b835260048301526024820190565b03915afa801561125057610df961270d916080946000916127ac575b50610b90565b61271a610df96066610d40565b6127246065611ebe565b906127576127326065611f76565b9461273c60405190565b97889687958695636b386e3760e01b5b875260048701612654565b03915afa8015611250576000928380938193612775575b5093929190565b925050925061279b915060803d81116127a5575b612793818361054f565b810190612618565b919390923861276e565b503d612789565b6127c4915060203d81116112495761123b818361054f565b38612707565b6102ae905b63ffffffff1690565b6102ae90546127ca565b6127ec6000610bff565b81036128105750610240612800607061125c565b61280a60716127d8565b90612841565b61024090612800565b6040906128356102409496959396610a218360608101996102e4565b019063ffffffff169052565b9061289660206128707f0000000000000000000000000000000000000000000000000000000000000000610b90565b6128786125e7565b9061288260405190565b93849283918291636f7a8bad60e01b6126dd565b03915afa908115611250576128b691610df9916000916127ac5750610b90565b906128c4610df96066610d40565b91803b15610212576128f6936000936128dc60405190565b958694859384936345cede6d60e11b855260048501612819565b03915afa8015611250576129075750565b610240906000612917818361054f565b810190610207565b6102ae6a0c097ce7bc90715b34b9f160241b610bff565b61297f61294b6129466066610d40565b6129f6565b5091829361295884613173565b9361296b6129666065611ebe565b612b6b565b916129796129666065611f76565b936140bb565b9290938261299b8561139b8861299361291f565b978891611bc0565b9081946129a8606961125c565b6129b5610e506000610bff565b036129bf57505050565b6129f39395506129dc6129ed916129d46131f3565b509490611bc0565b916129e7606961125c565b9261127c565b91611bc0565b91565b6103ca90612a0e610df9633850c7bd60e01b92610b90565b60046000809260409482525afa15610212576000519060205190565b6102ae6102ae6102ae9260020b90565b600160ff1b81146112895760000390565b6102ae620d89e719611efd565b60020b627fffff1981146112895760000390565b6102ae612a77612a4b565b612a58565b612a8c6102ae6102ae9260020b90565b62ffffff1690565b6102ae6102ae6102ae9262ffffff1690565b15612aad57565b60405162461bcd60e51b81526020600482015260016024820152601560fa1b6044820152606490fd5b612ae36102ae6102ae9290565b6001600160881b031690565b6102ae9081906001600160881b031681565b8181029291811591840414171561128957565b610d8b6102ae6102ae9290565b6102ae90612b35610e506102ae9460ff1690565b901c90565b8115611ef8570490565b8115611ef8570690565b6102ae6102ae6102ae9260ff1690565b610b826102ae6102ae9290565b612dfd6102ae91612bef612b7f6000611efd565b612b898360020b90565b928184121561313057612ba6612ba1612bab92612a2a565b612a3a565b610bff565b925b612bd3612bcb6102ae612bc6612bc1612a6c565b612a7c565b612a94565b851115612aa6565b612bdd6001610bff565b8416612be96000610bff565b93849190565b1461312057612c15612c106ffffcb933bd6fad37aa2d162d1a594001612ad6565b612aef565b938484612c2a612c256002610bff565b841690565b036130f6575b5083612c44612c3f6004610bff565b831690565b036130cf575b83612c58612c3f6008610bff565b036130a8575b83612c6c612c3f6010610bff565b03613081575b83612c80612c3f6020610bff565b0361305a575b83612c94612c3f6040610bff565b03613033575b83612ca8612c3f6080610bff565b0361300c575b83612cbd612c3f610100610bff565b03612fe5575b83612cd2612c3f610200610bff565b03612fbe575b83612ce7612c3f610400610bff565b03612f97575b83612cfc612c3f610800610bff565b03612f70575b83612d11612c3f611000610bff565b03612f49575b83612d26612c3f612000610bff565b03612f22575b83612d3b612c3f614000610bff565b03612efb575b83612d50612c3f618000610bff565b03612ed4575b83612d66612c3f62010000610bff565b03612ead575b83612d7c612c3f62020000610bff565b03612e87575b83612d92612c3f62040000610bff565b03612e5b575b612dad8491612da962080000610bff565b1690565b03612e22575b13612e0f575b612de66102ae612dd2612dcc6020612b14565b85612b21565b93612de0600160201b610bff565b90612b44565b03612e02576119e1612df86000612b14565b612b4e565b612b5e565b6119e1612df86001612b14565b90612e1c90600019612b3a565b90612db9565b92612e45612e5591612e3f6b048a170391f7dc42444e8fa2610bff565b90612b01565b612e4f6080612b14565b90612b21565b92612db3565b93612dad612e7e612e458693612e3f6d2216e584f5fa1ea926041bedfe98610bff565b95915050612d98565b93612e45612ea791612e3f6e5d6af8dedb81196699c329225ee604610bff565b93612d82565b93612e45612ece91612e3f6f09aa508b5b7a84e1c677de54f3e99bc9610bff565b93612d6c565b93612e45612ef591612e3f6f31be135f97d08fd981231505542fcfa6610bff565b93612d56565b93612e45612f1c91612e3f6f70d869a156d2a1b890bb3df62baf32f7610bff565b93612d41565b93612e45612f4391612e3f6fa9f746462d870fdf8a65dc1f90e061e5610bff565b93612d2c565b93612e45612f6a91612e3f6fd097f3bdfd2022b8845ad8f792aa5825610bff565b93612d17565b93612e45612f9191612e3f6fe7159475a2c29b7443b29c7fa6e889d9610bff565b93612d02565b93612e45612fb891612e3f6ff3392b0822b70005940c7a398e4b70f3610bff565b93612ced565b93612e45612fdf91612e3f6ff987a7253ac413176f2b074cf7815e54610bff565b93612cd8565b93612e4561300691612e3f6ffcbe86c7900a88aedcffc83b479aa3a4610bff565b93612cc3565b93612e4561302d91612e3f6ffe5dee046a99a2a811c461f1969c3053610bff565b93612cae565b93612e4561305491612e3f6fff2ea16466c96a3843ec78b326b52861610bff565b93612c9a565b93612e4561307b91612e3f6fff973b41fa98c081472e6896dfb254c0610bff565b93612c86565b93612e456130a291612e3f6fffcb9843d60f6159c9db58835c926644610bff565b93612c72565b93612e456130c991612e3f6fffe5caca7e10e4e61c3624eaa0941cd0610bff565b93612c5e565b93612e456130f091612e3f6ffff2e50f5f656932ef12357cf3c7fdcc610bff565b93612c4a565b613119919550612e4590612e3f6ffff97272373d413259a46990580e213a610bff565b9338612c30565b612c15612c10600160801b612ad6565b612ba661313c91612a2a565b92612bad565b6102ae61314d615d75565b505050615004565b610b826102ae6102ae92610217565b6102ae6102ae6102ae926102cf565b6131836001600160801b03613155565b61318c826102cf565b116131bb576131a66131a06102ae92613164565b80612b01565b6131ae61291f565b6129ed600160c01b610bff565b6131de6131ca6102ae92613164565b6131d7600160401b610bff565b9080611bc0565b6131e661291f565b6129ed600160801b610bff565b6131fb614f22565b90929161320b610df96067610d40565b9361321530610b90565b9161321f60405190565b926020846370a0823160e01b98898252818061323e86600483016102ed565b03915afa9384156112505761326e94602093613260926000926132a257500190565b96612496610df96068610d40565b03915afa908115611250576129f39260009261328957500190565b6105a591925060203d8111610e9c57610e8d818361054f565b6105a5919250853d8111610e9c57610e8d818361054f565b6132c2615d75565b5050506132cf6000610bff565b80821461334e5750602061332091613309610df97f0000000000000000000000000000000000000000000000000000000000000000610b90565b6040519384928391829163672f9ce360e11b6126dd565b03915afa90811561125057600091613336575090565b6102ae915060203d8111610e9c57610e8d818361054f565b905090565b6102ae60c0610575565b61027781610217565b905051906102408261335d565b9091606082840312610212576102ae61338c8484613366565b93604061339c8260208701610d9b565b9401610d9b565b9060a080610240936133b58482519052565b6133c460208201516020860152565b6133d360408201516040860152565b6133e260608201516060860152565b6133f160808201516080860152565b0151910152565b60c08101929161024091906133a3565b6102ae9060401c612a8c565b6102ae9054613408565b6102ae610160610575565b9061022c906102db565b608081830312610212576134478282610d9b565b926102ae6134588460208501613366565b93606061339c8260408701610d9b565b90610140806102409361347c8482516102e4565b61348e602082015160208601906102e4565b60408181015162ffffff169085015260608181015160020b9085015260808181015160020b908501526134c660a082015160a0860152565b6134d560c082015160c0860152565b6134e460e082015160e0860152565b6134f5610100820151610100860152565b6133f16101208201516101208601906102e4565b610160810192916102409190613468565b6102ae6080610575565b90613578606060016102409461354161353b865190565b8261128e565b019261355a613554602083015160020b90565b85611f1a565b61357161356b604083015160020b90565b85611f3d565b0151151590565b90611e44565b9061024091613524565b6135a56135956065611ebe565b61359f6065611f76565b90615caf565b926135af84615d19565b94915050816135be868361508c565b613892576135cc6000610bff565b928381036137935750506135e0606b610d40565b6135e990610b90565b916135f46067610d40565b6135fd90610b90565b956136086068610d40565b61361190610b90565b9261361c6065613414565b6136266065611ebe565b6136306065611f76565b9161363a30610b90565b9661364361341e565b9b61364e908d613429565b61365b9060208d01613429565b62ffffff1660408b015260020b60608a015260020b608089015260a088015260c087015261368a8160e0880152565b61010086015261369e906101208601613429565b6136aa42610140860152565b6040519384908190634418b22b60e11b82526136c99060048301613509565b03815a608094600091f193841561125057600090819582958391613757575b5061373690959694610edf8461371f6137016065611ebe565b61067c61370e6065611f76565b9161067261371a61351a565b958652565b6000606082015261373185606c611e35565b61357e565b61373e575050565b6001611ea361374f61024094613db0565b92606c611e35565b919550506137369550613781915060803d811161378c575b613779818361054f565b810190613433565b9196909591906136e8565b503d61376f565b916060926137fd61382693956137ec60009a8a8c14613882576112c86137db610df97f0000000000000000000000000000000000000000000000000000000000000000610b90565b966112c16137e7613353565b978852565b6137f68187850152565b6080830152565b6138084260a0830152565b604051978893849283919063219f5d1760e01b8352600483016133f8565b03925af19485156112505760009586958791613847575b5094959315613736565b9050613736965061387091955060603d811161387b575b613868818361054f565b810190613373565b95919690959061383d565b503d61385e565b6112c86137db610df9606b610d40565b505050925050506138a36000610bff565b9081906102ae60006118bf565b906138da7f0000000000000000000000000000000000000000000000000000000000000000610b90565b60206138e560405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015291829060249082905afa90811561125057600091613949575b5061393b610bd1336102db565b036112105761024091613967565b613961915060203d81116112495761123b818361054f565b3861392e565b9061024091613993565b90610240916138b0565b908152604081019291610240916020905b01906102e4565b9061399d91615caf565b6139a681615d19565b929150506139b46000610bff565b808214611583576020613a20926139ed610df97f0000000000000000000000000000000000000000000000000000000000000000610b90565b6139f630610b90565b916000613a0260405190565b809781958294613a1562f714ce60e01b90565b84526004840161397b565b03925af191821561125057600092613b11575b508111613a55575b50613a435750565b60006001611ea361024093606c611e35565b613a62610df9606a610d40565b90613a8c7f0000000000000000000000000000000000000000000000000000000000000000610b90565b916020613a9860405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015293849060249082905afa90811561125057613aeb93600092613af1575b50611b87565b38613a3b565b613b0a91925060203d81116112495761123b818361054f565b9038613ae5565b613b2a91925060203d8111610e9c57610e8d818361054f565b9038613a33565b50505050506102ae63150b7a0261145f565b6102ae60a0610575565b9061022c90610217565b91906040838203126102125780602061339c6102ae9386610d9b565b9060808061024093613b858482519052565b613b9760208201516020860190610223565b613ba660408201516040860152565b6133f160608201516060860152565b60a0810192916102409190613b73565b9060608061024093613bd78482519052565b613be9602082015160208601906102e4565b613bfb60408201516040860190610223565b0151910190610223565b6080810192916102409190613bc5565b92613cab92909115613da1576040613c4f610df97f0000000000000000000000000000000000000000000000000000000000000000610b90565b91613c6d613c5b613b43565b91613c64888452565b60208301613b4d565b613c84613c7a6000610bff565b6112cf8185850152565b613c8f426080830152565b604051948591829190630624e65f60e11b835260048301613bb5565b03816000855af18015611250576000938491613d74575b50613d386000926040929596613cf3613cda30610b90565b613cea613ce561351a565b938452565b60208301613429565b613d066001600160801b03828601613b4d565b613d1a6001600160801b0360608301613b4d565b604051948593849283919063fc6f786560e01b835260048301613c05565b03925af1801561125057613d495750565b613d699060403d8111613d6d575b613d61818361054f565b810190613b57565b5050565b503d613d57565b600092945060409150613d96613d3891833d8111613d6d57613d61818361054f565b909593509150613cc2565b6040613c4f610df9606b610d40565b90600091613dbe6000610bff565b8114613e6757613dd1610df9606b610d40565b90613ddb30610b90565b90823b1561021257613e359260009283613df460405190565b809681958294613e086342842e0e60e01b90565b84527f00000000000000000000000000000000000000000000000000000000000000009060048501611485565b03925af19081613e51575b50613e4b5760009150565b60019150565b613e61906000612917818361054f565b38613e40565b5060009150565b91946137f661092f92989795613ea260a096613e9b6102409a613e948960c081019f9052565b6020890152565b6040870152565b6060850152565b61218b613eb46131f3565b5091906115b3613ec2614b2d565b909150613ecd613ee7565b91613ed8606961125c565b60405197889660208801613e6e565b613eef615d75565b505050613f1e610df97f0000000000000000000000000000000000000000000000000000000000000000610b90565b613f477f0000000000000000000000000000000000000000000000000000000000000000610b90565b906020613f5360405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015292839060249082905afa90811561125057613fc393602093600093613fd9575b506000613faf60405190565b809681958294613a156318fccc7660e01b90565b03925af190811561125057600091613336575090565b613ff1919350843d81116112495761123b818361054f565b9138613fa3565b9061254c959161402395949394614012612800607061125c565b8061401d6000610bff565b97889190565b036140a7575061403393506143d5565b9290915b81810361409e575061404c612800607061125c565b614054615d75565b9250505060001461408a57827f0000000000000000000000000000000000000000000000000000000000000000915b8084612539565b82614098610df9606b610d40565b91614083565b61404c90612800565b9150506140b3926147c2565b929091614037565b6103ca949293916140ce918484876140d4565b9261425a565b936140de836102cf565b6140e7836102cf565b11614165575b6140f6826102cf565b94614100816102cf565b9586116141135750506102ae935061419f565b9290939194614121826102cf565b11156141595782916141379161413d959461419f565b93614224565b61414681610217565b61414f83610217565b101561334e575090565b9150506102ae92614224565b9091906140ed565b6102ae600160601b610bff565b61418661418c916102cf565b916102cf565b9003906001600160a01b03821161128957565b916141f5916102ae936141b1826102cf565b6141ba826102cf565b116141fa575b6141f06129ed916141ea6141d261416d565b6141db83613164565b6141e487613164565b90611bc0565b9361417a565b613164565b614200565b906141c0565b9061024061420d836118bf565b61421e614218829590565b916118b0565b14611bb9565b916141f5916102ae93614236826102cf565b61423f826102cf565b11614254575b6141f06129ed916141ea61416d565b90614245565b90939290916000928361426c836102cf565b614275886102cf565b116142d9575b614284876102cf565b61428d836102cf565b9081116142a2575050506129f3929394614304565b90919394506142b0836102cf565b11156142cd5750906142c7836102ae949383614304565b94614367565b946102ae939250614367565b95919561427b565b6102ae6060612b14565b6102ae906142ff610e506102ae9460ff1690565b901b90565b906102ae92614312826102cf565b61431b846102cf565b1161435f575b61435991614342614334614353936118b0565b61433c6142e1565b906142eb565b906129ed6143536141f0878461417a565b91613164565b90612b3a565b909190614321565b61438c906102ae9392614379816102cf565b614382836102cf565b116143a05761417a565b6141e461435361439a61416d565b936118b0565b9061417a565b91946143cc6108d992989795613ea260a096613e9b6102409a613e948960c081019f9052565b15156080830152565b90929060009061440960206128707f0000000000000000000000000000000000000000000000000000000000000000610b90565b03915afa9081156112505761442c610df984936080936000916127ac5750610b90565b614439610df96066610d40565b906144446065611ebe565b61444e6065611f76565b926144708b61445c60405190565b98899687958695636b386e3760e01b61274c565b03915afa801561125057600080938192614549575b506144a1610e508293968660001461453f5761334e606e61125c565b111561451b576144dd6144b484836145fa565b976144d889946000858860001461450a576105a591506144d46000610bff565b0390565b980190565b955b6144e95750505050565b859361218b9388936115b3936144fe60405190565b978896602088016143a6565b6144d461451692610bff565b9a0190565b509493915061452a6000610bff565b806145386129466066610d40565b50936144df565b61334e606f61125c565b91505061456591925060803d81116127a557612793818361054f565b93929150929038614485565b6102ae73fffd8963efd1fc6a506488495d951d5263988d26612b5e565b6102ae6401000276a3612b5e565b6141866145a8916102cf565b01906001600160a01b03821161128957565b91936145df60a0946112c86102ae976145d6876145e9976102e4565b15156020870152565b60608301906108a5565b816080820152016000815260200190565b81156146cc57604061461d61460d61458e565b6146176001612b5e565b9061459c565b915b61462c610df96066610d40565b84600061464161463b30610b90565b94614746565b9361466861464e60405190565b97889687958694630251596160e31b8652600486016145ba565b03925af1908115611250576102ae9260009182936146aa575b501561469b575061469190610bff565b6144d46000610bff565b6146a59150610bff565b614691565b9092506146c5915060403d8111613d6d57613d61818361054f565b9138614681565b60406146e36146d9614571565b6143a06001612b5e565b9161461f565b156146f057565b60405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608490fd5b6102ae90612ba661475e836001600160ff1b03610bff565b8211156146e9565b916060838303126102125761477b828461032d565b926147898360208301610782565b9260408201356001600160401b038111610212576102ae92016105e5565b6040906108d96102409496959396610a218360608101999052565b6147d56147dd9161481893810190614766565b929091610b90565b90156148ff576148076147f3610df96067610d40565b926148016000198486611531565b8261494a565b506148126000610bff565b91611531565b614825610df96067610d40565b9161482f30610b90565b604051906020826370a0823160e01b96878252818061485186600483016102ed565b03915afa9081156112505761487b926000926148dd575b506020908296612496610df96068610d40565b03915afa918215611250576000926148bd575b508193614899575050565b61218b906115b36148ad6129466066610d40565b50604051948593602085016147a7565b6148d691925060203d8111610e9c57610e8d818361054f565b903861488e565b60209192506148f890823d8111610e9c57610e8d818361054f565b9190614868565b6148076147f3610df96068610d40565b614919601e610cd5565b7f416464726573733a206c6f772d6c6576656c2063616c6c206661696c65640000602082015290565b6102ae61490f565b6102ae916149586000610bff565b90614961614942565b926149c2565b1561496e57565b60405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608490fd5b90600080916102ae95946149e26149d830610b90565b8290311015614967565b60208251920190855af16149f4610f9b565b91614a46565b15614a0157565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b91929015614a7857508151614a5e610e506000610bff565b14614a67575090565b614a736102ae91610f0d565b6149fa565b82614ae6565b60005b838110614a915750506000910152565b8181015183820152602001614a81565b614ac2614acb6020936105a593614ab6815190565b80835293849260200190565b95869101614a7e565b601f01601f191690565b9060206102ae928181520190614aa1565b90614aef825190565b614afc610e506000610bff565b1115614b0b5750805190602001fd5b610bfb90614b1860405190565b62461bcd60e51b815291829160048301614ad5565b61187e614b52565b611f996102409461067c6060949897956108cb85608081019b9052565b600080614b5d615d75565b614b6a6000979497610bff565b808814614df65750614b7b87615004565b9687614b90614b8a60006118bf565b91610217565b11614b9b5750505050565b919450919450614bae610df96067610d40565b614bb730610b90565b604051926020846370a0823160e01b948582528180614bd987600483016102ed565b03915afa93841561125057600094614dd6575b50614bfa610df96068610d40565b946020614c0660405190565b80978682528180614c1a88600483016102ed565b03915afa95861561125057600096614daa575b50614c826000926040928414614d9d57614c69610df97f0000000000000000000000000000000000000000000000000000000000000000610b90565b90614c75610ce261351a565b613cf38660208301613429565b03925af1801561125057614d7f575b50614c9f610df96067610d40565b906020614cab60405190565b80938582528180614cbf86600483016102ed565b03915afa91821561125057614cf094602093614ce292600091614d6857506118a3565b92612496610df96068610d40565b03915afa918215611250577f96cdf6990078e09c90b811caef18d461056ba3c9bb37d628b0d0ee82963b169193614d4293614d3292600091611aae57506118a3565b90614d3d8282614e4d565b614ede565b90614d5c82958297614d5360405190565b94859485614b35565b0390a138808080611583565b611ac69150853d8111610e9c57610e8d818361054f565b614d969060403d8111613d6d57613d61818361054f565b9050614c91565b614c69610df9606b610d40565b6040919650600092614dcc614c829260203d8111610e9c57610e8d818361054f565b9792509250614c2d565b614def91945060203d8111610e9c57610e8d818361054f565b9238614bec565b9550505050925050614e0860006118bf565b918190565b6102ae9060301c5b61ffff1690565b6102ae9054614e0d565b6102ae6102ae6102ae9261ffff1690565b6102ae9060581c6102cf565b6102ae9054614e37565b614e8890614e7a614e66614e616065614e1c565b614e26565b91614e72612710610bff565b928391611bc0565b926141e4614e616065614e1c565b90614e936000610bff565b90818111614ec7575b508111614ea65750565b61024090614eb7610df96068610d40565b614ec16065614e43565b90611b87565b614ed890614eb7610df96067610d40565b38614e9c565b91906102ae90611c98614f0e614ef7614e616065614e1c565b95611c98614f06612710610bff565b809883611bc0565b94614f1c614e616065614e1c565b83611bc0565b6000908190614f2f615d75565b509291614f3c6000610bff565b808214614fa35750614f4d90615004565b908193614f5a60006118bf565b614f6384610217565b11614f6d57505050565b9091929550614f9e939450614f98614f92614f8b6129466066610d40565b5093612b6b565b91612b6b565b9161425a565b919092565b9550505091505081906102ae60006118bf565b614fc0602a610cd5565b7f5048797065724c506f6f6c53776170496e736964653a206765744c69717569646020820152691a5d1e4819985a5b195960b21b604082015290565b6102ae614fb6565b61500e6000610bff565b811461506857615063610100916115b361505561502e610df9606b610d40565b9261503860405190565b63133f757160e31b60208201529283916024830190815260200190565b61505d614ffc565b91615073565b015190565b506102ae60006118bf565b6000806102ae9493602081519101845afa6149f4610f9b565b6150af906150bb926150a16129466066610d40565b5061296b6129666065611ebe565b91906116ef6000610bff565b1491826150c757505090565b14919050565b156150d457565b60405162461bcd60e51b815260206004820152600f60248201526e31b0b6363130b1b59031b0b63632b960891b6044820152606490fd5b91509150615131615122610c9f610df96066610d40565b61512b336102db565b146150cd565b61513b6000610bff565b808213156151675750610240915061515f615159610df96067610d40565b91610bff565b903390611b87565b905081136151725750565b6102409061515f615159610df96068610d40565b7f12e0d3ce89f556b797246ec55ba4b224e777f2c6e71e1d520ead0ade815ddf6190565b506151e160206151d97f0000000000000000000000000000000000000000000000000000000000000000610b90565b612878615186565b03915afa90811561125057600091615208575b50615201610bd1336102db565b0361121057565b615220915060203d81116112495761123b818361054f565b386151f4565b610240906151aa565b6102ae9060081c610d8b565b6102ae905461522f565b610d8b6102ae6102ae9260ff1690565b906152656102ae610ecf92615245565b825460ff191660ff9091161790565b906152846102ae610ecf92151590565b825461ff00191660089190911b61ff00161790565b61022c90612b14565b6020810192916102409190615299565b6152bf610edf600061523b565b9081806153a5575b8015615360575b155b61534e576152f690826152ed6152e66001612b14565b6000615255565b61533d576155d3565b6152fc57565b615307600080615274565b7f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249861533160405190565b806113b46001826152a2565b61534960016000615274565b6155d3565b604051632785437f60e21b8152600490fd5b50615375610edf61537030610b90565b610f0d565b80156152ce57506152d06153896000610d91565b61539d6153966001612b14565b9160ff1690565b1490506152ce565b506153b06000610d91565b6153bd6153966001612b14565b106152c7565b61ffff8116610277565b90505190610240826153c3565b905051906102408261026d565b9050519061024082610408565b9190610160838203126102125761540b8184611149565b9261541982602083016153cd565b9261542783604084016153da565b9261543581606085016153da565b926154438260808301611149565b926154518360a08401611149565b9261545f8160c08501611149565b9261546d8260e08301610d9b565b926102ae61547f846101008501610d9b565b93610140615491826101208701610d9b565b94016153e7565b62ffffff8116610277565b9050519061024082615498565b90602082820312610212576102ae916154a3565b612a8c6102ae6102ae9262ffffff1690565b906154e66102ae610ecf926154c4565b82549062ffffff60401b9060401b62ffffff60401b1990921691161790565b90602082820312610212576102ae916153da565b614e156102ae6102ae9290565b614e156102ae6102ae9261ffff1690565b906155476102ae610ecf92615526565b82549061ffff60301b9060301b61ffff60301b1990921691161790565b906155746102ae610ecf92610b90565b825490600160581b600160f81b039060581b600160581b600160f81b031990921691161790565b6127cf6102ae6102ae9263ffffffff1690565b906155be6102ae610ecf9261559b565b825463ffffffff191663ffffffff9091161790565b61563561562261561c61561c61562861560661562e966155f1615908565b6020806155fc835190565b83010191016153f4565b9e95999f949a93979d92969c91989b909f610b90565b98610b90565b94610b90565b95610b90565b6066610ea3565b615642610df96066610d40565b602061564d60405190565b63ddca3f4360e01b815291829060049082905afa80156112505761567b916000916158ac575b5060656154d6565b615688610df96066610d40565b602061569360405190565b6334324e9f60e21b815291829060049082905afa8015611250576156c19160009161587e575b50606d611f1a565b6156ce610df96066610d40565b60206156d960405190565b630dfe168160e01b815291829060049082905afa9081156112505761571091615709916000916127ac5750610b90565b6067610ea3565b61571d610df96066610d40565b602061572860405190565b63d21220a760e01b815291829060049082905afa9283156112505761578f95610df961577361577a93610df961576c61578899615781986000916127ac5750610b90565b6068610ea3565b606b610ea3565b606a610ea3565b606e61128e565b606f61128e565b61579a612710615519565b61ffff83161161581c576157b26157b9926065615537565b6065615564565b6157c38160020b90565b6157cd8360020b90565b12801590615856575b801561582e575b61225c576157ef6157f6926065611f1a565b6065611f3d565b615801612710610bff565b821161581c5761581561024092607061128e565b60716155ae565b604051632453e7fb60e11b8152600490fd5b5061584261583c606d611ebe565b82611ede565b61584f611ee66000611efd565b14156157dd565b5061586a615864606d611ebe565b83611ede565b615877611ee66000611efd565b14156157d6565b61589f915060203d81116158a5575b615897818361054f565b810190615505565b386156b9565b503d61588d565b6158cd915060203d81116158d3575b6158c5818361054f565b8101906154b0565b38615673565b503d6158bb565b610240906152b2565b6158f0610edf600061523b565b6158f657565b60405163dec57a6f60e01b8152600490fd5b6102406158e3565b9061593a7f0000000000000000000000000000000000000000000000000000000000000000610b90565b602061594560405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015291829060249082905afa908115611250576000916159a9575b5061599b610bd1336102db565b036112105761024091615a0d565b6159c1915060203d81116112495761123b818361054f565b3861598e565b6159d46102ae6102ae9290565b60010b90565b614e156102ae6102ae9260010b90565b6102ae90612b5e565b91602061024092949361398c81604081019761ffff169052565b615a186127106159c7565b615a228260010b90565b90811361581c57615a3360006159c7565b1315615ab4575b50615a4560006159ea565b615a51610bd1836102db565b03615aa3575b507f02ad1d89af887cf4c74a2ec40d38a38311767043c332bf5dae1a66b62bd2bc98615a836065614e1c565b615a8d6065614e43565b906113b4615a9a60405190565b928392836159f3565b615aae906065615564565b38615a57565b615ac0615ac7916159da565b6065615537565b38615a3a565b9061024091615910565b90615b017f0000000000000000000000000000000000000000000000000000000000000000610b90565b6020615b0c60405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015291829060249082905afa90811561125057600091615b70575b50615b62610bd1336102db565b036112105761024091615b8e565b615b88915060203d81116112495761123b818361054f565b38615b55565b90615801612710610bff565b9061024091615ad7565b90615bce7f0000000000000000000000000000000000000000000000000000000000000000610b90565b6020615bd960405190565b636f7a8bad60e01b81527f0000000000000000000000000000000000000000000000000000000000000000600482015291829060249082905afa90811561125057600091615c3d575b50615c2f610bd1336102db565b036112105761024091615c5b565b615c55915060203d81116112495761123b818361054f565b38615c22565b9061578861024092606e61128e565b9061024091615ba4565b615c8061022c916102db565b60601b90565b9192615ca5601a94615c9b856105a595615c74565b60e81b6014850152565b60e81b6017830152565b90615cd6906115b3615cc030610b90565b91615cca60405190565b94859360208501615c86565b615ce8615ce1825190565b9160200190565b2090565b6102ae6135956065611ebe565b906102ae91615caf565b6102ae9060301c610d8b565b6102ae9054615d03565b615d2c615d2782606c611e35565b61125c565b615d426001615d3c84606c611e35565b01611ebe565b92615d6e6001615d68615d6082615d5a88606c611e35565b01611f76565b95606c611e35565b01615d0f565b9193929190565b611208615d856135956065611ebe565b615d19565b61120891615d8591615caf565b615d9f615186565b90615da86125e7565b7f0000000000000000000000000000000000000000000000000000000000000000917f00000000000000000000000000000000000000000000000000000000000000009190565b6102ae606961125c565b6102ae610df9606a610d40565b6115b3615e52615e357fb73f6756a11e4a570b87c653cea2c6b38c15219c8b15d5740d4a6c262c5679ae611478565b92615e3f60405190565b9283916020830195865260248301614ad5565b5190fdfea2646970667358221220dcb89526b8e303e72cf217d91241b0c9c340dd11deac047eab2296661618bf2664736f6c6343000814003300000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf2027500000000000000000000000022e2f236065b780fa33ec8c4e58b99ebc8b55c5700000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000015555344435553445431303053776170496e736964650000000000000000000000
Deployed Bytecode
0x6080604052600436101561001257600080fd5b60003560e01c80630910a510146102025780630e20622c146101fd578063125f9e33146101f8578063150b7a02146101f357806319903c81146101ee57806323a69e75146101e957806324ea6a19146101e45780633659cfe6146101df578063439fab91146101da5780634641257d146101d557806347243a32146101d05780634f1ef286146101cb57806352d1902d146101c657806353c9d830146101c15780635a23248d146101bc57806360e7ff04146101b75780637708c2ae146101b257806381c7e089146101ad5780639894f21a146101a8578063a4770a88146101a3578063a86aa9271461019e578063b50157ca14610199578063bbfad5b514610194578063bdc9e4101461018f578063c4a7761e1461018a578063c948660914610185578063df28408a14610180578063e7d3fe6b1461017b578063f69e204614610176578063fab2cb36146101715763fcd3533c0361021257610b57565b610b20565b610b08565b610ad6565b610a75565b610a59565b610a2f565b6109f1565b6109d8565b6109a6565b610964565b610933565b6108e0565b610855565b61083a565b6107f1565b61075f565b610747565b610708565b6106f4565b61068e565b61063d565b610625565b610521565b6104f4565b61049e565b610444565b6103ce565b6102fd565b6102b1565b610242565b600091031261021257565b600080fd5b6001600160801b031690565b61022c90610217565b9052565b6020810192916102409190610223565b565b3461021257610252366004610207565b61026961025d613142565b60405191829182610230565b0390f35b6102778160020b90565b0361021257565b905035906102408261026d565b9190604083820312610212578060206102a76102ae938661027e565b940161027e565b90565b34610212576102ca6102c436600461028b565b90613971565b604051005b6001600160a01b031690565b6102ae906102cf565b61022c906102db565b60208101929161024091906102e4565b346102125761030d366004610207565b610269610318615df9565b604051918291826102ed565b610277816102db565b9050359061024082610324565b80610277565b905035906102408261033a565b9181601f8401121561021257823591826001600160401b038111610212576020908186019501011161021257565b9060808282031261021257610390818361032d565b9261039e826020850161032d565b926103ac8360408301610340565b9260608201356001600160401b038111610212576103ca920161034d565b9091565b34610212576102696103ed6103e436600461037b565b93929092613b31565b604051918291826001600160e01b0319909116815260200190565b63ffffffff8116610277565b9050359061024082610408565b91906040838203126102125780602061043d6102ae9386610340565b9401610414565b34610212576102ca610457366004610421565b90615b9a565b91606083830312610212576104728284610340565b926104808360208301610340565b9260408201356001600160401b038111610212576103ca920161034d565b34610212576102ca6104b136600461045d565b9291909161510b565b6102778160010b90565b90503590610240826104ba565b9190604083820312610212578060206104ed6102ae93866104c4565b940161032d565b34610212576102ca6105073660046104d1565b90615acd565b90602082820312610212576102ae9161032d565b34610212576102ca61053436600461050d565b610d37565b634e487b7160e01b600052604160045260246000fd5b90601f01601f191681019081106001600160401b0382111761057057604052565b610539565b9061024061058260405190565b928361054f565b6001600160401b03811161057057602090601f01601f19160190565b0190565b90826000939282370152565b909291926105ca6105c582610589565b610575565b918294828452828201116102125760206102409301906105a9565b9080601f83011215610212578160206102ae933591016105b5565b906020828203126102125781356001600160401b038111610212576102ae92016105e5565b34610212576102ca610638366004610600565b6158da565b346102125761064d366004610207565b6102ca611d77565b6106866102409461067c60609498979561067285608081019b9052565b60020b6020850152565b60020b6040830152565b019015159052565b346102125761069e366004610207565b6102696106a9615d75565b906106b694929460405190565b94859485610655565b919091604081840312610212576106d6838261032d565b9260208201356001600160401b038111610212576102ae92016105e5565b6102ca6107023660046106bf565b9061113f565b3461021257610718366004610207565b610269610723610c3e565b6040519182918290815260200190565b90602082820312610212576102ae91610340565b34610212576102ca61075a366004610733565b6127e2565b346102125761076f366004610207565b6102696107236132ba565b801515610277565b905035906102408261077a565b909160a082840312610212576107a5838361027e565b926107b3816020850161027e565b926107c18260408301610340565b9260608201356001600160401b03811161021257836107e76080956102ae93860161034d565b9590959401610782565b34610212576102ca61080436600461078f565b94939093929192611fcc565b610277816102cf565b9050359061024082610810565b90602082820312610212576102ae91610819565b3461021257610269610723610850366004610826565b613173565b3461021257610865366004610207565b610269610870611ea9565b60405191829182901515815260200190565b91906040838203126102125780602061089e6102ae9386610340565b9401610340565b61022c906102cf565b6108d9610240946108d26060949897956108cb85608081019b9052565b6020850152565b6040830152565b01906108a5565b34610212576102696108fc6108f6366004610882565b90612936565b9061090994929460405190565b948594856108ae565b61092f610240946108d26060949897956108cb85608081019b9052565b0152565b3461021257610943366004610207565b61026961094e615d97565b9061095b94929460405190565b94859485610912565b34610212576102696106a961097a36600461028b565b90615d8a565b6108d96102409461099d6060949897956108cb85608081019b9052565b15156040830152565b34610212576102696109c26109bc366004610882565b9061268b565b906109cf94929460405190565b94859485610980565b34610212576102ca6109eb366004610882565b90615c6a565b3461021257610a01366004610207565b613ea9565b604090610a286102409496959396610a218360608101999052565b6020830152565b0190610223565b3461021257610a3f366004610207565b610269610a4a6131f3565b60405191939193849384610a06565b3461021257610269610723610a6f36600461028b565b90615cf9565b3461021257610a85366004610207565b610269610723615cec565b9091606082840312610212576102ae610aa98484610340565b9360406104ed8260208701610340565b610a28610240946108d26060949897956108cb85608081019b9052565b3461021257610269610af2610aec366004610a90565b9161144f565b90610aff94929460405190565b94859485610ab9565b3461021257610b18366004610207565b6102ca6125df565b3461021257610b30366004610207565b610269610723615def565b9190604083820312610212578060206104ed6102ae9386610340565b3461021257610269610a4a610b6d366004610b3b565b90611af9565b610b826102ae6102ae926102cf565b6102cf565b6102ae90610b73565b6102ae90610b87565b610bdc610ba530610b90565b610bd7610bd17f000000000000000000000000a67d800c8a18d02035f596c68690a78a4cc03f376102db565b916102db565b141590565b610be9576102ae90610c35565b604051632e4771e760e21b8152600490fd5b0390fd5b6102ae6102ae6102ae9290565b6102ae7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc610bff565b506102ae610c0c565b6102ae6000610b99565b610c88610c8c610c5730610b90565b610c807f000000000000000000000000a67d800c8a18d02035f596c68690a78a4cc03f376102db565b9283916102db565b1490565b610cc357610ca490610bd7610c9f610d4a565b6102db565b610cb15761024090610d11565b604051631b50ae3760e11b8152600490fd5b604051637170f3db60e01b8152600490fd5b90610ce26105c583610589565b918252565b369037565b90610240610cf983610cd5565b60208194610d09601f1991610589565b019101610ce7565b600061024091610d2081615226565b610d31610d2c83610bff565b610cec565b90610dc8565b61024090610c48565b6102ae90546102db565b6102ae610d586102ae610c0c565b610d40565b6102ae7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143610bff565b6102ae905b60ff1690565b6102ae9054610d86565b905051906102408261033a565b90602082820312610212576102ae91610d9b565b6040513d6000823e3d90fd5b9190610ddd610dd86102ae610d5d565b610d91565b15610ded57505061024090610ed3565b610dfe610df984610b90565b610b90565b6020610e0960405190565b6352d1902d60e01b815291829060049082905afa60009181610e73575b50610e3e5750604051636f5837f160e01b8152600490fd5b610e5490610bd7610e506102ae610c0c565b9190565b610e615761024092610f1f565b6040516304e7393f60e41b8152600490fd5b610e9591925060203d8111610e9c575b610e8d818361054f565b810190610da8565b9038610e26565b503d610e83565b90610eb36102ae610ecf92610b90565b82546001600160a01b0319166001600160a01b03919091161790565b9055565b610ee3610edf82610f0d565b1590565b610efb5761024090610ef66102ae610c0c565b610ea3565b60405163075de2d760e51b8152600490fd5b3b610f1b610e506000610bff565b1190565b91610f2983610f5e565b8151610f38610e506000610bff565b11908115610f56575b50610f4a575050565b610f5391610ff2565b50565b905038610f41565b610f6b90610df981610ed3565b7fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b610f9560405190565b600090a2565b3d15610fb557610faa3d610cd5565b903d6000602084013e565b606090565b634e487b7160e01b600052602160045260246000fd5b60051115610fda57565b610fba565b9061024082610fd0565b6102ae90610fdf565b90610fff610edf83610f0d565b61102c576000816102ae9360208394519201905af461101c610f9b565b6110266004610fe9565b9161103e565b60405163ae931db960e01b8152600490fd5b9091901561104a575090565b8151611059610e506000610bff565b11156110685750805190602001fd5b6110756102ae6001610fe9565b8190810361108f5760405163014bd73d60e21b8152600490fd5b61109c6102ae6002610fe9565b81036110b457604051630a4d4fd160e01b8152600490fd5b6110c16102ae6003610fe9565b036110d85760405163166c491f60e11b8152600490fd5b610bfb906110e560405190565b632638bfdb60e11b81529182916004830190815260200190565b90610c8861110f610c5730610b90565b610cc35761112290610bd7610c9f610d4a565b610cb157610240916102409160019161113a81615226565b610dc8565b90610240916110ff565b9050519061024082610324565b90602082820312610212576102ae91611149565b9594939291906111997f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b60206111a460405190565b636f7a8bad60e01b81527ffa95ce2023416ef654dc08154ac556137b64b5ba29f8c57a333dbcb35e67a198600482015291829060249082905afa90811561125057600091611222575b506111fa610bd1336102db565b0361121057611208966112d6565b929391929091565b604051639d7b369d60e01b8152600490fd5b611243915060203d8111611249575b61123b818361054f565b810190611156565b386111ed565b503d611231565b610dbc565b6102ae9081565b6102ae9054611255565b634e487b7160e01b600052601160045260246000fd5b9190820180921161128957565b611266565b906102ae6102ae610ecf92610bff565b90959492610240946112cf610a28926112c86080966112c18760a081019d6102e4565b6020870152565b6040850152565b6060830152565b5050505092906112e66000610bff565b9182851480611446575b6114345761132d7f55801cfe493000b734571da1694b21e7f66b11e8ce9fdaa0524ecb59105e73e79261137f96611325614b2d565b505050612936565b509691879561133a615d75565b9250505060001461142057827f00000000000000000000000022e2f236065b780fa33ec8c4e58b99ebc8b55c57915b8084116113f8575b81116113b9575b5050613588565b93919690956113b485888a6113a76113a08761139b606961125c565b61127c565b606961128e565b6040515b9586958661129e565b0390a1565b6113f1916113df826113ce610df96068610d40565b6113d730610b90565b9033906114ab565b6113ec610df96068610d40565b611531565b3882611378565b611409846113ce610df96067610d40565b61141b84846113ec610df96067610d40565b611371565b8261142e610df9606b610d40565b91611369565b60405163162908e360e11b8152600490fd5b508282146112f0565b611208929190600080808061116a565b6114786114726102ae9263ffffffff1690565b60e01b90565b6001600160e01b03191690565b60409061092f61024094969593966114a18360608101996102e4565b60208301906102e4565b90916114ee906114e0610240956114c56323b872dd61145f565b926114cf60405190565b968794602086015260248501611485565b03601f19810184528361054f565b6115f1565b91602061024092949361092f8160408101976102e4565b61022c90610bff565b91602061024092949361152a8160408101976102e4565b019061150a565b611563919261157161154663095ea7b361145f565b9161155060405190565b94859184602084015287602484016114f3565b03601f19810185528461054f565b61157e610edf8484611763565b611589575b50505050565b6115c7936115c16114ee926115b360006115a260405190565b948593602085015260248401611513565b03601f19810183528261054f565b826115f1565b38808080611583565b905051906102408261077a565b90602082820312610212576102ae916115d0565b6115fd61160491610b90565b918261166b565b8051611613610e506000610bff565b14159081611647575b506116245750565b610bfb9061163160405190565b635274afe760e01b8152918291600483016102ed565b61166591508060208061165b610edf945190565b83010191016115dd565b3861161c565b6102ae916116796000610bff565b61168230610b90565b818131106116ac5750600082819260206102ae969551920190855af16116a6610f9b565b916116cf565b610bfb906116b960405190565b63cd78605960e01b8152918291600483016102ed565b906116da5750611734565b6116f56116e5835190565b6116ef6000610bff565b91829190565b149081611729575b50611706575090565b610bfb9061171360405190565b639996b31560e01b8152918291600483016102ed565b9050813b14386116fd565b8051611743610e506000610bff565b111561175157805190602001fd5b604051630a12f52160e11b8152600490fd5b600061176f8192610b90565b9260208151910182855af190611783610f9b565b826117a3575b5081611793575090565b90503b610f1b610e506000610bff565b9091506117ae815190565b6117bb610e506000610bff565b149081156117cc575b509038611789565b6117dc915060208061165b835190565b386117c4565b9392919061180f7f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b602061181a60405190565b636f7a8bad60e01b81527ffa95ce2023416ef654dc08154ac556137b64b5ba29f8c57a333dbcb35e67a198600482015291829060249082905afa90811561125057600091611885575b50611870610bd1336102db565b036112105761187e946118d1565b9192909190565b61189d915060203d81116112495761123b818361054f565b38611863565b9190820391821161128957565b6102ae6102ae6102ae92610217565b6118cc6102ae6102ae9290565b610217565b50505091906118e06000610bff565b91838314848115611ae3575b50611434576118f9614b2d565b505050611906606961125c565b61193e61193982611933611918613142565b61192e6113a08b611929606961125c565b6118a3565b6118b0565b88611bc0565b611b63565b94859361194b60006118bf565b61195488610217565b146114345761196e87611965615d75565b92915050613c15565b93909761197e610df96067610d40565b9861198830610b90565b9061199260405190565b6020816370a0823160e01b9d8e825281806119b088600483016102ed565b03915afa801561125057826119e1878a6119dc611a12976119e796602098600091611acc575b506118a3565b611bc0565b9061127c565b92839c6119f7610df96068610d40565b90611a0160405190565b8095819482938352600483016102ed565b03915afa968715611250576119e16113b495886119dc847f7239dff1718b550db7f36cbf69c665cfeb56d0e96b4fb76a5cba712961b655099c611a5c97600091611aae57506118a3565b90819980611a678390565b11611a97575b8211611a7b576040516113ab565b611a928286611a8d610df96068610d40565b611b87565b6113a7565b611aa98287611a8d610df96067610d40565b611a6d565b611ac6915060203d8111610e9c57610e8d818361054f565b386119d6565b611ac69150893d8111610e9c57610e8d818361054f565b9050611af26102ae606961125c565b10386118ec565b61187e9190600080806117e2565b15611b0e57565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608490fd5b6102ae90611b82611b7a6001600160801b036118b0565b821115611b07565b6118bf565b6114ee610240936114e0611b9e63a9059cbb61145f565b91611ba860405190565b9586936020850152602484016114f3565b1561021257565b90919060001983820991838202928380821091030391611be06000610bff565b8390808214611ca55750948291611c016102ae97611bfb8590565b11611bb9565b09611c9d611c30611c1784196105a56001610bff565b8416809404946001858060000304019087851190030290565b93611c42611c4682611c426003610bff565b0290565b611c98611c92611c89611c80611c77611c6e611c626002610bff565b96871889810288030290565b80890287030290565b80880286030290565b80870285030290565b80860284030290565b80940290565b900390565b930304170290565b9295505050611cb69150611bfb8490565b0490565b611ce37f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b6020611cee60405190565b636f7a8bad60e01b81527ffa95ce2023416ef654dc08154ac556137b64b5ba29f8c57a333dbcb35e67a198600482015291829060249082905afa90811561125057600091611d51575b50611d44610bd1336102db565b0361121057610240611d6f565b611d69915060203d81116112495761123b818361054f565b38611d37565b610f53613ee7565b610240611cba565b611da87f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b6020611db360405190565b636f7a8bad60e01b81527fc163638083542155b9149dbfd43451b2a8cc3457fc2ac0268080cac1c06947ff600482015291829060249082905afa90811561125057600091611e17575b50611e09610bd1336102db565b03611210576102ae90611e6f565b611e2f915060203d81116112495761123b818361054f565b38611dfc565b90600052602052604060002090565b90611e546102ae610ecf92151590565b82549060ff60301b9060301b60ff60301b1990921691161790565b50611e78615cec565b90611e8282615d19565b91505061021257611e9561024091613db0565b6001611ea38295606c611e35565b01611e44565b6102ae6000611d7f565b6102ae905b60020b90565b6102ae9054611eb3565b634e487b7160e01b600052601260045260246000fd5b611eed9060020b5b9160020b90565b908115611ef8570790565b611ec8565b611eb86102ae6102ae9290565b611eb86102ae6102ae9260020b90565b90611f2a6102ae610ecf92611f0a565b825462ffffff191662ffffff9091161790565b90611f4d6102ae610ecf92611f0a565b825465ffffff000000191660189190911b65ffffff000000161790565b6102ae9060181c611eb8565b6102ae9054611f6a565b916020610240929493611f9981604081019760020b9052565b019060020b9052565b610a2861024094611fc260609498979561067285608081019b60020b9052565b6040830190610223565b9194909391928115806122be575b61121057611fe88560020b90565b611ff28560020b90565b12801590612296575b801561226e575b61225c57600080612013606961125c565b612020610e506000610bff565b111561223c575050612030613142565b95869361203d60006118bf565b978861204882610217565b116121e8575b5061205a866065611f1a565b612065876065611f3d565b612072610df96067610d40565b9261207c30610b90565b9261208660405190565b936020856370a0823160e01b9788825281806120a586600483016102ed565b03915afa948515611250576000956121c2575b506020906120e995966120ce610df96068610d40565b906120d860405190565b8098819482938352600483016102ed565b03915afa8015611250576121079587956000926121a2575b50613ff8565b61210f613142565b9461211986610217565b14612190575b61215b577fc749f9ae947d4734cf1569606a8a347391ae94a063478aa853aeff48ac5f99e8936113b49161215260405190565b94859485611fa2565b6121656065611ebe565b61218b6121726065611f76565b916115b361217f60405190565b93849260208401611f80565b615e06565b604051631f2a200560e01b8152600490fd5b6121bb91925060203d8111610e9c57610e8d818361054f565b9038612101565b6120e99550906121e0602092833d8111610e9c57610e8d818361054f565b9550906120b8565b612211906121f4614b2d565b5050506121ff615d75565b80938196939695929561222e57613c15565b505061221e575b5061204e565b61222791613993565b3880612218565b612236613ee7565b50613c15565b935095505061224c836065611f1a565b612257846065611f3d565b61211f565b6040516333a3bdff60e21b8152600490fd5b5061228261227c606d611ebe565b86611ede565b61228f611ee66000611efd565b1415612002565b506122aa6122a4606d611ebe565b85611ede565b6122b7611ee66000611efd565b1415611ffb565b506122e87f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b60206122f360405190565b636f7a8bad60e01b81527fc163638083542155b9149dbfd43451b2a8cc3457fc2ac0268080cac1c06947ff600482015291829060249082905afa90811561125057600091612350575b50612349610bd1336102db565b1415611fda565b612368915060203d81116112495761123b818361054f565b3861233c565b6123977f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b60206123a260405190565b636f7a8bad60e01b81527fc163638083542155b9149dbfd43451b2a8cc3457fc2ac0268080cac1c06947ff600482015291829060249082905afa90811561125057600091612405575b506123f8610bd1336102db565b0361121057610240612423565b61241d915060203d81116112495761123b818361054f565b386123eb565b61242b614b2d565b50505061243b610df96067610d40565b61244430610b90565b9061244e60405190565b916020836370a0823160e01b93848252818061246d86600483016102ed565b03915afa908115611250576124b1936000926125bf575b5060209192612496610df96068610d40565b906124a060405190565b8096819482938352600483016102ed565b03915afa9182156112505760009261259f575b506124cf6000610bff565b9182821480612596575b61254c576124e691612936565b5050906124f08190565b8381148061258d575b611583578261254c9461250a615d75565b9250505060001461257957807f00000000000000000000000022e2f236065b780fa33ec8c4e58b99ebc8b55c57935b11612562575b8111612551575050613588565b505050565b6113f1916113ec610df96068610d40565b61257484846113ec610df96067610d40565b61253f565b80612587610df9606b610d40565b93612539565b508383146124f9565b508281146124d9565b6125b891925060203d8111610e9c57610e8d818361054f565b90386124c4565b602092506125d990833d8111610e9c57610e8d818361054f565b91612484565b61024061236e565b7ff98f8de0e40e1ae544b53961cd5e87fbc36fdc8ea99f85e11da8da2e496d48ce90565b9050519061024082610810565b6080818303126102125761262c8282610d9b565b926102ae61263d8460208501610d9b565b93606061264d82604087016115d0565b940161260b565b90959492610240946112cf61092f926126816080966126778760a081019d6102e4565b60020b6020870152565b60020b6040850152565b906126eb9060206126bb7f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b6126c36125e7565b906126cd60405190565b94859283918291636f7a8bad60e01b5b835260048301526024820190565b03915afa801561125057610df961270d916080946000916127ac575b50610b90565b61271a610df96066610d40565b6127246065611ebe565b906127576127326065611f76565b9461273c60405190565b97889687958695636b386e3760e01b5b875260048701612654565b03915afa8015611250576000928380938193612775575b5093929190565b925050925061279b915060803d81116127a5575b612793818361054f565b810190612618565b919390923861276e565b503d612789565b6127c4915060203d81116112495761123b818361054f565b38612707565b6102ae905b63ffffffff1690565b6102ae90546127ca565b6127ec6000610bff565b81036128105750610240612800607061125c565b61280a60716127d8565b90612841565b61024090612800565b6040906128356102409496959396610a218360608101996102e4565b019063ffffffff169052565b9061289660206128707f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b6128786125e7565b9061288260405190565b93849283918291636f7a8bad60e01b6126dd565b03915afa908115611250576128b691610df9916000916127ac5750610b90565b906128c4610df96066610d40565b91803b15610212576128f6936000936128dc60405190565b958694859384936345cede6d60e11b855260048501612819565b03915afa8015611250576129075750565b610240906000612917818361054f565b810190610207565b6102ae6a0c097ce7bc90715b34b9f160241b610bff565b61297f61294b6129466066610d40565b6129f6565b5091829361295884613173565b9361296b6129666065611ebe565b612b6b565b916129796129666065611f76565b936140bb565b9290938261299b8561139b8861299361291f565b978891611bc0565b9081946129a8606961125c565b6129b5610e506000610bff565b036129bf57505050565b6129f39395506129dc6129ed916129d46131f3565b509490611bc0565b916129e7606961125c565b9261127c565b91611bc0565b91565b6103ca90612a0e610df9633850c7bd60e01b92610b90565b60046000809260409482525afa15610212576000519060205190565b6102ae6102ae6102ae9260020b90565b600160ff1b81146112895760000390565b6102ae620d89e719611efd565b60020b627fffff1981146112895760000390565b6102ae612a77612a4b565b612a58565b612a8c6102ae6102ae9260020b90565b62ffffff1690565b6102ae6102ae6102ae9262ffffff1690565b15612aad57565b60405162461bcd60e51b81526020600482015260016024820152601560fa1b6044820152606490fd5b612ae36102ae6102ae9290565b6001600160881b031690565b6102ae9081906001600160881b031681565b8181029291811591840414171561128957565b610d8b6102ae6102ae9290565b6102ae90612b35610e506102ae9460ff1690565b901c90565b8115611ef8570490565b8115611ef8570690565b6102ae6102ae6102ae9260ff1690565b610b826102ae6102ae9290565b612dfd6102ae91612bef612b7f6000611efd565b612b898360020b90565b928184121561313057612ba6612ba1612bab92612a2a565b612a3a565b610bff565b925b612bd3612bcb6102ae612bc6612bc1612a6c565b612a7c565b612a94565b851115612aa6565b612bdd6001610bff565b8416612be96000610bff565b93849190565b1461312057612c15612c106ffffcb933bd6fad37aa2d162d1a594001612ad6565b612aef565b938484612c2a612c256002610bff565b841690565b036130f6575b5083612c44612c3f6004610bff565b831690565b036130cf575b83612c58612c3f6008610bff565b036130a8575b83612c6c612c3f6010610bff565b03613081575b83612c80612c3f6020610bff565b0361305a575b83612c94612c3f6040610bff565b03613033575b83612ca8612c3f6080610bff565b0361300c575b83612cbd612c3f610100610bff565b03612fe5575b83612cd2612c3f610200610bff565b03612fbe575b83612ce7612c3f610400610bff565b03612f97575b83612cfc612c3f610800610bff565b03612f70575b83612d11612c3f611000610bff565b03612f49575b83612d26612c3f612000610bff565b03612f22575b83612d3b612c3f614000610bff565b03612efb575b83612d50612c3f618000610bff565b03612ed4575b83612d66612c3f62010000610bff565b03612ead575b83612d7c612c3f62020000610bff565b03612e87575b83612d92612c3f62040000610bff565b03612e5b575b612dad8491612da962080000610bff565b1690565b03612e22575b13612e0f575b612de66102ae612dd2612dcc6020612b14565b85612b21565b93612de0600160201b610bff565b90612b44565b03612e02576119e1612df86000612b14565b612b4e565b612b5e565b6119e1612df86001612b14565b90612e1c90600019612b3a565b90612db9565b92612e45612e5591612e3f6b048a170391f7dc42444e8fa2610bff565b90612b01565b612e4f6080612b14565b90612b21565b92612db3565b93612dad612e7e612e458693612e3f6d2216e584f5fa1ea926041bedfe98610bff565b95915050612d98565b93612e45612ea791612e3f6e5d6af8dedb81196699c329225ee604610bff565b93612d82565b93612e45612ece91612e3f6f09aa508b5b7a84e1c677de54f3e99bc9610bff565b93612d6c565b93612e45612ef591612e3f6f31be135f97d08fd981231505542fcfa6610bff565b93612d56565b93612e45612f1c91612e3f6f70d869a156d2a1b890bb3df62baf32f7610bff565b93612d41565b93612e45612f4391612e3f6fa9f746462d870fdf8a65dc1f90e061e5610bff565b93612d2c565b93612e45612f6a91612e3f6fd097f3bdfd2022b8845ad8f792aa5825610bff565b93612d17565b93612e45612f9191612e3f6fe7159475a2c29b7443b29c7fa6e889d9610bff565b93612d02565b93612e45612fb891612e3f6ff3392b0822b70005940c7a398e4b70f3610bff565b93612ced565b93612e45612fdf91612e3f6ff987a7253ac413176f2b074cf7815e54610bff565b93612cd8565b93612e4561300691612e3f6ffcbe86c7900a88aedcffc83b479aa3a4610bff565b93612cc3565b93612e4561302d91612e3f6ffe5dee046a99a2a811c461f1969c3053610bff565b93612cae565b93612e4561305491612e3f6fff2ea16466c96a3843ec78b326b52861610bff565b93612c9a565b93612e4561307b91612e3f6fff973b41fa98c081472e6896dfb254c0610bff565b93612c86565b93612e456130a291612e3f6fffcb9843d60f6159c9db58835c926644610bff565b93612c72565b93612e456130c991612e3f6fffe5caca7e10e4e61c3624eaa0941cd0610bff565b93612c5e565b93612e456130f091612e3f6ffff2e50f5f656932ef12357cf3c7fdcc610bff565b93612c4a565b613119919550612e4590612e3f6ffff97272373d413259a46990580e213a610bff565b9338612c30565b612c15612c10600160801b612ad6565b612ba661313c91612a2a565b92612bad565b6102ae61314d615d75565b505050615004565b610b826102ae6102ae92610217565b6102ae6102ae6102ae926102cf565b6131836001600160801b03613155565b61318c826102cf565b116131bb576131a66131a06102ae92613164565b80612b01565b6131ae61291f565b6129ed600160c01b610bff565b6131de6131ca6102ae92613164565b6131d7600160401b610bff565b9080611bc0565b6131e661291f565b6129ed600160801b610bff565b6131fb614f22565b90929161320b610df96067610d40565b9361321530610b90565b9161321f60405190565b926020846370a0823160e01b98898252818061323e86600483016102ed565b03915afa9384156112505761326e94602093613260926000926132a257500190565b96612496610df96068610d40565b03915afa908115611250576129f39260009261328957500190565b6105a591925060203d8111610e9c57610e8d818361054f565b6105a5919250853d8111610e9c57610e8d818361054f565b6132c2615d75565b5050506132cf6000610bff565b80821461334e5750602061332091613309610df97f00000000000000000000000022e2f236065b780fa33ec8c4e58b99ebc8b55c57610b90565b6040519384928391829163672f9ce360e11b6126dd565b03915afa90811561125057600091613336575090565b6102ae915060203d8111610e9c57610e8d818361054f565b905090565b6102ae60c0610575565b61027781610217565b905051906102408261335d565b9091606082840312610212576102ae61338c8484613366565b93604061339c8260208701610d9b565b9401610d9b565b9060a080610240936133b58482519052565b6133c460208201516020860152565b6133d360408201516040860152565b6133e260608201516060860152565b6133f160808201516080860152565b0151910152565b60c08101929161024091906133a3565b6102ae9060401c612a8c565b6102ae9054613408565b6102ae610160610575565b9061022c906102db565b608081830312610212576134478282610d9b565b926102ae6134588460208501613366565b93606061339c8260408701610d9b565b90610140806102409361347c8482516102e4565b61348e602082015160208601906102e4565b60408181015162ffffff169085015260608181015160020b9085015260808181015160020b908501526134c660a082015160a0860152565b6134d560c082015160c0860152565b6134e460e082015160e0860152565b6134f5610100820151610100860152565b6133f16101208201516101208601906102e4565b610160810192916102409190613468565b6102ae6080610575565b90613578606060016102409461354161353b865190565b8261128e565b019261355a613554602083015160020b90565b85611f1a565b61357161356b604083015160020b90565b85611f3d565b0151151590565b90611e44565b9061024091613524565b6135a56135956065611ebe565b61359f6065611f76565b90615caf565b926135af84615d19565b94915050816135be868361508c565b613892576135cc6000610bff565b928381036137935750506135e0606b610d40565b6135e990610b90565b916135f46067610d40565b6135fd90610b90565b956136086068610d40565b61361190610b90565b9261361c6065613414565b6136266065611ebe565b6136306065611f76565b9161363a30610b90565b9661364361341e565b9b61364e908d613429565b61365b9060208d01613429565b62ffffff1660408b015260020b60608a015260020b608089015260a088015260c087015261368a8160e0880152565b61010086015261369e906101208601613429565b6136aa42610140860152565b6040519384908190634418b22b60e11b82526136c99060048301613509565b03815a608094600091f193841561125057600090819582958391613757575b5061373690959694610edf8461371f6137016065611ebe565b61067c61370e6065611f76565b9161067261371a61351a565b958652565b6000606082015261373185606c611e35565b61357e565b61373e575050565b6001611ea361374f61024094613db0565b92606c611e35565b919550506137369550613781915060803d811161378c575b613779818361054f565b810190613433565b9196909591906136e8565b503d61376f565b916060926137fd61382693956137ec60009a8a8c14613882576112c86137db610df97f00000000000000000000000022e2f236065b780fa33ec8c4e58b99ebc8b55c57610b90565b966112c16137e7613353565b978852565b6137f68187850152565b6080830152565b6138084260a0830152565b604051978893849283919063219f5d1760e01b8352600483016133f8565b03925af19485156112505760009586958791613847575b5094959315613736565b9050613736965061387091955060603d811161387b575b613868818361054f565b810190613373565b95919690959061383d565b503d61385e565b6112c86137db610df9606b610d40565b505050925050506138a36000610bff565b9081906102ae60006118bf565b906138da7f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b60206138e560405190565b636f7a8bad60e01b81527fc163638083542155b9149dbfd43451b2a8cc3457fc2ac0268080cac1c06947ff600482015291829060249082905afa90811561125057600091613949575b5061393b610bd1336102db565b036112105761024091613967565b613961915060203d81116112495761123b818361054f565b3861392e565b9061024091613993565b90610240916138b0565b908152604081019291610240916020905b01906102e4565b9061399d91615caf565b6139a681615d19565b929150506139b46000610bff565b808214611583576020613a20926139ed610df97f00000000000000000000000022e2f236065b780fa33ec8c4e58b99ebc8b55c57610b90565b6139f630610b90565b916000613a0260405190565b809781958294613a1562f714ce60e01b90565b84526004840161397b565b03925af191821561125057600092613b11575b508111613a55575b50613a435750565b60006001611ea361024093606c611e35565b613a62610df9606a610d40565b90613a8c7f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b916020613a9860405190565b636f7a8bad60e01b81527ffa95ce2023416ef654dc08154ac556137b64b5ba29f8c57a333dbcb35e67a198600482015293849060249082905afa90811561125057613aeb93600092613af1575b50611b87565b38613a3b565b613b0a91925060203d81116112495761123b818361054f565b9038613ae5565b613b2a91925060203d8111610e9c57610e8d818361054f565b9038613a33565b50505050506102ae63150b7a0261145f565b6102ae60a0610575565b9061022c90610217565b91906040838203126102125780602061339c6102ae9386610d9b565b9060808061024093613b858482519052565b613b9760208201516020860190610223565b613ba660408201516040860152565b6133f160608201516060860152565b60a0810192916102409190613b73565b9060608061024093613bd78482519052565b613be9602082015160208601906102e4565b613bfb60408201516040860190610223565b0151910190610223565b6080810192916102409190613bc5565b92613cab92909115613da1576040613c4f610df97f00000000000000000000000022e2f236065b780fa33ec8c4e58b99ebc8b55c57610b90565b91613c6d613c5b613b43565b91613c64888452565b60208301613b4d565b613c84613c7a6000610bff565b6112cf8185850152565b613c8f426080830152565b604051948591829190630624e65f60e11b835260048301613bb5565b03816000855af18015611250576000938491613d74575b50613d386000926040929596613cf3613cda30610b90565b613cea613ce561351a565b938452565b60208301613429565b613d066001600160801b03828601613b4d565b613d1a6001600160801b0360608301613b4d565b604051948593849283919063fc6f786560e01b835260048301613c05565b03925af1801561125057613d495750565b613d699060403d8111613d6d575b613d61818361054f565b810190613b57565b5050565b503d613d57565b600092945060409150613d96613d3891833d8111613d6d57613d61818361054f565b909593509150613cc2565b6040613c4f610df9606b610d40565b90600091613dbe6000610bff565b8114613e6757613dd1610df9606b610d40565b90613ddb30610b90565b90823b1561021257613e359260009283613df460405190565b809681958294613e086342842e0e60e01b90565b84527f00000000000000000000000022e2f236065b780fa33ec8c4e58b99ebc8b55c579060048501611485565b03925af19081613e51575b50613e4b5760009150565b60019150565b613e61906000612917818361054f565b38613e40565b5060009150565b91946137f661092f92989795613ea260a096613e9b6102409a613e948960c081019f9052565b6020890152565b6040870152565b6060850152565b61218b613eb46131f3565b5091906115b3613ec2614b2d565b909150613ecd613ee7565b91613ed8606961125c565b60405197889660208801613e6e565b613eef615d75565b505050613f1e610df97f00000000000000000000000022e2f236065b780fa33ec8c4e58b99ebc8b55c57610b90565b613f477f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b906020613f5360405190565b636f7a8bad60e01b81527ffa95ce2023416ef654dc08154ac556137b64b5ba29f8c57a333dbcb35e67a198600482015292839060249082905afa90811561125057613fc393602093600093613fd9575b506000613faf60405190565b809681958294613a156318fccc7660e01b90565b03925af190811561125057600091613336575090565b613ff1919350843d81116112495761123b818361054f565b9138613fa3565b9061254c959161402395949394614012612800607061125c565b8061401d6000610bff565b97889190565b036140a7575061403393506143d5565b9290915b81810361409e575061404c612800607061125c565b614054615d75565b9250505060001461408a57827f00000000000000000000000022e2f236065b780fa33ec8c4e58b99ebc8b55c57915b8084612539565b82614098610df9606b610d40565b91614083565b61404c90612800565b9150506140b3926147c2565b929091614037565b6103ca949293916140ce918484876140d4565b9261425a565b936140de836102cf565b6140e7836102cf565b11614165575b6140f6826102cf565b94614100816102cf565b9586116141135750506102ae935061419f565b9290939194614121826102cf565b11156141595782916141379161413d959461419f565b93614224565b61414681610217565b61414f83610217565b101561334e575090565b9150506102ae92614224565b9091906140ed565b6102ae600160601b610bff565b61418661418c916102cf565b916102cf565b9003906001600160a01b03821161128957565b916141f5916102ae936141b1826102cf565b6141ba826102cf565b116141fa575b6141f06129ed916141ea6141d261416d565b6141db83613164565b6141e487613164565b90611bc0565b9361417a565b613164565b614200565b906141c0565b9061024061420d836118bf565b61421e614218829590565b916118b0565b14611bb9565b916141f5916102ae93614236826102cf565b61423f826102cf565b11614254575b6141f06129ed916141ea61416d565b90614245565b90939290916000928361426c836102cf565b614275886102cf565b116142d9575b614284876102cf565b61428d836102cf565b9081116142a2575050506129f3929394614304565b90919394506142b0836102cf565b11156142cd5750906142c7836102ae949383614304565b94614367565b946102ae939250614367565b95919561427b565b6102ae6060612b14565b6102ae906142ff610e506102ae9460ff1690565b901b90565b906102ae92614312826102cf565b61431b846102cf565b1161435f575b61435991614342614334614353936118b0565b61433c6142e1565b906142eb565b906129ed6143536141f0878461417a565b91613164565b90612b3a565b909190614321565b61438c906102ae9392614379816102cf565b614382836102cf565b116143a05761417a565b6141e461435361439a61416d565b936118b0565b9061417a565b91946143cc6108d992989795613ea260a096613e9b6102409a613e948960c081019f9052565b15156080830152565b90929060009061440960206128707f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b03915afa9081156112505761442c610df984936080936000916127ac5750610b90565b614439610df96066610d40565b906144446065611ebe565b61444e6065611f76565b926144708b61445c60405190565b98899687958695636b386e3760e01b61274c565b03915afa801561125057600080938192614549575b506144a1610e508293968660001461453f5761334e606e61125c565b111561451b576144dd6144b484836145fa565b976144d889946000858860001461450a576105a591506144d46000610bff565b0390565b980190565b955b6144e95750505050565b859361218b9388936115b3936144fe60405190565b978896602088016143a6565b6144d461451692610bff565b9a0190565b509493915061452a6000610bff565b806145386129466066610d40565b50936144df565b61334e606f61125c565b91505061456591925060803d81116127a557612793818361054f565b93929150929038614485565b6102ae73fffd8963efd1fc6a506488495d951d5263988d26612b5e565b6102ae6401000276a3612b5e565b6141866145a8916102cf565b01906001600160a01b03821161128957565b91936145df60a0946112c86102ae976145d6876145e9976102e4565b15156020870152565b60608301906108a5565b816080820152016000815260200190565b81156146cc57604061461d61460d61458e565b6146176001612b5e565b9061459c565b915b61462c610df96066610d40565b84600061464161463b30610b90565b94614746565b9361466861464e60405190565b97889687958694630251596160e31b8652600486016145ba565b03925af1908115611250576102ae9260009182936146aa575b501561469b575061469190610bff565b6144d46000610bff565b6146a59150610bff565b614691565b9092506146c5915060403d8111613d6d57613d61818361054f565b9138614681565b60406146e36146d9614571565b6143a06001612b5e565b9161461f565b156146f057565b60405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608490fd5b6102ae90612ba661475e836001600160ff1b03610bff565b8211156146e9565b916060838303126102125761477b828461032d565b926147898360208301610782565b9260408201356001600160401b038111610212576102ae92016105e5565b6040906108d96102409496959396610a218360608101999052565b6147d56147dd9161481893810190614766565b929091610b90565b90156148ff576148076147f3610df96067610d40565b926148016000198486611531565b8261494a565b506148126000610bff565b91611531565b614825610df96067610d40565b9161482f30610b90565b604051906020826370a0823160e01b96878252818061485186600483016102ed565b03915afa9081156112505761487b926000926148dd575b506020908296612496610df96068610d40565b03915afa918215611250576000926148bd575b508193614899575050565b61218b906115b36148ad6129466066610d40565b50604051948593602085016147a7565b6148d691925060203d8111610e9c57610e8d818361054f565b903861488e565b60209192506148f890823d8111610e9c57610e8d818361054f565b9190614868565b6148076147f3610df96068610d40565b614919601e610cd5565b7f416464726573733a206c6f772d6c6576656c2063616c6c206661696c65640000602082015290565b6102ae61490f565b6102ae916149586000610bff565b90614961614942565b926149c2565b1561496e57565b60405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608490fd5b90600080916102ae95946149e26149d830610b90565b8290311015614967565b60208251920190855af16149f4610f9b565b91614a46565b15614a0157565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b91929015614a7857508151614a5e610e506000610bff565b14614a67575090565b614a736102ae91610f0d565b6149fa565b82614ae6565b60005b838110614a915750506000910152565b8181015183820152602001614a81565b614ac2614acb6020936105a593614ab6815190565b80835293849260200190565b95869101614a7e565b601f01601f191690565b9060206102ae928181520190614aa1565b90614aef825190565b614afc610e506000610bff565b1115614b0b5750805190602001fd5b610bfb90614b1860405190565b62461bcd60e51b815291829160048301614ad5565b61187e614b52565b611f996102409461067c6060949897956108cb85608081019b9052565b600080614b5d615d75565b614b6a6000979497610bff565b808814614df65750614b7b87615004565b9687614b90614b8a60006118bf565b91610217565b11614b9b5750505050565b919450919450614bae610df96067610d40565b614bb730610b90565b604051926020846370a0823160e01b948582528180614bd987600483016102ed565b03915afa93841561125057600094614dd6575b50614bfa610df96068610d40565b946020614c0660405190565b80978682528180614c1a88600483016102ed565b03915afa95861561125057600096614daa575b50614c826000926040928414614d9d57614c69610df97f00000000000000000000000022e2f236065b780fa33ec8c4e58b99ebc8b55c57610b90565b90614c75610ce261351a565b613cf38660208301613429565b03925af1801561125057614d7f575b50614c9f610df96067610d40565b906020614cab60405190565b80938582528180614cbf86600483016102ed565b03915afa91821561125057614cf094602093614ce292600091614d6857506118a3565b92612496610df96068610d40565b03915afa918215611250577f96cdf6990078e09c90b811caef18d461056ba3c9bb37d628b0d0ee82963b169193614d4293614d3292600091611aae57506118a3565b90614d3d8282614e4d565b614ede565b90614d5c82958297614d5360405190565b94859485614b35565b0390a138808080611583565b611ac69150853d8111610e9c57610e8d818361054f565b614d969060403d8111613d6d57613d61818361054f565b9050614c91565b614c69610df9606b610d40565b6040919650600092614dcc614c829260203d8111610e9c57610e8d818361054f565b9792509250614c2d565b614def91945060203d8111610e9c57610e8d818361054f565b9238614bec565b9550505050925050614e0860006118bf565b918190565b6102ae9060301c5b61ffff1690565b6102ae9054614e0d565b6102ae6102ae6102ae9261ffff1690565b6102ae9060581c6102cf565b6102ae9054614e37565b614e8890614e7a614e66614e616065614e1c565b614e26565b91614e72612710610bff565b928391611bc0565b926141e4614e616065614e1c565b90614e936000610bff565b90818111614ec7575b508111614ea65750565b61024090614eb7610df96068610d40565b614ec16065614e43565b90611b87565b614ed890614eb7610df96067610d40565b38614e9c565b91906102ae90611c98614f0e614ef7614e616065614e1c565b95611c98614f06612710610bff565b809883611bc0565b94614f1c614e616065614e1c565b83611bc0565b6000908190614f2f615d75565b509291614f3c6000610bff565b808214614fa35750614f4d90615004565b908193614f5a60006118bf565b614f6384610217565b11614f6d57505050565b9091929550614f9e939450614f98614f92614f8b6129466066610d40565b5093612b6b565b91612b6b565b9161425a565b919092565b9550505091505081906102ae60006118bf565b614fc0602a610cd5565b7f5048797065724c506f6f6c53776170496e736964653a206765744c69717569646020820152691a5d1e4819985a5b195960b21b604082015290565b6102ae614fb6565b61500e6000610bff565b811461506857615063610100916115b361505561502e610df9606b610d40565b9261503860405190565b63133f757160e31b60208201529283916024830190815260200190565b61505d614ffc565b91615073565b015190565b506102ae60006118bf565b6000806102ae9493602081519101845afa6149f4610f9b565b6150af906150bb926150a16129466066610d40565b5061296b6129666065611ebe565b91906116ef6000610bff565b1491826150c757505090565b14919050565b156150d457565b60405162461bcd60e51b815260206004820152600f60248201526e31b0b6363130b1b59031b0b63632b960891b6044820152606490fd5b91509150615131615122610c9f610df96066610d40565b61512b336102db565b146150cd565b61513b6000610bff565b808213156151675750610240915061515f615159610df96067610d40565b91610bff565b903390611b87565b905081136151725750565b6102409061515f615159610df96068610d40565b7f12e0d3ce89f556b797246ec55ba4b224e777f2c6e71e1d520ead0ade815ddf6190565b506151e160206151d97f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b612878615186565b03915afa90811561125057600091615208575b50615201610bd1336102db565b0361121057565b615220915060203d81116112495761123b818361054f565b386151f4565b610240906151aa565b6102ae9060081c610d8b565b6102ae905461522f565b610d8b6102ae6102ae9260ff1690565b906152656102ae610ecf92615245565b825460ff191660ff9091161790565b906152846102ae610ecf92151590565b825461ff00191660089190911b61ff00161790565b61022c90612b14565b6020810192916102409190615299565b6152bf610edf600061523b565b9081806153a5575b8015615360575b155b61534e576152f690826152ed6152e66001612b14565b6000615255565b61533d576155d3565b6152fc57565b615307600080615274565b7f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249861533160405190565b806113b46001826152a2565b61534960016000615274565b6155d3565b604051632785437f60e21b8152600490fd5b50615375610edf61537030610b90565b610f0d565b80156152ce57506152d06153896000610d91565b61539d6153966001612b14565b9160ff1690565b1490506152ce565b506153b06000610d91565b6153bd6153966001612b14565b106152c7565b61ffff8116610277565b90505190610240826153c3565b905051906102408261026d565b9050519061024082610408565b9190610160838203126102125761540b8184611149565b9261541982602083016153cd565b9261542783604084016153da565b9261543581606085016153da565b926154438260808301611149565b926154518360a08401611149565b9261545f8160c08501611149565b9261546d8260e08301610d9b565b926102ae61547f846101008501610d9b565b93610140615491826101208701610d9b565b94016153e7565b62ffffff8116610277565b9050519061024082615498565b90602082820312610212576102ae916154a3565b612a8c6102ae6102ae9262ffffff1690565b906154e66102ae610ecf926154c4565b82549062ffffff60401b9060401b62ffffff60401b1990921691161790565b90602082820312610212576102ae916153da565b614e156102ae6102ae9290565b614e156102ae6102ae9261ffff1690565b906155476102ae610ecf92615526565b82549061ffff60301b9060301b61ffff60301b1990921691161790565b906155746102ae610ecf92610b90565b825490600160581b600160f81b039060581b600160581b600160f81b031990921691161790565b6127cf6102ae6102ae9263ffffffff1690565b906155be6102ae610ecf9261559b565b825463ffffffff191663ffffffff9091161790565b61563561562261561c61561c61562861560661562e966155f1615908565b6020806155fc835190565b83010191016153f4565b9e95999f949a93979d92969c91989b909f610b90565b98610b90565b94610b90565b95610b90565b6066610ea3565b615642610df96066610d40565b602061564d60405190565b63ddca3f4360e01b815291829060049082905afa80156112505761567b916000916158ac575b5060656154d6565b615688610df96066610d40565b602061569360405190565b6334324e9f60e21b815291829060049082905afa8015611250576156c19160009161587e575b50606d611f1a565b6156ce610df96066610d40565b60206156d960405190565b630dfe168160e01b815291829060049082905afa9081156112505761571091615709916000916127ac5750610b90565b6067610ea3565b61571d610df96066610d40565b602061572860405190565b63d21220a760e01b815291829060049082905afa9283156112505761578f95610df961577361577a93610df961576c61578899615781986000916127ac5750610b90565b6068610ea3565b606b610ea3565b606a610ea3565b606e61128e565b606f61128e565b61579a612710615519565b61ffff83161161581c576157b26157b9926065615537565b6065615564565b6157c38160020b90565b6157cd8360020b90565b12801590615856575b801561582e575b61225c576157ef6157f6926065611f1a565b6065611f3d565b615801612710610bff565b821161581c5761581561024092607061128e565b60716155ae565b604051632453e7fb60e11b8152600490fd5b5061584261583c606d611ebe565b82611ede565b61584f611ee66000611efd565b14156157dd565b5061586a615864606d611ebe565b83611ede565b615877611ee66000611efd565b14156157d6565b61589f915060203d81116158a5575b615897818361054f565b810190615505565b386156b9565b503d61588d565b6158cd915060203d81116158d3575b6158c5818361054f565b8101906154b0565b38615673565b503d6158bb565b610240906152b2565b6158f0610edf600061523b565b6158f657565b60405163dec57a6f60e01b8152600490fd5b6102406158e3565b9061593a7f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b602061594560405190565b636f7a8bad60e01b81527fc163638083542155b9149dbfd43451b2a8cc3457fc2ac0268080cac1c06947ff600482015291829060249082905afa908115611250576000916159a9575b5061599b610bd1336102db565b036112105761024091615a0d565b6159c1915060203d81116112495761123b818361054f565b3861598e565b6159d46102ae6102ae9290565b60010b90565b614e156102ae6102ae9260010b90565b6102ae90612b5e565b91602061024092949361398c81604081019761ffff169052565b615a186127106159c7565b615a228260010b90565b90811361581c57615a3360006159c7565b1315615ab4575b50615a4560006159ea565b615a51610bd1836102db565b03615aa3575b507f02ad1d89af887cf4c74a2ec40d38a38311767043c332bf5dae1a66b62bd2bc98615a836065614e1c565b615a8d6065614e43565b906113b4615a9a60405190565b928392836159f3565b615aae906065615564565b38615a57565b615ac0615ac7916159da565b6065615537565b38615a3a565b9061024091615910565b90615b017f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b6020615b0c60405190565b636f7a8bad60e01b81527fc163638083542155b9149dbfd43451b2a8cc3457fc2ac0268080cac1c06947ff600482015291829060249082905afa90811561125057600091615b70575b50615b62610bd1336102db565b036112105761024091615b8e565b615b88915060203d81116112495761123b818361054f565b38615b55565b90615801612710610bff565b9061024091615ad7565b90615bce7f00000000000000000000000002ea2e205695d31e0308fdc844cbb2d41bf20275610b90565b6020615bd960405190565b636f7a8bad60e01b81527fc163638083542155b9149dbfd43451b2a8cc3457fc2ac0268080cac1c06947ff600482015291829060249082905afa90811561125057600091615c3d575b50615c2f610bd1336102db565b036112105761024091615c5b565b615c55915060203d81116112495761123b818361054f565b38615c22565b9061578861024092606e61128e565b9061024091615ba4565b615c8061022c916102db565b60601b90565b9192615ca5601a94615c9b856105a595615c74565b60e81b6014850152565b60e81b6017830152565b90615cd6906115b3615cc030610b90565b91615cca60405190565b94859360208501615c86565b615ce8615ce1825190565b9160200190565b2090565b6102ae6135956065611ebe565b906102ae91615caf565b6102ae9060301c610d8b565b6102ae9054615d03565b615d2c615d2782606c611e35565b61125c565b615d426001615d3c84606c611e35565b01611ebe565b92615d6e6001615d68615d6082615d5a88606c611e35565b01611f76565b95606c611e35565b01615d0f565b9193929190565b611208615d856135956065611ebe565b615d19565b61120891615d8591615caf565b615d9f615186565b90615da86125e7565b7fc163638083542155b9149dbfd43451b2a8cc3457fc2ac0268080cac1c06947ff917ffa95ce2023416ef654dc08154ac556137b64b5ba29f8c57a333dbcb35e67a1989190565b6102ae606961125c565b6102ae610df9606a610d40565b6115b3615e52615e357fb73f6756a11e4a570b87c653cea2c6b38c15219c8b15d5740d4a6c262c5679ae611478565b92615e3f60405190565b9283916020830195865260248301614ad5565b5190fdfea2646970667358221220dcb89526b8e303e72cf217d91241b0c9c340dd11deac047eab2296661618bf2664736f6c63430008140033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.