Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
Advanced mode: Intended for advanced users or developers and will display all Internal Transactions including zero value transfers.
Latest 20 internal transactions
Advanced mode:
| Parent Transaction Hash | Block | From | To | ||||
|---|---|---|---|---|---|---|---|
| 18151652 | 3 hrs ago | 0 ETH | |||||
| 18151652 | 3 hrs ago | 0 ETH | |||||
| 18151652 | 3 hrs ago | 0 ETH | |||||
| 18151652 | 3 hrs ago | 0 ETH | |||||
| 18151652 | 3 hrs ago | 0 ETH | |||||
| 18151652 | 3 hrs ago | 0 ETH | |||||
| 18151652 | 3 hrs ago | 0 ETH | |||||
| 18151615 | 3 hrs ago | 0 ETH | |||||
| 18151615 | 3 hrs ago | 0 ETH | |||||
| 18151615 | 3 hrs ago | 0 ETH | |||||
| 18151615 | 3 hrs ago | 0 ETH | |||||
| 18151615 | 3 hrs ago | 0 ETH | |||||
| 18151615 | 3 hrs ago | 0 ETH | |||||
| 18151615 | 3 hrs ago | 0 ETH | |||||
| 18151615 | 3 hrs ago | 0 ETH | |||||
| 18151615 | 3 hrs ago | 0 ETH | |||||
| 18149828 | 3 hrs ago | 0 ETH | |||||
| 18149828 | 3 hrs ago | 0 ETH | |||||
| 18149828 | 3 hrs ago | 0 ETH | |||||
| 18149828 | 3 hrs ago | 0 ETH |
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Source Code Verified (Exact Match)
Contract Name:
EverlongALM
Compiler Version
v0.8.26+commit.8a97fa7a
Optimization Enabled:
Yes with 1 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.26;
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin-upgradeable/contracts/proxy/utils/UUPSUpgradeable.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {IUniswapV3MintCallback} from "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3MintCallback.sol";
import {IUniswapV3SwapCallback} from "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol";
import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {PositionKey} from "@uniswap/v3-periphery/contracts/libraries/PositionKey.sol";
import {TickMath} from "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import {IEverlongALM, SwappersLib, SafeERC20, IPriceFeed, IALMGetters, IERC20} from "src/interfaces/core/alm/IEverlongALM.sol";
import {ALMLib} from "src/core/alm/library/ALMLib.sol";
/**
* @title Everlong ALM Vault
* @notice A vault that provides liquidity on Uniswap V3.
* @dev Modified from Alpha Pro Vault, from Charm Finance
*/
contract EverlongALM is
IEverlongALM,
IUniswapV3MintCallback,
IUniswapV3SwapCallback,
ERC20Upgradeable,
ReentrancyGuardUpgradeable,
UUPSUpgradeable
{
using SafeERC20 for IERC20;
using SwappersLib for SwappersLib.SwapperData;
uint24 constant HUNDRED_PERCENT = 1e6;
// keccak256(abi.encode(uint(keccak256("openzeppelin.storage.EverlongALM")) - 1)) & ~bytes32(uint(0xff))
bytes32 private constant EverlongALMStorageLocation = 0xb4801203179a1f53d2a89513756c4fddeb24d0f949ce9fc7cf03114c341dc500;
function _getEverlongALMStorage() internal pure returns (EverlongALMStorage storage store) {
assembly {
store.slot := EverlongALMStorageLocation
}
}
function _authorizeUpgrade(address newImplementation) internal override onlyManager {}
/// @dev 'manager' is the operations multisig
/// @dev 'rebalanceDelegate' is a keeper charged on rebalances
/// @dev 'activeRebalancing needs both tokens to be priceable by priceFeed
function initialize(VaultParams memory _params) public initializer {
__ERC20_init(_params.name, _params.symbol);
__ReentrancyGuard_init();
EverlongALMStorage storage $ = _getEverlongALMStorage();
$.owner = _params.owner;
$.pool = IUniswapV3Pool(_params.pool);
$.priceFeed = IPriceFeed(_params.priceFeed);
$.token0 = IERC20($.pool.token0());
$.token1 = IERC20($.pool.token1());
int24 _tickSpacing = $.tickSpacing = $.pool.tickSpacing();
$.maxTick = TickMath.MAX_TICK / _tickSpacing * _tickSpacing;
$.manager = _params.manager;
$.rebalanceDelegate = _params.rebalanceDelegate;
$.depositDelegate = _params.depositDelegate;
$.maxTotalSupply = _params.maxTotalSupply;
$.baseThreshold = _params.baseThreshold;
$.limitThreshold = _params.limitThreshold;
$.wideRangeWeight = _params.wideRangeWeight;
$.wideThreshold = _params.wideThreshold;
$.period = _params.period;
$.minTickMove = _params.minTickMove;
$.maxTwapDeviation = _params.maxTwapDeviation;
$.twapDuration = _params.twapDuration;
$.protocolFee = _params.protocolFee;
$.swapDeviationThreshold = _params.swapDeviationThreshold;
$.ratioDeviationThreshold = _params.ratioDeviationThreshold;
$.rebalanceDelegateCooldown = _params.rebalanceDelegateCooldown;
$.lastRatioDeviationThresholdUpdateTimestamp = uint40(block.timestamp);
$.maxRatioDeviationThresholdIncrease = _params.maxRatioDeviationThresholdIncrease;
$.getters = IALMGetters(_params.getters);
_checkThreshold(_params.baseThreshold, _tickSpacing);
_checkThreshold(_params.limitThreshold, _tickSpacing);
_checkThreshold(_params.wideThreshold, _tickSpacing);
if (_params.wideRangeWeight > HUNDRED_PERCENT) revert EV_WideRangeWeight();
if (_params.minTickMove < 0) revert EV_MinTickMove();
if (_params.maxTwapDeviation < 0) revert EV_MaxTwapDeviation();
if (_params.twapDuration == 0) revert EV_TwapDuration();
if (_params.wideThreshold == _params.baseThreshold) revert EV_ThresholdsCannotBeSame();
if (_params.swapDeviationThreshold > HUNDRED_PERCENT) revert EV_SwapDeviationThreshold();
if (_params.ratioDeviationThreshold > HUNDRED_PERCENT) revert EV_RatioDeviationThreshold();
if (_params.rebalanceDelegateCooldown == 0) revert EV_RebalanceDelegateCooldown();
if (_params.maxRatioDeviationThresholdIncrease == 0) revert EV_MaxRatioDeviationThresholdIncrease();
for (uint i; i < _params.initialWhitelistedSwappers.length; ++i) {
$.swapperData.addWhitelistedSwapper(_params.initialWhitelistedSwappers[i], true);
}
}
/**
* @notice Deposits tokens in proportion to the vault's current holdings.
* @dev Tokens are deposited directly into a Uniswap pool. Also
* note it's not necessary to check if user manipulated price to deposit
* cheaper, as the value of range orders can only be manipulated higher.
* @param amount0Desired Max amount of token0 to deposit
* @param amount1Desired Max amount of token1 to deposit
* @param amount0Min Revert if resulting `amount0` is less than this
* @param amount1Min Revert if resulting `amount1` is less than this
* @param to Recipient of shares
* @return shares Number of shares minted
* @return amount0 Amount of token0 deposited
* @return amount1 Amount of token1 deposited
*/
function deposit(uint256 amount0Desired, uint256 amount1Desired, uint256 amount0Min, uint256 amount1Min, address to)
external
override
nonReentrant
returns (uint256 shares, uint256 amount0, uint256 amount1)
{
EverlongALMStorage storage $ = _getEverlongALMStorage();
if ($.depositDelegate != address(0)) {
if (msg.sender != $.depositDelegate) revert EV_NotDepositDelegate();
}
if (amount0Desired == 0 && amount1Desired == 0) revert EV_ZeroDepositAmount();
if (to == address(0) || to == address(this)) revert EV_InvalidRecipient();
$.getters.checkPriceNearTwap();
// Poke positions so vault's current holdings are up-to-date
int24[2][3] memory positions = getPositions();
uint128[3] memory liquidities;
for (uint256 i; i < 3; i++) {
(liquidities[i],,,,) = _position(positions[i][0], positions[i][1]);
if (liquidities[i] > 0) {
$.pool.burn(positions[i][0], positions[i][1], 0);
}
}
// Calculate amounts proportional to vault's holdings
uint256 _totalSupply = totalSupply();
(shares, amount0, amount1) =
_calcDepositSharesAndAmounts($, _totalSupply, amount0Desired, amount1Desired);
if (shares == 0) revert EV_ZeroShares();
if (amount0 < amount0Min) revert EV_Amount0Min();
if (amount1 < amount1Min) revert EV_Amount1Min();
// Permanently lock the first MINIMUM_LIQUIDITY tokens
if (_totalSupply == 0) {
_mint(address(0xdead), ALMLib.MINIMUM_LIQUIDITY);
}
// Pull in tokens from sender
if (amount0 > 0) $.token0.safeTransferFrom(msg.sender, address(this), amount0);
if (amount1 > 0) $.token1.safeTransferFrom(msg.sender, address(this), amount1);
_totalSupply = _totalSupply == 0 ? _totalSupply + ALMLib.MINIMUM_LIQUIDITY : _totalSupply;
(uint160 sqrtRatioX96,,,,,,) = $.pool.slot0();
(uint256 depositAmount0, uint256 depositAmount1) = (amount0, amount1);
for (uint256 i; i < 3; i++) {
int24 tickLower = positions[i][0];
int24 tickUpper = positions[i][1];
if (liquidities[i] > 0) {
uint128 liquidityToMint = uint128(Math.mulDiv(liquidities[i], shares, _totalSupply));
uint128 liquidityFromAmounts =
ALMLib._liquidityForAmounts(tickLower, tickUpper, depositAmount0, depositAmount1, sqrtRatioX96);
liquidityToMint = liquidityToMint > liquidityFromAmounts ? liquidityFromAmounts : liquidityToMint;
(uint256 mintAmount0, uint256 mintAmount1) = _mintLiquidity(tickLower, tickUpper, liquidityToMint);
depositAmount0 -= mintAmount0;
depositAmount1 -= mintAmount1;
}
}
// Mint shares to recipient
_mint(to, shares);
emit Deposit(msg.sender, to, shares, amount0, amount1);
if (totalSupply() > $.maxTotalSupply) revert EV_MaxTotalSupply();
}
function _calcDepositSharesAndAmounts(
EverlongALMStorage storage $,
uint256 totalSupply_,
uint256 amount0Desired,
uint256 amount1Desired
) private view returns (uint256 shares, uint256 amount0, uint256 amount1) {
(uint256 total0, uint256 total1) = $.getters.getTotalAmounts(true);
(shares, amount0, amount1) =
ALMLib._calcSharesAndAmounts(totalSupply_, total0, total1, amount0Desired, amount1Desired);
}
/**
* @notice Withdraw tokens in proportion to the vault's holdings.
* @param shares Shares burned by sender
* @param amount0Min Revert if resulting `amount0` is smaller than this
* @param amount1Min Revert if resulting `amount1` is smaller than this
* @param to Recipient of tokens
* @return amount0 Amount of token0 sent to recipient
* @return amount1 Amount of token1 sent to recipient
*/
function withdraw(uint256 shares, uint256 amount0Min, uint256 amount1Min, address to)
external
override
nonReentrant
returns (uint256 amount0, uint256 amount1)
{
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (shares == 0) revert EV_ZeroShares();
if (to == address(0) || to == address(this)) revert EV_InvalidRecipient();
uint256 _totalSupply = totalSupply();
// Burn shares
_burn(msg.sender, shares);
// Calculate token amounts proportional to unused balances
amount0 = (getBalance0() * shares) / _totalSupply;
amount1 = (getBalance1() * shares) / _totalSupply;
// Withdraw proportion of liquidity from Uniswap pool
BurnContext memory b;
(b.wideAmount0, b.wideAmount1) = _burnLiquidityShare($.wideLower, $.wideUpper, shares, _totalSupply);
(b.baseAmount0, b.baseAmount1) = _burnLiquidityShare($.baseLower, $.baseUpper, shares, _totalSupply);
(b.limitAmount0, b.limitAmount1) = _burnLiquidityShare($.limitLower, $.limitUpper, shares, _totalSupply);
// Sum up total amounts owed to recipient
amount0 = amount0 + b.wideAmount0 + b.baseAmount0 + b.limitAmount0;
amount1 = amount1 + b.wideAmount1 + b.baseAmount1 + b.limitAmount1;
if (amount0 < amount0Min) revert EV_Amount0Min();
if (amount1 < amount1Min) revert EV_Amount1Min();
// Push tokens to recipient
if (amount0 > 0) $.token0.safeTransfer(to, amount0);
if (amount1 > 0) $.token1.safeTransfer(to, amount1);
emit Withdraw(msg.sender, to, shares, amount0, amount1);
}
/// @dev Withdraws share of liquidity in a range from Uniswap pool.
function _burnLiquidityShare(int24 tickLower, int24 tickUpper, uint256 shares, uint256 _totalSupply)
internal
returns (uint256 amount0, uint256 amount1)
{
(uint128 totalLiquidity,,,,) = _position(tickLower, tickUpper);
uint128 liquidity = uint128(Math.mulDiv(totalLiquidity, shares, _totalSupply));
if (liquidity > 0) {
(uint256 burned0, uint256 burned1, uint128 fees0, uint128 fees1) =
_burnAndCollect(tickLower, tickUpper, liquidity);
// Add share of fees
amount0 = burned0 + ((fees0 * shares) / _totalSupply);
amount1 = burned1 + ((fees1 * shares) / _totalSupply);
}
}
/**
* @notice Updates vault's positions.
* @dev Three orders are placed - a wide-range order, a base order and a
* limit order. The wide-range order is placed first. Then the base
* order is placed with as much remaining liquidity as possible. This order
* should use up all of one token, leaving only the other one. This excess
* amount is then placed as a single-sided bid or ask order.
*/
function rebalance() external override nonReentrant onlyManagerOrRebalanceDelegate {
_getEverlongALMStorage().getters.checkCanRebalance();
// Withdraw all current liquidity from Uniswap pool
_withdrawLiquidity();
// Recalculate and place new liquidity positions
_rebalance(_noSwap());
}
/**
* @notice Swaps limit order for the vault to end up in a balanced state, maximizes liquidity position during rebalance by keeping wide and base.
* @dev Keeper should overswap the limit order to counteract the further imbalancing that the swapping through internal liquidity could cause
* @dev Steps:
* 1. Withdraw all positions
* 2. Add wide and base
* 3. Swap half of limit order to the other token (includes check for slippage loss and ratio accuracy given oracle price)
* 4. Withdraw wide and base
* 5. Deposit everything
*/
function activeRebalance(ExternalRebalanceParams memory swapParams) external nonReentrant onlyManagerOrRebalanceDelegate {
if (swapParams.swapper == address(0)) revert EV_ZeroAddress();
_withdrawLiquidity();
_rebalance(swapParams);
_withdrawLiquidity({ withdrawLimit: false });
_rebalance(_noSwap());
}
function _swapImbalance(ExternalRebalanceParams memory params, uint256 balance0, uint256 balance1) internal {
EverlongALMStorage storage $ = _getEverlongALMStorage();
address tokenIn = params.isZeroForOne ? address($.token0) : address($.token1);
address tokenOut = params.isZeroForOne ? address($.token1) : address($.token0);
IPriceFeed priceFeed = $.priceFeed;
/// @dev Intentionally fetching price before external call
/// @dev Make sure token0 and token1 of this pool are not fetched by pull feeds or spot oracles
uint256 sentPrice = priceFeed.fetchPrice(tokenIn);
uint256 receivedPrice = priceFeed.fetchPrice(tokenOut);
uint256 tokenOutBalanceBefore = params.isZeroForOne ? balance1 : balance0;
uint256 tokenInBalanceBefore = params.isZeroForOne ? balance0 : balance1;
/// @dev Avoid sending tokens reserved for protocol fees
if (params.sentAmount > tokenInBalanceBefore)
revert EV_InsufficientBalance(tokenInBalanceBefore, params.sentAmount);
IERC20(tokenIn).forceApprove(params.swapper, params.sentAmount);
$.swapperData.executeSwap(params.swapper, params.payload);
/// @dev Make sure allowance is zeroed out
IERC20(tokenIn).forceApprove(params.swapper, 0);
$.getters.checkMaxSlippageAndRatioDeviation(
params,
tokenOutBalanceBefore,
tokenIn,
tokenOut,
sentPrice,
receivedPrice
);
}
function _noSwap() internal pure returns (ExternalRebalanceParams memory) {
return ExternalRebalanceParams(false, 0, address(0), "", 0);
}
function _rebalance(ExternalRebalanceParams memory swapParams) internal {
EverlongALMStorage storage $ = _getEverlongALMStorage();
// Calculate new ranges
(uint160 sqrtRatioX96, int24 tick,,,,,) = $.pool.slot0();
int24 _bidLower;
int24 _bidUpper;
int24 _askLower;
int24 _askUpper;
{
int24 tickFloor = ALMLib._floor(tick, $.tickSpacing);
int24 tickCeil = tickFloor + $.tickSpacing;
int24 _maxTick = $.maxTick;
$.wideLower = ALMLib._boundTick(tickFloor - $.wideThreshold, _maxTick);
$.wideUpper = ALMLib._boundTick(tickCeil + $.wideThreshold, _maxTick);
$.baseLower = tickFloor - $.baseThreshold;
$.baseUpper = tickCeil + $.baseThreshold;
_bidLower = tickFloor - $.limitThreshold;
_bidUpper = tickFloor;
_askLower = tickCeil;
_askUpper = tickCeil + $.limitThreshold;
}
// Emit snapshot to record balances and supply
uint256 balance0 = getBalance0();
uint256 balance1 = getBalance1();
emit Snapshot(tick, balance0, balance1, totalSupply());
// Place wide range order on Uniswap
if ($.wideRangeWeight > 0) {
uint128 wideLiquidity = ALMLib._liquidityForAmounts($.wideLower, $.wideUpper, balance0, balance1, sqrtRatioX96);
wideLiquidity = _toUint128((uint256(wideLiquidity) * $.wideRangeWeight) / HUNDRED_PERCENT);
(uint256 mintAmount0, uint256 mintAmount1) = _mintLiquidity($.wideLower, $.wideUpper, wideLiquidity);
balance0 -= mintAmount0;
balance1 -= mintAmount1;
}
// Place base order on Uniswap
{
uint128 baseLiquidity = ALMLib._liquidityForAmounts($.baseLower, $.baseUpper, balance0, balance1, sqrtRatioX96);
(uint256 mintAmount0, uint256 mintAmount1) = _mintLiquidity($.baseLower, $.baseUpper, baseLiquidity);
balance0 -= mintAmount0;
balance1 -= mintAmount1;
}
if (swapParams.swapper != address(0)) {
_swapImbalance(swapParams, balance0, balance1);
} else {
// Place bid or ask order on Uniswap depending on which token is left
uint128 bidLiquidity = ALMLib._liquidityForAmounts(_bidLower, _bidUpper, balance0, balance1, sqrtRatioX96);
uint128 askLiquidity = ALMLib._liquidityForAmounts(_askLower, _askUpper, balance0, balance1, sqrtRatioX96);
if (bidLiquidity > askLiquidity) {
_mintLiquidity(_bidLower, _bidUpper, bidLiquidity);
$.limitLower = _bidLower;
$.limitUpper = _bidUpper;
} else {
_mintLiquidity(_askLower, _askUpper, askLiquidity);
$.limitLower = _askLower;
$.limitUpper = _askUpper;
}
}
$.lastTimestamp = uint40(block.timestamp);
$.lastTick = tick;
// Update fee only at each rebalance, so that if fee is changed
// it won't be applied retroactively to current open positions
uint24 pendingProtocolFeePlusOne = $.pendingProtocolFee;
uint24 _protocolFee = $.protocolFee;
if (pendingProtocolFeePlusOne != 0) {
uint24 newProtocolFee = pendingProtocolFeePlusOne - 1;
$.protocolFee = newProtocolFee;
_protocolFee = newProtocolFee;
$.pendingProtocolFee = 0;
}
}
function _withdrawLiquidity() internal {
_withdrawLiquidity(true);
}
function _withdrawLiquidity(bool withdrawLimit) internal {
EverlongALMStorage storage $ = _getEverlongALMStorage();
int24 _wideLower = $.wideLower;
int24 _wideUpper = $.wideUpper;
int24 _baseLower = $.baseLower;
int24 _baseUpper = $.baseUpper;
(uint128 wideLiquidity,,,,) = _position(_wideLower, _wideUpper);
(uint128 baseLiquidity,,,,) = _position(_baseLower, _baseUpper);
_burnAndCollect(_wideLower, _wideUpper, wideLiquidity);
_burnAndCollect(_baseLower, _baseUpper, baseLiquidity);
if (withdrawLimit) {
int24 _limitLower = $.limitLower;
int24 _limitUpper = $.limitUpper;
(uint128 limitLiquidity,,,,) = _position(_limitLower, _limitUpper);
_burnAndCollect(_limitLower, _limitUpper, limitLiquidity);
}
}
function _checkThreshold(int24 threshold, int24 _tickSpacing) internal pure {
if (threshold <= 0) revert EV_ThresholdNotPositive();
if (threshold % _tickSpacing != 0) revert EV_ThresholdNotMultipleOfTickSpacing();
}
/// @dev Withdraws liquidity from a range and collects all fees in the
/// process.
function _burnAndCollect(int24 tickLower, int24 tickUpper, uint128 liquidity)
internal
returns (uint256 burned0, uint256 burned1, uint128 feesToVault0, uint128 feesToVault1)
{
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (liquidity > 0) {
(burned0, burned1) = $.pool.burn(tickLower, tickUpper, liquidity);
}
// Collect all owed tokens including earned fees
(uint128 collect0, uint128 collect1) =
$.pool.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max);
feesToVault0 = uint128(collect0 - burned0);
feesToVault1 = uint128(collect1 - burned1);
// Update accrued protocol fees
uint24 _protocolFee = $.protocolFee;
uint128 feesToProtocol0 = feesToVault0 * _protocolFee / HUNDRED_PERCENT;
uint128 feesToProtocol1 = feesToVault1 * _protocolFee / HUNDRED_PERCENT;
$.accruedProtocolFees0 += feesToProtocol0;
$.accruedProtocolFees1 += feesToProtocol1;
feesToVault0 -= feesToProtocol0;
feesToVault1 -= feesToProtocol1;
emit CollectFees(feesToVault0, feesToVault1, feesToProtocol0, feesToProtocol1);
}
/// @dev Deposits liquidity in a range on the Uniswap pool.
function _mintLiquidity(int24 tickLower, int24 tickUpper, uint128 liquidity)
internal
returns (uint256 amount0, uint256 amount1)
{
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (liquidity > 0) {
(amount0, amount1) = $.pool.mint(address(this), tickLower, tickUpper, liquidity, "");
}
}
/**
* @notice Calculates the vault's total holdings of token0 and token1 - in
* other words, how much of each token the vault would hold if it withdrew
* all its liquidity from Uniswap.
*/
function getTotalAmounts() public view override returns (uint256 total0, uint256 total1) {
(total0, total1) = _getEverlongALMStorage().getters.getTotalAmounts(false);
}
/**
* @notice Balance of token0 in vault not used in any position.
*/
function getBalance0() public view override returns (uint256) {
EverlongALMStorage storage $ = _getEverlongALMStorage();
return $.token0.balanceOf(address(this)) - $.accruedProtocolFees0;
}
/**
* @notice Balance of token1 in vault not used in any position.
*/
function getBalance1() public view override returns (uint256) {
EverlongALMStorage storage $ = _getEverlongALMStorage();
return $.token1.balanceOf(address(this)) - $.accruedProtocolFees1;
}
/**
* @notice Returns the ranges of the vault's positions.
*/
function getPositions() public view returns (int24[2][3] memory) {
EverlongALMStorage storage $ = _getEverlongALMStorage();
return [[$.wideLower, $.wideUpper], [$.baseLower, $.baseUpper], [$.limitLower, $.limitUpper]];
}
/// @dev Wrapper around `IUniswapV3Pool.positions()`.
function _position(int24 tickLower, int24 tickUpper)
internal
view
returns (uint128, uint256, uint256, uint128, uint128)
{
EverlongALMStorage storage $ = _getEverlongALMStorage();
bytes32 positionKey = PositionKey.compute(address(this), tickLower, tickUpper);
return $.pool.positions(positionKey);
}
/// @dev Casts uint256 to uint128 with overflow check.
function _toUint128(uint256 x) internal pure returns (uint128) {
assert(x <= type(uint128).max);
return uint128(x);
}
/// @dev Callback for Uniswap V3 pool.
function uniswapV3MintCallback(uint256 amount0, uint256 amount1, bytes calldata) external override {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (msg.sender != address($.pool)) revert EV_NotPool();
if (amount0 > 0) $.token0.safeTransfer(msg.sender, amount0);
if (amount1 > 0) $.token1.safeTransfer(msg.sender, amount1);
}
/// @dev Callback for Uniswap V3 pool.
function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata) external override {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (msg.sender != address($.pool)) revert EV_NotPool();
if (amount0Delta > 0) $.token0.safeTransfer(msg.sender, uint256(amount0Delta));
if (amount1Delta > 0) $.token1.safeTransfer(msg.sender, uint256(amount1Delta));
}
/**
* @notice Used to collect accumulated protocol fees.
*/
function collectProtocol(address to) external {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (msg.sender != $.owner) revert EV_NotGovernance();
uint256 _accruedProtocolFees0 = $.accruedProtocolFees0;
uint256 _accruedProtocolFees1 = $.accruedProtocolFees1;
$.accruedProtocolFees0 = 0;
$.accruedProtocolFees1 = 0;
if (_accruedProtocolFees0 > 0) $.token0.safeTransfer(to, _accruedProtocolFees0);
if (_accruedProtocolFees1 > 0) $.token1.safeTransfer(to, _accruedProtocolFees1);
emit CollectProtocol(_accruedProtocolFees0, _accruedProtocolFees1);
}
/**
* @notice Change the protocol fee charged on pool fees earned from
* Uniswap, expressed as multiple of 1e-6. Fee is hard capped at 25%.
*/
function setProtocolFee(uint24 _pendingProtocolFee) external {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (msg.sender != $.owner) revert EV_NotGovernance();
if (_pendingProtocolFee > 25e4) revert EV_ProtocolFeeTooHigh();
// Store value with +1 so zero remains a sentinel meaning "no pending update"
$.pendingProtocolFee = _pendingProtocolFee + 1;
emit UpdateProtocolFee(_pendingProtocolFee);
}
function addWhitelistedSwapper(
address _swapRouter,
bool status
) external {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (msg.sender != $.owner) revert EV_NotGovernance();
if (_swapRouter == address(0)) revert EV_ZeroAddress();
$.swapperData.addWhitelistedSwapper(_swapRouter, status);
}
/**
* @notice Removes tokens accidentally sent to this vault.
*/
function sweep(IERC20 token, uint256 amount, address to) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (token == $.token0 || token == $.token1) revert EV_SweepToken();
token.safeTransfer(to, amount);
}
function setBaseThreshold(int24 _baseThreshold) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (_baseThreshold == $.wideThreshold) revert EV_ThresholdsCannotBeSame();
_checkThreshold(_baseThreshold, $.tickSpacing);
$.baseThreshold = _baseThreshold;
emit UpdateBaseThreshold(_baseThreshold);
}
function setLimitThreshold(int24 _limitThreshold) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
_checkThreshold(_limitThreshold, $.tickSpacing);
$.limitThreshold = _limitThreshold;
emit UpdateLimitThreshold(_limitThreshold);
}
function setWideRangeWeight(uint24 _wideRangeWeight) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (_wideRangeWeight > HUNDRED_PERCENT) revert EV_WideRangeWeight();
$.wideRangeWeight = _wideRangeWeight;
emit UpdateWideRangeWeight(_wideRangeWeight);
}
function setWideThreshold(int24 _wideThreshold) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (_wideThreshold == $.baseThreshold) revert EV_ThresholdsCannotBeSame();
_checkThreshold(_wideThreshold, $.tickSpacing);
$.wideThreshold = _wideThreshold;
emit UpdateWideThreshold(_wideThreshold);
}
function setPeriod(uint32 _period) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
$.period = _period;
emit UpdatePeriod(_period);
}
function setMinTickMove(int24 _minTickMove) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (_minTickMove < 0) revert EV_MinTickMove();
$.minTickMove = _minTickMove;
emit UpdateMinTickMove(_minTickMove);
}
function setMaxTwapDeviation(int24 _maxTwapDeviation) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (_maxTwapDeviation < 0) revert EV_MaxTwapDeviation();
$.maxTwapDeviation = _maxTwapDeviation;
emit UpdateMaxTwapDeviation(_maxTwapDeviation);
}
function setTwapDuration(uint32 _twapDuration) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (_twapDuration == 0) revert EV_TwapDuration();
$.twapDuration = _twapDuration;
emit UpdateTwapDuration(_twapDuration);
}
function setSwapDeviationThreshold(uint24 _swapDeviationThreshold) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (_swapDeviationThreshold > HUNDRED_PERCENT) revert EV_SwapDeviationThreshold();
$.swapDeviationThreshold = _swapDeviationThreshold;
emit UpdateSwapDeviationThreshold(_swapDeviationThreshold);
}
/**
* @dev If the value is low (tight), only activeRebalances that bring the reserves value ratio close to 1:1, will be allowed
* If there are liquidity or costs constraints, it's possible for the rebalance delegate keeper to progressively increase the allowed threshold to perform the rebalance progressively
* The rationale is to avoid large imbalances if the keeper turns malicious.
* An external service will look if the ratio deviations being requested by the keeper align with onchain liquidity needs, if not, it may alert governance to take action.
* @dev Lower ratio deviation thresholds are not affected by any cooldown
*/
function setRatioDeviationThreshold(uint24 _ratioDeviationThreshold) external onlyManagerOrRebalanceDelegate {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (_ratioDeviationThreshold > HUNDRED_PERCENT) revert EV_RatioDeviationThreshold();
if (_ratioDeviationThreshold > $.ratioDeviationThreshold) {
// increasing the threshold, check it's within allowed limits
uint256 effectiveTimeSinceLastUpdate = Math.min(block.timestamp - $.lastRatioDeviationThresholdUpdateTimestamp, $.rebalanceDelegateCooldown);
uint256 maxAllowedIncrease =
effectiveTimeSinceLastUpdate * $.maxRatioDeviationThresholdIncrease / $.rebalanceDelegateCooldown;
if (_ratioDeviationThreshold > $.ratioDeviationThreshold + maxAllowedIncrease) {
revert EV_RatioDeviationThresholdIncreaseExceeded(
_ratioDeviationThreshold,
$.ratioDeviationThreshold + maxAllowedIncrease
);
}
}
$.ratioDeviationThreshold = _ratioDeviationThreshold;
$.lastRatioDeviationThresholdUpdateTimestamp = uint40(block.timestamp);
emit UpdateRatioDeviationThreshold(_ratioDeviationThreshold);
}
/**
* @dev Sets a cooldown period for the rebalance delegate to prevent frequent 'setRatioDeviationThreshold' updates
*/
function setRebalanceDelegateCooldown(uint24 _rebalanceDelegateCooldown) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (_rebalanceDelegateCooldown == 0) revert EV_RebalanceDelegateCooldown();
$.rebalanceDelegateCooldown = _rebalanceDelegateCooldown;
emit UpdateRebalanceDelegateCooldown(_rebalanceDelegateCooldown);
}
function setMaxRatioDeviationThresholdIncrease(uint24 _maxRatioDeviationThresholdIncrease) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (_maxRatioDeviationThresholdIncrease > HUNDRED_PERCENT) revert EV_MaxRatioDeviationThresholdIncrease();
$.maxRatioDeviationThresholdIncrease = _maxRatioDeviationThresholdIncrease;
emit UpdateMaxRatioDeviationThresholdIncrease(_maxRatioDeviationThresholdIncrease);
}
/**
* @notice Used to change deposit cap for a guarded launch or to ensure
* vault doesn't grow too large relative to the pool. Cap is on total
* supply rather than amounts of token0 and token1 as those amounts
* fluctuate naturally over time.
*/
function setMaxTotalSupply(uint256 _maxTotalSupply) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
$.maxTotalSupply = _maxTotalSupply;
emit UpdateMaxTotalSupply(_maxTotalSupply);
}
/**
* @notice Removes all liquidity from all positions in case of emergency.
* @dev Can as well be called if the manager foresees the strategy no longer being profitable
*/
function fullEmergencyBurn() external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
_emergencyBurn($.wideLower, $.wideUpper, type(uint128).max);
_emergencyBurn($.baseLower, $.baseUpper, type(uint128).max);
_emergencyBurn($.limitLower, $.limitUpper, type(uint128).max);
}
function _emergencyBurn(int24 tickLower, int24 tickUpper, uint128 liquidity) internal {
EverlongALMStorage storage $ = _getEverlongALMStorage();
$.pool.burn(tickLower, tickUpper, liquidity);
$.pool.collect(address(this), tickLower, tickUpper, type(uint128).max, type(uint128).max);
}
/**
* @notice Manager address is not updated until the new manager
* address has called `acceptManager()` to accept this responsibility.
*/
function setManager(address _manager) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
$.pendingManager = _manager;
emit UpdatePendingManager(_manager);
}
function setDepositDelegate(address _depositDelegate) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
$.depositDelegate = _depositDelegate;
emit UpdateDepositDelegate(_depositDelegate);
}
function setRebalanceDelegate(address _rebalanceDelegate) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
$.rebalanceDelegate = _rebalanceDelegate;
emit UpdateRebalanceDelegate(_rebalanceDelegate);
}
function setGetters(address _getters) external onlyManager {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (_getters == address(0)) revert EV_ZeroAddress();
$.getters = IALMGetters(_getters);
emit UpdateGetters(_getters);
}
/**
* @notice `setManager()` should be called by the existing manager
* address prior to calling this function.
*/
function acceptManager() external {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (msg.sender != $.pendingManager) revert EV_NotPendingManager();
$.manager = msg.sender;
$.pendingManager = address(0);
emit UpdateManager(msg.sender);
}
modifier onlyManager() {
_onlyManager();
_;
}
function _onlyManager() private view {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (msg.sender != $.manager) revert EV_NotManager();
}
modifier onlyManagerOrRebalanceDelegate() {
_onlyManagerOrDelegate();
_;
}
function _onlyManagerOrDelegate() private view {
EverlongALMStorage storage $ = _getEverlongALMStorage();
if (msg.sender != $.manager && msg.sender != $.rebalanceDelegate) {
revert EV_NotManagerOrRebalanceDelegate();
}
}
function pool() external view override returns (IUniswapV3Pool) {
return _getEverlongALMStorage().pool;
}
function protocolFee() external view override returns (uint24) {
return _getEverlongALMStorage().protocolFee;
}
/* STORAGE VIEW */
function extSloads(bytes32[] memory slots) external view override returns (bytes32[] memory res) {
uint nSlots = slots.length;
res = new bytes32[](nSlots);
for (uint i; i < nSlots;) {
bytes32 slot = slots[i++];
assembly ("memory-safe") {
mstore(add(res, mul(i, 32)), sload(slot))
}
}
}
function token0() external view override returns (address) {
return address(_getEverlongALMStorage().token0);
}
function token1() external view override returns (address) {
return address(_getEverlongALMStorage().token1);
}
function totalSupply() public view override(ERC20Upgradeable, IEverlongALM) returns (uint256) {
return super.totalSupply();
}
function balanceOf(address account) public view override(ERC20Upgradeable, IEverlongALM) returns (uint256) {
return super.balanceOf(account);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {ContextUpgradeable} from "../../utils/ContextUpgradeable.sol";
import {IERC20Errors} from "../../lib/openzeppelin-contracts/contracts/interfaces/draft-IERC6093.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20, IERC20Metadata, IERC20Errors {
/// @custom:storage-location erc7201:openzeppelin.storage.ERC20
struct ERC20Storage {
mapping(address account => uint256) _balances;
mapping(address account => mapping(address spender => uint256)) _allowances;
uint256 _totalSupply;
string _name;
string _symbol;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC20")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ERC20StorageLocation = 0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00;
function _getERC20Storage() private pure returns (ERC20Storage storage $) {
assembly {
$.slot := ERC20StorageLocation
}
}
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC20_init_unchained(name_, symbol_);
}
function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
ERC20Storage storage $ = _getERC20Storage();
$._name = name_;
$._symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
ERC20Storage storage $ = _getERC20Storage();
return $._name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
ERC20Storage storage $ = _getERC20Storage();
return $._symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
ERC20Storage storage $ = _getERC20Storage();
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
$._totalSupply += value;
} else {
uint256 fromBalance = $._balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
$._balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
$._totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
$._balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
ERC20Storage storage $ = _getERC20Storage();
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
$._allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardUpgradeable is Initializable {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
/// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
struct ReentrancyGuardStorage {
uint256 _status;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
assembly {
$.slot := ReentrancyGuardStorageLocation
}
}
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
$._status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
// On the first call to nonReentrant, _status will be NOT_ENTERED
if ($._status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
$._status = ENTERED;
}
function _nonReentrantAfter() private {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
$._status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
return $._status == ENTERED;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.20;
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "../../lib/openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable __self = address(this);
/**
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
* and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
* while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
* If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
* during an upgrade.
*/
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
/**
* @dev The call is from an unauthorized context.
*/
error UUPSUnauthorizedCallContext();
/**
* @dev The storage `slot` is unsupported as a UUID.
*/
error UUPSUnsupportedProxiableUUID(bytes32 slot);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
_checkProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
_checkNotDelegated();
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual notDelegated returns (bytes32) {
return ERC1967Utils.IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data);
}
/**
* @dev Reverts if the execution is not performed via delegatecall or the execution
* context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
* See {_onlyProxy}.
*/
function _checkProxy() internal view virtual {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Reverts if the execution is performed via delegatecall.
* See {notDelegated}.
*/
function _checkNotDelegated() internal view virtual {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
*
* As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
* is expected to be the implementation slot in ERC-1967.
*
* Emits an {IERC1967-Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
revert UUPSUnsupportedProxiableUUID(slot);
}
ERC1967Utils.upgradeToAndCall(newImplementation, data);
} catch {
// The implementation is not UUPS
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
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 for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the 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.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // 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 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Callback for IUniswapV3PoolActions#mint
/// @notice Any contract that calls IUniswapV3PoolActions#mint must implement this interface
interface IUniswapV3MintCallback {
/// @notice Called to `msg.sender` after minting liquidity to a position from IUniswapV3Pool#mint.
/// @dev In the implementation you must pay the pool tokens owed for the minted liquidity.
/// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
/// @param amount0Owed The amount of token0 due to the pool for the minted liquidity
/// @param amount1Owed The amount of token1 due to the pool for the minted liquidity
/// @param data Any data passed through by the caller via the IUniswapV3PoolActions#mint call
function uniswapV3MintCallback(
uint256 amount0Owed,
uint256 amount1Owed,
bytes calldata data
) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
/// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
/// @dev In the implementation you must pay the pool tokens owed for the swap.
/// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
/// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
/// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
/// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
/// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import {IUniswapV3PoolImmutables} from './pool/IUniswapV3PoolImmutables.sol';
import {IUniswapV3PoolState} from './pool/IUniswapV3PoolState.sol';
import {IUniswapV3PoolDerivedState} from './pool/IUniswapV3PoolDerivedState.sol';
import {IUniswapV3PoolActions} from './pool/IUniswapV3PoolActions.sol';
import {IUniswapV3PoolOwnerActions} from './pool/IUniswapV3PoolOwnerActions.sol';
import {IUniswapV3PoolErrors} from './pool/IUniswapV3PoolErrors.sol';
import {IUniswapV3PoolEvents} from './pool/IUniswapV3PoolEvents.sol';
/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
IUniswapV3PoolImmutables,
IUniswapV3PoolState,
IUniswapV3PoolDerivedState,
IUniswapV3PoolActions,
IUniswapV3PoolOwnerActions,
IUniswapV3PoolErrors,
IUniswapV3PoolEvents
{
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
library PositionKey {
/// @dev Returns the key of the position in the core library
function compute(
address owner,
int24 tickLower,
int24 tickUpper
) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(owner, tickLower, tickUpper));
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
error T();
error R();
/// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
int24 internal constant MIN_TICK = -887272;
/// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
int24 internal constant MAX_TICK = -MIN_TICK;
/// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
uint160 internal constant MIN_SQRT_RATIO = 4295128739;
/// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;
/// @notice Calculates sqrt(1.0001^tick) * 2^96
/// @dev Throws if |tick| > max tick
/// @param tick The input tick for the above formula
/// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
/// at the given tick
function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
unchecked {
uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
if (absTick > uint256(int256(MAX_TICK))) revert T();
uint256 ratio = absTick & 0x1 != 0
? 0xfffcb933bd6fad37aa2d162d1a594001
: 0x100000000000000000000000000000000;
if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;
if (tick > 0) ratio = type(uint256).max / ratio;
// this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
// we then downcast because we know the result always fits within 160 bits due to our tick input constraint
// we round up in the division so getTickAtSqrtRatio of the output price is always consistent
sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
}
}
/// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
/// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
/// ever return.
/// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
/// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
unchecked {
// second inequality must be < because the price can never reach the price at the max tick
if (!(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO)) revert R();
uint256 ratio = uint256(sqrtPriceX96) << 32;
uint256 r = ratio;
uint256 msb = 0;
assembly {
let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(5, gt(r, 0xFFFFFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(4, gt(r, 0xFFFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(3, gt(r, 0xFF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(2, gt(r, 0xF))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := shl(1, gt(r, 0x3))
msb := or(msb, f)
r := shr(f, r)
}
assembly {
let f := gt(r, 0x1)
msb := or(msb, f)
}
if (msb >= 128) r = ratio >> (msb - 127);
else r = ratio << (127 - msb);
int256 log_2 = (int256(msb) - 128) << 64;
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(63, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(62, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(61, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(60, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(59, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(58, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(57, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(56, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(55, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(54, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(53, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(52, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(51, f))
r := shr(f, r)
}
assembly {
r := shr(127, mul(r, r))
let f := shr(128, r)
log_2 := or(log_2, shl(50, f))
}
int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number
int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);
tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
}
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.26;
import {IERC20, SafeERC20} from "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {IPriceFeed} from "src/interfaces/core/oracles/IPriceFeed.sol";
import {IALMGetters} from "src/core/alm/getters/ALMGetters.sol";
import {SwappersLib} from "src/libraries/SwappersLib.sol";
interface IEverlongALM {
/**
* @param pool Underlying Uniswap V3 pool address
* @param manager Address of manager who can set parameters and call rebalance
* @param rebalanceDelegate Address of an additional wallet that can call rebalance
* @param maxTotalSupply Cap on the total supply of vault shares
* @param wideRangeWeight Proportion of liquidity in wide range multiplied by 1e6
* @param wideThreshold Half of the wide order width in ticks
* @param baseThreshold Half of the base order width in ticks
* @param limitThreshold Limit order width in ticks
* @param period Can only rebalance if this length of time (in seconds) has passed
* @param minTickMove Can only rebalance if price has moved at least this much
* @param maxTwapDeviation Max deviation (in ticks) from the TWAP during rebalance or deposit
* @param twapDuration TWAP duration in seconds for maxTwapDeviation check
* @param protocolFee % Fee charged to cover protocol costs, in BP
* @param name name of the vault to be created
* @param symbol symbol of the vault to be created
*/
struct VaultParams {
address owner;
address pool;
address priceFeed;
address manager;
address rebalanceDelegate;
address depositDelegate;
uint24 protocolFee; // In 1e6
uint256 maxTotalSupply;
uint24 wideRangeWeight; // In 1e6
int24 wideThreshold;
int24 baseThreshold;
int24 limitThreshold;
uint32 period;
int24 minTickMove;
int24 maxTwapDeviation;
uint32 twapDuration;
string name;
string symbol;
uint24 swapDeviationThreshold; // In 1e6
uint24 ratioDeviationThreshold; // In 1e6
uint24 rebalanceDelegateCooldown; // In seconds
uint24 maxRatioDeviationThresholdIncrease; // In 1e6
address[] initialWhitelistedSwappers;
address getters;
}
struct EverlongALMStorage {
address owner;
IUniswapV3Pool pool;
IPriceFeed priceFeed;
IERC20 token0;
IERC20 token1;
address manager;
address pendingManager;
address rebalanceDelegate;
address depositDelegate;
uint256 maxTotalSupply;
uint128 accruedProtocolFees0;
uint128 accruedProtocolFees1;
uint32 period;
uint24 protocolFee;
uint24 pendingProtocolFee;
uint24 wideRangeWeight;
int24 baseThreshold;
int24 limitThreshold;
int24 wideThreshold;
int24 minTickMove;
int24 tickSpacing;
int24 maxTwapDeviation;
uint32 twapDuration;
int24 wideLower;
int24 wideUpper;
int24 baseLower;
int24 baseUpper;
int24 limitLower;
int24 limitUpper;
int24 lastTick;
uint40 lastTimestamp;
int24 maxTick;
uint24 swapDeviationThreshold; // In 1e6
uint24 ratioDeviationThreshold; // In 1e6
uint24 rebalanceDelegateCooldown; // In seconds
uint40 lastRatioDeviationThresholdUpdateTimestamp;
uint24 maxRatioDeviationThresholdIncrease; // In 1e6
SwappersLib.SwapperData swapperData;
IALMGetters getters;
}
struct BurnContext {
uint256 wideAmount0;
uint256 wideAmount1;
uint256 baseAmount0;
uint256 baseAmount1;
uint256 limitAmount0;
uint256 limitAmount1;
}
struct ExternalRebalanceParams {
bool isZeroForOne;
uint256 sentAmount;
address swapper;
bytes payload;
uint256 minRebalanceOut;
}
function deposit(uint256, uint256, uint256, uint256, address) external returns (uint256, uint256, uint256);
function withdraw(uint256, uint256, uint256, address) external returns (uint256, uint256);
function extSloads(bytes32[] memory slots) external view returns (bytes32[] memory values);
function getTotalAmounts() external view returns (uint256, uint256);
function getBalance0() external view returns (uint256);
function getBalance1() external view returns (uint256);
function rebalance() external;
// state variables
function pool() external view returns (IUniswapV3Pool);
function protocolFee() external view returns (uint24);
function getPositions() external view returns (int24[2][3] memory);
function token0() external view returns (address);
function token1() external view returns (address);
function totalSupply() external view returns (uint256);
function balanceOf(address) external view returns (uint256);
event Deposit(address indexed sender, address indexed to, uint256 shares, uint256 amount0, uint256 amount1);
event Withdraw(address indexed sender, address indexed to, uint256 shares, uint256 amount0, uint256 amount1);
event CollectFees(
uint256 feesToVault0,
uint256 feesToVault1,
uint256 feesToProtocol0,
uint256 feesToProtocol1
);
event Snapshot(int24 tick, uint256 totalAmount0, uint256 totalAmount1, uint256 totalSupply);
event CollectProtocol(uint256 amount0, uint256 amount1);
event UpdateManager(address manager);
event UpdatePendingManager(address manager);
event UpdateRebalanceDelegate(address delegate);
event UpdateDepositDelegate(address delegate);
event UpdateProtocolFee(uint24 protocolFee);
event UpdateBaseThreshold(int24 threshold);
event UpdateLimitThreshold(int24 threshold);
event UpdateWideRangeWeight(uint24 weight);
event UpdateWideThreshold(int24 threshold);
event UpdatePeriod(uint32 period);
event UpdateMinTickMove(int24 minTickMove);
event UpdateMaxTwapDeviation(int24 maxTwapDeviation);
event UpdateTwapDuration(uint32 twapDuration);
event UpdateMaxTotalSupply(uint256 maxTotalSupply);
event UpdateSwapDeviationThreshold(uint24 swapDeviationThreshold);
event UpdateRatioDeviationThreshold(uint24 ratioDeviationThreshold);
event UpdateRebalanceDelegateCooldown(uint24 rebalanceDelegateCooldown);
event UpdateMaxRatioDeviationThresholdIncrease(uint24 maxRatioDeviationThresholdIncrease);
event UpdateGetters(address getters);
// Errors
error EV_ZeroAddress();
error EV_WideRangeWeight();
error EV_MinTickMove();
error EV_MaxTwapDeviation();
error EV_TwapDuration();
error EV_ThresholdsCannotBeSame();
error EV_ThresholdNotPositive();
error EV_ThresholdNotMultipleOfTickSpacing();
error EV_NotDepositDelegate();
error EV_ZeroDepositAmount();
error EV_InvalidRecipient();
error EV_ZeroShares();
error EV_Amount0Min();
error EV_Amount1Min();
error EV_MaxTotalSupply();
error EV_NotManagerOrRebalanceDelegate();
error EV_NotPool();
error EV_NotGovernance();
error EV_ProtocolFee();
error EV_ProtocolFeeTooHigh();
error EV_NotManager();
error EV_SweepToken();
error EV_NotPendingManager();
error EV_InsufficientBalance(uint256 available, uint256 required);
error EV_SwapDeviationThreshold();
error EV_RatioDeviationThreshold();
error EV_RebalanceDelegateCooldown();
error EV_MaxRatioDeviationThresholdIncrease();
error EV_RatioDeviationThresholdIncreaseExceeded(uint24 proposedThreshold, uint256 maxAllowedThreshold);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.26;
import {LiquidityAmounts} from "@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol";
import {TickMath} from "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import {SqrtPriceMath} from "@uniswap/v3-core/contracts/libraries/SqrtPriceMath.sol";
import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
library ALMLib {
uint24 constant MINIMUM_LIQUIDITY = 1e3;
error EV_ZeroCross();
/// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`.
function _liquidityForAmounts(
int24 tickLower,
int24 tickUpper,
uint256 amount0,
uint256 amount1,
uint160 sqrtRatioX96
) external pure returns (uint128) {
return LiquidityAmounts.getLiquidityForAmounts(
sqrtRatioX96,
TickMath.getSqrtRatioAtTick(tickLower),
TickMath.getSqrtRatioAtTick(tickUpper),
amount0,
amount1
);
}
/**
* @notice Computes the token0 and token1 value for a given amount of liquidity,
* respecting rounding for deposit/withdraw to align with uniswap's approach when providing/removing liquidity.
*/
function _amountsForLiquidity(address pool, int24 tickLower, int24 tickUpper, uint128 liquidity, bool roundUp)
external
view
returns (uint256 amount0, uint256 amount1)
{
(uint160 sqrtRatioX96,,,,,,) = IUniswapV3Pool(pool).slot0();
uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower);
uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper);
if (sqrtRatioAX96 > sqrtRatioBX96) {
(sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
}
if (sqrtRatioX96 <= sqrtRatioAX96) {
amount0 = SqrtPriceMath.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp);
} else if (sqrtRatioX96 < sqrtRatioBX96) {
amount0 = SqrtPriceMath.getAmount0Delta(sqrtRatioX96, sqrtRatioBX96, liquidity, roundUp);
amount1 = SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioX96, liquidity, roundUp);
} else {
amount1 = SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp);
}
}
/// @dev Calculates the largest possible `amount0` and `amount1` such that
/// they're in the same proportion as total amounts, but not greater than
/// `amount0Desired` and `amount1Desired` respectively.
function _calcSharesAndAmounts(
uint256 _totalSupply,
uint256 total0,
uint256 total1,
uint256 amount0Desired,
uint256 amount1Desired
)
external
view
returns (uint256 shares, uint256 amount0, uint256 amount1)
{
// If total supply > 0, vault can't be empty
assert(_totalSupply == 0 || total0 > 0 || total1 > 0);
if (_totalSupply == 0) {
// For first deposit, just use the amounts desired
amount0 = amount0Desired;
amount1 = amount1Desired;
shares = (amount0 > amount1 ? amount0 : amount1) - MINIMUM_LIQUIDITY;
} else if (total0 == 0) {
amount1 = amount1Desired;
shares = amount1 * _totalSupply / total1;
} else if (total1 == 0) {
amount0 = amount0Desired;
shares = amount0 * _totalSupply / total0;
} else {
uint256 cross0 = amount0Desired * total1;
uint256 cross1 = amount1Desired * total0;
uint256 cross = cross0 > cross1 ? cross1 : cross0;
if (cross == 0) revert EV_ZeroCross();
// Round up amounts
amount0 = (cross - 1) / total1 + 1;
amount1 = (cross - 1) / total0 + 1;
shares = cross * _totalSupply / total0 / total1;
}
}
/// @dev Ensures tick is within the maximum range boundaries
function _boundTick(int24 tick, int24 _maxTick) external pure returns (int24) {
if (tick < -_maxTick) {
return -_maxTick;
}
if (tick > _maxTick) {
return _maxTick;
}
return tick;
}
/// @dev Rounds tick down towards negative infinity so that it's a multiple
/// of `tickSpacing`.
function _floor(int24 tick, int24 tickSpacing) external pure returns (int24) {
int24 compressed = tick / tickSpacing;
if (tick < 0 && tick % tickSpacing != 0) compressed--;
return compressed * tickSpacing;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)
pragma solidity ^0.8.21;
import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
*/
library ERC1967Utils {
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev The `implementation` of the proxy is invalid.
*/
error ERC1967InvalidImplementation(address implementation);
/**
* @dev The `admin` of the proxy is invalid.
*/
error ERC1967InvalidAdmin(address admin);
/**
* @dev The `beacon` of the proxy is invalid.
*/
error ERC1967InvalidBeacon(address beacon);
/**
* @dev An upgrade function sees `msg.value > 0` that may be lost.
*/
error ERC1967NonPayable();
/**
* @dev Returns the current implementation address.
*/
function getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
if (newImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(newImplementation);
}
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
_setImplementation(newImplementation);
emit IERC1967.Upgraded(newImplementation);
if (data.length > 0) {
Address.functionDelegateCall(newImplementation, data);
} else {
_checkNonPayable();
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
if (newAdmin == address(0)) {
revert ERC1967InvalidAdmin(address(0));
}
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {IERC1967-AdminChanged} event.
*/
function changeAdmin(address newAdmin) internal {
emit IERC1967.AdminChanged(getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the ERC-1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
if (newBeacon.code.length == 0) {
revert ERC1967InvalidBeacon(newBeacon);
}
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
address beaconImplementation = IBeacon(newBeacon).implementation();
if (beaconImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(beaconImplementation);
}
}
/**
* @dev Change the beacon and trigger a setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-BeaconUpgraded} event.
*
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
* efficiency.
*/
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
_setBeacon(newBeacon);
emit IERC1967.BeaconUpgraded(newBeacon);
if (data.length > 0) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
} else {
_checkNonPayable();
}
}
/**
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
* if an upgrade doesn't perform an initialization call.
*/
function _checkNonPayable() private {
if (msg.value > 0) {
revert ERC1967NonPayable();
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
/// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
/// @return The contract address
function factory() external view returns (address);
/// @notice The first of the two tokens of the pool, sorted by address
/// @return The token contract address
function token0() external view returns (address);
/// @notice The second of the two tokens of the pool, sorted by address
/// @return The token contract address
function token1() external view returns (address);
/// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
/// @return The fee
function fee() external view returns (uint24);
/// @notice The pool tick spacing
/// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
/// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
/// This value is an int24 to avoid casting even though it is always positive.
/// @return The tick spacing
function tickSpacing() external view returns (int24);
/// @notice The maximum amount of position liquidity that can use any tick in the range
/// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
/// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
/// @return The max amount of liquidity per tick
function maxLiquidityPerTick() external view returns (uint128);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
/// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
/// when accessed externally.
/// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
/// @return tick The current tick of the pool, i.e. according to the last tick transition that was run.
/// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
/// boundary.
/// @return observationIndex The index of the last oracle observation that was written,
/// @return observationCardinality The current maximum number of observations stored in the pool,
/// @return observationCardinalityNext The next maximum number of observations, to be updated when the observation.
/// @return feeProtocol The protocol fee for both tokens of the pool.
/// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
/// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
/// unlocked Whether the pool is currently locked to reentrancy
function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint8 feeProtocol,
bool unlocked
);
/// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal0X128() external view returns (uint256);
/// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal1X128() external view returns (uint256);
/// @notice The amounts of token0 and token1 that are owed to the protocol
/// @dev Protocol fees will never exceed uint128 max in either token
function protocolFees() external view returns (uint128 token0, uint128 token1);
/// @notice The currently in range liquidity available to the pool
/// @dev This value has no relationship to the total liquidity across all ticks
/// @return The liquidity at the current price of the pool
function liquidity() external view returns (uint128);
/// @notice Look up information about a specific tick in the pool
/// @param tick The tick to look up
/// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
/// tick upper
/// @return liquidityNet how much liquidity changes when the pool price crosses the tick,
/// @return feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
/// @return feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
/// @return tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
/// @return secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
/// @return secondsOutside the seconds spent on the other side of the tick from the current tick,
/// @return initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
/// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
/// In addition, these values are only relative and must be used only in comparison to previous snapshots for
/// a specific position.
function ticks(int24 tick)
external
view
returns (
uint128 liquidityGross,
int128 liquidityNet,
uint256 feeGrowthOutside0X128,
uint256 feeGrowthOutside1X128,
int56 tickCumulativeOutside,
uint160 secondsPerLiquidityOutsideX128,
uint32 secondsOutside,
bool initialized
);
/// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
function tickBitmap(int16 wordPosition) external view returns (uint256);
/// @notice Returns the information about a position by the position's key
/// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
/// @return liquidity The amount of liquidity in the position,
/// @return feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
/// @return feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
/// @return tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
/// @return tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
function positions(bytes32 key)
external
view
returns (
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
/// @notice Returns data about a specific observation index
/// @param index The element of the observations array to fetch
/// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
/// ago, rather than at a specific index in the array.
/// @return blockTimestamp The timestamp of the observation,
/// @return tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
/// @return secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
/// @return initialized whether the observation has been initialized and the values are safe to use
function observations(uint256 index)
external
view
returns (
uint32 blockTimestamp,
int56 tickCumulative,
uint160 secondsPerLiquidityCumulativeX128,
bool initialized
);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
/// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
/// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
/// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
/// you must call it with secondsAgos = [3600, 0].
/// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
/// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
/// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
/// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
/// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
/// timestamp
function observe(uint32[] calldata secondsAgos)
external
view
returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);
/// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
/// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
/// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
/// snapshot is taken and the second snapshot is taken.
/// @param tickLower The lower tick of the range
/// @param tickUpper The upper tick of the range
/// @return tickCumulativeInside The snapshot of the tick accumulator for the range
/// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
/// @return secondsInside The snapshot of seconds per liquidity for the range
function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
external
view
returns (
int56 tickCumulativeInside,
uint160 secondsPerLiquidityInsideX128,
uint32 secondsInside
);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
/// @notice Set the denominator of the protocol's % share of the fees
/// @param feeProtocol0 new protocol fee for token0 of the pool
/// @param feeProtocol1 new protocol fee for token1 of the pool
function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;
/// @notice Collect the protocol fee accrued to the pool
/// @param recipient The address to which collected protocol fees should be sent
/// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
/// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
/// @return amount0 The protocol fee collected in token0
/// @return amount1 The protocol fee collected in token1
function collectProtocol(
address recipient,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Errors emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolErrors {
error LOK();
error TLU();
error TLM();
error TUM();
error AI();
error M0();
error M1();
error AS();
error IIA();
error L();
error F0();
error F1();
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
/// @notice Emitted exactly once by a pool when #initialize is first called on the pool
/// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
/// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
/// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
event Initialize(uint160 sqrtPriceX96, int24 tick);
/// @notice Emitted when liquidity is minted for a given position
/// @param sender The address that minted the liquidity
/// @param owner The owner of the position and recipient of any minted liquidity
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity minted to the position range
/// @param amount0 How much token0 was required for the minted liquidity
/// @param amount1 How much token1 was required for the minted liquidity
event Mint(
address sender,
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted when fees are collected by the owner of a position
/// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
/// @param owner The owner of the position for which fees are collected
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount0 The amount of token0 fees collected
/// @param amount1 The amount of token1 fees collected
event Collect(
address indexed owner,
address recipient,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount0,
uint128 amount1
);
/// @notice Emitted when a position's liquidity is removed
/// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
/// @param owner The owner of the position for which liquidity is removed
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity to remove
/// @param amount0 The amount of token0 withdrawn
/// @param amount1 The amount of token1 withdrawn
event Burn(
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted by the pool for any swaps between token0 and token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the output of the swap
/// @param amount0 The delta of the token0 balance of the pool
/// @param amount1 The delta of the token1 balance of the pool
/// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
/// @param liquidity The liquidity of the pool after the swap
/// @param tick The log base 1.0001 of price of the pool after the swap
event Swap(
address indexed sender,
address indexed recipient,
int256 amount0,
int256 amount1,
uint160 sqrtPriceX96,
uint128 liquidity,
int24 tick
);
/// @notice Emitted by the pool for any flashes of token0/token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the tokens from flash
/// @param amount0 The amount of token0 that was flashed
/// @param amount1 The amount of token1 that was flashed
/// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
/// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
event Flash(
address indexed sender,
address indexed recipient,
uint256 amount0,
uint256 amount1,
uint256 paid0,
uint256 paid1
);
/// @notice Emitted by the pool for increases to the number of observations that can be stored
/// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
/// just before a mint/swap/burn.
/// @param observationCardinalityNextOld The previous value of the next observation cardinality
/// @param observationCardinalityNextNew The updated value of the next observation cardinality
event IncreaseObservationCardinalityNext(
uint16 observationCardinalityNextOld,
uint16 observationCardinalityNextNew
);
/// @notice Emitted when the protocol fee is changed by the pool
/// @param feeProtocol0Old The previous value of the token0 protocol fee
/// @param feeProtocol1Old The previous value of the token1 protocol fee
/// @param feeProtocol0New The updated value of the token0 protocol fee
/// @param feeProtocol1New The updated value of the token1 protocol fee
event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);
/// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
/// @param sender The address that collects the protocol fees
/// @param recipient The address that receives the collected protocol fees
/// @param amount0 The amount of token0 protocol fees that is withdrawn
/// @param amount0 The amount of token1 protocol fees that is withdrawn
event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IPriceFeed {
struct FeedType {
address spotOracle;
bool isCollVault;
}
event NewOracleRegistered(address token, address chainlinkAggregator, address underlyingDerivative);
event PriceFeedStatusUpdated(address token, address oracle, bool isWorking);
event PriceRecordUpdated(address indexed token, uint256 _price);
event NewCollVaultRegistered(address collVault, bool enable);
event NewSpotOracleRegistered(address token, address spotOracle);
function fetchPrice(address _token) external view returns (uint256);
function getMultiplePrices(address[] memory _tokens) external view returns (uint256[] memory prices);
function setOracle(
address _token,
address _chainlinkOracle,
uint32 _heartbeat,
uint16 _staleThreshold,
address underlyingDerivative
) external;
function whitelistCollateralVault(address _collateralVaultShareToken, bool enable) external;
function setSpotOracle(address _token, address _spotOracle) external;
function MAX_PRICE_DEVIATION_FROM_PREVIOUS_ROUND() external view returns (uint256);
function CORE() external view returns (address);
function RESPONSE_TIMEOUT() external view returns (uint256);
function TARGET_DIGITS() external view returns (uint256);
function guardian() external view returns (address);
function oracleRecords(
address
)
external
view
returns (
address chainLinkOracle,
uint8 decimals,
uint32 heartbeat,
uint16 staleThreshold,
address underlyingDerivative
);
function isCollVault(address _collateralVaultShareToken) external view returns (bool);
function isStableBPT(address _oracle) external view returns (bool);
function isWeightedBPT(address _oracle) external view returns (bool);
function getSpotOracle(address _token) external view returns (address);
function feedType(address _token) external view returns (FeedType memory);
function owner() external view returns (address);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.26;
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {PositionKey} from "@uniswap/v3-periphery/contracts/libraries/PositionKey.sol";
import {TickMath} from "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import {PropMath} from "src/libraries/PropMath.sol";
import {PriceLib} from "src/libraries/PriceLib.sol";
import {IEverlongALM} from "src/interfaces/core/alm/IEverlongALM.sol";
import {IAsset} from "src/interfaces/utils/tokens/IAsset.sol";
import {ALMLib} from "src/core/alm/library/ALMLib.sol";
library EverlongALMStorageLib {
// keccak256(abi.encode(uint(keccak256("openzeppelin.storage.EverlongALM")) - 1)) & ~bytes32(uint(0xff))
bytes32 internal constant EVERLONG_ALM_STORAGE_LOC = 0xb4801203179a1f53d2a89513756c4fddeb24d0f949ce9fc7cf03114c341dc500;
uint256 internal constant MANAGER_SLOT = 5;
uint256 internal constant PENDING_MANAGER_SLOT = 6;
uint256 internal constant REBALANCE_DELEGATE_SLOT = 7;
uint256 internal constant DEPOSIT_DELEGATE_SLOT = 8;
uint256 internal constant MAX_TOTAL_SUPPLY_SLOT = 9;
uint256 internal constant ACCRUED_PROTOCOL_FEES_SLOT = 10;
uint256 internal constant PARAMS_SLOT = 11;
uint256 internal constant RANGE_SLOT = 12;
uint256 internal constant RATIO_SLOT = 13;
uint256 internal constant SWAPPER_DATA_SLOT = 14;
uint256 internal constant GETTERS_SLOT = 15;
// PARAMS_SLOT bit offsets
uint256 internal constant PROTOCOL_FEE_OFFSET = 32;
uint256 internal constant PENDING_PROTOCOL_FEE_OFFSET = 56;
uint256 internal constant WIDE_RANGE_WEIGHT_OFFSET = 80;
uint256 internal constant BASE_THRESHOLD_OFFSET = 104;
uint256 internal constant LIMIT_THRESHOLD_OFFSET = 128;
uint256 internal constant WIDE_THRESHOLD_OFFSET = 152;
uint256 internal constant MIN_TICK_MOVE_OFFSET = 176;
uint256 internal constant TICK_SPACING_OFFSET = 200;
uint256 internal constant MAX_TWAP_DEVIATION_OFFSET = 224;
// RANGE_SLOT bit offsets
uint256 internal constant TWAP_DURATION_OFFSET = 0;
uint256 internal constant WIDE_LOWER_OFFSET = 32;
uint256 internal constant WIDE_UPPER_OFFSET = 56;
uint256 internal constant BASE_LOWER_OFFSET = 80;
uint256 internal constant BASE_UPPER_OFFSET = 104;
uint256 internal constant LIMIT_LOWER_OFFSET = 128;
uint256 internal constant LIMIT_UPPER_OFFSET = 152;
uint256 internal constant LAST_TICK_OFFSET = 176;
uint256 internal constant LAST_TIMESTAMP_OFFSET = 200;
// RATIO_SLOT bit offsets
uint256 internal constant MAX_TICK_OFFSET = 0;
uint256 internal constant SWAP_DEVIATION_THRESHOLD_OFFSET = 24;
uint256 internal constant RATIO_DEVIATION_THRESHOLD_OFFSET = 48;
uint256 internal constant REBALANCE_DELEGATE_COOLDOWN_OFFSET = 72;
uint256 internal constant LAST_RATIO_DEV_UPDATE_TIMESTAMP_OFFSET = 96;
uint256 internal constant MAX_RATIO_DEV_THRESHOLD_INCREASE_OFFSET = 136;
function managerSlot() internal pure returns (bytes32) {
return bytes32(uint256(EVERLONG_ALM_STORAGE_LOC) + MANAGER_SLOT);
}
function pendingManagerSlot() internal pure returns (bytes32) {
return bytes32(uint256(EVERLONG_ALM_STORAGE_LOC) + PENDING_MANAGER_SLOT);
}
function rebalanceDelegateSlot() internal pure returns (bytes32) {
return bytes32(uint256(EVERLONG_ALM_STORAGE_LOC) + REBALANCE_DELEGATE_SLOT);
}
function depositDelegateSlot() internal pure returns (bytes32) {
return bytes32(uint256(EVERLONG_ALM_STORAGE_LOC) + DEPOSIT_DELEGATE_SLOT);
}
function maxTotalSupplySlot() internal pure returns (bytes32) {
return bytes32(uint256(EVERLONG_ALM_STORAGE_LOC) + MAX_TOTAL_SUPPLY_SLOT);
}
function accruedProtocolFeesSlot() internal pure returns (bytes32) {
return bytes32(uint256(EVERLONG_ALM_STORAGE_LOC) + ACCRUED_PROTOCOL_FEES_SLOT);
}
function paramsSlot() internal pure returns (bytes32) {
return bytes32(uint256(EVERLONG_ALM_STORAGE_LOC) + PARAMS_SLOT);
}
function rangeSlot() internal pure returns (bytes32) {
return bytes32(uint256(EVERLONG_ALM_STORAGE_LOC) + RANGE_SLOT);
}
function ratioSlot() internal pure returns (bytes32) {
return bytes32(uint256(EVERLONG_ALM_STORAGE_LOC) + RATIO_SLOT);
}
function swapperDataSlot() internal pure returns (bytes32) {
return bytes32(uint256(EVERLONG_ALM_STORAGE_LOC) + SWAPPER_DATA_SLOT);
}
function gettersSlot() internal pure returns (bytes32) {
return bytes32(uint256(EVERLONG_ALM_STORAGE_LOC) + GETTERS_SLOT);
}
}
interface IALMGetters {
error EV_PeriodNotElapsed();
error EV_TickNotMoved();
error EV_PriceOutOfBounds();
error EV_TwapPriceDeviation();
error EV_SwapSlippageExceeded(uint256 receivedValue, uint256 sentValue);
error EV_InsufficientSwapOutput(uint256 actual, uint256 required);
error EV_RatioDeviationExceeded(uint256 tokenInValue, uint256 tokenOutValue);
function getTotalAmounts(bool roundUp) external view returns (uint256 total0, uint256 total1);
function getPositionAmounts(int24 tickLower, int24 tickUpper, bool roundUp) external view returns (uint256 amount0, uint256 amount1);
function checkCanRebalance() external view;
function checkPriceNearTwap() external view;
function getTwap() external view returns (int24);
function checkMaxSlippageAndRatioDeviation(
IEverlongALM.ExternalRebalanceParams memory params,
uint256 tokenOutBalanceBefore,
address tokenIn,
address tokenOut,
uint256 sentPrice,
uint256 receivedPrice
) external view;
}
contract ALMGetters is IALMGetters {
using PriceLib for uint256;
IEverlongALM immutable public alm;
IUniswapV3Pool immutable public pool;
uint24 constant HUNDRED_PERCENT = 1e6;
constructor (address _alm, address _pool) {
alm = IEverlongALM(_alm);
/// @dev Assumes pool never changes
pool = IUniswapV3Pool(_pool);
}
// ─── extSloads helpers ───────────────────────────────────────────
function _loadSlot(bytes32 slot) private view returns (uint256 word) {
bytes32[] memory slots = new bytes32[](1);
slots[0] = slot;
word = uint256(alm.extSloads(slots)[0]);
}
function _loadCoreSlots() private view returns (uint256 params, uint256 ranges, uint256 ratios) {
bytes32[] memory slots = new bytes32[](3);
slots[0] = EverlongALMStorageLib.paramsSlot();
slots[1] = EverlongALMStorageLib.rangeSlot();
slots[2] = EverlongALMStorageLib.ratioSlot();
bytes32[] memory r = alm.extSloads(slots);
params = uint256(r[0]);
ranges = uint256(r[1]);
ratios = uint256(r[2]);
}
function _loadParams() private view returns (uint256) {
return _loadSlot(EverlongALMStorageLib.paramsSlot());
}
function _loadRange() private view returns (uint256) {
return _loadSlot(EverlongALMStorageLib.rangeSlot());
}
function _loadRatios() private view returns (uint256) {
return _loadSlot(EverlongALMStorageLib.ratioSlot());
}
function _decodeUint24(uint256 word, uint256 offset) private pure returns (uint24) {
return uint24(word >> offset);
}
function _decodeInt24(uint256 word, uint256 offset) private pure returns (int24) {
return int24(uint24(word >> offset));
}
function getters() public view returns (address) {
return address(uint160(_loadSlot(EverlongALMStorageLib.gettersSlot())));
}
function isSwapperWhitelisted(address swapper) public view returns (bool) {
bytes32[] memory slots = new bytes32[](1);
slots[0] = keccak256(abi.encode(swapper, EverlongALMStorageLib.swapperDataSlot()));
return uint256(alm.extSloads(slots)[0]) != 0;
}
// ─── extSloads-backed getters ─────────────────────────────────────
function manager() public view returns (address) {
return address(uint160(_loadSlot(EverlongALMStorageLib.managerSlot())));
}
function pendingManager() public view returns (address) {
return address(uint160(_loadSlot(EverlongALMStorageLib.pendingManagerSlot())));
}
function rebalanceDelegate() public view returns (address) {
return address(uint160(_loadSlot(EverlongALMStorageLib.rebalanceDelegateSlot())));
}
function depositDelegate() public view returns (address) {
return address(uint160(_loadSlot(EverlongALMStorageLib.depositDelegateSlot())));
}
function maxTotalSupply() public view returns (uint256) {
return _loadSlot(EverlongALMStorageLib.maxTotalSupplySlot());
}
function accruedProtocolFees0() public view returns (uint128) {
uint256 word = _loadSlot(EverlongALMStorageLib.accruedProtocolFeesSlot());
return uint128(word);
}
function accruedProtocolFees1() public view returns (uint128) {
uint256 word = _loadSlot(EverlongALMStorageLib.accruedProtocolFeesSlot());
return uint128(word >> 128);
}
function period() public view returns (uint32) {
return uint32(_loadParams());
}
function protocolFee() public view returns (uint24) {
return _decodeUint24(_loadParams(), EverlongALMStorageLib.PROTOCOL_FEE_OFFSET);
}
function pendingProtocolFee() public view returns (uint24) {
uint24 pendingProtocolFeePlusOne = _decodeUint24(_loadParams(), EverlongALMStorageLib.PENDING_PROTOCOL_FEE_OFFSET);
return pendingProtocolFeePlusOne == 0 ? 0 : pendingProtocolFeePlusOne - 1;
}
function wideRangeWeight() public view returns (uint24) {
return _decodeUint24(_loadParams(), EverlongALMStorageLib.WIDE_RANGE_WEIGHT_OFFSET);
}
function baseThreshold() public view returns (int24) {
return _decodeInt24(_loadParams(), EverlongALMStorageLib.BASE_THRESHOLD_OFFSET);
}
function limitThreshold() public view returns (int24) {
return _decodeInt24(_loadParams(), EverlongALMStorageLib.LIMIT_THRESHOLD_OFFSET);
}
function wideThreshold() public view returns (int24) {
return _decodeInt24(_loadParams(), EverlongALMStorageLib.WIDE_THRESHOLD_OFFSET);
}
function minTickMove() public view returns (int24) {
return _decodeInt24(_loadParams(), EverlongALMStorageLib.MIN_TICK_MOVE_OFFSET);
}
function tickSpacing() public view returns (int24) {
return _decodeInt24(_loadParams(), EverlongALMStorageLib.TICK_SPACING_OFFSET);
}
function maxTwapDeviation() public view returns (int24) {
return _decodeInt24(_loadParams(), EverlongALMStorageLib.MAX_TWAP_DEVIATION_OFFSET);
}
function twapDuration() public view returns (uint32) {
return uint32(_loadRange() >> EverlongALMStorageLib.TWAP_DURATION_OFFSET);
}
function lastTick() public view returns (int24) {
return _decodeInt24(_loadRange(), EverlongALMStorageLib.LAST_TICK_OFFSET);
}
function lastTimestamp() public view returns (uint40) {
return uint40(_loadRange() >> EverlongALMStorageLib.LAST_TIMESTAMP_OFFSET);
}
function swapDeviationThreshold() public view returns (uint24) {
return _decodeUint24(_loadRatios(), EverlongALMStorageLib.SWAP_DEVIATION_THRESHOLD_OFFSET);
}
function ratioDeviationThreshold() public view returns (uint24) {
return _decodeUint24(_loadRatios(), EverlongALMStorageLib.RATIO_DEVIATION_THRESHOLD_OFFSET);
}
function rebalanceDelegateCooldown() public view returns (uint24) {
return _decodeUint24(_loadRatios(), EverlongALMStorageLib.REBALANCE_DELEGATE_COOLDOWN_OFFSET);
}
function lastRatioDeviationThresholdUpdateTimestamp() public view returns (uint40) {
return uint40(_loadRatios() >> EverlongALMStorageLib.LAST_RATIO_DEV_UPDATE_TIMESTAMP_OFFSET);
}
function maxRatioDeviationThresholdIncrease() public view returns (uint24) {
return _decodeUint24(_loadRatios(), EverlongALMStorageLib.MAX_RATIO_DEV_THRESHOLD_INCREASE_OFFSET);
}
function getTotalAmounts(bool roundUp) public view override returns (uint256 total0, uint256 total1) {
int24[2][3] memory positions = alm.getPositions();
(uint256 wideAmount0, uint256 wideAmount1) = getPositionAmounts(positions[0][0], positions[0][1], roundUp);
(uint256 baseAmount0, uint256 baseAmount1) = getPositionAmounts(positions[1][0], positions[1][1], roundUp);
(uint256 limitAmount0, uint256 limitAmount1) = getPositionAmounts(positions[2][0], positions[2][1], roundUp);
total0 = alm.getBalance0() + wideAmount0 + baseAmount0 + limitAmount0;
total1 = alm.getBalance1() + wideAmount1 + baseAmount1 + limitAmount1;
}
/**
* @notice Amounts of token0 and token1 held in vault's position. Includes
* owed fees but excludes the proportion of fees that will be paid to the
* protocol. Doesn't include fees accrued since last poke.
*/
function getPositionAmounts(int24 tickLower, int24 tickUpper, bool roundUp)
public
view
returns (uint256 amount0, uint256 amount1)
{
(uint128 liquidity,,, uint128 tokensOwed0, uint128 tokensOwed1) = _position(tickLower, tickUpper);
(amount0, amount1) = ALMLib._amountsForLiquidity(address(pool), tickLower, tickUpper, liquidity, roundUp);
// Subtract protocol and manager fees
uint256 paramsWord = _loadParams();
uint24 _protocolFee = _decodeUint24(paramsWord, EverlongALMStorageLib.PROTOCOL_FEE_OFFSET);
uint128 protocolFees0 = tokensOwed0 * _protocolFee / HUNDRED_PERCENT;
uint128 protocolFees1 = tokensOwed1 * _protocolFee / HUNDRED_PERCENT;
amount0 += tokensOwed0 - protocolFees0;
amount1 += tokensOwed1 - protocolFees1;
}
function checkCanRebalance() public view {
checkPriceNearTwap();
(uint256 paramsWord, uint256 rangesWord, uint256 ratiosWord) = _loadCoreSlots();
uint40 _lastTimestamp = uint40(rangesWord >> EverlongALMStorageLib.LAST_TIMESTAMP_OFFSET);
int24 lastTick = _decodeInt24(rangesWord, EverlongALMStorageLib.LAST_TICK_OFFSET);
int24 baseThreshold = _decodeInt24(paramsWord, EverlongALMStorageLib.BASE_THRESHOLD_OFFSET);
int24 limitThreshold = _decodeInt24(paramsWord, EverlongALMStorageLib.LIMIT_THRESHOLD_OFFSET);
int24 tickSpacing = _decodeInt24(paramsWord, EverlongALMStorageLib.TICK_SPACING_OFFSET);
uint32 _period = uint32(paramsWord);
int24 minTickMove_ = _decodeInt24(paramsWord, EverlongALMStorageLib.MIN_TICK_MOVE_OFFSET);
// check enough time has passed
if (block.timestamp < (_lastTimestamp + _period)) revert EV_PeriodNotElapsed();
// check price has moved enough
(, int24 tick,,,,,) = pool.slot0();
int24 tickMove = tick > lastTick ? tick - lastTick : lastTick - tick;
if (_lastTimestamp != 0 && tickMove < minTickMove_) revert EV_TickNotMoved();
// check price not too close to boundary
int24 maxThreshold = baseThreshold > limitThreshold ? baseThreshold : limitThreshold;
if (
!(
tick >= TickMath.MIN_TICK + maxThreshold + tickSpacing
&& tick <= TickMath.MAX_TICK - maxThreshold - tickSpacing
)
) revert EV_PriceOutOfBounds();
}
function checkPriceNearTwap() public view {
(, int24 tick,,,,,) = pool.slot0();
int24 twap = getTwap();
int24 twapDeviation = tick > twap ? tick - twap : twap - tick;
if (twapDeviation > maxTwapDeviation()) revert EV_TwapPriceDeviation();
}
/// @dev Fetches time-weighted average price in ticks from Uniswap pool.
function getTwap() public view returns (int24) {
uint32 _twapDuration = twapDuration();
uint32[] memory secondsAgo = new uint32[](2);
secondsAgo[0] = _twapDuration;
secondsAgo[1] = 0;
(int56[] memory tickCumulatives,) = pool.observe(secondsAgo);
return int24((tickCumulatives[1] - tickCumulatives[0]) / int56(uint56((_twapDuration))));
}
function checkMaxSlippageAndRatioDeviation(
IEverlongALM.ExternalRebalanceParams memory params,
uint256 tokenOutBalanceBefore,
address tokenIn,
address tokenOut,
uint256 sentPrice,
uint256 receivedPrice
) external view {
uint256 tokenOutBalanceAfter = params.isZeroForOne ? alm.getBalance1() : alm.getBalance0();
uint8 tokenInDecimals = IAsset(tokenIn).decimals();
uint8 tokenOutDecimals = IAsset(tokenOut).decimals();
uint256 ratiosWord = _loadRatios();
uint24 _swapDeviationThreshold = _decodeUint24(ratiosWord, EverlongALMStorageLib.SWAP_DEVIATION_THRESHOLD_OFFSET);
uint24 _ratioDeviationThreshold = _decodeUint24(ratiosWord, EverlongALMStorageLib.RATIO_DEVIATION_THRESHOLD_OFFSET);
{
uint256 amountOut = tokenOutBalanceAfter - tokenOutBalanceBefore;
uint256 sentValue = _assetValue(params.sentAmount, sentPrice, tokenInDecimals);
{
uint256 receivedValue = _assetValue(amountOut, receivedPrice, tokenOutDecimals);
if (receivedValue < sentValue * (HUNDRED_PERCENT - _swapDeviationThreshold) / HUNDRED_PERCENT) {
revert EV_SwapSlippageExceeded(receivedValue, sentValue);
}
}
if (amountOut < params.minRebalanceOut) {
revert EV_InsufficientSwapOutput(amountOut, params.minRebalanceOut);
}
}
(uint256 total0, uint256 total1) = alm.getTotalAmounts();
uint256 totalTokenIn = params.isZeroForOne ? total0 : total1;
uint256 totalTokenOut = params.isZeroForOne ? total1 : total0;
uint256 tokenInBalanceValue = _assetValue(totalTokenIn, sentPrice, tokenInDecimals);
uint256 tokenOutBalanceValue = _assetValue(totalTokenOut, receivedPrice, tokenOutDecimals);
uint256 maxDelta = Math.min(tokenInBalanceValue, tokenOutBalanceValue) * _ratioDeviationThreshold / HUNDRED_PERCENT;
if (!PropMath._isApproxEqAbs(tokenInBalanceValue, tokenOutBalanceValue, maxDelta)) {
revert EV_RatioDeviationExceeded(tokenInBalanceValue, tokenOutBalanceValue);
}
}
/// @dev Wrapper around `IUniswapV3Pool.positions()`.
function _position(int24 tickLower, int24 tickUpper)
internal
view
returns (uint128, uint256, uint256, uint128, uint128)
{
bytes32 positionKey = PositionKey.compute(address(alm), tickLower, tickUpper);
return pool.positions(positionKey);
}
/// @dev Returned in WAD
function _assetValue(uint256 amount, uint256 price, uint8 decimals) internal pure returns (uint256) {
return amount.convertToValue(price, decimals);
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {UtilsLib} from "./UtilsLib.sol";
library SwappersLib {
using UtilsLib for bytes;
error SwapperNotWhitelisted();
event SwapperAdded(address indexed swapRouter, bool status);
struct SwapperData {
mapping(address => bool) whitelistedSwappers;
}
function addWhitelistedSwapper(SwapperData storage self, address _swapRouter, bool status) internal {
self.whitelistedSwappers[_swapRouter] = status;
emit SwapperAdded(_swapRouter, status);
}
function executeSwap(SwapperData storage self, address swapRouter, bytes memory dexCalldata) internal {
if (!self.whitelistedSwappers[swapRouter]) revert SwapperNotWhitelisted();
(bool success, bytes memory retData) = swapRouter.call(dexCalldata);
if (!success) {
retData.bubbleUpRevert();
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import '@uniswap/v3-core/contracts/libraries/FullMath.sol';
import '@uniswap/v3-core/contracts/libraries/FixedPoint96.sol';
/// @title Liquidity amount functions
/// @notice Provides functions for computing liquidity amounts from token amounts and prices
library LiquidityAmounts {
/// @notice Downcasts uint256 to uint128
/// @param x The uint258 to be downcasted
/// @return y The passed value, downcasted to uint128
function toUint128(uint256 x) private pure returns (uint128 y) {
require((y = uint128(x)) == x);
}
/// @notice Computes the amount of liquidity received for a given amount of token0 and price range
/// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount0 The amount0 being sent in
/// @return liquidity The amount of returned liquidity
function getLiquidityForAmount0(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint256 amount0
) internal pure returns (uint128 liquidity) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96);
unchecked {
return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96));
}
}
/// @notice Computes the amount of liquidity received for a given amount of token1 and price range
/// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)).
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount1 The amount1 being sent in
/// @return liquidity The amount of returned liquidity
function getLiquidityForAmount1(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint256 amount1
) internal pure returns (uint128 liquidity) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
unchecked {
return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96));
}
}
/// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current
/// pool prices and the prices at the tick boundaries
/// @param sqrtRatioX96 A sqrt price representing the current pool prices
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount0 The amount of token0 being sent in
/// @param amount1 The amount of token1 being sent in
/// @return liquidity The maximum amount of liquidity received
function getLiquidityForAmounts(
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint256 amount0,
uint256 amount1
) internal pure returns (uint128 liquidity) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
if (sqrtRatioX96 <= sqrtRatioAX96) {
liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);
} else if (sqrtRatioX96 < sqrtRatioBX96) {
uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);
uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);
liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;
} else {
liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1);
}
}
/// @notice Computes the amount of token0 for a given amount of liquidity and a price range
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param liquidity The liquidity being valued
/// @return amount0 The amount of token0
function getAmount0ForLiquidity(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) internal pure returns (uint256 amount0) {
unchecked {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
return
FullMath.mulDiv(
uint256(liquidity) << FixedPoint96.RESOLUTION,
sqrtRatioBX96 - sqrtRatioAX96,
sqrtRatioBX96
) / sqrtRatioAX96;
}
}
/// @notice Computes the amount of token1 for a given amount of liquidity and a price range
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param liquidity The liquidity being valued
/// @return amount1 The amount of token1
function getAmount1ForLiquidity(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) internal pure returns (uint256 amount1) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
unchecked {
return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);
}
}
/// @notice Computes the token0 and token1 value for a given amount of liquidity, the current
/// pool prices and the prices at the tick boundaries
/// @param sqrtRatioX96 A sqrt price representing the current pool prices
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param liquidity The liquidity being valued
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function getAmountsForLiquidity(
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) internal pure returns (uint256 amount0, uint256 amount1) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
if (sqrtRatioX96 <= sqrtRatioAX96) {
amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
} else if (sqrtRatioX96 < sqrtRatioBX96) {
amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity);
amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity);
} else {
amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
}
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import {SafeCast} from './SafeCast.sol';
import {FullMath} from './FullMath.sol';
import {UnsafeMath} from './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;
/// @notice Gets the next sqrt price given a delta of token0
/// @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 token0 delta
/// @param liquidity The amount of usable liquidity
/// @param amount How much of token0 to add or remove from virtual reserves
/// @param add Whether to add or remove the amount of token0
/// @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;
if ((product = amount * sqrtPX96) / 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;
// if the product overflows, we know the denominator underflows
// in addition, we must check that the denominator does not underflow
require((product = amount * sqrtPX96) / amount == sqrtPX96 && numerator1 > product);
uint256 denominator = numerator1 - product;
return FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator).toUint160();
}
}
}
/// @notice Gets the next sqrt price given a delta of token1
/// @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 token1 delta
/// @param liquidity The amount of usable liquidity
/// @param amount How much of token1 to add, or remove, from virtual reserves
/// @param add Whether to add, or remove, the amount of token1
/// @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)
);
require(sqrtPX96 > quotient);
// always fits 160 bits
unchecked {
return uint160(sqrtPX96 - quotient);
}
}
}
/// @notice Gets the next sqrt price given an input amount of token0 or token1
/// @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 token0, or token1, is being swapped in
/// @param zeroForOne Whether the amount in is token0 or token1
/// @return sqrtQX96 The price after adding the input amount to token0 or token1
function getNextSqrtPriceFromInput(
uint160 sqrtPX96,
uint128 liquidity,
uint256 amountIn,
bool zeroForOne
) internal pure returns (uint160 sqrtQX96) {
require(sqrtPX96 > 0);
require(liquidity > 0);
// 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 token0 or token1
/// @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 token0, or token1, is being swapped out
/// @param zeroForOne Whether the amount out is token0 or token1
/// @return sqrtQX96 The price after removing the output amount of token0 or token1
function getNextSqrtPriceFromOutput(
uint160 sqrtPX96,
uint128 liquidity,
uint256 amountOut,
bool zeroForOne
) internal pure returns (uint160 sqrtQX96) {
require(sqrtPX96 > 0);
require(liquidity > 0);
// 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 amount0 Amount of token0 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 amount0) {
unchecked {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;
uint256 numerator2 = sqrtRatioBX96 - sqrtRatioAX96;
require(sqrtRatioAX96 > 0);
return
roundUp
? UnsafeMath.divRoundingUp(
FullMath.mulDivRoundingUp(numerator1, numerator2, sqrtRatioBX96),
sqrtRatioAX96
)
: FullMath.mulDiv(numerator1, numerator2, sqrtRatioBX96) / sqrtRatioAX96;
}
}
/// @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 token1 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) {
unchecked {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
return
roundUp
? FullMath.mulDivRoundingUp(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96)
: FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);
}
}
/// @notice Helper that gets signed token0 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 amount0 Amount of token0 corresponding to the passed liquidityDelta between the two prices
function getAmount0Delta(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
int128 liquidity
) internal pure returns (int256 amount0) {
unchecked {
return
liquidity < 0
? -getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256()
: getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256();
}
}
/// @notice Helper that gets signed token1 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 amount1 Amount of token1 corresponding to the passed liquidityDelta between the two prices
function getAmount1Delta(
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
int128 liquidity
) internal pure returns (int256 amount1) {
unchecked {
return
liquidity < 0
? -getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256()
: getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1967.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*/
interface IERC1967 {
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
library PropMath {
uint256 internal constant DECIMAL_PRECISION = 1e18;
/* Precision for Nominal ICR (independent of price). Rationale for the value:
*
* - Making it “too high” could lead to overflows.
* - Making it “too low” could lead to an ICR equal to zero, due to truncation from Solidity floor division.
*
* This value of 1e20 is chosen for safety: the NICR will only overflow for numerator > ~1e39,
* and will only truncate to 0 if the denominator is at least 1e20 times greater than the numerator.
*
*/
uint256 internal constant NICR_PRECISION = 1e20;
function _min(uint256 _a, uint256 _b) internal pure returns (uint256) {
return (_a < _b) ? _a : _b;
}
function _max(uint256 _a, uint256 _b) internal pure returns (uint256) {
return (_a >= _b) ? _a : _b;
}
/*
* Multiply two decimal numbers and use normal rounding rules:
* -round product up if 19'th mantissa digit >= 5
* -round product down if 19'th mantissa digit < 5
*
* Used only inside the exponentiation, _decPow().
*/
function decMul(uint256 x, uint256 y) internal pure returns (uint256 decProd) {
uint256 prod_xy = x * y;
decProd = (prod_xy + (DECIMAL_PRECISION / 2)) / DECIMAL_PRECISION;
}
/*
* _decPow: Exponentiation function for 18-digit decimal base, and integer exponent n.
*
* Uses the efficient "exponentiation by squaring" algorithm. O(log(n)) complexity.
*
* Called by two functions that represent time in units of minutes:
* 1) PositionManager._calcDecayedBaseRate
* 2) CommunityIssuance._getCumulativeIssuanceFraction
*
* The exponent is capped to avoid reverting due to overflow. The cap 525600000 equals
* "minutes in 1000 years": 60 * 24 * 365 * 1000
*
* If a period of > 1000 years is ever used as an exponent in either of the above functions, the result will be
* negligibly different from just passing the cap, since:
*
* In function 1), the decayed base rate will be 0 for 1000 years or > 1000 years
* In function 2), the difference in tokens issued at 1000 years and any time > 1000 years, will be negligible
*/
function _decPow(uint256 _base, uint256 _minutes) internal pure returns (uint256) {
if (_minutes > 525600000) {
_minutes = 525600000;
} // cap to avoid overflow
if (_minutes == 0) {
return DECIMAL_PRECISION;
}
uint256 y = DECIMAL_PRECISION;
uint256 x = _base;
uint256 n = _minutes;
// Exponentiation-by-squaring
while (n > 1) {
if (n % 2 == 0) {
x = decMul(x, x);
n = n / 2;
} else {
// if (n % 2 != 0)
y = decMul(x, y);
x = decMul(x, x);
n = (n - 1) / 2;
}
}
return decMul(x, y);
}
function _getAbsoluteDifference(uint256 _a, uint256 _b) internal pure returns (uint256) {
return (_a >= _b) ? _a - _b : _b - _a;
}
function _computeNominalCR(uint256 _coll, uint256 _debt) internal pure returns (uint256) {
if (_debt > 0) {
return (_coll * NICR_PRECISION) / _debt;
}
// Return the maximal value for uint256 if the Position has a debt of 0. Represents "infinite" CR.
else {
// if (_debt == 0)
return 2 ** 256 - 1;
}
}
function _computeCR(uint256 _coll, uint256 _debt, uint256 _price) internal pure returns (uint256) {
if (_debt > 0) {
uint256 newCollRatio = (_coll * _price) / _debt;
return newCollRatio;
}
// Return the maximal value for uint256 if the Position has a debt of 0. Represents "infinite" CR.
else {
// if (_debt == 0)
return 2 ** 256 - 1;
}
}
function _computeCR(uint256 _coll, uint256 _debt) internal pure returns (uint256) {
if (_debt > 0) {
uint256 newCollRatio = (_coll) / _debt;
return newCollRatio;
}
// Return the maximal value for uint256 if the Position has a debt of 0. Represents "infinite" CR.
else {
// if (_debt == 0)
return 2 ** 256 - 1;
}
}
function _isApproxEqAbs(uint256 a, uint256 b, uint256 tolerance) internal pure returns (bool) {
return a > b ? (a - b) <= tolerance : (b - a) <= tolerance;
}
function _isWithinToleranceAbove(
uint256 a,
uint256 b,
uint256 tolerance
) internal pure returns (bool) {
if (a < b) return false;
return (a - b) <= tolerance;
}
function _isWithinToleranceBelow(
uint256 a,
uint256 b,
uint256 tolerance
) internal pure returns (bool) {
if (a > b) return false;
return (b - a) <= tolerance;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
library PriceLib {
using Math for uint;
// WAD adjusted result
function convertToValue(uint amount, uint price, uint8 decimals) internal pure returns (uint) {
return amount * price / 10 ** decimals;
}
function convertToAmount(uint amountInUsd, uint collPrice, uint8 collDecimals, Math.Rounding rounding) internal pure returns (uint) {
if (collPrice == 0 || amountInUsd == 0) {
return 0;
}
return amountInUsd.mulDiv(10 ** collDecimals, collPrice, rounding);
}
// Coll decimal adjust amount result
function convertAssetsToCollAmount(uint assets, uint collPrice, uint debtTokenPrice, uint8 vaultDecimals, uint8 collDecimals, Math.Rounding rounding) internal pure returns (uint) {
uint assetsUsdValue = assets.mulDiv(debtTokenPrice, 10 ** vaultDecimals, rounding);
if (collPrice != 0) {
return convertToAmount(assetsUsdValue, collPrice, collDecimals, rounding);
} else {
return 0;
}
}
function convertCollAmountToAssets(uint collAmount, uint collPrice, uint debtTokenPrice, uint8 vaultDecimals, uint8 collDecimals) internal pure returns (uint) {
uint collUsdValue = collAmount * collPrice / 10 ** collDecimals;
if (debtTokenPrice != 0) {
return collUsdValue * 10 ** vaultDecimals / debtTokenPrice;
} else {
return 0;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
interface IAsset is IERC20 {
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
library UtilsLib {
error DexCalldataTooShort();
function getSelector(bytes memory data) internal pure returns (bytes4 selector) {
if (data.length < 4) {
revert DexCalldataTooShort();
}
selector = bytes4(data);
}
function bubbleUpRevert(bytes memory reason) internal pure {
assembly {
revert(add(reason, 0x20), mload(reason))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
/// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
/// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
function mulDiv(
uint256 a,
uint256 b,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = a * b
// Compute the product mod 2**256 and mod 2**256 - 1
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2**256 + prod0
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(a, b, not(0))
prod0 := mul(a, b)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division
if (prod1 == 0) {
require(denominator > 0);
assembly {
result := div(prod0, denominator)
}
return result;
}
// Make sure the result is less than 2**256.
// Also prevents denominator == 0
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0]
// Compute remainder using mulmod
uint256 remainder;
assembly {
remainder := mulmod(a, b, denominator)
}
// Subtract 256 bit number from 512 bit number
assembly {
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator
// Compute largest power of two divisor of denominator.
// Always >= 1.
uint256 twos = (0 - denominator) & denominator;
// Divide denominator by power of two
assembly {
denominator := div(denominator, twos)
}
// Divide [prod1 prod0] by the factors of two
assembly {
prod0 := div(prod0, twos)
}
// Shift in bits from prod1 into prod0. For this we need
// to flip `twos` such that it is 2**256 / twos.
// If twos is zero, then it becomes one
assembly {
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
// Invert denominator mod 2**256
// Now that denominator is an odd number, it has an inverse
// modulo 2**256 such that denominator * inv = 1 mod 2**256.
// Compute the inverse by starting with a seed that is correct
// correct for four bits. That is, denominator * inv = 1 mod 2**4
uint256 inv = (3 * denominator) ^ 2;
// Now use Newton-Raphson iteration to improve the precision.
// Thanks to Hensel's lifting lemma, this also works in modular
// arithmetic, doubling the correct bits in each step.
inv *= 2 - denominator * inv; // inverse mod 2**8
inv *= 2 - denominator * inv; // inverse mod 2**16
inv *= 2 - denominator * inv; // inverse mod 2**32
inv *= 2 - denominator * inv; // inverse mod 2**64
inv *= 2 - denominator * inv; // inverse mod 2**128
inv *= 2 - denominator * inv; // inverse mod 2**256
// Because the division is now exact we can divide by multiplying
// with the modular inverse of denominator. This will give us the
// correct result modulo 2**256. Since the precoditions guarantee
// that the outcome is less than 2**256, this is the final result.
// We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inv;
return result;
}
}
/// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
function mulDivRoundingUp(
uint256 a,
uint256 b,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
result = mulDiv(a, b, denominator);
if (mulmod(a, b, denominator) > 0) {
require(result < type(uint256).max);
result++;
}
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.4.0;
/// @title FixedPoint96
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
/// @dev Used in SqrtPriceMath.sol
library FixedPoint96 {
uint8 internal constant RESOLUTION = 96;
uint256 internal constant Q96 = 0x1000000000000000000000000;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Safe casting methods
/// @notice Contains methods for safely casting between types
library SafeCast {
/// @notice Cast a uint256 to a uint160, revert on overflow
/// @param y The uint256 to be downcasted
/// @return z The downcasted integer, now type uint160
function toUint160(uint256 y) internal pure returns (uint160 z) {
require((z = uint160(y)) == y);
}
/// @notice Cast a int256 to a int128, revert on overflow or underflow
/// @param y The int256 to be downcasted
/// @return z The downcasted integer, now type int128
function toInt128(int256 y) internal pure returns (int128 z) {
require((z = int128(y)) == y);
}
/// @notice Cast a uint256 to a int256, revert on overflow
/// @param y The uint256 to be casted
/// @return z The casted integer, now type int256
function toInt256(uint256 y) internal pure returns (int256 z) {
require(y < 2**255);
z = int256(y);
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.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 has unspecified behavior, and must 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 {
z := add(div(x, y), gt(mod(x, y), 0))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
}// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol) pragma solidity ^0.8.0; import "../token/ERC20/IERC20.sol";
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}{
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin-upgradeable/contracts/=lib/openzeppelin-contracts-upgradeable/contracts/",
"forge-std/=lib/forge-std/src/",
"@uniswap/v3-core/=lib/v3-core/",
"@uniswap/v3-periphery/=lib/v3-periphery/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"ds-test/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"v3-core/=lib/v3-core/contracts/",
"v3-periphery/=lib/v3-periphery/contracts/"
],
"optimizer": {
"enabled": true,
"runs": 1
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": false,
"libraries": {
"src/core/alm/EverlongALM.sol": {
"ALMLib": "0x6c4e0f30ee76a1c360387a0504f32c991d46f817"
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"inputs":[],"name":"EV_Amount0Min","type":"error"},{"inputs":[],"name":"EV_Amount1Min","type":"error"},{"inputs":[{"internalType":"uint256","name":"available","type":"uint256"},{"internalType":"uint256","name":"required","type":"uint256"}],"name":"EV_InsufficientBalance","type":"error"},{"inputs":[],"name":"EV_InvalidRecipient","type":"error"},{"inputs":[],"name":"EV_MaxRatioDeviationThresholdIncrease","type":"error"},{"inputs":[],"name":"EV_MaxTotalSupply","type":"error"},{"inputs":[],"name":"EV_MaxTwapDeviation","type":"error"},{"inputs":[],"name":"EV_MinTickMove","type":"error"},{"inputs":[],"name":"EV_NotDepositDelegate","type":"error"},{"inputs":[],"name":"EV_NotGovernance","type":"error"},{"inputs":[],"name":"EV_NotManager","type":"error"},{"inputs":[],"name":"EV_NotManagerOrRebalanceDelegate","type":"error"},{"inputs":[],"name":"EV_NotPendingManager","type":"error"},{"inputs":[],"name":"EV_NotPool","type":"error"},{"inputs":[],"name":"EV_ProtocolFee","type":"error"},{"inputs":[],"name":"EV_ProtocolFeeTooHigh","type":"error"},{"inputs":[],"name":"EV_RatioDeviationThreshold","type":"error"},{"inputs":[{"internalType":"uint24","name":"proposedThreshold","type":"uint24"},{"internalType":"uint256","name":"maxAllowedThreshold","type":"uint256"}],"name":"EV_RatioDeviationThresholdIncreaseExceeded","type":"error"},{"inputs":[],"name":"EV_RebalanceDelegateCooldown","type":"error"},{"inputs":[],"name":"EV_SwapDeviationThreshold","type":"error"},{"inputs":[],"name":"EV_SweepToken","type":"error"},{"inputs":[],"name":"EV_ThresholdNotMultipleOfTickSpacing","type":"error"},{"inputs":[],"name":"EV_ThresholdNotPositive","type":"error"},{"inputs":[],"name":"EV_ThresholdsCannotBeSame","type":"error"},{"inputs":[],"name":"EV_TwapDuration","type":"error"},{"inputs":[],"name":"EV_WideRangeWeight","type":"error"},{"inputs":[],"name":"EV_ZeroAddress","type":"error"},{"inputs":[],"name":"EV_ZeroDepositAmount","type":"error"},{"inputs":[],"name":"EV_ZeroShares","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"SwapperNotWhitelisted","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feesToVault0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feesToVault1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feesToProtocol0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feesToProtocol1","type":"uint256"}],"name":"CollectFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"CollectProtocol","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"tick","type":"int24"},{"indexed":false,"internalType":"uint256","name":"totalAmount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalAmount1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalSupply","type":"uint256"}],"name":"Snapshot","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"swapRouter","type":"address"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"SwapperAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"threshold","type":"int24"}],"name":"UpdateBaseThreshold","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"}],"name":"UpdateDepositDelegate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"getters","type":"address"}],"name":"UpdateGetters","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"threshold","type":"int24"}],"name":"UpdateLimitThreshold","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"manager","type":"address"}],"name":"UpdateManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint24","name":"maxRatioDeviationThresholdIncrease","type":"uint24"}],"name":"UpdateMaxRatioDeviationThresholdIncrease","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxTotalSupply","type":"uint256"}],"name":"UpdateMaxTotalSupply","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"maxTwapDeviation","type":"int24"}],"name":"UpdateMaxTwapDeviation","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"minTickMove","type":"int24"}],"name":"UpdateMinTickMove","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"manager","type":"address"}],"name":"UpdatePendingManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"period","type":"uint32"}],"name":"UpdatePeriod","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint24","name":"protocolFee","type":"uint24"}],"name":"UpdateProtocolFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint24","name":"ratioDeviationThreshold","type":"uint24"}],"name":"UpdateRatioDeviationThreshold","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"delegate","type":"address"}],"name":"UpdateRebalanceDelegate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint24","name":"rebalanceDelegateCooldown","type":"uint24"}],"name":"UpdateRebalanceDelegateCooldown","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint24","name":"swapDeviationThreshold","type":"uint24"}],"name":"UpdateSwapDeviationThreshold","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"twapDuration","type":"uint32"}],"name":"UpdateTwapDuration","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint24","name":"weight","type":"uint24"}],"name":"UpdateWideRangeWeight","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"threshold","type":"int24"}],"name":"UpdateWideThreshold","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"isZeroForOne","type":"bool"},{"internalType":"uint256","name":"sentAmount","type":"uint256"},{"internalType":"address","name":"swapper","type":"address"},{"internalType":"bytes","name":"payload","type":"bytes"},{"internalType":"uint256","name":"minRebalanceOut","type":"uint256"}],"internalType":"struct IEverlongALM.ExternalRebalanceParams","name":"swapParams","type":"tuple"}],"name":"activeRebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_swapRouter","type":"address"},{"internalType":"bool","name":"status","type":"bool"}],"name":"addWhitelistedSwapper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"collectProtocol","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0Desired","type":"uint256"},{"internalType":"uint256","name":"amount1Desired","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"slots","type":"bytes32[]"}],"name":"extSloads","outputs":[{"internalType":"bytes32[]","name":"res","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fullEmergencyBurn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getBalance0","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBalance1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPositions","outputs":[{"internalType":"int24[2][3]","name":"","type":"int24[2][3]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalAmounts","outputs":[{"internalType":"uint256","name":"total0","type":"uint256"},{"internalType":"uint256","name":"total1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"priceFeed","type":"address"},{"internalType":"address","name":"manager","type":"address"},{"internalType":"address","name":"rebalanceDelegate","type":"address"},{"internalType":"address","name":"depositDelegate","type":"address"},{"internalType":"uint24","name":"protocolFee","type":"uint24"},{"internalType":"uint256","name":"maxTotalSupply","type":"uint256"},{"internalType":"uint24","name":"wideRangeWeight","type":"uint24"},{"internalType":"int24","name":"wideThreshold","type":"int24"},{"internalType":"int24","name":"baseThreshold","type":"int24"},{"internalType":"int24","name":"limitThreshold","type":"int24"},{"internalType":"uint32","name":"period","type":"uint32"},{"internalType":"int24","name":"minTickMove","type":"int24"},{"internalType":"int24","name":"maxTwapDeviation","type":"int24"},{"internalType":"uint32","name":"twapDuration","type":"uint32"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint24","name":"swapDeviationThreshold","type":"uint24"},{"internalType":"uint24","name":"ratioDeviationThreshold","type":"uint24"},{"internalType":"uint24","name":"rebalanceDelegateCooldown","type":"uint24"},{"internalType":"uint24","name":"maxRatioDeviationThresholdIncrease","type":"uint24"},{"internalType":"address[]","name":"initialWhitelistedSwappers","type":"address[]"},{"internalType":"address","name":"getters","type":"address"}],"internalType":"struct IEverlongALM.VaultParams","name":"_params","type":"tuple"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pool","outputs":[{"internalType":"contract IUniswapV3Pool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFee","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"_baseThreshold","type":"int24"}],"name":"setBaseThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_depositDelegate","type":"address"}],"name":"setDepositDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_getters","type":"address"}],"name":"setGetters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"_limitThreshold","type":"int24"}],"name":"setLimitThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_manager","type":"address"}],"name":"setManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint24","name":"_maxRatioDeviationThresholdIncrease","type":"uint24"}],"name":"setMaxRatioDeviationThresholdIncrease","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxTotalSupply","type":"uint256"}],"name":"setMaxTotalSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"_maxTwapDeviation","type":"int24"}],"name":"setMaxTwapDeviation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"_minTickMove","type":"int24"}],"name":"setMinTickMove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_period","type":"uint32"}],"name":"setPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint24","name":"_pendingProtocolFee","type":"uint24"}],"name":"setProtocolFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint24","name":"_ratioDeviationThreshold","type":"uint24"}],"name":"setRatioDeviationThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rebalanceDelegate","type":"address"}],"name":"setRebalanceDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint24","name":"_rebalanceDelegateCooldown","type":"uint24"}],"name":"setRebalanceDelegateCooldown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint24","name":"_swapDeviationThreshold","type":"uint24"}],"name":"setSwapDeviationThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_twapDuration","type":"uint32"}],"name":"setTwapDuration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint24","name":"_wideRangeWeight","type":"uint24"}],"name":"setWideRangeWeight","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"_wideThreshold","type":"int24"}],"name":"setWideThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"sweep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token0","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"uniswapV3MintCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60a0604052306080523480156012575f80fd5b50608051615ef56100395f395f81816133e10152818161340a01526135400152615ef55ff3fe608060405260043610610243575f3560e01c806306fdde0314610247578063095ea7b3146102715780630dfe1681146102a057806316f0115b146102c157806318160ddd146102d55780631d769828146102f757806323b872dd146103185780632953323a14610337578063313ce5671461034b578063365d0ed7146103665780633cbff3fe146103945780633f3e4c11146103b357806341aec538146103d257806348ff15b3146103e65780634f1ef286146103fa57806352d1902d1461040d5780635d9b6fd414610421578063629d94051461044057806370a08231146104545780637784c685146104735780637d7c2a1c1461049f5780637feedaa1146104b357806380275860146104d257806388c74e08146104f35780639573ea251461051257806395d89b4114610531578063a632935514610545578063a7e6b92c14610564578063a9059cbb14610583578063ad3cb1cc146105a2578063af794480146105d2578063b0e21e8a146105f1578063b8ec2d3814610612578063bbd31f9f14610631578063c24e55b514610650578063c433c80a1461066f578063c4a7761e1461068e578063c4b4c30f146106b7578063c688d9a5146106d6578063d0a7a964146106f5578063d0ebdbe714610714578063d21220a714610733578063d331bef714610747578063d348799714610766578063dc2c256f14610785578063dd62ed3e146107a4578063f4005cae146107c3578063f5da7fd6146107e2578063f8d01c9d14610801578063fa461e3314610820578063fae1fb5f1461083f575b5f80fd5b348015610252575f80fd5b5061025b61085e565b6040516102689190614e08565b60405180910390f35b34801561027c575f80fd5b5061029061028b366004614e3e565b6108fc565b6040519015158152602001610268565b3480156102ab575f80fd5b506102b4610915565b6040516102689190614e75565b3480156102cc575f80fd5b506102b4610930565b3480156102e0575f80fd5b506102e961094b565b604051908152602001610268565b348015610302575f80fd5b50610316610311366004614e89565b610959565b005b348015610323575f80fd5b50610290610332366004614ea4565b610a2a565b348015610342575f80fd5b50610316610a4f565b348015610356575f80fd5b5060405160128152602001610268565b348015610371575f80fd5b50610385610380366004614ee2565b610aea565b60405161026893929190614f2b565b34801561039f575f80fd5b506103166103ae366004614f5a565b6110f8565b3480156103be575f80fd5b506103166103cd366004614f75565b611189565b3480156103dd575f80fd5b506102e96111d4565b3480156103f1575f80fd5b50610316611278565b61031661040836600461508c565b61130d565b348015610418575f80fd5b506102e961132c565b34801561042c575f80fd5b5061031661043b366004614e89565b611347565b34801561044b575f80fd5b506102e96113a8565b34801561045f575f80fd5b506102e961046e366004614e89565b6113f8565b34801561047e575f80fd5b5061049261048d3660046150fa565b611402565b6040516102689190615185565b3480156104aa575f80fd5b50610316611493565b3480156104be575f80fd5b506103166104cd3660046151d9565b61152f565b3480156104dd575f80fd5b506104e66115e8565b60405161026891906151f2565b3480156104fe575f80fd5b5061031661050d3660046151d9565b611682565b34801561051d575f80fd5b5061031661052c366004615259565b61170c565b34801561053c575f80fd5b5061025b61177c565b348015610550575f80fd5b5061031661055f366004614f5a565b611798565b34801561056f575f80fd5b5061031661057e366004615311565b611847565b34801561058e575f80fd5b5061029061059d366004614e3e565b612068565b3480156105ad575f80fd5b5061025b604051806040016040528060058152602001640352e302e360dc1b81525081565b3480156105dd575f80fd5b506103166105ec366004614f5a565b612075565b3480156105fc575f80fd5b506106056120f1565b604051610268919061554e565b34801561061d575f80fd5b5061031661062c36600461555e565b61210f565b34801561063c575f80fd5b5061031661064b366004615577565b61216d565b34801561065b575f80fd5b5061031661066a3660046151d9565b6121d5565b34801561067a575f80fd5b5061031661068936600461555e565b61225e565b348015610699575f80fd5b506106a26122e1565b60408051928352602083019190915201610268565b3480156106c2575f80fd5b506103166106d1366004614f5a565b61235e565b3480156106e1575f80fd5b506103166106f0366004614e89565b61240d565b348015610700575f80fd5b5061031661070f3660046151d9565b612494565b34801561071f575f80fd5b5061031661072e366004614e89565b612641565b34801561073e575f80fd5b506102b46126a2565b348015610752575f80fd5b506106a261076136600461561d565b6126bd565b348015610771575f80fd5b5061031661078036600461569f565b61297f565b348015610790575f80fd5b5061031661079f3660046156ed565b6129fd565b3480156107af575f80fd5b506102e96107be36600461572c565b612a76565b3480156107ce575f80fd5b506103166107dd366004614f5a565b612ab0565b3480156107ed575f80fd5b506103166107fc3660046151d9565b612b35565b34801561080c575f80fd5b5061031661081b366004614e89565b612bbf565b34801561082b575f80fd5b5061031661083a36600461569f565b612c20565b34801561084a575f80fd5b506103166108593660046151d9565b612c9b565b60605f610869612d21565b905080600301805461087a90615758565b80601f01602080910402602001604051908101604052809291908181526020018280546108a690615758565b80156108f15780601f106108c8576101008083540402835291602001916108f1565b820191905f5260205f20905b8154815290600101906020018083116108d457829003601f168201915b505050505091505090565b5f33610909818585612d45565b60019150505b92915050565b5f61091e612d52565b600301546001600160a01b0316919050565b5f610939612d52565b600101546001600160a01b0316919050565b5f610954612d76565b905090565b5f610962612d52565b80549091506001600160a01b0316331461098f57604051633bd5209f60e01b815260040160405180910390fd5b600a810180545f9091556001600160801b0380821691600160801b90041681156109cc5760038301546109cc906001600160a01b03168584612d8a565b80156109eb5760048301546109eb906001600160a01b03168583612d8a565b60408051838152602081018390527fd63986ca13f11502796aee70ba80ac7317d99f08e5871fd9fd602a2764c7ef30910160405180910390a150505050565b5f33610a37858285612de2565b610a42858585612e2c565b60019150505b9392505050565b610a57612e89565b5f610a60612d52565b600c810154909150610a8f90600160201b8104600290810b91600160381b9004900b6001600160801b03612ec2565b600c810154610abb90600160501b8104600290810b91600160681b9004900b6001600160801b03612ec2565b600c810154610ae790600160801b8104600290810b91600160981b9004900b6001600160801b03612ec2565b50565b5f805f610af5612fc3565b5f610afe612d52565b60088101549091506001600160a01b031615610b415760088101546001600160a01b03163314610b4157604051630a2002cb60e01b815260040160405180910390fd5b88158015610b4d575087155b15610b6b5760405163f7e8bf5d60e01b815260040160405180910390fd5b6001600160a01b0385161580610b8957506001600160a01b03851630145b15610ba757604051637c878f9360e01b815260040160405180910390fd5b80600f015f9054906101000a90046001600160a01b03166001600160a01b031663345d90e26040518163ffffffff1660e01b81526004015f6040518083038186803b158015610bf4575f80fd5b505afa158015610c06573d5f803e3d5ffd5b505050505f610c136115e8565b9050610c1d614d71565b5f5b6003811015610d6a57610c66838260038110610c3d57610c3d615790565b602002015151848360038110610c5557610c55615790565b602002015160016020020151612ff8565b508592508491505060038110610c7e57610c7e615790565b6001600160801b0390921660209290920201525f828260038110610ca457610ca4615790565b60200201516001600160801b03161115610d625760018401546001600160a01b031663a34123a7848360038110610cdd57610cdd615790565b602002015151858460038110610cf557610cf5615790565b6020020151600160200201515f6040518463ffffffff1660e01b8152600401610d20939291906157a4565b60408051808303815f875af1158015610d3b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d5f91906157ca565b50505b600101610c1f565b505f610d7461094b565b9050610d8284828e8e6130d2565b919850965094505f879003610daa57604051631f65ad9d60e01b815260040160405180910390fd5b89861015610dcb57604051631121139960e11b815260040160405180910390fd5b88851015610dec57604051634824c64160e11b815260040160405180910390fd5b805f03610e0157610e0161dead6103e86131eb565b8515610e21576003840154610e21906001600160a01b031633308961321f565b8415610e41576004840154610e41906001600160a01b031633308861321f565b8015610e4d5780610e59565b610e596103e882615800565b90505f846001015f9054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015610eae573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ed29190615824565b509495508b94508a93505f925050505b6003811015611058575f878260038110610efe57610efe615790565b60200201515190505f888360038110610f1957610f19615790565b60200201516001602002015190505f888460038110610f3a57610f3a615790565b60200201516001600160801b0316111561104e575f610f79898560038110610f6457610f64615790565b60200201516001600160801b03168f8a613258565b90505f736c4e0f30ee76a1c360387a0504f32c991d46f817636bea771a85858a8a8d6040518663ffffffff1660e01b8152600401610fbb9594939291906158b6565b602060405180830381865af4158015610fd6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ffa91906158ff565b9050806001600160801b0316826001600160801b03161161101b578161101d565b805b91505f8061102c868686613301565b909250905061103b828a615918565b98506110478189615918565b9750505050505b5050600101610ee2565b506110638b8b6131eb565b8a6001600160a01b0316336001600160a01b03167f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f68c8c8c6040516110aa93929190614f2b565b60405180910390a386600901546110bf61094b565b11156110de5760405163dbc1bae360e01b815260040160405180910390fd5b505050505050506110ed6133c6565b955095509592505050565b611100612e89565b5f611109612d52565b90505f8260020b121561112f5760405163445f5a6f60e11b815260040160405180910390fd5b600b8101805462ffffff60e01b1916600160e01b62ffffff8516021790556040517f957dddabc1ac2b52bf67ebbe53150c1b46f57ec0e1dc487632d5bcc3a36a2d829061117d90849061592b565b60405180910390a15050565b611191612e89565b5f61119a612d52565b600981018390556040518381529091507f49e8da6bc2b1ffc75cb81c88d1a8e64d5b1224c626dc9be8787d6ff982b46a399060200161117d565b5f806111de612d52565b600a8101546004808301546040516370a0823160e01b8152939450600160801b9092046001600160801b0316926001600160a01b03909216916370a082319161122991309101614e75565b602060405180830381865afa158015611244573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112689190615939565b6112729190615918565b91505090565b5f611281612d52565b60068101549091506001600160a01b031633146112b1576040516323920ffd60e11b815260040160405180910390fd5b600581018054336001600160a01b0319918216811790925560068301805490911690556040517f5c18ab5c697b63d102fc7e14c77bfaef0f1013206eca139920fd389277814e099161130291614e75565b60405180910390a150565b6113156133d6565b61131e8261347a565b6113288282613482565b5050565b5f611335613535565b505f80516020615e7983398151915290565b61134f612e89565b5f611358612d52565b6008810180546001600160a01b0319166001600160a01b0385161790556040519091507f3b3e178c01607aa6eab8fd24b33e3de1d5f41d603b21010e65903bdce27dec139061117d908490614e75565b5f806113b2612d52565b600a81015460038201546040516370a0823160e01b81529293506001600160801b03909116916001600160a01b03909116906370a0823190611229903090600401614e75565b5f61090f8261357e565b8051606090806001600160401b0381111561141f5761141f614f8c565b604051908082528060200260200182016040528015611448578160200160208202803683370190505b5091505f5b8181101561148c575f848261146181615950565b93508151811061147357611473615790565b602002602001015190508054602083028501525061144d565b5050919050565b61149b612fc3565b6114a36135a7565b6114ab612d52565b600f015f9054906101000a90046001600160a01b03166001600160a01b03166371bd0ea76040518163ffffffff1660e01b81526004015f6040518083038186803b1580156114f7575f80fd5b505afa158015611509573d5f803e3d5ffd5b505050506115156135fb565b611525611520613605565b613673565b61152d6133c6565b565b5f611538612d52565b80549091506001600160a01b0316331461156557604051633bd5209f60e01b815260040160405180910390fd5b6203d0908262ffffff16111561158e57604051630f28c84160e11b815260040160405180910390fd5b611599826001615968565b81600b0160076101000a81548162ffffff021916908362ffffff1602179055507f24a0d123bf9f15cb6bd5c3bc9b5cfe044075db4114c7a2f2a83a2409de73ac928260405161117d919061554e565b6115f0614d8f565b5f6115f9612d52565b6040805160a081018252600c90920154600160201b8104600290810b60608501908152600160381b8304820b6080860152845282518084018452600160501b8304820b8152600160681b8304820b6020828101919091528086019190915283518085018552600160801b8404830b8152600160981b90930490910b908201529082015292915050565b61168a612e89565b5f611693612d52565b9050620f424062ffffff831611156116be57604051637eb4a3ab60e11b815260040160405180910390fd5b600d8101805465ffffff0000001916630100000062ffffff8516021790556040517f9ed124f3fe3c19722c9573c877ab9038c8257f068248c730533542993bab11e09061117d90849061554e565b5f611715612d52565b80549091506001600160a01b0316331461174257604051633bd5209f60e01b815260040160405180910390fd5b6001600160a01b0383166117695760405163746db8e560e01b815260040160405180910390fd5b611777600e82018484613f0e565b505050565b60605f611787612d21565b905080600401805461087a90615758565b6117a0612e89565b5f6117a9612d52565b600b810154909150600160981b9004600290810b9083900b036117df576040516306dde9e760e21b815260040160405180910390fd5b600b8101546117f9908390600160c81b900460020b613f6b565b600b8101805462ffffff60681b1916600160681b62ffffff8516021790556040517ff1759909677b9c42577caba6b12efd5bcf3a398d02a2c1c97d23bbd312b561a79061117d90849061592b565b5f611850613fb9565b805490915060ff600160401b82041615906001600160401b03165f811580156118765750825b90505f826001600160401b031660011480156118915750303b155b90508115801561189f575080155b156118bd5760405163f92ee8a960e01b815260040160405180910390fd5b84546001600160401b031916600117855583156118e657845460ff60401b1916600160401b1785555b6118fa866102000151876102200151613fdd565b611902613fef565b5f61190b612d52565b875181546001600160a01b03199081166001600160a01b039283161783556020808b0151600185018054841691851691821790556040808d01516002870180549095169516949094179092558251630dfe168160e01b815292519394509092630dfe16819260048082019392918290030181865afa15801561198f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119b39190615983565b6003820180546001600160a01b0319166001600160a01b0392831617905560018201546040805163d21220a760e01b81529051919092169163d21220a79160048083019260209291908290030181865afa158015611a13573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a379190615983565b600482810180546001600160a01b0319166001600160a01b039384161790556001830154604080516334324e9f60e21b815290515f94929092169263d0c93a7c9282820192602092908290030181865afa158015611a97573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611abb919061599e565b600b8301805462ffffff60c81b1916600160c81b62ffffff84160217905590508080611aea620d89e7196159b9565b611af491906159ed565b611afe9190615a25565b82600d015f6101000a81548162ffffff021916908360020b62ffffff1602179055508760600151826005015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055508760800151826007015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055508760a00151826008015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055508760e00151826009018190555087610140015182600b01600d6101000a81548162ffffff021916908360020b62ffffff16021790555087610160015182600b0160106101000a81548162ffffff021916908360020b62ffffff16021790555087610100015182600b01600a6101000a81548162ffffff021916908362ffffff16021790555087610120015182600b0160136101000a81548162ffffff021916908360020b62ffffff16021790555087610180015182600b015f6101000a81548163ffffffff021916908363ffffffff160217905550876101a0015182600b0160166101000a81548162ffffff021916908360020b62ffffff160217905550876101c0015182600b01601c6101000a81548162ffffff021916908360020b62ffffff160217905550876101e0015182600c015f6101000a81548163ffffffff021916908363ffffffff1602179055508760c0015182600b0160046101000a81548162ffffff021916908362ffffff16021790555087610240015182600d0160036101000a81548162ffffff021916908362ffffff16021790555087610260015182600d0160066101000a81548162ffffff021916908362ffffff16021790555087610280015182600d0160096101000a81548162ffffff021916908362ffffff1602179055504282600d01600c6101000a81548164ffffffffff021916908364ffffffffff160217905550876102a0015182600d0160116101000a81548162ffffff021916908362ffffff160217905550876102e0015182600f015f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550611e1088610140015182613f6b565b611e1f88610160015182613f6b565b611e2e88610120015182613f6b565b620f424062ffffff1688610100015162ffffff161115611e6157604051630b5073c960e01b815260040160405180910390fd5b5f886101a0015160020b1215611e8a57604051636927528b60e01b815260040160405180910390fd5b5f886101c0015160020b1215611eb35760405163445f5a6f60e11b815260040160405180910390fd5b876101e0015163ffffffff165f03611ede5760405163bfd58a7960e01b815260040160405180910390fd5b87610140015160020b88610120015160020b03611f0e576040516306dde9e760e21b815260040160405180910390fd5b620f424062ffffff1688610240015162ffffff161115611f4157604051637eb4a3ab60e11b815260040160405180910390fd5b620f424062ffffff1688610260015162ffffff161115611f745760405163164881f360e01b815260040160405180910390fd5b87610280015162ffffff165f03611f9e57604051633d73a3e160e11b815260040160405180910390fd5b876102a0015162ffffff165f03611fc85760405163712ee3d360e01b815260040160405180910390fd5b5f5b886102c00151518110156120175761200f896102c001518281518110611ff257611ff2615790565b6020026020010151600185600e01613f0e9092919063ffffffff16565b600101611fca565b505050831561206057845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050565b5f33610909818585612e2c565b61207d612e89565b5f612086612d52565b600b8101549091506120a3908390600160c81b900460020b613f6b565b600b8101805462ffffff60801b1916600160801b62ffffff8516021790556040517fc797ac22933a04255304effee6a7d3c3e4bbfaa0b2897c52c61a8b1fb027b9f29061117d90849061592b565b5f6120fa612d52565b600b0154600160201b900462ffffff16919050565b612117612e89565b5f612120612d52565b600b8101805463ffffffff191663ffffffff85169081179091556040519081529091507fa55d4ed589bc280e365d3ff1dc7fe4f59dff2d75e22716e29d6a9158fe0598469060200161117d565b612175612fc3565b61217d6135a7565b60408101516001600160a01b03166121a85760405163746db8e560e01b815260040160405180910390fd5b6121b06135fb565b6121b981613673565b6121c25f613fff565b6121cd611520613605565b610ae76133c6565b6121dd612e89565b5f6121e6612d52565b9050620f424062ffffff8316111561221157604051630b5073c960e01b815260040160405180910390fd5b600b8101805462ffffff60501b1916600160501b62ffffff8516021790556040517e47af854b92d7c4ca4913ffd329caf1c2e2b5e262b29139ae6cb247f18b886c9061117d90849061554e565b612266612e89565b5f61226f612d52565b90508163ffffffff165f036122975760405163bfd58a7960e01b815260040160405180910390fd5b600c8101805463ffffffff191663ffffffff84169081179091556040519081527f2402faf0100aca3dc010189fd1fb0e310ab05da61ce9a65457e0fe7018e920d99060200161117d565b5f806122eb612d52565b600f01546040516347c570fd60e01b81525f60048201526001600160a01b03909116906347c570fd906024016040805180830381865afa158015612331573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061235591906157ca565b90939092509050565b612366612e89565b5f61236f612d52565b600b810154909150600160681b9004600290810b9083900b036123a5576040516306dde9e760e21b815260040160405180910390fd5b600b8101546123bf908390600160c81b900460020b613f6b565b600b8101805462ffffff60981b1916600160981b62ffffff8516021790556040517f6be14bdbb0283c52b91dff0090b8bda078b11ce7f87486a7c14ae7595fd0f9389061117d90849061592b565b612415612e89565b5f61241e612d52565b90506001600160a01b0382166124475760405163746db8e560e01b815260040160405180910390fd5b600f810180546001600160a01b0319166001600160a01b0384161790556040517fa5e5f21996a9e755b40ab15ce550a8e3a8fc1f785f595161a00f887078ff01dc9061117d908490614e75565b61249c6135a7565b5f6124a5612d52565b9050620f424062ffffff831611156124d05760405163164881f360e01b815260040160405180910390fd5b600d81015462ffffff600160301b909104811690831611156125d157600d8101545f906125259061250f90600160601b900464ffffffffff1642615918565b600d840154600160481b900462ffffff166140c9565b600d8301549091505f9062ffffff600160481b820481169161255091600160881b9091041684615a4b565b61255a9190615a62565b600d840154909150612579908290600160301b900462ffffff16615800565b8462ffffff1611156125ce57600d83015484906125a3908390600160301b900462ffffff16615800565b6040516313c042e760e21b815262ffffff909216600483015260248201526044015b60405180910390fd5b50505b600d810180546affffffffff000000ffffff60301b1916600160301b62ffffff85160264ffffffffff60601b191617600160601b4264ffffffffff16021790556040517fa576875e509dca098a87c161a87c921b7e48b19999837e3c3c5529348cef73739061117d90849061554e565b612649612e89565b5f612652612d52565b6006810180546001600160a01b0319166001600160a01b0385161790556040519091507f4d3334a0a69f5f1c54636cf743914f0b34fb2e7849b55ee7c1faddd0e06b4dfd9061117d908490614e75565b5f6126ab612d52565b600401546001600160a01b0316919050565b5f806126c7612fc3565b5f6126d0612d52565b9050865f036126f257604051631f65ad9d60e01b815260040160405180910390fd5b6001600160a01b038416158061271057506001600160a01b03841630145b1561272e57604051637c878f9360e01b815260040160405180910390fd5b5f61273761094b565b905061274333896140de565b808861274d6113a8565b6127579190615a4b565b6127619190615a62565b9350808861276d6111d4565b6127779190615a4b565b6127819190615a62565b92506127b66040518060c001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b600c8301546127dc90600160201b8104600290810b91600160381b9004900b8b85614112565b60208301528152600c83015461280990600160501b8104600290810b91600160681b9004900b8b85614112565b60608301526040820152600c83015461283990600160801b8104600290810b91600160981b9004900b8b85614112565b60a083015260808201819052604082015182516128569088615800565b6128609190615800565b61286a9190615800565b94508060a0015181606001518260200151866128869190615800565b6128909190615800565b61289a9190615800565b9350878510156128bd57604051631121139960e11b815260040160405180910390fd5b868410156128de57604051634824c64160e11b815260040160405180910390fd5b84156128fd5760038301546128fd906001600160a01b03168787612d8a565b831561291c57600483015461291c906001600160a01b03168786612d8a565b856001600160a01b0316336001600160a01b03167febff2602b3f468259e1e99f613fed6691f3a6526effe6ef3e768ba7ae7a36c4f8b888860405161296393929190614f2b565b60405180910390a35050506129766133c6565b94509492505050565b5f612988612d52565b60018101549091506001600160a01b031633146129b857604051630e18314d60e01b815260040160405180910390fd5b84156129d75760038101546129d7906001600160a01b03163387612d8a565b83156129f65760048101546129f6906001600160a01b03163386612d8a565b5050505050565b612a05612e89565b5f612a0e612d52565b60038101549091506001600160a01b0385811691161480612a3e575060048101546001600160a01b038581169116145b15612a5c576040516308bde84760e41b815260040160405180910390fd5b612a706001600160a01b0385168385612d8a565b50505050565b5f80612a80612d21565b6001600160a01b039485165f90815260019190910160209081526040808320959096168252939093525050205490565b612ab8612e89565b5f612ac1612d52565b90505f8260020b1215612ae757604051636927528b60e01b815260040160405180910390fd5b600b8101805462ffffff60b01b1916600160b01b62ffffff8516021790556040517f52a3cbe96b59de1055b9b043e8906557387b821f26af47beea677164a7f26b629061117d90849061592b565b612b3d612e89565b5f612b46612d52565b9050620f424062ffffff83161115612b715760405163712ee3d360e01b815260040160405180910390fd5b600d8101805462ffffff60881b1916600160881b62ffffff8516021790556040517f844c878cbc82b5c2b2a506e29cbabbd2829292d0f875d96b5063898879326e859061117d90849061554e565b612bc7612e89565b5f612bd0612d52565b6007810180546001600160a01b0319166001600160a01b0385161790556040519091507f02d71f3b54d658df30617ce7b33fa5f9835dd21a1da2a6dce6368dc9e5a40a979061117d908490614e75565b5f612c29612d52565b60018101549091506001600160a01b03163314612c5957604051630e18314d60e01b815260040160405180910390fd5b5f851315612c7a576003810154612c7a906001600160a01b03163387612d8a565b5f8413156129f65760048101546129f6906001600160a01b03163386612d8a565b612ca3612e89565b5f612cac612d52565b90508162ffffff165f03612cd357604051633d73a3e160e11b815260040160405180910390fd5b600d8101805462ffffff60481b1916600160481b62ffffff8516021790556040517f2f11ce9f67c3ee30ded0d2833bc7428a527dc8d3e61c39a4b11865956a66cd359061117d90849061554e565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0090565b61177783838360016141c8565b7fb4801203179a1f53d2a89513756c4fddeb24d0f949ce9fc7cf03114c341dc50090565b5f80612d80612d21565b6002015492915050565b61177783846001600160a01b031663a9059cbb8585604051602401612db0929190615a75565b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506142a8565b5f612ded8484612a76565b90505f198114612a705781811015612e1e57828183604051637dc7a0d960e11b81526004016125c593929190615a8e565b612a7084848484035f6141c8565b6001600160a01b038316612e55575f604051634b637e8f60e11b81526004016125c59190614e75565b6001600160a01b038216612e7e575f60405163ec442f0560e01b81526004016125c59190614e75565b61177783838361430b565b5f612e92612d52565b60058101549091506001600160a01b03163314610ae75760405163307b0c8760e11b815260040160405180910390fd5b5f612ecb612d52565b600181015460405163a34123a760e01b81529192506001600160a01b03169063a34123a790612f02908790879087906004016157a4565b60408051808303815f875af1158015612f1d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f4191906157ca565b505060018101546040516309e3d67b60e31b81526001600160a01b0390911690634f1eb3d890612f84903090889088906001600160801b03908190600401615aaf565b60408051808303815f875af1158015612f9f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120609190615aec565b5f612fcc61442e565b805490915060011901612ff257604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b5f805f805f80613006612d52565b604080513060601b6001600160601b03191660208083019190915260e88c811b60348401528b901b60378301528251601a818403018152603a90920190925280519101209091505f90600183015460405163514ea4bf60e01b8152600481018390529192506001600160a01b03169063514ea4bf9060240160a060405180830381865afa158015613099573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906130bd9190615b1d565b939d929c50909a509850909650945050505050565b600f8401546040516347c570fd60e01b8152600160048201525f9182918291829182916001600160a01b0316906347c570fd906024016040805180830381865afa158015613122573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061314691906157ca565b60405163030e25c760e31b8152600481018b90526024810183905260448101829052606481018a9052608481018990529193509150736c4e0f30ee76a1c360387a0504f32c991d46f817906318712e389060a401606060405180830381865af41580156131b5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131d99190615b71565b919b909a509098509650505050505050565b6001600160a01b038216613214575f60405163ec442f0560e01b81526004016125c59190614e75565b6113285f838361430b565b6040516001600160a01b038481166024830152838116604483015260648201839052612a709186918216906323b872dd90608401612db0565b5f80805f19858709858702925082811083820303915050805f0361328f57838281613285576132856159d9565b0492505050610a48565b80841161329a575f80fd5b5f8486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091025f889003889004909101858311909403939093029303949094049190911702949350505050565b5f805f61330c612d52565b90506001600160801b038416156133bd576001810154604051633c8a7d8d60e01b8152306004820152600288810b602483015287900b60448201526001600160801b038616606482015260a060848201525f60a48201526001600160a01b0390911690633c8a7d8d9060c40160408051808303815f875af1158015613393573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906133b791906157ca565b90935091505b50935093915050565b5f6133cf61442e565b6001905550565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148061345c57507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166134505f80516020615e79833981519152546001600160a01b031690565b6001600160a01b031614155b1561152d5760405163703e46dd60e11b815260040160405180910390fd5b610ae7612e89565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156134dc575060408051601f3d908101601f191682019092526134d991810190615939565b60015b6134fb5781604051634c9c8ce360e01b81526004016125c59190614e75565b5f80516020615e79833981519152811461352b57604051632a87526960e21b8152600481018290526024016125c5565b6117778383614452565b306001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461152d5760405163703e46dd60e11b815260040160405180910390fd5b5f80613588612d21565b6001600160a01b039093165f9081526020939093525050604090205490565b5f6135b0612d52565b60058101549091506001600160a01b031633148015906135dd575060078101546001600160a01b03163314155b15610ae7576040516319bb854760e21b815260040160405180910390fd5b61152d6001613fff565b6040805160a0810182525f8082526020820181905291810182905260608082015260808101919091526040518060a001604052805f151581526020015f81526020015f6001600160a01b0316815260200160405180602001604052805f81525081526020015f815250905090565b5f61367c612d52565b90505f80826001015f9054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156136d2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906136f69190615824565b5050505050915091505f805f805f736c4e0f30ee76a1c360387a0504f32c991d46f81763756d1aca878a600b0160199054906101000a900460020b6040518363ffffffff1660e01b815260040161374e929190615b9c565b602060405180830381865af4158015613769573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061378d919061599e565b600b8901549091505f906137ab90600160c81b900460020b83615bb0565b600d8a0154600b8b0154919250600290810b91736c4e0f30ee76a1c360387a0504f32c991d46f81791633e68e68f916137ee91600160981b909104900b86615bd5565b836040518363ffffffff1660e01b815260040161380c929190615b9c565b602060405180830381865af4158015613827573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061384b919061599e565b600c8b01805462ffffff92909216600160201b0262ffffff60201b19909216919091179055600b8a0154736c4e0f30ee76a1c360387a0504f32c991d46f81790633e68e68f906138a590600160981b900460020b85615bb0565b836040518363ffffffff1660e01b81526004016138c3929190615b9c565b602060405180830381865af41580156138de573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613902919061599e565b600c8b01805462ffffff92909216600160381b0262ffffff60381b19909216919091179055600b8a015461394090600160681b900460020b84615bd5565b600c8b01805462ffffff92909216600160501b0262ffffff60501b19909216919091179055600b8a015461397e90600160681b900460020b83615bb0565b600c8b01805462ffffff92909216600160681b0262ffffff60681b19909216919091179055600b8a01546139bc90600160801b900460020b84615bd5565b965082955081945089600b0160109054906101000a900460020b826139e19190615bb0565b93505050505f6139ef6113a8565b90505f6139fa6111d4565b90507f210f60adf1db7a02e9db9a49ec7c2eb2060c516cbcfd01a0c05288144738ee5d878383613a2861094b565b6040805160029590950b8552602085019390935291830152606082015260800160405180910390a1600b890154600160501b900462ffffff1615613b93575f736c4e0f30ee76a1c360387a0504f32c991d46f817636bea771a8b600c0160049054906101000a900460020b8c600c0160079054906101000a900460020b86868e6040518663ffffffff1660e01b8152600401613ac89594939291906158b6565b602060405180830381865af4158015613ae3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613b0791906158ff565b600b8b0154909150613b4690620f424090613b3790600160501b900462ffffff166001600160801b038516615a4b565b613b419190615a62565b6144a7565b600c8b01549091505f908190613b7290600160201b8104600290810b91600160381b9004900b85613301565b9092509050613b818286615918565b9450613b8d8185615918565b93505050505b5f736c4e0f30ee76a1c360387a0504f32c991d46f817636bea771a8b600c01600a9054906101000a900460020b8c600c01600d9054906101000a900460020b86868e6040518663ffffffff1660e01b8152600401613bf59594939291906158b6565b602060405180830381865af4158015613c10573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613c3491906158ff565b600c8b01549091505f908190613c6090600160501b8104600290810b91600160681b9004900b85613301565b9092509050613c6f8286615918565b9450613c7b8185615918565b93505050505f6001600160a01b03168a604001516001600160a01b031614613cad57613ca88a83836144c3565b613e66565b5f736c4e0f30ee76a1c360387a0504f32c991d46f817636bea771a888886868e6040518663ffffffff1660e01b8152600401613ced9594939291906158b6565b602060405180830381865af4158015613d08573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613d2c91906158ff565b90505f736c4e0f30ee76a1c360387a0504f32c991d46f817636bea771a878787878f6040518663ffffffff1660e01b8152600401613d6e9594939291906158b6565b602060405180830381865af4158015613d89573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613dad91906158ff565b9050806001600160801b0316826001600160801b03161115613e1857613dd4888884613301565b5050600c8b01805462ffffff898116600160981b0262ffffff60981b19918c16600160801b029190911665ffffffffffff60801b1990921691909117179055613e63565b613e23868683613301565b5050600c8b01805462ffffff878116600160981b0262ffffff60981b19918a16600160801b029190911665ffffffffffff60801b19909216919091171790555b50505b600c89018054600160b01b600160f01b031916600160c81b4264ffffffffff160262ffffff60b01b191617600160b01b62ffffff8a81169190910291909117909155600b8a0154600160381b8104821691600160201b909104168115613f00575f613ed2600184615bfa565b600b8d01805465ffffffffffff60201b1916600160201b62ffffff84160262ffffff60381b19161790559150505b505050505050505050505050565b6001600160a01b0382165f8181526020858152604091829020805460ff191685151590811790915591519182527f7dc49220c17ba736a5a8f465c46784ed2262884e4ea605ae95e6fd117a77a421910160405180910390a2505050565b5f8260020b13613f8e57604051634416881b60e11b815260040160405180910390fd5b613f988183615c15565b60020b156113285760405163265fe24560e01b815260040160405180910390fd5b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0090565b613fe561471b565b6113288282614740565b613ff761471b565b61152d614770565b5f614008612d52565b600c810154909150600160201b8104600290810b91600160381b8104820b91600160501b8204810b91600160681b9004900b5f6140458585612ff8565b5050505090505f6140568484612ff8565b505050509050614067868684614778565b50505050614076848483614778565b5050505087156140bf57600c870154600160801b8104600290810b91600160981b9004900b5f6140a68383612ff8565b5050505090506140b7838383614778565b505050505050505b5050505050505050565b5f8183106140d75781610a48565b5090919050565b6001600160a01b038216614107575f604051634b637e8f60e11b81526004016125c59190614e75565b611328825f8361430b565b5f805f61411f8787612ff8565b5050505090505f61413a826001600160801b03168787613258565b90506001600160801b038116156141bd575f805f8061415a8c8c87614778565b9350935093509350888a836001600160801b03166141789190615a4b565b6141829190615a62565b61418c9085615800565b9750886141a28b6001600160801b038416615a4b565b6141ac9190615a62565b6141b69084615800565b9650505050505b505094509492505050565b5f6141d1612d21565b90506001600160a01b0385166141fc575f60405163e602df0560e01b81526004016125c59190614e75565b6001600160a01b038416614225575f604051634a1406b160e11b81526004016125c59190614e75565b6001600160a01b038086165f908152600183016020908152604080832093881683529290522083905581156129f657836001600160a01b0316856001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258560405161429991815260200190565b60405180910390a35050505050565b5f8060205f8451602086015f885af1806142c7576040513d5f823e3d81fd5b50505f513d915081156142de5780600114156142eb565b6001600160a01b0384163b155b15612a705783604051635274afe760e01b81526004016125c59190614e75565b5f614314612d21565b90506001600160a01b0384166143425781816002015f8282546143379190615800565b9091555061439f9050565b6001600160a01b0384165f90815260208290526040902054828110156143815784818460405163391434e360e21b81526004016125c593929190615a8e565b6001600160a01b0385165f9081526020839052604090209083900390555b6001600160a01b0383166143bd5760028101805483900390556143db565b6001600160a01b0383165f9081526020829052604090208054830190555b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161442091815260200190565b60405180910390a350505050565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0090565b61445b82614a1c565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a280511561449f576117778282614a76565b611328614a9b565b5f6001600160801b038211156144bf576144bf615c36565b5090565b5f6144cc612d52565b90505f845f01516144ea5760048201546001600160a01b03166144f9565b60038201546001600160a01b03165b90505f855f01516145175760038301546001600160a01b0316614526565b60048301546001600160a01b03165b6002840154604051635670bcc760e11b81529192506001600160a01b0316905f90829063ace1798e9061455d908790600401614e75565b602060405180830381865afa158015614578573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061459c9190615939565b90505f826001600160a01b031663ace1798e856040518263ffffffff1660e01b81526004016145cb9190614e75565b602060405180830381865afa1580156145e6573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061460a9190615939565b90505f895f015161461b578861461d565b875b90505f8a5f015161462e5788614630565b895b9050808b6020015111156146675760208b01516040516367f6e06560e01b81526125c5918391600401918252602082015260400190565b60408b015160208c0151614685916001600160a01b038a1691614aba565b60408b015160608c015161469d91600e8b0191614b4a565b60408b01516146b7906001600160a01b038916905f614aba565b600f88015460405163756041cf60e11b81526001600160a01b039091169063eac0839e906146f3908e9086908c908c908b908b90600401615c4a565b5f6040518083038186803b158015614709575f80fd5b505afa1580156140b7573d5f803e3d5ffd5b614723614bed565b61152d57604051631afcd79f60e31b815260040160405180910390fd5b61474861471b565b5f614751612d21565b9050600381016147618482615d1a565b5060048101612a708382615d1a565b6133c661471b565b5f805f805f614785612d52565b90506001600160801b0386161561481157600181015460405163a34123a760e01b81526001600160a01b039091169063a34123a7906147cc908b908b908b906004016157a4565b60408051808303815f875af11580156147e7573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061480b91906157ca565b90955093505b60018101546040516309e3d67b60e31b81525f9182916001600160a01b0390911690634f1eb3d8906148569030908e908e906001600160801b03908190600401615aaf565b60408051808303815f875af1158015614871573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906148959190615aec565b90925090506148ad876001600160801b038416615918565b94506148c2866001600160801b038316615918565b600b840154909450600160201b900462ffffff165f620f42406148e58389615dd4565b6148ef9190615df6565b90505f620f424061490562ffffff851689615dd4565b61490f9190615df6565b600a8701805491925083915f906149309084906001600160801b0316615e24565b92506101000a8154816001600160801b0302191690836001600160801b031602179055508086600a0160108282829054906101000a90046001600160801b031661497a9190615e24565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555081886149aa9190615e43565b97506149b68188615e43565b604080516001600160801b038b811682528381166020830152858116828401528416606082015290519198507f1ac56d7e866e3f5ea9aa92aa11758ead39a0a5f013f3fefb0f47cb9d008edd27919081900360800190a150505050505093509350935093565b806001600160a01b03163b5f03614a485780604051634c9c8ce360e01b81526004016125c59190614e75565b5f80516020615e7983398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6060610a488383604051806060016040528060278152602001615e9960279139614c06565b341561152d5760405163b398979f60e01b815260040160405180910390fd5b5f836001600160a01b031663095ea7b38484604051602401614add929190615a75565b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050509050614b168482614c7a565b612a7057614b4084856001600160a01b031663095ea7b3865f604051602401612db0929190615a75565b612a7084826142a8565b6001600160a01b0382165f9081526020849052604090205460ff16614b8257604051635d7763a160e11b815260040160405180910390fd5b5f80836001600160a01b031683604051614b9c9190615e62565b5f604051808303815f865af19150503d805f8114614bd5576040519150601f19603f3d011682016040523d82523d5f602084013e614bda565b606091505b5091509150816129f6576129f681614cbf565b5f614bf6613fb9565b54600160401b900460ff16919050565b60605f80856001600160a01b031685604051614c229190615e62565b5f60405180830381855af49150503d805f8114614c5a576040519150601f19603f3d011682016040523d82523d5f602084013e614c5f565b606091505b5091509150614c7086838387614cc7565b9695505050505050565b5f805f8060205f8651602088015f8a5af192503d91505f519050828015614c7057508115614cab5780600114614c70565b50505050506001600160a01b03163b151590565b805160208201fd5b60608315614d355782515f03614d2e576001600160a01b0385163b614d2e5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016125c5565b5081614d3f565b614d3f8383614d47565b949350505050565b815115614d575781518083602001fd5b8060405162461bcd60e51b81526004016125c59190614e08565b60405180606001604052806003906020820280368337509192915050565b60405180606001604052806003905b614da6614dbc565b815260200190600190039081614d9e5790505090565b60405180604001604052806002906020820280368337509192915050565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f610a486020830184614dda565b6001600160a01b0381168114610ae7575f80fd5b8035614e3981614e1a565b919050565b5f8060408385031215614e4f575f80fd5b8235614e5a81614e1a565b946020939093013593505050565b6001600160a01b03169052565b6001600160a01b0391909116815260200190565b5f60208284031215614e99575f80fd5b8135610a4881614e1a565b5f805f60608486031215614eb6575f80fd5b8335614ec181614e1a565b92506020840135614ed181614e1a565b929592945050506040919091013590565b5f805f805f60a08688031215614ef6575f80fd5b853594506020860135935060408601359250606086013591506080860135614f1d81614e1a565b809150509295509295909350565b9283526020830191909152604082015260600190565b8060020b8114610ae7575f80fd5b8035614e3981614f41565b5f60208284031215614f6a575f80fd5b8135610a4881614f41565b5f60208284031215614f85575f80fd5b5035919050565b634e487b7160e01b5f52604160045260245ffd5b60405161030081016001600160401b0381118282101715614fc357614fc3614f8c565b60405290565b60405160a081016001600160401b0381118282101715614fc357614fc3614f8c565b604051601f8201601f191681016001600160401b038111828210171561501357615013614f8c565b604052919050565b5f82601f83011261502a575f80fd5b8135602083015f806001600160401b0384111561504957615049614f8c565b50601f8301601f191660200161505e81614feb565b915050828152858383011115615072575f80fd5b828260208301375f92810160200192909252509392505050565b5f806040838503121561509d575f80fd5b82356150a881614e1a565b915060208301356001600160401b038111156150c2575f80fd5b6150ce8582860161501b565b9150509250929050565b5f6001600160401b038211156150f0576150f0614f8c565b5060051b60200190565b5f6020828403121561510a575f80fd5b81356001600160401b0381111561511f575f80fd5b8201601f8101841361512f575f80fd5b803561514261513d826150d8565b614feb565b8082825260208201915060208360051b850101925086831115615163575f80fd5b6020840193505b82841015614c7057833582526020938401939091019061516a565b602080825282518282018190525f918401906040840190835b818110156151bc57835183526020938401939092019160010161519e565b509095945050505050565b803562ffffff81168114614e39575f80fd5b5f602082840312156151e9575f80fd5b610a48826151c7565b60c0810181835f5b6003811015615243578151835f5b600281101561522a57825160020b825260209283019290910190600101615208565b50505060409290920191602091909101906001016151fa565b50505092915050565b8015158114610ae7575f80fd5b5f806040838503121561526a575f80fd5b823561527581614e1a565b915060208301356152858161524c565b809150509250929050565b803563ffffffff81168114614e39575f80fd5b5f82601f8301126152b2575f80fd5b81356152c061513d826150d8565b8082825260208201915060208360051b8601019250858311156152e1575f80fd5b602085015b838110156153075780356152f981614e1a565b8352602092830192016152e6565b5095945050505050565b5f60208284031215615321575f80fd5b81356001600160401b03811115615336575f80fd5b82016103008185031215615348575f80fd5b615350614fa0565b61535982614e2e565b815261536760208301614e2e565b602082015261537860408301614e2e565b604082015261538960608301614e2e565b606082015261539a60808301614e2e565b60808201526153ab60a08301614e2e565b60a08201526153bc60c083016151c7565b60c082015260e082810135908201526153d861010083016151c7565b6101008201526153eb6101208301614f4f565b6101208201526153fe6101408301614f4f565b6101408201526154116101608301614f4f565b6101608201526154246101808301615290565b6101808201526154376101a08301614f4f565b6101a082015261544a6101c08301614f4f565b6101c082015261545d6101e08301615290565b6101e08201526102008201356001600160401b0381111561547c575f80fd5b6154888682850161501b565b610200830152506102208201356001600160401b038111156154a8575f80fd5b6154b48682850161501b565b610220830152506154c861024083016151c7565b6102408201526154db61026083016151c7565b6102608201526154ee61028083016151c7565b6102808201526155016102a083016151c7565b6102a08201526102c08201356001600160401b03811115615520575f80fd5b61552c868285016152a3565b6102c0830152506155406102e08301614e2e565b6102e0820152949350505050565b62ffffff91909116815260200190565b5f6020828403121561556e575f80fd5b610a4882615290565b5f60208284031215615587575f80fd5b81356001600160401b0381111561559c575f80fd5b820160a081850312156155ad575f80fd5b6155b5614fc9565b81356155c08161524c565b81526020828101359082015260408201356155da81614e1a565b604082015260608201356001600160401b038111156155f7575f80fd5b6156038682850161501b565b606083015250608091820135918101919091529392505050565b5f805f8060808587031215615630575f80fd5b843593506020850135925060408501359150606085013561565081614e1a565b939692955090935050565b5f8083601f84011261566b575f80fd5b5081356001600160401b03811115615681575f80fd5b602083019150836020828501011115615698575f80fd5b9250929050565b5f805f80606085870312156156b2575f80fd5b843593506020850135925060408501356001600160401b038111156156d5575f80fd5b6156e18782880161565b565b95989497509550505050565b5f805f606084860312156156ff575f80fd5b833561570a81614e1a565b925060208401359150604084013561572181614e1a565b809150509250925092565b5f806040838503121561573d575f80fd5b823561574881614e1a565b9150602083013561528581614e1a565b600181811c9082168061576c57607f821691505b60208210810361578a57634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52603260045260245ffd5b600293840b81529190920b60208201526001600160801b03909116604082015260600190565b5f80604083850312156157db575f80fd5b505080516020909101519092909150565b634e487b7160e01b5f52601160045260245ffd5b8082018082111561090f5761090f6157ec565b805161ffff81168114614e39575f80fd5b5f805f805f805f60e0888a03121561583a575f80fd5b875161584581614e1a565b602089015190975061585681614f41565b955061586460408901615813565b945061587260608901615813565b935061588060808901615813565b925060a088015160ff81168114615895575f80fd5b60c08901519092506158a68161524c565b8091505092959891949750929550565b600295860b81529390940b6020840152604083019190915260608201526001600160a01b03909116608082015260a00190565b80516001600160801b0381168114614e39575f80fd5b5f6020828403121561590f575f80fd5b610a48826158e9565b8181038181111561090f5761090f6157ec565b60029190910b815260200190565b5f60208284031215615949575f80fd5b5051919050565b5f60018201615961576159616157ec565b5060010190565b62ffffff818116838216019081111561090f5761090f6157ec565b5f60208284031215615993575f80fd5b8151610a4881614e1a565b5f602082840312156159ae575f80fd5b8151610a4881614f41565b5f8160020b627fffff1981036159d1576159d16157ec565b5f0392915050565b634e487b7160e01b5f52601260045260245ffd5b5f8160020b8360020b80615a0357615a036159d9565b627fffff1982145f1982141615615a1c57615a1c6157ec565b90059392505050565b5f8260020b8260020b028060020b9150808214615a4457615a446157ec565b5092915050565b808202811582820484141761090f5761090f6157ec565b5f82615a7057615a706159d9565b500490565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039390931683526020830191909152604082015260600190565b6001600160a01b03959095168552600293840b60208601529190920b60408401526001600160801b03918216606084015216608082015260a00190565b5f8060408385031215615afd575f80fd5b615b06836158e9565b9150615b14602084016158e9565b90509250929050565b5f805f805f60a08688031215615b31575f80fd5b615b3a866158e9565b6020870151604088015191965094509250615b57606087016158e9565b9150615b65608087016158e9565b90509295509295909350565b5f805f60608486031215615b83575f80fd5b5050815160208301516040909301519094929350919050565b600292830b8152910b602082015260400190565b600281810b9083900b01627fffff8113627fffff198212171561090f5761090f6157ec565b600282810b9082900b03627fffff198112627fffff8213171561090f5761090f6157ec565b62ffffff828116828216039081111561090f5761090f6157ec565b5f8260020b80615c2757615c276159d9565b808360020b0791505092915050565b634e487b7160e01b5f52600160045260245ffd5b60c08082528751151590820152602087015160e082015260408701516001600160a01b0316610100820152606087015160a06101208301525f90615c92610160840182614dda565b60808a0151610140850152602084018990529150615cb590506040830187614e68565b615cc26060830186614e68565b608082019390935260a00152949350505050565b601f82111561177757805f5260205f20601f840160051c81016020851015615cfb5750805b601f840160051c820191505b818110156129f6575f8155600101615d07565b81516001600160401b03811115615d3357615d33614f8c565b615d4781615d418454615758565b84615cd6565b6020601f821160018114615d79575f8315615d625750848201515b5f19600385901b1c1916600184901b1784556129f6565b5f84815260208120601f198516915b82811015615da85787850151825560209485019460019092019101615d88565b5084821015615dc557868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b6001600160801b038181168382160290811690818114615a4457615a446157ec565b5f6001600160801b03831680615e0e57615e0e6159d9565b6001600160801b03929092169190910492915050565b6001600160801b03818116838216019081111561090f5761090f6157ec565b6001600160801b03828116828216039081111561090f5761090f6157ec565b5f82518060208501845e5f92019182525091905056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220950999e7215737066da3e4b811189b2ab763d8bb75331774286328c281aa8f8864736f6c634300081a0033
Deployed Bytecode
0x608060405260043610610243575f3560e01c806306fdde0314610247578063095ea7b3146102715780630dfe1681146102a057806316f0115b146102c157806318160ddd146102d55780631d769828146102f757806323b872dd146103185780632953323a14610337578063313ce5671461034b578063365d0ed7146103665780633cbff3fe146103945780633f3e4c11146103b357806341aec538146103d257806348ff15b3146103e65780634f1ef286146103fa57806352d1902d1461040d5780635d9b6fd414610421578063629d94051461044057806370a08231146104545780637784c685146104735780637d7c2a1c1461049f5780637feedaa1146104b357806380275860146104d257806388c74e08146104f35780639573ea251461051257806395d89b4114610531578063a632935514610545578063a7e6b92c14610564578063a9059cbb14610583578063ad3cb1cc146105a2578063af794480146105d2578063b0e21e8a146105f1578063b8ec2d3814610612578063bbd31f9f14610631578063c24e55b514610650578063c433c80a1461066f578063c4a7761e1461068e578063c4b4c30f146106b7578063c688d9a5146106d6578063d0a7a964146106f5578063d0ebdbe714610714578063d21220a714610733578063d331bef714610747578063d348799714610766578063dc2c256f14610785578063dd62ed3e146107a4578063f4005cae146107c3578063f5da7fd6146107e2578063f8d01c9d14610801578063fa461e3314610820578063fae1fb5f1461083f575b5f80fd5b348015610252575f80fd5b5061025b61085e565b6040516102689190614e08565b60405180910390f35b34801561027c575f80fd5b5061029061028b366004614e3e565b6108fc565b6040519015158152602001610268565b3480156102ab575f80fd5b506102b4610915565b6040516102689190614e75565b3480156102cc575f80fd5b506102b4610930565b3480156102e0575f80fd5b506102e961094b565b604051908152602001610268565b348015610302575f80fd5b50610316610311366004614e89565b610959565b005b348015610323575f80fd5b50610290610332366004614ea4565b610a2a565b348015610342575f80fd5b50610316610a4f565b348015610356575f80fd5b5060405160128152602001610268565b348015610371575f80fd5b50610385610380366004614ee2565b610aea565b60405161026893929190614f2b565b34801561039f575f80fd5b506103166103ae366004614f5a565b6110f8565b3480156103be575f80fd5b506103166103cd366004614f75565b611189565b3480156103dd575f80fd5b506102e96111d4565b3480156103f1575f80fd5b50610316611278565b61031661040836600461508c565b61130d565b348015610418575f80fd5b506102e961132c565b34801561042c575f80fd5b5061031661043b366004614e89565b611347565b34801561044b575f80fd5b506102e96113a8565b34801561045f575f80fd5b506102e961046e366004614e89565b6113f8565b34801561047e575f80fd5b5061049261048d3660046150fa565b611402565b6040516102689190615185565b3480156104aa575f80fd5b50610316611493565b3480156104be575f80fd5b506103166104cd3660046151d9565b61152f565b3480156104dd575f80fd5b506104e66115e8565b60405161026891906151f2565b3480156104fe575f80fd5b5061031661050d3660046151d9565b611682565b34801561051d575f80fd5b5061031661052c366004615259565b61170c565b34801561053c575f80fd5b5061025b61177c565b348015610550575f80fd5b5061031661055f366004614f5a565b611798565b34801561056f575f80fd5b5061031661057e366004615311565b611847565b34801561058e575f80fd5b5061029061059d366004614e3e565b612068565b3480156105ad575f80fd5b5061025b604051806040016040528060058152602001640352e302e360dc1b81525081565b3480156105dd575f80fd5b506103166105ec366004614f5a565b612075565b3480156105fc575f80fd5b506106056120f1565b604051610268919061554e565b34801561061d575f80fd5b5061031661062c36600461555e565b61210f565b34801561063c575f80fd5b5061031661064b366004615577565b61216d565b34801561065b575f80fd5b5061031661066a3660046151d9565b6121d5565b34801561067a575f80fd5b5061031661068936600461555e565b61225e565b348015610699575f80fd5b506106a26122e1565b60408051928352602083019190915201610268565b3480156106c2575f80fd5b506103166106d1366004614f5a565b61235e565b3480156106e1575f80fd5b506103166106f0366004614e89565b61240d565b348015610700575f80fd5b5061031661070f3660046151d9565b612494565b34801561071f575f80fd5b5061031661072e366004614e89565b612641565b34801561073e575f80fd5b506102b46126a2565b348015610752575f80fd5b506106a261076136600461561d565b6126bd565b348015610771575f80fd5b5061031661078036600461569f565b61297f565b348015610790575f80fd5b5061031661079f3660046156ed565b6129fd565b3480156107af575f80fd5b506102e96107be36600461572c565b612a76565b3480156107ce575f80fd5b506103166107dd366004614f5a565b612ab0565b3480156107ed575f80fd5b506103166107fc3660046151d9565b612b35565b34801561080c575f80fd5b5061031661081b366004614e89565b612bbf565b34801561082b575f80fd5b5061031661083a36600461569f565b612c20565b34801561084a575f80fd5b506103166108593660046151d9565b612c9b565b60605f610869612d21565b905080600301805461087a90615758565b80601f01602080910402602001604051908101604052809291908181526020018280546108a690615758565b80156108f15780601f106108c8576101008083540402835291602001916108f1565b820191905f5260205f20905b8154815290600101906020018083116108d457829003601f168201915b505050505091505090565b5f33610909818585612d45565b60019150505b92915050565b5f61091e612d52565b600301546001600160a01b0316919050565b5f610939612d52565b600101546001600160a01b0316919050565b5f610954612d76565b905090565b5f610962612d52565b80549091506001600160a01b0316331461098f57604051633bd5209f60e01b815260040160405180910390fd5b600a810180545f9091556001600160801b0380821691600160801b90041681156109cc5760038301546109cc906001600160a01b03168584612d8a565b80156109eb5760048301546109eb906001600160a01b03168583612d8a565b60408051838152602081018390527fd63986ca13f11502796aee70ba80ac7317d99f08e5871fd9fd602a2764c7ef30910160405180910390a150505050565b5f33610a37858285612de2565b610a42858585612e2c565b60019150505b9392505050565b610a57612e89565b5f610a60612d52565b600c810154909150610a8f90600160201b8104600290810b91600160381b9004900b6001600160801b03612ec2565b600c810154610abb90600160501b8104600290810b91600160681b9004900b6001600160801b03612ec2565b600c810154610ae790600160801b8104600290810b91600160981b9004900b6001600160801b03612ec2565b50565b5f805f610af5612fc3565b5f610afe612d52565b60088101549091506001600160a01b031615610b415760088101546001600160a01b03163314610b4157604051630a2002cb60e01b815260040160405180910390fd5b88158015610b4d575087155b15610b6b5760405163f7e8bf5d60e01b815260040160405180910390fd5b6001600160a01b0385161580610b8957506001600160a01b03851630145b15610ba757604051637c878f9360e01b815260040160405180910390fd5b80600f015f9054906101000a90046001600160a01b03166001600160a01b031663345d90e26040518163ffffffff1660e01b81526004015f6040518083038186803b158015610bf4575f80fd5b505afa158015610c06573d5f803e3d5ffd5b505050505f610c136115e8565b9050610c1d614d71565b5f5b6003811015610d6a57610c66838260038110610c3d57610c3d615790565b602002015151848360038110610c5557610c55615790565b602002015160016020020151612ff8565b508592508491505060038110610c7e57610c7e615790565b6001600160801b0390921660209290920201525f828260038110610ca457610ca4615790565b60200201516001600160801b03161115610d625760018401546001600160a01b031663a34123a7848360038110610cdd57610cdd615790565b602002015151858460038110610cf557610cf5615790565b6020020151600160200201515f6040518463ffffffff1660e01b8152600401610d20939291906157a4565b60408051808303815f875af1158015610d3b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d5f91906157ca565b50505b600101610c1f565b505f610d7461094b565b9050610d8284828e8e6130d2565b919850965094505f879003610daa57604051631f65ad9d60e01b815260040160405180910390fd5b89861015610dcb57604051631121139960e11b815260040160405180910390fd5b88851015610dec57604051634824c64160e11b815260040160405180910390fd5b805f03610e0157610e0161dead6103e86131eb565b8515610e21576003840154610e21906001600160a01b031633308961321f565b8415610e41576004840154610e41906001600160a01b031633308861321f565b8015610e4d5780610e59565b610e596103e882615800565b90505f846001015f9054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa158015610eae573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ed29190615824565b509495508b94508a93505f925050505b6003811015611058575f878260038110610efe57610efe615790565b60200201515190505f888360038110610f1957610f19615790565b60200201516001602002015190505f888460038110610f3a57610f3a615790565b60200201516001600160801b0316111561104e575f610f79898560038110610f6457610f64615790565b60200201516001600160801b03168f8a613258565b90505f736c4e0f30ee76a1c360387a0504f32c991d46f817636bea771a85858a8a8d6040518663ffffffff1660e01b8152600401610fbb9594939291906158b6565b602060405180830381865af4158015610fd6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ffa91906158ff565b9050806001600160801b0316826001600160801b03161161101b578161101d565b805b91505f8061102c868686613301565b909250905061103b828a615918565b98506110478189615918565b9750505050505b5050600101610ee2565b506110638b8b6131eb565b8a6001600160a01b0316336001600160a01b03167f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f68c8c8c6040516110aa93929190614f2b565b60405180910390a386600901546110bf61094b565b11156110de5760405163dbc1bae360e01b815260040160405180910390fd5b505050505050506110ed6133c6565b955095509592505050565b611100612e89565b5f611109612d52565b90505f8260020b121561112f5760405163445f5a6f60e11b815260040160405180910390fd5b600b8101805462ffffff60e01b1916600160e01b62ffffff8516021790556040517f957dddabc1ac2b52bf67ebbe53150c1b46f57ec0e1dc487632d5bcc3a36a2d829061117d90849061592b565b60405180910390a15050565b611191612e89565b5f61119a612d52565b600981018390556040518381529091507f49e8da6bc2b1ffc75cb81c88d1a8e64d5b1224c626dc9be8787d6ff982b46a399060200161117d565b5f806111de612d52565b600a8101546004808301546040516370a0823160e01b8152939450600160801b9092046001600160801b0316926001600160a01b03909216916370a082319161122991309101614e75565b602060405180830381865afa158015611244573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112689190615939565b6112729190615918565b91505090565b5f611281612d52565b60068101549091506001600160a01b031633146112b1576040516323920ffd60e11b815260040160405180910390fd5b600581018054336001600160a01b0319918216811790925560068301805490911690556040517f5c18ab5c697b63d102fc7e14c77bfaef0f1013206eca139920fd389277814e099161130291614e75565b60405180910390a150565b6113156133d6565b61131e8261347a565b6113288282613482565b5050565b5f611335613535565b505f80516020615e7983398151915290565b61134f612e89565b5f611358612d52565b6008810180546001600160a01b0319166001600160a01b0385161790556040519091507f3b3e178c01607aa6eab8fd24b33e3de1d5f41d603b21010e65903bdce27dec139061117d908490614e75565b5f806113b2612d52565b600a81015460038201546040516370a0823160e01b81529293506001600160801b03909116916001600160a01b03909116906370a0823190611229903090600401614e75565b5f61090f8261357e565b8051606090806001600160401b0381111561141f5761141f614f8c565b604051908082528060200260200182016040528015611448578160200160208202803683370190505b5091505f5b8181101561148c575f848261146181615950565b93508151811061147357611473615790565b602002602001015190508054602083028501525061144d565b5050919050565b61149b612fc3565b6114a36135a7565b6114ab612d52565b600f015f9054906101000a90046001600160a01b03166001600160a01b03166371bd0ea76040518163ffffffff1660e01b81526004015f6040518083038186803b1580156114f7575f80fd5b505afa158015611509573d5f803e3d5ffd5b505050506115156135fb565b611525611520613605565b613673565b61152d6133c6565b565b5f611538612d52565b80549091506001600160a01b0316331461156557604051633bd5209f60e01b815260040160405180910390fd5b6203d0908262ffffff16111561158e57604051630f28c84160e11b815260040160405180910390fd5b611599826001615968565b81600b0160076101000a81548162ffffff021916908362ffffff1602179055507f24a0d123bf9f15cb6bd5c3bc9b5cfe044075db4114c7a2f2a83a2409de73ac928260405161117d919061554e565b6115f0614d8f565b5f6115f9612d52565b6040805160a081018252600c90920154600160201b8104600290810b60608501908152600160381b8304820b6080860152845282518084018452600160501b8304820b8152600160681b8304820b6020828101919091528086019190915283518085018552600160801b8404830b8152600160981b90930490910b908201529082015292915050565b61168a612e89565b5f611693612d52565b9050620f424062ffffff831611156116be57604051637eb4a3ab60e11b815260040160405180910390fd5b600d8101805465ffffff0000001916630100000062ffffff8516021790556040517f9ed124f3fe3c19722c9573c877ab9038c8257f068248c730533542993bab11e09061117d90849061554e565b5f611715612d52565b80549091506001600160a01b0316331461174257604051633bd5209f60e01b815260040160405180910390fd5b6001600160a01b0383166117695760405163746db8e560e01b815260040160405180910390fd5b611777600e82018484613f0e565b505050565b60605f611787612d21565b905080600401805461087a90615758565b6117a0612e89565b5f6117a9612d52565b600b810154909150600160981b9004600290810b9083900b036117df576040516306dde9e760e21b815260040160405180910390fd5b600b8101546117f9908390600160c81b900460020b613f6b565b600b8101805462ffffff60681b1916600160681b62ffffff8516021790556040517ff1759909677b9c42577caba6b12efd5bcf3a398d02a2c1c97d23bbd312b561a79061117d90849061592b565b5f611850613fb9565b805490915060ff600160401b82041615906001600160401b03165f811580156118765750825b90505f826001600160401b031660011480156118915750303b155b90508115801561189f575080155b156118bd5760405163f92ee8a960e01b815260040160405180910390fd5b84546001600160401b031916600117855583156118e657845460ff60401b1916600160401b1785555b6118fa866102000151876102200151613fdd565b611902613fef565b5f61190b612d52565b875181546001600160a01b03199081166001600160a01b039283161783556020808b0151600185018054841691851691821790556040808d01516002870180549095169516949094179092558251630dfe168160e01b815292519394509092630dfe16819260048082019392918290030181865afa15801561198f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119b39190615983565b6003820180546001600160a01b0319166001600160a01b0392831617905560018201546040805163d21220a760e01b81529051919092169163d21220a79160048083019260209291908290030181865afa158015611a13573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a379190615983565b600482810180546001600160a01b0319166001600160a01b039384161790556001830154604080516334324e9f60e21b815290515f94929092169263d0c93a7c9282820192602092908290030181865afa158015611a97573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611abb919061599e565b600b8301805462ffffff60c81b1916600160c81b62ffffff84160217905590508080611aea620d89e7196159b9565b611af491906159ed565b611afe9190615a25565b82600d015f6101000a81548162ffffff021916908360020b62ffffff1602179055508760600151826005015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055508760800151826007015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055508760a00151826008015f6101000a8154816001600160a01b0302191690836001600160a01b031602179055508760e00151826009018190555087610140015182600b01600d6101000a81548162ffffff021916908360020b62ffffff16021790555087610160015182600b0160106101000a81548162ffffff021916908360020b62ffffff16021790555087610100015182600b01600a6101000a81548162ffffff021916908362ffffff16021790555087610120015182600b0160136101000a81548162ffffff021916908360020b62ffffff16021790555087610180015182600b015f6101000a81548163ffffffff021916908363ffffffff160217905550876101a0015182600b0160166101000a81548162ffffff021916908360020b62ffffff160217905550876101c0015182600b01601c6101000a81548162ffffff021916908360020b62ffffff160217905550876101e0015182600c015f6101000a81548163ffffffff021916908363ffffffff1602179055508760c0015182600b0160046101000a81548162ffffff021916908362ffffff16021790555087610240015182600d0160036101000a81548162ffffff021916908362ffffff16021790555087610260015182600d0160066101000a81548162ffffff021916908362ffffff16021790555087610280015182600d0160096101000a81548162ffffff021916908362ffffff1602179055504282600d01600c6101000a81548164ffffffffff021916908364ffffffffff160217905550876102a0015182600d0160116101000a81548162ffffff021916908362ffffff160217905550876102e0015182600f015f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550611e1088610140015182613f6b565b611e1f88610160015182613f6b565b611e2e88610120015182613f6b565b620f424062ffffff1688610100015162ffffff161115611e6157604051630b5073c960e01b815260040160405180910390fd5b5f886101a0015160020b1215611e8a57604051636927528b60e01b815260040160405180910390fd5b5f886101c0015160020b1215611eb35760405163445f5a6f60e11b815260040160405180910390fd5b876101e0015163ffffffff165f03611ede5760405163bfd58a7960e01b815260040160405180910390fd5b87610140015160020b88610120015160020b03611f0e576040516306dde9e760e21b815260040160405180910390fd5b620f424062ffffff1688610240015162ffffff161115611f4157604051637eb4a3ab60e11b815260040160405180910390fd5b620f424062ffffff1688610260015162ffffff161115611f745760405163164881f360e01b815260040160405180910390fd5b87610280015162ffffff165f03611f9e57604051633d73a3e160e11b815260040160405180910390fd5b876102a0015162ffffff165f03611fc85760405163712ee3d360e01b815260040160405180910390fd5b5f5b886102c00151518110156120175761200f896102c001518281518110611ff257611ff2615790565b6020026020010151600185600e01613f0e9092919063ffffffff16565b600101611fca565b505050831561206057845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050565b5f33610909818585612e2c565b61207d612e89565b5f612086612d52565b600b8101549091506120a3908390600160c81b900460020b613f6b565b600b8101805462ffffff60801b1916600160801b62ffffff8516021790556040517fc797ac22933a04255304effee6a7d3c3e4bbfaa0b2897c52c61a8b1fb027b9f29061117d90849061592b565b5f6120fa612d52565b600b0154600160201b900462ffffff16919050565b612117612e89565b5f612120612d52565b600b8101805463ffffffff191663ffffffff85169081179091556040519081529091507fa55d4ed589bc280e365d3ff1dc7fe4f59dff2d75e22716e29d6a9158fe0598469060200161117d565b612175612fc3565b61217d6135a7565b60408101516001600160a01b03166121a85760405163746db8e560e01b815260040160405180910390fd5b6121b06135fb565b6121b981613673565b6121c25f613fff565b6121cd611520613605565b610ae76133c6565b6121dd612e89565b5f6121e6612d52565b9050620f424062ffffff8316111561221157604051630b5073c960e01b815260040160405180910390fd5b600b8101805462ffffff60501b1916600160501b62ffffff8516021790556040517e47af854b92d7c4ca4913ffd329caf1c2e2b5e262b29139ae6cb247f18b886c9061117d90849061554e565b612266612e89565b5f61226f612d52565b90508163ffffffff165f036122975760405163bfd58a7960e01b815260040160405180910390fd5b600c8101805463ffffffff191663ffffffff84169081179091556040519081527f2402faf0100aca3dc010189fd1fb0e310ab05da61ce9a65457e0fe7018e920d99060200161117d565b5f806122eb612d52565b600f01546040516347c570fd60e01b81525f60048201526001600160a01b03909116906347c570fd906024016040805180830381865afa158015612331573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061235591906157ca565b90939092509050565b612366612e89565b5f61236f612d52565b600b810154909150600160681b9004600290810b9083900b036123a5576040516306dde9e760e21b815260040160405180910390fd5b600b8101546123bf908390600160c81b900460020b613f6b565b600b8101805462ffffff60981b1916600160981b62ffffff8516021790556040517f6be14bdbb0283c52b91dff0090b8bda078b11ce7f87486a7c14ae7595fd0f9389061117d90849061592b565b612415612e89565b5f61241e612d52565b90506001600160a01b0382166124475760405163746db8e560e01b815260040160405180910390fd5b600f810180546001600160a01b0319166001600160a01b0384161790556040517fa5e5f21996a9e755b40ab15ce550a8e3a8fc1f785f595161a00f887078ff01dc9061117d908490614e75565b61249c6135a7565b5f6124a5612d52565b9050620f424062ffffff831611156124d05760405163164881f360e01b815260040160405180910390fd5b600d81015462ffffff600160301b909104811690831611156125d157600d8101545f906125259061250f90600160601b900464ffffffffff1642615918565b600d840154600160481b900462ffffff166140c9565b600d8301549091505f9062ffffff600160481b820481169161255091600160881b9091041684615a4b565b61255a9190615a62565b600d840154909150612579908290600160301b900462ffffff16615800565b8462ffffff1611156125ce57600d83015484906125a3908390600160301b900462ffffff16615800565b6040516313c042e760e21b815262ffffff909216600483015260248201526044015b60405180910390fd5b50505b600d810180546affffffffff000000ffffff60301b1916600160301b62ffffff85160264ffffffffff60601b191617600160601b4264ffffffffff16021790556040517fa576875e509dca098a87c161a87c921b7e48b19999837e3c3c5529348cef73739061117d90849061554e565b612649612e89565b5f612652612d52565b6006810180546001600160a01b0319166001600160a01b0385161790556040519091507f4d3334a0a69f5f1c54636cf743914f0b34fb2e7849b55ee7c1faddd0e06b4dfd9061117d908490614e75565b5f6126ab612d52565b600401546001600160a01b0316919050565b5f806126c7612fc3565b5f6126d0612d52565b9050865f036126f257604051631f65ad9d60e01b815260040160405180910390fd5b6001600160a01b038416158061271057506001600160a01b03841630145b1561272e57604051637c878f9360e01b815260040160405180910390fd5b5f61273761094b565b905061274333896140de565b808861274d6113a8565b6127579190615a4b565b6127619190615a62565b9350808861276d6111d4565b6127779190615a4b565b6127819190615a62565b92506127b66040518060c001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b600c8301546127dc90600160201b8104600290810b91600160381b9004900b8b85614112565b60208301528152600c83015461280990600160501b8104600290810b91600160681b9004900b8b85614112565b60608301526040820152600c83015461283990600160801b8104600290810b91600160981b9004900b8b85614112565b60a083015260808201819052604082015182516128569088615800565b6128609190615800565b61286a9190615800565b94508060a0015181606001518260200151866128869190615800565b6128909190615800565b61289a9190615800565b9350878510156128bd57604051631121139960e11b815260040160405180910390fd5b868410156128de57604051634824c64160e11b815260040160405180910390fd5b84156128fd5760038301546128fd906001600160a01b03168787612d8a565b831561291c57600483015461291c906001600160a01b03168786612d8a565b856001600160a01b0316336001600160a01b03167febff2602b3f468259e1e99f613fed6691f3a6526effe6ef3e768ba7ae7a36c4f8b888860405161296393929190614f2b565b60405180910390a35050506129766133c6565b94509492505050565b5f612988612d52565b60018101549091506001600160a01b031633146129b857604051630e18314d60e01b815260040160405180910390fd5b84156129d75760038101546129d7906001600160a01b03163387612d8a565b83156129f65760048101546129f6906001600160a01b03163386612d8a565b5050505050565b612a05612e89565b5f612a0e612d52565b60038101549091506001600160a01b0385811691161480612a3e575060048101546001600160a01b038581169116145b15612a5c576040516308bde84760e41b815260040160405180910390fd5b612a706001600160a01b0385168385612d8a565b50505050565b5f80612a80612d21565b6001600160a01b039485165f90815260019190910160209081526040808320959096168252939093525050205490565b612ab8612e89565b5f612ac1612d52565b90505f8260020b1215612ae757604051636927528b60e01b815260040160405180910390fd5b600b8101805462ffffff60b01b1916600160b01b62ffffff8516021790556040517f52a3cbe96b59de1055b9b043e8906557387b821f26af47beea677164a7f26b629061117d90849061592b565b612b3d612e89565b5f612b46612d52565b9050620f424062ffffff83161115612b715760405163712ee3d360e01b815260040160405180910390fd5b600d8101805462ffffff60881b1916600160881b62ffffff8516021790556040517f844c878cbc82b5c2b2a506e29cbabbd2829292d0f875d96b5063898879326e859061117d90849061554e565b612bc7612e89565b5f612bd0612d52565b6007810180546001600160a01b0319166001600160a01b0385161790556040519091507f02d71f3b54d658df30617ce7b33fa5f9835dd21a1da2a6dce6368dc9e5a40a979061117d908490614e75565b5f612c29612d52565b60018101549091506001600160a01b03163314612c5957604051630e18314d60e01b815260040160405180910390fd5b5f851315612c7a576003810154612c7a906001600160a01b03163387612d8a565b5f8413156129f65760048101546129f6906001600160a01b03163386612d8a565b612ca3612e89565b5f612cac612d52565b90508162ffffff165f03612cd357604051633d73a3e160e11b815260040160405180910390fd5b600d8101805462ffffff60481b1916600160481b62ffffff8516021790556040517f2f11ce9f67c3ee30ded0d2833bc7428a527dc8d3e61c39a4b11865956a66cd359061117d90849061554e565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0090565b61177783838360016141c8565b7fb4801203179a1f53d2a89513756c4fddeb24d0f949ce9fc7cf03114c341dc50090565b5f80612d80612d21565b6002015492915050565b61177783846001600160a01b031663a9059cbb8585604051602401612db0929190615a75565b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506142a8565b5f612ded8484612a76565b90505f198114612a705781811015612e1e57828183604051637dc7a0d960e11b81526004016125c593929190615a8e565b612a7084848484035f6141c8565b6001600160a01b038316612e55575f604051634b637e8f60e11b81526004016125c59190614e75565b6001600160a01b038216612e7e575f60405163ec442f0560e01b81526004016125c59190614e75565b61177783838361430b565b5f612e92612d52565b60058101549091506001600160a01b03163314610ae75760405163307b0c8760e11b815260040160405180910390fd5b5f612ecb612d52565b600181015460405163a34123a760e01b81529192506001600160a01b03169063a34123a790612f02908790879087906004016157a4565b60408051808303815f875af1158015612f1d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f4191906157ca565b505060018101546040516309e3d67b60e31b81526001600160a01b0390911690634f1eb3d890612f84903090889088906001600160801b03908190600401615aaf565b60408051808303815f875af1158015612f9f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120609190615aec565b5f612fcc61442e565b805490915060011901612ff257604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b5f805f805f80613006612d52565b604080513060601b6001600160601b03191660208083019190915260e88c811b60348401528b901b60378301528251601a818403018152603a90920190925280519101209091505f90600183015460405163514ea4bf60e01b8152600481018390529192506001600160a01b03169063514ea4bf9060240160a060405180830381865afa158015613099573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906130bd9190615b1d565b939d929c50909a509850909650945050505050565b600f8401546040516347c570fd60e01b8152600160048201525f9182918291829182916001600160a01b0316906347c570fd906024016040805180830381865afa158015613122573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061314691906157ca565b60405163030e25c760e31b8152600481018b90526024810183905260448101829052606481018a9052608481018990529193509150736c4e0f30ee76a1c360387a0504f32c991d46f817906318712e389060a401606060405180830381865af41580156131b5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131d99190615b71565b919b909a509098509650505050505050565b6001600160a01b038216613214575f60405163ec442f0560e01b81526004016125c59190614e75565b6113285f838361430b565b6040516001600160a01b038481166024830152838116604483015260648201839052612a709186918216906323b872dd90608401612db0565b5f80805f19858709858702925082811083820303915050805f0361328f57838281613285576132856159d9565b0492505050610a48565b80841161329a575f80fd5b5f8486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091025f889003889004909101858311909403939093029303949094049190911702949350505050565b5f805f61330c612d52565b90506001600160801b038416156133bd576001810154604051633c8a7d8d60e01b8152306004820152600288810b602483015287900b60448201526001600160801b038616606482015260a060848201525f60a48201526001600160a01b0390911690633c8a7d8d9060c40160408051808303815f875af1158015613393573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906133b791906157ca565b90935091505b50935093915050565b5f6133cf61442e565b6001905550565b306001600160a01b037f000000000000000000000000d90b611789cb1c9b853644dbbb37bfabe4a5fc6716148061345c57507f000000000000000000000000d90b611789cb1c9b853644dbbb37bfabe4a5fc676001600160a01b03166134505f80516020615e79833981519152546001600160a01b031690565b6001600160a01b031614155b1561152d5760405163703e46dd60e11b815260040160405180910390fd5b610ae7612e89565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156134dc575060408051601f3d908101601f191682019092526134d991810190615939565b60015b6134fb5781604051634c9c8ce360e01b81526004016125c59190614e75565b5f80516020615e79833981519152811461352b57604051632a87526960e21b8152600481018290526024016125c5565b6117778383614452565b306001600160a01b037f000000000000000000000000d90b611789cb1c9b853644dbbb37bfabe4a5fc67161461152d5760405163703e46dd60e11b815260040160405180910390fd5b5f80613588612d21565b6001600160a01b039093165f9081526020939093525050604090205490565b5f6135b0612d52565b60058101549091506001600160a01b031633148015906135dd575060078101546001600160a01b03163314155b15610ae7576040516319bb854760e21b815260040160405180910390fd5b61152d6001613fff565b6040805160a0810182525f8082526020820181905291810182905260608082015260808101919091526040518060a001604052805f151581526020015f81526020015f6001600160a01b0316815260200160405180602001604052805f81525081526020015f815250905090565b5f61367c612d52565b90505f80826001015f9054906101000a90046001600160a01b03166001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156136d2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906136f69190615824565b5050505050915091505f805f805f736c4e0f30ee76a1c360387a0504f32c991d46f81763756d1aca878a600b0160199054906101000a900460020b6040518363ffffffff1660e01b815260040161374e929190615b9c565b602060405180830381865af4158015613769573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061378d919061599e565b600b8901549091505f906137ab90600160c81b900460020b83615bb0565b600d8a0154600b8b0154919250600290810b91736c4e0f30ee76a1c360387a0504f32c991d46f81791633e68e68f916137ee91600160981b909104900b86615bd5565b836040518363ffffffff1660e01b815260040161380c929190615b9c565b602060405180830381865af4158015613827573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061384b919061599e565b600c8b01805462ffffff92909216600160201b0262ffffff60201b19909216919091179055600b8a0154736c4e0f30ee76a1c360387a0504f32c991d46f81790633e68e68f906138a590600160981b900460020b85615bb0565b836040518363ffffffff1660e01b81526004016138c3929190615b9c565b602060405180830381865af41580156138de573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613902919061599e565b600c8b01805462ffffff92909216600160381b0262ffffff60381b19909216919091179055600b8a015461394090600160681b900460020b84615bd5565b600c8b01805462ffffff92909216600160501b0262ffffff60501b19909216919091179055600b8a015461397e90600160681b900460020b83615bb0565b600c8b01805462ffffff92909216600160681b0262ffffff60681b19909216919091179055600b8a01546139bc90600160801b900460020b84615bd5565b965082955081945089600b0160109054906101000a900460020b826139e19190615bb0565b93505050505f6139ef6113a8565b90505f6139fa6111d4565b90507f210f60adf1db7a02e9db9a49ec7c2eb2060c516cbcfd01a0c05288144738ee5d878383613a2861094b565b6040805160029590950b8552602085019390935291830152606082015260800160405180910390a1600b890154600160501b900462ffffff1615613b93575f736c4e0f30ee76a1c360387a0504f32c991d46f817636bea771a8b600c0160049054906101000a900460020b8c600c0160079054906101000a900460020b86868e6040518663ffffffff1660e01b8152600401613ac89594939291906158b6565b602060405180830381865af4158015613ae3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613b0791906158ff565b600b8b0154909150613b4690620f424090613b3790600160501b900462ffffff166001600160801b038516615a4b565b613b419190615a62565b6144a7565b600c8b01549091505f908190613b7290600160201b8104600290810b91600160381b9004900b85613301565b9092509050613b818286615918565b9450613b8d8185615918565b93505050505b5f736c4e0f30ee76a1c360387a0504f32c991d46f817636bea771a8b600c01600a9054906101000a900460020b8c600c01600d9054906101000a900460020b86868e6040518663ffffffff1660e01b8152600401613bf59594939291906158b6565b602060405180830381865af4158015613c10573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613c3491906158ff565b600c8b01549091505f908190613c6090600160501b8104600290810b91600160681b9004900b85613301565b9092509050613c6f8286615918565b9450613c7b8185615918565b93505050505f6001600160a01b03168a604001516001600160a01b031614613cad57613ca88a83836144c3565b613e66565b5f736c4e0f30ee76a1c360387a0504f32c991d46f817636bea771a888886868e6040518663ffffffff1660e01b8152600401613ced9594939291906158b6565b602060405180830381865af4158015613d08573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613d2c91906158ff565b90505f736c4e0f30ee76a1c360387a0504f32c991d46f817636bea771a878787878f6040518663ffffffff1660e01b8152600401613d6e9594939291906158b6565b602060405180830381865af4158015613d89573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613dad91906158ff565b9050806001600160801b0316826001600160801b03161115613e1857613dd4888884613301565b5050600c8b01805462ffffff898116600160981b0262ffffff60981b19918c16600160801b029190911665ffffffffffff60801b1990921691909117179055613e63565b613e23868683613301565b5050600c8b01805462ffffff878116600160981b0262ffffff60981b19918a16600160801b029190911665ffffffffffff60801b19909216919091171790555b50505b600c89018054600160b01b600160f01b031916600160c81b4264ffffffffff160262ffffff60b01b191617600160b01b62ffffff8a81169190910291909117909155600b8a0154600160381b8104821691600160201b909104168115613f00575f613ed2600184615bfa565b600b8d01805465ffffffffffff60201b1916600160201b62ffffff84160262ffffff60381b19161790559150505b505050505050505050505050565b6001600160a01b0382165f8181526020858152604091829020805460ff191685151590811790915591519182527f7dc49220c17ba736a5a8f465c46784ed2262884e4ea605ae95e6fd117a77a421910160405180910390a2505050565b5f8260020b13613f8e57604051634416881b60e11b815260040160405180910390fd5b613f988183615c15565b60020b156113285760405163265fe24560e01b815260040160405180910390fd5b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0090565b613fe561471b565b6113288282614740565b613ff761471b565b61152d614770565b5f614008612d52565b600c810154909150600160201b8104600290810b91600160381b8104820b91600160501b8204810b91600160681b9004900b5f6140458585612ff8565b5050505090505f6140568484612ff8565b505050509050614067868684614778565b50505050614076848483614778565b5050505087156140bf57600c870154600160801b8104600290810b91600160981b9004900b5f6140a68383612ff8565b5050505090506140b7838383614778565b505050505050505b5050505050505050565b5f8183106140d75781610a48565b5090919050565b6001600160a01b038216614107575f604051634b637e8f60e11b81526004016125c59190614e75565b611328825f8361430b565b5f805f61411f8787612ff8565b5050505090505f61413a826001600160801b03168787613258565b90506001600160801b038116156141bd575f805f8061415a8c8c87614778565b9350935093509350888a836001600160801b03166141789190615a4b565b6141829190615a62565b61418c9085615800565b9750886141a28b6001600160801b038416615a4b565b6141ac9190615a62565b6141b69084615800565b9650505050505b505094509492505050565b5f6141d1612d21565b90506001600160a01b0385166141fc575f60405163e602df0560e01b81526004016125c59190614e75565b6001600160a01b038416614225575f604051634a1406b160e11b81526004016125c59190614e75565b6001600160a01b038086165f908152600183016020908152604080832093881683529290522083905581156129f657836001600160a01b0316856001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258560405161429991815260200190565b60405180910390a35050505050565b5f8060205f8451602086015f885af1806142c7576040513d5f823e3d81fd5b50505f513d915081156142de5780600114156142eb565b6001600160a01b0384163b155b15612a705783604051635274afe760e01b81526004016125c59190614e75565b5f614314612d21565b90506001600160a01b0384166143425781816002015f8282546143379190615800565b9091555061439f9050565b6001600160a01b0384165f90815260208290526040902054828110156143815784818460405163391434e360e21b81526004016125c593929190615a8e565b6001600160a01b0385165f9081526020839052604090209083900390555b6001600160a01b0383166143bd5760028101805483900390556143db565b6001600160a01b0383165f9081526020829052604090208054830190555b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161442091815260200190565b60405180910390a350505050565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0090565b61445b82614a1c565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a280511561449f576117778282614a76565b611328614a9b565b5f6001600160801b038211156144bf576144bf615c36565b5090565b5f6144cc612d52565b90505f845f01516144ea5760048201546001600160a01b03166144f9565b60038201546001600160a01b03165b90505f855f01516145175760038301546001600160a01b0316614526565b60048301546001600160a01b03165b6002840154604051635670bcc760e11b81529192506001600160a01b0316905f90829063ace1798e9061455d908790600401614e75565b602060405180830381865afa158015614578573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061459c9190615939565b90505f826001600160a01b031663ace1798e856040518263ffffffff1660e01b81526004016145cb9190614e75565b602060405180830381865afa1580156145e6573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061460a9190615939565b90505f895f015161461b578861461d565b875b90505f8a5f015161462e5788614630565b895b9050808b6020015111156146675760208b01516040516367f6e06560e01b81526125c5918391600401918252602082015260400190565b60408b015160208c0151614685916001600160a01b038a1691614aba565b60408b015160608c015161469d91600e8b0191614b4a565b60408b01516146b7906001600160a01b038916905f614aba565b600f88015460405163756041cf60e11b81526001600160a01b039091169063eac0839e906146f3908e9086908c908c908b908b90600401615c4a565b5f6040518083038186803b158015614709575f80fd5b505afa1580156140b7573d5f803e3d5ffd5b614723614bed565b61152d57604051631afcd79f60e31b815260040160405180910390fd5b61474861471b565b5f614751612d21565b9050600381016147618482615d1a565b5060048101612a708382615d1a565b6133c661471b565b5f805f805f614785612d52565b90506001600160801b0386161561481157600181015460405163a34123a760e01b81526001600160a01b039091169063a34123a7906147cc908b908b908b906004016157a4565b60408051808303815f875af11580156147e7573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061480b91906157ca565b90955093505b60018101546040516309e3d67b60e31b81525f9182916001600160a01b0390911690634f1eb3d8906148569030908e908e906001600160801b03908190600401615aaf565b60408051808303815f875af1158015614871573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906148959190615aec565b90925090506148ad876001600160801b038416615918565b94506148c2866001600160801b038316615918565b600b840154909450600160201b900462ffffff165f620f42406148e58389615dd4565b6148ef9190615df6565b90505f620f424061490562ffffff851689615dd4565b61490f9190615df6565b600a8701805491925083915f906149309084906001600160801b0316615e24565b92506101000a8154816001600160801b0302191690836001600160801b031602179055508086600a0160108282829054906101000a90046001600160801b031661497a9190615e24565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555081886149aa9190615e43565b97506149b68188615e43565b604080516001600160801b038b811682528381166020830152858116828401528416606082015290519198507f1ac56d7e866e3f5ea9aa92aa11758ead39a0a5f013f3fefb0f47cb9d008edd27919081900360800190a150505050505093509350935093565b806001600160a01b03163b5f03614a485780604051634c9c8ce360e01b81526004016125c59190614e75565b5f80516020615e7983398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6060610a488383604051806060016040528060278152602001615e9960279139614c06565b341561152d5760405163b398979f60e01b815260040160405180910390fd5b5f836001600160a01b031663095ea7b38484604051602401614add929190615a75565b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050509050614b168482614c7a565b612a7057614b4084856001600160a01b031663095ea7b3865f604051602401612db0929190615a75565b612a7084826142a8565b6001600160a01b0382165f9081526020849052604090205460ff16614b8257604051635d7763a160e11b815260040160405180910390fd5b5f80836001600160a01b031683604051614b9c9190615e62565b5f604051808303815f865af19150503d805f8114614bd5576040519150601f19603f3d011682016040523d82523d5f602084013e614bda565b606091505b5091509150816129f6576129f681614cbf565b5f614bf6613fb9565b54600160401b900460ff16919050565b60605f80856001600160a01b031685604051614c229190615e62565b5f60405180830381855af49150503d805f8114614c5a576040519150601f19603f3d011682016040523d82523d5f602084013e614c5f565b606091505b5091509150614c7086838387614cc7565b9695505050505050565b5f805f8060205f8651602088015f8a5af192503d91505f519050828015614c7057508115614cab5780600114614c70565b50505050506001600160a01b03163b151590565b805160208201fd5b60608315614d355782515f03614d2e576001600160a01b0385163b614d2e5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016125c5565b5081614d3f565b614d3f8383614d47565b949350505050565b815115614d575781518083602001fd5b8060405162461bcd60e51b81526004016125c59190614e08565b60405180606001604052806003906020820280368337509192915050565b60405180606001604052806003905b614da6614dbc565b815260200190600190039081614d9e5790505090565b60405180604001604052806002906020820280368337509192915050565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b602081525f610a486020830184614dda565b6001600160a01b0381168114610ae7575f80fd5b8035614e3981614e1a565b919050565b5f8060408385031215614e4f575f80fd5b8235614e5a81614e1a565b946020939093013593505050565b6001600160a01b03169052565b6001600160a01b0391909116815260200190565b5f60208284031215614e99575f80fd5b8135610a4881614e1a565b5f805f60608486031215614eb6575f80fd5b8335614ec181614e1a565b92506020840135614ed181614e1a565b929592945050506040919091013590565b5f805f805f60a08688031215614ef6575f80fd5b853594506020860135935060408601359250606086013591506080860135614f1d81614e1a565b809150509295509295909350565b9283526020830191909152604082015260600190565b8060020b8114610ae7575f80fd5b8035614e3981614f41565b5f60208284031215614f6a575f80fd5b8135610a4881614f41565b5f60208284031215614f85575f80fd5b5035919050565b634e487b7160e01b5f52604160045260245ffd5b60405161030081016001600160401b0381118282101715614fc357614fc3614f8c565b60405290565b60405160a081016001600160401b0381118282101715614fc357614fc3614f8c565b604051601f8201601f191681016001600160401b038111828210171561501357615013614f8c565b604052919050565b5f82601f83011261502a575f80fd5b8135602083015f806001600160401b0384111561504957615049614f8c565b50601f8301601f191660200161505e81614feb565b915050828152858383011115615072575f80fd5b828260208301375f92810160200192909252509392505050565b5f806040838503121561509d575f80fd5b82356150a881614e1a565b915060208301356001600160401b038111156150c2575f80fd5b6150ce8582860161501b565b9150509250929050565b5f6001600160401b038211156150f0576150f0614f8c565b5060051b60200190565b5f6020828403121561510a575f80fd5b81356001600160401b0381111561511f575f80fd5b8201601f8101841361512f575f80fd5b803561514261513d826150d8565b614feb565b8082825260208201915060208360051b850101925086831115615163575f80fd5b6020840193505b82841015614c7057833582526020938401939091019061516a565b602080825282518282018190525f918401906040840190835b818110156151bc57835183526020938401939092019160010161519e565b509095945050505050565b803562ffffff81168114614e39575f80fd5b5f602082840312156151e9575f80fd5b610a48826151c7565b60c0810181835f5b6003811015615243578151835f5b600281101561522a57825160020b825260209283019290910190600101615208565b50505060409290920191602091909101906001016151fa565b50505092915050565b8015158114610ae7575f80fd5b5f806040838503121561526a575f80fd5b823561527581614e1a565b915060208301356152858161524c565b809150509250929050565b803563ffffffff81168114614e39575f80fd5b5f82601f8301126152b2575f80fd5b81356152c061513d826150d8565b8082825260208201915060208360051b8601019250858311156152e1575f80fd5b602085015b838110156153075780356152f981614e1a565b8352602092830192016152e6565b5095945050505050565b5f60208284031215615321575f80fd5b81356001600160401b03811115615336575f80fd5b82016103008185031215615348575f80fd5b615350614fa0565b61535982614e2e565b815261536760208301614e2e565b602082015261537860408301614e2e565b604082015261538960608301614e2e565b606082015261539a60808301614e2e565b60808201526153ab60a08301614e2e565b60a08201526153bc60c083016151c7565b60c082015260e082810135908201526153d861010083016151c7565b6101008201526153eb6101208301614f4f565b6101208201526153fe6101408301614f4f565b6101408201526154116101608301614f4f565b6101608201526154246101808301615290565b6101808201526154376101a08301614f4f565b6101a082015261544a6101c08301614f4f565b6101c082015261545d6101e08301615290565b6101e08201526102008201356001600160401b0381111561547c575f80fd5b6154888682850161501b565b610200830152506102208201356001600160401b038111156154a8575f80fd5b6154b48682850161501b565b610220830152506154c861024083016151c7565b6102408201526154db61026083016151c7565b6102608201526154ee61028083016151c7565b6102808201526155016102a083016151c7565b6102a08201526102c08201356001600160401b03811115615520575f80fd5b61552c868285016152a3565b6102c0830152506155406102e08301614e2e565b6102e0820152949350505050565b62ffffff91909116815260200190565b5f6020828403121561556e575f80fd5b610a4882615290565b5f60208284031215615587575f80fd5b81356001600160401b0381111561559c575f80fd5b820160a081850312156155ad575f80fd5b6155b5614fc9565b81356155c08161524c565b81526020828101359082015260408201356155da81614e1a565b604082015260608201356001600160401b038111156155f7575f80fd5b6156038682850161501b565b606083015250608091820135918101919091529392505050565b5f805f8060808587031215615630575f80fd5b843593506020850135925060408501359150606085013561565081614e1a565b939692955090935050565b5f8083601f84011261566b575f80fd5b5081356001600160401b03811115615681575f80fd5b602083019150836020828501011115615698575f80fd5b9250929050565b5f805f80606085870312156156b2575f80fd5b843593506020850135925060408501356001600160401b038111156156d5575f80fd5b6156e18782880161565b565b95989497509550505050565b5f805f606084860312156156ff575f80fd5b833561570a81614e1a565b925060208401359150604084013561572181614e1a565b809150509250925092565b5f806040838503121561573d575f80fd5b823561574881614e1a565b9150602083013561528581614e1a565b600181811c9082168061576c57607f821691505b60208210810361578a57634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52603260045260245ffd5b600293840b81529190920b60208201526001600160801b03909116604082015260600190565b5f80604083850312156157db575f80fd5b505080516020909101519092909150565b634e487b7160e01b5f52601160045260245ffd5b8082018082111561090f5761090f6157ec565b805161ffff81168114614e39575f80fd5b5f805f805f805f60e0888a03121561583a575f80fd5b875161584581614e1a565b602089015190975061585681614f41565b955061586460408901615813565b945061587260608901615813565b935061588060808901615813565b925060a088015160ff81168114615895575f80fd5b60c08901519092506158a68161524c565b8091505092959891949750929550565b600295860b81529390940b6020840152604083019190915260608201526001600160a01b03909116608082015260a00190565b80516001600160801b0381168114614e39575f80fd5b5f6020828403121561590f575f80fd5b610a48826158e9565b8181038181111561090f5761090f6157ec565b60029190910b815260200190565b5f60208284031215615949575f80fd5b5051919050565b5f60018201615961576159616157ec565b5060010190565b62ffffff818116838216019081111561090f5761090f6157ec565b5f60208284031215615993575f80fd5b8151610a4881614e1a565b5f602082840312156159ae575f80fd5b8151610a4881614f41565b5f8160020b627fffff1981036159d1576159d16157ec565b5f0392915050565b634e487b7160e01b5f52601260045260245ffd5b5f8160020b8360020b80615a0357615a036159d9565b627fffff1982145f1982141615615a1c57615a1c6157ec565b90059392505050565b5f8260020b8260020b028060020b9150808214615a4457615a446157ec565b5092915050565b808202811582820484141761090f5761090f6157ec565b5f82615a7057615a706159d9565b500490565b6001600160a01b03929092168252602082015260400190565b6001600160a01b039390931683526020830191909152604082015260600190565b6001600160a01b03959095168552600293840b60208601529190920b60408401526001600160801b03918216606084015216608082015260a00190565b5f8060408385031215615afd575f80fd5b615b06836158e9565b9150615b14602084016158e9565b90509250929050565b5f805f805f60a08688031215615b31575f80fd5b615b3a866158e9565b6020870151604088015191965094509250615b57606087016158e9565b9150615b65608087016158e9565b90509295509295909350565b5f805f60608486031215615b83575f80fd5b5050815160208301516040909301519094929350919050565b600292830b8152910b602082015260400190565b600281810b9083900b01627fffff8113627fffff198212171561090f5761090f6157ec565b600282810b9082900b03627fffff198112627fffff8213171561090f5761090f6157ec565b62ffffff828116828216039081111561090f5761090f6157ec565b5f8260020b80615c2757615c276159d9565b808360020b0791505092915050565b634e487b7160e01b5f52600160045260245ffd5b60c08082528751151590820152602087015160e082015260408701516001600160a01b0316610100820152606087015160a06101208301525f90615c92610160840182614dda565b60808a0151610140850152602084018990529150615cb590506040830187614e68565b615cc26060830186614e68565b608082019390935260a00152949350505050565b601f82111561177757805f5260205f20601f840160051c81016020851015615cfb5750805b601f840160051c820191505b818110156129f6575f8155600101615d07565b81516001600160401b03811115615d3357615d33614f8c565b615d4781615d418454615758565b84615cd6565b6020601f821160018114615d79575f8315615d625750848201515b5f19600385901b1c1916600184901b1784556129f6565b5f84815260208120601f198516915b82811015615da85787850151825560209485019460019092019101615d88565b5084821015615dc557868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b6001600160801b038181168382160290811690818114615a4457615a446157ec565b5f6001600160801b03831680615e0e57615e0e6159d9565b6001600160801b03929092169190910492915050565b6001600160801b03818116838216019081111561090f5761090f6157ec565b6001600160801b03828116828216039081111561090f5761090f6157ec565b5f82518060208501845e5f92019182525091905056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220950999e7215737066da3e4b811189b2ab763d8bb75331774286328c281aa8f8864736f6c634300081a0033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.