Source Code
Overview
S Balance
S Value
$0.00More Info
Private Name Tags
ContractCreator
TokenTracker
Latest 18 from a total of 18 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Transfer From | 46389925 | 87 days ago | IN | 0 S | 0.0023915 | ||||
| Modify Liquiditi... | 46389851 | 87 days ago | IN | 0 S | 0.0257037 | ||||
| Transfer From | 46368390 | 87 days ago | IN | 0 S | 0.0023915 | ||||
| Modify Liquiditi... | 46368111 | 87 days ago | IN | 0 S | 0.03199738 | ||||
| Transfer From | 41021347 | 128 days ago | IN | 0 S | 0.0021515 | ||||
| Transfer From | 41021336 | 128 days ago | IN | 0 S | 0.0023915 | ||||
| Modify Liquiditi... | 41019738 | 128 days ago | IN | 0 S | 0.0193477 | ||||
| Modify Liquiditi... | 40985560 | 128 days ago | IN | 0 S | 0.01096485 | ||||
| Modify Liquiditi... | 40983950 | 128 days ago | IN | 0 S | 0.01211795 | ||||
| Modify Liquiditi... | 40983875 | 128 days ago | IN | 0 S | 0.01537845 | ||||
| Modify Liquiditi... | 40983533 | 128 days ago | IN | 0 S | 0.0282717 | ||||
| Transfer From | 40891466 | 129 days ago | IN | 0 S | 0.0030065 | ||||
| Modify Liquiditi... | 40890871 | 129 days ago | IN | 0 S | 0.0202156 | ||||
| Modify Liquiditi... | 40581286 | 131 days ago | IN | 0 S | 0.02656875 | ||||
| Modify Liquiditi... | 40574032 | 131 days ago | IN | 0 S | 0.0148373 | ||||
| Modify Liquiditi... | 39826892 | 136 days ago | IN | 0 S | 0.0138391 | ||||
| Modify Liquiditi... | 39826651 | 136 days ago | IN | 0 S | 0.018719 | ||||
| Modify Liquiditi... | 27156152 | 204 days ago | IN | 0 S | 0.0259016 |
Latest 1 internal transaction
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 27155190 | 204 days ago | Contract Creation | 0 S |
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.
Contract Source Code Verified (Exact Match)
Contract Name:
CLPositionManager
Compiler Version
v0.8.26+commit.8a97fa7a
Optimization Enabled:
Yes with 9000 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity 0.8.26;
import {IVault} from "infinity-core/src/interfaces/IVault.sol";
import {Currency, CurrencyLibrary} from "infinity-core/src/types/Currency.sol";
import {BalanceDelta} from "infinity-core/src/types/BalanceDelta.sol";
import {ICLPoolManager} from "infinity-core/src/pool-cl/interfaces/ICLPoolManager.sol";
import {CLPosition} from "infinity-core/src/pool-cl/libraries/CLPosition.sol";
import {SafeCast} from "infinity-core/src/libraries/SafeCast.sol";
import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol";
import {PoolIdLibrary} from "infinity-core/src/types/PoolId.sol";
import {PoolKey} from "infinity-core/src/types/PoolKey.sol";
import {PoolId} from "infinity-core/src/types/PoolId.sol";
import {IPositionManager} from "../interfaces/IPositionManager.sol";
import {BaseActionsRouter} from "../base/BaseActionsRouter.sol";
import {ReentrancyLock} from "../base/ReentrancyLock.sol";
import {DeltaResolver} from "../base/DeltaResolver.sol";
import {Permit2Forwarder} from "../base/Permit2Forwarder.sol";
import {ICLPositionManager} from "./interfaces/ICLPositionManager.sol";
import {CalldataDecoder} from "../libraries/CalldataDecoder.sol";
import {CLCalldataDecoder} from "./libraries/CLCalldataDecoder.sol";
import {Actions} from "../libraries/Actions.sol";
import {ERC721Permit} from "./base/ERC721Permit.sol";
import {SlippageCheck} from "../libraries/SlippageCheck.sol";
import {Multicall} from "../base/Multicall.sol";
import {CLNotifier} from "./base/CLNotifier.sol";
import {CLPositionInfo, CLPositionInfoLibrary} from "./libraries/CLPositionInfoLibrary.sol";
import {ICLSubscriber} from "./interfaces/ICLSubscriber.sol";
import {ICLPositionDescriptor} from "./interfaces/ICLPositionDescriptor.sol";
import {NativeWrapper} from "../base/NativeWrapper.sol";
import {IWETH9} from "../interfaces/external/IWETH9.sol";
import {LiquidityAmounts} from "../pool-cl/libraries/LiquidityAmounts.sol";
import {TickMath} from "infinity-core/src/pool-cl/libraries/TickMath.sol";
/// @title CLPositionManager
/// @notice Contract for modifying liquidity for PCS Infinity CL pools
contract CLPositionManager is
ICLPositionManager,
ERC721Permit,
Multicall,
DeltaResolver,
ReentrancyLock,
BaseActionsRouter,
CLNotifier,
Permit2Forwarder,
NativeWrapper
{
using CalldataDecoder for bytes;
using CLCalldataDecoder for bytes;
using CLPositionInfoLibrary for CLPositionInfo;
using SafeCast for uint256;
using SlippageCheck for BalanceDelta;
ICLPoolManager public immutable override clPoolManager;
/// @inheritdoc ICLPositionManager
/// @dev The ID of the next token that will be minted. Skips 0
uint256 public nextTokenId = 1;
ICLPositionDescriptor public immutable tokenDescriptor;
mapping(uint256 tokenId => CLPositionInfo info) public positionInfo;
mapping(bytes25 poolId => PoolKey poolKey) public poolKeys;
constructor(
IVault _vault,
ICLPoolManager _clPoolManager,
IAllowanceTransfer _permit2,
uint256 _unsubscribeGasLimit,
ICLPositionDescriptor _tokenDescriptor,
IWETH9 _weth9
)
BaseActionsRouter(_vault)
Permit2Forwarder(_permit2)
ERC721Permit("Soda Positions NFT", "SODA-POSM")
CLNotifier(_unsubscribeGasLimit)
NativeWrapper(_weth9)
{
clPoolManager = _clPoolManager;
tokenDescriptor = _tokenDescriptor;
}
/// @dev <wip> might be refactored to BasePositionManager later
/// @notice Reverts if the deadline has passed
/// @param deadline The timestamp at which the call is no longer valid, passed in by the caller
modifier checkDeadline(uint256 deadline) {
if (block.timestamp > deadline) revert DeadlinePassed(deadline);
_;
}
/// @notice Reverts if the caller is not the owner or approved for the ERC721 token
/// @param caller The address of the caller
/// @param tokenId the unique identifier of the ERC721 token
/// @dev either msg.sender or msgSender() is passed in as the caller
/// msgSender() should ONLY be used if this is being called from within the lockAcquired
modifier onlyIfApproved(address caller, uint256 tokenId) override {
if (!_isApprovedOrOwner(caller, tokenId)) revert NotApproved(caller);
_;
}
/// @notice Enforces that the vault is unlocked.
modifier onlyIfVaultUnlocked() override {
if (vault.getLocker() != address(0)) revert VaultMustBeUnlocked();
_;
}
function tokenURI(uint256 tokenId) public view override returns (string memory) {
return tokenDescriptor.tokenURI(this, tokenId);
}
/// @dev Register my contract on Sonic FeeM
function registerMe() external {
(bool _success,) = address(0xDC2B0D2Dd2b7759D97D50db4eabDC36973110830).call(
abi.encodeWithSignature("selfRegister(uint256)", 158)
);
require(_success, "FeeM registration failed");
}
/// @inheritdoc ICLPositionManager
function initializePool(PoolKey calldata key, uint160 sqrtPriceX96) external payable override returns (int24) {
/// @dev Swallow any error. If the pool revert due to other errors eg. currencyOutOfOrder etc..,
/// then follow-up action to the pool will still revert accordingly
try clPoolManager.initialize(key, sqrtPriceX96) returns (int24 tick) {
return tick;
} catch {
return type(int24).max;
}
}
/// @inheritdoc IPositionManager
function modifyLiquidities(bytes calldata payload, uint256 deadline)
external
payable
override
isNotLocked
checkDeadline(deadline)
{
_executeActions(payload);
}
/// @inheritdoc IPositionManager
function modifyLiquiditiesWithoutLock(bytes calldata actions, bytes[] calldata params)
external
payable
override
isNotLocked
{
_executeActionsWithoutLock(actions, params);
}
/// @inheritdoc BaseActionsRouter
function msgSender() public view override returns (address) {
return _getLocker();
}
function _handleAction(uint256 action, bytes calldata params) internal virtual override {
if (action < Actions.CL_SWAP_EXACT_IN_SINGLE) {
if (action == Actions.CL_INCREASE_LIQUIDITY) {
(uint256 tokenId, uint256 liquidity, uint128 amount0Max, uint128 amount1Max, bytes calldata hookData) =
params.decodeCLModifyLiquidityParams();
_increase(tokenId, liquidity, amount0Max, amount1Max, hookData);
return;
} else if (action == Actions.CL_INCREASE_LIQUIDITY_FROM_DELTAS) {
(uint256 tokenId, uint128 amount0Max, uint128 amount1Max, bytes calldata hookData) =
params.decodeCLIncreaseLiquidityFromDeltasParams();
_increaseFromDeltas(tokenId, amount0Max, amount1Max, hookData);
return;
} else if (action == Actions.CL_DECREASE_LIQUIDITY) {
(uint256 tokenId, uint256 liquidity, uint128 amount0Min, uint128 amount1Min, bytes calldata hookData) =
params.decodeCLModifyLiquidityParams();
_decrease(tokenId, liquidity, amount0Min, amount1Min, hookData);
return;
} else if (action == Actions.CL_MINT_POSITION) {
(
PoolKey calldata poolKey,
int24 tickLower,
int24 tickUpper,
uint256 liquidity,
uint128 amount0Max,
uint128 amount1Max,
address owner,
bytes calldata hookData
) = params.decodeCLMintParams();
_mint(poolKey, tickLower, tickUpper, liquidity, amount0Max, amount1Max, _mapRecipient(owner), hookData);
return;
} else if (action == Actions.CL_MINT_POSITION_FROM_DELTAS) {
(
PoolKey calldata poolKey,
int24 tickLower,
int24 tickUpper,
uint128 amount0Max,
uint128 amount1Max,
address owner,
bytes calldata hookData
) = params.decodeCLMintFromDeltasParams();
_mintFromDeltas(poolKey, tickLower, tickUpper, amount0Max, amount1Max, _mapRecipient(owner), hookData);
return;
} else if (action == Actions.CL_BURN_POSITION) {
// Will automatically decrease liquidity to 0 if the position is not already empty.
(uint256 tokenId, uint128 amount0Min, uint128 amount1Min, bytes calldata hookData) =
params.decodeCLBurnParams();
_burn(tokenId, amount0Min, amount1Min, hookData);
return;
}
} else {
if (action == Actions.SETTLE_PAIR) {
(Currency currency0, Currency currency1) = params.decodeCurrencyPair();
_settlePair(currency0, currency1);
return;
} else if (action == Actions.TAKE_PAIR) {
(Currency currency0, Currency currency1, address recipient) = params.decodeCurrencyPairAndAddress();
_takePair(currency0, currency1, _mapRecipient(recipient));
return;
} else if (action == Actions.SETTLE) {
(Currency currency, uint256 amount, bool payerIsUser) = params.decodeCurrencyUint256AndBool();
_settle(currency, _mapPayer(payerIsUser), _mapSettleAmount(amount, currency));
return;
} else if (action == Actions.TAKE) {
(Currency currency, address recipient, uint256 amount) = params.decodeCurrencyAddressAndUint256();
_take(currency, _mapRecipient(recipient), _mapTakeAmount(amount, currency));
return;
} else if (action == Actions.CLOSE_CURRENCY) {
Currency currency = params.decodeCurrency();
_close(currency);
return;
} else if (action == Actions.CLEAR_OR_TAKE) {
(Currency currency, uint256 amountMax) = params.decodeCurrencyAndUint256();
_clearOrTake(currency, amountMax);
return;
} else if (action == Actions.SWEEP) {
(Currency currency, address to) = params.decodeCurrencyAndAddress();
_sweep(currency, _mapRecipient(to));
return;
} else if (action == Actions.WRAP) {
uint256 amount = params.decodeUint256();
_wrap(_mapWrapUnwrapAmount(CurrencyLibrary.NATIVE, amount, Currency.wrap(address(WETH9))));
return;
} else if (action == Actions.UNWRAP) {
uint256 amount = params.decodeUint256();
_unwrap(_mapWrapUnwrapAmount(Currency.wrap(address(WETH9)), amount, CurrencyLibrary.NATIVE));
return;
}
}
revert UnsupportedAction(action);
}
/// @dev Calling increase with 0 liquidity will credit the caller with any underlying fees of the position
function _increase(
uint256 tokenId,
uint256 liquidity,
uint128 amount0Max,
uint128 amount1Max,
bytes calldata hookData
) internal onlyIfApproved(msgSender(), tokenId) {
(PoolKey memory poolKey, CLPositionInfo info) = getPoolAndPositionInfo(tokenId);
// Note: The tokenId is used as the salt for this position, so every minted position has unique storage in the pool manager.
(BalanceDelta liquidityDelta, BalanceDelta feesAccrued) =
_modifyLiquidity(info, poolKey, liquidity.toInt256(), bytes32(tokenId), hookData);
// Slippage checks should be done on the principal liquidityDelta which is the liquidityDelta - feesAccrued
(liquidityDelta - feesAccrued).validateMaxIn(amount0Max, amount1Max);
}
/// @dev The liquidity delta is derived from open deltas in the pool manager.
function _increaseFromDeltas(uint256 tokenId, uint128 amount0Max, uint128 amount1Max, bytes calldata hookData)
internal
onlyIfApproved(msgSender(), tokenId)
{
(PoolKey memory poolKey, CLPositionInfo info) = getPoolAndPositionInfo(tokenId);
(uint160 sqrtPriceX96,,,) = clPoolManager.getSlot0(poolKey.toId());
// Use the credit on the pool manager as the amounts for the mint.
uint256 liquidity = LiquidityAmounts.getLiquidityForAmounts(
sqrtPriceX96,
TickMath.getSqrtRatioAtTick(info.tickLower()),
TickMath.getSqrtRatioAtTick(info.tickUpper()),
_getFullCredit(poolKey.currency0),
_getFullCredit(poolKey.currency1)
);
// Note: The tokenId is used as the salt for this position, so every minted position has unique storage in the pool manager.
(BalanceDelta liquidityDelta, BalanceDelta feesAccrued) =
_modifyLiquidity(info, poolKey, liquidity.toInt256(), bytes32(tokenId), hookData);
// Slippage checks should be done on the principal liquidityDelta which is the liquidityDelta - feesAccrued
(liquidityDelta - feesAccrued).validateMaxIn(amount0Max, amount1Max);
}
/// @dev Calling decrease with 0 liquidity will credit the caller with any underlying fees of the position
function _decrease(
uint256 tokenId,
uint256 liquidity,
uint128 amount0Min,
uint128 amount1Min,
bytes calldata hookData
) internal onlyIfApproved(msgSender(), tokenId) {
(PoolKey memory poolKey, CLPositionInfo info) = getPoolAndPositionInfo(tokenId);
// Note: the tokenId is used as the salt.
(BalanceDelta liquidityDelta, BalanceDelta feesAccrued) =
_modifyLiquidity(info, poolKey, -(liquidity.toInt256()), bytes32(tokenId), hookData);
// Slippage checks should be done on the principal liquidityDelta which is the liquidityDelta - feesAccrued
(liquidityDelta - feesAccrued).validateMinOut(amount0Min, amount1Min);
}
function _mint(
PoolKey calldata poolKey,
int24 tickLower,
int24 tickUpper,
uint256 liquidity,
uint128 amount0Max,
uint128 amount1Max,
address owner,
bytes calldata hookData
) internal {
// mint receipt token
uint256 tokenId;
// tokenId is assigned to current nextTokenId before incrementing it
unchecked {
tokenId = nextTokenId++;
}
_mint(owner, tokenId);
// Initialize the position info
CLPositionInfo info = CLPositionInfoLibrary.initialize(poolKey, tickLower, tickUpper);
positionInfo[tokenId] = info;
// Store the poolKey if it is not already stored.
// if parameter (hook permission and tickSpacing) is bytes(0), it means the pool is not initialized yet
bytes25 poolId = info.poolId();
if (poolKeys[poolId].parameters == bytes32(0)) {
poolKeys[poolId] = poolKey;
}
// fee delta can be ignored as this is a new position
(BalanceDelta liquidityDelta,) =
_modifyLiquidity(info, poolKey, liquidity.toInt256(), bytes32(tokenId), hookData);
liquidityDelta.validateMaxIn(amount0Max, amount1Max);
emit MintPosition(tokenId);
}
function _mintFromDeltas(
PoolKey calldata poolKey,
int24 tickLower,
int24 tickUpper,
uint128 amount0Max,
uint128 amount1Max,
address owner,
bytes calldata hookData
) internal {
(uint160 sqrtPriceX96,,,) = clPoolManager.getSlot0(poolKey.toId());
// Use the credit on the pool manager as the amounts for the mint.
uint256 liquidity = LiquidityAmounts.getLiquidityForAmounts(
sqrtPriceX96,
TickMath.getSqrtRatioAtTick(tickLower),
TickMath.getSqrtRatioAtTick(tickUpper),
_getFullCredit(poolKey.currency0),
_getFullCredit(poolKey.currency1)
);
_mint(poolKey, tickLower, tickUpper, liquidity, amount0Max, amount1Max, owner, hookData);
}
/// @dev this is overloaded with ERC721Permit._burn
function _burn(uint256 tokenId, uint128 amount0Min, uint128 amount1Min, bytes calldata hookData)
internal
onlyIfApproved(msgSender(), tokenId)
{
(PoolKey memory poolKey, CLPositionInfo info) = getPoolAndPositionInfo(tokenId);
uint256 liquidity = uint256(_getLiquidity(tokenId, poolKey, info.tickLower(), info.tickUpper()));
address owner = ownerOf(tokenId);
// Clear the position info.
positionInfo[tokenId] = CLPositionInfoLibrary.EMPTY_POSITION_INFO;
// Burn the token.
_burn(tokenId);
// Can only call modify if there is non zero liquidity.
BalanceDelta feesAccrued;
if (liquidity > 0) {
BalanceDelta liquidityDelta;
(liquidityDelta, feesAccrued) = clPoolManager.modifyLiquidity(
poolKey,
ICLPoolManager.ModifyLiquidityParams({
tickLower: info.tickLower(),
tickUpper: info.tickUpper(),
liquidityDelta: -(liquidity.toInt256()),
salt: bytes32(tokenId)
}),
hookData
);
// Slippage checks should be done on the principal liquidityDelta which is the liquidityDelta - feesAccrued
(liquidityDelta - feesAccrued).validateMinOut(amount0Min, amount1Min);
emit ModifyLiquidity(tokenId, -(liquidity.toInt256()), feesAccrued);
}
if (info.hasSubscriber()) _removeSubscriberAndNotifyBurn(tokenId, owner, info, liquidity, feesAccrued);
}
function _settlePair(Currency currency0, Currency currency1) internal {
// the locker is the payer when settling
address caller = msgSender();
_settle(currency0, caller, _getFullDebt(currency0));
_settle(currency1, caller, _getFullDebt(currency1));
}
function _takePair(Currency currency0, Currency currency1, address recipient) internal {
_take(currency0, recipient, _getFullCredit(currency0));
_take(currency1, recipient, _getFullCredit(currency1));
}
function _close(Currency currency) internal {
// this address has applied all deltas on behalf of the user/owner
// it is safe to close this entire delta because of slippage checks throughout the batched calls.
int256 currencyDelta = vault.currencyDelta(address(this), currency);
// the locker is the payer or receiver
address caller = msgSender();
if (currencyDelta < 0) {
_settle(currency, caller, uint256(-currencyDelta));
} else {
_take(currency, caller, uint256(currencyDelta));
}
}
/// @dev integrators may elect to forfeit positive deltas with clear
/// if the forfeit amount exceeds the user-specified max, the amount is taken instead
function _clearOrTake(Currency currency, uint256 amountMax) internal {
uint256 delta = _getFullCredit(currency);
// forfeit the delta if its less than or equal to the user-specified limit
if (delta <= amountMax) {
vault.clear(currency, delta);
} else {
_take(currency, msgSender(), delta);
}
}
/// @notice Sweeps the entire contract balance of specified currency to the recipient
function _sweep(Currency currency, address to) internal {
uint256 balance = currency.balanceOfSelf();
if (balance > 0) currency.transfer(to, balance);
}
/// @dev if there is a subscriber attached to the position, this function will notify the subscriber
function _modifyLiquidity(
CLPositionInfo info,
PoolKey memory poolKey,
int256 liquidityChange,
bytes32 salt,
bytes calldata hookData
) internal returns (BalanceDelta liquidityDelta, BalanceDelta feesAccrued) {
(liquidityDelta, feesAccrued) = clPoolManager.modifyLiquidity(
poolKey,
ICLPoolManager.ModifyLiquidityParams({
tickLower: info.tickLower(),
tickUpper: info.tickUpper(),
liquidityDelta: liquidityChange,
salt: salt
}),
hookData
);
uint256 tokenId = uint256(salt);
emit ModifyLiquidity(tokenId, liquidityChange, feesAccrued);
if (info.hasSubscriber()) {
_notifyModifyLiquidity(tokenId, liquidityChange, feesAccrued);
}
}
function _pay(Currency currency, address payer, uint256 amount) internal override(DeltaResolver) {
if (payer == address(this)) {
currency.transfer(address(vault), amount);
} else {
permit2.transferFrom(payer, address(vault), uint160(amount), Currency.unwrap(currency));
}
}
/// @notice an internal helper used by CLNotifier
function _setSubscribed(uint256 tokenId) internal override {
positionInfo[tokenId] = positionInfo[tokenId].setSubscribe();
}
/// @notice an internal helper used by CLNotifier
function _setUnsubscribed(uint256 tokenId) internal override {
positionInfo[tokenId] = positionInfo[tokenId].setUnsubscribe();
}
/// @dev overrides solmate transferFrom in case a notification to subscribers is needed
/// @dev will revert if vault is locked
function transferFrom(address from, address to, uint256 id) public virtual override onlyIfVaultUnlocked {
super.transferFrom(from, to, id);
if (positionInfo[id].hasSubscriber()) _unsubscribe(id);
}
/// @inheritdoc ICLPositionManager
function getPoolAndPositionInfo(uint256 tokenId)
public
view
returns (PoolKey memory poolKey, CLPositionInfo info)
{
info = positionInfo[tokenId];
poolKey = poolKeys[info.poolId()];
}
/// @inheritdoc ICLPositionManager
function getPositionLiquidity(uint256 tokenId) external view returns (uint128 liquidity) {
(PoolKey memory poolKey, CLPositionInfo info) = getPoolAndPositionInfo(tokenId);
return _getLiquidity(tokenId, poolKey, info.tickLower(), info.tickUpper());
}
/// @inheritdoc ICLPositionManager
function positions(uint256 tokenId)
external
view
returns (
PoolKey memory poolKey,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
ICLSubscriber _subscriber
)
{
CLPositionInfo info;
(poolKey, info) = getPoolAndPositionInfo(tokenId);
PoolId poolId = poolKey.toId();
if (CLPositionInfo.unwrap(info) == 0) revert InvalidTokenID();
tickLower = info.tickLower();
tickUpper = info.tickUpper();
CLPosition.Info memory position =
clPoolManager.getPosition(poolId, address(this), tickLower, tickUpper, bytes32(tokenId));
liquidity = position.liquidity;
feeGrowthInside0LastX128 = position.feeGrowthInside0LastX128;
feeGrowthInside1LastX128 = position.feeGrowthInside1LastX128;
_subscriber = subscriber[tokenId];
}
function _getLiquidity(uint256 tokenId, PoolKey memory poolKey, int24 tickLower, int24 tickUpper)
internal
view
returns (uint128 liquidity)
{
CLPosition.Info memory position =
clPoolManager.getPosition(poolKey.toId(), address(this), tickLower, tickUpper, bytes32(tokenId));
liquidity = position.liquidity;
}
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Currency} from "../types/Currency.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {IVaultToken} from "./IVaultToken.sol";
interface IVault is IVaultToken {
event AppRegistered(address indexed app);
/// @notice Thrown when a app is not registered
error AppUnregistered();
/// @notice Thrown when a currency is not netted out after a lock
error CurrencyNotSettled();
/// @notice Thrown when there is already a locker
/// @param locker The address of the current locker
error LockerAlreadySet(address locker);
/// @notice Thrown when passing in msg.value for non-native currency
error SettleNonNativeCurrencyWithValue();
/// @notice Thrown when `clear` is called with an amount that is not exactly equal to the open currency delta.
error MustClearExactPositiveDelta();
/// @notice Thrown when there is no locker
error NoLocker();
/// @notice Thrown when collectFee is attempted on a token that is synced.
error FeeCurrencySynced();
function isAppRegistered(address app) external returns (bool);
/// @notice Returns the reserves for a a given pool type and currency
function reservesOfApp(address app, Currency currency) external view returns (uint256);
/// @notice register an app so that it can perform accounting base on vault
function registerApp(address app) external;
/// @notice Returns the locker who is locking the vault
function getLocker() external view returns (address locker);
/// @notice Returns the reserve and its amount that is currently being stored in trnasient storage
function getVaultReserve() external view returns (Currency, uint256);
/// @notice Returns lock data
function getUnsettledDeltasCount() external view returns (uint256 count);
/// @notice Get the current delta for a locker in the given currency
/// @param currency The currency for which to lookup the delta
function currencyDelta(address settler, Currency currency) external view returns (int256);
/// @notice All operations go through this function
/// @param data Any data to pass to the callback, via `ILockCallback(msg.sender).lockCallback(data)`
/// @return The data returned by the call to `ILockCallback(msg.sender).lockCallback(data)`
function lock(bytes calldata data) external returns (bytes memory);
/// @notice Called by registered app to account for a change in the pool balance,
/// convenient for AMM pool manager, typically after modifyLiquidity, swap, donate,
/// include the case where hookDelta is involved
/// @param currency0 The PoolKey currency0 to update
/// @param currency1 The PoolKey currency1 to update
/// @param delta The change in the pool's balance
/// @param settler The address whose delta will be updated
/// @param hookDelta The change in the pool's balance from hook
/// @param hook The address whose hookDelta will be updated
function accountAppBalanceDelta(
Currency currency0,
Currency currency1,
BalanceDelta delta,
address settler,
BalanceDelta hookDelta,
address hook
) external;
/// @notice Called by registered app to account for a change in the pool balance,
/// convenient for AMM pool manager, typically after modifyLiquidity, swap, donate
/// @param currency0 The PoolKey currency0 to update
/// @param currency1 The PoolKey currency1 to update
/// @param delta The change in the pool's balance
/// @param settler The address whose delta will be updated
function accountAppBalanceDelta(Currency currency0, Currency currency1, BalanceDelta delta, address settler)
external;
/// @notice This works as a general accounting mechanism for non-dex app
/// @param currency The currency to update
/// @param delta The change in the balance
/// @param settler The address whose delta will be updated
function accountAppBalanceDelta(Currency currency, int128 delta, address settler) external;
/// @notice Called by the user to net out some value owed to the user
/// @dev Will revert if the requested amount is not available, consider using `mint` instead
/// @dev Can also be used as a mechanism for free flash loans
function take(Currency currency, address to, uint256 amount) external;
/// @notice Writes the current ERC20 balance of the specified currency to transient storage
/// This is used to checkpoint balances for the manager and derive deltas for the caller.
/// @dev This MUST be called before any ERC20 tokens are sent into the contract, but can be skipped
/// for native tokens because the amount to settle is determined by the sent value.
/// However, if an ERC20 token has been synced and not settled, and the caller instead wants to settle
/// native funds, this function can be called with the native currency to then be able to settle the native currency
function sync(Currency token0) external;
/// @notice Called by the user to pay what is owed
function settle() external payable returns (uint256 paid);
/// @notice Called by the user to pay on behalf of another address
/// @param recipient The address to credit for the payment
/// @return paid The amount of currency settled
function settleFor(address recipient) external payable returns (uint256 paid);
/// @notice WARNING - Any currency that is cleared, will be non-retreivable, and locked in the contract permanently.
/// A call to clear will zero out a positive balance WITHOUT a corresponding transfer.
/// @dev This could be used to clear a balance that is considered dust.
/// Additionally, the amount must be the exact positive balance. This is to enforce that the caller is aware of the amount being cleared.
function clear(Currency currency, uint256 amount) external;
/// @notice Called by app to collect any fee related
/// @dev no restriction on caller, underflow happen if caller collect more than the reserve
function collectFee(Currency currency, uint256 amount, address recipient) external;
/// @notice Called by the user to store surplus tokens in the vault
function mint(address to, Currency currency, uint256 amount) external;
/// @notice Called by the user to use surplus tokens for payment settlement
function burn(address from, Currency currency, uint256 amount) external;
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20Minimal} from "../interfaces/IERC20Minimal.sol";
import {CustomRevert} from "../libraries/CustomRevert.sol";
type Currency is address;
using {greaterThan as >, lessThan as <, greaterThanOrEqualTo as >=, equals as ==} for Currency global;
using CurrencyLibrary for Currency global;
function equals(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) == Currency.unwrap(other);
}
function greaterThan(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) > Currency.unwrap(other);
}
function lessThan(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) < Currency.unwrap(other);
}
function greaterThanOrEqualTo(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) >= Currency.unwrap(other);
}
/// @title CurrencyLibrary
/// @dev This library allows for transferring and holding native tokens and ERC20 tokens
library CurrencyLibrary {
using CurrencyLibrary for Currency;
/// @notice Additional context for ERC-7751 wrapped error when a native transfer fails
error NativeTransferFailed();
/// @notice Additional context for ERC-7751 wrapped error when an ERC20 transfer fails
error ERC20TransferFailed();
/// @notice A constant to represent the native currency
Currency public constant NATIVE = Currency.wrap(address(0));
function transfer(Currency currency, address to, uint256 amount) internal {
// altered from https://github.com/transmissions11/solmate/blob/44a9963d4c78111f77caa0e65d677b8b46d6f2e6/src/utils/SafeTransferLib.sol
// modified custom error selectors
bool success;
if (currency.isNative()) {
assembly ("memory-safe") {
// Transfer the ETH and revert if it fails.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
// revert with NativeTransferFailed, containing the bubbled up error as an argument
if (!success) CustomRevert.bubbleUpAndRevertWith(to, bytes4(0), NativeTransferFailed.selector);
} else {
assembly ("memory-safe") {
// Get a pointer to some free memory.
let fmp := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(fmp, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(fmp, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(fmp, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success :=
and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), currency, 0, fmp, 68, 0, 32)
)
// Now clean the memory we used
mstore(fmp, 0) // 4 byte `selector` and 28 bytes of `to` were stored here
mstore(add(fmp, 0x20), 0) // 4 bytes of `to` and 28 bytes of `amount` were stored here
mstore(add(fmp, 0x40), 0) // 4 bytes of `amount` were stored here
}
// revert with ERC20TransferFailed, containing the bubbled up error as an argument
if (!success) {
CustomRevert.bubbleUpAndRevertWith(
Currency.unwrap(currency), IERC20Minimal.transfer.selector, ERC20TransferFailed.selector
);
}
}
}
function balanceOfSelf(Currency currency) internal view returns (uint256) {
if (currency.isNative()) {
return address(this).balance;
} else {
return IERC20Minimal(Currency.unwrap(currency)).balanceOf(address(this));
}
}
function balanceOf(Currency currency, address owner) internal view returns (uint256) {
if (currency.isNative()) {
return owner.balance;
} else {
return IERC20Minimal(Currency.unwrap(currency)).balanceOf(owner);
}
}
function isNative(Currency currency) internal pure returns (bool) {
return Currency.unwrap(currency) == Currency.unwrap(NATIVE);
}
function toId(Currency currency) internal pure returns (uint256) {
return uint160(Currency.unwrap(currency));
}
function fromId(uint256 id) internal pure returns (Currency) {
return Currency.wrap(address(uint160(id)));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {SafeCast} from "../libraries/SafeCast.sol";
/// @dev Two `int128` values packed into a single `int256` where the upper 128 bits represent the amount0
/// and the lower 128 bits represent the amount1.
type BalanceDelta is int256;
using {add as +, sub as -, eq as ==, neq as !=} for BalanceDelta global;
using BalanceDeltaLibrary for BalanceDelta global;
using SafeCast for int256;
function toBalanceDelta(int128 _amount0, int128 _amount1) pure returns (BalanceDelta balanceDelta) {
assembly ("memory-safe") {
balanceDelta := or(shl(128, _amount0), and(sub(shl(128, 1), 1), _amount1))
}
}
function add(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
int256 res0;
int256 res1;
assembly ("memory-safe") {
let a0 := sar(128, a)
let a1 := signextend(15, a)
let b0 := sar(128, b)
let b1 := signextend(15, b)
res0 := add(a0, b0)
res1 := add(a1, b1)
}
return toBalanceDelta(res0.toInt128(), res1.toInt128());
}
function sub(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
int256 res0;
int256 res1;
assembly ("memory-safe") {
let a0 := sar(128, a)
let a1 := signextend(15, a)
let b0 := sar(128, b)
let b1 := signextend(15, b)
res0 := sub(a0, b0)
res1 := sub(a1, b1)
}
return toBalanceDelta(res0.toInt128(), res1.toInt128());
}
function eq(BalanceDelta a, BalanceDelta b) pure returns (bool) {
return BalanceDelta.unwrap(a) == BalanceDelta.unwrap(b);
}
function neq(BalanceDelta a, BalanceDelta b) pure returns (bool) {
return BalanceDelta.unwrap(a) != BalanceDelta.unwrap(b);
}
/// @notice Library for getting the amount0 and amount1 deltas from the BalanceDelta type
library BalanceDeltaLibrary {
/// @notice Constant for a BalanceDelta of zero value
BalanceDelta public constant ZERO_DELTA = BalanceDelta.wrap(0);
function amount0(BalanceDelta balanceDelta) internal pure returns (int128 _amount0) {
assembly ("memory-safe") {
_amount0 := sar(128, balanceDelta)
}
}
function amount1(BalanceDelta balanceDelta) internal pure returns (int128 _amount1) {
assembly ("memory-safe") {
_amount1 := signextend(15, balanceDelta)
}
}
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Currency} from "../../types/Currency.sol";
import {PoolKey} from "../../types/PoolKey.sol";
import {CLPool} from "../libraries/CLPool.sol";
import {IHooks} from "../../interfaces/IHooks.sol";
import {IProtocolFees} from "../../interfaces/IProtocolFees.sol";
import {BalanceDelta} from "../../types/BalanceDelta.sol";
import {PoolId} from "../../types/PoolId.sol";
import {CLPosition} from "../libraries/CLPosition.sol";
import {IPoolManager} from "../../interfaces/IPoolManager.sol";
import {IExtsload} from "../../interfaces/IExtsload.sol";
import {Tick} from "../libraries/Tick.sol";
interface ICLPoolManager is IProtocolFees, IPoolManager, IExtsload {
/// @notice PoolManagerMismatch is thrown when pool manager specified in the pool key does not match current contract
error PoolManagerMismatch();
/// @notice Pools are limited to type(int16).max tickSpacing in #initialize, to prevent overflow
error TickSpacingTooLarge(int24 tickSpacing);
/// @notice Pools must have a positive non-zero tickSpacing passed to #initialize
error TickSpacingTooSmall(int24 tickSpacing);
/// @notice Error thrown when add liquidity is called when paused()
error PoolPaused();
/// @notice Thrown when trying to swap amount of 0
error SwapAmountCannotBeZero();
/// @notice Emitted when a new pool is initialized
/// @param id The abi encoded hash of the pool key struct for the new pool
/// @param currency0 The first currency of the pool by address sort order
/// @param currency1 The second currency of the pool by address sort order
/// @param hooks The hooks contract address for the pool, or address(0) if none
/// @param fee The lp fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @param parameters Includes hooks callback bitmap and tickSpacing
/// @param sqrtPriceX96 The sqrt(price) of the pool on initialization, as a Q64.96
/// @param tick The tick corresponding to the price of the pool on initialization
event Initialize(
PoolId indexed id,
Currency indexed currency0,
Currency indexed currency1,
IHooks hooks,
uint24 fee,
bytes32 parameters,
uint160 sqrtPriceX96,
int24 tick
);
/// @notice Emitted when a liquidity position is modified
/// @param id The abi encoded hash of the pool key struct for the pool that was modified
/// @param sender The address that modified the pool
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param liquidityDelta The amount of liquidity that was added or removed
/// @param salt The value used to create a unique liquidity position
event ModifyLiquidity(
PoolId indexed id, address indexed sender, int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt
);
/// @notice Emitted for swaps between currency0 and currency1
/// @param id The abi encoded hash of the pool key struct for the pool that was modified
/// @param sender The address that initiated the swap call, and that received the callback
/// @param amount0 The delta of the currency0 balance of the pool
/// @param amount1 The delta of the currency1 balance of the pool
/// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
/// @param liquidity The liquidity of the pool after the swap
/// @param tick The log base 1.0001 of the price of the pool after the swap
/// @param fee The fee collected upon every swap in the pool (including protocol fee and LP fee), denominated in hundredths of a bip
/// @param protocolFee Single direction protocol fee from the swap, also denominated in hundredths of a bip
event Swap(
PoolId indexed id,
address indexed sender,
int128 amount0,
int128 amount1,
uint160 sqrtPriceX96,
uint128 liquidity,
int24 tick,
uint24 fee,
uint16 protocolFee
);
/// @notice Emitted when donate happen
/// @param id The abi encoded hash of the pool key struct for the pool that was modified
/// @param sender The address that modified the pool
/// @param amount0 The delta of the currency0 balance of the pool
/// @param amount1 The delta of the currency1 balance of the pool
/// @param tick The donated tick
event Donate(PoolId indexed id, address indexed sender, uint256 amount0, uint256 amount1, int24 tick);
/// @notice Get the current value in slot0 of the given pool
function getSlot0(PoolId id)
external
view
returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee);
/// @notice Get the current value of liquidity of the given pool
function getLiquidity(PoolId id) external view returns (uint128 liquidity);
/// @notice Get the current value of liquidity for the specified pool and position
function getLiquidity(PoolId id, address owner, int24 tickLower, int24 tickUpper, bytes32 salt)
external
view
returns (uint128 liquidity);
/// @notice Get the tick info about a specific tick in the pool
function getPoolTickInfo(PoolId id, int24 tick) external view returns (Tick.Info memory);
/// @notice Get the tick bitmap info about a specific range (a word range) in the pool
function getPoolBitmapInfo(PoolId id, int16 word) external view returns (uint256 tickBitmap);
/// @notice Get the fee growth global for the given pool
/// @return feeGrowthGlobal0x128 The global fee growth for token0
/// @return feeGrowthGlobal1x128 The global fee growth for token1
/// @dev feeGrowthGlobal can be artificially inflated by a malicious actor and integrators should be careful using the value
/// For pools with a single liquidity position, actors can donate to themselves to freely inflate feeGrowthGlobal
/// atomically donating and collecting fees in the same lockAcquired callback may make the inflated value more extreme
function getFeeGrowthGlobals(PoolId id)
external
view
returns (uint256 feeGrowthGlobal0x128, uint256 feeGrowthGlobal1x128);
/// @notice Get the position struct for a specified pool and position
function getPosition(PoolId id, address owner, int24 tickLower, int24 tickUpper, bytes32 salt)
external
view
returns (CLPosition.Info memory position);
/// @notice Initialize the state for a given pool ID
function initialize(PoolKey memory key, uint160 sqrtPriceX96) external returns (int24 tick);
struct ModifyLiquidityParams {
// the lower and upper tick of the position
int24 tickLower;
int24 tickUpper;
// how to modify the liquidity
int256 liquidityDelta;
// a value to set if you want unique liquidity positions at the same range
bytes32 salt;
}
/// @notice Modify the position for the given pool
/// @return delta The total balance delta of the caller of modifyLiquidity.
/// @return feeDelta The balance delta of the fees generated in the liquidity range.
/// @dev feeDelta can be artificially inflated by a malicious actor and integrators should be careful using the value
/// For pools with a single liquidity position, actors can donate to themselves to inflate feeGrowthGlobal (and consequently feeDelta)
/// atomically donating and collecting fees in the same lockAcquired callback may make the inflated value more extreme
function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData)
external
returns (BalanceDelta delta, BalanceDelta feeDelta);
struct SwapParams {
bool zeroForOne;
int256 amountSpecified;
uint160 sqrtPriceLimitX96;
}
/// @notice Swap against the given pool
/// @param key The pool to swap in
/// @param params The parameters for swapping
/// @param hookData Any data to pass to the callback
/// @return delta The balance delta of the address swapping
/// @dev Swapping on low liquidity pools may cause unexpected swap amounts when liquidity available is less than amountSpecified.
/// Additionally note that if interacting with hooks that have the BEFORE_SWAP_RETURNS_DELTA_FLAG or AFTER_SWAP_RETURNS_DELTA_FLAG
/// the hook may alter the swap input/output. Integrators should perform checks on the returned swapDelta.
function swap(PoolKey memory key, SwapParams memory params, bytes calldata hookData)
external
returns (BalanceDelta delta);
/// @notice Donate the given currency amounts to the in-range liquidity providers of a pool
/// @dev Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds.
/// Donors should keep this in mind when designing donation mechanisms.
/// @dev This function donates to in-range LPs at slot0.tick. In certain edge-cases of the swap algorithm, the `sqrtPrice` of
/// a pool can be at the lower boundary of tick `n`, but the `slot0.tick` of the pool is already `n - 1`. In this case a call to
/// `donate` would donate to tick `n - 1` (slot0.tick) not tick `n` (getTickAtSqrtPrice(slot0.sqrtPriceX96)).
/// Read the comments in `Pool.swap()` for more information about this.
/// @param key The pool to donate to
/// @param amount0 The amount of currency0 to donate
/// @param amount1 The amount of currency1 to donate
/// @param hookData Any data to pass to the callback
/// @return delta The balance delta of the address donating
function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)
external
returns (BalanceDelta delta);
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {FullMath} from "./FullMath.sol";
import {FixedPoint128} from "./FixedPoint128.sol";
import {LiquidityMath} from "./LiquidityMath.sol";
/// @title CLPosition
/// @notice Positions represent an owner address' liquidity between a lower and upper tick boundary
/// @dev Positions store additional state for tracking fees owed to the position
library CLPosition {
/// @notice Cannot update a position with no liquidity
error CannotUpdateEmptyPosition();
// info stored for each user's position
struct Info {
// the amount of liquidity owned by this position
uint128 liquidity;
// fee growth per unit of liquidity as of the last update to liquidity or fees owed
uint256 feeGrowthInside0LastX128;
uint256 feeGrowthInside1LastX128;
}
/// @notice A helper function to calculate the position key
/// @param owner The address of the position owner
/// @param tickLower the lower tick boundary of the position
/// @param tickUpper the upper tick boundary of the position
/// @param salt A unique value to differentiate between multiple positions in the same range, by the same owner. Passed in by the caller.
function calculatePositionKey(address owner, int24 tickLower, int24 tickUpper, bytes32 salt)
internal
pure
returns (bytes32 key)
{
// same as `positionKey = keccak256(abi.encodePacked(tickLower, tickUpper, owner, salt))`
// make salt, tickUpper, tickLower, owner to be tightly packed in memory
assembly ("memory-safe") {
mstore(
0x0,
or(
shl(160, and(0xFFFFFF, tickUpper)),
or(shl(184, tickLower), and(owner, 0xffffffffffffffffffffffffffffffffffffffff))
)
) // tickLower at [0x06, 0x09), tickUpper at [0x09,0x0c), owner at [0x0c, 0x20)
mstore(0x20, salt) // salt at [0x20, 0x40)
key := keccak256(0x06, 0x3a) // len is 58 bytes
}
}
/// @notice Returns the Info struct of a position, given an owner and position boundaries
/// @param self The mapping containing all user positions
/// @param owner The address of the position owner
/// @param tickLower The lower tick boundary of the position
/// @param tickUpper The upper tick boundary of the position
/// @param salt A unique value to differentiate between multiple positions in the same range
/// @return position The position info struct of the given owners' position
function get(mapping(bytes32 => Info) storage self, address owner, int24 tickLower, int24 tickUpper, bytes32 salt)
internal
view
returns (Info storage position)
{
bytes32 key = calculatePositionKey(owner, tickLower, tickUpper, salt);
position = self[key];
}
/// @notice Credits accumulated fees to a user's position
/// @param self The individual position to update
/// @param liquidityDelta The change in pool liquidity as a result of the position update
/// @param feeGrowthInside0X128 The all-time fee growth in currency0, per unit of liquidity, inside the position's tick boundaries
/// @param feeGrowthInside1X128 The all-time fee growth in currency1, per unit of liquidity, inside the position's tick boundaries
/// @return feesOwed0 The amount of currency0 owed to the position owner
/// @return feesOwed1 The amount of currency1 owed to the position owner
function update(
Info storage self,
int128 liquidityDelta,
uint256 feeGrowthInside0X128,
uint256 feeGrowthInside1X128
) internal returns (uint256 feesOwed0, uint256 feesOwed1) {
uint128 liquidity = self.liquidity;
uint128 liquidityNext;
if (liquidityDelta == 0) {
if (liquidity == 0) revert CannotUpdateEmptyPosition(); // disallow pokes for 0 liquidity positions
liquidityNext = liquidity;
} else {
liquidityNext = LiquidityMath.addDelta(liquidity, liquidityDelta);
}
///@dev Tho overflow is expected, it's technically possible users can lose their rewards if it hits type(uint128).max
unchecked {
feesOwed0 =
FullMath.mulDiv(feeGrowthInside0X128 - self.feeGrowthInside0LastX128, liquidity, FixedPoint128.Q128);
feesOwed1 =
FullMath.mulDiv(feeGrowthInside1X128 - self.feeGrowthInside1LastX128, liquidity, FixedPoint128.Q128);
}
// update the position
if (liquidityDelta != 0) self.liquidity = liquidityNext;
self.feeGrowthInside0LastX128 = feeGrowthInside0X128;
self.feeGrowthInside1LastX128 = feeGrowthInside1X128;
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @title Safe casting methods
/// @notice Contains methods for safely casting between types
library SafeCast {
error SafeCastOverflow();
function _revertOverflow() private pure {
assembly ("memory-safe") {
// Store the function selector of `SafeCastOverflow()`.
mstore(0x00, 0x93dafdf1)
// Revert with (offset, size).
revert(0x1c, 0x04)
}
}
/// @notice Cast a uint256 to a uint160, revert on overflow
/// @param x The uint256 to be downcasted
/// @return y The downcasted integer, now type uint160
function toUint160(uint256 x) internal pure returns (uint160 y) {
y = uint160(x);
if (y != x) _revertOverflow();
}
/// @notice Cast a int256 to a int128, revert on overflow or underflow
/// @param x The int256 to be downcasted
/// @return y The downcasted integer, now type int128
function toInt128(int256 x) internal pure returns (int128 y) {
y = int128(x);
if (y != x) _revertOverflow();
}
/// @notice Cast a uint256 to a int256, revert on overflow
/// @param x The uint256 to be casted
/// @return y The casted integer, now type int256
function toInt256(uint256 x) internal pure returns (int256 y) {
y = int256(x);
if (y < 0) _revertOverflow();
}
/// @notice Cast a int256 to a uint256, revert on overflow
/// @param x The int256 to be casted
/// @return y The casted integer, now type uint256
function toUint256(int256 x) internal pure returns (uint256 y) {
if (x < 0) _revertOverflow();
y = uint256(x);
}
/// @notice Cast a uint256 to a int128, revert on overflow
/// @param x The uint256 to be downcasted
/// @return The downcasted integer, now type int128
function toInt128(uint256 x) internal pure returns (int128) {
if (x >= 1 << 127) _revertOverflow();
return int128(int256(x));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {IEIP712} from "./IEIP712.sol";
/// @title AllowanceTransfer
/// @notice Handles ERC20 token permissions through signature based allowance setting and ERC20 token transfers by checking allowed amounts
/// @dev Requires user's token approval on the Permit2 contract
interface IAllowanceTransfer is IEIP712 {
/// @notice Thrown when an allowance on a token has expired.
/// @param deadline The timestamp at which the allowed amount is no longer valid
error AllowanceExpired(uint256 deadline);
/// @notice Thrown when an allowance on a token has been depleted.
/// @param amount The maximum amount allowed
error InsufficientAllowance(uint256 amount);
/// @notice Thrown when too many nonces are invalidated.
error ExcessiveInvalidation();
/// @notice Emits an event when the owner successfully invalidates an ordered nonce.
event NonceInvalidation(
address indexed owner, address indexed token, address indexed spender, uint48 newNonce, uint48 oldNonce
);
/// @notice Emits an event when the owner successfully sets permissions on a token for the spender.
event Approval(
address indexed owner, address indexed token, address indexed spender, uint160 amount, uint48 expiration
);
/// @notice Emits an event when the owner successfully sets permissions using a permit signature on a token for the spender.
event Permit(
address indexed owner,
address indexed token,
address indexed spender,
uint160 amount,
uint48 expiration,
uint48 nonce
);
/// @notice Emits an event when the owner sets the allowance back to 0 with the lockdown function.
event Lockdown(address indexed owner, address token, address spender);
/// @notice The permit data for a token
struct PermitDetails {
// ERC20 token address
address token;
// the maximum amount allowed to spend
uint160 amount;
// timestamp at which a spender's token allowances become invalid
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice The permit message signed for a single token allownce
struct PermitSingle {
// the permit data for a single token alownce
PermitDetails details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The permit message signed for multiple token allowances
struct PermitBatch {
// the permit data for multiple token allowances
PermitDetails[] details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The saved permissions
/// @dev This info is saved per owner, per token, per spender and all signed over in the permit message
/// @dev Setting amount to type(uint160).max sets an unlimited approval
struct PackedAllowance {
// amount allowed
uint160 amount;
// permission expiry
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice A token spender pair.
struct TokenSpenderPair {
// the token the spender is approved
address token;
// the spender address
address spender;
}
/// @notice Details for a token transfer.
struct AllowanceTransferDetails {
// the owner of the token
address from;
// the recipient of the token
address to;
// the amount of the token
uint160 amount;
// the token to be transferred
address token;
}
/// @notice A mapping from owner address to token address to spender address to PackedAllowance struct, which contains details and conditions of the approval.
/// @notice The mapping is indexed in the above order see: allowance[ownerAddress][tokenAddress][spenderAddress]
/// @dev The packed slot holds the allowed amount, expiration at which the allowed amount is no longer valid, and current nonce thats updated on any signature based approvals.
function allowance(address user, address token, address spender)
external
view
returns (uint160 amount, uint48 expiration, uint48 nonce);
/// @notice Approves the spender to use up to amount of the specified token up until the expiration
/// @param token The token to approve
/// @param spender The spender address to approve
/// @param amount The approved amount of the token
/// @param expiration The timestamp at which the approval is no longer valid
/// @dev The packed allowance also holds a nonce, which will stay unchanged in approve
/// @dev Setting amount to type(uint160).max sets an unlimited approval
function approve(address token, address spender, uint160 amount, uint48 expiration) external;
/// @notice Permit a spender to a given amount of the owners token via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitSingle Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitSingle memory permitSingle, bytes calldata signature) external;
/// @notice Permit a spender to the signed amounts of the owners tokens via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitBatch Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitBatch memory permitBatch, bytes calldata signature) external;
/// @notice Transfer approved tokens from one address to another
/// @param from The address to transfer from
/// @param to The address of the recipient
/// @param amount The amount of the token to transfer
/// @param token The token address to transfer
/// @dev Requires the from address to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(address from, address to, uint160 amount, address token) external;
/// @notice Transfer approved tokens in a batch
/// @param transferDetails Array of owners, recipients, amounts, and tokens for the transfers
/// @dev Requires the from addresses to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(AllowanceTransferDetails[] calldata transferDetails) external;
/// @notice Enables performing a "lockdown" of the sender's Permit2 identity
/// by batch revoking approvals
/// @param approvals Array of approvals to revoke.
function lockdown(TokenSpenderPair[] calldata approvals) external;
/// @notice Invalidate nonces for a given (token, spender) pair
/// @param token The token to invalidate nonces for
/// @param spender The spender to invalidate nonces for
/// @param newNonce The new nonce to set. Invalidates all nonces less than it.
/// @dev Can't invalidate more than 2**16 nonces per transaction.
function invalidateNonces(address token, address spender, uint48 newNonce) external;
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "./PoolKey.sol";
type PoolId is bytes32;
/// @notice Library for computing the ID of a pool
library PoolIdLibrary {
function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) {
assembly ("memory-safe") {
// 0xc0 represents the total size of the poolKey struct (6 slots of 32 bytes)
poolId := keccak256(poolKey, 0xc0)
}
}
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Currency} from "./Currency.sol";
import {IPoolManager} from "../interfaces/IPoolManager.sol";
import {IHooks} from "../interfaces/IHooks.sol";
import {PoolIdLibrary} from "./PoolId.sol";
using PoolIdLibrary for PoolKey global;
/// @notice Returns the key for identifying a pool
struct PoolKey {
/// @notice The lower currency of the pool, sorted numerically
Currency currency0;
/// @notice The higher currency of the pool, sorted numerically
Currency currency1;
/// @notice The hooks of the pool, won't have a general interface because hooks interface vary on pool type
IHooks hooks;
/// @notice The pool manager of the pool
IPoolManager poolManager;
/// @notice The pool lp fee, capped at 1_000_000. If the pool has a dynamic fee then it must be exactly equal to 0x800000
uint24 fee;
/// @notice Hooks callback and pool specific parameters, i.e. tickSpacing for CL, binStep for bin
bytes32 parameters;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {IImmutableState} from "./IImmutableState.sol";
/// @title IPositionManager
/// @notice Interface for the PositionManager contract
interface IPositionManager is IImmutableState {
/// @notice Thrown when the block.timestamp exceeds the user-provided deadline
error DeadlinePassed(uint256 deadline);
/// @notice Thrown when calling transfer, subscribe, or unsubscribe on CLPositionManager
/// or batchTransferFrom on BinPositionManager when the vault is locked.
/// @dev This is to prevent hooks from being able to trigger actions or notifications at the same time the position is being modified.
error VaultMustBeUnlocked();
/// @notice Thrown when the token ID is bind to an unexisting pool
error InvalidTokenID();
/// @notice Unlocks Vault and batches actions for modifying liquidity
/// @dev This is the standard entrypoint for the PositionManager
/// @param payload is an encoding of actions, and parameters for those actions
/// @param deadline is the deadline for the batched actions to be executed
function modifyLiquidities(bytes calldata payload, uint256 deadline) external payable;
/// @notice Batches actions for modifying liquidity without getting a lock from vault
/// @dev This must be called by a contract that has already locked the vault
/// @param actions the actions to perform
/// @param params the parameters to provide for the actions
function modifyLiquiditiesWithoutLock(bytes calldata actions, bytes[] calldata params) external payable;
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.24;
import {IVault} from "infinity-core/src/interfaces/IVault.sol";
import {SafeCallback} from "./SafeCallback.sol";
import {CalldataDecoder} from "../libraries/CalldataDecoder.sol";
import {ActionConstants} from "../libraries/ActionConstants.sol";
/// @notice Abstract contract for performing a combination of actions on Pancakeswap infinity.
/// @dev Suggested uint256 action values are defined in Actions.sol, however any definition can be used
abstract contract BaseActionsRouter is SafeCallback {
using CalldataDecoder for bytes;
/// @notice emitted when different numbers of parameters and actions are provided
error InputLengthMismatch();
/// @notice emitted when an inheriting contract does not support an action
error UnsupportedAction(uint256 action);
constructor(IVault _vault) SafeCallback(_vault) {}
/// @notice internal function that triggers the execution of a set of actions on infinity
/// @dev inheriting contracts should call this function to trigger execution
function _executeActions(bytes calldata data) internal {
vault.lock(data);
}
/// @notice function that is called by the Vault through the SafeCallback.lockAcquired
/// @param data Abi encoding of (bytes actions, bytes[] params)
/// where params[i] is the encoded parameters for actions[i]
function _lockAcquired(bytes calldata data) internal override returns (bytes memory) {
// abi.decode(data, (bytes, bytes[]));
(bytes calldata actions, bytes[] calldata params) = data.decodeActionsRouterParams();
_executeActionsWithoutLock(actions, params);
return "";
}
function _executeActionsWithoutLock(bytes calldata actions, bytes[] calldata params) internal {
uint256 numActions = actions.length;
if (numActions != params.length) revert InputLengthMismatch();
for (uint256 actionIndex = 0; actionIndex < numActions; actionIndex++) {
uint256 action = uint8(actions[actionIndex]);
_handleAction(action, params[actionIndex]);
}
}
/// @notice function to handle the parsing and execution of an action and its parameters
function _handleAction(uint256 action, bytes calldata params) internal virtual;
/// @notice function that returns address considered executor of the actions
/// @dev The other context functions, _msgData and _msgValue, are not supported by this contract
/// In many contracts this will be the address that calls the initial entry point that calls `_executeActions`
/// `msg.sender` shouldn't be used, as this will be the vault contract that calls `lockAcquired`
/// If using ReentrancyLock.sol, this function can return _getLocker()
function msgSender() public view virtual returns (address);
/// @notice Calculates the address for a action
function _mapRecipient(address recipient) internal view returns (address) {
if (recipient == ActionConstants.MSG_SENDER) {
return msgSender();
} else if (recipient == ActionConstants.ADDRESS_THIS) {
return address(this);
} else {
return recipient;
}
}
/// @notice Calculates the payer for an action
function _mapPayer(bool payerIsUser) internal view returns (address) {
return payerIsUser ? msgSender() : address(this);
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.24;
/// @notice A transient reentrancy lock, that stores the caller's address as the lock
contract ReentrancyLock {
// The slot holding the locker state, transiently. bytes32(uint256(keccak256("LockedBy")) - 1)
bytes32 constant LOCKED_BY_SLOT = 0x0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a;
error ContractLocked();
modifier isNotLocked() {
if (_getLocker() != address(0)) revert ContractLocked();
_setLocker(msg.sender);
_;
_setLocker(address(0));
}
function _setLocker(address locker) internal {
assembly ("memory-safe") {
tstore(LOCKED_BY_SLOT, locker)
}
}
function _getLocker() internal view returns (address locker) {
assembly ("memory-safe") {
locker := tload(LOCKED_BY_SLOT)
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.24;
import {Currency} from "infinity-core/src/types/Currency.sol";
import {ImmutableState} from "./ImmutableState.sol";
import {ActionConstants} from "../libraries/ActionConstants.sol";
/// @notice Abstract contract used to sync, send, and settle funds to the vault
/// @dev Note that sync() is called before any erc-20 transfer in `settle`.
abstract contract DeltaResolver is ImmutableState {
/// @notice Emitted trying to settle a positive delta.
error DeltaNotPositive(Currency currency);
/// @notice Emitted trying to take a negative delta.
error DeltaNotNegative(Currency currency);
/// @notice Emitted when the contract does not have enough balance to wrap or unwrap.
error InsufficientBalance();
/// @notice Take an amount of currency out of the vault
/// @param currency Currency to take
/// @param recipient Address to receive the currency
/// @param amount Amount to take
/// @dev Returns early if the amount is 0
function _take(Currency currency, address recipient, uint256 amount) internal {
if (amount == 0) return;
vault.take(currency, recipient, amount);
}
/// @notice Pay and settle a currency to the vault
/// @dev The implementing contract must ensure that the `payer` is a secure address
/// @param currency Currency to settle
/// @param payer Address of the payer
/// @param amount Amount to send
/// @dev Returns early if the amount is 0
function _settle(Currency currency, address payer, uint256 amount) internal {
if (amount == 0) return;
vault.sync(currency);
if (currency.isNative()) {
vault.settle{value: amount}();
} else {
_pay(currency, payer, amount);
vault.settle();
}
}
/// @notice Abstract function for contracts to implement paying tokens to the vault
/// @dev The recipient of the payment should be the vault
/// @param token The token to settle. This is known not to be the native currency
/// @param payer The address who should pay tokens
/// @param amount The number of tokens to send
function _pay(Currency token, address payer, uint256 amount) internal virtual;
/// @notice Obtain the full amount owed by this contract (negative delta)
/// @param currency Currency to get the delta for
/// @return amount The amount owed by this contract as a uint256
function _getFullDebt(Currency currency) internal view returns (uint256 amount) {
int256 _amount = vault.currencyDelta(address(this), currency);
// If the amount is positive, it should be taken not settled.
if (_amount > 0) revert DeltaNotNegative(currency);
// Casting is safe due to limits on the total supply of a pool
amount = uint256(-_amount);
}
/// @notice Obtain the full credit owed to this contract (positive delta)
/// @param currency Currency to get the delta for
/// @return amount The amount owed to this contract as a uint256
function _getFullCredit(Currency currency) internal view returns (uint256 amount) {
int256 _amount = vault.currencyDelta(address(this), currency);
// If the amount is negative, it should be settled not taken.
if (_amount < 0) revert DeltaNotPositive(currency);
amount = uint256(_amount);
}
/// @notice Calculates the amount for a settle action
function _mapSettleAmount(uint256 amount, Currency currency) internal view returns (uint256) {
if (amount == ActionConstants.CONTRACT_BALANCE) {
return currency.balanceOfSelf();
} else if (amount == ActionConstants.OPEN_DELTA) {
return _getFullDebt(currency);
} else {
return amount;
}
}
/// @notice Calculates the amount for a take action
function _mapTakeAmount(uint256 amount, Currency currency) internal view returns (uint256) {
if (amount == ActionConstants.OPEN_DELTA) {
return _getFullCredit(currency);
} else {
return amount;
}
}
/// @notice Calculates the sanitized amount before wrapping/unwrapping.
/// @param inputCurrency The currency, either native or wrapped native, that this contract holds
/// @param amount The amount to wrap or unwrap. Can be CONTRACT_BALANCE, OPEN_DELTA or a specific amount
/// @param outputCurrency The currency after the wrap/unwrap that the user may owe a balance in on the poolManager
function _mapWrapUnwrapAmount(Currency inputCurrency, uint256 amount, Currency outputCurrency)
internal
view
returns (uint256)
{
// if wrapping, the balance in this contract is in ETH
// if unwrapping, the balance in this contract is in WETH
uint256 balance = inputCurrency.balanceOf(address(this));
if (amount == ActionConstants.CONTRACT_BALANCE) {
// return early to avoid unnecessary balance check
return balance;
}
if (amount == ActionConstants.OPEN_DELTA) {
// if wrapping, the open currency on the PoolManager is WETH.
// if unwrapping, the open currency on the PoolManager is ETH.
// note that we use the DEBT amount. Positive deltas can be taken and then wrapped.
amount = _getFullDebt(outputCurrency);
}
if (amount > balance) revert InsufficientBalance();
return amount;
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol";
/// @notice PermitForwarder allows permitting this contract as a spender on permit2
/// @dev This contract does not enforce the spender to be this contract, but that is the intended use case
contract Permit2Forwarder {
/// @notice the Permit2 contract to forward approvals
IAllowanceTransfer public immutable permit2;
constructor(IAllowanceTransfer _permit2) {
permit2 = _permit2;
}
/// @notice allows forwarding a single permit to permit2
/// @dev this function is payable to allow multicall with NATIVE based actions
/// @param owner the owner of the tokens
/// @param permitSingle the permit data
/// @param signature the signature of the permit; abi.encodePacked(r, s, v)
function permit(address owner, IAllowanceTransfer.PermitSingle calldata permitSingle, bytes calldata signature)
external
payable
returns (bytes memory err)
{
// use try/catch in case an actor front-runs the permit, which would DOS multicalls
try permit2.permit(owner, permitSingle, signature) {}
catch (bytes memory reason) {
err = reason;
}
}
/// @notice allows forwarding batch permits to permit2
/// @dev this function is payable to allow multicall with NATIVE based actions
/// @param owner the owner of the tokens
/// @param _permitBatch a batch of approvals
/// @param signature the signature of the permit; abi.encodePacked(r, s, v)
function permitBatch(address owner, IAllowanceTransfer.PermitBatch calldata _permitBatch, bytes calldata signature)
external
payable
returns (bytes memory err)
{
// use try/catch in case an actor front-runs the permit, which would DOS multicalls
try permit2.permit(owner, _permitBatch, signature) {}
catch (bytes memory reason) {
err = reason;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {PoolKey} from "infinity-core/src/types/PoolKey.sol";
import {BalanceDelta} from "infinity-core/src/types/BalanceDelta.sol";
import {ICLPoolManager} from "infinity-core/src/pool-cl/interfaces/ICLPoolManager.sol";
import {IPositionManager} from "../../interfaces/IPositionManager.sol";
import {CLPositionInfo} from "../libraries/CLPositionInfoLibrary.sol";
import {ICLSubscriber} from "./ICLSubscriber.sol";
interface ICLPositionManager is IPositionManager {
/// @notice Thrown when the caller is not approved to modify a position
error NotApproved(address caller);
/// @notice Emitted when a new liquidity position is minted
event MintPosition(uint256 indexed tokenId);
/// @notice Emitted when liquidity is modified
/// @param tokenId the tokenId of the position that was modified
/// @param liquidityChange the change in liquidity of the position
/// @param feesAccrued the fees collected from the liquidity change
event ModifyLiquidity(uint256 indexed tokenId, int256 liquidityChange, BalanceDelta feesAccrued);
/// @notice Get the clPoolManager
function clPoolManager() external view returns (ICLPoolManager);
/// @notice Initialize an infinity cl pool
/// @dev If the pool is already initialized, this function will not revert and just return type(int24).max
/// @param key the PoolKey of the pool to initialize
/// @param sqrtPriceX96 the initial sqrtPriceX96 of the pool
/// @return tick The current tick of the pool
function initializePool(PoolKey calldata key, uint160 sqrtPriceX96) external payable returns (int24);
/// @notice Used to get the ID that will be used for the next minted liquidity position
/// @return uint256 The next token ID
function nextTokenId() external view returns (uint256);
/// @param tokenId the ERC721 tokenId
/// @return liquidity the position's liquidity, as a liquidityAmount
/// @dev this value can be processed as an amount0 and amount1 by using the LiquidityAmounts library
function getPositionLiquidity(uint256 tokenId) external view returns (uint128 liquidity);
/// @notice Get the detailed information for a specified position
/// @param tokenId the ERC721 tokenId
/// @return poolKey the pool key of the position
/// @return tickLower the lower tick of the position
/// @return tickUpper the upper tick of the position
/// @return liquidity the liquidity of the position
/// @return feeGrowthInside0LastX128 the fee growth count of token0 since last time updated
/// @return feeGrowthInside1LastX128 the fee growth count of token1 since last time updated
/// @return _subscriber the address of the subscriber, if not set, it returns address(0)
function positions(uint256 tokenId)
external
view
returns (
PoolKey memory poolKey,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
ICLSubscriber _subscriber
);
/// @param tokenId the ERC721 tokenId
/// @return poolKey the pool key of the position
/// @return CLPositionInfo a uint256 packed value holding information about the position including the range (tickLower, tickUpper)
function getPoolAndPositionInfo(uint256 tokenId) external view returns (PoolKey memory, CLPositionInfo);
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {Currency} from "infinity-core/src/types/Currency.sol";
/// @title Library for abi decoding in calldata
library CalldataDecoder {
using CalldataDecoder for bytes;
error SliceOutOfBounds();
/// @notice mask used for offsets and lengths to ensure no overflow
/// @dev no sane abi encoding will pass in an offset or length greater than type(uint32).max
/// (note that this does deviate from standard solidity behavior and offsets/lengths will
/// be interpreted as mod type(uint32).max which will only impact malicious/buggy callers)
uint256 constant OFFSET_OR_LENGTH_MASK = 0xffffffff;
uint256 constant OFFSET_OR_LENGTH_MASK_AND_WORD_ALIGN = 0xffffffe0;
/// @notice equivalent to SliceOutOfBounds.selector, stored in least-significant bits
uint256 constant SLICE_ERROR_SELECTOR = 0x3b99b53d;
/// @dev equivalent to: abi.decode(params, (bytes, bytes[])) in calldata (requires strict abi encoding)
function decodeActionsRouterParams(bytes calldata _bytes)
internal
pure
returns (bytes calldata actions, bytes[] calldata params)
{
assembly ("memory-safe") {
// Strict encoding requires that the data begin with:
// 0x00: 0x40 (offset to `actions.length`)
// 0x20: 0x60 + actions.length (offset to `params.length`)
// 0x40: `actions.length`
// 0x60: beginning of actions
// Verify actions offset matches strict encoding
let invalidData := xor(calldataload(_bytes.offset), 0x40)
actions.offset := add(_bytes.offset, 0x60)
actions.length := and(calldataload(add(_bytes.offset, 0x40)), OFFSET_OR_LENGTH_MASK)
// Round actions length up to be word-aligned, and add 0x60 (for the first 3 words of encoding)
let paramsLengthOffset := add(and(add(actions.length, 0x1f), OFFSET_OR_LENGTH_MASK_AND_WORD_ALIGN), 0x60)
// Verify params offset matches strict encoding
invalidData := or(invalidData, xor(calldataload(add(_bytes.offset, 0x20)), paramsLengthOffset))
let paramsLengthPointer := add(_bytes.offset, paramsLengthOffset)
params.length := and(calldataload(paramsLengthPointer), OFFSET_OR_LENGTH_MASK)
params.offset := add(paramsLengthPointer, 0x20)
// Expected offset for `params[0]` is params.length * 32
// As the first `params.length` slots are pointers to each of the array element lengths
let tailOffset := shl(5, params.length)
let expectedOffset := tailOffset
for { let offset := 0 } lt(offset, tailOffset) { offset := add(offset, 32) } {
let itemLengthOffset := calldataload(add(params.offset, offset))
// Verify that the offset matches the expected offset from strict encoding
invalidData := or(invalidData, xor(itemLengthOffset, expectedOffset))
let itemLengthPointer := add(params.offset, itemLengthOffset)
let length :=
add(and(add(calldataload(itemLengthPointer), 0x1f), OFFSET_OR_LENGTH_MASK_AND_WORD_ALIGN), 0x20)
expectedOffset := add(expectedOffset, length)
}
// if the data encoding was invalid, or the provided bytes string isn't as long as the encoding says, revert
if or(invalidData, lt(add(_bytes.length, _bytes.offset), add(params.offset, expectedOffset))) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
}
}
/// @dev equivalent to: abi.decode(params, (Currency)) in calldata
function decodeCurrency(bytes calldata params) internal pure returns (Currency currency) {
assembly ("memory-safe") {
if lt(params.length, 0x20) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency := calldataload(params.offset)
}
}
/// @dev equivalent to: abi.decode(params, (Currency, Currency)) in calldata
function decodeCurrencyPair(bytes calldata params) internal pure returns (Currency currency0, Currency currency1) {
assembly ("memory-safe") {
if lt(params.length, 0x40) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency0 := calldataload(params.offset)
currency1 := calldataload(add(params.offset, 0x20))
}
}
/// @dev equivalent to: abi.decode(params, (Currency, Currency, address)) in calldata
function decodeCurrencyPairAndAddress(bytes calldata params)
internal
pure
returns (Currency currency0, Currency currency1, address _address)
{
assembly ("memory-safe") {
if lt(params.length, 0x60) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency0 := calldataload(params.offset)
currency1 := calldataload(add(params.offset, 0x20))
_address := calldataload(add(params.offset, 0x40))
}
}
/// @dev equivalent to: abi.decode(params, (Currency, address)) in calldata
function decodeCurrencyAndAddress(bytes calldata params)
internal
pure
returns (Currency currency, address _address)
{
assembly ("memory-safe") {
if lt(params.length, 0x40) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency := calldataload(params.offset)
_address := calldataload(add(params.offset, 0x20))
}
}
/// @dev equivalent to: abi.decode(params, (Currency, address, uint256)) in calldata
function decodeCurrencyAddressAndUint256(bytes calldata params)
internal
pure
returns (Currency currency, address _address, uint256 amount)
{
assembly ("memory-safe") {
if lt(params.length, 0x60) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency := calldataload(params.offset)
_address := calldataload(add(params.offset, 0x20))
amount := calldataload(add(params.offset, 0x40))
}
}
/// @dev equivalent to: abi.decode(params, (Currency, uint256)) in calldata
function decodeCurrencyAndUint256(bytes calldata params)
internal
pure
returns (Currency currency, uint256 amount)
{
assembly ("memory-safe") {
if lt(params.length, 0x40) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency := calldataload(params.offset)
amount := calldataload(add(params.offset, 0x20))
}
}
/// @dev equivalent to: abi.decode(params, (uint256)) in calldata
function decodeUint256(bytes calldata params) internal pure returns (uint256 amount) {
assembly ("memory-safe") {
if lt(params.length, 0x20) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
amount := calldataload(params.offset)
}
}
/// @dev equivalent to: abi.decode(params, (Currency, uint256, bool)) in calldata
function decodeCurrencyUint256AndBool(bytes calldata params)
internal
pure
returns (Currency currency, uint256 amount, bool boolean)
{
assembly ("memory-safe") {
if lt(params.length, 0x60) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
currency := calldataload(params.offset)
amount := calldataload(add(params.offset, 0x20))
boolean := calldataload(add(params.offset, 0x40))
}
}
/// @notice Decode the `_arg`-th element in `_bytes` as `bytes`
/// @param _bytes The input bytes string to extract a bytes string from
/// @param _arg The index of the argument to extract
function toBytes(bytes calldata _bytes, uint256 _arg) internal pure returns (bytes calldata res) {
uint256 length;
assembly ("memory-safe") {
// The offset of the `_arg`-th element is `32 * arg`, which stores the offset of the length pointer.
// shl(5, x) is equivalent to mul(32, x)
let lengthPtr :=
add(_bytes.offset, and(calldataload(add(_bytes.offset, shl(5, _arg))), OFFSET_OR_LENGTH_MASK))
// the number of bytes in the bytes string
length := and(calldataload(lengthPtr), OFFSET_OR_LENGTH_MASK)
// the offset where the bytes string begins
let offset := add(lengthPtr, 0x20)
// assign the return parameters
res.length := length
res.offset := offset
// if the provided bytes string isn't as long as the encoding says, revert
if lt(add(_bytes.length, _bytes.offset), add(length, offset)) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {IInfinityRouter} from "../../interfaces/IInfinityRouter.sol";
import {CalldataDecoder} from "../../libraries/CalldataDecoder.sol";
import {PoolKey} from "infinity-core/src/types/PoolKey.sol";
/// @title Library for abi decoding in cl pool calldata
library CLCalldataDecoder {
using CalldataDecoder for bytes;
/// @notice equivalent to SliceOutOfBounds.selector, stored in least-significant bits
uint256 constant SLICE_ERROR_SELECTOR = 0x3b99b53d;
/// @dev equivalent to: abi.decode(params, (IInfinityRouter.CLExactInputParams))
function decodeCLSwapExactInParams(bytes calldata params)
internal
pure
returns (IInfinityRouter.CLSwapExactInputParams calldata swapParams)
{
// CLExactInputParams is a variable length struct so we just have to look up its location
assembly ("memory-safe") {
// only safety checks for the minimum length, where path is empty
// 0xa0 = 5 * 0x20 -> 3 elements, path offset, and path length 0
if lt(params.length, 0xa0) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
swapParams := add(params.offset, calldataload(params.offset))
}
}
/// @dev equivalent to: abi.decode(params, (IInfinityRouter.CLExactInputSingleParams))
function decodeCLSwapExactInSingleParams(bytes calldata params)
internal
pure
returns (IInfinityRouter.CLSwapExactInputSingleParams calldata swapParams)
{
// CLExactInputSingleParams is a variable length struct so we just have to look up its location
assembly ("memory-safe") {
// only safety checks for the minimum length, where hookData is empty
// 0x160 = 11 * 0x20 -> 9 elements, bytes offset, and bytes length 0
if lt(params.length, 0x160) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
swapParams := add(params.offset, calldataload(params.offset))
}
}
/// @dev equivalent to: abi.decode(params, (IInfinityRouter.CLExactOutputParams))
function decodeCLSwapExactOutParams(bytes calldata params)
internal
pure
returns (IInfinityRouter.CLSwapExactOutputParams calldata swapParams)
{
// CLExactOutputParams is a variable length struct so we just have to look up its location
assembly ("memory-safe") {
// only safety checks for the minimum length, where path is empty
// 0xa0 = 5 * 0x20 -> 3 elements, path offset, and path length 0
if lt(params.length, 0xa0) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
swapParams := add(params.offset, calldataload(params.offset))
}
}
/// @dev equivalent to: abi.decode(params, (IInfinityRouter.CLExactOutputSingleParams))
function decodeCLSwapExactOutSingleParams(bytes calldata params)
internal
pure
returns (IInfinityRouter.CLSwapExactOutputSingleParams calldata swapParams)
{
// CLExactOutputSingleParams is a variable length struct so we just have to look up its location
assembly ("memory-safe") {
// only safety checks for the minimum length, where hookData is empty
// 0x160 = 9 * 0x20 -> 9 elements, bytes offset, and bytes length 0
if lt(params.length, 0x160) {
mstore(0, SLICE_ERROR_SELECTOR)
revert(0x1c, 4)
}
swapParams := add(params.offset, calldataload(params.offset))
}
}
/// @dev equivalent to: abi.decode(params, (uint256, uint256, uint128, uint128, bytes)) in calldata
function decodeCLModifyLiquidityParams(bytes calldata params)
internal
pure
returns (uint256 tokenId, uint256 liquidity, uint128 amount0, uint128 amount1, bytes calldata hookData)
{
// length validation is already handled in `params.toBytes`
assembly ("memory-safe") {
tokenId := calldataload(params.offset)
liquidity := calldataload(add(params.offset, 0x20))
amount0 := calldataload(add(params.offset, 0x40))
amount1 := calldataload(add(params.offset, 0x60))
}
hookData = params.toBytes(4);
}
/// @dev equivalent to: abi.decode(params, (uint256, uint128, uint128, bytes)) in calldata
function decodeCLIncreaseLiquidityFromDeltasParams(bytes calldata params)
internal
pure
returns (uint256 tokenId, uint128 amount0Max, uint128 amount1Max, bytes calldata hookData)
{
// length validation is already handled in `params.toBytes`
assembly ("memory-safe") {
tokenId := calldataload(params.offset)
amount0Max := calldataload(add(params.offset, 0x20))
amount1Max := calldataload(add(params.offset, 0x40))
}
hookData = params.toBytes(3);
}
/// @dev equivalent to: abi.decode(params, (PoolKey, int24, int24, uint256, uint128, uint128, address, bytes)) in calldata
function decodeCLMintParams(bytes calldata params)
internal
pure
returns (
PoolKey calldata poolKey,
int24 tickLower,
int24 tickUpper,
uint256 liquidity,
uint128 amount0Max,
uint128 amount1Max,
address owner,
bytes calldata hookData
)
{
// length validation is already handled in `params.toBytes`
assembly ("memory-safe") {
poolKey := params.offset
tickLower := calldataload(add(params.offset, 0xc0))
tickUpper := calldataload(add(params.offset, 0xe0))
liquidity := calldataload(add(params.offset, 0x100))
amount0Max := calldataload(add(params.offset, 0x120))
amount1Max := calldataload(add(params.offset, 0x140))
owner := calldataload(add(params.offset, 0x160))
}
hookData = params.toBytes(12);
}
/// @dev equivalent to: abi.decode(params, (PoolKey, int24, int24, uint128, uint128, address, bytes)) in calldata
function decodeCLMintFromDeltasParams(bytes calldata params)
internal
pure
returns (
PoolKey calldata poolKey,
int24 tickLower,
int24 tickUpper,
uint128 amount0Max,
uint128 amount1Max,
address owner,
bytes calldata hookData
)
{
// length validation is already handled in `params.toBytes`
assembly ("memory-safe") {
poolKey := params.offset
tickLower := calldataload(add(params.offset, 0xc0))
tickUpper := calldataload(add(params.offset, 0xe0))
amount0Max := calldataload(add(params.offset, 0x100))
amount1Max := calldataload(add(params.offset, 0x120))
owner := calldataload(add(params.offset, 0x140))
}
hookData = params.toBytes(11);
}
/// @dev equivalent to: abi.decode(params, (uint256, uint128, uint128, bytes)) in calldata
function decodeCLBurnParams(bytes calldata params)
internal
pure
returns (uint256 tokenId, uint128 amount0Min, uint128 amount1Min, bytes calldata hookData)
{
// length validation is already handled in `params.toBytes`
assembly ("memory-safe") {
tokenId := calldataload(params.offset)
amount0Min := calldataload(add(params.offset, 0x20))
amount1Min := calldataload(add(params.offset, 0x40))
}
hookData = params.toBytes(3);
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @notice Library to define different pool actions.
/// @dev These are suggested common commands, however additional commands should be defined as required
/// Some of these actions are not supported in the Router contracts or Position Manager contracts, but are left as they may be helpful commands for other peripheral contracts.
library Actions {
// cl-pool actions
// liquidity actions
uint256 internal constant CL_INCREASE_LIQUIDITY = 0x00;
uint256 internal constant CL_DECREASE_LIQUIDITY = 0x01;
uint256 internal constant CL_MINT_POSITION = 0x02;
uint256 internal constant CL_BURN_POSITION = 0x03;
uint256 internal constant CL_INCREASE_LIQUIDITY_FROM_DELTAS = 0x04;
uint256 internal constant CL_MINT_POSITION_FROM_DELTAS = 0x05;
// swapping
uint256 internal constant CL_SWAP_EXACT_IN_SINGLE = 0x06;
uint256 internal constant CL_SWAP_EXACT_IN = 0x07;
uint256 internal constant CL_SWAP_EXACT_OUT_SINGLE = 0x08;
uint256 internal constant CL_SWAP_EXACT_OUT = 0x09;
// donate
/// @dev this is not supported in the position manager or router
uint256 internal constant CL_DONATE = 0x0a;
// closing deltas on the pool manager
// settling
uint256 internal constant SETTLE = 0x0b;
uint256 internal constant SETTLE_ALL = 0x0c;
uint256 internal constant SETTLE_PAIR = 0x0d;
// taking
uint256 internal constant TAKE = 0x0e;
uint256 internal constant TAKE_ALL = 0x0f;
uint256 internal constant TAKE_PORTION = 0x10;
uint256 internal constant TAKE_PAIR = 0x11;
uint256 internal constant CLOSE_CURRENCY = 0x12;
uint256 internal constant CLEAR_OR_TAKE = 0x13;
uint256 internal constant SWEEP = 0x14;
uint256 internal constant WRAP = 0x15;
uint256 internal constant UNWRAP = 0x16;
// minting/burning 6909s to close deltas
/// @dev this is not supported in the position manager or router
uint256 internal constant MINT_6909 = 0x17;
uint256 internal constant BURN_6909 = 0x18;
// bin-pool actions
// liquidity actions
uint256 internal constant BIN_ADD_LIQUIDITY = 0x19;
uint256 internal constant BIN_REMOVE_LIQUIDITY = 0x1a;
uint256 internal constant BIN_ADD_LIQUIDITY_FROM_DELTAS = 0x1b;
// swapping
uint256 internal constant BIN_SWAP_EXACT_IN_SINGLE = 0x1c;
uint256 internal constant BIN_SWAP_EXACT_IN = 0x1d;
uint256 internal constant BIN_SWAP_EXACT_OUT_SINGLE = 0x1e;
uint256 internal constant BIN_SWAP_EXACT_OUT = 0x1f;
// donate
uint256 internal constant BIN_DONATE = 0x20;
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {ERC721} from "solmate/src/tokens/ERC721.sol";
import {ERC721PermitHash} from "../libraries/ERC721PermitHash.sol";
import {SignatureVerification} from "permit2/src/libraries/SignatureVerification.sol";
import {EIP712} from "./EIP712.sol";
import {IERC721Permit} from "../interfaces/IERC721Permit.sol";
import {UnorderedNonce} from "./UnorderedNonce.sol";
/// @title ERC721 with permit
/// @notice Nonfungible tokens that support an approve via signature, i.e. permit
abstract contract ERC721Permit is ERC721, IERC721Permit, EIP712, UnorderedNonce {
using SignatureVerification for bytes;
/// @notice Computes the nameHash and versionHash
constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) EIP712(name_) {}
/// @notice Checks if the block's timestamp is before a signature's deadline
modifier checkSignatureDeadline(uint256 deadline) {
if (block.timestamp > deadline) revert SignatureDeadlineExpired();
_;
}
/// @inheritdoc IERC721Permit
function permit(address spender, uint256 tokenId, uint256 deadline, uint256 nonce, bytes calldata signature)
external
payable
checkSignatureDeadline(deadline)
{
// the .verify function checks the owner is non-0
address owner = ownerOf(tokenId);
bytes32 digest = ERC721PermitHash.hashPermit(spender, tokenId, nonce, deadline);
signature.verify(_hashTypedData(digest), owner);
_useUnorderedNonce(owner, nonce);
_approve(owner, spender, tokenId);
}
/// @inheritdoc IERC721Permit
function permitForAll(
address owner,
address operator,
bool approved,
uint256 deadline,
uint256 nonce,
bytes calldata signature
) external payable checkSignatureDeadline(deadline) {
bytes32 digest = ERC721PermitHash.hashPermitForAll(operator, approved, nonce, deadline);
signature.verify(_hashTypedData(digest), owner);
_useUnorderedNonce(owner, nonce);
_approveForAll(owner, operator, approved);
}
/// @notice Enable or disable approval for a third party ("operator") to manage
/// all of `msg.sender`'s assets
/// @dev Emits the ApprovalForAll event. The contract MUST allow
/// multiple operators per owner.
/// @dev Override Solmate's ERC721 setApprovalForAll so setApprovalForAll() and permit() share the _approveForAll method
/// @param operator Address to add to the set of authorized operators
/// @param approved True if the operator is approved, false to revoke approval
function setApprovalForAll(address operator, bool approved) public override {
_approveForAll(msg.sender, operator, approved);
}
function _approveForAll(address owner, address operator, bool approved) internal {
isApprovedForAll[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/// @notice Change or reaffirm the approved address for an NFT
/// @dev override Solmate's ERC721 approve so approve() and permit() share the _approve method
/// Passing a spender address of zero can be used to remove any outstanding approvals
/// Throws error unless `msg.sender` is the current NFT owner,
/// or an authorized operator of the current owner.
/// @param spender The new approved NFT controller
/// @param id The tokenId of the NFT to approve
function approve(address spender, uint256 id) public override {
address owner = _ownerOf[id];
if (msg.sender != owner && !isApprovedForAll[owner][msg.sender]) revert Unauthorized();
_approve(owner, spender, id);
}
function _approve(address owner, address spender, uint256 id) internal {
getApproved[id] = spender;
emit Approval(owner, spender, id);
}
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) {
return spender == ownerOf(tokenId) || getApproved[tokenId] == spender
|| isApprovedForAll[ownerOf(tokenId)][spender];
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {BalanceDelta} from "infinity-core/src/types/BalanceDelta.sol";
import {SafeCastTemp} from "./SafeCast.sol";
/// @title Slippage Check Library
/// @notice a library for checking if a delta exceeds a maximum ceiling or fails to meet a minimum floor
library SlippageCheck {
using SafeCastTemp for int128;
error MaximumAmountExceeded(uint128 maximumAmount, uint128 amountRequested);
error MinimumAmountInsufficient(uint128 minimumAmount, uint128 amountReceived);
/// @notice Revert if one or both deltas does not meet a minimum output
/// @param delta The principal amount of tokens to be removed, does not include any fees accrued
/// @param amount0Min The minimum amount of token0 to receive
/// @param amount1Min The minimum amount of token1 to receive
/// @dev This should be called when removing liquidity (burn or decrease)
function validateMinOut(BalanceDelta delta, uint128 amount0Min, uint128 amount1Min) internal pure {
// Called on burn or decrease, where we expect the returned delta to be positive.
// However, on pools where hooks can return deltas on modify liquidity, it is possible for a returned delta to be negative.
// Because we use SafeCast, this will revert in those cases when the delta is negative.
// This means this contract will NOT support pools where the hook returns a negative delta on burn/decrease.
if (delta.amount0().toUint128() < amount0Min) {
revert MinimumAmountInsufficient(amount0Min, delta.amount0().toUint128());
}
if (delta.amount1().toUint128() < amount1Min) {
revert MinimumAmountInsufficient(amount1Min, delta.amount1().toUint128());
}
}
/// @notice Revert if one or both deltas exceeds a maximum input
/// @param delta The principal amount of tokens to be added, does not include any fees accrued (which is possible on increase)
/// @param amount0Max The maximum amount of token0 to spend
/// @param amount1Max The maximum amount of token1 to spend
/// @dev This should be called when adding liquidity (mint or increase)
function validateMaxIn(BalanceDelta delta, uint128 amount0Max, uint128 amount1Max) internal pure {
// Called on mint or increase, where we expect the returned delta to be negative.
// However, on pools where hooks can return deltas on modify liquidity, it is possible for a returned delta to be positive (even after discounting fees accrued).
// Thus, we only cast the delta if it is guaranteed to be negative.
// And we do NOT revert in the positive delta case. Since a positive delta means the hook is crediting tokens to the user for minting/increasing liquidity, we do not check slippage.
// This means this contract will NOT support _positive_ slippage checks (minAmountOut checks) on pools where the hook returns a positive delta on mint/increase.
int256 amount0 = delta.amount0();
int256 amount1 = delta.amount1();
if (amount0 < 0 && amount0Max < uint128(uint256(-amount0))) {
revert MaximumAmountExceeded(amount0Max, uint128(uint256(-amount0)));
}
if (amount1 < 0 && amount1Max < uint128(uint256(-amount1))) {
revert MaximumAmountExceeded(amount1Max, uint128(uint256(-amount1)));
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {IMulticall} from "../interfaces/IMulticall.sol";
/// @title Multicall
/// @notice Enables calling multiple methods in a single call to the contract
abstract contract Multicall is IMulticall {
/// @inheritdoc IMulticall
function multicall(bytes[] calldata data) external payable override returns (bytes[] memory results) {
results = new bytes[](data.length);
for (uint256 i = 0; i < data.length; i++) {
(bool success, bytes memory result) = address(this).delegatecall(data[i]);
if (!success) {
// bubble up the revert reason
assembly ("memory-safe") {
revert(add(result, 0x20), mload(result))
}
}
results[i] = result;
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {ICLSubscriber} from "../interfaces/ICLSubscriber.sol";
import {ICLNotifier} from "../interfaces/ICLNotifier.sol";
import {CLPositionInfo} from "../libraries/CLPositionInfoLibrary.sol";
import {CustomRevert} from "infinity-core/src/libraries/CustomRevert.sol";
import {BalanceDelta} from "infinity-core/src/types/BalanceDelta.sol";
/// @notice Notifier is used to opt in to sending updates to external contracts about position modifications or transfers
abstract contract CLNotifier is ICLNotifier {
using CustomRevert for address;
ICLSubscriber private constant NO_SUBSCRIBER = ICLSubscriber(address(0));
/// @inheritdoc ICLNotifier
uint256 public immutable unsubscribeGasLimit;
/// @inheritdoc ICLNotifier
mapping(uint256 tokenId => ICLSubscriber subscriber) public subscriber;
constructor(uint256 _unsubscribeGasLimit) {
unsubscribeGasLimit = _unsubscribeGasLimit;
}
/// @notice Only allow callers that are approved as spenders or operators of the tokenId
/// @dev to be implemented by the parent contract (CLPositionManager)
/// @param caller the address of the caller
/// @param tokenId the tokenId of the position
modifier onlyIfApproved(address caller, uint256 tokenId) virtual;
/// @notice Enforces that the Vault is unlocked.
modifier onlyIfVaultUnlocked() virtual;
function _setUnsubscribed(uint256 tokenId) internal virtual;
function _setSubscribed(uint256 tokenId) internal virtual;
/// @inheritdoc ICLNotifier
function subscribe(uint256 tokenId, address newSubscriber, bytes calldata data)
external
payable
onlyIfVaultUnlocked
onlyIfApproved(msg.sender, tokenId)
{
ICLSubscriber _subscriber = subscriber[tokenId];
if (_subscriber != NO_SUBSCRIBER) revert AlreadySubscribed(tokenId, address(_subscriber));
_setSubscribed(tokenId);
subscriber[tokenId] = ICLSubscriber(newSubscriber);
bool success = _call(newSubscriber, abi.encodeCall(ICLSubscriber.notifySubscribe, (tokenId, data)));
if (!success) {
newSubscriber.bubbleUpAndRevertWith(ICLSubscriber.notifySubscribe.selector, SubscriptionReverted.selector);
}
emit Subscription(tokenId, newSubscriber);
}
/// @inheritdoc ICLNotifier
function unsubscribe(uint256 tokenId) external payable onlyIfVaultUnlocked onlyIfApproved(msg.sender, tokenId) {
_unsubscribe(tokenId);
}
function _unsubscribe(uint256 tokenId) internal {
ICLSubscriber _subscriber = subscriber[tokenId];
if (_subscriber == NO_SUBSCRIBER) revert NotSubscribed();
_setUnsubscribed(tokenId);
delete subscriber[tokenId];
if (address(_subscriber).code.length > 0) {
// require that the remaining gas is sufficient to notify the subscriber
// otherwise, users can select a gas limit where .notifyUnsubscribe hits OutOfGas yet the
// transaction/unsubscription can still succeed
if (gasleft() < unsubscribeGasLimit) revert GasLimitTooLow();
try _subscriber.notifyUnsubscribe{gas: unsubscribeGasLimit}(tokenId) {} catch {}
}
emit Unsubscription(tokenId, address(_subscriber));
}
/// @dev note this function also deletes the subscriber address from the mapping
function _removeSubscriberAndNotifyBurn(
uint256 tokenId,
address owner,
CLPositionInfo info,
uint256 liquidity,
BalanceDelta feesAccrued
) internal {
address _subscriber = address(subscriber[tokenId]);
// remove the subscriber
delete subscriber[tokenId];
bool success =
_call(_subscriber, abi.encodeCall(ICLSubscriber.notifyBurn, (tokenId, owner, info, liquidity, feesAccrued)));
if (!success) {
_subscriber.bubbleUpAndRevertWith(ICLSubscriber.notifyBurn.selector, BurnNotificationReverted.selector);
}
}
function _notifyModifyLiquidity(uint256 tokenId, int256 liquidityChange, BalanceDelta feesAccrued) internal {
address _subscriber = address(subscriber[tokenId]);
bool success = _call(
_subscriber, abi.encodeCall(ICLSubscriber.notifyModifyLiquidity, (tokenId, liquidityChange, feesAccrued))
);
if (!success) {
_subscriber.bubbleUpAndRevertWith(
ICLSubscriber.notifyModifyLiquidity.selector, ModifyLiquidityNotificationReverted.selector
);
}
}
function _call(address target, bytes memory encodedCall) internal returns (bool success) {
if (target.code.length == 0) revert NoCodeSubscriber();
assembly ("memory-safe") {
success := call(gas(), target, 0, add(encodedCall, 0x20), mload(encodedCall), 0, 0)
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.24;
import {PoolKey} from "infinity-core/src/types/PoolKey.sol";
import {PoolId, PoolIdLibrary} from "infinity-core/src/types/PoolId.sol";
/**
* @dev PositionInfo is a packed version of solidity structure.
* Using the packaged version saves gas and memory by not storing the structure fields in memory slots.
*
* Layout:
* 200 bits poolId | 24 bits tickUpper | 24 bits tickLower | 8 bits hasSubscriber
*
* Fields in the direction from the least significant bit:
*
* A flag to know if the tokenId is subscribed to an address
* uint8 hasSubscriber;
*
* The tickUpper of the position
* int24 tickUpper;
*
* The tickLower of the position
* int24 tickLower;
*
* The truncated poolId. Truncates a bytes32 value so the most signifcant (highest) 200 bits are used.
* bytes25 poolId;
*
* Note: If more bits are needed, hasSubscriber can be a single bit.
*
*/
type CLPositionInfo is uint256;
library CLPositionInfoLibrary {
using PoolIdLibrary for PoolKey;
CLPositionInfo internal constant EMPTY_POSITION_INFO = CLPositionInfo.wrap(0);
uint256 internal constant MASK_UPPER_200_BITS = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000;
uint256 internal constant MASK_8_BITS = 0xFF;
uint24 internal constant MASK_24_BITS = 0xFFFFFF;
uint256 internal constant SET_UNSUBSCRIBE = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00;
uint256 internal constant SET_SUBSCRIBE = 0x01;
uint8 internal constant TICK_LOWER_OFFSET = 8;
uint8 internal constant TICK_UPPER_OFFSET = 32;
/// @dev This poolId is NOT compatible with the poolId used in infinity core. It is truncated to 25 bytes, and just used to lookup PoolKey in the poolKeys mapping.
function poolId(CLPositionInfo info) internal pure returns (bytes25 _poolId) {
assembly ("memory-safe") {
_poolId := and(MASK_UPPER_200_BITS, info)
}
}
function tickLower(CLPositionInfo info) internal pure returns (int24 _tickLower) {
assembly ("memory-safe") {
_tickLower := signextend(2, shr(TICK_LOWER_OFFSET, info))
}
}
function tickUpper(CLPositionInfo info) internal pure returns (int24 _tickUpper) {
assembly ("memory-safe") {
_tickUpper := signextend(2, shr(TICK_UPPER_OFFSET, info))
}
}
function hasSubscriber(CLPositionInfo info) internal pure returns (bool _hasSubscriber) {
assembly ("memory-safe") {
_hasSubscriber := and(MASK_8_BITS, info)
}
}
/// @dev this does not actually set any storage
function setSubscribe(CLPositionInfo info) internal pure returns (CLPositionInfo _info) {
assembly ("memory-safe") {
_info := or(info, SET_SUBSCRIBE)
}
}
/// @dev this does not actually set any storage
function setUnsubscribe(CLPositionInfo info) internal pure returns (CLPositionInfo _info) {
assembly ("memory-safe") {
_info := and(info, SET_UNSUBSCRIBE)
}
}
/// @notice Creates the default PositionInfo struct
/// @dev Called when minting a new position
/// @param _poolKey the pool key of the position
/// @param _tickLower the lower tick of the position
/// @param _tickUpper the upper tick of the position
/// @return info packed position info, with the truncated poolId and the hasSubscriber flag set to false
function initialize(PoolKey memory _poolKey, int24 _tickLower, int24 _tickUpper)
internal
pure
returns (CLPositionInfo info)
{
bytes25 _poolId = bytes25(PoolId.unwrap(_poolKey.toId()));
assembly {
info :=
or(
or(and(MASK_UPPER_200_BITS, _poolId), shl(TICK_UPPER_OFFSET, and(MASK_24_BITS, _tickUpper))),
shl(TICK_LOWER_OFFSET, and(MASK_24_BITS, _tickLower))
)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {BalanceDelta} from "infinity-core/src/types/BalanceDelta.sol";
import {CLPositionInfo} from "../libraries/CLPositionInfoLibrary.sol";
/// @notice Interface that a Subscriber contract should implement to receive updates from infinity cl pool position manager
interface ICLSubscriber {
/// @notice Called when a position subscribes to this subscriber contract
/// @param tokenId the token ID of the position
/// @param data additional data passed in by the caller
function notifySubscribe(uint256 tokenId, bytes memory data) external;
/// @notice Called when a position unsubscribes from the subscriber
/// @dev This call's gas is capped at `unsubscribeGasLimit` (set at deployment)
/// @dev Because of EIP-150, solidity may only allocate 63/64 of gasleft()
/// @param tokenId the token ID of the position
function notifyUnsubscribe(uint256 tokenId) external;
/// @notice Called when a position is burned
/// @param tokenId the token ID of the position
/// @param owner the current owner of the tokenId
/// @param info information about the position
/// @param liquidity the amount of liquidity decreased in the position, may be 0
/// @param feesAccrued the fees accrued by the position if liquidity was decreased
function notifyBurn(
uint256 tokenId,
address owner,
CLPositionInfo info,
uint256 liquidity,
BalanceDelta feesAccrued
) external;
/// @notice Called when a position modifies its liquidity or collects fees
/// @param tokenId the token ID of the position
/// @param liquidityChange the change in liquidity on the underlying position
/// @param feesAccrued the fees to be collected from the position as a result of the modifyLiquidity call
/// @dev feesAccrued can be artificially inflated by a malicious user
/// Pools with a single liquidity position can inflate feeGrowthGlobal (and consequently feesAccrued) by donating to themselves;
/// automatically donating and collecting fees within the same unlockCallback may further inflate feeGrowthGlobal/feesAccrued
function notifyModifyLiquidity(uint256 tokenId, int256 liquidityChange, BalanceDelta feesAccrued) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {ICLPositionManager} from "./ICLPositionManager.sol";
/// @title Describes cl pool position NFT tokens via URI
interface ICLPositionDescriptor {
/// @notice Produces the URI describing a particular token ID
/// @dev Note this URI may be a data: URI with the JSON contents directly inlined
/// @param positionManager The position manager for which to describe the token
/// @param tokenId The ID of the token for which to produce a description, which may not be valid
/// @return The URI of the ERC721-compliant metadata
function tokenURI(ICLPositionManager positionManager, uint256 tokenId) external view returns (string memory);
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {IWETH9} from "../interfaces/external/IWETH9.sol";
import {ActionConstants} from "../libraries/ActionConstants.sol";
import {ImmutableState} from "./ImmutableState.sol";
/// @title Native Wrapper
/// @notice Used for wrapping and unwrapping native
abstract contract NativeWrapper is ImmutableState {
/// @notice The address for WETH9
IWETH9 public immutable WETH9;
/// @notice Thrown when an unexpected address sends ETH to this contract
error InvalidEthSender();
constructor(IWETH9 _weth9) {
WETH9 = _weth9;
}
/// @dev The amount should already be <= the current balance in this contract.
function _wrap(uint256 amount) internal {
if (amount > 0) WETH9.deposit{value: amount}();
}
/// @dev The amount should already be <= the current balance in this contract.
function _unwrap(uint256 amount) internal {
if (amount > 0) WETH9.withdraw(amount);
}
receive() external payable {
if (msg.sender != address(WETH9) && msg.sender != address(vault)) revert InvalidEthSender();
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title IWETH9
/// @notice Interface for WETH9
interface IWETH9 is IERC20 {
/// @notice Deposit ether to get wrapped ether
function deposit() external payable;
/// @notice Withdraw wrapped ether to get ether
function withdraw(uint256) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {FullMath} from "infinity-core/src/pool-cl/libraries/FullMath.sol";
import {FixedPoint96} from "infinity-core/src/pool-cl/libraries/FixedPoint96.sol";
import {SafeCastTemp as SafeCast} from "../../libraries/SafeCast.sol";
/// @title Liquidity amount functions
/// @notice Provides functions for computing liquidity amounts from token amounts and prices
library LiquidityAmounts {
/// @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 SafeCast.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 SafeCast.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: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
/// @notice Thrown when the tick passed to #getSqrtRatioAtTick is not between MIN_TICK and MAX_TICK
error InvalidTick(int24 tick);
/// @notice Thrown when the ratio passed to #getTickAtSqrtRatio does not correspond to a price between MIN_TICK and MAX_TICK
error InvalidSqrtRatio(uint160 sqrtPriceX96);
/// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
/// @dev If ever MIN_TICK and MAX_TICK are not centered around 0, the absTick logic in getSqrtRatioAtTick cannot be used
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
/// @dev If ever MIN_TICK and MAX_TICK are not centered around 0, the absTick logic in getSqrtRatioAtTick cannot be used
int24 internal constant MAX_TICK = 887272;
/// @dev The minimum tick spacing value drawn from the range of type int16 that is greater than 0, i.e. min from the range [1, 32767]
int24 internal constant MIN_TICK_SPACING = 1;
/// @dev The maximum tick spacing value drawn from the range of type int16, i.e. max from the range [1, 32767]
int24 internal constant MAX_TICK_SPACING = type(int16).max;
/// @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;
/// @dev A threshold used for optimized bounds check, equals `MAX_SQRT_RATIO - MIN_SQRT_RATIO - 1`
uint160 internal constant MAX_SQRT_RATIO_MINUS_MIN_SQRT_RATIO_MINUS_ONE =
1461446703485210103287273052203988822378723970342 - 4295128739 - 1;
/// @notice Given a tickSpacing, compute the maximum usable tick
function maxUsableTick(int24 tickSpacing) internal pure returns (int24) {
unchecked {
return (MAX_TICK / tickSpacing) * tickSpacing;
}
}
/// @notice Given a tickSpacing, compute the minimum usable tick
function minUsableTick(int24 tickSpacing) internal pure returns (int24) {
unchecked {
return (MIN_TICK / tickSpacing) * tickSpacing;
}
}
/// @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 (currency1/currency0)
/// at the given tick
function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
unchecked {
// Equivalent: uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
uint256 absTick;
assembly ("memory-safe") {
tick := signextend(2, tick)
// mask = 0 if tick >= 0 else -1 (all 1s)
let mask := sar(255, tick)
absTick := xor(mask, add(mask, tick))
}
if (absTick > uint256(int256(MAX_TICK))) revert InvalidTick(tick);
// Equivalent to:
// ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;
// or price = int(2**128 / sqrt(1.0001)) if (absTick & 0x1) else 1 << 128
uint256 ratio;
assembly ("memory-safe") {
ratio := xor(shl(128, 1), mul(xor(shl(128, 1), 0xfffcb933bd6fad37aa2d162d1a594001), and(absTick, 0x1)))
}
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;
assembly ("memory-safe") {
// Equivalent: if (tick > 0) ratio = type(uint256).max / ratio;
if sgt(tick, 0) { ratio := div(not(0), 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 getTickAtSqrtPrice of the output price is always consistent
// `sub(shl(32, 1), 1)` is `type(uint32).max`
// `ratio + type(uint32).max` will not overflow because `ratio` fits in 192 bits
sqrtPriceX96 := shr(32, add(ratio, sub(shl(32, 1), 1)))
}
}
}
/// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
/// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
/// ever return.
/// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
/// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
unchecked {
// second inequality must be >= because the price can never reach the price at the max tick
// if sqrtPriceX96 < MIN_SQRT_PRICE, the `sub` underflows and `gt` is true
// if sqrtPriceX96 >= MAX_SQRT_PRICE, sqrtPriceX96 - MIN_SQRT_PRICE > MAX_SQRT_PRICE - MIN_SQRT_PRICE - 1
if ((sqrtPriceX96 - MIN_SQRT_RATIO) > MAX_SQRT_RATIO_MINUS_MIN_SQRT_RATIO_MINUS_ONE) {
revert InvalidSqrtRatio(sqrtPriceX96);
}
uint256 ratio = uint256(sqrtPriceX96) << 32;
uint256 r = ratio;
uint256 msb = 0;
assembly ("memory-safe") {
let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly ("memory-safe") {
let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly ("memory-safe") {
let f := shl(5, gt(r, 0xFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly ("memory-safe") {
let f := shl(4, gt(r, 0xFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly ("memory-safe") {
let f := shl(3, gt(r, 0xFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly ("memory-safe") {
let f := shl(2, gt(r, 0xF))
msb := or(msb, f)
r := shr(f, r)
}
assembly ("memory-safe") {
let f := shl(1, gt(r, 0x3))
msb := or(msb, f)
r := shr(f, r)
}
assembly ("memory-safe") {
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 ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(63, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(62, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(61, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(60, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(59, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(58, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(57, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(56, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(55, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(54, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(53, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(52, f))
r := shr(f, r)
}
assembly ("memory-safe") {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(51, f))
r := shr(f, r)
}
assembly ("memory-safe") {
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.0;
import {PoolId} from "../types/PoolId.sol";
import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {IPoolManager} from "./IPoolManager.sol";
import {Currency} from "../types/Currency.sol";
interface IVaultToken {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event OperatorSet(address indexed owner, address indexed operator, bool approved);
event Approval(address indexed owner, address indexed spender, Currency indexed currency, uint256 amount);
event Transfer(address caller, address indexed from, address indexed to, Currency indexed currency, uint256 amount);
/// @notice get the amount of owner's surplus token in vault
/// @param owner The address you want to query the balance of
/// @param currency The currency you want to query the balance of
/// @return balance The balance of the specified address
function balanceOf(address owner, Currency currency) external view returns (uint256 balance);
/// @notice get the amount that owner has authorized for spender to use
/// @param owner The address of the owner
/// @param spender The address who is allowed to spend the owner's token
/// @param currency The currency the spender is allowed to spend
/// @return amount The amount of token the spender is allowed to spend
function allowance(address owner, address spender, Currency currency) external view returns (uint256 amount);
/// @notice approve spender for using user's token
/// @param spender The address msg.sender is approving to spend the his token
/// @param currency The currency the spender is allowed to spend
/// @param amount The amount of token the spender is allowed to spend
/// @return bool Whether the approval was successful or not
function approve(address spender, Currency currency, uint256 amount) external returns (bool);
/// @notice transfer msg.sender's token to someone else
/// @param to The address to transfer the token to
/// @param currency The currency to transfer
/// @param amount The amount of token to transfer
/// @return bool Whether the transfer was successful or not
function transfer(address to, Currency currency, uint256 amount) external returns (bool);
/// @notice transfer from address's token on behalf of him
/// @param from The address to transfer the token from
/// @param to The address to transfer the token to
/// @param currency The currency to transfer
/// @param amount The amount of token to transfer
/// @return bool Whether the transfer was successful or not
function transferFrom(address from, address to, Currency currency, uint256 amount) external returns (bool);
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Minimal ERC20 interface for PancakeSwap
/// @notice Contains a subset of the full ERC20 interface that is used in PancakeSwap V3
interface IERC20Minimal {
/// @notice Returns the balance of a token
/// @param account The account for which to look up the number of tokens it has, i.e. its balance
/// @return The number of tokens held by the account
function balanceOf(address account) external view returns (uint256);
/// @notice Transfers the amount of token from the `msg.sender` to the recipient
/// @param recipient The account that will receive the amount transferred
/// @param amount The number of tokens to send from the sender to the recipient
/// @return Returns true for a successful transfer, false for an unsuccessful transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/// @notice Returns the current allowance given to a spender by an owner
/// @param owner The account of the token owner
/// @param spender The account of the token spender
/// @return The current allowance granted by `owner` to `spender`
function allowance(address owner, address spender) external view returns (uint256);
/// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount`
/// @param spender The account which will be allowed to spend a given amount of the owners tokens
/// @param amount The amount of tokens allowed to be used by `spender`
/// @return Returns true for a successful approval, false for unsuccessful
function approve(address spender, uint256 amount) external returns (bool);
/// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender`
/// @param sender The account from which the transfer will be initiated
/// @param recipient The recipient of the transfer
/// @param amount The amount of the transfer
/// @return Returns true for a successful transfer, false for unsuccessful
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`.
/// @param from The account from which the tokens were sent, i.e. the balance decreased
/// @param to The account to which the tokens were sent, i.e. the balance increased
/// @param value The amount of tokens that were transferred
event Transfer(address indexed from, address indexed to, uint256 value);
/// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes.
/// @param owner The account that approved spending of its tokens
/// @param spender The account for which the spending allowance was modified
/// @param value The new allowance from the owner to the spender
event Approval(address indexed owner, address indexed spender, uint256 value);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Library for reverting with custom errors efficiently
/// @notice Contains functions for reverting with custom errors with different argument types efficiently
/// @dev The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately
library CustomRevert {
/// @dev ERC-7751 error for wrapping bubbled up reverts
error WrappedError(address target, bytes4 selector, bytes reason, bytes details);
/// @notice bubble up the revert message returned by a call and revert with a wrapped ERC-7751 error
/// @dev this method can be vulnerable to revert data bombs
function bubbleUpAndRevertWith(
address revertingContract,
bytes4 revertingFunctionSelector,
bytes4 additionalContext
) internal pure {
bytes4 wrappedErrorSelector = WrappedError.selector;
assembly ("memory-safe") {
// Ensure the size of the revert data is a multiple of 32 bytes
let encodedDataSize := mul(div(add(returndatasize(), 31), 32), 32)
let fmp := mload(0x40)
// Encode wrapped error selector, address, function selector, offset, additional context, size, revert reason
mstore(fmp, wrappedErrorSelector)
mstore(add(fmp, 0x04), and(revertingContract, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(
add(fmp, 0x24),
and(revertingFunctionSelector, 0xffffffff00000000000000000000000000000000000000000000000000000000)
)
// offset revert reason
mstore(add(fmp, 0x44), 0x80)
// offset additional context
mstore(add(fmp, 0x64), add(0xa0, encodedDataSize))
// size revert reason
mstore(add(fmp, 0x84), returndatasize())
// revert reason
returndatacopy(add(fmp, 0xa4), 0, returndatasize())
// size additional context
mstore(add(fmp, add(0xa4, encodedDataSize)), 0x04)
// additional context
mstore(
add(fmp, add(0xc4, encodedDataSize)),
and(additionalContext, 0xffffffff00000000000000000000000000000000000000000000000000000000)
)
revert(fmp, add(0xe4, encodedDataSize))
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {CLPosition} from "./CLPosition.sol";
import {TickMath} from "./TickMath.sol";
import {BalanceDelta, BalanceDeltaLibrary, toBalanceDelta} from "../../types/BalanceDelta.sol";
import {CLSlot0} from "../types/CLSlot0.sol";
import {Tick} from "./Tick.sol";
import {TickBitmap} from "./TickBitmap.sol";
import {SqrtPriceMath} from "./SqrtPriceMath.sol";
import {SafeCast} from "../../libraries/SafeCast.sol";
import {FixedPoint128} from "./FixedPoint128.sol";
import {UnsafeMath} from "../../libraries/math/UnsafeMath.sol";
import {SwapMath} from "./SwapMath.sol";
import {LiquidityMath} from "./LiquidityMath.sol";
import {ProtocolFeeLibrary} from "../../libraries/ProtocolFeeLibrary.sol";
import {LPFeeLibrary} from "../../libraries/LPFeeLibrary.sol";
/// @notice a library with all actions that can be performed on cl pool
library CLPool {
using SafeCast for int256;
using SafeCast for uint256;
using Tick for mapping(int24 => Tick.Info);
using TickBitmap for mapping(int16 => uint256);
using CLPosition for mapping(bytes32 => CLPosition.Info);
using CLPosition for CLPosition.Info;
using LiquidityMath for uint128;
using CLPool for State;
using ProtocolFeeLibrary for uint24;
using ProtocolFeeLibrary for uint16;
using LPFeeLibrary for uint24;
/// @notice Thrown when trying to initialize an already initialized pool
error PoolAlreadyInitialized();
/// @notice Thrown when trying to interact with a non-initialized pool
error PoolNotInitialized();
/// @notice Thrown when trying to swap with max lp fee and specifying an output amount
error InvalidFeeForExactOut();
/// @notice Thrown when sqrtPriceLimitX96 is out of range
/// @param sqrtPriceCurrentX96 current price in the pool
/// @param sqrtPriceLimitX96 The price limit specified by user
error InvalidSqrtPriceLimit(uint160 sqrtPriceCurrentX96, uint160 sqrtPriceLimitX96);
/// @notice Thrown by donate if there is currently 0 liquidity, since the fees will not go to any liquidity providers
error NoLiquidityToReceiveFees();
/// @notice The state of a pool
/// @dev feeGrowthGlobal can be artificially inflated
/// For pools with a single liquidity position, actors can donate to themselves to freely inflate feeGrowthGlobal
/// atomically donating and collecting fees in the same lockAcquired callback may make the inflated value more extreme
struct State {
CLSlot0 slot0;
/// @dev accumulated lp fees
uint256 feeGrowthGlobal0X128;
uint256 feeGrowthGlobal1X128;
/// @dev current active liquidity
uint128 liquidity;
mapping(int24 tick => Tick.Info info) ticks;
mapping(int16 pos => uint256 bitmap) tickBitmap;
mapping(bytes32 positionHash => CLPosition.Info info) positions;
}
function initialize(State storage self, uint160 sqrtPriceX96, uint24 protocolFee, uint24 lpFee)
internal
returns (int24 tick)
{
if (self.slot0.sqrtPriceX96() != 0) revert PoolAlreadyInitialized();
tick = TickMath.getTickAtSqrtRatio(sqrtPriceX96);
self.slot0 = CLSlot0.wrap(bytes32(0)).setSqrtPriceX96(sqrtPriceX96).setTick(tick).setProtocolFee(protocolFee)
.setLpFee(lpFee);
}
struct ModifyLiquidityParams {
// the address that owns the position
address owner;
// the lower and upper tick of the position
int24 tickLower;
int24 tickUpper;
// any change in liquidity
int128 liquidityDelta;
// the spacing between ticks
int24 tickSpacing;
// used to distinguish positions of the same owner, at the same tick range
bytes32 salt;
}
/// @dev Effect changes to the liquidity of a position in a pool
/// @param params the position details and the change to the position's liquidity to effect
/// @return delta the deltas from liquidity changes
/// @return feeDelta the delta of the fees generated in the liquidity range
function modifyLiquidity(State storage self, ModifyLiquidityParams memory params)
internal
returns (BalanceDelta delta, BalanceDelta feeDelta)
{
int24 tickLower = params.tickLower;
int24 tickUpper = params.tickUpper;
Tick.checkTicks(tickLower, tickUpper);
int24 tick = self.slot0.tick();
(uint256 feesOwed0, uint256 feesOwed1) = _updatePosition(self, params, tick);
///@dev calculate the tokens delta needed
int128 liquidityDelta = params.liquidityDelta;
if (liquidityDelta != 0) {
uint160 sqrtPriceX96 = self.slot0.sqrtPriceX96();
int128 amount0;
int128 amount1;
if (tick < tickLower) {
// current tick is below the passed range; liquidity can only become in range by crossing from left to
// right, when we'll need _more_ currency0 (it's becoming more valuable) so user must provide it
amount0 = SqrtPriceMath.getAmount0Delta(
TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidityDelta
).toInt128();
} else if (tick < tickUpper) {
amount0 = SqrtPriceMath.getAmount0Delta(
sqrtPriceX96, TickMath.getSqrtRatioAtTick(tickUpper), liquidityDelta
).toInt128();
amount1 = SqrtPriceMath.getAmount1Delta(
TickMath.getSqrtRatioAtTick(tickLower), sqrtPriceX96, liquidityDelta
).toInt128();
self.liquidity = LiquidityMath.addDelta(self.liquidity, liquidityDelta);
} else {
// current tick is above the passed range; liquidity can only become in range by crossing from right to
// left, when we'll need _more_ currency1 (it's becoming more valuable) so user must provide it
amount1 = SqrtPriceMath.getAmount1Delta(
TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidityDelta
).toInt128();
}
// Amount required for updating liquidity
delta = toBalanceDelta(amount0, amount1);
}
// Fees earned from LPing are removed from the pool balance and returned separately
feeDelta = toBalanceDelta(feesOwed0.toInt128(), feesOwed1.toInt128());
}
// the top level state of the swap, the results of which are recorded in storage at the end
struct SwapState {
// the amount remaining to be swapped in/out of the input/output asset
int256 amountSpecifiedRemaining;
// the amount already swapped out/in of the output/input asset
int256 amountCalculated;
// current sqrt(price)
uint160 sqrtPriceX96;
// the tick associated with the current price
int24 tick;
// the swapFee (the total percentage charged within a swap, including the protocol fee and the LP fee)
uint24 swapFee;
// the single direction protocol fee for the swap
uint16 protocolFee;
// the global fee growth of the input token
uint256 feeGrowthGlobalX128;
// amount of input token paid as protocol fee
uint256 feeAmountToProtocol;
// the current liquidity in range
uint128 liquidity;
}
struct StepComputations {
// the price at the beginning of the step
uint160 sqrtPriceStartX96;
// the next tick to swap to from the current tick in the swap direction
int24 tickNext;
// whether tickNext is initialized or not
bool initialized;
// sqrt(price) for the next tick (1/0)
uint160 sqrtPriceNextX96;
// how much is being swapped in in this step
uint256 amountIn;
// how much is being swapped out
uint256 amountOut;
// how much fee is being paid in
uint256 feeAmount;
}
struct SwapParams {
int24 tickSpacing;
bool zeroForOne;
int256 amountSpecified;
uint160 sqrtPriceLimitX96;
uint24 lpFeeOverride;
}
function swap(State storage self, SwapParams memory params)
internal
returns (BalanceDelta balanceDelta, SwapState memory state)
{
// cache variables for gas optimization
CLSlot0 slot0Start = self.slot0;
bool zeroForOne = params.zeroForOne;
uint160 sqrtPriceLimitX96 = params.sqrtPriceLimitX96;
// check price limit
// Swaps can never occur at MIN_TICK, only at MIN_TICK + 1, except at initialization of a pool
// Under certain circumstances outlined below, the tick will preemptively reach MIN_TICK without swapping there
if (
zeroForOne
? (sqrtPriceLimitX96 >= slot0Start.sqrtPriceX96() || sqrtPriceLimitX96 <= TickMath.MIN_SQRT_RATIO)
: (sqrtPriceLimitX96 <= slot0Start.sqrtPriceX96() || sqrtPriceLimitX96 >= TickMath.MAX_SQRT_RATIO)
) {
revert InvalidSqrtPriceLimit(slot0Start.sqrtPriceX96(), sqrtPriceLimitX96);
}
// cache variables for gas optimization
// liquidity at the beginning of the swap
uint128 liquidityStart = self.liquidity;
bool exactInput = params.amountSpecified < 0;
// init swap state
{
uint16 protocolFee =
zeroForOne ? slot0Start.protocolFee().getZeroForOneFee() : slot0Start.protocolFee().getOneForZeroFee();
uint24 lpFee = params.lpFeeOverride.isOverride()
? params.lpFeeOverride.removeOverrideAndValidate(LPFeeLibrary.ONE_HUNDRED_PERCENT_FEE)
: slot0Start.lpFee();
state = SwapState({
amountSpecifiedRemaining: params.amountSpecified,
amountCalculated: 0,
sqrtPriceX96: slot0Start.sqrtPriceX96(),
tick: slot0Start.tick(),
swapFee: protocolFee == 0 ? lpFee : protocolFee.calculateSwapFee(lpFee),
protocolFee: protocolFee,
feeGrowthGlobalX128: zeroForOne ? self.feeGrowthGlobal0X128 : self.feeGrowthGlobal1X128,
feeAmountToProtocol: 0,
liquidity: liquidityStart
});
}
/// @dev a swap fee totaling 100% makes exact output swaps impossible since the input is entirely consumed by the fee
if (state.swapFee >= LPFeeLibrary.ONE_HUNDRED_PERCENT_FEE) {
if (!exactInput) {
revert InvalidFeeForExactOut();
}
}
/// @notice early return if hook has updated amountSpecified to 0
if (params.amountSpecified == 0) return (BalanceDeltaLibrary.ZERO_DELTA, state);
StepComputations memory step;
// continue swapping as long as we haven't used the entire input/output and haven't reached the price limit
while (state.amountSpecifiedRemaining != 0 && state.sqrtPriceX96 != sqrtPriceLimitX96) {
step.sqrtPriceStartX96 = state.sqrtPriceX96;
(step.tickNext, step.initialized) =
self.tickBitmap.nextInitializedTickWithinOneWord(state.tick, params.tickSpacing, zeroForOne);
// ensure that we do not overshoot the min/max tick, as the tick bitmap is not aware of these bounds
if (step.tickNext < TickMath.MIN_TICK) {
step.tickNext = TickMath.MIN_TICK;
} else if (step.tickNext > TickMath.MAX_TICK) {
step.tickNext = TickMath.MAX_TICK;
}
// get the price for the next tick
step.sqrtPriceNextX96 = TickMath.getSqrtRatioAtTick(step.tickNext);
// compute values to swap to the target tick, price limit, or point where input/output amount is exhausted
(state.sqrtPriceX96, step.amountIn, step.amountOut, step.feeAmount) = SwapMath.computeSwapStep(
state.sqrtPriceX96,
SwapMath.getSqrtPriceTarget(zeroForOne, step.sqrtPriceNextX96, sqrtPriceLimitX96),
state.liquidity,
state.amountSpecifiedRemaining,
state.swapFee
);
if (exactInput) {
/// @dev SwapMath will always ensure that amountSpecified > amountIn + feeAmount
unchecked {
state.amountSpecifiedRemaining += (step.amountIn + step.feeAmount).toInt256();
}
/// @dev amountCalculated is the amount of output token, hence neg in this case
state.amountCalculated += step.amountOut.toInt256();
} else {
unchecked {
state.amountSpecifiedRemaining -= step.amountOut.toInt256();
}
state.amountCalculated -= (step.amountIn + step.feeAmount).toInt256();
}
/// @dev if the protocol fee is on, calculate how much is owed, decrement feeAmount, and increment protocolFee
if (state.protocolFee > 0) {
unchecked {
// cannot overflow due to limits on the size of protocolFee and params.amountSpecified
// this rounds down to favor LPs over the protocol
uint256 delta = (state.swapFee == state.protocolFee)
? step.feeAmount // lp fee is 0, so the entire fee is owed to the protocol instead
: (step.amountIn + step.feeAmount) * state.protocolFee / ProtocolFeeLibrary.PIPS_DENOMINATOR;
// subtract it from the total fee then left over is the LP fee
step.feeAmount -= delta;
state.feeAmountToProtocol += delta;
}
}
// update global fee tracker
if (state.liquidity > 0) {
unchecked {
state.feeGrowthGlobalX128 +=
UnsafeMath.simpleMulDiv(step.feeAmount, FixedPoint128.Q128, state.liquidity);
}
}
// Shift tick if we reached the next price, and preemptively decrement for zeroForOne swaps to tickNext - 1.
// If the swap doesnt continue (if amountRemaining == 0 or sqrtPriceLimit is met), slot0.tick will be 1 less
// than getTickAtSqrtPrice(slot0.sqrtPrice). This doesn't affect swaps, but donation calls should verify both
// price and tick to reward the correct LPs.
if (state.sqrtPriceX96 == step.sqrtPriceNextX96) {
// if the tick is initialized, run the tick transition
if (step.initialized) {
int128 liquidityNet = self.ticks.cross(
step.tickNext,
(zeroForOne ? state.feeGrowthGlobalX128 : self.feeGrowthGlobal0X128),
(zeroForOne ? self.feeGrowthGlobal1X128 : state.feeGrowthGlobalX128)
);
// if we're moving leftward, we interpret liquidityNet as the opposite sign
// safe because liquidityNet cannot be type(int128).min
unchecked {
if (zeroForOne) liquidityNet = -liquidityNet;
}
state.liquidity = state.liquidity.addDelta(liquidityNet);
}
unchecked {
state.tick = zeroForOne ? step.tickNext - 1 : step.tickNext;
}
} else if (state.sqrtPriceX96 != step.sqrtPriceStartX96) {
// recompute unless we're on a lower tick boundary (i.e. already transitioned ticks), and haven't moved
state.tick = TickMath.getTickAtSqrtRatio(state.sqrtPriceX96);
}
}
// update tick and price if changed
if (state.tick != slot0Start.tick()) {
self.slot0 = self.slot0.setSqrtPriceX96(state.sqrtPriceX96).setTick(state.tick);
} else {
// otherwise just update the price
self.slot0 = self.slot0.setSqrtPriceX96(state.sqrtPriceX96);
}
// update liquidity if it changed
if (liquidityStart != state.liquidity) self.liquidity = state.liquidity;
// update fee growth global
if (zeroForOne) {
self.feeGrowthGlobal0X128 = state.feeGrowthGlobalX128;
} else {
self.feeGrowthGlobal1X128 = state.feeGrowthGlobalX128;
}
unchecked {
(int128 amount0, int128 amount1) = zeroForOne == exactInput
? ((params.amountSpecified - state.amountSpecifiedRemaining).toInt128(), state.amountCalculated.toInt128())
: (
(state.amountCalculated.toInt128()),
(params.amountSpecified - state.amountSpecifiedRemaining).toInt128()
);
balanceDelta = toBalanceDelta(amount0, amount1);
}
}
struct UpdatePositionCache {
bool flippedLower;
bool flippedUpper;
uint256 feeGrowthInside0X128;
uint256 feeGrowthInside1X128;
uint256 feesOwed0;
uint256 feesOwed1;
uint128 maxLiquidityPerTick;
}
function _updatePosition(State storage self, ModifyLiquidityParams memory params, int24 tick)
internal
returns (uint256, uint256)
{
//@dev avoid stack too deep
UpdatePositionCache memory cache;
{
uint256 _feeGrowthGlobal0X128 = self.feeGrowthGlobal0X128; // SLOAD for gas optimization
uint256 _feeGrowthGlobal1X128 = self.feeGrowthGlobal1X128; // SLOAD for gas optimization
///@dev update ticks if nencessary
if (params.liquidityDelta != 0) {
cache.maxLiquidityPerTick = Tick.tickSpacingToMaxLiquidityPerTick(params.tickSpacing);
cache.flippedLower = self.ticks.update(
params.tickLower,
tick,
params.liquidityDelta,
_feeGrowthGlobal0X128,
_feeGrowthGlobal1X128,
false,
cache.maxLiquidityPerTick
);
cache.flippedUpper = self.ticks.update(
params.tickUpper,
tick,
params.liquidityDelta,
_feeGrowthGlobal0X128,
_feeGrowthGlobal1X128,
true,
cache.maxLiquidityPerTick
);
if (cache.flippedLower) {
self.tickBitmap.flipTick(params.tickLower, params.tickSpacing);
}
if (cache.flippedUpper) {
self.tickBitmap.flipTick(params.tickUpper, params.tickSpacing);
}
}
(cache.feeGrowthInside0X128, cache.feeGrowthInside1X128) = self.ticks.getFeeGrowthInside(
params.tickLower, params.tickUpper, tick, _feeGrowthGlobal0X128, _feeGrowthGlobal1X128
);
}
///@dev update user position and collect fees
/// must be done after ticks are updated in case of a 0 -> 1 flip
(cache.feesOwed0, cache.feesOwed1) = self.positions.get(
params.owner, params.tickLower, params.tickUpper, params.salt
).update(params.liquidityDelta, cache.feeGrowthInside0X128, cache.feeGrowthInside1X128);
///@dev clear any tick data that is no longer needed
/// must be done after fee collection in case of a 1 -> 0 flip
if (params.liquidityDelta < 0) {
if (cache.flippedLower) {
self.ticks.clear(params.tickLower);
}
if (cache.flippedUpper) {
self.ticks.clear(params.tickUpper);
}
}
return (cache.feesOwed0, cache.feesOwed1);
}
/// @notice Donates are in fact giving token to in-ranged liquidity providers only
function donate(State storage state, uint256 amount0, uint256 amount1)
internal
returns (BalanceDelta delta, int24 tick)
{
if (state.liquidity == 0) revert NoLiquidityToReceiveFees();
delta = toBalanceDelta(-(amount0.toInt128()), -(amount1.toInt128()));
unchecked {
if (amount0 > 0) {
state.feeGrowthGlobal0X128 += UnsafeMath.simpleMulDiv(amount0, FixedPoint128.Q128, state.liquidity);
}
if (amount1 > 0) {
state.feeGrowthGlobal1X128 += UnsafeMath.simpleMulDiv(amount1, FixedPoint128.Q128, state.liquidity);
}
tick = state.slot0.tick();
}
}
function setProtocolFee(State storage self, uint24 protocolFee) internal {
self.checkPoolInitialized();
self.slot0 = self.slot0.setProtocolFee(protocolFee);
}
/// @notice Only dynamic fee pools may update the lp fee.
function setLPFee(State storage self, uint24 lpFee) internal {
self.checkPoolInitialized();
self.slot0 = self.slot0.setLpFee(lpFee);
}
function checkPoolInitialized(State storage self) internal view {
if (self.slot0.sqrtPriceX96() == 0) {
// revert PoolNotInitialized();
assembly ("memory-safe") {
mstore(0x00, 0x486aa307)
revert(0x1c, 0x04)
}
}
}
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IHooks {
function getHooksRegistrationBitmap() external view returns (uint16);
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Currency} from "../types/Currency.sol";
import {IProtocolFeeController} from "./IProtocolFeeController.sol";
import {PoolId} from "../types/PoolId.sol";
import {PoolKey} from "../types/PoolKey.sol";
import {IVault} from "./IVault.sol";
interface IProtocolFees {
/// @notice Thrown when the protocol fee exceeds the upper limit.
error ProtocolFeeTooLarge(uint24 fee);
/// @notice Thrown when calls to protocolFeeController fails or return size is not 32 bytes
error ProtocolFeeCannotBeFetched();
/// @notice Thrown when user not authorized to set or collect protocol fee
error InvalidCaller();
/// @notice Emitted when protocol fee is updated
/// @dev The event is emitted even if the updated protocolFee is the same as previous protocolFee
/// @param id The pool id for which the protocol fee is updated
/// @param protocolFee The new protocol fee value
event ProtocolFeeUpdated(PoolId indexed id, uint24 protocolFee);
/// @notice Emitted when protocol fee controller is updated
/// @param protocolFeeController The new protocol fee controller
event ProtocolFeeControllerUpdated(address indexed protocolFeeController);
/// @notice Given a currency address, returns the protocol fees accrued in that currency
/// @param currency The currency to check
/// @return amount The amount of protocol fees accrued in the given currency
function protocolFeesAccrued(Currency currency) external view returns (uint256 amount);
/// @notice Returns the current protocol fee controller address
/// @return IProtocolFeeController The currency protocol fee controller
function protocolFeeController() external view returns (IProtocolFeeController);
/// @notice Sets the protocol's swap fee for the given pool
/// @param key The pool key for which to set the protocol fee
/// @param newProtocolFee The new protocol fee to set
function setProtocolFee(PoolKey memory key, uint24 newProtocolFee) external;
/// @notice Update the protocol fee controller, called by the owner
/// @param controller The new protocol fee controller to be set
function setProtocolFeeController(IProtocolFeeController controller) external;
/// @notice Collects the protocol fee accrued in the given currency, called by the owner or the protocol fee controller
/// @dev This will revert if vault is locked
/// @param recipient The address to which the protocol fees should be sent
/// @param currency The currency in which to collect the protocol fees
/// @param amount The amount of protocol fees to collect
/// @return amountCollected The amount of protocol fees actually collected
function collectProtocolFees(address recipient, Currency currency, uint256 amount)
external
returns (uint256 amountCollected);
/// @notice Returns the vault where the protocol fees are safely stored
/// @return IVault The address of the vault
function vault() external view returns (IVault);
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IHooks} from "./IHooks.sol";
import {PoolKey} from "../types/PoolKey.sol";
import {PoolId} from "../types/PoolId.sol";
import {Currency} from "../types/Currency.sol";
interface IPoolManager {
/// @notice Thrown when trying to interact with a non-initialized pool
error PoolNotInitialized();
/// @notice PoolKey must have currencies where address(currency0) < address(currency1)
error CurrenciesInitializedOutOfOrder(address currency0, address currency1);
/// @notice Thrown when a call to updateDynamicLPFee is made by an address that is not the hook,
/// or on a pool is not a dynamic fee pool.
error UnauthorizedDynamicLPFeeUpdate();
/// @notice Emitted when lp fee is updated
/// @dev The event is emitted even if the updated fee value is the same as previous one
event DynamicLPFeeUpdated(PoolId indexed id, uint24 dynamicLPFee);
/// @notice Updates lp fee for a dyanmic fee pool
/// @dev Some of the use case could be:
/// 1) when hook#beforeSwap() is called and hook call this function to update the lp fee
/// 2) For BinPool only, when hook#beforeMint() is called and hook call this function to update the lp fee
/// 3) other use case where the hook might want to on an ad-hoc basis increase/reduce lp fee
function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external;
/// @notice Return PoolKey for a given PoolId
function poolIdToPoolKey(PoolId id)
external
view
returns (
Currency currency0,
Currency currency1,
IHooks hooks,
IPoolManager poolManager,
uint24 fee,
bytes32 parameters
);
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IExtsload {
/// @notice Called by external contracts to access granular pool state
/// @param slot Key of slot to sload
/// @return value The value of the slot as bytes32
function extsload(bytes32 slot) external view returns (bytes32 value);
/// @notice Called by external contracts to access sparse pool state
/// @param slots List of slots to SLOAD from.
/// @return values List of loaded values.
function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory values);
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import "../../libraries/SafeCast.sol";
import "./TickMath.sol";
import "./LiquidityMath.sol";
/// @title Tick
/// @notice Contains functions for managing tick processes and relevant calculations
library Tick {
using SafeCast for int256;
/// @notice Thrown when tickLower is not below tickUpper
/// @param tickLower The invalid tickLower
/// @param tickUpper The invalid tickUpper
error TicksMisordered(int24 tickLower, int24 tickUpper);
/// @notice Thrown when tickLower is less than min tick
/// @param tickLower The invalid tickLower
error TickLowerOutOfBounds(int24 tickLower);
/// @notice Thrown when tickUpper exceeds max tick
/// @param tickUpper The invalid tickUpper
error TickUpperOutOfBounds(int24 tickUpper);
/// @notice For the tick spacing, the tick has too much liquidity
error TickLiquidityOverflow(int24 tick);
// info stored for each initialized individual tick
struct Info {
// the total position liquidity that references this tick
uint128 liquidityGross;
// amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left),
int128 liquidityNet;
// fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)
// only has relative meaning, not absolute — the value depends on when the tick is initialized
uint256 feeGrowthOutside0X128;
uint256 feeGrowthOutside1X128;
}
/// @dev Common checks for valid tick inputs.
function checkTicks(int24 tickLower, int24 tickUpper) internal pure {
if (tickLower >= tickUpper) revert TicksMisordered(tickLower, tickUpper);
if (tickLower < TickMath.MIN_TICK) revert TickLowerOutOfBounds(tickLower);
if (tickUpper > TickMath.MAX_TICK) revert TickUpperOutOfBounds(tickUpper);
}
/// @notice Derives max liquidity per tick from given tick spacing
/// @dev Executed within the pool constructor
/// @param tickSpacing The amount of required tick separation, realized in multiples of `tickSpacing`
/// e.g., a tickSpacing of 3 requires ticks to be initialized every 3rd tick i.e., ..., -6, -3, 0, 3, 6, ...
/// @return result The max liquidity per tick
function tickSpacingToMaxLiquidityPerTick(int24 tickSpacing) internal pure returns (uint128 result) {
// Equivalent to v3 but in assembly for gas efficiency:
// int24 minTick = (TickMath.MIN_TICK / tickSpacing);
// if (TickMath.MIN_TICK % tickSpacing != 0) minTick--;
// int24 maxTick = (TickMath.MAX_TICK / tickSpacing);
// uint24 numTicks = maxTick - minTick + 1;
// return type(uint128).max / numTicks;
int24 MAX_TICK = TickMath.MAX_TICK;
int24 MIN_TICK = TickMath.MIN_TICK;
// tick spacing will never be 0 since TickMath.MIN_TICK_SPACING is 1
assembly ("memory-safe") {
tickSpacing := signextend(2, tickSpacing)
let minTick := sub(sdiv(MIN_TICK, tickSpacing), slt(smod(MIN_TICK, tickSpacing), 0))
let maxTick := sdiv(MAX_TICK, tickSpacing)
let numTicks := add(sub(maxTick, minTick), 1)
result := div(sub(shl(128, 1), 1), numTicks)
}
}
/// @notice Retrieves fee growth data
/// @param self The mapping containing all tick information for initialized ticks
/// @param tickLower The lower tick boundary of the position
/// @param tickUpper The upper tick boundary of the position
/// @param tickCurrent The current tick
/// @param feeGrowthGlobal0X128 The all-time global fee growth, per unit of liquidity, in token0
/// @param feeGrowthGlobal1X128 The all-time global fee growth, per unit of liquidity, in token1
/// @return feeGrowthInside0X128 The all-time fee growth in token0, per unit of liquidity, inside the position's tick boundaries
/// @return feeGrowthInside1X128 The all-time fee growth in token1, per unit of liquidity, inside the position's tick boundaries
function getFeeGrowthInside(
mapping(int24 => Tick.Info) storage self,
int24 tickLower,
int24 tickUpper,
int24 tickCurrent,
uint256 feeGrowthGlobal0X128,
uint256 feeGrowthGlobal1X128
) internal view returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) {
Info storage lower = self[tickLower];
Info storage upper = self[tickUpper];
// calculate fee growth below
uint256 feeGrowthBelow0X128;
uint256 feeGrowthBelow1X128;
unchecked {
if (tickCurrent >= tickLower) {
feeGrowthBelow0X128 = lower.feeGrowthOutside0X128;
feeGrowthBelow1X128 = lower.feeGrowthOutside1X128;
} else {
feeGrowthBelow0X128 = feeGrowthGlobal0X128 - lower.feeGrowthOutside0X128;
feeGrowthBelow1X128 = feeGrowthGlobal1X128 - lower.feeGrowthOutside1X128;
}
// calculate fee growth above
uint256 feeGrowthAbove0X128;
uint256 feeGrowthAbove1X128;
if (tickCurrent < tickUpper) {
feeGrowthAbove0X128 = upper.feeGrowthOutside0X128;
feeGrowthAbove1X128 = upper.feeGrowthOutside1X128;
} else {
feeGrowthAbove0X128 = feeGrowthGlobal0X128 - upper.feeGrowthOutside0X128;
feeGrowthAbove1X128 = feeGrowthGlobal1X128 - upper.feeGrowthOutside1X128;
}
feeGrowthInside0X128 = feeGrowthGlobal0X128 - feeGrowthBelow0X128 - feeGrowthAbove0X128;
feeGrowthInside1X128 = feeGrowthGlobal1X128 - feeGrowthBelow1X128 - feeGrowthAbove1X128;
}
}
/// @notice Updates a tick and returns true if the tick was flipped from initialized to uninitialized, or vice versa
/// @param self The mapping containing all tick information for initialized ticks
/// @param tick The tick that will be updated
/// @param tickCurrent The current tick
/// @param liquidityDelta A new amount of liquidity to be added (subtracted) when tick is crossed from left to right (right to left)
/// @param feeGrowthGlobal0X128 The all-time global fee growth, per unit of liquidity, in token0
/// @param feeGrowthGlobal1X128 The all-time global fee growth, per unit of liquidity, in token1
/// @param upper true for updating a position's upper tick, or false for updating a position's lower tick
/// @param maxLiquidity The maximum liquidity allocation for a single tick
/// @return flipped Whether the tick was flipped from initialized to uninitialized, or vice versa
function update(
mapping(int24 => Tick.Info) storage self,
int24 tick,
int24 tickCurrent,
int128 liquidityDelta,
uint256 feeGrowthGlobal0X128,
uint256 feeGrowthGlobal1X128,
bool upper,
uint128 maxLiquidity
) internal returns (bool flipped) {
Tick.Info storage info = self[tick];
///@dev accessing two members without touching the same slot twice
uint128 liquidityGrossBefore;
int128 liquidityNetBefore;
assembly ("memory-safe") {
let slot0 := sload(info.slot)
liquidityGrossBefore := shr(128, shl(128, slot0))
liquidityNetBefore := shr(128, slot0)
}
uint128 liquidityGrossAfter = LiquidityMath.addDelta(liquidityGrossBefore, liquidityDelta);
if (liquidityGrossAfter > maxLiquidity) revert TickLiquidityOverflow(tick);
flipped = (liquidityGrossAfter == 0) != (liquidityGrossBefore == 0);
if (liquidityGrossBefore == 0) {
// by convention, we assume that all growth before a tick was initialized happened _below_ the tick
if (tick <= tickCurrent) {
info.feeGrowthOutside0X128 = feeGrowthGlobal0X128;
info.feeGrowthOutside1X128 = feeGrowthGlobal1X128;
}
}
// when the lower (upper) tick is crossed left to right, liquidity must be added (removed)
// when the lower (upper) tick is crossed right to left, liquidity must be removed (added)
int128 liquidityNetAfter = upper ? (liquidityNetBefore - liquidityDelta) : (liquidityNetBefore + liquidityDelta);
// update two members in one go
assembly ("memory-safe") {
sstore(
info.slot, or(and(liquidityGrossAfter, 0xffffffffffffffffffffffffffffffff), shl(128, liquidityNetAfter))
)
}
}
/// @notice Clears tick data
/// @param self The mapping containing all initialized tick information for initialized ticks
/// @param tick The tick that will be cleared
function clear(mapping(int24 => Tick.Info) storage self, int24 tick) internal {
delete self[tick];
}
/// @notice Transitions to next tick as needed by price movement
/// @param self The mapping containing all tick information for initialized ticks
/// @param tick The destination tick of the transition
/// @param feeGrowthGlobal0X128 The all-time global fee growth, per unit of liquidity, in token0
/// @param feeGrowthGlobal1X128 The all-time global fee growth, per unit of liquidity, in token1
/// @return liquidityNet The amount of liquidity added (subtracted) when tick is crossed from left to right (right to left)
function cross(
mapping(int24 => Tick.Info) storage self,
int24 tick,
uint256 feeGrowthGlobal0X128,
uint256 feeGrowthGlobal1X128
) internal returns (int128 liquidityNet) {
unchecked {
Tick.Info storage info = self[tick];
info.feeGrowthOutside0X128 = feeGrowthGlobal0X128 - info.feeGrowthOutside0X128;
info.feeGrowthOutside1X128 = feeGrowthGlobal1X128 - info.feeGrowthOutside1X128;
liquidityNet = info.liquidityNet;
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
/// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
/// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = a * b
// Compute the product mod 2**256 and mod 2**256 - 1
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2**256 + prod0
uint256 prod0 = a * b; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly ("memory-safe") {
let mm := mulmod(a, b, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Make sure the result is less than 2**256.
// Also prevents denominator == 0
require(denominator > prod1);
// Handle non-overflow cases, 256 by 256 division
if (prod1 == 0) {
assembly ("memory-safe") {
result := div(prod0, denominator)
}
return result;
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0]
// Compute remainder using mulmod
uint256 remainder;
assembly ("memory-safe") {
remainder := mulmod(a, b, denominator)
}
// Subtract 256 bit number from 512 bit number
assembly ("memory-safe") {
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator
// Compute largest power of two divisor of denominator.
// Always >= 1.
uint256 twos = (0 - denominator) & denominator;
// Divide denominator by power of two
assembly ("memory-safe") {
denominator := div(denominator, twos)
}
// Divide [prod1 prod0] by the factors of two
assembly ("memory-safe") {
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 ("memory-safe") {
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 preconditions guarantee
// that the outcome is less than 2**256, this is the final result.
// We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inv;
return result;
}
}
/// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
function mulDivRoundingUp(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
result = mulDiv(a, b, denominator);
if (mulmod(a, b, denominator) != 0) {
require(++result > 0);
}
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @title FixedPoint128
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
library FixedPoint128 {
uint256 internal constant Q128 = 0x100000000000000000000000000000000;
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @title Math library for liquidity
library LiquidityMath {
/// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows
/// @param x The liquidity before change
/// @param y The delta by which liquidity should be changed
/// @return z The liquidity delta
function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) {
assembly ("memory-safe") {
z := add(and(x, 0xffffffffffffffffffffffffffffffff), signextend(15, y))
if shr(128, z) {
// store 0x93dafdf1, error SafeCastOverflow at memory 0 address and revert from pointer 28, to byte 32
mstore(0x0, 0x93dafdf1)
revert(0x1c, 0x04)
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
interface IEIP712 {
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IVault} from "infinity-core/src/interfaces/IVault.sol";
/// @title IImmutableState
/// @notice Interface for the ImmutableState contract
interface IImmutableState {
/// @notice The Pancakeswap Infinity Vault contract
function vault() external view returns (IVault);
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.24;
import {ILockCallback} from "infinity-core/src/interfaces/ILockCallback.sol";
import {IVault} from "infinity-core/src/interfaces/IVault.sol";
import {ImmutableState} from "./ImmutableState.sol";
/// @title Safe Callback
/// @notice A contract that only allows the PCS Infinity Vault to call the lockAcquired function
abstract contract SafeCallback is ImmutableState, ILockCallback {
/// @notice Thrown when calling lockAcquired where the caller is not the Vault
error NotVault();
constructor(IVault _vault) ImmutableState(_vault) {}
/// @notice Only allow calls from the Vault contract
modifier onlyByVault() {
if (msg.sender != address(vault)) revert NotVault();
_;
}
/// @inheritdoc ILockCallback
/// @dev We force the onlyByVault modifier by exposing a virtual function after the onlyByVault check.
function lockAcquired(bytes calldata data) external onlyByVault returns (bytes memory) {
return _lockAcquired(data);
}
/// @dev to be implemented by the child contract, to safely guarantee the logic is only executed by the Vault
function _lockAcquired(bytes calldata data) internal virtual returns (bytes memory);
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @title Action Constants
/// @notice Common constants used in actions
/// @dev Constants are gas efficient alternatives to their literal values
library ActionConstants {
/// @notice used to signal that an action should use the input value of the open delta on the vault
/// or of the balance that the contract holds
uint128 internal constant OPEN_DELTA = 0;
/// @notice used to signal that an action should use the contract's entire balance of a currency
/// This value is equivalent to 1<<255, i.e. a singular 1 in the most significant bit.
uint256 internal constant CONTRACT_BALANCE = 0x8000000000000000000000000000000000000000000000000000000000000000;
/// @notice used to signal that the recipient of an action should be the msgSender
address internal constant MSG_SENDER = address(1);
/// @notice used to signal that the recipient of an action should be the address(this)
address internal constant ADDRESS_THIS = address(2);
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {IVault} from "infinity-core/src/interfaces/IVault.sol";
import {IImmutableState} from "../interfaces/IImmutableState.sol";
/// @title Immutable State
/// @notice A collection of immutable state variables, commonly used across multiple contracts
contract ImmutableState is IImmutableState {
/// @inheritdoc IImmutableState
IVault public immutable vault;
constructor(IVault _vault) {
vault = _vault;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {PoolKey} from "infinity-core/src/types/PoolKey.sol";
import {Currency} from "infinity-core/src/types/Currency.sol";
import {PathKey} from "../libraries/PathKey.sol";
import {ICLRouterBase} from "../pool-cl/interfaces/ICLRouterBase.sol";
import {IBinRouterBase} from "../pool-bin/interfaces/IBinRouterBase.sol";
/// @title IInfinityRouter
/// @notice Interface containing all the structs and errors for different infinity swap types
interface IInfinityRouter is ICLRouterBase, IBinRouterBase {
/// @notice Emitted when an exactInput swap does not receive its minAmountOut
error TooLittleReceived(uint256 minAmountOutReceived, uint256 amountReceived);
/// @notice Emitted when an exactOutput is asked for more than its maxAmountIn
error TooMuchRequested(uint256 maxAmountInRequested, uint256 amountRequested);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern, minimalist, and gas efficient ERC-721 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC721.sol)
abstract contract ERC721 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 indexed id);
event Approval(address indexed owner, address indexed spender, uint256 indexed id);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE/LOGIC
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
function tokenURI(uint256 id) public view virtual returns (string memory);
/*//////////////////////////////////////////////////////////////
ERC721 BALANCE/OWNER STORAGE
//////////////////////////////////////////////////////////////*/
mapping(uint256 => address) internal _ownerOf;
mapping(address => uint256) internal _balanceOf;
function ownerOf(uint256 id) public view virtual returns (address owner) {
require((owner = _ownerOf[id]) != address(0), "NOT_MINTED");
}
function balanceOf(address owner) public view virtual returns (uint256) {
require(owner != address(0), "ZERO_ADDRESS");
return _balanceOf[owner];
}
/*//////////////////////////////////////////////////////////////
ERC721 APPROVAL STORAGE
//////////////////////////////////////////////////////////////*/
mapping(uint256 => address) public getApproved;
mapping(address => mapping(address => bool)) public isApprovedForAll;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(string memory _name, string memory _symbol) {
name = _name;
symbol = _symbol;
}
/*//////////////////////////////////////////////////////////////
ERC721 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 id) public virtual {
address owner = _ownerOf[id];
require(msg.sender == owner || isApprovedForAll[owner][msg.sender], "NOT_AUTHORIZED");
getApproved[id] = spender;
emit Approval(owner, spender, id);
}
function setApprovalForAll(address operator, bool approved) public virtual {
isApprovedForAll[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
function transferFrom(
address from,
address to,
uint256 id
) public virtual {
require(from == _ownerOf[id], "WRONG_FROM");
require(to != address(0), "INVALID_RECIPIENT");
require(
msg.sender == from || isApprovedForAll[from][msg.sender] || msg.sender == getApproved[id],
"NOT_AUTHORIZED"
);
// Underflow of the sender's balance is impossible because we check for
// ownership above and the recipient's balance can't realistically overflow.
unchecked {
_balanceOf[from]--;
_balanceOf[to]++;
}
_ownerOf[id] = to;
delete getApproved[id];
emit Transfer(from, to, id);
}
function safeTransferFrom(
address from,
address to,
uint256 id
) public virtual {
transferFrom(from, to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, "") ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
function safeTransferFrom(
address from,
address to,
uint256 id,
bytes calldata data
) public virtual {
transferFrom(from, to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, from, id, data) ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
/*//////////////////////////////////////////////////////////////
ERC165 LOGIC
//////////////////////////////////////////////////////////////*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return
interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165
interfaceId == 0x80ac58cd || // ERC165 Interface ID for ERC721
interfaceId == 0x5b5e139f; // ERC165 Interface ID for ERC721Metadata
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 id) internal virtual {
require(to != address(0), "INVALID_RECIPIENT");
require(_ownerOf[id] == address(0), "ALREADY_MINTED");
// Counter overflow is incredibly unrealistic.
unchecked {
_balanceOf[to]++;
}
_ownerOf[id] = to;
emit Transfer(address(0), to, id);
}
function _burn(uint256 id) internal virtual {
address owner = _ownerOf[id];
require(owner != address(0), "NOT_MINTED");
// Ownership check above ensures no underflow.
unchecked {
_balanceOf[owner]--;
}
delete _ownerOf[id];
delete getApproved[id];
emit Transfer(owner, address(0), id);
}
/*//////////////////////////////////////////////////////////////
INTERNAL SAFE MINT LOGIC
//////////////////////////////////////////////////////////////*/
function _safeMint(address to, uint256 id) internal virtual {
_mint(to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, "") ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
function _safeMint(
address to,
uint256 id,
bytes memory data
) internal virtual {
_mint(to, id);
require(
to.code.length == 0 ||
ERC721TokenReceiver(to).onERC721Received(msg.sender, address(0), id, data) ==
ERC721TokenReceiver.onERC721Received.selector,
"UNSAFE_RECIPIENT"
);
}
}
/// @notice A generic interface for a contract which properly accepts ERC721 tokens.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC721.sol)
abstract contract ERC721TokenReceiver {
function onERC721Received(
address,
address,
uint256,
bytes calldata
) external virtual returns (bytes4) {
return ERC721TokenReceiver.onERC721Received.selector;
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
library ERC721PermitHash {
/// @dev Value is equal to keccak256("Permit(address spender,uint256 tokenId,uint256 nonce,uint256 deadline)");
bytes32 constant PERMIT_TYPEHASH = 0x49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad;
/// @dev Value is equal to keccak256("PermitForAll(address operator,bool approved,uint256 nonce,uint256 deadline)");
bytes32 constant PERMIT_FOR_ALL_TYPEHASH = 0x6673cb397ee2a50b6b8401653d3638b4ac8b3db9c28aa6870ffceb7574ec2f76;
/// @notice Hashes the data that will be signed for IERC721Permit.permit()
/// @param spender The address which may spend the tokenId
/// @param tokenId The tokenId of the owner, which may be spent by spender
/// @param nonce A unique non-ordered value for each signature to prevent replay attacks
/// @param deadline The time at which the signature expires
/// @return digest The hash of the data to be signed; the equivalent to keccak256(abi.encode(PERMIT_TYPEHASH, spender, tokenId, nonce, deadline));
function hashPermit(address spender, uint256 tokenId, uint256 nonce, uint256 deadline)
internal
pure
returns (bytes32 digest)
{
// equivalent to: keccak256(abi.encode(PERMIT_TYPEHASH, spender, tokenId, nonce, deadline));
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, PERMIT_TYPEHASH)
mstore(add(fmp, 0x20), and(spender, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(fmp, 0x40), tokenId)
mstore(add(fmp, 0x60), nonce)
mstore(add(fmp, 0x80), deadline)
digest := keccak256(fmp, 0xa0)
// now clean the memory we used
mstore(fmp, 0) // fmp held PERMIT_TYPEHASH
mstore(add(fmp, 0x20), 0) // fmp+0x20 held spender
mstore(add(fmp, 0x40), 0) // fmp+0x40 held tokenId
mstore(add(fmp, 0x60), 0) // fmp+0x60 held nonce
mstore(add(fmp, 0x80), 0) // fmp+0x80 held deadline
}
}
/// @notice Hashes the data that will be signed for IERC721Permit.permit()
/// @param operator The address which may spend any of the owner's tokenIds
/// @param approved true if the operator is to have full permission over the owner's tokenIds; false otherwise
/// @param nonce A unique non-ordered value for each signature to prevent replay attacks
/// @param deadline The time at which the signature expires
/// @return digest The hash of the data to be signed; the equivalent to keccak256(abi.encode(PERMIT_FOR_ALL_TYPEHASH, operator, approved, nonce, deadline));
function hashPermitForAll(address operator, bool approved, uint256 nonce, uint256 deadline)
internal
pure
returns (bytes32 digest)
{
// equivalent to: keccak256(abi.encode(PERMIT_FOR_ALL_TYPEHASH, operator, approved, nonce, deadline));
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, PERMIT_FOR_ALL_TYPEHASH)
mstore(add(fmp, 0x20), and(operator, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(fmp, 0x40), and(approved, 0x1))
mstore(add(fmp, 0x60), nonce)
mstore(add(fmp, 0x80), deadline)
digest := keccak256(fmp, 0xa0)
// now clean the memory we used
mstore(fmp, 0) // fmp held PERMIT_FOR_ALL_TYPEHASH
mstore(add(fmp, 0x20), 0) // fmp+0x20 held operator
mstore(add(fmp, 0x40), 0) // fmp+0x40 held approved
mstore(add(fmp, 0x60), 0) // fmp+0x60 held nonce
mstore(add(fmp, 0x80), 0) // fmp+0x80 held deadline
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {IERC1271} from "../interfaces/IERC1271.sol";
library SignatureVerification {
/// @notice Thrown when the passed in signature is not a valid length
error InvalidSignatureLength();
/// @notice Thrown when the recovered signer is equal to the zero address
error InvalidSignature();
/// @notice Thrown when the recovered signer does not equal the claimedSigner
error InvalidSigner();
/// @notice Thrown when the recovered contract signature is incorrect
error InvalidContractSignature();
bytes32 constant UPPER_BIT_MASK = (0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
function verify(bytes calldata signature, bytes32 hash, address claimedSigner) internal view {
bytes32 r;
bytes32 s;
uint8 v;
if (claimedSigner.code.length == 0) {
if (signature.length == 65) {
(r, s) = abi.decode(signature, (bytes32, bytes32));
v = uint8(signature[64]);
} else if (signature.length == 64) {
// EIP-2098
bytes32 vs;
(r, vs) = abi.decode(signature, (bytes32, bytes32));
s = vs & UPPER_BIT_MASK;
v = uint8(uint256(vs >> 255)) + 27;
} else {
revert InvalidSignatureLength();
}
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) revert InvalidSignature();
if (signer != claimedSigner) revert InvalidSigner();
} else {
bytes4 magicValue = IERC1271(claimedSigner).isValidSignature(hash, signature);
if (magicValue != IERC1271.isValidSignature.selector) revert InvalidContractSignature();
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IEIP712} from "../interfaces/IEIP712.sol";
/// @notice Generic EIP712 implementation
/// @dev Maintains cross-chain replay protection in the event of a fork
/// @dev Should not be delegatecall'd because DOMAIN_SEPARATOR returns the cached hash and does not recompute with the delegatecallers address
/// @dev Reference: https://github.com/pancakeswap/permit2/blob/main/src/EIP712.sol
/// @dev Reference: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/EIP712.sol
contract EIP712 is IEIP712 {
// Cache the domain separator as an immutable value, but also store the chain id that it
// corresponds to, in order to invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
uint256 private immutable _CACHED_CHAIN_ID;
bytes32 private immutable _HASHED_NAME;
/// @dev equal to keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)")
bytes32 private constant _TYPE_HASH = 0x8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a866;
constructor(string memory name) {
_HASHED_NAME = keccak256(bytes(name));
_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator();
}
/// @inheritdoc IEIP712
function DOMAIN_SEPARATOR() public view override returns (bytes32) {
// uses cached version if chainid is unchanged from construction
return block.chainid == _CACHED_CHAIN_ID ? _CACHED_DOMAIN_SEPARATOR : _buildDomainSeparator();
}
/// @notice Builds a domain separator using the current chainId and contract address.
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _HASHED_NAME, block.chainid, address(this)));
}
/// @notice Creates an EIP-712 typed data hash
function _hashTypedData(bytes32 dataHash) internal view returns (bytes32 digest) {
// equal to keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), dataHash));
bytes32 domainSeparator = DOMAIN_SEPARATOR();
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, hex"1901")
mstore(add(fmp, 0x02), domainSeparator)
mstore(add(fmp, 0x22), dataHash)
digest := keccak256(fmp, 0x42)
// now clean the memory we used
mstore(fmp, 0) // fmp held "\x19\x01", domainSeparator
mstore(add(fmp, 0x20), 0) // fmp+0x20 held domainSeparator, dataHash
mstore(add(fmp, 0x40), 0) // fmp+0x40 held dataHash
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title ERC721 with permit
/// @notice Extension to ERC721 that includes a permit function for signature based approvals
interface IERC721Permit {
error SignatureDeadlineExpired();
error NoSelfPermit();
error Unauthorized();
/// @notice Approve of a specific token ID for spending by spender via signature
/// @param spender The account that is being approved
/// @param tokenId The ID of the token that is being approved for spending
/// @param deadline The deadline timestamp by which the call must be mined for the approve to work
/// @param nonce a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word
/// @param signature Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)
/// @dev payable so it can be multicalled with NATIVE related actions
function permit(address spender, uint256 tokenId, uint256 deadline, uint256 nonce, bytes calldata signature)
external
payable;
/// @notice Set an operator with full permission to an owner's tokens via signature
/// @param owner The address that is setting the operator
/// @param operator The address that will be set as an operator for the owner
/// @param approved The permission to set on the operator
/// @param deadline The deadline timestamp by which the call must be mined for the approve to work
/// @param nonce a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word
/// @param signature Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)
/// @dev payable so it can be multicalled with NATIVE related actions
function permitForAll(
address owner,
address operator,
bool approved,
uint256 deadline,
uint256 nonce,
bytes calldata signature
) external payable;
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @title Unordered Nonce
/// @notice Contract state and methods for using unordered nonces in signatures
contract UnorderedNonce {
error NonceAlreadyUsed();
/// @notice mapping of nonces consumed by each address, where a nonce is a single bit on the 256-bit bitmap
/// @dev word is at most type(uint248).max
mapping(address owner => mapping(uint256 word => uint256 bitmap)) public nonces;
/// @notice Consume a nonce, reverting if its already been used
/// @param owner address, the owner/signer of the nonce
/// @param nonce uint256, the nonce to consume. the top 248 bits are the word, the bottom 8 bits indicate the bit position
function _useUnorderedNonce(address owner, uint256 nonce) internal {
uint256 wordPos = nonce >> 8;
uint256 bitPos = uint8(nonce);
uint256 bit = 1 << bitPos;
uint256 flipped = nonces[owner][wordPos] ^= bit;
if (flipped & bit == 0) revert NonceAlreadyUsed();
}
/// @notice Revoke a nonce by spending it, preventing it from being used again
/// @dev Used in cases where a valid nonce has not been broadcasted onchain, and the owner wants to revoke the validity of the nonce
/// @dev payable so it can be multicalled with native-token related actions
function revokeNonce(uint256 nonce) external payable {
_useUnorderedNonce(msg.sender, nonce);
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @title Safe casting methods
/// @notice Contains methods for safely casting between types
/// TODO after audits move this function to core's SafeCast.sol!
library SafeCastTemp {
error SafeCastOverflow();
/// @notice Cast a uint256 to a uint128, revert on overflow
/// @param x The uint256 to be downcasted
/// @return y The downcasted integer, now type uint128
function toUint128(uint256 x) internal pure returns (uint128 y) {
y = uint128(x);
if (x != y) revert SafeCastOverflow();
}
/// @notice Cast a int128 to a uint128, revert on overflow or underflow
/// @param x The int128 to be casted
/// @return y The casted integer, now type uint128
function toUint128(int128 x) internal pure returns (uint128 y) {
if (x < 0) revert SafeCastOverflow();
y = uint128(x);
}
/// @notice Cast a uint256 to a int128, revert on overflow
/// @param x The uint256 to be downcasted
/// @return The downcasted integer, now type int128
function toInt128(uint256 x) internal pure returns (int128) {
if (x >= 1 << 127) revert SafeCastOverflow();
return int128(int256(x));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Multicall interface
/// @notice Enables calling multiple methods in a single call to the contract
interface IMulticall {
/// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
/// @dev The `msg.value` is passed onto all subcalls, even if a previous subcall has consumed the ether.
/// Subcalls can instead use `address(this).value` to see the available ETH, and consume it using {value: x}.
/// @param data The encoded function data for each of the calls to make to this contract
/// @return results The results from each of the calls passed in via data
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {ICLSubscriber} from "./ICLSubscriber.sol";
/// @notice This interface is used to opt in to sending updates to external contracts about position modifications or transfers
interface ICLNotifier {
/// @notice Thrown when unsubscribing without a subscriber
error NotSubscribed();
/// @notice Thrown when a subscriber does not have code
error NoCodeSubscriber();
/// @notice Thrown when a user specifies a gas limit too low to avoid valid unsubscribe notifications
error GasLimitTooLow();
/// @notice Wraps the revert message of the subscriber contract on a reverting subscription
error SubscriptionReverted(address subscriber, bytes reason);
/// @notice Wraps the revert message of the subscriber contract on a reverting modify liquidity notification
error ModifyLiquidityNotificationReverted(address subscriber, bytes reason);
/// @notice Wraps the revert message of the subscriber contract on a reverting burn notification
error BurnNotificationReverted(address subscriber, bytes reason);
/// @notice Thrown when a tokenId already has a subscriber
error AlreadySubscribed(uint256 tokenId, address subscriber);
/// @notice Emitted on a successful call to subscribe
event Subscription(uint256 indexed tokenId, address indexed subscriber);
/// @notice Emitted on a successful call to unsubscribe
event Unsubscription(uint256 indexed tokenId, address indexed subscriber);
/// @notice Returns the subscriber for a respective position
/// @param tokenId the ERC721 tokenId
/// @return subscriber the subscriber contract
function subscriber(uint256 tokenId) external view returns (ICLSubscriber subscriber);
/// @notice Enables the subscriber to receive notifications for a respective position
/// @param tokenId the ERC721 tokenId
/// @param newSubscriber the address of the subscriber contract
/// @param data caller-provided data that's forwarded to the subscriber contract
/// @dev Calling subscribe when a position is already subscribed will revert
/// @dev payable so it can be multicalled with NATIVE related actions
/// @dev will revert if vault is locked
function subscribe(uint256 tokenId, address newSubscriber, bytes calldata data) external payable;
/// @notice Removes the subscriber from receiving notifications for a respective position
/// @param tokenId the ERC721 tokenId
/// @dev Callers must specify a high gas limit (remaining gas should be higher than unsubscriberGasLimit) such that the subscriber can be notified
/// @dev payable so it can be multicalled with NATIVE related actions
/// @dev Must always allow a user to unsubscribe. In the case of a malicious subscriber, a user can always unsubscribe safely, ensuring liquidity is always modifiable.
/// @dev will revert if vault is locked
function unsubscribe(uint256 tokenId) external payable;
/// @notice Returns and determines the maximum allowable gas-used for notifying unsubscribe
/// @return uint256 the maximum gas limit when notifying a subscriber's `notifyUnsubscribe` function
function unsubscribeGasLimit() external view returns (uint256);
}// 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: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.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.8.0;
/**
* @dev CLSlot0 is a packed version of solidity structure.
* Using the packaged version saves gas by not storing the structure fields in memory slots.
*
* Layout:
* 24 bits empty | 24 bits lpFee | 12 bits protocolFee 1->0 | 12 bits protocolFee 0->1 | 24 bits tick | 160 bits sqrtPriceX96
*
* Fields in the direction from the least significant bit:
*
* The current price
* uint160 sqrtPriceX96;
*
* The current tick
* int24 tick;
*
* Protocol fee, expressed in hundredths of a bip, upper 12 bits are for 1->0, and the lower 12 are for 0->1
* the maximum is 1000 - meaning the maximum protocol fee is 0.1%
* the protocolFee is taken from the input first, then the lpFee is taken from the remaining input
* uint24 protocolFee;
*
* The current LP fee of the pool. If the pool is dynamic, this does not include the dynamic fee flag.
* uint24 lpFee;
*/
type CLSlot0 is bytes32;
using CLSlot0Library for CLSlot0 global;
/// @notice Library for getting and setting values in the Slot0 type
library CLSlot0Library {
uint160 internal constant MASK_160_BITS = 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
uint24 internal constant MASK_24_BITS = 0xFFFFFF;
uint8 internal constant TICK_OFFSET = 160;
uint8 internal constant PROTOCOL_FEE_OFFSET = 184;
uint8 internal constant LP_FEE_OFFSET = 208;
////////////////////////////////////////////////////////////////////////////////////////
// #### GETTERS ####
////////////////////////////////////////////////////////////////////////////////////////
function sqrtPriceX96(CLSlot0 _packed) internal pure returns (uint160 _sqrtPriceX96) {
assembly ("memory-safe") {
_sqrtPriceX96 := and(MASK_160_BITS, _packed)
}
}
function tick(CLSlot0 _packed) internal pure returns (int24 _tick) {
assembly ("memory-safe") {
_tick := signextend(2, shr(TICK_OFFSET, _packed))
}
}
function protocolFee(CLSlot0 _packed) internal pure returns (uint24 _protocolFee) {
assembly ("memory-safe") {
_protocolFee := and(MASK_24_BITS, shr(PROTOCOL_FEE_OFFSET, _packed))
}
}
function lpFee(CLSlot0 _packed) internal pure returns (uint24 _lpFee) {
assembly ("memory-safe") {
_lpFee := and(MASK_24_BITS, shr(LP_FEE_OFFSET, _packed))
}
}
////////////////////////////////////////////////////////////////////////////////////////
// #### SETTERS ####
////////////////////////////////////////////////////////////////////////////////////////
function setSqrtPriceX96(CLSlot0 _packed, uint160 _sqrtPriceX96) internal pure returns (CLSlot0 _result) {
assembly ("memory-safe") {
_result := or(and(not(MASK_160_BITS), _packed), and(MASK_160_BITS, _sqrtPriceX96))
}
}
function setTick(CLSlot0 _packed, int24 _tick) internal pure returns (CLSlot0 _result) {
assembly ("memory-safe") {
_result := or(and(not(shl(TICK_OFFSET, MASK_24_BITS)), _packed), shl(TICK_OFFSET, and(MASK_24_BITS, _tick)))
}
}
function setProtocolFee(CLSlot0 _packed, uint24 _protocolFee) internal pure returns (CLSlot0 _result) {
assembly ("memory-safe") {
_result :=
or(
and(not(shl(PROTOCOL_FEE_OFFSET, MASK_24_BITS)), _packed),
shl(PROTOCOL_FEE_OFFSET, and(MASK_24_BITS, _protocolFee))
)
}
}
function setLpFee(CLSlot0 _packed, uint24 _lpFee) internal pure returns (CLSlot0 _result) {
assembly ("memory-safe") {
_result :=
or(and(not(shl(LP_FEE_OFFSET, MASK_24_BITS)), _packed), shl(LP_FEE_OFFSET, and(MASK_24_BITS, _lpFee)))
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {BitMath} from "./BitMath.sol";
/// @title Packed tick initialized state library
/// @notice Stores a packed mapping of tick index to its initialized state
/// @dev The mapping uses int16 for keys since ticks are represented as int24 and there are 256 (2^8) values per word.
library TickBitmap {
/// @notice Thrown when the tick is not enumerated by the tick spacing
/// @param tick the invalid tick
/// @param tickSpacing The tick spacing of the pool
error TickMisaligned(int24 tick, int24 tickSpacing);
/// @dev round towards negative infinity
function compress(int24 tick, int24 tickSpacing) internal pure returns (int24 compressed) {
// Equivalent to:
// compressed = tick / tickSpacing;
// if (tick < 0 && tick % tickSpacing != 0) compressed--;
assembly ("memory-safe") {
tick := signextend(2, tick)
tickSpacing := signextend(2, tickSpacing)
compressed :=
sub(
sdiv(tick, tickSpacing),
// if (tick < 0 && tick % tickSpacing != 0) then tick % tickSpacing < 0, vice versa
slt(smod(tick, tickSpacing), 0)
)
}
}
/// @notice Computes the position in the mapping where the initialized bit for a tick lives
/// @param tick The tick for which to compute the position
/// @return wordPos The key in the mapping containing the word in which the bit is stored
/// @return bitPos The bit position in the word where the flag is stored
function position(int24 tick) internal pure returns (int16 wordPos, uint8 bitPos) {
assembly ("memory-safe") {
// signed arithmetic shift right
wordPos := sar(8, signextend(2, tick))
bitPos := and(tick, 0xff)
}
}
/// @notice Flips the initialized state for a given tick from false to true, or vice versa
/// @param self The mapping in which to flip the tick
/// @param tick The tick to flip
/// @param tickSpacing The spacing between usable ticks
function flipTick(mapping(int16 => uint256) storage self, int24 tick, int24 tickSpacing) internal {
// Equivalent to:
// if (tick % tickSpacing != 0) revert TickMisaligned(tick, tickSpacing); // ensure that the tick is spaced
// (int16 wordPos, uint8 bitPos) = position(tick / tickSpacing);
// uint256 mask = 1 << bitPos;
// self[wordPos] ^= mask;
assembly ("memory-safe") {
tick := signextend(2, tick)
tickSpacing := signextend(2, tickSpacing)
// ensure that the tick is spaced
if smod(tick, tickSpacing) {
let fmp := mload(0x40)
mstore(fmp, 0xd4d8f3e6) // selector for TickMisaligned(int24,int24)
mstore(add(fmp, 0x20), tick)
mstore(add(fmp, 0x40), tickSpacing)
revert(add(fmp, 0x1c), 0x44)
}
tick := sdiv(tick, tickSpacing)
// calculate the storage slot corresponding to the tick
// wordPos = tick >> 8
mstore(0, sar(8, tick))
mstore(0x20, self.slot)
// the slot of self[wordPos] is keccak256(abi.encode(wordPos, self.slot))
let slot := keccak256(0, 0x40)
// mask = 1 << bitPos = 1 << (tick % 256)
// self[wordPos] ^= mask
sstore(slot, xor(sload(slot), shl(and(tick, 0xff), 1)))
}
}
/// @notice Returns the next initialized tick contained in the same word (or adjacent word) as the tick that is either
/// to the left (less than or equal to) or right (greater than) of the given tick
/// @param self The mapping in which to compute the next initialized tick
/// @param tick The starting tick
/// @param tickSpacing The spacing between usable ticks
/// @param lte Whether to search for the next initialized tick to the left (less than or equal to the starting tick)
/// @return next The next initialized or uninitialized tick up to 256 ticks away from the current tick
/// @return initialized Whether the next tick is initialized, as the function only searches within up to 256 ticks
function nextInitializedTickWithinOneWord(
mapping(int16 => uint256) storage self,
int24 tick,
int24 tickSpacing,
bool lte
) internal view returns (int24 next, bool initialized) {
unchecked {
int24 compressed = compress(tick, tickSpacing);
if (lte) {
(int16 wordPos, uint8 bitPos) = position(compressed);
// all the 1s at or to the right of the current bitPos
// uint256 mask = (1 << bitPos) - 1 + (1 << bitPos);
uint256 mask = type(uint256).max >> (uint256(type(uint8).max) - bitPos);
uint256 masked = self[wordPos] & mask;
// if there are no initialized ticks to the right of or at the current tick, return rightmost in the word
initialized = masked != 0;
// overflow/underflow is possible, but prevented externally by limiting both tickSpacing and tick
next = initialized
? (compressed - int24(uint24(bitPos - BitMath.mostSignificantBit(masked)))) * tickSpacing
: (compressed - int24(uint24(bitPos))) * tickSpacing;
} else {
// start from the word of the next tick, since the current tick state doesn't matter
(int16 wordPos, uint8 bitPos) = position(++compressed);
// all the 1s at or to the left of the bitPos
uint256 mask = ~((1 << bitPos) - 1);
uint256 masked = self[wordPos] & mask;
// if there are no initialized ticks to the left of the current tick, return leftmost in the word
initialized = masked != 0;
// overflow/underflow is possible, but prevented externally by limiting both tickSpacing and tick
next = initialized
? (compressed + int24(uint24(BitMath.leastSignificantBit(masked) - bitPos))) * tickSpacing
: (compressed + int24(uint24(type(uint8).max - bitPos))) * tickSpacing;
}
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {SafeCast} from "../../libraries/SafeCast.sol";
import {FullMath} from "./FullMath.sol";
import {UnsafeMath} from "../../libraries/math/UnsafeMath.sol";
import {FixedPoint96} from "./FixedPoint96.sol";
/// @title Functions based on Q64.96 sqrt price and liquidity
/// @notice Contains the math that uses square root of price as a Q64.96 and liquidity to compute deltas
library SqrtPriceMath {
using SafeCast for uint256;
error InvalidPriceOrLiquidity();
error InvalidPrice();
error NotEnoughLiquidity();
error PriceOverflow();
/// @notice Gets the next sqrt price given a delta of currency0
/// @dev Always rounds up, because in the exact output case (increasing price) we need to move the price at least
/// far enough to get the desired output amount, and in the exact input case (decreasing price) we need to move the
/// price less in order to not send too much output.
/// The most precise formula for this is liquidity * sqrtPX96 / (liquidity +- amount * sqrtPX96),
/// if this is impossible because of overflow, we calculate liquidity / (liquidity / sqrtPX96 +- amount).
/// @param sqrtPX96 The starting price, i.e. before accounting for the currency0 delta
/// @param liquidity The amount of usable liquidity
/// @param amount How much of currency0 to add or remove from virtual reserves
/// @param add Whether to add or remove the amount of currency0
/// @return The price after adding or removing amount, depending on add
function getNextSqrtPriceFromAmount0RoundingUp(uint160 sqrtPX96, uint128 liquidity, uint256 amount, bool add)
internal
pure
returns (uint160)
{
// we short circuit amount == 0 because the result is otherwise not guaranteed to equal the input price
if (amount == 0) return sqrtPX96;
uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;
if (add) {
unchecked {
uint256 product = amount * sqrtPX96;
if (product / amount == sqrtPX96) {
uint256 denominator = numerator1 + product;
if (denominator >= numerator1) {
// always fits in 160 bits
return uint160(FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator));
}
}
}
// denominator is checked for overflow
return uint160(UnsafeMath.divRoundingUp(numerator1, (numerator1 / sqrtPX96) + amount));
} else {
unchecked {
uint256 product = amount * sqrtPX96;
// if the product overflows, we know the denominator underflows
// in addition, we must check that the denominator does not underflow
// equivalent: if (product / amount != sqrtPX96 || numerator1 <= product) revert PriceOverflow();
assembly ("memory-safe") {
if iszero(
and(
eq(div(product, amount), and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff)),
gt(numerator1, product)
)
) {
mstore(0, 0xf5c787f1) // selector for PriceOverflow()
revert(0x1c, 0x04)
}
}
uint256 denominator = numerator1 - product;
return FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator).toUint160();
}
}
}
/// @notice Gets the next sqrt price given a delta of currency1
/// @dev Always rounds down, because in the exact output case (decreasing price) we need to move the price at least
/// far enough to get the desired output amount, and in the exact input case (increasing price) we need to move the
/// price less in order to not send too much output.
/// The formula we compute is within <1 wei of the lossless version: sqrtPX96 +- amount / liquidity
/// @param sqrtPX96 The starting price, i.e., before accounting for the currency1 delta
/// @param liquidity The amount of usable liquidity
/// @param amount How much of currency1 to add, or remove, from virtual reserves
/// @param add Whether to add, or remove, the amount of currency1
/// @return The price after adding or removing `amount`
function getNextSqrtPriceFromAmount1RoundingDown(uint160 sqrtPX96, uint128 liquidity, uint256 amount, bool add)
internal
pure
returns (uint160)
{
// if we're adding (subtracting), rounding down requires rounding the quotient down (up)
// in both cases, avoid a mulDiv for most inputs
if (add) {
uint256 quotient = (
amount <= type(uint160).max
? (amount << FixedPoint96.RESOLUTION) / liquidity
: FullMath.mulDiv(amount, FixedPoint96.Q96, liquidity)
);
return (uint256(sqrtPX96) + quotient).toUint160();
} else {
uint256 quotient = (
amount <= type(uint160).max
? UnsafeMath.divRoundingUp(amount << FixedPoint96.RESOLUTION, liquidity)
: FullMath.mulDivRoundingUp(amount, FixedPoint96.Q96, liquidity)
);
// equivalent: if (sqrtPX96 <= quotient) revert NotEnoughLiquidity();
assembly ("memory-safe") {
if iszero(gt(and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff), quotient)) {
mstore(0, 0x4323a555) // selector for NotEnoughLiquidity()
revert(0x1c, 0x04)
}
}
// always fits 160 bits
unchecked {
return uint160(sqrtPX96 - quotient);
}
}
}
/// @notice Gets the next sqrt price given an input amount of currency0 or currency1
/// @dev Throws if price or liquidity are 0, or if the next price is out of bounds
/// @param sqrtPX96 The starting price, i.e., before accounting for the input amount
/// @param liquidity The amount of usable liquidity
/// @param amountIn How much of currency0, or currency1, is being swapped in
/// @param zeroForOne Whether the amount in is currency0 or currency1
/// @return uint160 The price after adding the input amount to currency0 or currency1
function getNextSqrtPriceFromInput(uint160 sqrtPX96, uint128 liquidity, uint256 amountIn, bool zeroForOne)
internal
pure
returns (uint160)
{
// equivalent: if (sqrtPX96 == 0 || liquidity == 0) revert InvalidPriceOrLiquidity();
assembly ("memory-safe") {
if or(
iszero(and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff)),
iszero(and(liquidity, 0xffffffffffffffffffffffffffffffff))
) {
mstore(0, 0x4f2461b8) // selector for InvalidPriceOrLiquidity()
revert(0x1c, 0x04)
}
}
// round to make sure that we don't pass the target price
return zeroForOne
? getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, true)
: getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountIn, true);
}
/// @notice Gets the next sqrt price given an output amount of currency0 or currency1
/// @dev Throws if price or liquidity are 0 or the next price is out of bounds
/// @param sqrtPX96 The starting price before accounting for the output amount
/// @param liquidity The amount of usable liquidity
/// @param amountOut How much of currency0, or currency1, is being swapped out
/// @param zeroForOne Whether the amount out is currency0 or currency1
/// @return uint160 The price after removing the output amount of currency0 or currency1
function getNextSqrtPriceFromOutput(uint160 sqrtPX96, uint128 liquidity, uint256 amountOut, bool zeroForOne)
internal
pure
returns (uint160)
{
// equivalent: if (sqrtPX96 == 0 || liquidity == 0) revert InvalidPriceOrLiquidity();
assembly ("memory-safe") {
if or(
iszero(and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff)),
iszero(and(liquidity, 0xffffffffffffffffffffffffffffffff))
) {
mstore(0, 0x4f2461b8) // selector for InvalidPriceOrLiquidity()
revert(0x1c, 0x04)
}
}
// round to make sure that we pass the target price
return zeroForOne
? getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, false)
: getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountOut, false);
}
/// @notice Gets the amount0 delta between two prices
/// @dev Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper),
/// i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower))
/// @param sqrtRatioAX96 A sqrt price
/// @param sqrtRatioBX96 Another sqrt price
/// @param liquidity The amount of usable liquidity
/// @param roundUp Whether to round the amount up or down
/// @return uint256 Amount of currency0 required to cover a position of size liquidity between the two passed prices
function getAmount0Delta(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity, bool roundUp)
internal
pure
returns (uint256)
{
unchecked {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
// equivalent: if (sqrtRatioAX96 == 0) revert InvalidPrice();
assembly ("memory-safe") {
if iszero(and(sqrtRatioAX96, 0xffffffffffffffffffffffffffffffffffffffff)) {
mstore(0, 0x00bfc921) // selector for InvalidPrice()
revert(0x1c, 0x04)
}
}
uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;
uint256 numerator2 = sqrtRatioBX96 - sqrtRatioAX96;
return roundUp
? UnsafeMath.divRoundingUp(FullMath.mulDivRoundingUp(numerator1, numerator2, sqrtRatioBX96), sqrtRatioAX96)
: FullMath.mulDiv(numerator1, numerator2, sqrtRatioBX96) / sqrtRatioAX96;
}
}
/// @notice Equivalent to: `a >= b ? a - b : b - a`
function absDiff(uint160 a, uint160 b) internal pure returns (uint256 res) {
assembly ("memory-safe") {
let diff :=
sub(and(a, 0xffffffffffffffffffffffffffffffffffffffff), and(b, 0xffffffffffffffffffffffffffffffffffffffff))
// mask = 0 if a >= b else -1 (all 1s)
let mask := sar(255, diff)
// if a >= b, res = a - b = 0 ^ (a - b)
// if a < b, res = b - a = ~~(b - a) = ~(-(b - a) - 1) = ~(a - b - 1) = (-1) ^ (a - b - 1)
// either way, res = mask ^ (a - b + mask)
res := xor(mask, add(mask, diff))
}
}
/// @notice Gets the amount1 delta between two prices
/// @dev Calculates liquidity * (sqrt(upper) - sqrt(lower))
/// @param sqrtRatioAX96 A sqrt price
/// @param sqrtRatioBX96 Another sqrt price
/// @param liquidity The amount of usable liquidity
/// @param roundUp Whether to round the amount up, or down
/// @return amount1 Amount of currency1 required to cover a position of size liquidity between the two passed prices
function getAmount1Delta(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity, bool roundUp)
internal
pure
returns (uint256 amount1)
{
uint256 numerator = absDiff(sqrtRatioAX96, sqrtRatioBX96);
uint256 denominator = FixedPoint96.Q96;
uint256 _liquidity = uint256(liquidity);
/**
* Equivalent to:
* amount1 = roundUp
* ? FullMath.mulDivRoundingUp(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96)
* : FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);
* Cannot overflow because `type(uint128).max * type(uint160).max >> 96 < (1 << 192)`.
*/
amount1 = FullMath.mulDiv(_liquidity, numerator, denominator);
assembly ("memory-safe") {
amount1 := add(amount1, and(gt(mulmod(_liquidity, numerator, denominator), 0), and(roundUp, 0x1)))
}
}
/// @notice Helper that gets signed currency0 delta
/// @param sqrtRatioAX96 A sqrt price
/// @param sqrtRatioBX96 Another sqrt price
/// @param liquidity The change in liquidity for which to compute the amount0 delta
/// @return int256 Amount of currency0 corresponding to the passed liquidityDelta between the two prices
function getAmount0Delta(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, int128 liquidity)
internal
pure
returns (int256)
{
unchecked {
return liquidity < 0
? getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256()
: -getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256();
}
}
/// @notice Helper that gets signed currency1 delta
/// @param sqrtRatioAX96 A sqrt price
/// @param sqrtRatioBX96 Another sqrt price
/// @param liquidity The change in liquidity for which to compute the amount1 delta
/// @return int256 Amount of currency1 corresponding to the passed liquidityDelta between the two prices
function getAmount1Delta(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, int128 liquidity)
internal
pure
returns (int256)
{
unchecked {
return liquidity < 0
? getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256()
: -getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256();
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @title Math functions that do not check inputs or outputs
/// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks
library UnsafeMath {
/// @notice Returns ceil(x / y)
/// @dev division by 0 will return 0, and should be checked externally
/// @param x The dividend
/// @param y The divisor
/// @return z The quotient, ceil(x / y)
function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
assembly ("memory-safe") {
z := add(div(x, y), gt(mod(x, y), 0))
}
}
/// @notice Calculates floor(a×b÷denominator)
/// @dev division by 0 will return 0, and should be checked externally
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result, floor(a×b÷denominator)
function simpleMulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
assembly ("memory-safe") {
result := div(mul(a, b), denominator)
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import "./FullMath.sol";
import "./SqrtPriceMath.sol";
import "../../libraries/LPFeeLibrary.sol";
/// @title Computes the result of a swap within ticks
/// @notice Contains methods for computing the result of a swap within a single tick price range, i.e., a single tick.
library SwapMath {
uint256 internal constant MAX_FEE_PIPS = LPFeeLibrary.ONE_HUNDRED_PERCENT_FEE;
/// @notice Computes the sqrt price target for the next swap step
/// @param zeroForOne The direction of the swap, true for currency0 to currency1, false for currency1 to currency0
/// @param sqrtPriceNextX96 The Q64.96 sqrt price for the next initialized tick
/// @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
/// @return sqrtPriceTargetX96 The price target for the next swap step
function getSqrtPriceTarget(bool zeroForOne, uint160 sqrtPriceNextX96, uint160 sqrtPriceLimitX96)
internal
pure
returns (uint160 sqrtPriceTargetX96)
{
assembly ("memory-safe") {
// a flag to toggle between sqrtPriceNextX96 and sqrtPriceLimitX96
// when zeroForOne == true, nextOrLimit reduces to sqrtPriceNextX96 >= sqrtPriceLimitX96
// sqrtPriceTargetX96 = max(sqrtPriceNextX96, sqrtPriceLimitX96)
// when zeroForOne == false, nextOrLimit reduces to sqrtPriceNextX96 < sqrtPriceLimitX96
// sqrtPriceTargetX96 = min(sqrtPriceNextX96, sqrtPriceLimitX96)
sqrtPriceNextX96 := and(sqrtPriceNextX96, 0xffffffffffffffffffffffffffffffffffffffff)
sqrtPriceLimitX96 := and(sqrtPriceLimitX96, 0xffffffffffffffffffffffffffffffffffffffff)
let nextOrLimit := xor(lt(sqrtPriceNextX96, sqrtPriceLimitX96), and(zeroForOne, 0x1))
let symDiff := xor(sqrtPriceNextX96, sqrtPriceLimitX96)
sqrtPriceTargetX96 := xor(sqrtPriceLimitX96, mul(symDiff, nextOrLimit))
}
}
/// @notice Computes the result of swapping some amount in, or amount out, given the parameters of the swap
/// @dev The fee, plus the amount in, will never exceed the amount remaining if the swap's `amountSpecified` is positive
/// @param sqrtRatioCurrentX96 The current sqrt price of the pool
/// @param sqrtRatioTargetX96 The price that cannot be exceeded, from which the direction of the swap is inferred
/// @param liquidity The usable liquidity
/// @param amountRemaining How much input or output amount is remaining to be swapped in/out
/// @param feePips The fee taken from the input amount, expressed in hundredths of a bip
/// @return sqrtRatioNextX96 The price after swapping the amount in/out, not to exceed the price target
/// @return amountIn The amount to be swapped in, of either token0 or token1, based on the direction of the swap
/// @return amountOut The amount to be received, of either token0 or token1, based on the direction of the swap
/// @return feeAmount The amount of input that will be taken as a fee
/// @dev feePips must be no larger than MAX_FEE_PIPS for this function. We ensure that before setting a fee using LPFeeLibrary.validate.
function computeSwapStep(
uint160 sqrtRatioCurrentX96,
uint160 sqrtRatioTargetX96,
uint128 liquidity,
int256 amountRemaining,
uint24 feePips
) internal pure returns (uint160 sqrtRatioNextX96, uint256 amountIn, uint256 amountOut, uint256 feeAmount) {
unchecked {
uint256 _feePips = feePips; // upcast once and cache
bool zeroForOne = sqrtRatioCurrentX96 >= sqrtRatioTargetX96;
bool exactIn = amountRemaining < 0;
if (exactIn) {
uint256 amountRemainingLessFee =
FullMath.mulDiv(uint256(-amountRemaining), MAX_FEE_PIPS - _feePips, MAX_FEE_PIPS);
amountIn = zeroForOne
? SqrtPriceMath.getAmount0Delta(sqrtRatioTargetX96, sqrtRatioCurrentX96, liquidity, true)
: SqrtPriceMath.getAmount1Delta(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, true);
if (amountRemainingLessFee >= amountIn) {
// `amountIn` is capped by the target price
sqrtRatioNextX96 = sqrtRatioTargetX96;
feeAmount = _feePips == MAX_FEE_PIPS
? amountIn
: FullMath.mulDivRoundingUp(amountIn, _feePips, MAX_FEE_PIPS - _feePips);
} else {
// exhaust the remaining amount
amountIn = amountRemainingLessFee;
sqrtRatioNextX96 = SqrtPriceMath.getNextSqrtPriceFromInput(
sqrtRatioCurrentX96, liquidity, amountRemainingLessFee, zeroForOne
);
// we didn't reach the target, so take the remainder of the maximum input as fee
feeAmount = uint256(-amountRemaining) - amountIn;
}
amountOut = zeroForOne
? SqrtPriceMath.getAmount1Delta(sqrtRatioNextX96, sqrtRatioCurrentX96, liquidity, false)
: SqrtPriceMath.getAmount0Delta(sqrtRatioCurrentX96, sqrtRatioNextX96, liquidity, false);
} else {
amountOut = zeroForOne
? SqrtPriceMath.getAmount1Delta(sqrtRatioTargetX96, sqrtRatioCurrentX96, liquidity, false)
: SqrtPriceMath.getAmount0Delta(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, false);
if (uint256(amountRemaining) >= amountOut) {
// `amountOut` is capped by the target price
sqrtRatioNextX96 = sqrtRatioTargetX96;
} else {
// cap the output amount to not exceed the remaining output amount
amountOut = uint256(amountRemaining);
sqrtRatioNextX96 =
SqrtPriceMath.getNextSqrtPriceFromOutput(sqrtRatioCurrentX96, liquidity, amountOut, zeroForOne);
}
amountIn = zeroForOne
? SqrtPriceMath.getAmount0Delta(sqrtRatioNextX96, sqrtRatioCurrentX96, liquidity, true)
: SqrtPriceMath.getAmount1Delta(sqrtRatioCurrentX96, sqrtRatioNextX96, liquidity, true);
// `feePips` cannot be `MAX_FEE_PIPS` for exact out
feeAmount = FullMath.mulDivRoundingUp(amountIn, _feePips, MAX_FEE_PIPS - _feePips);
}
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import "./math/UnsafeMath.sol";
library ProtocolFeeLibrary {
/// @dev Increasing these values could lead to overflow in Pool.swap
/// @notice Max protocol fee is 0.4% (4000 pips)
uint16 public constant MAX_PROTOCOL_FEE = 4000;
/// @notice Thresholds used for optimized bounds checks on protocol fees
uint24 internal constant FEE_0_THRESHOLD = 4001;
uint24 internal constant FEE_1_THRESHOLD = 4001 << 12;
/// @notice the protocol fee is represented in hundredths of a bip
uint256 internal constant PIPS_DENOMINATOR = 1_000_000;
/// @notice Get the fee taken when swap token0 for token1
/// @param self The composite protocol fee to get the single direction fee from
/// @return The fee taken when swapping token0 for token1
function getZeroForOneFee(uint24 self) internal pure returns (uint16) {
return uint16(self & 0xfff);
}
/// @notice Get the fee taken when swap token1 for token0
/// @param self The composite protocol fee to get the single direction fee from
/// @return The fee taken when swapping token1 for token0
function getOneForZeroFee(uint24 self) internal pure returns (uint16) {
return uint16(self >> 12);
}
/// @notice Validate that the protocol fee is within bounds
/// @param self The composite protocol fee to validate
/// @return valid True if the fee is within bounds
function validate(uint24 self) internal pure returns (bool valid) {
// Equivalent to: getZeroForOneFee(self) <= MAX_PROTOCOL_FEE && getOneForZeroFee(self) <= MAX_PROTOCOL_FEE
assembly ("memory-safe") {
let isZeroForOneFeeOk := lt(and(self, 0xfff), FEE_0_THRESHOLD)
let isOneForZeroFeeOk := lt(and(self, 0xfff000), FEE_1_THRESHOLD)
valid := and(isZeroForOneFeeOk, isOneForZeroFeeOk)
}
}
/// @notice The protocol fee is taken from the input amount first and then the LP fee is taken from the remaining
// Equivalent to protocolFee + lpFee(1_000_000 - protocolFee) / 1_000_000 (rounded up)
/// Also note the swap fee is capped at 1_000_000 (100%) for cl pool and 100_000 (10%) for bin pool
/// @param self The single direction protocol fee to calculate the swap fee from
/// @param lpFee The LP fee to calculate the swap fee from
/// @return swapFee The composite swap fee
function calculateSwapFee(uint16 self, uint24 lpFee) internal pure returns (uint24 swapFee) {
// protocolFee + lpFee - (protocolFee * lpFee / 1_000_000)
assembly ("memory-safe") {
self := and(self, 0xfff)
lpFee := and(lpFee, 0xffffff)
let numerator := mul(self, lpFee)
swapFee := sub(add(self, lpFee), div(numerator, PIPS_DENOMINATOR))
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @notice Library for handling lp fee setting from `PoolKey.fee`
/// It can be either static or dynamic, and upper 4 bits are used to store the flag:
/// 1. if the flag is set, then the fee is dynamic, it can be set and updated by hook
/// 2. otherwise if the flag is not set, then the fee is static, and the lower 20 bits are used to store the fee
library LPFeeLibrary {
using LPFeeLibrary for uint24;
/// @notice Thrown when the static/dynamic fee on a pool exceeds 100%.
error LPFeeTooLarge(uint24 fee);
/// @notice mask to remove the override fee flag from a fee returned by the beforeSwaphook
uint24 public constant OVERRIDE_MASK = 0xBFFFFF;
/// @notice a dynamic fee pool must have exactly same value for fee field
uint24 public constant DYNAMIC_FEE_FLAG = 0x800000;
/// @notice the second bit of the fee returned by beforeSwap is used to signal if the stored LP fee should be overridden in this swap
// only dynamic-fee pools can return a fee via the beforeSwap hook
uint24 public constant OVERRIDE_FEE_FLAG = 0x400000;
/// @notice the fee is represented in hundredths of a bip
/// max fee varies between different pool types i.e. it's 100% for cl pool and 10% for bin pool
uint24 public constant ONE_HUNDRED_PERCENT_FEE = 1_000_000;
uint24 public constant TEN_PERCENT_FEE = 100_000;
/// @notice returns true if a pool's LP fee signals that the pool has a dynamic fee
/// @param self The fee to check
/// @return bool True of the fee is dynamic
function isDynamicLPFee(uint24 self) internal pure returns (bool) {
return self == DYNAMIC_FEE_FLAG;
}
/// @notice validates whether an LP fee is larger than the maximum, and reverts if invalid
/// @param self The fee to validate
/// @param maxFee The maximum fee allowed for the pool
function validate(uint24 self, uint24 maxFee) internal pure {
if (self > maxFee) revert LPFeeTooLarge(self);
}
/// @notice gets the initial LP fee for a pool. Dynamic fee pools have an initial fee of 0.
/// @dev if a dynamic fee pool wants a non-0 initial fee, it should call `updateDynamicLPFee` in the afterInitialize hook
/// @param self The fee to get the initial LP from
/// @return initialFee 0 if the fee is dynamic, otherwise the original value
function getInitialLPFee(uint24 self) internal pure returns (uint24 initialFee) {
// the initial fee for a dynamic fee pool is 0
if (self.isDynamicLPFee()) return 0;
initialFee = self;
}
/// @notice returns true if the fee has the override flag set (2nd highest bit of the uint24)
/// @param self The fee to check
/// @return bool True of the fee has the override flag set
function isOverride(uint24 self) internal pure returns (bool) {
return self & OVERRIDE_FEE_FLAG != 0;
}
/// @notice returns a fee with the override flag removed
/// @param self The fee to remove the override flag from
/// @return fee The fee without the override flag set
function removeOverrideFlag(uint24 self) internal pure returns (uint24) {
return self & OVERRIDE_MASK;
}
/// @notice Removes the override flag and validates the fee (reverts if the fee is too large)
/// @param self The fee to remove the override flag from, and then validate
/// @param maxFee The maximum fee allowed for the pool
/// @return fee The fee without the override flag set (if valid)
function removeOverrideAndValidate(uint24 self, uint24 maxFee) internal pure returns (uint24) {
uint24 fee = self.removeOverrideFlag();
fee.validate(maxFee);
return fee;
}
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "../types/PoolKey.sol";
interface IProtocolFeeController {
/// @notice Get the protocol fee for a pool given the conditions of this contract
/// @param poolKey The pool key to identify the pool. The controller may want to use attributes on the pool
/// to determine the protocol fee, hence the entire key is needed.
/// @return protocolFee The pool's protocol fee, expressed in hundredths of a bip. The upper 12 bits are for 1->0
/// and the lower 12 are for 0->1. The maximum is 4000 - meaning the maximum protocol fee is 0.4%.
/// the protocolFee is taken from the input first, then the lpFee is taken from the remaining input
function protocolFeeForPool(PoolKey memory poolKey) external view returns (uint24 protocolFee);
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice Interface for the callback executed when an address locks the vault
interface ILockCallback {
/// @notice Called by the pool manager on `msg.sender` when a lock is acquired
/// @param data The data that was passed to the call to lock
/// @return Any data that you want to be returned from the lock call
function lockAcquired(bytes calldata data) external returns (bytes memory);
}//SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
import {Currency} from "infinity-core/src/types/Currency.sol";
import {PoolKey} from "infinity-core/src/types/PoolKey.sol";
import {IHooks} from "infinity-core/src/interfaces/IHooks.sol";
import {IPoolManager} from "infinity-core/src/interfaces/IPoolManager.sol";
struct PathKey {
Currency intermediateCurrency;
uint24 fee;
IHooks hooks;
IPoolManager poolManager;
bytes hookData;
bytes32 parameters;
}
using PathKeyLibrary for PathKey global;
library PathKeyLibrary {
/// @notice Get the pool and swap direction for a given PathKey
/// @param params the given PathKey
/// @param currencyIn the input currency
/// @return poolKey the pool key of the swap
/// @return zeroForOne the direction of the swap, true if currency0 is being swapped for currency1
function getPoolAndSwapDirection(PathKey memory params, Currency currencyIn)
internal
pure
returns (PoolKey memory poolKey, bool zeroForOne)
{
(Currency currency0, Currency currency1) = currencyIn < params.intermediateCurrency
? (currencyIn, params.intermediateCurrency)
: (params.intermediateCurrency, currencyIn);
zeroForOne = currencyIn == currency0;
poolKey = PoolKey(currency0, currency1, params.hooks, params.poolManager, params.fee, params.parameters);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Currency} from "infinity-core/src/types/Currency.sol";
import {PoolKey} from "infinity-core/src/types/PoolKey.sol";
import {PathKey} from "../../libraries/PathKey.sol";
import {IImmutableState} from "../../interfaces/IImmutableState.sol";
interface ICLRouterBase is IImmutableState {
/// @notice Parameters for a single-hop exact-input swap
struct CLSwapExactInputSingleParams {
PoolKey poolKey;
bool zeroForOne;
uint128 amountIn;
uint128 amountOutMinimum;
bytes hookData;
}
/// @notice Parameters for a multi-hop exact-input swap
struct CLSwapExactInputParams {
Currency currencyIn;
PathKey[] path;
uint128 amountIn;
uint128 amountOutMinimum;
}
/// @notice Parameters for a single-hop exact-output swap
struct CLSwapExactOutputSingleParams {
PoolKey poolKey;
bool zeroForOne;
uint128 amountOut;
uint128 amountInMaximum;
bytes hookData;
}
/// @notice Parameters for a multi-hop exact-output swap
struct CLSwapExactOutputParams {
Currency currencyOut;
PathKey[] path;
uint128 amountOut;
uint128 amountInMaximum;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {PoolKey} from "infinity-core/src/types/PoolKey.sol";
import {Currency} from "infinity-core/src/types/Currency.sol";
import {PathKey} from "../../libraries/PathKey.sol";
import {IImmutableState} from "../../interfaces/IImmutableState.sol";
interface IBinRouterBase is IImmutableState {
struct BinSwapExactInputSingleParams {
PoolKey poolKey;
bool swapForY;
uint128 amountIn;
uint128 amountOutMinimum;
bytes hookData;
}
struct BinSwapExactInputParams {
Currency currencyIn;
PathKey[] path;
uint128 amountIn;
uint128 amountOutMinimum;
}
struct BinSwapExactOutputSingleParams {
PoolKey poolKey;
bool swapForY;
uint128 amountOut;
uint128 amountInMaximum;
bytes hookData;
}
struct BinSwapExactOutputParams {
Currency currencyOut;
PathKey[] path;
uint128 amountOut;
uint128 amountInMaximum;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
interface IERC1271 {
/// @dev Should return whether the signature provided is valid for the provided data
/// @param hash Hash of the data to be signed
/// @param signature Signature byte array associated with _data
/// @return magicValue The bytes4 magic value 0x1626ba7e
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice This interface is used for an EIP712 implementation
interface IEIP712 {
/// @notice Returns the domain separator for the current chain.
/// @dev Uses cached version if chainid is unchanged from construction.
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.0;
/// @title BitMath
/// @dev This library provides functionality for computing bit properties of an unsigned integer
/// @author Solady (https://github.com/Vectorized/solady/blob/8200a70e8dc2a77ecb074fc2e99a2a0d36547522/src/utils/LibBit.sol)
library BitMath {
/// @notice Returns the index of the most significant bit of the number,
/// where the least significant bit is at index 0 and the most significant bit is at index 255
/// @param x the value for which to compute the most significant bit, must be greater than 0
/// @return r the index of the most significant bit
function mostSignificantBit(uint256 x) internal pure returns (uint8 r) {
require(x > 0);
assembly ("memory-safe") {
r := or(shl(8, iszero(x)), shl(7, lt(0xffffffffffffffffffffffffffffffff, x)))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// forgefmt: disable-next-item
r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
0x0706060506020504060203020504030106050205030304010505030400000000))
}
}
/// @notice Returns the index of the least significant bit of the number,
/// where the least significant bit is at index 0 and the most significant bit is at index 255
/// @param x the value for which to compute the least significant bit, must be greater than 0
/// @return r the index of the least significant bit
function leastSignificantBit(uint256 x) internal pure returns (uint8 r) {
require(x > 0);
assembly ("memory-safe") {
// Isolate the least significant bit.
x := and(x, add(not(x), 1))
// For the upper 3 bits of the result, use a De Bruijn-like lookup.
// Credit to adhusson: https://blog.adhusson.com/cheap-find-first-set-evm/
// forgefmt: disable-next-item
r := shl(5, shr(252, shl(shl(2, shr(250, mul(x,
0xb6db6db6ddddddddd34d34d349249249210842108c6318c639ce739cffffffff))),
0x8040405543005266443200005020610674053026020000107506200176117077)))
// For the lower 5 bits of the result, use a De Bruijn lookup.
// forgefmt: disable-next-item
r := or(r, byte(and(div(0xd76453e0, shr(r, x)), 0x1f),
0x001f0d1e100c1d070f090b19131c1706010e11080a1a141802121b1503160405))
}
}
}{
"remappings": [
"infinity-core/=lib/infinity-core/",
"ds-test/=lib/infinity-core/lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/infinity-core/lib/forge-std/src/",
"openzeppelin-contracts/=lib/infinity-core/lib/openzeppelin-contracts/",
"solmate/=lib/infinity-core/lib/solmate/",
"permit2/=lib/permit2/",
"@openzeppelin/=lib/infinity-core/lib/openzeppelin-contracts/",
"@openzeppelin/contracts/=lib/infinity-core/lib/openzeppelin-contracts/contracts/",
"erc4626-tests/=lib/infinity-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/infinity-core/lib/forge-gas-snapshot/src/",
"halmos-cheatcodes/=lib/infinity-core/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"pancake-create3-factory/=lib/pancake-create3-factory/"
],
"optimizer": {
"enabled": true,
"runs": 9000
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": true,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IVault","name":"_vault","type":"address"},{"internalType":"contract ICLPoolManager","name":"_clPoolManager","type":"address"},{"internalType":"contract IAllowanceTransfer","name":"_permit2","type":"address"},{"internalType":"uint256","name":"_unsubscribeGasLimit","type":"uint256"},{"internalType":"contract ICLPositionDescriptor","name":"_tokenDescriptor","type":"address"},{"internalType":"contract IWETH9","name":"_weth9","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"subscriber","type":"address"}],"name":"AlreadySubscribed","type":"error"},{"inputs":[{"internalType":"address","name":"subscriber","type":"address"},{"internalType":"bytes","name":"reason","type":"bytes"}],"name":"BurnNotificationReverted","type":"error"},{"inputs":[],"name":"ContractLocked","type":"error"},{"inputs":[{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"DeadlinePassed","type":"error"},{"inputs":[{"internalType":"Currency","name":"currency","type":"address"}],"name":"DeltaNotNegative","type":"error"},{"inputs":[{"internalType":"Currency","name":"currency","type":"address"}],"name":"DeltaNotPositive","type":"error"},{"inputs":[],"name":"GasLimitTooLow","type":"error"},{"inputs":[],"name":"InputLengthMismatch","type":"error"},{"inputs":[],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"InvalidContractSignature","type":"error"},{"inputs":[],"name":"InvalidEthSender","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"InvalidSignatureLength","type":"error"},{"inputs":[],"name":"InvalidSigner","type":"error"},{"inputs":[{"internalType":"int24","name":"tick","type":"int24"}],"name":"InvalidTick","type":"error"},{"inputs":[],"name":"InvalidTokenID","type":"error"},{"inputs":[{"internalType":"uint128","name":"maximumAmount","type":"uint128"},{"internalType":"uint128","name":"amountRequested","type":"uint128"}],"name":"MaximumAmountExceeded","type":"error"},{"inputs":[{"internalType":"uint128","name":"minimumAmount","type":"uint128"},{"internalType":"uint128","name":"amountReceived","type":"uint128"}],"name":"MinimumAmountInsufficient","type":"error"},{"inputs":[{"internalType":"address","name":"subscriber","type":"address"},{"internalType":"bytes","name":"reason","type":"bytes"}],"name":"ModifyLiquidityNotificationReverted","type":"error"},{"inputs":[],"name":"NoCodeSubscriber","type":"error"},{"inputs":[],"name":"NoSelfPermit","type":"error"},{"inputs":[],"name":"NonceAlreadyUsed","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"NotApproved","type":"error"},{"inputs":[],"name":"NotSubscribed","type":"error"},{"inputs":[],"name":"NotVault","type":"error"},{"inputs":[],"name":"SafeCastOverflow","type":"error"},{"inputs":[],"name":"SignatureDeadlineExpired","type":"error"},{"inputs":[{"internalType":"address","name":"subscriber","type":"address"},{"internalType":"bytes","name":"reason","type":"bytes"}],"name":"SubscriptionReverted","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[{"internalType":"uint256","name":"action","type":"uint256"}],"name":"UnsupportedAction","type":"error"},{"inputs":[],"name":"VaultMustBeUnlocked","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"MintPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"int256","name":"liquidityChange","type":"int256"},{"indexed":false,"internalType":"BalanceDelta","name":"feesAccrued","type":"int256"}],"name":"ModifyLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"subscriber","type":"address"}],"name":"Subscription","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"subscriber","type":"address"}],"name":"Unsubscription","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"contract IWETH9","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"clPoolManager","outputs":[{"internalType":"contract ICLPoolManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getPoolAndPositionInfo","outputs":[{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"contract IHooks","name":"hooks","type":"address"},{"internalType":"contract IPoolManager","name":"poolManager","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"bytes32","name":"parameters","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"CLPositionInfo","name":"info","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getPositionLiquidity","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"contract IHooks","name":"hooks","type":"address"},{"internalType":"contract IPoolManager","name":"poolManager","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"bytes32","name":"parameters","type":"bytes32"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"name":"initializePool","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"lockAcquired","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"modifyLiquidities","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"actions","type":"bytes"},{"internalType":"bytes[]","name":"params","type":"bytes[]"}],"name":"modifyLiquiditiesWithoutLock","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"msgSender","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextTokenId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"word","type":"uint256"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"bitmap","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"owner","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"permit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"uint48","name":"expiration","type":"uint48"},{"internalType":"uint48","name":"nonce","type":"uint48"}],"internalType":"struct IAllowanceTransfer.PermitDetails","name":"details","type":"tuple"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"sigDeadline","type":"uint256"}],"internalType":"struct IAllowanceTransfer.PermitSingle","name":"permitSingle","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"permit","outputs":[{"internalType":"bytes","name":"err","type":"bytes"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"permit2","outputs":[{"internalType":"contract IAllowanceTransfer","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint160","name":"amount","type":"uint160"},{"internalType":"uint48","name":"expiration","type":"uint48"},{"internalType":"uint48","name":"nonce","type":"uint48"}],"internalType":"struct IAllowanceTransfer.PermitDetails[]","name":"details","type":"tuple[]"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"sigDeadline","type":"uint256"}],"internalType":"struct IAllowanceTransfer.PermitBatch","name":"_permitBatch","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"permitBatch","outputs":[{"internalType":"bytes","name":"err","type":"bytes"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"permitForAll","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes25","name":"poolId","type":"bytes25"}],"name":"poolKeys","outputs":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"contract IHooks","name":"hooks","type":"address"},{"internalType":"contract IPoolManager","name":"poolManager","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"bytes32","name":"parameters","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"positionInfo","outputs":[{"internalType":"CLPositionInfo","name":"info","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"positions","outputs":[{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"contract IHooks","name":"hooks","type":"address"},{"internalType":"contract IPoolManager","name":"poolManager","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"bytes32","name":"parameters","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"feeGrowthInside0LastX128","type":"uint256"},{"internalType":"uint256","name":"feeGrowthInside1LastX128","type":"uint256"},{"internalType":"contract ICLSubscriber","name":"_subscriber","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"registerMe","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"revokeNonce","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"newSubscriber","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"subscribe","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"subscriber","outputs":[{"internalType":"contract ICLSubscriber","name":"subscriber","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenDescriptor","outputs":[{"internalType":"contract ICLPositionDescriptor","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"unsubscribe","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"unsubscribeGasLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"contract IVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
6101a080604052346105365760c08161640a8038038091610020828561053a565b8339810103126105365780516001600160a01b0381168103610536576020820151906001600160a01b03821682036105365760408301516001600160a01b03811681036105365760608401516080850151946001600160a01b03861686036105365760a00151926001600160a01b0384168403610536576040516100a560408261053a565b6012815260208101907114dbd91848141bdcda5d1a5bdb9cc813919560721b82526040516100d460408261053a565b6009815268534f44412d504f534d60b81b602082015281516001600160401b03811161044a575f54600181811c9116801561052c575b602082101461042c57601f81116104ca575b50806020601f8211600114610469575f9161045e575b508160011b915f199060031b1c1916175f555b8051906001600160401b03821161044a5760015490600182811c92168015610440575b602083101461042c5781601f8493116103be575b50602090601f8311600114610358575f9261034d575b50508160011b915f199060031b1c1916176001555b5190208060c0524660a05260405160208101917f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a86683526040820152466060820152306080820152608081526101fd60a08261053a565b51902060805260e05261010052610120526101405260016008556101605261018052604051615eac908161055e823960805181612adb015260a05181612ab5015260c05181612b2a015260e0518181816086015281816102a2015281816104f80152818161079f01528181610b9a01528181610e000152818161171701528181611c030152818161209f0152818161424a0152818161431d015281816146fe015281816147d901528181615022015261534a0152610100518181816116ac0152613584015261012051818181611f16015281816122ef015281816126ca01526149360152610140518181816024015281816116700152818161442c01526144c90152610160518181816110cc015281816119fd01528181612c46015281816134090152818161396d01528181613bcc01528181613fe2015261598201526101805181818161067201526115ea0152f35b015190505f80610192565b60015f9081528281209350601f198516905b8181106103a6575090846001959493921061038e575b505050811b016001556101a7565b01515f1960f88460031b161c191690555f8080610380565b9293602060018192878601518155019501930161036a565b60015f529091507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6601f840160051c81019160208510610422575b90601f859493920160051c01905b818110610414575061017c565b5f8155849350600101610407565b90915081906103f9565b634e487b7160e01b5f52602260045260245ffd5b91607f1691610168565b634e487b7160e01b5f52604160045260245ffd5b90508301515f610132565b5f8080528181209250601f198416905b8181106104b25750908360019493921061049a575b5050811b015f55610145565b8501515f1960f88460031b161c191690555f8061048e565b9192602060018192868a015181550194019201610479565b5f80527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563601f830160051c81019160208410610522575b601f0160051c01905b818110610517575061011c565b5f815560010161050a565b9091508190610501565b90607f169061010a565b5f80fd5b601f909101601f19168101906001600160401b0382119082101761044a5760405256fe60808060405260043610156100ae575b50361561001a575f80fd5b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163314158061007b575b61005357005b7f38bbd576000000000000000000000000000000000000000000000000000000005f5260045ffd5b506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001633141561004d565b5f905f3560e01c9081622a3e3a146126655750806301ffc9a71461259257806305c1ee201461257957806306fdde03146124db578063081812fc146124a8578063095ea7b3146124095780630f5730f11461231357806312261ee7146122cf57806316a241311461229c5780631efeed331461224a57806323b872dd146120585780632b67b57014611eb05780632b9261de14611b935780633644e51514611b705780633aea60f014611a605780633fd40e5614611a2157806340679361146119dd57806342842e0e146116cf5780634767565f146116945780634aa4a4fc14611650578063502e1a161461160e5780635a9d7a68146115ca5780636352211e1461159a57806370a08231146114fd57806375794a3c146114df5780637ba03aad1461145157806386b6be7d1461139d57806389097a6a1461137357806395d89b411461122f57806399fbab88146110345780639a198d6114610f57578063a22cb46514610f27578063ab6291fe14610dc2578063ac9650d814610c6e578063ad0b27fb14610b54578063b88d4fde1461071f578063c87b56dd1461061c578063d737d0c7146105d6578063dd46508f1461041f578063e985e9c5146103cc578063eb80d35e146102c95763fbfa77cf0361000f57346102c657806003193601126102c65760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b80fd5b5060406003193601126102c65760043567ffffffffffffffff81116103c8576102f69036906004016128cf565b60249291923567ffffffffffffffff81116103c4576103199036906004016129e4565b916001600160a01b037f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c1661039c576103769394337f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5d6137b3565b807f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5d80f35b6004847f6f5ffb7e000000000000000000000000000000000000000000000000000000008152fd5b8280fd5b5080fd5b50346102c65760406003193601126102c6576001600160a01b0360406103f061288f565b92826103fa6128a5565b9416815260056020522091165f52602052602060ff60405f2054166040519015158152f35b5060406003193601126102c65760043567ffffffffffffffff81116103c85761044c9036906004016128cf565b6024356001600160a01b037f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c1661039c57337f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5d8042116105ab57506104eb91839160405193849283927f81548319000000000000000000000000000000000000000000000000000000008452602060048501526024840191612a28565b0381836001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165af180156105a05761054c575b50807f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5d80f35b3d8083833e61055b8183612987565b8101906020818303126103c45780519067ffffffffffffffff821161059c57019080601f830112156103c457815161059592602001612fd8565b505f610525565b8380fd5b6040513d84823e3d90fd5b7fbfb22adf000000000000000000000000000000000000000000000000000000008452600452602483fd5b50346102c657806003193601126102c65760207f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c6001600160a01b0360405191168152f35b50346102c65760206003193601126102c657604051907fe9dc6375000000000000000000000000000000000000000000000000000000008252306004830152600435602483015280826044816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa9081156107135780916106bc575b604051602080825281906106b8908201856128fd565b0390f35b90503d8082843e6106cd8184612987565b8201916020818403126103c85780519067ffffffffffffffff82116103c457019082601f830112156102c657506106b89181602061070d93519101612fd8565b5f6106a2565b604051903d90823e3d90fd5b50346102c65760806003193601126102c65761073961288f565b6107416128a5565b906044359160643567ffffffffffffffff8111610b50576107669036906004016128cf565b9190936040517f5d4e0ced0000000000000000000000000000000000000000000000000000000081526020816004816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa8015610b45576001600160a01b03918891610b16575b5016610aee5780865260026020526001600160a01b03806040882054169416938403610a90576001600160a01b03821691610813831515613477565b8433148015610a67575b8015610a49575b156109eb5786908582526003602052604082205f198154019055838252600360205260408220600181540190558282526002602052604082208473ffffffffffffffffffffffffffffffffffffffff1982541617905582825260046020526040822073ffffffffffffffffffffffffffffffffffffffff1981541690558284877fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8580a48282526009602052604082205460ff166109dd575b3b159485156108f4575b506108f185612cf4565b80f35b60209550610949604051978896879586947f150b7a0200000000000000000000000000000000000000000000000000000000865233600487015260248601526044850152608060648501526084840191612a28565b03925af180156105a0577fffffffff000000000000000000000000000000000000000000000000000000007f150b7a0200000000000000000000000000000000000000000000000000000000916108f19385916109ae575b5016145f808085816108e7565b6109d0915060203d6020116109d6575b6109c88183612987565b810190612cbc565b5f6109a1565b503d6109be565b6109e6836134dc565b6108dd565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f4e4f545f415554484f52495a45440000000000000000000000000000000000006044820152fd5b5081875260046020526001600160a01b036040882054163314610824565b508487526005602052604087206001600160a01b0333165f5260205260ff60405f20541661081d565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f57524f4e475f46524f4d000000000000000000000000000000000000000000006044820152fd5b6004867f07f5f526000000000000000000000000000000000000000000000000000000008152fd5b610b38915060203d602011610b3e575b610b308183612987565b810190612a93565b5f6107d7565b503d610b26565b6040513d89823e3d90fd5b8480fd5b5060206003193601126102c6576004356040517f5d4e0ced0000000000000000000000000000000000000000000000000000000081526020816004816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa8015610c63576001600160a01b03918491610c44575b5016610c1c57610be28133613677565b15610bf0576108f1906134dc565b6024827f0ca968d800000000000000000000000000000000000000000000000000000000815233600452fd5b6004827f07f5f526000000000000000000000000000000000000000000000000000000008152fd5b610c5d915060203d602011610b3e57610b308183612987565b5f610bd2565b6040513d85823e3d90fd5b5060206003193601126102c65760043567ffffffffffffffff81116103c857610c9b9036906004016129e4565b90610ca582612f1f565b91610cb36040519384612987565b808352601f19610cc282612f1f565b01845b818110610db1575050835b818110610d5a5783856040519182916020830160208452825180915260408401602060408360051b870101940192905b828210610d0f57505050500390f35b91936020610d4a827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0600195979984950301865288516128fd565b9601920192018594939192610d00565b8480610d67838587612f37565b9081604051928392833781018381520390305af4610d83612a64565b9015610da95790600191610d978287612fc4565b52610da28186612fc4565b5001610cd0565b602081519101fd5b806060602080938801015201610cc5565b50346102c65760206003193601126102c65760043567ffffffffffffffff81116103c857610df49036906004016128cf565b91906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163303610eff5760408135189263ffffffff6040830135169063ffffffe0601f8301169460608601602085013518179483019460608601359184641fffffffe08460051b16888189905b808210610ecd5750500160800191011017610ec057916106b894916060608063ffffffff610e9b9616940192016137b3565b60405190610eaa602083612987565b81526040519182916020835260208301906128fd565b633b99b53d84526004601cfd5b9281945063ffffffe0601f608085998160209796889701013590858218179a0101350116010192018990889392610e69565b6004827f62df0545000000000000000000000000000000000000000000000000000000008152fd5b50346102c65760406003193601126102c657610f4161288f565b60243580151581036103c4576108f19133613734565b50346102c657806003193601126102c657808060405160208101907f1e60fd14000000000000000000000000000000000000000000000000000000008252609e602482015260248152610fab604482612987565b51908273dc2b0d2dd2b7759d97d50db4eabdc369731108305af1610fcd612a64565b5015610fd65780f35b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4665654d20726567697374726174696f6e206661696c656400000000000000006044820152fd5b50346102c65760206003193601126102c657600435611051612de1565b5061105b81612e11565b909160c083208215611207576040517f7388426b0000000000000000000000000000000000000000000000000000000081526004810191909152306024820152600883901c600290810b6044830181905260209490941c900b6064820181905260848201839052909460608660a4817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9182156111fa576101809682936111c9575b506001600160a01b0360406fffffffffffffffffffffffffffffffff855116938160208701519601519681526007602052205416946111a5604051809860a080916001600160a01b0381511684526001600160a01b0360208201511660208501526001600160a01b0360408201511660408501526001600160a01b03606082015116606085015262ffffff60808201511660808501520151910152565b60c087015260e0860152610100850152610120840152610140830152610160820152f35b6111ec91935060603d6060116111f3575b6111e48183612987565b810190612ec1565b915f611108565b503d6111da565b50604051903d90823e3d90fd5b6004857f6aa2a937000000000000000000000000000000000000000000000000000000008152fd5b50346102c657806003193601126102c6576040519080600154908160011c91600181168015611369575b60208410811461133c578386529081156112f7575060011461129a575b6106b88461128681860382612987565b6040519182916020835260208301906128fd565b600181527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6939250905b8082106112dd5750909150810160200161128682611276565b9192600181602092548385880101520191019092916112c4565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660208087019190915292151560051b850190920192506112869150839050611276565b6024837f4e487b710000000000000000000000000000000000000000000000000000000081526022600452fd5b92607f1692611259565b50346102c65760206003193601126102c65760406020916004358152600983522054604051908152f35b50346102c65760206003193601126102c6576004357fffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000081168091036103c8578160409160c09352600a602052206001600160a01b038154169062ffffff6001600160a01b03600183015416916001600160a01b036002820154166004600383015492015493604051958652602086015260408501526001600160a01b038116606085015260a01c16608083015260a0820152f35b50346102c65760206003193601126102c65760e0611470600435612e11565b6114d8604051809360a080916001600160a01b0381511684526001600160a01b0360208201511660208501526001600160a01b0360408201511660408501526001600160a01b03606082015116606085015262ffffff60808201511660808501520151910152565b60c0820152f35b50346102c657806003193601126102c6576020600854604051908152f35b50346102c65760206003193601126102c6576001600160a01b0361151f61288f565b16801561153c578160409160209352600383522054604051908152f35b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f5a45524f5f4144445245535300000000000000000000000000000000000000006044820152fd5b50346102c65760206003193601126102c65760206115b9600435612dbe565b6001600160a01b0360405191168152f35b50346102c657806003193601126102c65760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346102c65760406003193601126102c65760406020916001600160a01b0361163561288f565b16815260068352818120602435825283522054604051908152f35b50346102c657806003193601126102c65760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346102c657806003193601126102c65760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346102c6576116de366129aa565b6040929192517f5d4e0ced0000000000000000000000000000000000000000000000000000000081526020816004816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa80156119d2576001600160a01b039186916119b3575b501661198b5780845260026020526001600160a01b03806040862054169216918203610a90576001600160a01b0383169261178b841515613477565b8233148015611962575b8015611944575b156109eb578285526003602052604085205f198154019055838552600360205260408520600181540190558185526002602052604085208473ffffffffffffffffffffffffffffffffffffffff1982541617905581855260046020526040852073ffffffffffffffffffffffffffffffffffffffff1981541690558184847fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8880a48185526009602052604085205460ff16611936575b3b15918215611867575b846108f184612cf4565b6020925060a4908560405195869485937f150b7a0200000000000000000000000000000000000000000000000000000000855233600486015260248501526044840152608060648401528160848401525af180156105a0577fffffffff000000000000000000000000000000000000000000000000000000007f150b7a0200000000000000000000000000000000000000000000000000000000916108f1938591611917575b5016145f8061185d565b611930915060203d6020116109d6576109c88183612987565b5f61190d565b61193f826134dc565b611853565b5081855260046020526001600160a01b03604086205416331461179c565b508285526005602052604085206001600160a01b0333165f5260205260ff60405f205416611795565b6004847f07f5f526000000000000000000000000000000000000000000000000000000008152fd5b6119cc915060203d602011610b3e57610b308183612987565b5f61174f565b6040513d87823e3d90fd5b50346102c657806003193601126102c65760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b50600319360160e081126103c85760c0136102c65760c435906001600160a01b03821682036102c6576020611a5583612b7d565b6040519060020b8152f35b5060c06003193601126102c657611a7561288f565b90611a7e6128a5565b6044359081151582036103c4576064359360843560a43567ffffffffffffffff8111611b6c57611ab29036906004016128cf565b9096804211611b44578387988493611b33888b611b399681611b3f9a6108f19f8f81604051977f6673cb397ee2a50b6b8401653d3638b4ac8b3db9c28aa6870ffceb7574ec2f7689526001600160a01b0360208a0191168152600160408a019316835260608901948552608089019687528160a08a209952525252526130ce565b91613134565b8261300e565b613734565b6004877f5a9165ff000000000000000000000000000000000000000000000000000000008152fd5b8580fd5b50346102c657806003193601126102c6576020611b8b612ab2565b604051908152f35b5060606003193601126102c657600435611bab6128a5565b9060443567ffffffffffffffff811161059c57611bcc9036906004016128cf565b926040517f5d4e0ced0000000000000000000000000000000000000000000000000000000081526020816004816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa8015611ea5576001600160a01b03918791611e86575b5016611e5e57611c4b8333613677565b15611e325782855260076020526001600160a01b0360408620541680611e02575090611d27918386526009602052600160408720541784875260096020526040872055611d226001600160a01b038216958588526007602052604088206001600160a01b03881673ffffffffffffffffffffffffffffffffffffffff19825416179055611d146040519485927f8d57f6b2000000000000000000000000000000000000000000000000000000006020850152886024850152604060448501526064840191612a28565b03601f198101845283612987565b6136f3565b15611d53577f9709492381f90bdc5938bb4e3b8e35b7e0eac8af058619e27191c5a40ce79fa98380a380f35b5090601f19601f3d011690604051927f90bfb86500000000000000000000000000000000000000000000000000000000845260048401527f8d57f6b2000000000000000000000000000000000000000000000000000000006024840152608060448401528160a00160648401523d60848401523d9060a484013e7f81ea5e9e0000000000000000000000000000000000000000000000000000000060c4828401600460a4820152015260e40190fd5b85604491857f25fbd8be000000000000000000000000000000000000000000000000000000008352600452602452fd5b6024857f0ca968d800000000000000000000000000000000000000000000000000000000815233600452fd5b6004857f07f5f526000000000000000000000000000000000000000000000000000000008152fd5b611e9f915060203d602011610b3e57610b308183612987565b5f611c3b565b6040513d88823e3d90fd5b506101006003193601126102c657611ec661288f565b60c07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc3601126103c85760e43567ffffffffffffffff81116103c457611f109036906004016128cf565b606093917f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031691823b1561059c576001600160a01b03604051957f2b67b5700000000000000000000000000000000000000000000000000000000087521660048601526024356001600160a01b038116809103610b505760248601526044356001600160a01b038116809103610b5057604486015260643565ffffffffffff8116809103610b5057606486015260843565ffffffffffff8116809103610b5057608486015260a4356001600160a01b038116809103610b5057848661201d8195839795839560a485015260c43560c485015261010060e4850152610104840191612a28565b03925af19182612043575b505061203a57506106b8611286612a64565b6106b890611286565b61204e828092612987565b6102c65780612028565b50346102c657612067366129aa565b91906040517f5d4e0ced0000000000000000000000000000000000000000000000000000000081526020816004816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa80156119d2576001600160a01b0391869161222b575b501661198b5782845260026020526001600160a01b03806040862054169216918203610a90576001600160a01b0316612111811515613477565b8133148015612202575b80156121e4575b156109eb5781839285526003602052604085205f198154019055818552600360205260408520600181540190558285526002602052604085208273ffffffffffffffffffffffffffffffffffffffff1982541617905582855260046020526040852073ffffffffffffffffffffffffffffffffffffffff1981541690557fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8580a48082526009602052604082205460ff166121db575080f35b6108f1906134dc565b5082845260046020526001600160a01b036040852054163314612122565b508184526005602052604084206001600160a01b0333165f5260205260ff60405f20541661211b565b612244915060203d602011610b3e57610b308183612987565b5f6120d7565b50346102c65760206003193601126102c657602061228260043561226d81612e11565b919082851c60020b9260081c60020b916133b0565b6fffffffffffffffffffffffffffffffff60405191168152f35b50346102c65760206003193601126102c6576001600160a01b036040602092600435815260078452205416604051908152f35b50346102c657806003193601126102c65760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b5060a06003193601126102c65761232861288f565b906024356044359260643560843567ffffffffffffffff8111610b50576123539036906004016128cf565b90958042116123e15791611b398587986123dc94611b33888b80996108f19d8961237c89612dbe565b9c8d9981604051977f49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad89526001600160a01b0360208a01911681526040890192835260608901948552608089019687528160a08a209952525252526130ce565b61306f565b6004867f5a9165ff000000000000000000000000000000000000000000000000000000008152fd5b50346102c65760406003193601126102c65761242361288f565b9060243580825260026020526001600160a01b0360408320541692833314158061247e575b612456576108f1929361306f565b6004837f82b42900000000000000000000000000000000000000000000000000000000008152fd5b508383526005602052604083206001600160a01b0333165f5260205260ff60405f20541615612448565b50346102c65760206003193601126102c6576001600160a01b036040602092600435815260048452205416604051908152f35b50346102c657806003193601126102c65760405190808054908160011c9160018116801561256f575b60208410811461133c578386529081156112f75750600114612530576106b88461128681860382612987565b80805260208120939250905b8082106125555750909150810160200161128682611276565b91926001816020925483858801015201910190929161253c565b92607f1692612504565b5060206003193601126102c6576108f16004353361300e565b50346102c65760206003193601126102c6576004357fffffffff0000000000000000000000000000000000000000000000000000000081168091036103c857807f01ffc9a7000000000000000000000000000000000000000000000000000000006020921490811561263b575b8115612611575b506040519015158152f35b7f5b5e139f0000000000000000000000000000000000000000000000000000000091501482612606565b7f80ac58cd00000000000000000000000000000000000000000000000000000000811491506125ff565b606060031936011261288b5761267961288f565b906024359167ffffffffffffffff831161288b57823603606060031982011261288b5760443567ffffffffffffffff811161288b576126bc9036906004016128cf565b906060956001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001694853b1561288b576001600160a01b03907f2a2d80d100000000000000000000000000000000000000000000000000000000885216600487015286602487015260c48601937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdd8260040135910181121561288b5781016024600482013591019467ffffffffffffffff821161288b578160071b3603861361288b5760648801899052819052869460e48601949392915f5b8a82821061281357505050506127e75f9694869488946044856001600160a01b036127c960248b99016128bb565b166084880152013560a4860152600319858403016044860152612a28565b03925af19081612803575b5061203a57506106b8611286612a64565b5f61280d91612987565b5f6127f2565b8398506001929495969765ffffffffffff6128756080949693826128686040876001600160a01b036128458b9a6128bb565b1688526001600160a01b0361285c602083016128bb565b16602089015201612a15565b1660408501528c01612a15565b168d82015201970191019188969594939261279b565b5f80fd5b600435906001600160a01b038216820361288b57565b602435906001600160a01b038216820361288b57565b35906001600160a01b038216820361288b57565b9181601f8401121561288b5782359167ffffffffffffffff831161288b576020838186019501011161288b57565b90601f19601f602080948051918291828752018686015e5f8582860101520116010190565b60c0810190811067ffffffffffffffff82111761293e57604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6080810190811067ffffffffffffffff82111761293e57604052565b90601f601f19910116810190811067ffffffffffffffff82111761293e57604052565b600319606091011261288b576004356001600160a01b038116810361288b57906024356001600160a01b038116810361288b579060443590565b9181601f8401121561288b5782359167ffffffffffffffff831161288b576020808501948460051b01011161288b57565b359065ffffffffffff8216820361288b57565b601f8260209493601f1993818652868601375f8582860101520116010190565b67ffffffffffffffff811161293e57601f01601f191660200190565b3d15612a8e573d90612a7582612a48565b91612a836040519384612987565b82523d5f602084013e565b606090565b9081602091031261288b57516001600160a01b038116810361288b5790565b467f000000000000000000000000000000000000000000000000000000000000000003612afd577f000000000000000000000000000000000000000000000000000000000000000090565b60405160208101907f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a86682527f0000000000000000000000000000000000000000000000000000000000000000604082015246606082015230608082015260808152612b6960a082612987565b51902090565b51908160020b820361288b57565b604051907f8b0c1b220000000000000000000000000000000000000000000000000000000082526004356001600160a01b03811680910361288b5760048301526024356001600160a01b03811680910361288b5760248301526044356001600160a01b03811680910361288b5760448301526064356001600160a01b03811680910361288b5760648301526084359062ffffff821680920361288b576001600160a01b0391608484015260a43560a48401521660c482015260208160e4815f6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165af15f9181612c80575b50612c7d5750627fffff90565b90565b9091506020813d602011612cb4575b81612c9c60209383612987565b8101031261288b57612cad90612b6f565b905f612c70565b3d9150612c8f565b9081602091031261288b57517fffffffff000000000000000000000000000000000000000000000000000000008116810361288b5790565b15612cfb57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f554e534146455f524543495049454e54000000000000000000000000000000006044820152fd5b15612d6057565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f4e4f545f4d494e544544000000000000000000000000000000000000000000006044820152fd5b5f5260026020526001600160a01b0360405f20541690612ddf821515612d59565b565b60405190612dee82612922565b5f60a0838281528260208201528260408201528260608201528260808201520152565b612e19612de1565b505f52600960205260405f2054807fffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000165f52600a60205260405f20600460405191612e6383612922565b6001600160a01b0381541683526001600160a01b0360018201541660208401526001600160a01b03600282015416604084015262ffffff60038201546001600160a01b038116606086015260a01c166080840152015460a082015291565b9081606091031261288b57604051906060820182811067ffffffffffffffff82111761293e576040528051906fffffffffffffffffffffffffffffffff8216820361288b576040918352602081015160208401520151604082015290565b67ffffffffffffffff811161293e5760051b60200190565b9190811015612f975760051b810135907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18136030182121561288b57019081359167ffffffffffffffff831161288b57602001823603811361288b579190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b8051821015612f975760209160051b010190565b929192612fe482612a48565b91612ff26040519384612987565b82948184528183011161288b578281602093845f96015e010152565b906001600160a01b03600160ff83161b92165f52600660205260405f209060081c5f5260205260405f2081815418809155161561304757565b7f1fb09b80000000000000000000000000000000000000000000000000000000005f5260045ffd5b906001600160a01b038091845f52600460205260405f2082821673ffffffffffffffffffffffffffffffffffffffff198254161790551691167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9255f80a4565b906130d7612ab2565b91604051927f19010000000000000000000000000000000000000000000000000000000000008452600284015260228301525f604060428420938281528260208201520152565b919082604091031261288b576020823592013590565b833b6132b557604182036132095761314e8282018261311e565b93909260401015612f97576020935f9360ff6040608095013560f81c5b60405194855216868401526040830152606082015282805260015afa156131fe576001600160a01b035f51169081156131d6576001600160a01b0316036131ae57565b7f815e1d64000000000000000000000000000000000000000000000000000000005f5260045ffd5b7f8baa579f000000000000000000000000000000000000000000000000000000005f5260045ffd5b6040513d5f823e3d90fd5b6040820361328d5761321d9181019061311e565b91601b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff84169360ff1c019060ff8211613260576020935f9360ff60809461316b565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b7f4be6321b000000000000000000000000000000000000000000000000000000005f5260045ffd5b9092613309936001600160a01b03602094604051968795869485937f1626ba7e0000000000000000000000000000000000000000000000000000000085526004850152604060248501526044840191612a28565b0392165afa9081156131fe577f1626ba7e00000000000000000000000000000000000000000000000000000000917fffffffff00000000000000000000000000000000000000000000000000000000915f91613391575b50160361336957565b7fb0669cbc000000000000000000000000000000000000000000000000000000005f5260045ffd5b6133aa915060203d6020116109d6576109c88183612987565b5f613360565b60c09091206040517f7388426b0000000000000000000000000000000000000000000000000000000081526004810191909152306024820152600292830b60448201529290910b6064830152608482015260608160a4817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa80156131fe576fffffffffffffffffffffffffffffffff915f91613458575b50511690565b613471915060603d6060116111f3576111e48183612987565b5f613452565b1561347e57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f494e56414c49445f524543495049454e540000000000000000000000000000006044820152fd5b5f90805f5260076020526001600160a01b0360405f20541691821561364f575f82815260096020908152604080832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905560079091529020805473ffffffffffffffffffffffffffffffffffffffff19169055823b613580575b807fa0ebb1de82db929a9153472f37d3a66dbede4436258311ad0f52a35a2c91d15091a3565b5a907f000000000000000000000000000000000000000000000000000000000000000080921061362757833b1561288b575f846024829460405195869384927faf45dd14000000000000000000000000000000000000000000000000000000008452896004850152f16135f5575b905061355a565b505f61360091612987565b7fa0ebb1de82db929a9153472f37d3a66dbede4436258311ad0f52a35a2c91d1505f6135ee565b7fed43c3a6000000000000000000000000000000000000000000000000000000005f5260045ffd5b7f237e6c28000000000000000000000000000000000000000000000000000000005f5260045ffd5b6001600160a01b038061368984612dbe565b1691169081149182156136d3575b82156136a257505090565b6001600160a01b039192506136b690612dbe565b165f52600560205260405f20905f5260205260ff60405f20541690565b8092505f526004602052806001600160a01b0360405f2054161491613697565b803b1561370c57815f92918360208194519301915af190565b7f7c402b21000000000000000000000000000000000000000000000000000000005f5260045ffd5b60206001600160a01b03807f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31931693845f526005835260405f208282165f52835260405f20951515957fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0081541660ff88161790556040519586521693a3565b909291938284036137f4575f5b848110156137ec576001906137e68185016137dc83888b612f37565b913560f81c61381c565b016137c0565b509350505050565b7faaad13f7000000000000000000000000000000000000000000000000000000005f5260045ffd5b90919060068110156140cc57806138d6575061383791614efc565b95949091937f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c6138688382613677565b156138a157509561389c9282613890612ddf989961388861389696612e11565b9290916153ef565b9161590a565b90615406565b615b2f565b6001600160a01b03907f0ca968d8000000000000000000000000000000000000000000000000000000005f521660045260245ffd5b60048103613a4757506138e8916149f9565b7f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a9491949392935c61391a8382613677565b156138a1575061392982612e11565b91909560c0872093604051947fc815641c00000000000000000000000000000000000000000000000000000000865260048601526080856024816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa9384156131fe57612ddf986138906fffffffffffffffffffffffffffffffff613a0f6138969861389c9a5f91613a15575b506139d08660081c60020b61550a565b6139df8760201c60020b61550a565b6139f26001600160a01b038851166152fa565b91613a096001600160a01b0360208a0151166152fa565b9361585d565b166153ef565b613a37915060803d608011613a40575b613a2f8183612987565b810190614b7b565b5050505f6139c0565b503d613a25565b60018103613abf5750613a5991614efc565b95949091937f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c613a8a8382613677565b156138a1575095613aba9282613ab5612ddf9899613890613aad61389697612e11565b9390926153ef565b614694565b615443565b60028103613b36575063ffffffff61018083013516820163ffffffff8135169183602080840193850101910110613b295782613b02610160612ddf950135614640565b9061014081013590610120810135906101008101359060e08101359060c081013590614bd3565b633b99b53d5f526004601cfd5b60058103613c82575060c082013560e08301359063ffffffff6101608501351684019163ffffffff8335169385602080860195870101910110613b2957613b81610140860135614640565b9160c0613b8e3688614af2565b2095604051967fc815641c00000000000000000000000000000000000000000000000000000000885260048801526080876024816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa9283156131fe57612ddf975f94613c5e575b50613c0a8361550a565b926fffffffffffffffffffffffffffffffff613c57613c288461550a565b96613c3a613c3587614bbf565b6152fa565b6101208701359861010088013598613a09613c3560208b01614bbf565b1692614bd3565b613c7891945060803d608011613a4057613a2f8183612987565b505050925f613c00565b929160038414613cbb575050505b7f5cda29d7000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b613cc69293506149f9565b939190927f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c613cf68482613677565b156138a15750613d0583612e11565b9490918560081c60020b938660201c60020b946fffffffffffffffffffffffffffffffff613d358783888b6133b0565b1694613d4088612dbe565b99885f5260096020525f6040812055885f526002602052885f6001600160a01b03604082205416613d72811515612d59565b8082526003602052604082205f19815401905582825260026020526040822073ffffffffffffffffffffffffffffffffffffffff19815416905582825260046020526040822073ffffffffffffffffffffffffffffffffffffffff1981541690557fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8280a45f9787613f6c575b505050505050508360ff16613e16575b5050505050565b613eb293835f5260076020526001600160a01b038060405f20541696855f52600760205260405f2073ffffffffffffffffffffffffffffffffffffffff198154169055604051957fb1a9116f00000000000000000000000000000000000000000000000000000000602088015260248701521660448501526064840152608483015260a482015260a48152613eac60c482612987565b826136f3565b15613ec05780808080613e0f565b601f19601f3d0116604051917f90bfb86500000000000000000000000000000000000000000000000000000000835260048301527fb1a9116f000000000000000000000000000000000000000000000000000000006024830152608060448301528060a00160648301523d60848301523d5f60a484013e7face944810000000000000000000000000000000000000000000000000000000060c4828401600460a4820152015260e40190fd5b6040949596985090613fd591613f84613ab58a6153ef565b90865195613f918761296b565b8652602086015285850152896060850152845198899485947f9371d11500000000000000000000000000000000000000000000000000000000865260048601614a4b565b03815f6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165af19081156131fe5785925f955f9361406f575b509161404b6040927f547f338f02d501a923ee4865857cad34ce600348ee714b1968240d63259bb02e94613aba84809a615406565b614057613ab5866153ef565b9082519182526020820152a25f808080808080613dff565b60409296507f547f338f02d501a923ee4865857cad34ce600348ee714b1968240d63259bb02e93506140b961404b91843d86116140c5575b6140b18183612987565b810190614a35565b97909794509250614016565b503d6140a7565b919291600d810361412657506140e690612ddf929361462d565b9061411d7f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c918261411782614fd2565b916147c6565b61411782614fd2565b60118103614167575061414d61414361415e92612ddf94956146c0565b9391929093614640565b9182614158826152fa565b916146ec565b614158826152fa565b600b81036141ba575061417e90612ddf92936146c0565b156141af57614117827f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c92614785565b614117823092614785565b600e81036141e757506141e16141d761415892612ddf94956146c0565b9282949291614640565b926146d8565b601281036142ef57506141fa9192614545565b6040517fa54b28310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038216602482015290602082806044810103816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa9182156131fe575f926142bb575b507f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c5f8312156142b157614117612ddf93614694565b612ddf92916146ec565b9091506020813d6020116142e7575b816142d760209383612987565b8101031261288b5751905f61427a565b3d91506142ca565b601381036143cf5750614302919261462d565b9061430c816152fa565b9182116143a2576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690813b1561288b5760446001600160a01b03915f809460405196879586947f80f0b44c00000000000000000000000000000000000000000000000000000000865216600485015260248401525af180156131fe576143985750565b5f612ddf91612987565b90612ddf917f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c906146ec565b6014810361440b57506143e6906143ee929361462d565b919091614640565b6143f7826150cd565b908161440257505050565b612ddf92615128565b92601584036144a15761441f929350614545565b6144536001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001680926145d1565b908161445d575050565b803b1561288b575f906004604051809481937fd0e30db00000000000000000000000000000000000000000000000000000000083525af180156131fe576143985750565b601684146144b157505050613c90565b6144bc929350614545565b6144f06001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169182614551565b806144f9575050565b813b1561288b575f916024839260405194859384927f2e1a7d4d00000000000000000000000000000000000000000000000000000000845260048401525af180156131fe576143985750565b90602011613b29573590565b61455c903090614f3e565b7f800000000000000000000000000000000000000000000000000000000000000082146145cc5781156145bb575b81116145935790565b7ff4d678b8000000000000000000000000000000000000000000000000000000005f5260045ffd5b90506145c65f614fd2565b9061458a565b905090565b906145dc305f614f3e565b907f80000000000000000000000000000000000000000000000000000000000000008314614627578215614615575b5081116145935790565b614620919250614fd2565b905f61460b565b50905090565b9190604011613b29576020823592013590565b6001600160a01b038116600181036146795750507f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c90565b600203612c7d57503090565b9081602091031261288b575190565b7f80000000000000000000000000000000000000000000000000000000000000008114613260575f0390565b90606011613b29578035916040602083013592013590565b90816146e857612c7d91506152fa565b5090565b90918015614780576001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016803b1561288b575f92836064926001600160a01b03948560405198899788967f0b0d9c0900000000000000000000000000000000000000000000000000000000885216600487015216602485015260448401525af180156131fe576143985750565b505050565b907f800000000000000000000000000000000000000000000000000000000000000082036147b757612c7d91506150cd565b816146e857612c7d9150614fd2565b905f9183156149f3576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001691823b1561288b57604051907fa58411940000000000000000000000000000000000000000000000000000000082526001600160a01b038316918260048201525f8160248183895af180156131fe576149de575b50816148c1575050506020906004604051809581937f11da60b40000000000000000000000000000000000000000000000000000000083525af190811561071357506148965750565b6148b79060203d6020116148ba575b6148af8183612987565b810190614685565b50565b503d6148a5565b906001600160a01b038596939216903082145f1461492657505082916020936148e992615128565b6004604051809581937f11da60b40000000000000000000000000000000000000000000000000000000083525af190811561071357506148965750565b9150919293506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690813b15611b6c578592836001600160a01b03959360849360405197889687957f36c7851600000000000000000000000000000000000000000000000000000000875260048701528a602487015216604485015260648401525af18015610c63579083916149c9575b50906020906148e9565b816149d391612987565b6103c857815f6149bf565b6149eb9195505f90612987565b5f935f61484d565b50505050565b919082359260208101359260408201359263ffffffff60608401351683019063ffffffff82351693602080840193860101910110613b29579190565b919082604091031261288b576020825192015190565b6060612c7d9593614aba836101609560a080916001600160a01b0381511684526001600160a01b0360208201511660208501526001600160a01b0360408201511660408501526001600160a01b03606082015116606085015262ffffff60808201511660808501520151910152565b805160020b60c0840152602081015160020b60e084015260408101516101008401520151610120820152816101408201520191612a28565b91908260c091031261288b57604051614b0a81612922565b8092614b15816128bb565b8252614b23602082016128bb565b6020830152614b34604082016128bb565b6040830152614b45606082016128bb565b6060830152608081013562ffffff8116810361288b57608083015260a090810135910152565b519062ffffff8216820361288b57565b919082608091031261288b5781516001600160a01b038116810361288b5791614ba660208201612b6f565b91612c7d6060614bb860408501614b6b565b9301614b6b565b356001600160a01b038116810361288b5790565b90969297939495976001600160a01b036008549960018b016008551692614bfb841515613477565b895f5260026020526001600160a01b0360405f205416614e9e57898481955f52600360205260405f2060018154019055815f52600260205260405f208173ffffffffffffffffffffffffffffffffffffffff198254161790555f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8180a466ffffff0000000063ffffff007fffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000060c0614cb33688614af2565b20169a60081b169160201b1689171797835f5260096020528860405f2055805f52600a602052600460405f20015415614d39575b5090614d1397614d07614cff614d0d979695946153ef565b923690614af2565b9061590a565b50615b2f565b7f2c0223eed283e194c1112e080d31bdec9e2760ba1454153666cd9d7d6a8779645f80a2565b90949392505f52600a60205260405f20906001600160a01b03614d5b82614bbf565b1673ffffffffffffffffffffffffffffffffffffffff19835416178255614d8460208201614bbf565b6001600160a01b0360018401911673ffffffffffffffffffffffffffffffffffffffff1982541617905560408101356001600160a01b038116810361288b576001600160a01b0360028401911673ffffffffffffffffffffffffffffffffffffffff19825416179055600382019760608201356001600160a01b038116810361288b576001600160a01b031673ffffffffffffffffffffffffffffffffffffffff198a541617895560808201359862ffffff8a168a0361288b5780547fffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffff1660a09a8b1b76ffffff00000000000000000000000000000000000000001617905597810135600490920191909155919290918791614d13614ce7565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f414c52454144595f4d494e5445440000000000000000000000000000000000006044820152fd5b909181359260208301359260408101359260608201359263ffffffff60808401351683019063ffffffff82351693602080840193860101910110613b29579190565b6001600160a01b031680614f5157503190565b906001600160a01b03602460209260405194859384927f70a082310000000000000000000000000000000000000000000000000000000084521660048301525afa9081156131fe575f91614fa3575090565b90506020813d602011614fca575b81614fbe60209383612987565b8101031261288b575190565b3d9150614fb1565b6040517fa54b28310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038216602482015290602082806044810103816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa9182156131fe575f92615099575b505f82136150645750612c7d90614694565b6001600160a01b03907f3351b260000000000000000000000000000000000000000000000000000000005f521660045260245ffd5b9091506020813d6020116150c5575b816150b560209383612987565b8101031261288b5751905f615052565b3d91506150a8565b6001600160a01b0316806150e057504790565b6020602491604051928380927f70a082310000000000000000000000000000000000000000000000000000000082523060048301525afa9081156131fe575f91614fa3575090565b9091906001600160a01b03811690816151e25750505f80808093855af11561514d5750565b601f19601f3d01166001600160a01b03604051927f90bfb8650000000000000000000000000000000000000000000000000000000084521660048301525f6024830152608060448301528060a00160648301523d60848301523d5f60a484013e7ff4b3b1bc0000000000000000000000000000000000000000000000000000000060c4828401600460a4820152015260e40190fd5b60205f6044819496826040956001600160a01b03988751998a947fa9059cbb00000000000000000000000000000000000000000000000000000000865216600485015260248401525af13d15601f3d1160018551141617169282815282602082015201521561524e5750565b601f19601f3d0116604051917f90bfb86500000000000000000000000000000000000000000000000000000000835260048301527fa9059cbb000000000000000000000000000000000000000000000000000000006024830152608060448301528060a00160648301523d60848301523d5f60a484013e7ff27f64e40000000000000000000000000000000000000000000000000000000060c4828401600460a4820152015260e40190fd5b6040517fa54b28310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038216602482015290602082806044810103816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa9182156131fe575f926153bb575b505f8212615386575090565b6001600160a01b03907f4c085bf1000000000000000000000000000000000000000000000000000000005f521660045260245ffd5b9091506020813d6020116153e7575b816153d760209383612987565b8101031261288b5751905f61537a565b3d91506153ca565b905f82126153f957565b6393dafdf15f526004601cfd5b6154299061541b8360801d8260801d03615c12565b92600f0b90600f0b03615c12565b6fffffffffffffffffffffffffffffffff169060801b1790565b929190926fffffffffffffffffffffffffffffffff8160801d948161546787615c20565b911691829116106154ef57506fffffffffffffffffffffffffffffffff929350600f0b908261549583615c20565b911692839116106154a4575050565b906154bf6fffffffffffffffffffffffffffffffff92615c20565b907f12816f22000000000000000000000000000000000000000000000000000000005f526004521660245260445ffd5b6fffffffffffffffffffffffffffffffff906154bf86615c20565b60020b908160ff1d82810118620d89e881116158315763ffffffff9192600182167001fffcb933bd6fad37aa2d162d1a59400102700100000000000000000000000000000000189160028116615815575b600481166157f9575b600881166157dd575b601081166157c1575b602081166157a5575b60408116615789575b6080811661576d575b6101008116615751575b6102008116615735575b6104008116615719575b61080081166156fd575b61100081166156e1575b61200081166156c5575b61400081166156a9575b618000811661568d575b620100008116615671575b620200008116615656575b62040000811661563b575b6208000016615622575b5f1261561a575b0160201c90565b5f1904615613565b6b048a170391f7dc42444e8fa290910260801c9061560c565b6d2216e584f5fa1ea926041bedfe9890920260801c91615602565b916e5d6af8dedb81196699c329225ee6040260801c916155f7565b916f09aa508b5b7a84e1c677de54f3e99bc90260801c916155ec565b916f31be135f97d08fd981231505542fcfa60260801c916155e1565b916f70d869a156d2a1b890bb3df62baf32f70260801c916155d7565b916fa9f746462d870fdf8a65dc1f90e061e50260801c916155cd565b916fd097f3bdfd2022b8845ad8f792aa58250260801c916155c3565b916fe7159475a2c29b7443b29c7fa6e889d90260801c916155b9565b916ff3392b0822b70005940c7a398e4b70f30260801c916155af565b916ff987a7253ac413176f2b074cf7815e540260801c916155a5565b916ffcbe86c7900a88aedcffc83b479aa3a40260801c9161559b565b916ffe5dee046a99a2a811c461f1969c30530260801c91615591565b916fff2ea16466c96a3843ec78b326b528610260801c91615588565b916fff973b41fa98c081472e6896dfb254c00260801c9161557f565b916fffcb9843d60f6159c9db58835c9266440260801c91615576565b916fffe5caca7e10e4e61c3624eaa0941cd00260801c9161556d565b916ffff2e50f5f656932ef12357cf3c7fdcc0260801c91615564565b916ffff97272373d413259a46990580e213a0260801c9161555b565b827f8b86327a000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b936001600160a01b0383166001600160a01b03831611615902575b6001600160a01b03858116959083168611615899575050612c7d9350615cbd565b92909391946001600160a01b038216115f146158f65782916158bf916158c59594615cbd565b93615c87565b6fffffffffffffffffffffffffffffffff81166fffffffffffffffffffffffffffffffff8316105f146145cc575090565b915050612c7d92615c87565b909190615878565b9593946040919392936159758351926159228461296b565b8960081c60020b84528960201c60020b60208501528685850152856060850152845198899485947f9371d11500000000000000000000000000000000000000000000000000000000865260048601614a4b565b03815f6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165af19081156131fe575f945f92615b0b575b50819495817f547f338f02d501a923ee4865857cad34ce600348ee714b1968240d63259bb02e60408051878152866020820152a260ff166159f457505050565b615a5791815f5260076020526001600160a01b0360405f20541693604051927fd8865c2700000000000000000000000000000000000000000000000000000000602085015260248401526044830152606482015260648152613eac608482612987565b15615a5f5750565b601f19601f3d0116604051917f90bfb86500000000000000000000000000000000000000000000000000000000835260048301527fd8865c27000000000000000000000000000000000000000000000000000000006024830152608060448301528060a00160648301523d60848301523d5f60a484013e7fe94f10e20000000000000000000000000000000000000000000000000000000060c4828401600460a4820152015260e40190fd5b909450615b27915060403d6040116140c5576140b18183612987565b90935f6159b4565b908160801d600f0b91600f0b915f811280615bdd575b615b5c5750505f811280615ba8575b615b5c575050565b6fffffffffffffffffffffffffffffffff615b778192614694565b16917f31e30ad0000000000000000000000000000000000000000000000000000000005f521660045260245260445ffd5b506fffffffffffffffffffffffffffffffff615bc382614694565b166fffffffffffffffffffffffffffffffff831610615b54565b506fffffffffffffffffffffffffffffffff615bf882614694565b166fffffffffffffffffffffffffffffffff831610615b45565b9081600f0b9182036153f957565b5f81600f0b12615c3f576fffffffffffffffffffffffffffffffff1690565b7f93dafdf1000000000000000000000000000000000000000000000000000000005f5260045ffd5b906001600160a01b03809116911603906001600160a01b03821161326057565b916001600160a01b03615cab612c7d94615cb29483811684831611615cb757615c67565b1690615d0d565b615e82565b90615c67565b91615cb291612c7d936001600160a01b0382166001600160a01b03821611615d07575b615d006001600160a01b0391615cfa838516848316615da7565b93615c67565b1691615e02565b90615ce0565b908160601b905f196c0100000000000000000000000084099282808510940393808503948584111561288b5714615da0576c0100000000000000000000000082910981805f03168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b5091500490565b90808202915f19828209918380841093039280840393846c01000000000000000000000000111561288b5714615df9576c01000000000000000000000000910990828211900360a01b910360601c1790565b50505060601c90565b91818302915f198185099383808610950394808603958685111561288b5714615e7a579082910981805f03168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b505091500490565b906fffffffffffffffffffffffffffffffff8216809203615c3f5756fea164736f6c634300081a000a00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545000000000000000000000000a3256ab552a271a16acdfdb521b32ef82d481f43000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba30000000000000000000000000000000000000000000000000000000000030d4000000000000000000000000083ff9fc474dbe927ba5bb822571e0814122655bb0000000000000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x60808060405260043610156100ae575b50361561001a575f80fd5b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163314158061007b575b61005357005b7f38bbd576000000000000000000000000000000000000000000000000000000005f5260045ffd5b506001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c05451633141561004d565b5f905f3560e01c9081622a3e3a146126655750806301ffc9a71461259257806305c1ee201461257957806306fdde03146124db578063081812fc146124a8578063095ea7b3146124095780630f5730f11461231357806312261ee7146122cf57806316a241311461229c5780631efeed331461224a57806323b872dd146120585780632b67b57014611eb05780632b9261de14611b935780633644e51514611b705780633aea60f014611a605780633fd40e5614611a2157806340679361146119dd57806342842e0e146116cf5780634767565f146116945780634aa4a4fc14611650578063502e1a161461160e5780635a9d7a68146115ca5780636352211e1461159a57806370a08231146114fd57806375794a3c146114df5780637ba03aad1461145157806386b6be7d1461139d57806389097a6a1461137357806395d89b411461122f57806399fbab88146110345780639a198d6114610f57578063a22cb46514610f27578063ab6291fe14610dc2578063ac9650d814610c6e578063ad0b27fb14610b54578063b88d4fde1461071f578063c87b56dd1461061c578063d737d0c7146105d6578063dd46508f1461041f578063e985e9c5146103cc578063eb80d35e146102c95763fbfa77cf0361000f57346102c657806003193601126102c65760206040516001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545168152f35b80fd5b5060406003193601126102c65760043567ffffffffffffffff81116103c8576102f69036906004016128cf565b60249291923567ffffffffffffffff81116103c4576103199036906004016129e4565b916001600160a01b037f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c1661039c576103769394337f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5d6137b3565b807f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5d80f35b6004847f6f5ffb7e000000000000000000000000000000000000000000000000000000008152fd5b8280fd5b5080fd5b50346102c65760406003193601126102c6576001600160a01b0360406103f061288f565b92826103fa6128a5565b9416815260056020522091165f52602052602060ff60405f2054166040519015158152f35b5060406003193601126102c65760043567ffffffffffffffff81116103c85761044c9036906004016128cf565b6024356001600160a01b037f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c1661039c57337f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5d8042116105ab57506104eb91839160405193849283927f81548319000000000000000000000000000000000000000000000000000000008452602060048501526024840191612a28565b0381836001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545165af180156105a05761054c575b50807f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5d80f35b3d8083833e61055b8183612987565b8101906020818303126103c45780519067ffffffffffffffff821161059c57019080601f830112156103c457815161059592602001612fd8565b505f610525565b8380fd5b6040513d84823e3d90fd5b7fbfb22adf000000000000000000000000000000000000000000000000000000008452600452602483fd5b50346102c657806003193601126102c65760207f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c6001600160a01b0360405191168152f35b50346102c65760206003193601126102c657604051907fe9dc6375000000000000000000000000000000000000000000000000000000008252306004830152600435602483015280826044816001600160a01b037f00000000000000000000000083ff9fc474dbe927ba5bb822571e0814122655bb165afa9081156107135780916106bc575b604051602080825281906106b8908201856128fd565b0390f35b90503d8082843e6106cd8184612987565b8201916020818403126103c85780519067ffffffffffffffff82116103c457019082601f830112156102c657506106b89181602061070d93519101612fd8565b5f6106a2565b604051903d90823e3d90fd5b50346102c65760806003193601126102c65761073961288f565b6107416128a5565b906044359160643567ffffffffffffffff8111610b50576107669036906004016128cf565b9190936040517f5d4e0ced0000000000000000000000000000000000000000000000000000000081526020816004816001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545165afa8015610b45576001600160a01b03918891610b16575b5016610aee5780865260026020526001600160a01b03806040882054169416938403610a90576001600160a01b03821691610813831515613477565b8433148015610a67575b8015610a49575b156109eb5786908582526003602052604082205f198154019055838252600360205260408220600181540190558282526002602052604082208473ffffffffffffffffffffffffffffffffffffffff1982541617905582825260046020526040822073ffffffffffffffffffffffffffffffffffffffff1981541690558284877fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8580a48282526009602052604082205460ff166109dd575b3b159485156108f4575b506108f185612cf4565b80f35b60209550610949604051978896879586947f150b7a0200000000000000000000000000000000000000000000000000000000865233600487015260248601526044850152608060648501526084840191612a28565b03925af180156105a0577fffffffff000000000000000000000000000000000000000000000000000000007f150b7a0200000000000000000000000000000000000000000000000000000000916108f19385916109ae575b5016145f808085816108e7565b6109d0915060203d6020116109d6575b6109c88183612987565b810190612cbc565b5f6109a1565b503d6109be565b6109e6836134dc565b6108dd565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f4e4f545f415554484f52495a45440000000000000000000000000000000000006044820152fd5b5081875260046020526001600160a01b036040882054163314610824565b508487526005602052604087206001600160a01b0333165f5260205260ff60405f20541661081d565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f57524f4e475f46524f4d000000000000000000000000000000000000000000006044820152fd5b6004867f07f5f526000000000000000000000000000000000000000000000000000000008152fd5b610b38915060203d602011610b3e575b610b308183612987565b810190612a93565b5f6107d7565b503d610b26565b6040513d89823e3d90fd5b8480fd5b5060206003193601126102c6576004356040517f5d4e0ced0000000000000000000000000000000000000000000000000000000081526020816004816001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545165afa8015610c63576001600160a01b03918491610c44575b5016610c1c57610be28133613677565b15610bf0576108f1906134dc565b6024827f0ca968d800000000000000000000000000000000000000000000000000000000815233600452fd5b6004827f07f5f526000000000000000000000000000000000000000000000000000000008152fd5b610c5d915060203d602011610b3e57610b308183612987565b5f610bd2565b6040513d85823e3d90fd5b5060206003193601126102c65760043567ffffffffffffffff81116103c857610c9b9036906004016129e4565b90610ca582612f1f565b91610cb36040519384612987565b808352601f19610cc282612f1f565b01845b818110610db1575050835b818110610d5a5783856040519182916020830160208452825180915260408401602060408360051b870101940192905b828210610d0f57505050500390f35b91936020610d4a827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0600195979984950301865288516128fd565b9601920192018594939192610d00565b8480610d67838587612f37565b9081604051928392833781018381520390305af4610d83612a64565b9015610da95790600191610d978287612fc4565b52610da28186612fc4565b5001610cd0565b602081519101fd5b806060602080938801015201610cc5565b50346102c65760206003193601126102c65760043567ffffffffffffffff81116103c857610df49036906004016128cf565b91906001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545163303610eff5760408135189263ffffffff6040830135169063ffffffe0601f8301169460608601602085013518179483019460608601359184641fffffffe08460051b16888189905b808210610ecd5750500160800191011017610ec057916106b894916060608063ffffffff610e9b9616940192016137b3565b60405190610eaa602083612987565b81526040519182916020835260208301906128fd565b633b99b53d84526004601cfd5b9281945063ffffffe0601f608085998160209796889701013590858218179a0101350116010192018990889392610e69565b6004827f62df0545000000000000000000000000000000000000000000000000000000008152fd5b50346102c65760406003193601126102c657610f4161288f565b60243580151581036103c4576108f19133613734565b50346102c657806003193601126102c657808060405160208101907f1e60fd14000000000000000000000000000000000000000000000000000000008252609e602482015260248152610fab604482612987565b51908273dc2b0d2dd2b7759d97d50db4eabdc369731108305af1610fcd612a64565b5015610fd65780f35b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4665654d20726567697374726174696f6e206661696c656400000000000000006044820152fd5b50346102c65760206003193601126102c657600435611051612de1565b5061105b81612e11565b909160c083208215611207576040517f7388426b0000000000000000000000000000000000000000000000000000000081526004810191909152306024820152600883901c600290810b6044830181905260209490941c900b6064820181905260848201839052909460608660a4817f000000000000000000000000a3256ab552a271a16acdfdb521b32ef82d481f436001600160a01b03165afa9182156111fa576101809682936111c9575b506001600160a01b0360406fffffffffffffffffffffffffffffffff855116938160208701519601519681526007602052205416946111a5604051809860a080916001600160a01b0381511684526001600160a01b0360208201511660208501526001600160a01b0360408201511660408501526001600160a01b03606082015116606085015262ffffff60808201511660808501520151910152565b60c087015260e0860152610100850152610120840152610140830152610160820152f35b6111ec91935060603d6060116111f3575b6111e48183612987565b810190612ec1565b915f611108565b503d6111da565b50604051903d90823e3d90fd5b6004857f6aa2a937000000000000000000000000000000000000000000000000000000008152fd5b50346102c657806003193601126102c6576040519080600154908160011c91600181168015611369575b60208410811461133c578386529081156112f7575060011461129a575b6106b88461128681860382612987565b6040519182916020835260208301906128fd565b600181527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6939250905b8082106112dd5750909150810160200161128682611276565b9192600181602092548385880101520191019092916112c4565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660208087019190915292151560051b850190920192506112869150839050611276565b6024837f4e487b710000000000000000000000000000000000000000000000000000000081526022600452fd5b92607f1692611259565b50346102c65760206003193601126102c65760406020916004358152600983522054604051908152f35b50346102c65760206003193601126102c6576004357fffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000081168091036103c8578160409160c09352600a602052206001600160a01b038154169062ffffff6001600160a01b03600183015416916001600160a01b036002820154166004600383015492015493604051958652602086015260408501526001600160a01b038116606085015260a01c16608083015260a0820152f35b50346102c65760206003193601126102c65760e0611470600435612e11565b6114d8604051809360a080916001600160a01b0381511684526001600160a01b0360208201511660208501526001600160a01b0360408201511660408501526001600160a01b03606082015116606085015262ffffff60808201511660808501520151910152565b60c0820152f35b50346102c657806003193601126102c6576020600854604051908152f35b50346102c65760206003193601126102c6576001600160a01b0361151f61288f565b16801561153c578160409160209352600383522054604051908152f35b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f5a45524f5f4144445245535300000000000000000000000000000000000000006044820152fd5b50346102c65760206003193601126102c65760206115b9600435612dbe565b6001600160a01b0360405191168152f35b50346102c657806003193601126102c65760206040516001600160a01b037f00000000000000000000000083ff9fc474dbe927ba5bb822571e0814122655bb168152f35b50346102c65760406003193601126102c65760406020916001600160a01b0361163561288f565b16815260068352818120602435825283522054604051908152f35b50346102c657806003193601126102c65760206040516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346102c657806003193601126102c65760206040517f0000000000000000000000000000000000000000000000000000000000030d408152f35b50346102c6576116de366129aa565b6040929192517f5d4e0ced0000000000000000000000000000000000000000000000000000000081526020816004816001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545165afa80156119d2576001600160a01b039186916119b3575b501661198b5780845260026020526001600160a01b03806040862054169216918203610a90576001600160a01b0383169261178b841515613477565b8233148015611962575b8015611944575b156109eb578285526003602052604085205f198154019055838552600360205260408520600181540190558185526002602052604085208473ffffffffffffffffffffffffffffffffffffffff1982541617905581855260046020526040852073ffffffffffffffffffffffffffffffffffffffff1981541690558184847fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8880a48185526009602052604085205460ff16611936575b3b15918215611867575b846108f184612cf4565b6020925060a4908560405195869485937f150b7a0200000000000000000000000000000000000000000000000000000000855233600486015260248501526044840152608060648401528160848401525af180156105a0577fffffffff000000000000000000000000000000000000000000000000000000007f150b7a0200000000000000000000000000000000000000000000000000000000916108f1938591611917575b5016145f8061185d565b611930915060203d6020116109d6576109c88183612987565b5f61190d565b61193f826134dc565b611853565b5081855260046020526001600160a01b03604086205416331461179c565b508285526005602052604085206001600160a01b0333165f5260205260ff60405f205416611795565b6004847f07f5f526000000000000000000000000000000000000000000000000000000008152fd5b6119cc915060203d602011610b3e57610b308183612987565b5f61174f565b6040513d87823e3d90fd5b50346102c657806003193601126102c65760206040516001600160a01b037f000000000000000000000000a3256ab552a271a16acdfdb521b32ef82d481f43168152f35b50600319360160e081126103c85760c0136102c65760c435906001600160a01b03821682036102c6576020611a5583612b7d565b6040519060020b8152f35b5060c06003193601126102c657611a7561288f565b90611a7e6128a5565b6044359081151582036103c4576064359360843560a43567ffffffffffffffff8111611b6c57611ab29036906004016128cf565b9096804211611b44578387988493611b33888b611b399681611b3f9a6108f19f8f81604051977f6673cb397ee2a50b6b8401653d3638b4ac8b3db9c28aa6870ffceb7574ec2f7689526001600160a01b0360208a0191168152600160408a019316835260608901948552608089019687528160a08a209952525252526130ce565b91613134565b8261300e565b613734565b6004877f5a9165ff000000000000000000000000000000000000000000000000000000008152fd5b8580fd5b50346102c657806003193601126102c6576020611b8b612ab2565b604051908152f35b5060606003193601126102c657600435611bab6128a5565b9060443567ffffffffffffffff811161059c57611bcc9036906004016128cf565b926040517f5d4e0ced0000000000000000000000000000000000000000000000000000000081526020816004816001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545165afa8015611ea5576001600160a01b03918791611e86575b5016611e5e57611c4b8333613677565b15611e325782855260076020526001600160a01b0360408620541680611e02575090611d27918386526009602052600160408720541784875260096020526040872055611d226001600160a01b038216958588526007602052604088206001600160a01b03881673ffffffffffffffffffffffffffffffffffffffff19825416179055611d146040519485927f8d57f6b2000000000000000000000000000000000000000000000000000000006020850152886024850152604060448501526064840191612a28565b03601f198101845283612987565b6136f3565b15611d53577f9709492381f90bdc5938bb4e3b8e35b7e0eac8af058619e27191c5a40ce79fa98380a380f35b5090601f19601f3d011690604051927f90bfb86500000000000000000000000000000000000000000000000000000000845260048401527f8d57f6b2000000000000000000000000000000000000000000000000000000006024840152608060448401528160a00160648401523d60848401523d9060a484013e7f81ea5e9e0000000000000000000000000000000000000000000000000000000060c4828401600460a4820152015260e40190fd5b85604491857f25fbd8be000000000000000000000000000000000000000000000000000000008352600452602452fd5b6024857f0ca968d800000000000000000000000000000000000000000000000000000000815233600452fd5b6004857f07f5f526000000000000000000000000000000000000000000000000000000008152fd5b611e9f915060203d602011610b3e57610b308183612987565b5f611c3b565b6040513d88823e3d90fd5b506101006003193601126102c657611ec661288f565b60c07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc3601126103c85760e43567ffffffffffffffff81116103c457611f109036906004016128cf565b606093917f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba36001600160a01b031691823b1561059c576001600160a01b03604051957f2b67b5700000000000000000000000000000000000000000000000000000000087521660048601526024356001600160a01b038116809103610b505760248601526044356001600160a01b038116809103610b5057604486015260643565ffffffffffff8116809103610b5057606486015260843565ffffffffffff8116809103610b5057608486015260a4356001600160a01b038116809103610b5057848661201d8195839795839560a485015260c43560c485015261010060e4850152610104840191612a28565b03925af19182612043575b505061203a57506106b8611286612a64565b6106b890611286565b61204e828092612987565b6102c65780612028565b50346102c657612067366129aa565b91906040517f5d4e0ced0000000000000000000000000000000000000000000000000000000081526020816004816001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545165afa80156119d2576001600160a01b0391869161222b575b501661198b5782845260026020526001600160a01b03806040862054169216918203610a90576001600160a01b0316612111811515613477565b8133148015612202575b80156121e4575b156109eb5781839285526003602052604085205f198154019055818552600360205260408520600181540190558285526002602052604085208273ffffffffffffffffffffffffffffffffffffffff1982541617905582855260046020526040852073ffffffffffffffffffffffffffffffffffffffff1981541690557fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8580a48082526009602052604082205460ff166121db575080f35b6108f1906134dc565b5082845260046020526001600160a01b036040852054163314612122565b508184526005602052604084206001600160a01b0333165f5260205260ff60405f20541661211b565b612244915060203d602011610b3e57610b308183612987565b5f6120d7565b50346102c65760206003193601126102c657602061228260043561226d81612e11565b919082851c60020b9260081c60020b916133b0565b6fffffffffffffffffffffffffffffffff60405191168152f35b50346102c65760206003193601126102c6576001600160a01b036040602092600435815260078452205416604051908152f35b50346102c657806003193601126102c65760206040516001600160a01b037f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3168152f35b5060a06003193601126102c65761232861288f565b906024356044359260643560843567ffffffffffffffff8111610b50576123539036906004016128cf565b90958042116123e15791611b398587986123dc94611b33888b80996108f19d8961237c89612dbe565b9c8d9981604051977f49ecf333e5b8c95c40fdafc95c1ad136e8914a8fb55e9dc8bb01eaa83a2df9ad89526001600160a01b0360208a01911681526040890192835260608901948552608089019687528160a08a209952525252526130ce565b61306f565b6004867f5a9165ff000000000000000000000000000000000000000000000000000000008152fd5b50346102c65760406003193601126102c65761242361288f565b9060243580825260026020526001600160a01b0360408320541692833314158061247e575b612456576108f1929361306f565b6004837f82b42900000000000000000000000000000000000000000000000000000000008152fd5b508383526005602052604083206001600160a01b0333165f5260205260ff60405f20541615612448565b50346102c65760206003193601126102c6576001600160a01b036040602092600435815260048452205416604051908152f35b50346102c657806003193601126102c65760405190808054908160011c9160018116801561256f575b60208410811461133c578386529081156112f75750600114612530576106b88461128681860382612987565b80805260208120939250905b8082106125555750909150810160200161128682611276565b91926001816020925483858801015201910190929161253c565b92607f1692612504565b5060206003193601126102c6576108f16004353361300e565b50346102c65760206003193601126102c6576004357fffffffff0000000000000000000000000000000000000000000000000000000081168091036103c857807f01ffc9a7000000000000000000000000000000000000000000000000000000006020921490811561263b575b8115612611575b506040519015158152f35b7f5b5e139f0000000000000000000000000000000000000000000000000000000091501482612606565b7f80ac58cd00000000000000000000000000000000000000000000000000000000811491506125ff565b606060031936011261288b5761267961288f565b906024359167ffffffffffffffff831161288b57823603606060031982011261288b5760443567ffffffffffffffff811161288b576126bc9036906004016128cf565b906060956001600160a01b037f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba31694853b1561288b576001600160a01b03907f2a2d80d100000000000000000000000000000000000000000000000000000000885216600487015286602487015260c48601937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdd8260040135910181121561288b5781016024600482013591019467ffffffffffffffff821161288b578160071b3603861361288b5760648801899052819052869460e48601949392915f5b8a82821061281357505050506127e75f9694869488946044856001600160a01b036127c960248b99016128bb565b166084880152013560a4860152600319858403016044860152612a28565b03925af19081612803575b5061203a57506106b8611286612a64565b5f61280d91612987565b5f6127f2565b8398506001929495969765ffffffffffff6128756080949693826128686040876001600160a01b036128458b9a6128bb565b1688526001600160a01b0361285c602083016128bb565b16602089015201612a15565b1660408501528c01612a15565b168d82015201970191019188969594939261279b565b5f80fd5b600435906001600160a01b038216820361288b57565b602435906001600160a01b038216820361288b57565b35906001600160a01b038216820361288b57565b9181601f8401121561288b5782359167ffffffffffffffff831161288b576020838186019501011161288b57565b90601f19601f602080948051918291828752018686015e5f8582860101520116010190565b60c0810190811067ffffffffffffffff82111761293e57604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6080810190811067ffffffffffffffff82111761293e57604052565b90601f601f19910116810190811067ffffffffffffffff82111761293e57604052565b600319606091011261288b576004356001600160a01b038116810361288b57906024356001600160a01b038116810361288b579060443590565b9181601f8401121561288b5782359167ffffffffffffffff831161288b576020808501948460051b01011161288b57565b359065ffffffffffff8216820361288b57565b601f8260209493601f1993818652868601375f8582860101520116010190565b67ffffffffffffffff811161293e57601f01601f191660200190565b3d15612a8e573d90612a7582612a48565b91612a836040519384612987565b82523d5f602084013e565b606090565b9081602091031261288b57516001600160a01b038116810361288b5790565b467f000000000000000000000000000000000000000000000000000000000000009203612afd577f5d4e504d4587544fc1733037c393af91b8e1d5ba6474e77dde77817444d1cea890565b60405160208101907f8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a86682527f4b737a7cd1ab003e3316131917a463448cdb493b9e97b0b0fc1f191f25029e42604082015246606082015230608082015260808152612b6960a082612987565b51902090565b51908160020b820361288b57565b604051907f8b0c1b220000000000000000000000000000000000000000000000000000000082526004356001600160a01b03811680910361288b5760048301526024356001600160a01b03811680910361288b5760248301526044356001600160a01b03811680910361288b5760448301526064356001600160a01b03811680910361288b5760648301526084359062ffffff821680920361288b576001600160a01b0391608484015260a43560a48401521660c482015260208160e4815f6001600160a01b037f000000000000000000000000a3256ab552a271a16acdfdb521b32ef82d481f43165af15f9181612c80575b50612c7d5750627fffff90565b90565b9091506020813d602011612cb4575b81612c9c60209383612987565b8101031261288b57612cad90612b6f565b905f612c70565b3d9150612c8f565b9081602091031261288b57517fffffffff000000000000000000000000000000000000000000000000000000008116810361288b5790565b15612cfb57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f554e534146455f524543495049454e54000000000000000000000000000000006044820152fd5b15612d6057565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f4e4f545f4d494e544544000000000000000000000000000000000000000000006044820152fd5b5f5260026020526001600160a01b0360405f20541690612ddf821515612d59565b565b60405190612dee82612922565b5f60a0838281528260208201528260408201528260608201528260808201520152565b612e19612de1565b505f52600960205260405f2054807fffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000165f52600a60205260405f20600460405191612e6383612922565b6001600160a01b0381541683526001600160a01b0360018201541660208401526001600160a01b03600282015416604084015262ffffff60038201546001600160a01b038116606086015260a01c166080840152015460a082015291565b9081606091031261288b57604051906060820182811067ffffffffffffffff82111761293e576040528051906fffffffffffffffffffffffffffffffff8216820361288b576040918352602081015160208401520151604082015290565b67ffffffffffffffff811161293e5760051b60200190565b9190811015612f975760051b810135907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18136030182121561288b57019081359167ffffffffffffffff831161288b57602001823603811361288b579190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b8051821015612f975760209160051b010190565b929192612fe482612a48565b91612ff26040519384612987565b82948184528183011161288b578281602093845f96015e010152565b906001600160a01b03600160ff83161b92165f52600660205260405f209060081c5f5260205260405f2081815418809155161561304757565b7f1fb09b80000000000000000000000000000000000000000000000000000000005f5260045ffd5b906001600160a01b038091845f52600460205260405f2082821673ffffffffffffffffffffffffffffffffffffffff198254161790551691167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9255f80a4565b906130d7612ab2565b91604051927f19010000000000000000000000000000000000000000000000000000000000008452600284015260228301525f604060428420938281528260208201520152565b919082604091031261288b576020823592013590565b833b6132b557604182036132095761314e8282018261311e565b93909260401015612f97576020935f9360ff6040608095013560f81c5b60405194855216868401526040830152606082015282805260015afa156131fe576001600160a01b035f51169081156131d6576001600160a01b0316036131ae57565b7f815e1d64000000000000000000000000000000000000000000000000000000005f5260045ffd5b7f8baa579f000000000000000000000000000000000000000000000000000000005f5260045ffd5b6040513d5f823e3d90fd5b6040820361328d5761321d9181019061311e565b91601b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff84169360ff1c019060ff8211613260576020935f9360ff60809461316b565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b7f4be6321b000000000000000000000000000000000000000000000000000000005f5260045ffd5b9092613309936001600160a01b03602094604051968795869485937f1626ba7e0000000000000000000000000000000000000000000000000000000085526004850152604060248501526044840191612a28565b0392165afa9081156131fe577f1626ba7e00000000000000000000000000000000000000000000000000000000917fffffffff00000000000000000000000000000000000000000000000000000000915f91613391575b50160361336957565b7fb0669cbc000000000000000000000000000000000000000000000000000000005f5260045ffd5b6133aa915060203d6020116109d6576109c88183612987565b5f613360565b60c09091206040517f7388426b0000000000000000000000000000000000000000000000000000000081526004810191909152306024820152600292830b60448201529290910b6064830152608482015260608160a4817f000000000000000000000000a3256ab552a271a16acdfdb521b32ef82d481f436001600160a01b03165afa80156131fe576fffffffffffffffffffffffffffffffff915f91613458575b50511690565b613471915060603d6060116111f3576111e48183612987565b5f613452565b1561347e57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f494e56414c49445f524543495049454e540000000000000000000000000000006044820152fd5b5f90805f5260076020526001600160a01b0360405f20541691821561364f575f82815260096020908152604080832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905560079091529020805473ffffffffffffffffffffffffffffffffffffffff19169055823b613580575b807fa0ebb1de82db929a9153472f37d3a66dbede4436258311ad0f52a35a2c91d15091a3565b5a907f0000000000000000000000000000000000000000000000000000000000030d4080921061362757833b1561288b575f846024829460405195869384927faf45dd14000000000000000000000000000000000000000000000000000000008452896004850152f16135f5575b905061355a565b505f61360091612987565b7fa0ebb1de82db929a9153472f37d3a66dbede4436258311ad0f52a35a2c91d1505f6135ee565b7fed43c3a6000000000000000000000000000000000000000000000000000000005f5260045ffd5b7f237e6c28000000000000000000000000000000000000000000000000000000005f5260045ffd5b6001600160a01b038061368984612dbe565b1691169081149182156136d3575b82156136a257505090565b6001600160a01b039192506136b690612dbe565b165f52600560205260405f20905f5260205260ff60405f20541690565b8092505f526004602052806001600160a01b0360405f2054161491613697565b803b1561370c57815f92918360208194519301915af190565b7f7c402b21000000000000000000000000000000000000000000000000000000005f5260045ffd5b60206001600160a01b03807f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31931693845f526005835260405f208282165f52835260405f20951515957fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0081541660ff88161790556040519586521693a3565b909291938284036137f4575f5b848110156137ec576001906137e68185016137dc83888b612f37565b913560f81c61381c565b016137c0565b509350505050565b7faaad13f7000000000000000000000000000000000000000000000000000000005f5260045ffd5b90919060068110156140cc57806138d6575061383791614efc565b95949091937f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c6138688382613677565b156138a157509561389c9282613890612ddf989961388861389696612e11565b9290916153ef565b9161590a565b90615406565b615b2f565b6001600160a01b03907f0ca968d8000000000000000000000000000000000000000000000000000000005f521660045260245ffd5b60048103613a4757506138e8916149f9565b7f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a9491949392935c61391a8382613677565b156138a1575061392982612e11565b91909560c0872093604051947fc815641c00000000000000000000000000000000000000000000000000000000865260048601526080856024816001600160a01b037f000000000000000000000000a3256ab552a271a16acdfdb521b32ef82d481f43165afa9384156131fe57612ddf986138906fffffffffffffffffffffffffffffffff613a0f6138969861389c9a5f91613a15575b506139d08660081c60020b61550a565b6139df8760201c60020b61550a565b6139f26001600160a01b038851166152fa565b91613a096001600160a01b0360208a0151166152fa565b9361585d565b166153ef565b613a37915060803d608011613a40575b613a2f8183612987565b810190614b7b565b5050505f6139c0565b503d613a25565b60018103613abf5750613a5991614efc565b95949091937f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c613a8a8382613677565b156138a1575095613aba9282613ab5612ddf9899613890613aad61389697612e11565b9390926153ef565b614694565b615443565b60028103613b36575063ffffffff61018083013516820163ffffffff8135169183602080840193850101910110613b295782613b02610160612ddf950135614640565b9061014081013590610120810135906101008101359060e08101359060c081013590614bd3565b633b99b53d5f526004601cfd5b60058103613c82575060c082013560e08301359063ffffffff6101608501351684019163ffffffff8335169385602080860195870101910110613b2957613b81610140860135614640565b9160c0613b8e3688614af2565b2095604051967fc815641c00000000000000000000000000000000000000000000000000000000885260048801526080876024816001600160a01b037f000000000000000000000000a3256ab552a271a16acdfdb521b32ef82d481f43165afa9283156131fe57612ddf975f94613c5e575b50613c0a8361550a565b926fffffffffffffffffffffffffffffffff613c57613c288461550a565b96613c3a613c3587614bbf565b6152fa565b6101208701359861010088013598613a09613c3560208b01614bbf565b1692614bd3565b613c7891945060803d608011613a4057613a2f8183612987565b505050925f613c00565b929160038414613cbb575050505b7f5cda29d7000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b613cc69293506149f9565b939190927f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c613cf68482613677565b156138a15750613d0583612e11565b9490918560081c60020b938660201c60020b946fffffffffffffffffffffffffffffffff613d358783888b6133b0565b1694613d4088612dbe565b99885f5260096020525f6040812055885f526002602052885f6001600160a01b03604082205416613d72811515612d59565b8082526003602052604082205f19815401905582825260026020526040822073ffffffffffffffffffffffffffffffffffffffff19815416905582825260046020526040822073ffffffffffffffffffffffffffffffffffffffff1981541690557fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8280a45f9787613f6c575b505050505050508360ff16613e16575b5050505050565b613eb293835f5260076020526001600160a01b038060405f20541696855f52600760205260405f2073ffffffffffffffffffffffffffffffffffffffff198154169055604051957fb1a9116f00000000000000000000000000000000000000000000000000000000602088015260248701521660448501526064840152608483015260a482015260a48152613eac60c482612987565b826136f3565b15613ec05780808080613e0f565b601f19601f3d0116604051917f90bfb86500000000000000000000000000000000000000000000000000000000835260048301527fb1a9116f000000000000000000000000000000000000000000000000000000006024830152608060448301528060a00160648301523d60848301523d5f60a484013e7face944810000000000000000000000000000000000000000000000000000000060c4828401600460a4820152015260e40190fd5b6040949596985090613fd591613f84613ab58a6153ef565b90865195613f918761296b565b8652602086015285850152896060850152845198899485947f9371d11500000000000000000000000000000000000000000000000000000000865260048601614a4b565b03815f6001600160a01b037f000000000000000000000000a3256ab552a271a16acdfdb521b32ef82d481f43165af19081156131fe5785925f955f9361406f575b509161404b6040927f547f338f02d501a923ee4865857cad34ce600348ee714b1968240d63259bb02e94613aba84809a615406565b614057613ab5866153ef565b9082519182526020820152a25f808080808080613dff565b60409296507f547f338f02d501a923ee4865857cad34ce600348ee714b1968240d63259bb02e93506140b961404b91843d86116140c5575b6140b18183612987565b810190614a35565b97909794509250614016565b503d6140a7565b919291600d810361412657506140e690612ddf929361462d565b9061411d7f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c918261411782614fd2565b916147c6565b61411782614fd2565b60118103614167575061414d61414361415e92612ddf94956146c0565b9391929093614640565b9182614158826152fa565b916146ec565b614158826152fa565b600b81036141ba575061417e90612ddf92936146c0565b156141af57614117827f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c92614785565b614117823092614785565b600e81036141e757506141e16141d761415892612ddf94956146c0565b9282949291614640565b926146d8565b601281036142ef57506141fa9192614545565b6040517fa54b28310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038216602482015290602082806044810103816001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545165afa9182156131fe575f926142bb575b507f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c5f8312156142b157614117612ddf93614694565b612ddf92916146ec565b9091506020813d6020116142e7575b816142d760209383612987565b8101031261288b5751905f61427a565b3d91506142ca565b601381036143cf5750614302919261462d565b9061430c816152fa565b9182116143a2576001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c05451690813b1561288b5760446001600160a01b03915f809460405196879586947f80f0b44c00000000000000000000000000000000000000000000000000000000865216600485015260248401525af180156131fe576143985750565b5f612ddf91612987565b90612ddf917f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c906146ec565b6014810361440b57506143e6906143ee929361462d565b919091614640565b6143f7826150cd565b908161440257505050565b612ddf92615128565b92601584036144a15761441f929350614545565b6144536001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001680926145d1565b908161445d575050565b803b1561288b575f906004604051809481937fd0e30db00000000000000000000000000000000000000000000000000000000083525af180156131fe576143985750565b601684146144b157505050613c90565b6144bc929350614545565b6144f06001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169182614551565b806144f9575050565b813b1561288b575f916024839260405194859384927f2e1a7d4d00000000000000000000000000000000000000000000000000000000845260048401525af180156131fe576143985750565b90602011613b29573590565b61455c903090614f3e565b7f800000000000000000000000000000000000000000000000000000000000000082146145cc5781156145bb575b81116145935790565b7ff4d678b8000000000000000000000000000000000000000000000000000000005f5260045ffd5b90506145c65f614fd2565b9061458a565b905090565b906145dc305f614f3e565b907f80000000000000000000000000000000000000000000000000000000000000008314614627578215614615575b5081116145935790565b614620919250614fd2565b905f61460b565b50905090565b9190604011613b29576020823592013590565b6001600160a01b038116600181036146795750507f0aedd6bde10e3aa2adec092b02a3e3e805795516cda41f27aa145b8f300af87a5c90565b600203612c7d57503090565b9081602091031261288b575190565b7f80000000000000000000000000000000000000000000000000000000000000008114613260575f0390565b90606011613b29578035916040602083013592013590565b90816146e857612c7d91506152fa565b5090565b90918015614780576001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c054516803b1561288b575f92836064926001600160a01b03948560405198899788967f0b0d9c0900000000000000000000000000000000000000000000000000000000885216600487015216602485015260448401525af180156131fe576143985750565b505050565b907f800000000000000000000000000000000000000000000000000000000000000082036147b757612c7d91506150cd565b816146e857612c7d9150614fd2565b905f9183156149f3576001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c05451691823b1561288b57604051907fa58411940000000000000000000000000000000000000000000000000000000082526001600160a01b038316918260048201525f8160248183895af180156131fe576149de575b50816148c1575050506020906004604051809581937f11da60b40000000000000000000000000000000000000000000000000000000083525af190811561071357506148965750565b6148b79060203d6020116148ba575b6148af8183612987565b810190614685565b50565b503d6148a5565b906001600160a01b038596939216903082145f1461492657505082916020936148e992615128565b6004604051809581937f11da60b40000000000000000000000000000000000000000000000000000000083525af190811561071357506148965750565b9150919293506001600160a01b037f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba31690813b15611b6c578592836001600160a01b03959360849360405197889687957f36c7851600000000000000000000000000000000000000000000000000000000875260048701528a602487015216604485015260648401525af18015610c63579083916149c9575b50906020906148e9565b816149d391612987565b6103c857815f6149bf565b6149eb9195505f90612987565b5f935f61484d565b50505050565b919082359260208101359260408201359263ffffffff60608401351683019063ffffffff82351693602080840193860101910110613b29579190565b919082604091031261288b576020825192015190565b6060612c7d9593614aba836101609560a080916001600160a01b0381511684526001600160a01b0360208201511660208501526001600160a01b0360408201511660408501526001600160a01b03606082015116606085015262ffffff60808201511660808501520151910152565b805160020b60c0840152602081015160020b60e084015260408101516101008401520151610120820152816101408201520191612a28565b91908260c091031261288b57604051614b0a81612922565b8092614b15816128bb565b8252614b23602082016128bb565b6020830152614b34604082016128bb565b6040830152614b45606082016128bb565b6060830152608081013562ffffff8116810361288b57608083015260a090810135910152565b519062ffffff8216820361288b57565b919082608091031261288b5781516001600160a01b038116810361288b5791614ba660208201612b6f565b91612c7d6060614bb860408501614b6b565b9301614b6b565b356001600160a01b038116810361288b5790565b90969297939495976001600160a01b036008549960018b016008551692614bfb841515613477565b895f5260026020526001600160a01b0360405f205416614e9e57898481955f52600360205260405f2060018154019055815f52600260205260405f208173ffffffffffffffffffffffffffffffffffffffff198254161790555f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8180a466ffffff0000000063ffffff007fffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000060c0614cb33688614af2565b20169a60081b169160201b1689171797835f5260096020528860405f2055805f52600a602052600460405f20015415614d39575b5090614d1397614d07614cff614d0d979695946153ef565b923690614af2565b9061590a565b50615b2f565b7f2c0223eed283e194c1112e080d31bdec9e2760ba1454153666cd9d7d6a8779645f80a2565b90949392505f52600a60205260405f20906001600160a01b03614d5b82614bbf565b1673ffffffffffffffffffffffffffffffffffffffff19835416178255614d8460208201614bbf565b6001600160a01b0360018401911673ffffffffffffffffffffffffffffffffffffffff1982541617905560408101356001600160a01b038116810361288b576001600160a01b0360028401911673ffffffffffffffffffffffffffffffffffffffff19825416179055600382019760608201356001600160a01b038116810361288b576001600160a01b031673ffffffffffffffffffffffffffffffffffffffff198a541617895560808201359862ffffff8a168a0361288b5780547fffffffffffffffffff000000ffffffffffffffffffffffffffffffffffffffff1660a09a8b1b76ffffff00000000000000000000000000000000000000001617905597810135600490920191909155919290918791614d13614ce7565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f414c52454144595f4d494e5445440000000000000000000000000000000000006044820152fd5b909181359260208301359260408101359260608201359263ffffffff60808401351683019063ffffffff82351693602080840193860101910110613b29579190565b6001600160a01b031680614f5157503190565b906001600160a01b03602460209260405194859384927f70a082310000000000000000000000000000000000000000000000000000000084521660048301525afa9081156131fe575f91614fa3575090565b90506020813d602011614fca575b81614fbe60209383612987565b8101031261288b575190565b3d9150614fb1565b6040517fa54b28310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038216602482015290602082806044810103816001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545165afa9182156131fe575f92615099575b505f82136150645750612c7d90614694565b6001600160a01b03907f3351b260000000000000000000000000000000000000000000000000000000005f521660045260245ffd5b9091506020813d6020116150c5575b816150b560209383612987565b8101031261288b5751905f615052565b3d91506150a8565b6001600160a01b0316806150e057504790565b6020602491604051928380927f70a082310000000000000000000000000000000000000000000000000000000082523060048301525afa9081156131fe575f91614fa3575090565b9091906001600160a01b03811690816151e25750505f80808093855af11561514d5750565b601f19601f3d01166001600160a01b03604051927f90bfb8650000000000000000000000000000000000000000000000000000000084521660048301525f6024830152608060448301528060a00160648301523d60848301523d5f60a484013e7ff4b3b1bc0000000000000000000000000000000000000000000000000000000060c4828401600460a4820152015260e40190fd5b60205f6044819496826040956001600160a01b03988751998a947fa9059cbb00000000000000000000000000000000000000000000000000000000865216600485015260248401525af13d15601f3d1160018551141617169282815282602082015201521561524e5750565b601f19601f3d0116604051917f90bfb86500000000000000000000000000000000000000000000000000000000835260048301527fa9059cbb000000000000000000000000000000000000000000000000000000006024830152608060448301528060a00160648301523d60848301523d5f60a484013e7ff27f64e40000000000000000000000000000000000000000000000000000000060c4828401600460a4820152015260e40190fd5b6040517fa54b28310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038216602482015290602082806044810103816001600160a01b037f00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545165afa9182156131fe575f926153bb575b505f8212615386575090565b6001600160a01b03907f4c085bf1000000000000000000000000000000000000000000000000000000005f521660045260245ffd5b9091506020813d6020116153e7575b816153d760209383612987565b8101031261288b5751905f61537a565b3d91506153ca565b905f82126153f957565b6393dafdf15f526004601cfd5b6154299061541b8360801d8260801d03615c12565b92600f0b90600f0b03615c12565b6fffffffffffffffffffffffffffffffff169060801b1790565b929190926fffffffffffffffffffffffffffffffff8160801d948161546787615c20565b911691829116106154ef57506fffffffffffffffffffffffffffffffff929350600f0b908261549583615c20565b911692839116106154a4575050565b906154bf6fffffffffffffffffffffffffffffffff92615c20565b907f12816f22000000000000000000000000000000000000000000000000000000005f526004521660245260445ffd5b6fffffffffffffffffffffffffffffffff906154bf86615c20565b60020b908160ff1d82810118620d89e881116158315763ffffffff9192600182167001fffcb933bd6fad37aa2d162d1a59400102700100000000000000000000000000000000189160028116615815575b600481166157f9575b600881166157dd575b601081166157c1575b602081166157a5575b60408116615789575b6080811661576d575b6101008116615751575b6102008116615735575b6104008116615719575b61080081166156fd575b61100081166156e1575b61200081166156c5575b61400081166156a9575b618000811661568d575b620100008116615671575b620200008116615656575b62040000811661563b575b6208000016615622575b5f1261561a575b0160201c90565b5f1904615613565b6b048a170391f7dc42444e8fa290910260801c9061560c565b6d2216e584f5fa1ea926041bedfe9890920260801c91615602565b916e5d6af8dedb81196699c329225ee6040260801c916155f7565b916f09aa508b5b7a84e1c677de54f3e99bc90260801c916155ec565b916f31be135f97d08fd981231505542fcfa60260801c916155e1565b916f70d869a156d2a1b890bb3df62baf32f70260801c916155d7565b916fa9f746462d870fdf8a65dc1f90e061e50260801c916155cd565b916fd097f3bdfd2022b8845ad8f792aa58250260801c916155c3565b916fe7159475a2c29b7443b29c7fa6e889d90260801c916155b9565b916ff3392b0822b70005940c7a398e4b70f30260801c916155af565b916ff987a7253ac413176f2b074cf7815e540260801c916155a5565b916ffcbe86c7900a88aedcffc83b479aa3a40260801c9161559b565b916ffe5dee046a99a2a811c461f1969c30530260801c91615591565b916fff2ea16466c96a3843ec78b326b528610260801c91615588565b916fff973b41fa98c081472e6896dfb254c00260801c9161557f565b916fffcb9843d60f6159c9db58835c9266440260801c91615576565b916fffe5caca7e10e4e61c3624eaa0941cd00260801c9161556d565b916ffff2e50f5f656932ef12357cf3c7fdcc0260801c91615564565b916ffff97272373d413259a46990580e213a0260801c9161555b565b827f8b86327a000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b936001600160a01b0383166001600160a01b03831611615902575b6001600160a01b03858116959083168611615899575050612c7d9350615cbd565b92909391946001600160a01b038216115f146158f65782916158bf916158c59594615cbd565b93615c87565b6fffffffffffffffffffffffffffffffff81166fffffffffffffffffffffffffffffffff8316105f146145cc575090565b915050612c7d92615c87565b909190615878565b9593946040919392936159758351926159228461296b565b8960081c60020b84528960201c60020b60208501528685850152856060850152845198899485947f9371d11500000000000000000000000000000000000000000000000000000000865260048601614a4b565b03815f6001600160a01b037f000000000000000000000000a3256ab552a271a16acdfdb521b32ef82d481f43165af19081156131fe575f945f92615b0b575b50819495817f547f338f02d501a923ee4865857cad34ce600348ee714b1968240d63259bb02e60408051878152866020820152a260ff166159f457505050565b615a5791815f5260076020526001600160a01b0360405f20541693604051927fd8865c2700000000000000000000000000000000000000000000000000000000602085015260248401526044830152606482015260648152613eac608482612987565b15615a5f5750565b601f19601f3d0116604051917f90bfb86500000000000000000000000000000000000000000000000000000000835260048301527fd8865c27000000000000000000000000000000000000000000000000000000006024830152608060448301528060a00160648301523d60848301523d5f60a484013e7fe94f10e20000000000000000000000000000000000000000000000000000000060c4828401600460a4820152015260e40190fd5b909450615b27915060403d6040116140c5576140b18183612987565b90935f6159b4565b908160801d600f0b91600f0b915f811280615bdd575b615b5c5750505f811280615ba8575b615b5c575050565b6fffffffffffffffffffffffffffffffff615b778192614694565b16917f31e30ad0000000000000000000000000000000000000000000000000000000005f521660045260245260445ffd5b506fffffffffffffffffffffffffffffffff615bc382614694565b166fffffffffffffffffffffffffffffffff831610615b54565b506fffffffffffffffffffffffffffffffff615bf882614694565b166fffffffffffffffffffffffffffffffff831610615b45565b9081600f0b9182036153f957565b5f81600f0b12615c3f576fffffffffffffffffffffffffffffffff1690565b7f93dafdf1000000000000000000000000000000000000000000000000000000005f5260045ffd5b906001600160a01b03809116911603906001600160a01b03821161326057565b916001600160a01b03615cab612c7d94615cb29483811684831611615cb757615c67565b1690615d0d565b615e82565b90615c67565b91615cb291612c7d936001600160a01b0382166001600160a01b03821611615d07575b615d006001600160a01b0391615cfa838516848316615da7565b93615c67565b1691615e02565b90615ce0565b908160601b905f196c0100000000000000000000000084099282808510940393808503948584111561288b5714615da0576c0100000000000000000000000082910981805f03168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b5091500490565b90808202915f19828209918380841093039280840393846c01000000000000000000000000111561288b5714615df9576c01000000000000000000000000910990828211900360a01b910360601c1790565b50505060601c90565b91818302915f198185099383808610950394808603958685111561288b5714615e7a579082910981805f03168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b505091500490565b906fffffffffffffffffffffffffffffffff8216809203615c3f5756fea164736f6c634300081a000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545000000000000000000000000a3256ab552a271a16acdfdb521b32ef82d481f43000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba30000000000000000000000000000000000000000000000000000000000030d4000000000000000000000000083ff9fc474dbe927ba5bb822571e0814122655bb0000000000000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _vault (address): 0x15d1e1eBe0c054791D6bff6D430b7e25b18C0545
Arg [1] : _clPoolManager (address): 0xA3256ab552A271A16AcDfdB521B32ef82d481F43
Arg [2] : _permit2 (address): 0x000000000022D473030F116dDEE9F6B43aC78BA3
Arg [3] : _unsubscribeGasLimit (uint256): 200000
Arg [4] : _tokenDescriptor (address): 0x83Ff9FC474DBe927BA5BB822571e0814122655bB
Arg [5] : _weth9 (address): 0x0000000000000000000000000000000000000000
-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 00000000000000000000000015d1e1ebe0c054791d6bff6d430b7e25b18c0545
Arg [1] : 000000000000000000000000a3256ab552a271a16acdfdb521b32ef82d481f43
Arg [2] : 000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3
Arg [3] : 0000000000000000000000000000000000000000000000000000000000030d40
Arg [4] : 00000000000000000000000083ff9fc474dbe927ba5bb822571e0814122655bb
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000000
Loading...
Loading
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ 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.