Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xcbA35E68...1A3B9DBC1 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
PendleUniversalOracle
Compiler Version
v0.8.24+commit.e11b9ed9
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {IPMarket} from "@pendle/core-v2/interfaces/IPMarket.sol";
import {IPPrincipalToken} from "@pendle/core-v2/interfaces/IPPrincipalToken.sol";
import {IPPYLpOracle} from "@pendle/core-v2/interfaces/IPPYLpOracle.sol";
import {IStandardizedYield} from "@pendle/core-v2/interfaces/IStandardizedYield.sol";
import {PendlePYOracleLib} from "@pendle/core-v2/oracles/PendlePYOracleLib.sol";
import {PendleLpOracleLib} from "@pendle/core-v2/oracles/PendleLpOracleLib.sol";
import {BaseAdapter, Errors, IPriceOracle} from "../BaseAdapter.sol";
import {ScaleUtils, Scale} from "../../lib/ScaleUtils.sol";
/// @title PendleUniversalOracle
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Adapter for Pendle PT and LP Oracle.
contract PendleUniversalOracle is BaseAdapter {
/// @inheritdoc IPriceOracle
string public constant name = "PendleUniversalOracle";
/// @dev The minimum length of the TWAP window.
uint32 internal constant MIN_TWAP_WINDOW = 5 minutes;
/// @dev The maximum length of the TWAP window.
uint32 internal constant MAX_TWAP_WINDOW = 60 minutes;
/// @notice The decimals of the Pendle Oracle. Fixed to 18.
uint8 internal constant FEED_DECIMALS = 18;
/// @notice The address of the Pendle market.
address public immutable pendleMarket;
/// @notice The desired length of the twap window.
uint32 public immutable twapWindow;
/// @notice The address of the base asset, the PT address.
address public immutable base;
/// @notice The address of the quote asset, the SY or underlying address.
address public immutable quote;
/// @notice The PendlePYOracleLib function to call.
function (IPMarket, uint32) view returns (uint256) internal immutable getRate;
/// @notice The scale factors used for decimal conversions.
Scale internal immutable scale;
/// @notice Deploy a PendleUniversalOracle.
/// @dev The oracle can price Pendle PT,LP to SY,Asset. Whether to use SY or Asset depends on the underlying.
/// Consult https://docs.pendle.finance/Developers/Contracts/StandardizedYield#standard-sys for more information.
/// Before deploying this adapter ensure that the oracle is initialized and the observation buffer is filled.
/// Note that this adapter allows specifing any `quote` as the underlying asset.
/// @param _pendleOracle The address of the PendlePYLpOracle contract. Used only in the constructor.
/// @param _pendleMarket The address of the Pendle market.
/// @param _base The address of the PT or LP token.
/// @param _quote The address of the SY token or the underlying asset.
/// @param _twapWindow The desired length of the twap window.
constructor(address _pendleOracle, address _pendleMarket, address _base, address _quote, uint32 _twapWindow) {
// Verify that the TWAP window is sufficiently long.
if (_twapWindow < MIN_TWAP_WINDOW || _twapWindow > MAX_TWAP_WINDOW) {
revert Errors.PriceOracle_InvalidConfiguration();
}
// Verify that the observations buffer is adequately sized and populated.
(bool increaseCardinalityRequired,, bool oldestObservationSatisfied) =
IPPYLpOracle(_pendleOracle).getOracleState(_pendleMarket, _twapWindow);
if (increaseCardinalityRequired || !oldestObservationSatisfied) {
revert Errors.PriceOracle_InvalidConfiguration();
}
(IStandardizedYield sy, IPPrincipalToken pt,) = IPMarket(_pendleMarket).readTokens();
// Note: we allow using any asset pricing to any token.
if (_base == address(pt)) {
if (_quote == address(sy)) {
getRate = PendlePYOracleLib.getPtToSyRate;
} else {
getRate = PendlePYOracleLib.getPtToAssetRate;
}
} else if (_base == _pendleMarket) {
if (_quote == address(sy)) {
getRate = PendleLpOracleLib.getLpToSyRate;
} else {
getRate = PendleLpOracleLib.getLpToAssetRate;
}
} else {
revert Errors.PriceOracle_InvalidConfiguration();
}
pendleMarket = _pendleMarket;
base = _base;
quote = _quote;
twapWindow = _twapWindow;
uint8 baseDecimals = _getDecimals(base);
uint8 quoteDecimals = _getDecimals(quote);
scale = ScaleUtils.calcScale(baseDecimals, quoteDecimals, FEED_DECIMALS);
}
/// @notice Get a quote by calling the Pendle oracle.
/// @param inAmount The amount of `base` to convert.
/// @param _base The token that is being priced.
/// @param _quote The token that is the unit of account.
/// @dev Note that the quote does not include instantaneous DEX slippage.
/// @return The converted amount using the Pendle oracle.
function _getQuote(uint256 inAmount, address _base, address _quote) internal view override returns (uint256) {
bool inverse = ScaleUtils.getDirectionOrRevert(_base, base, _quote, quote);
uint256 unitPrice = getRate(IPMarket(pendleMarket), twapWindow);
return ScaleUtils.calcOutAmount(inAmount, unitPrice, scale, inverse);
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./IPPrincipalToken.sol";
import "./IPYieldToken.sol";
import "./IStandardizedYield.sol";
import "./IPGauge.sol";
import "../core/Market/MarketMathCore.sol";
interface IPMarket is IERC20Metadata, IPGauge {
event Mint(address indexed receiver, uint256 netLpMinted, uint256 netSyUsed, uint256 netPtUsed);
event Burn(
address indexed receiverSy,
address indexed receiverPt,
uint256 netLpBurned,
uint256 netSyOut,
uint256 netPtOut
);
event Swap(
address indexed caller,
address indexed receiver,
int256 netPtOut,
int256 netSyOut,
uint256 netSyFee,
uint256 netSyToReserve
);
event UpdateImpliedRate(uint256 indexed timestamp, uint256 lnLastImpliedRate);
event IncreaseObservationCardinalityNext(
uint16 observationCardinalityNextOld,
uint16 observationCardinalityNextNew
);
function mint(
address receiver,
uint256 netSyDesired,
uint256 netPtDesired
) external returns (uint256 netLpOut, uint256 netSyUsed, uint256 netPtUsed);
function burn(
address receiverSy,
address receiverPt,
uint256 netLpToBurn
) external returns (uint256 netSyOut, uint256 netPtOut);
function swapExactPtForSy(
address receiver,
uint256 exactPtIn,
bytes calldata data
) external returns (uint256 netSyOut, uint256 netSyFee);
function swapSyForExactPt(
address receiver,
uint256 exactPtOut,
bytes calldata data
) external returns (uint256 netSyIn, uint256 netSyFee);
function redeemRewards(address user) external returns (uint256[] memory);
function readState(address router) external view returns (MarketState memory market);
function observe(uint32[] memory secondsAgos) external view returns (uint216[] memory lnImpliedRateCumulative);
function increaseObservationsCardinalityNext(uint16 cardinalityNext) external;
function readTokens() external view returns (IStandardizedYield _SY, IPPrincipalToken _PT, IPYieldToken _YT);
function getRewardTokens() external view returns (address[] memory);
function isExpired() external view returns (bool);
function expiry() external view returns (uint256);
function observations(
uint256 index
) external view returns (uint32 blockTimestamp, uint216 lnImpliedRateCumulative, bool initialized);
function _storage()
external
view
returns (
int128 totalPt,
int128 totalSy,
uint96 lastLnImpliedRate,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext
);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface IPPrincipalToken is IERC20Metadata {
function burnByYT(address user, uint256 amount) external;
function mintByYT(address user, uint256 amount) external;
function initialize(address _YT) external;
function SY() external view returns (address);
function YT() external view returns (address);
function factory() external view returns (address);
function expiry() external view returns (uint256);
function isExpired() external view returns (bool);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
interface IPPYLpOracle {
event SetBlockCycleNumerator(uint16 newBlockCycleNumerator);
function getPtToAssetRate(address market, uint32 duration) external view returns (uint256);
function getYtToAssetRate(address market, uint32 duration) external view returns (uint256);
function getLpToAssetRate(address market, uint32 duration) external view returns (uint256);
function getPtToSyRate(address market, uint32 duration) external view returns (uint256);
function getYtToSyRate(address market, uint32 duration) external view returns (uint256);
function getLpToSyRate(address market, uint32 duration) external view returns (uint256);
function getOracleState(
address market,
uint32 duration
)
external
view
returns (bool increaseCardinalityRequired, uint16 cardinalityRequired, bool oldestObservationSatisfied);
}// SPDX-License-Identifier: GPL-3.0-or-later
/*
* MIT License
* ===========
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface IStandardizedYield is IERC20Metadata {
/// @dev Emitted when any base tokens is deposited to mint shares
event Deposit(
address indexed caller,
address indexed receiver,
address indexed tokenIn,
uint256 amountDeposited,
uint256 amountSyOut
);
/// @dev Emitted when any shares are redeemed for base tokens
event Redeem(
address indexed caller,
address indexed receiver,
address indexed tokenOut,
uint256 amountSyToRedeem,
uint256 amountTokenOut
);
/// @dev check `assetInfo()` for more information
enum AssetType {
TOKEN,
LIQUIDITY
}
/// @dev Emitted when (`user`) claims their rewards
event ClaimRewards(address indexed user, address[] rewardTokens, uint256[] rewardAmounts);
/**
* @notice mints an amount of shares by depositing a base token.
* @param receiver shares recipient address
* @param tokenIn address of the base tokens to mint shares
* @param amountTokenToDeposit amount of base tokens to be transferred from (`msg.sender`)
* @param minSharesOut reverts if amount of shares minted is lower than this
* @return amountSharesOut amount of shares minted
* @dev Emits a {Deposit} event
*
* Requirements:
* - (`tokenIn`) must be a valid base token.
*/
function deposit(
address receiver,
address tokenIn,
uint256 amountTokenToDeposit,
uint256 minSharesOut
) external payable returns (uint256 amountSharesOut);
/**
* @notice redeems an amount of base tokens by burning some shares
* @param receiver recipient address
* @param amountSharesToRedeem amount of shares to be burned
* @param tokenOut address of the base token to be redeemed
* @param minTokenOut reverts if amount of base token redeemed is lower than this
* @param burnFromInternalBalance if true, burns from balance of `address(this)`, otherwise burns from `msg.sender`
* @return amountTokenOut amount of base tokens redeemed
* @dev Emits a {Redeem} event
*
* Requirements:
* - (`tokenOut`) must be a valid base token.
*/
function redeem(
address receiver,
uint256 amountSharesToRedeem,
address tokenOut,
uint256 minTokenOut,
bool burnFromInternalBalance
) external returns (uint256 amountTokenOut);
/**
* @notice exchangeRate * syBalance / 1e18 must return the asset balance of the account
* @notice vice-versa, if a user uses some amount of tokens equivalent to X asset, the amount of sy
he can mint must be X * exchangeRate / 1e18
* @dev SYUtils's assetToSy & syToAsset should be used instead of raw multiplication
& division
*/
function exchangeRate() external view returns (uint256 res);
/**
* @notice claims reward for (`user`)
* @param user the user receiving their rewards
* @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`
* @dev
* Emits a `ClaimRewards` event
* See {getRewardTokens} for list of reward tokens
*/
function claimRewards(address user) external returns (uint256[] memory rewardAmounts);
/**
* @notice get the amount of unclaimed rewards for (`user`)
* @param user the user to check for
* @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`
*/
function accruedRewards(address user) external view returns (uint256[] memory rewardAmounts);
function rewardIndexesCurrent() external returns (uint256[] memory indexes);
function rewardIndexesStored() external view returns (uint256[] memory indexes);
/**
* @notice returns the list of reward token addresses
*/
function getRewardTokens() external view returns (address[] memory);
/**
* @notice returns the address of the underlying yield token
*/
function yieldToken() external view returns (address);
/**
* @notice returns all tokens that can mint this SY
*/
function getTokensIn() external view returns (address[] memory res);
/**
* @notice returns all tokens that can be redeemed by this SY
*/
function getTokensOut() external view returns (address[] memory res);
function isValidTokenIn(address token) external view returns (bool);
function isValidTokenOut(address token) external view returns (bool);
function previewDeposit(
address tokenIn,
uint256 amountTokenToDeposit
) external view returns (uint256 amountSharesOut);
function previewRedeem(
address tokenOut,
uint256 amountSharesToRedeem
) external view returns (uint256 amountTokenOut);
/**
* @notice This function contains information to interpret what the asset is
* @return assetType the type of the asset (0 for ERC20 tokens, 1 for AMM liquidity tokens,
2 for bridged yield bearing tokens like wstETH, rETH on Arbi whose the underlying asset doesn't exist on the chain)
* @return assetAddress the address of the asset
* @return assetDecimals the decimals of the asset
*/
function assetInfo() external view returns (AssetType assetType, address assetAddress, uint8 assetDecimals);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "../interfaces/IPMarket.sol";
import "../core/libraries/math/PMath.sol";
// This library can & should be integrated directly for optimal gas usage.
// If you prefer not to integrate it directly, the PendlePtOracle contract (a pre-deployed version of this contract) can be used.
library PendlePYOracleLib {
using PMath for uint256;
using PMath for int256;
/**
* This function returns the twap rate PT/Asset on market, but take into account the current rate of SY
This is to account for special cases where underlying asset becomes insolvent and has decreasing exchangeRate
* @param market market to get rate from
* @param duration twap duration
*/
function getPtToAssetRate(IPMarket market, uint32 duration) internal view returns (uint256) {
(uint256 syIndex, uint256 pyIndex) = getSYandPYIndexCurrent(market);
if (syIndex >= pyIndex) {
return getPtToAssetRateRaw(market, duration);
} else {
return (getPtToAssetRateRaw(market, duration) * syIndex) / pyIndex;
}
}
/**
* This function returns the twap rate YT/Asset on market, but take into account the current rate of SY
This is to account for special cases where underlying asset becomes insolvent and has decreasing exchangeRate
* @param market market to get rate from
* @param duration twap duration
*/
function getYtToAssetRate(IPMarket market, uint32 duration) internal view returns (uint256) {
(uint256 syIndex, uint256 pyIndex) = getSYandPYIndexCurrent(market);
if (syIndex >= pyIndex) {
return getYtToAssetRateRaw(market, duration);
} else {
return (getYtToAssetRateRaw(market, duration) * syIndex) / pyIndex;
}
}
/// @notice Similar to getPtToAsset but returns the rate in SY instead
function getPtToSyRate(IPMarket market, uint32 duration) internal view returns (uint256) {
(uint256 syIndex, uint256 pyIndex) = getSYandPYIndexCurrent(market);
if (syIndex >= pyIndex) {
return getPtToAssetRateRaw(market, duration).divDown(syIndex);
} else {
return getPtToAssetRateRaw(market, duration).divDown(pyIndex);
}
}
/// @notice Similar to getPtToAsset but returns the rate in SY instead
function getYtToSyRate(IPMarket market, uint32 duration) internal view returns (uint256) {
(uint256 syIndex, uint256 pyIndex) = getSYandPYIndexCurrent(market);
if (syIndex >= pyIndex) {
return getYtToAssetRateRaw(market, duration).divDown(syIndex);
} else {
return getYtToAssetRateRaw(market, duration).divDown(pyIndex);
}
}
/// @notice returns the raw rate without taking into account whether SY is solvent
function getPtToAssetRateRaw(IPMarket market, uint32 duration) internal view returns (uint256) {
uint256 expiry = market.expiry();
if (expiry <= block.timestamp) {
return PMath.ONE;
} else {
uint256 lnImpliedRate = getMarketLnImpliedRate(market, duration);
uint256 timeToExpiry = expiry - block.timestamp;
uint256 assetToPtRate = MarketMathCore._getExchangeRateFromImpliedRate(lnImpliedRate, timeToExpiry).Uint();
return PMath.ONE.divDown(assetToPtRate);
}
}
/// @notice returns the raw rate without taking into account whether SY is solvent
function getYtToAssetRateRaw(IPMarket market, uint32 duration) internal view returns (uint256) {
return PMath.ONE - getPtToAssetRateRaw(market, duration);
}
function getSYandPYIndexCurrent(IPMarket market) internal view returns (uint256 syIndex, uint256 pyIndex) {
(IStandardizedYield SY, , IPYieldToken YT) = market.readTokens();
syIndex = SY.exchangeRate();
uint256 pyIndexStored = YT.pyIndexStored();
if (YT.doCacheIndexSameBlock() && YT.pyIndexLastUpdatedBlock() == block.number) {
pyIndex = pyIndexStored;
} else {
pyIndex = PMath.max(syIndex, pyIndexStored);
}
}
function getMarketLnImpliedRate(IPMarket market, uint32 duration) internal view returns (uint256) {
uint32[] memory durations = new uint32[](2);
durations[0] = duration;
uint216[] memory lnImpliedRateCumulative = market.observe(durations);
return (lnImpliedRateCumulative[1] - lnImpliedRateCumulative[0]) / duration;
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "./PendlePYOracleLib.sol";
library PendleLpOracleLib {
using PendlePYOracleLib for IPMarket;
using PMath for uint256;
using PMath for int256;
using MarketMathCore for MarketState;
/**
* This function returns the approximated twap rate LP/asset on market, but take into account the current rate of SY
This is to account for special cases where underlying asset becomes insolvent and has decreasing exchangeRate
* @param market market to get rate from
* @param duration twap duration
*/
function getLpToAssetRate(IPMarket market, uint32 duration) internal view returns (uint256) {
(uint256 syIndex, uint256 pyIndex) = market.getSYandPYIndexCurrent();
uint256 lpToAssetRateRaw = _getLpToAssetRateRaw(market, duration, pyIndex);
if (syIndex >= pyIndex) {
return lpToAssetRateRaw;
} else {
return (lpToAssetRateRaw * syIndex) / pyIndex;
}
}
/**
* This function returns the approximated twap rate LP/asset on market, but take into account the current rate of SY
This is to account for special cases where underlying asset becomes insolvent and has decreasing exchangeRate
* @param market market to get rate from
* @param duration twap duration
*/
function getLpToSyRate(IPMarket market, uint32 duration) internal view returns (uint256) {
(uint256 syIndex, uint256 pyIndex) = market.getSYandPYIndexCurrent();
uint256 lpToAssetRateRaw = _getLpToAssetRateRaw(market, duration, pyIndex);
if (syIndex >= pyIndex) {
return lpToAssetRateRaw.divDown(syIndex);
} else {
return lpToAssetRateRaw.divDown(pyIndex);
}
}
function _getLpToAssetRateRaw(
IPMarket market,
uint32 duration,
uint256 pyIndex
) private view returns (uint256 lpToAssetRateRaw) {
MarketState memory state = market.readState(address(0));
int256 totalHypotheticalAsset;
if (state.expiry <= block.timestamp) {
// 1 PT = 1 Asset post-expiry
totalHypotheticalAsset = state.totalPt + PYIndexLib.syToAsset(PYIndex.wrap(pyIndex), state.totalSy);
} else {
MarketPreCompute memory comp = state.getMarketPreCompute(PYIndex.wrap(pyIndex), block.timestamp);
(int256 rateOracle, int256 rateHypTrade) = _getPtRatesRaw(market, state, duration);
int256 cParam = LogExpMath.exp(comp.rateScalar.mulDown((rateOracle - comp.rateAnchor)));
int256 tradeSize = (cParam.mulDown(comp.totalAsset) - state.totalPt).divDown(
PMath.IONE + cParam.divDown(rateHypTrade)
);
totalHypotheticalAsset =
comp.totalAsset -
tradeSize.divDown(rateHypTrade) +
(state.totalPt + tradeSize).divDown(rateOracle);
}
lpToAssetRateRaw = totalHypotheticalAsset.divDown(state.totalLp).Uint();
}
function _getPtRatesRaw(
IPMarket market,
MarketState memory state,
uint32 duration
) private view returns (int256 rateOracle, int256 rateHypTrade) {
uint256 lnImpliedRate = market.getMarketLnImpliedRate(duration);
uint256 timeToExpiry = state.expiry - block.timestamp;
rateOracle = MarketMathCore._getExchangeRateFromImpliedRate(lnImpliedRate, timeToExpiry);
int256 rateLastTrade = MarketMathCore._getExchangeRateFromImpliedRate(state.lastLnImpliedRate, timeToExpiry);
rateHypTrade = (rateLastTrade + rateOracle) / 2;
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {IERC20} from "forge-std/interfaces/IERC20.sol";
import {IPriceOracle} from "../interfaces/IPriceOracle.sol";
import {Errors} from "../lib/Errors.sol";
/// @title BaseAdapter
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Abstract adapter with virtual bid/ask pricing.
abstract contract BaseAdapter is IPriceOracle {
// @dev Addresses <= 0x00..00ffffffff are considered to have 18 decimals without dispatching a call.
// This avoids collisions between ISO 4217 representations and (future) precompiles.
uint256 internal constant ADDRESS_RESERVED_RANGE = 0xffffffff;
/// @inheritdoc IPriceOracle
function getQuote(uint256 inAmount, address base, address quote) external view returns (uint256) {
return _getQuote(inAmount, base, quote);
}
/// @inheritdoc IPriceOracle
/// @dev Does not support true bid/ask pricing.
function getQuotes(uint256 inAmount, address base, address quote) external view returns (uint256, uint256) {
uint256 outAmount = _getQuote(inAmount, base, quote);
return (outAmount, outAmount);
}
/// @notice Determine the decimals of an asset.
/// @param asset ERC20 token address or other asset.
/// @dev Oracles can use ERC-7535, ISO 4217 or other conventions to represent non-ERC20 assets as addresses.
/// Integrator Note: `_getDecimals` will return 18 if `asset` is:
/// - any address <= 0x00000000000000000000000000000000ffffffff (4294967295)
/// - an EOA or a to-be-deployed contract (which may implement `decimals()` after deployment).
/// - a contract that does not implement `decimals()`.
/// @return The decimals of the asset.
function _getDecimals(address asset) internal view returns (uint8) {
if (uint160(asset) <= ADDRESS_RESERVED_RANGE) return 18;
(bool success, bytes memory data) = asset.staticcall(abi.encodeCall(IERC20.decimals, ()));
return success && data.length == 32 ? abi.decode(data, (uint8)) : 18;
}
/// @notice Return the quote for the given price query.
/// @dev Must be overridden in the inheriting contract.
function _getQuote(uint256, address, address) internal view virtual returns (uint256);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import {FixedPointMathLib} from "@solady/utils/FixedPointMathLib.sol";
import {Errors} from "./Errors.sol";
type Scale is uint256;
/// @title ScaleUtils
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice Utilities for handling decimal conversion of unit price feeds.
library ScaleUtils {
uint256 internal constant PRICE_SCALE_MASK = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff;
/// @notice The maximum allowed exponent for Scale components.
/// @dev 38 is the largest integer exponent of 10 that fits in 128 bits.
uint256 internal constant MAX_EXPONENT = 38;
/// @notice Create a `Scale` by packing 2 powers of 10.
/// @dev Upper 128 bits occupied by 10^feedExponent.
/// Lower 128 bits occupied by 10^priceExponent.
/// @param priceExponent The power for `priceScale = 10**priceExponent`.
/// @param feedExponent The power for `feedScale = 10**feedExponent`.
/// @return The two scale factors packed in `Scale`.
function from(uint8 priceExponent, uint8 feedExponent) internal pure returns (Scale) {
if (priceExponent > MAX_EXPONENT || feedExponent > MAX_EXPONENT) {
revert Errors.PriceOracle_Overflow();
}
return Scale.wrap((10 ** feedExponent << 128) | 10 ** priceExponent);
}
/// @notice Calculate the direction of pricing, or revert if no match.
/// @param givenBase The base asset supplied by the caller.
/// @param base The base asset in the price oracle adapter.
/// @param givenQuote The quote asset supplied by the caller.
/// @param quote The quote asset in the price oracle adapter.
/// @return False if base/quote, true if quote/base else revert.
function getDirectionOrRevert(address givenBase, address base, address givenQuote, address quote)
internal
pure
returns (bool)
{
if (givenBase == base && givenQuote == quote) return false;
if (givenBase == quote && givenQuote == base) return true;
revert Errors.PriceOracle_NotSupported(givenBase, givenQuote);
}
/// @notice Calculate the scale factors for converting a unit price.
/// @param baseDecimals The decimals of the base asset.
/// @param quoteDecimals The decimals of the quote asset.
/// @param feedDecimals The decimals of the feed, already incorporated into the price.
/// @return The scale factors used for price conversions.
function calcScale(uint8 baseDecimals, uint8 quoteDecimals, uint8 feedDecimals) internal pure returns (Scale) {
return from(quoteDecimals, feedDecimals + baseDecimals);
}
/// @notice Convert the price by applying scale factors.
/// @param inAmount The amount of `base` to convert.
/// @param unitPrice The unit price reported by the feed.
/// @param scale The scale factors returned by `calcScale`.
/// @param inverse Whether to price base/quote or quote/base.
/// @return The resulting outAmount.
function calcOutAmount(uint256 inAmount, uint256 unitPrice, Scale scale, bool inverse)
internal
pure
returns (uint256)
{
uint256 priceScale = Scale.unwrap(scale) & PRICE_SCALE_MASK;
uint256 feedScale = Scale.unwrap(scale) >> 128;
if (inverse) {
// (inAmount * feedScale) / (priceScale * unitPrice)
return FixedPointMathLib.fullMulDiv(inAmount, feedScale, priceScale * unitPrice);
} else {
// (inAmount * priceScale * unitPrice) / feedScale
return FixedPointMathLib.fullMulDiv(inAmount, priceScale * unitPrice, feedScale);
}
}
}// 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: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./IRewardManager.sol";
import "./IPInterestManagerYT.sol";
interface IPYieldToken is IERC20Metadata, IRewardManager, IPInterestManagerYT {
event NewInterestIndex(uint256 indexed newIndex);
event Mint(
address indexed caller,
address indexed receiverPT,
address indexed receiverYT,
uint256 amountSyToMint,
uint256 amountPYOut
);
event Burn(address indexed caller, address indexed receiver, uint256 amountPYToRedeem, uint256 amountSyOut);
event RedeemRewards(address indexed user, uint256[] amountRewardsOut);
event RedeemInterest(address indexed user, uint256 interestOut);
event CollectRewardFee(address indexed rewardToken, uint256 amountRewardFee);
function mintPY(address receiverPT, address receiverYT) external returns (uint256 amountPYOut);
function redeemPY(address receiver) external returns (uint256 amountSyOut);
function redeemPYMulti(
address[] calldata receivers,
uint256[] calldata amountPYToRedeems
) external returns (uint256[] memory amountSyOuts);
function redeemDueInterestAndRewards(
address user,
bool redeemInterest,
bool redeemRewards
) external returns (uint256 interestOut, uint256[] memory rewardsOut);
function rewardIndexesCurrent() external returns (uint256[] memory);
function pyIndexCurrent() external returns (uint256);
function pyIndexStored() external view returns (uint256);
function getRewardTokens() external view returns (address[] memory);
function SY() external view returns (address);
function PT() external view returns (address);
function factory() external view returns (address);
function expiry() external view returns (uint256);
function isExpired() external view returns (bool);
function doCacheIndexSameBlock() external view returns (bool);
function pyIndexLastUpdatedBlock() external view returns (uint128);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
interface IPGauge {
function totalActiveSupply() external view returns (uint256);
function activeBalance(address user) external view returns (uint256);
// only available for newer factories. please check the verified contracts
event RedeemRewards(address indexed user, uint256[] rewardsOut);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "../libraries/math/PMath.sol";
import "../libraries/math/LogExpMath.sol";
import "../StandardizedYield/PYIndex.sol";
import "../libraries/MiniHelpers.sol";
import "../libraries/Errors.sol";
struct MarketState {
int256 totalPt;
int256 totalSy;
int256 totalLp;
address treasury;
/// immutable variables ///
int256 scalarRoot;
uint256 expiry;
/// fee data ///
uint256 lnFeeRateRoot;
uint256 reserveFeePercent; // base 100
/// last trade data ///
uint256 lastLnImpliedRate;
}
// params that are expensive to compute, therefore we pre-compute them
struct MarketPreCompute {
int256 rateScalar;
int256 totalAsset;
int256 rateAnchor;
int256 feeRate;
}
// solhint-disable ordering
library MarketMathCore {
using PMath for uint256;
using PMath for int256;
using LogExpMath for int256;
using PYIndexLib for PYIndex;
int256 internal constant MINIMUM_LIQUIDITY = 10 ** 3;
int256 internal constant PERCENTAGE_DECIMALS = 100;
uint256 internal constant DAY = 86400;
uint256 internal constant IMPLIED_RATE_TIME = 365 * DAY;
int256 internal constant MAX_MARKET_PROPORTION = (1e18 * 96) / 100;
using PMath for uint256;
using PMath for int256;
/*///////////////////////////////////////////////////////////////
UINT FUNCTIONS TO PROXY TO CORE FUNCTIONS
//////////////////////////////////////////////////////////////*/
function addLiquidity(
MarketState memory market,
uint256 syDesired,
uint256 ptDesired,
uint256 blockTime
) internal pure returns (uint256 lpToReserve, uint256 lpToAccount, uint256 syUsed, uint256 ptUsed) {
(int256 _lpToReserve, int256 _lpToAccount, int256 _syUsed, int256 _ptUsed) = addLiquidityCore(
market,
syDesired.Int(),
ptDesired.Int(),
blockTime
);
lpToReserve = _lpToReserve.Uint();
lpToAccount = _lpToAccount.Uint();
syUsed = _syUsed.Uint();
ptUsed = _ptUsed.Uint();
}
function removeLiquidity(
MarketState memory market,
uint256 lpToRemove
) internal pure returns (uint256 netSyToAccount, uint256 netPtToAccount) {
(int256 _syToAccount, int256 _ptToAccount) = removeLiquidityCore(market, lpToRemove.Int());
netSyToAccount = _syToAccount.Uint();
netPtToAccount = _ptToAccount.Uint();
}
function swapExactPtForSy(
MarketState memory market,
PYIndex index,
uint256 exactPtToMarket,
uint256 blockTime
) internal pure returns (uint256 netSyToAccount, uint256 netSyFee, uint256 netSyToReserve) {
(int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(
market,
index,
exactPtToMarket.neg(),
blockTime
);
netSyToAccount = _netSyToAccount.Uint();
netSyFee = _netSyFee.Uint();
netSyToReserve = _netSyToReserve.Uint();
}
function swapSyForExactPt(
MarketState memory market,
PYIndex index,
uint256 exactPtToAccount,
uint256 blockTime
) internal pure returns (uint256 netSyToMarket, uint256 netSyFee, uint256 netSyToReserve) {
(int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(
market,
index,
exactPtToAccount.Int(),
blockTime
);
netSyToMarket = _netSyToAccount.neg().Uint();
netSyFee = _netSyFee.Uint();
netSyToReserve = _netSyToReserve.Uint();
}
/*///////////////////////////////////////////////////////////////
CORE FUNCTIONS
//////////////////////////////////////////////////////////////*/
function addLiquidityCore(
MarketState memory market,
int256 syDesired,
int256 ptDesired,
uint256 blockTime
) internal pure returns (int256 lpToReserve, int256 lpToAccount, int256 syUsed, int256 ptUsed) {
/// ------------------------------------------------------------
/// CHECKS
/// ------------------------------------------------------------
if (syDesired == 0 || ptDesired == 0) revert Errors.MarketZeroAmountsInput();
if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();
/// ------------------------------------------------------------
/// MATH
/// ------------------------------------------------------------
if (market.totalLp == 0) {
lpToAccount = PMath.sqrt((syDesired * ptDesired).Uint()).Int() - MINIMUM_LIQUIDITY;
lpToReserve = MINIMUM_LIQUIDITY;
syUsed = syDesired;
ptUsed = ptDesired;
} else {
int256 netLpByPt = (ptDesired * market.totalLp) / market.totalPt;
int256 netLpBySy = (syDesired * market.totalLp) / market.totalSy;
if (netLpByPt < netLpBySy) {
lpToAccount = netLpByPt;
ptUsed = ptDesired;
syUsed = (market.totalSy * lpToAccount).rawDivUp(market.totalLp);
} else {
lpToAccount = netLpBySy;
syUsed = syDesired;
ptUsed = (market.totalPt * lpToAccount).rawDivUp(market.totalLp);
}
}
if (lpToAccount <= 0 || syUsed <= 0 || ptUsed <= 0) revert Errors.MarketZeroAmountsOutput();
/// ------------------------------------------------------------
/// WRITE
/// ------------------------------------------------------------
market.totalSy += syUsed;
market.totalPt += ptUsed;
market.totalLp += lpToAccount + lpToReserve;
}
function removeLiquidityCore(
MarketState memory market,
int256 lpToRemove
) internal pure returns (int256 netSyToAccount, int256 netPtToAccount) {
/// ------------------------------------------------------------
/// CHECKS
/// ------------------------------------------------------------
if (lpToRemove == 0) revert Errors.MarketZeroAmountsInput();
/// ------------------------------------------------------------
/// MATH
/// ------------------------------------------------------------
netSyToAccount = (lpToRemove * market.totalSy) / market.totalLp;
netPtToAccount = (lpToRemove * market.totalPt) / market.totalLp;
if (netSyToAccount == 0 && netPtToAccount == 0) revert Errors.MarketZeroAmountsOutput();
/// ------------------------------------------------------------
/// WRITE
/// ------------------------------------------------------------
market.totalLp = market.totalLp.subNoNeg(lpToRemove);
market.totalPt = market.totalPt.subNoNeg(netPtToAccount);
market.totalSy = market.totalSy.subNoNeg(netSyToAccount);
}
function executeTradeCore(
MarketState memory market,
PYIndex index,
int256 netPtToAccount,
uint256 blockTime
) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {
/// ------------------------------------------------------------
/// CHECKS
/// ------------------------------------------------------------
if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();
if (market.totalPt <= netPtToAccount)
revert Errors.MarketInsufficientPtForTrade(market.totalPt, netPtToAccount);
/// ------------------------------------------------------------
/// MATH
/// ------------------------------------------------------------
MarketPreCompute memory comp = getMarketPreCompute(market, index, blockTime);
(netSyToAccount, netSyFee, netSyToReserve) = calcTrade(market, comp, index, netPtToAccount);
/// ------------------------------------------------------------
/// WRITE
/// ------------------------------------------------------------
_setNewMarketStateTrade(market, comp, index, netPtToAccount, netSyToAccount, netSyToReserve, blockTime);
}
function getMarketPreCompute(
MarketState memory market,
PYIndex index,
uint256 blockTime
) internal pure returns (MarketPreCompute memory res) {
if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();
uint256 timeToExpiry = market.expiry - blockTime;
res.rateScalar = _getRateScalar(market, timeToExpiry);
res.totalAsset = index.syToAsset(market.totalSy);
if (market.totalPt == 0 || res.totalAsset == 0)
revert Errors.MarketZeroTotalPtOrTotalAsset(market.totalPt, res.totalAsset);
res.rateAnchor = _getRateAnchor(
market.totalPt,
market.lastLnImpliedRate,
res.totalAsset,
res.rateScalar,
timeToExpiry
);
res.feeRate = _getExchangeRateFromImpliedRate(market.lnFeeRateRoot, timeToExpiry);
}
function calcTrade(
MarketState memory market,
MarketPreCompute memory comp,
PYIndex index,
int256 netPtToAccount
) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {
int256 preFeeExchangeRate = _getExchangeRate(
market.totalPt,
comp.totalAsset,
comp.rateScalar,
comp.rateAnchor,
netPtToAccount
);
int256 preFeeAssetToAccount = netPtToAccount.divDown(preFeeExchangeRate).neg();
int256 fee = comp.feeRate;
if (netPtToAccount > 0) {
int256 postFeeExchangeRate = preFeeExchangeRate.divDown(fee);
if (postFeeExchangeRate < PMath.IONE) revert Errors.MarketExchangeRateBelowOne(postFeeExchangeRate);
fee = preFeeAssetToAccount.mulDown(PMath.IONE - fee);
} else {
fee = ((preFeeAssetToAccount * (PMath.IONE - fee)) / fee).neg();
}
int256 netAssetToReserve = (fee * market.reserveFeePercent.Int()) / PERCENTAGE_DECIMALS;
int256 netAssetToAccount = preFeeAssetToAccount - fee;
netSyToAccount = netAssetToAccount < 0
? index.assetToSyUp(netAssetToAccount)
: index.assetToSy(netAssetToAccount);
netSyFee = index.assetToSy(fee);
netSyToReserve = index.assetToSy(netAssetToReserve);
}
function _setNewMarketStateTrade(
MarketState memory market,
MarketPreCompute memory comp,
PYIndex index,
int256 netPtToAccount,
int256 netSyToAccount,
int256 netSyToReserve,
uint256 blockTime
) internal pure {
uint256 timeToExpiry = market.expiry - blockTime;
market.totalPt = market.totalPt.subNoNeg(netPtToAccount);
market.totalSy = market.totalSy.subNoNeg(netSyToAccount + netSyToReserve);
market.lastLnImpliedRate = _getLnImpliedRate(
market.totalPt,
index.syToAsset(market.totalSy),
comp.rateScalar,
comp.rateAnchor,
timeToExpiry
);
if (market.lastLnImpliedRate == 0) revert Errors.MarketZeroLnImpliedRate();
}
function _getRateAnchor(
int256 totalPt,
uint256 lastLnImpliedRate,
int256 totalAsset,
int256 rateScalar,
uint256 timeToExpiry
) internal pure returns (int256 rateAnchor) {
int256 newExchangeRate = _getExchangeRateFromImpliedRate(lastLnImpliedRate, timeToExpiry);
if (newExchangeRate < PMath.IONE) revert Errors.MarketExchangeRateBelowOne(newExchangeRate);
{
int256 proportion = totalPt.divDown(totalPt + totalAsset);
int256 lnProportion = _logProportion(proportion);
rateAnchor = newExchangeRate - lnProportion.divDown(rateScalar);
}
}
/// @notice Calculates the current market implied rate.
/// @return lnImpliedRate the implied rate
function _getLnImpliedRate(
int256 totalPt,
int256 totalAsset,
int256 rateScalar,
int256 rateAnchor,
uint256 timeToExpiry
) internal pure returns (uint256 lnImpliedRate) {
// This will check for exchange rates < PMath.IONE
int256 exchangeRate = _getExchangeRate(totalPt, totalAsset, rateScalar, rateAnchor, 0);
// exchangeRate >= 1 so its ln >= 0
uint256 lnRate = exchangeRate.ln().Uint();
lnImpliedRate = (lnRate * IMPLIED_RATE_TIME) / timeToExpiry;
}
/// @notice Converts an implied rate to an exchange rate given a time to expiry. The
/// formula is E = e^rt
function _getExchangeRateFromImpliedRate(
uint256 lnImpliedRate,
uint256 timeToExpiry
) internal pure returns (int256 exchangeRate) {
uint256 rt = (lnImpliedRate * timeToExpiry) / IMPLIED_RATE_TIME;
exchangeRate = LogExpMath.exp(rt.Int());
}
function _getExchangeRate(
int256 totalPt,
int256 totalAsset,
int256 rateScalar,
int256 rateAnchor,
int256 netPtToAccount
) internal pure returns (int256 exchangeRate) {
int256 numerator = totalPt.subNoNeg(netPtToAccount);
int256 proportion = (numerator.divDown(totalPt + totalAsset));
if (proportion > MAX_MARKET_PROPORTION)
revert Errors.MarketProportionTooHigh(proportion, MAX_MARKET_PROPORTION);
int256 lnProportion = _logProportion(proportion);
exchangeRate = lnProportion.divDown(rateScalar) + rateAnchor;
if (exchangeRate < PMath.IONE) revert Errors.MarketExchangeRateBelowOne(exchangeRate);
}
function _logProportion(int256 proportion) internal pure returns (int256 res) {
if (proportion == PMath.IONE) revert Errors.MarketProportionMustNotEqualOne();
int256 logitP = proportion.divDown(PMath.IONE - proportion);
res = logitP.ln();
}
function _getRateScalar(MarketState memory market, uint256 timeToExpiry) internal pure returns (int256 rateScalar) {
rateScalar = (market.scalarRoot * IMPLIED_RATE_TIME.Int()) / timeToExpiry.Int();
if (rateScalar <= 0) revert Errors.MarketRateScalarBelowZero(rateScalar);
}
function setInitialLnImpliedRate(
MarketState memory market,
PYIndex index,
int256 initialAnchor,
uint256 blockTime
) internal pure {
/// ------------------------------------------------------------
/// CHECKS
/// ------------------------------------------------------------
if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();
/// ------------------------------------------------------------
/// MATH
/// ------------------------------------------------------------
int256 totalAsset = index.syToAsset(market.totalSy);
uint256 timeToExpiry = market.expiry - blockTime;
int256 rateScalar = _getRateScalar(market, timeToExpiry);
/// ------------------------------------------------------------
/// WRITE
/// ------------------------------------------------------------
market.lastLnImpliedRate = _getLnImpliedRate(
market.totalPt,
totalAsset,
rateScalar,
initialAnchor,
timeToExpiry
);
}
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.8.0;
/* solhint-disable private-vars-leading-underscore, reason-string */
library PMath {
uint256 internal constant ONE = 1e18; // 18 decimal places
int256 internal constant IONE = 1e18; // 18 decimal places
function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
return (a >= b ? a - b : 0);
}
}
function subNoNeg(int256 a, int256 b) internal pure returns (int256) {
require(a >= b, "negative");
return a - b; // no unchecked since if b is very negative, a - b might overflow
}
function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 product = a * b;
unchecked {
return product / ONE;
}
}
function mulDown(int256 a, int256 b) internal pure returns (int256) {
int256 product = a * b;
unchecked {
return product / IONE;
}
}
function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 aInflated = a * ONE;
unchecked {
return aInflated / b;
}
}
function divDown(int256 a, int256 b) internal pure returns (int256) {
int256 aInflated = a * IONE;
unchecked {
return aInflated / b;
}
}
function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {
return (a + b - 1) / b;
}
function rawDivUp(int256 a, int256 b) internal pure returns (int256) {
return (a + b - 1) / b;
}
function slipUp(uint256 a, uint256 factor) internal pure returns (uint256) {
return mulDown(a, ONE + factor);
}
function slipDown(uint256 a, uint256 factor) internal pure returns (uint256) {
return mulDown(a, ONE - factor);
}
// @author Uniswap
function sqrt(uint256 y) internal pure returns (uint256 z) {
if (y > 3) {
z = y;
uint256 x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
function square(uint256 x) internal pure returns (uint256) {
return x * x;
}
function squareDown(uint256 x) internal pure returns (uint256) {
return mulDown(x, x);
}
function abs(int256 x) internal pure returns (uint256) {
return uint256(x > 0 ? x : -x);
}
function neg(int256 x) internal pure returns (int256) {
return x * (-1);
}
function neg(uint256 x) internal pure returns (int256) {
return Int(x) * (-1);
}
function max(uint256 x, uint256 y) internal pure returns (uint256) {
return (x > y ? x : y);
}
function max(int256 x, int256 y) internal pure returns (int256) {
return (x > y ? x : y);
}
function min(uint256 x, uint256 y) internal pure returns (uint256) {
return (x < y ? x : y);
}
function min(int256 x, int256 y) internal pure returns (int256) {
return (x < y ? x : y);
}
/*///////////////////////////////////////////////////////////////
SIGNED CASTS
//////////////////////////////////////////////////////////////*/
function Int(uint256 x) internal pure returns (int256) {
require(x <= uint256(type(int256).max));
return int256(x);
}
function Int128(int256 x) internal pure returns (int128) {
require(type(int128).min <= x && x <= type(int128).max);
return int128(x);
}
function Int128(uint256 x) internal pure returns (int128) {
return Int128(Int(x));
}
/*///////////////////////////////////////////////////////////////
UNSIGNED CASTS
//////////////////////////////////////////////////////////////*/
function Uint(int256 x) internal pure returns (uint256) {
require(x >= 0);
return uint256(x);
}
function Uint32(uint256 x) internal pure returns (uint32) {
require(x <= type(uint32).max);
return uint32(x);
}
function Uint64(uint256 x) internal pure returns (uint64) {
require(x <= type(uint64).max);
return uint64(x);
}
function Uint112(uint256 x) internal pure returns (uint112) {
require(x <= type(uint112).max);
return uint112(x);
}
function Uint96(uint256 x) internal pure returns (uint96) {
require(x <= type(uint96).max);
return uint96(x);
}
function Uint128(uint256 x) internal pure returns (uint128) {
require(x <= type(uint128).max);
return uint128(x);
}
function Uint192(uint256 x) internal pure returns (uint192) {
require(x <= type(uint192).max);
return uint192(x);
}
function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps);
}
function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return a >= b && a <= mulDown(b, ONE + eps);
}
function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return a <= b && a >= mulDown(b, ONE - eps);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2;
/// @dev Interface of the ERC20 standard as defined in the EIP.
/// @dev This includes the optional name, symbol, and decimals metadata.
interface IERC20 {
/// @dev Emitted when `value` tokens are moved from one account (`from`) to another (`to`).
event Transfer(address indexed from, address indexed to, uint256 value);
/// @dev Emitted when the allowance of a `spender` for an `owner` is set, where `value`
/// is the new allowance.
event Approval(address indexed owner, address indexed spender, uint256 value);
/// @notice Returns the amount of tokens in existence.
function totalSupply() external view returns (uint256);
/// @notice Returns the amount of tokens owned by `account`.
function balanceOf(address account) external view returns (uint256);
/// @notice Moves `amount` tokens from the caller's account to `to`.
function transfer(address to, uint256 amount) external returns (bool);
/// @notice Returns the remaining number of tokens that `spender` is allowed
/// to spend on behalf of `owner`
function allowance(address owner, address spender) external view returns (uint256);
/// @notice Sets `amount` as the allowance of `spender` over the caller's tokens.
/// @dev Be aware of front-running risks: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
function approve(address spender, uint256 amount) external returns (bool);
/// @notice Moves `amount` tokens from `from` to `to` using the allowance mechanism.
/// `amount` is then deducted from the caller's allowance.
function transferFrom(address from, address to, uint256 amount) external returns (bool);
/// @notice Returns the name of the token.
function name() external view returns (string memory);
/// @notice Returns the symbol of the token.
function symbol() external view returns (string memory);
/// @notice Returns the decimals places of the token.
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.0; /// @title IPriceOracle /// @custom:security-contact [email protected] /// @author Euler Labs (https://www.eulerlabs.com/) /// @notice Common PriceOracle interface. interface IPriceOracle { /// @notice Get the name of the oracle. /// @return The name of the oracle. function name() external view returns (string memory); /// @notice One-sided price: How much quote token you would get for inAmount of base token, assuming no price spread. /// @param inAmount The amount of `base` to convert. /// @param base The token that is being priced. /// @param quote The token that is the unit of account. /// @return outAmount The amount of `quote` that is equivalent to `inAmount` of `base`. function getQuote(uint256 inAmount, address base, address quote) external view returns (uint256 outAmount); /// @notice Two-sided price: How much quote token you would get/spend for selling/buying inAmount of base token. /// @param inAmount The amount of `base` to convert. /// @param base The token that is being priced. /// @param quote The token that is the unit of account. /// @return bidOutAmount The amount of `quote` you would get for selling `inAmount` of `base`. /// @return askOutAmount The amount of `quote` you would spend for buying `inAmount` of `base`. function getQuotes(uint256 inAmount, address base, address quote) external view returns (uint256 bidOutAmount, uint256 askOutAmount); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; /// @title Errors /// @custom:security-contact [email protected] /// @author Euler Labs (https://www.eulerlabs.com/) /// @notice Collects common errors in PriceOracles. library Errors { /// @notice The external feed returned an invalid answer. error PriceOracle_InvalidAnswer(); /// @notice The configuration parameters for the PriceOracle are invalid. error PriceOracle_InvalidConfiguration(); /// @notice The base/quote path is not supported. /// @param base The address of the base asset. /// @param quote The address of the quote asset. error PriceOracle_NotSupported(address base, address quote); /// @notice The quote cannot be completed due to overflow. error PriceOracle_Overflow(); /// @notice The price is too stale. /// @param staleness The time elapsed since the price was updated. /// @param maxStaleness The maximum time elapsed since the last price update. error PriceOracle_TooStale(uint256 staleness, uint256 maxStaleness); /// @notice The method can only be called by the governor. error Governance_CallerNotGovernor(); }
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
library FixedPointMathLib {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The operation failed, as the output exceeds the maximum value of uint256.
error ExpOverflow();
/// @dev The operation failed, as the output exceeds the maximum value of uint256.
error FactorialOverflow();
/// @dev The operation failed, due to an overflow.
error RPowOverflow();
/// @dev The mantissa is too big to fit.
error MantissaOverflow();
/// @dev The operation failed, due to an multiplication overflow.
error MulWadFailed();
/// @dev The operation failed, due to an multiplication overflow.
error SMulWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error DivWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error SDivWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error MulDivFailed();
/// @dev The division failed, as the denominator is zero.
error DivFailed();
/// @dev The full precision multiply-divide operation failed, either due
/// to the result being larger than 256 bits, or a division by a zero.
error FullMulDivFailed();
/// @dev The output is undefined, as the input is less-than-or-equal to zero.
error LnWadUndefined();
/// @dev The input outside the acceptable domain.
error OutOfDomain();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The scalar of ETH and most ERC20s.
uint256 internal constant WAD = 1e18;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* SIMPLIFIED FIXED POINT OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Equivalent to `(x * y) / WAD` rounded down.
function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
if mul(y, gt(x, div(not(0), y))) {
mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
revert(0x1c, 0x04)
}
z := div(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down.
function sMulWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
// Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`.
if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) {
mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`.
revert(0x1c, 0x04)
}
z := sdiv(z, WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded up.
function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
if mul(y, gt(x, div(not(0), y))) {
mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks.
function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down.
function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.
if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {
mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
revert(0x1c, 0x04)
}
z := div(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down.
function sDivWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, WAD)
// Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`.
if iszero(and(iszero(iszero(y)), eq(sdiv(z, WAD), x))) {
mstore(0x00, 0x5c43740d) // `SDivWadFailed()`.
revert(0x1c, 0x04)
}
z := sdiv(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded up.
function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`.
if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) {
mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks.
function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
}
}
/// @dev Equivalent to `x` to the power of `y`.
/// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`.
function powWad(int256 x, int256 y) internal pure returns (int256) {
// Using `ln(x)` means `x` must be greater than 0.
return expWad((lnWad(x) * y) / int256(WAD));
}
/// @dev Returns `exp(x)`, denominated in `WAD`.
/// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
function expWad(int256 x) internal pure returns (int256 r) {
unchecked {
// When the result is less than 0.5 we return zero.
// This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`.
if (x <= -41446531673892822313) return r;
/// @solidity memory-safe-assembly
assembly {
// When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as
// an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`.
if iszero(slt(x, 135305999368893231589)) {
mstore(0x00, 0xa37bfec9) // `ExpOverflow()`.
revert(0x1c, 0x04)
}
}
// `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96`
// for more intermediate precision and a binary basis. This base conversion
// is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.
x = (x << 78) / 5 ** 18;
// Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers
// of two such that exp(x) = exp(x') * 2**k, where k is an integer.
// Solving this gives k = round(x / log(2)) and x' = x - k * log(2).
int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96;
x = x - k * 54916777467707473351141471128;
// `k` is in the range `[-61, 195]`.
// Evaluate using a (6, 7)-term rational approximation.
// `p` is made monic, we'll multiply by a scale factor later.
int256 y = x + 1346386616545796478920950773328;
y = ((y * x) >> 96) + 57155421227552351082224309758442;
int256 p = y + x - 94201549194550492254356042504812;
p = ((p * y) >> 96) + 28719021644029726153956944680412240;
p = p * x + (4385272521454847904659076985693276 << 96);
// We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
int256 q = x - 2855989394907223263936484059900;
q = ((q * x) >> 96) + 50020603652535783019961831881945;
q = ((q * x) >> 96) - 533845033583426703283633433725380;
q = ((q * x) >> 96) + 3604857256930695427073651918091429;
q = ((q * x) >> 96) - 14423608567350463180887372962807573;
q = ((q * x) >> 96) + 26449188498355588339934803723976023;
/// @solidity memory-safe-assembly
assembly {
// Div in assembly because solidity adds a zero check despite the unchecked.
// The q polynomial won't have zeros in the domain as all its roots are complex.
// No scaling is necessary because p is already `2**96` too large.
r := sdiv(p, q)
}
// r should be in the range `(0.09, 0.25) * 2**96`.
// We now need to multiply r by:
// - The scale factor `s ≈ 6.031367120`.
// - The `2**k` factor from the range reduction.
// - The `1e18 / 2**96` factor for base conversion.
// We do this all at once, with an intermediate result in `2**213`
// basis, so the final right shift is always by a positive amount.
r = int256(
(uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k)
);
}
}
/// @dev Returns `ln(x)`, denominated in `WAD`.
/// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
function lnWad(int256 x) internal pure returns (int256 r) {
/// @solidity memory-safe-assembly
assembly {
// We want to convert `x` from `10**18` fixed point to `2**96` fixed point.
// We do this by multiplying by `2**96 / 10**18`. But since
// `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here
// and add `ln(2**96 / 10**18)` at the end.
// Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// We place the check here for more optimal stack operations.
if iszero(sgt(x, 0)) {
mstore(0x00, 0x1615e638) // `LnWadUndefined()`.
revert(0x1c, 0x04)
}
// forgefmt: disable-next-item
r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))
// Reduce range of x to (1, 2) * 2**96
// ln(2^k * x) = k * ln(2) + ln(x)
x := shr(159, shl(r, x))
// Evaluate using a (8, 8)-term rational approximation.
// `p` is made monic, we will multiply by a scale factor later.
// forgefmt: disable-next-item
let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.
sar(96, mul(add(43456485725739037958740375743393,
sar(96, mul(add(24828157081833163892658089445524,
sar(96, mul(add(3273285459638523848632254066296,
x), x))), x))), x)), 11111509109440967052023855526967)
p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)
p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)
p := sub(mul(p, x), shl(96, 795164235651350426258249787498))
// We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
// `q` is monic by convention.
let q := add(5573035233440673466300451813936, x)
q := add(71694874799317883764090561454958, sar(96, mul(x, q)))
q := add(283447036172924575727196451306956, sar(96, mul(x, q)))
q := add(401686690394027663651624208769553, sar(96, mul(x, q)))
q := add(204048457590392012362485061816622, sar(96, mul(x, q)))
q := add(31853899698501571402653359427138, sar(96, mul(x, q)))
q := add(909429971244387300277376558375, sar(96, mul(x, q)))
// `p / q` is in the range `(0, 0.125) * 2**96`.
// Finalization, we need to:
// - Multiply by the scale factor `s = 5.549…`.
// - Add `ln(2**96 / 10**18)`.
// - Add `k * ln(2)`.
// - Multiply by `10**18 / 2**96 = 5**18 >> 78`.
// The q polynomial is known not to have zeros in the domain.
// No scaling required because p is already `2**96` too large.
p := sdiv(p, q)
// Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.
p := mul(1677202110996718588342820967067443963516166, p)
// Add `ln(2) * k * 5**18 * 2**192`.
// forgefmt: disable-next-item
p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)
// Add `ln(2**96 / 10**18) * 5**18 * 2**192`.
p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p)
// Base conversion: mul `2**18 / 2**192`.
r := sar(174, p)
}
}
/// @dev Returns `W_0(x)`, denominated in `WAD`.
/// See: https://en.wikipedia.org/wiki/Lambert_W_function
/// a.k.a. Product log function. This is an approximation of the principal branch.
function lambertW0Wad(int256 x) internal pure returns (int256 w) {
// forgefmt: disable-next-item
unchecked {
if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`.
int256 wad = int256(WAD);
int256 p = x;
uint256 c; // Whether we need to avoid catastrophic cancellation.
uint256 i = 4; // Number of iterations.
if (w <= 0x1ffffffffffff) {
if (-0x4000000000000 <= w) {
i = 1; // Inputs near zero only take one step to converge.
} else if (w <= -0x3ffffffffffffff) {
i = 32; // Inputs near `-1/e` take very long to converge.
}
} else if (w >> 63 == 0) {
/// @solidity memory-safe-assembly
assembly {
// Inline log2 for more performance, since the range is small.
let v := shr(49, w)
let l := shl(3, lt(0xff, v))
l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)),
0x0706060506020504060203020504030106050205030304010505030400000000)), 49)
w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13))
c := gt(l, 60)
i := add(2, add(gt(l, 53), c))
}
} else {
int256 ll = lnWad(w = lnWad(w));
/// @solidity memory-safe-assembly
assembly {
// `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`.
w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll))
i := add(3, iszero(shr(68, x)))
c := iszero(shr(143, x))
}
if (c == 0) {
do { // If `x` is big, use Newton's so that intermediate values won't overflow.
int256 e = expWad(w);
/// @solidity memory-safe-assembly
assembly {
let t := mul(w, div(e, wad))
w := sub(w, sdiv(sub(t, x), div(add(e, t), wad)))
}
if (p <= w) break;
p = w;
} while (--i != 0);
/// @solidity memory-safe-assembly
assembly {
w := sub(w, sgt(w, 2))
}
return w;
}
}
do { // Otherwise, use Halley's for faster convergence.
int256 e = expWad(w);
/// @solidity memory-safe-assembly
assembly {
let t := add(w, wad)
let s := sub(mul(w, e), mul(x, wad))
w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t)))))
}
if (p <= w) break;
p = w;
} while (--i != c);
/// @solidity memory-safe-assembly
assembly {
w := sub(w, sgt(w, 2))
}
// For certain ranges of `x`, we'll use the quadratic-rate recursive formula of
// R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation.
if (c != 0) {
int256 t = w | 1;
/// @solidity memory-safe-assembly
assembly {
x := sdiv(mul(x, wad), t)
}
x = (t * (wad + lnWad(x)));
/// @solidity memory-safe-assembly
assembly {
w := sdiv(x, add(wad, t))
}
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* GENERAL NUMBER UTILITIES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Calculates `floor(x * y / d)` with full precision.
/// Throws if result overflows a uint256 or when `d` is zero.
/// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv
function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
for {} 1 {} {
// 512-bit multiply `[p1 p0] = x * y`.
// Compute the product mod `2**256` and mod `2**256 - 1`
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that `product = p1 * 2**256 + p0`.
// Least significant 256 bits of the product.
result := mul(x, y) // Temporarily use `result` as `p0` to save gas.
let mm := mulmod(x, y, not(0))
// Most significant 256 bits of the product.
let p1 := sub(mm, add(result, lt(mm, result)))
// Handle non-overflow cases, 256 by 256 division.
if iszero(p1) {
if iszero(d) {
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
result := div(result, d)
break
}
// Make sure the result is less than `2**256`. Also prevents `d == 0`.
if iszero(gt(d, p1)) {
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
/*------------------- 512 by 256 division --------------------*/
// Make division exact by subtracting the remainder from `[p1 p0]`.
// Compute remainder using mulmod.
let r := mulmod(x, y, d)
// `t` is the least significant bit of `d`.
// Always greater or equal to 1.
let t := and(d, sub(0, d))
// Divide `d` by `t`, which is a power of two.
d := div(d, t)
// Invert `d mod 2**256`
// Now that `d` is an odd number, it has an inverse
// modulo `2**256` such that `d * inv = 1 mod 2**256`.
// Compute the inverse by starting with a seed that is correct
// correct for four bits. That is, `d * inv = 1 mod 2**4`.
let inv := xor(2, mul(3, d))
// 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 := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128
result :=
mul(
// Divide [p1 p0] by the factors of two.
// Shift in bits from `p1` into `p0`. For this we need
// to flip `t` such that it is `2**256 / t`.
or(
mul(sub(p1, gt(r, result)), add(div(sub(0, t), t), 1)),
div(sub(result, r), t)
),
// inverse mod 2**256
mul(inv, sub(2, mul(d, inv)))
)
break
}
}
}
/// @dev Calculates `floor(x * y / d)` with full precision, rounded up.
/// Throws if result overflows a uint256 or when `d` is zero.
/// Credit to Uniswap-v3-core under MIT license:
/// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol
function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) {
result = fullMulDiv(x, y, d);
/// @solidity memory-safe-assembly
assembly {
if mulmod(x, y, d) {
result := add(result, 1)
if iszero(result) {
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
}
}
}
/// @dev Returns `floor(x * y / d)`.
/// Reverts if `x * y` overflows, or `d` is zero.
function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
mstore(0x00, 0xad251c27) // `MulDivFailed()`.
revert(0x1c, 0x04)
}
z := div(mul(x, y), d)
}
}
/// @dev Returns `ceil(x * y / d)`.
/// Reverts if `x * y` overflows, or `d` is zero.
function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
mstore(0x00, 0xad251c27) // `MulDivFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(mul(x, y), d))), div(mul(x, y), d))
}
}
/// @dev Returns `ceil(x / d)`.
/// Reverts if `d` is zero.
function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
if iszero(d) {
mstore(0x00, 0x65244e4e) // `DivFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(x, d))), div(x, d))
}
}
/// @dev Returns `max(0, x - y)`.
function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(gt(x, y), sub(x, y))
}
}
/// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`.
/// Reverts if the computation overflows.
function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`.
if x {
z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x`
let half := shr(1, b) // Divide `b` by 2.
// Divide `y` by 2 every iteration.
for { y := shr(1, y) } y { y := shr(1, y) } {
let xx := mul(x, x) // Store x squared.
let xxRound := add(xx, half) // Round to the nearest number.
// Revert if `xx + half` overflowed, or if `x ** 2` overflows.
if or(lt(xxRound, xx), shr(128, x)) {
mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
revert(0x1c, 0x04)
}
x := div(xxRound, b) // Set `x` to scaled `xxRound`.
// If `y` is odd:
if and(y, 1) {
let zx := mul(z, x) // Compute `z * x`.
let zxRound := add(zx, half) // Round to the nearest number.
// If `z * x` overflowed or `zx + half` overflowed:
if or(xor(div(zx, x), z), lt(zxRound, zx)) {
// Revert if `x` is non-zero.
if iszero(iszero(x)) {
mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
revert(0x1c, 0x04)
}
}
z := div(zxRound, b) // Return properly scaled `zxRound`.
}
}
}
}
}
/// @dev Returns the square root of `x`.
function sqrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.
z := 181 // The "correct" value is 1, but this saves a multiplication later.
// This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
// start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
// Let `y = x / 2**r`. We check `y >= 2**(k + 8)`
// but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`.
let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffffff, shr(r, x))))
z := shl(shr(1, r), z)
// Goal was to get `z*z*y` within a small factor of `x`. More iterations could
// get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.
// We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.
// That's not possible if `x < 256` but we can just verify those cases exhaustively.
// Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.
// Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.
// Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.
// For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`
// is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,
// with largest error when `s = 1` and when `s = 256` or `1/256`.
// Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.
// Then we can estimate `sqrt(y)` using
// `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.
// There is no overflow risk here since `y < 2**136` after the first branch above.
z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.
// Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
// If `x+1` is a perfect square, the Babylonian method cycles between
// `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.
// See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
z := sub(z, lt(div(x, z), z))
}
}
/// @dev Returns the cube root of `x`.
/// Credit to bout3fiddy and pcaversaccio under AGPLv3 license:
/// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy
function cbrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3)))
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := sub(z, lt(div(x, mul(z, z)), z))
}
}
/// @dev Returns the square root of `x`, denominated in `WAD`.
function sqrtWad(uint256 x) internal pure returns (uint256 z) {
unchecked {
z = 10 ** 9;
if (x <= type(uint256).max / 10 ** 36 - 1) {
x *= 10 ** 18;
z = 1;
}
z *= sqrt(x);
}
}
/// @dev Returns the cube root of `x`, denominated in `WAD`.
function cbrtWad(uint256 x) internal pure returns (uint256 z) {
unchecked {
z = 10 ** 12;
if (x <= (type(uint256).max / 10 ** 36) * 10 ** 18 - 1) {
if (x >= type(uint256).max / 10 ** 36) {
x *= 10 ** 18;
z = 10 ** 6;
} else {
x *= 10 ** 36;
z = 1;
}
}
z *= cbrt(x);
}
}
/// @dev Returns the factorial of `x`.
function factorial(uint256 x) internal pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
if iszero(lt(x, 58)) {
mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`.
revert(0x1c, 0x04)
}
for { result := 1 } x { x := sub(x, 1) } { result := mul(result, x) }
}
}
/// @dev Returns the log2 of `x`.
/// Equivalent to computing the index of the most significant bit (MSB) of `x`.
/// Returns 0 if `x` is zero.
function log2(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// forgefmt: disable-next-item
r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
0x0706060506020504060203020504030106050205030304010505030400000000))
}
}
/// @dev Returns the log2 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log2Up(uint256 x) internal pure returns (uint256 r) {
r = log2(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(shl(r, 1), x))
}
}
/// @dev Returns the log10 of `x`.
/// Returns 0 if `x` is zero.
function log10(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
if iszero(lt(x, 100000000000000000000000000000000000000)) {
x := div(x, 100000000000000000000000000000000000000)
r := 38
}
if iszero(lt(x, 100000000000000000000)) {
x := div(x, 100000000000000000000)
r := add(r, 20)
}
if iszero(lt(x, 10000000000)) {
x := div(x, 10000000000)
r := add(r, 10)
}
if iszero(lt(x, 100000)) {
x := div(x, 100000)
r := add(r, 5)
}
r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999)))))
}
}
/// @dev Returns the log10 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log10Up(uint256 x) internal pure returns (uint256 r) {
r = log10(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(exp(10, r), x))
}
}
/// @dev Returns the log256 of `x`.
/// Returns 0 if `x` is zero.
function log256(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(shr(3, r), lt(0xff, shr(r, x)))
}
}
/// @dev Returns the log256 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log256Up(uint256 x) internal pure returns (uint256 r) {
r = log256(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(shl(shl(3, r), 1), x))
}
}
/// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`.
/// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent).
function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) {
/// @solidity memory-safe-assembly
assembly {
mantissa := x
if mantissa {
if iszero(mod(mantissa, 1000000000000000000000000000000000)) {
mantissa := div(mantissa, 1000000000000000000000000000000000)
exponent := 33
}
if iszero(mod(mantissa, 10000000000000000000)) {
mantissa := div(mantissa, 10000000000000000000)
exponent := add(exponent, 19)
}
if iszero(mod(mantissa, 1000000000000)) {
mantissa := div(mantissa, 1000000000000)
exponent := add(exponent, 12)
}
if iszero(mod(mantissa, 1000000)) {
mantissa := div(mantissa, 1000000)
exponent := add(exponent, 6)
}
if iszero(mod(mantissa, 10000)) {
mantissa := div(mantissa, 10000)
exponent := add(exponent, 4)
}
if iszero(mod(mantissa, 100)) {
mantissa := div(mantissa, 100)
exponent := add(exponent, 2)
}
if iszero(mod(mantissa, 10)) {
mantissa := div(mantissa, 10)
exponent := add(exponent, 1)
}
}
}
}
/// @dev Convenience function for packing `x` into a smaller number using `sci`.
/// The `mantissa` will be in bits [7..255] (the upper 249 bits).
/// The `exponent` will be in bits [0..6] (the lower 7 bits).
/// Use `SafeCastLib` to safely ensure that the `packed` number is small
/// enough to fit in the desired unsigned integer type:
/// ```
/// uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether));
/// ```
function packSci(uint256 x) internal pure returns (uint256 packed) {
(x, packed) = sci(x); // Reuse for `mantissa` and `exponent`.
/// @solidity memory-safe-assembly
assembly {
if shr(249, x) {
mstore(0x00, 0xce30380c) // `MantissaOverflow()`.
revert(0x1c, 0x04)
}
packed := or(shl(7, x), packed)
}
}
/// @dev Convenience function for unpacking a packed number from `packSci`.
function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) {
unchecked {
unpacked = (packed >> 7) * 10 ** (packed & 0x7f);
}
}
/// @dev Returns the average of `x` and `y`.
function avg(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = (x & y) + ((x ^ y) >> 1);
}
}
/// @dev Returns the average of `x` and `y`.
function avg(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = (x >> 1) + (y >> 1) + (x & y & 1);
}
}
/// @dev Returns the absolute value of `x`.
function abs(int256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(sub(0, shr(255, x)), add(sub(0, shr(255, x)), x))
}
}
/// @dev Returns the absolute distance between `x` and `y`.
function dist(int256 x, int256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(mul(xor(sub(y, x), sub(x, y)), sgt(x, y)), sub(y, x))
}
}
/// @dev Returns the minimum of `x` and `y`.
function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), lt(y, x)))
}
}
/// @dev Returns the minimum of `x` and `y`.
function min(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), slt(y, x)))
}
}
/// @dev Returns the maximum of `x` and `y`.
function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), gt(y, x)))
}
}
/// @dev Returns the maximum of `x` and `y`.
function max(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), sgt(y, x)))
}
}
/// @dev Returns `x`, bounded to `minValue` and `maxValue`.
function clamp(uint256 x, uint256 minValue, uint256 maxValue)
internal
pure
returns (uint256 z)
{
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, minValue), gt(minValue, x)))
z := xor(z, mul(xor(z, maxValue), lt(maxValue, z)))
}
}
/// @dev Returns `x`, bounded to `minValue` and `maxValue`.
function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, minValue), sgt(minValue, x)))
z := xor(z, mul(xor(z, maxValue), slt(maxValue, z)))
}
}
/// @dev Returns greatest common divisor of `x` and `y`.
function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
for { z := x } y {} {
let t := y
y := mod(z, y)
z := t
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* RAW NUMBER OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns `x + y`, without checking for overflow.
function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x + y;
}
}
/// @dev Returns `x + y`, without checking for overflow.
function rawAdd(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x + y;
}
}
/// @dev Returns `x - y`, without checking for underflow.
function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x - y;
}
}
/// @dev Returns `x - y`, without checking for underflow.
function rawSub(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x - y;
}
}
/// @dev Returns `x * y`, without checking for overflow.
function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x * y;
}
}
/// @dev Returns `x * y`, without checking for overflow.
function rawMul(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x * y;
}
}
/// @dev Returns `x / y`, returning 0 if `y` is zero.
function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(x, y)
}
}
/// @dev Returns `x / y`, returning 0 if `y` is zero.
function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(x, y)
}
}
/// @dev Returns `x % y`, returning 0 if `y` is zero.
function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mod(x, y)
}
}
/// @dev Returns `x % y`, returning 0 if `y` is zero.
function rawSMod(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := smod(x, y)
}
}
/// @dev Returns `(x + y) % d`, return 0 if `d` if zero.
function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := addmod(x, y, d)
}
}
/// @dev Returns `(x * y) % d`, return 0 if `d` if zero.
function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mulmod(x, y, d)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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: GPL-3.0-or-later
pragma solidity ^0.8.0;
interface IRewardManager {
function userReward(address token, address user) external view returns (uint128 index, uint128 accrued);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
interface IPInterestManagerYT {
event CollectInterestFee(uint256 amountInterestFee);
function userInterest(address user) external view returns (uint128 lastPYIndex, uint128 accruedInterest);
}// SPDX-License-Identifier: GPL-3.0-or-later
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
// Software.
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
pragma solidity ^0.8.0;
/* solhint-disable */
/**
* @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).
*
* Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural
* exponentiation and logarithm (where the base is Euler's number).
*
* @author Fernando Martinelli - @fernandomartinelli
* @author Sergio Yuhjtman - @sergioyuhjtman
* @author Daniel Fernandez - @dmf7z
*/
library LogExpMath {
// All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying
// two numbers, and multiply by ONE when dividing them.
// All arguments and return values are 18 decimal fixed point numbers.
int256 constant ONE_18 = 1e18;
// Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the
// case of ln36, 36 decimals.
int256 constant ONE_20 = 1e20;
int256 constant ONE_36 = 1e36;
// The domain of natural exponentiation is bound by the word size and number of decimals used.
//
// Because internally the result will be stored using 20 decimals, the largest possible result is
// (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.
// The smallest possible result is 10^(-18), which makes largest negative argument
// ln(10^(-18)) = -41.446531673892822312.
// We use 130.0 and -41.0 to have some safety margin.
int256 constant MAX_NATURAL_EXPONENT = 130e18;
int256 constant MIN_NATURAL_EXPONENT = -41e18;
// Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point
// 256 bit integer.
int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;
int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;
uint256 constant MILD_EXPONENT_BOUND = 2 ** 254 / uint256(ONE_20);
// 18 decimal constants
int256 constant x0 = 128000000000000000000; // 2ˆ7
int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)
int256 constant x1 = 64000000000000000000; // 2ˆ6
int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals)
// 20 decimal constants
int256 constant x2 = 3200000000000000000000; // 2ˆ5
int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2)
int256 constant x3 = 1600000000000000000000; // 2ˆ4
int256 constant a3 = 888611052050787263676000000; // eˆ(x3)
int256 constant x4 = 800000000000000000000; // 2ˆ3
int256 constant a4 = 298095798704172827474000; // eˆ(x4)
int256 constant x5 = 400000000000000000000; // 2ˆ2
int256 constant a5 = 5459815003314423907810; // eˆ(x5)
int256 constant x6 = 200000000000000000000; // 2ˆ1
int256 constant a6 = 738905609893065022723; // eˆ(x6)
int256 constant x7 = 100000000000000000000; // 2ˆ0
int256 constant a7 = 271828182845904523536; // eˆ(x7)
int256 constant x8 = 50000000000000000000; // 2ˆ-1
int256 constant a8 = 164872127070012814685; // eˆ(x8)
int256 constant x9 = 25000000000000000000; // 2ˆ-2
int256 constant a9 = 128402541668774148407; // eˆ(x9)
int256 constant x10 = 12500000000000000000; // 2ˆ-3
int256 constant a10 = 113314845306682631683; // eˆ(x10)
int256 constant x11 = 6250000000000000000; // 2ˆ-4
int256 constant a11 = 106449445891785942956; // eˆ(x11)
/**
* @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.
*
* Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.
*/
function exp(int256 x) internal pure returns (int256) {
unchecked {
require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, "Invalid exponent");
if (x < 0) {
// We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it
// fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT).
// Fixed point division requires multiplying by ONE_18.
return ((ONE_18 * ONE_18) / exp(-x));
}
// First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,
// where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7
// because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the
// decomposition.
// At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this
// decomposition, which will be lower than the smallest x_n.
// exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.
// We mutate x by subtracting x_n, making it the remainder of the decomposition.
// The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause
// intermediate overflows. Instead we store them as plain integers, with 0 decimals.
// Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the
// decomposition.
// For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct
// it and compute the accumulated product.
int256 firstAN;
if (x >= x0) {
x -= x0;
firstAN = a0;
} else if (x >= x1) {
x -= x1;
firstAN = a1;
} else {
firstAN = 1; // One with no decimal places
}
// We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the
// smaller terms.
x *= 100;
// `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point
// one. Recall that fixed point multiplication requires dividing by ONE_20.
int256 product = ONE_20;
if (x >= x2) {
x -= x2;
product = (product * a2) / ONE_20;
}
if (x >= x3) {
x -= x3;
product = (product * a3) / ONE_20;
}
if (x >= x4) {
x -= x4;
product = (product * a4) / ONE_20;
}
if (x >= x5) {
x -= x5;
product = (product * a5) / ONE_20;
}
if (x >= x6) {
x -= x6;
product = (product * a6) / ONE_20;
}
if (x >= x7) {
x -= x7;
product = (product * a7) / ONE_20;
}
if (x >= x8) {
x -= x8;
product = (product * a8) / ONE_20;
}
if (x >= x9) {
x -= x9;
product = (product * a9) / ONE_20;
}
// x10 and x11 are unnecessary here since we have high enough precision already.
// Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series
// expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).
int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places.
int256 term; // Each term in the sum, where the nth term is (x^n / n!).
// The first term is simply x.
term = x;
seriesSum += term;
// Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,
// multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.
term = ((term * x) / ONE_20) / 2;
seriesSum += term;
term = ((term * x) / ONE_20) / 3;
seriesSum += term;
term = ((term * x) / ONE_20) / 4;
seriesSum += term;
term = ((term * x) / ONE_20) / 5;
seriesSum += term;
term = ((term * x) / ONE_20) / 6;
seriesSum += term;
term = ((term * x) / ONE_20) / 7;
seriesSum += term;
term = ((term * x) / ONE_20) / 8;
seriesSum += term;
term = ((term * x) / ONE_20) / 9;
seriesSum += term;
term = ((term * x) / ONE_20) / 10;
seriesSum += term;
term = ((term * x) / ONE_20) / 11;
seriesSum += term;
term = ((term * x) / ONE_20) / 12;
seriesSum += term;
// 12 Taylor terms are sufficient for 18 decimal precision.
// We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor
// approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply
// all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),
// and then drop two digits to return an 18 decimal value.
return (((product * seriesSum) / ONE_20) * firstAN) / 100;
}
}
/**
* @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
*/
function ln(int256 a) internal pure returns (int256) {
unchecked {
// The real natural logarithm is not defined for negative numbers or zero.
require(a > 0, "out of bounds");
if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) {
return _ln_36(a) / ONE_18;
} else {
return _ln(a);
}
}
}
/**
* @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.
*
* Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.
*/
function pow(uint256 x, uint256 y) internal pure returns (uint256) {
unchecked {
if (y == 0) {
// We solve the 0^0 indetermination by making it equal one.
return uint256(ONE_18);
}
if (x == 0) {
return 0;
}
// Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to
// arrive at that r`esult. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means
// x^y = exp(y * ln(x)).
// The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.
require(x < 2 ** 255, "x out of bounds");
int256 x_int256 = int256(x);
// We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In
// both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.
// This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.
require(y < MILD_EXPONENT_BOUND, "y out of bounds");
int256 y_int256 = int256(y);
int256 logx_times_y;
if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {
int256 ln_36_x = _ln_36(x_int256);
// ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just
// bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal
// multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the
// (downscaled) last 18 decimals.
logx_times_y = ((ln_36_x / ONE_18) * y_int256 + ((ln_36_x % ONE_18) * y_int256) / ONE_18);
} else {
logx_times_y = _ln(x_int256) * y_int256;
}
logx_times_y /= ONE_18;
// Finally, we compute exp(y * ln(x)) to arrive at x^y
require(
MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,
"product out of bounds"
);
return uint256(exp(logx_times_y));
}
}
/**
* @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
*/
function _ln(int256 a) private pure returns (int256) {
unchecked {
if (a < ONE_18) {
// Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less
// than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call.
// Fixed point division requires multiplying by ONE_18.
return (-_ln((ONE_18 * ONE_18) / a));
}
// First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which
// we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,
// ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot
// be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.
// At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this
// decomposition, which will be lower than the smallest a_n.
// ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.
// We mutate a by subtracting a_n, making it the remainder of the decomposition.
// For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point
// numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by
// ONE_18 to convert them to fixed point.
// For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide
// by it and compute the accumulated sum.
int256 sum = 0;
if (a >= a0 * ONE_18) {
a /= a0; // Integer, not fixed point division
sum += x0;
}
if (a >= a1 * ONE_18) {
a /= a1; // Integer, not fixed point division
sum += x1;
}
// All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.
sum *= 100;
a *= 100;
// Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.
if (a >= a2) {
a = (a * ONE_20) / a2;
sum += x2;
}
if (a >= a3) {
a = (a * ONE_20) / a3;
sum += x3;
}
if (a >= a4) {
a = (a * ONE_20) / a4;
sum += x4;
}
if (a >= a5) {
a = (a * ONE_20) / a5;
sum += x5;
}
if (a >= a6) {
a = (a * ONE_20) / a6;
sum += x6;
}
if (a >= a7) {
a = (a * ONE_20) / a7;
sum += x7;
}
if (a >= a8) {
a = (a * ONE_20) / a8;
sum += x8;
}
if (a >= a9) {
a = (a * ONE_20) / a9;
sum += x9;
}
if (a >= a10) {
a = (a * ONE_20) / a10;
sum += x10;
}
if (a >= a11) {
a = (a * ONE_20) / a11;
sum += x11;
}
// a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series
// that converges rapidly for values of `a` close to one - the same one used in ln_36.
// Let z = (a - 1) / (a + 1).
// ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))
// Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires
// division by ONE_20.
int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20);
int256 z_squared = (z * z) / ONE_20;
// num is the numerator of the series: the z^(2 * n + 1) term
int256 num = z;
// seriesSum holds the accumulated sum of each term in the series, starting with the initial z
int256 seriesSum = num;
// In each step, the numerator is multiplied by z^2
num = (num * z_squared) / ONE_20;
seriesSum += num / 3;
num = (num * z_squared) / ONE_20;
seriesSum += num / 5;
num = (num * z_squared) / ONE_20;
seriesSum += num / 7;
num = (num * z_squared) / ONE_20;
seriesSum += num / 9;
num = (num * z_squared) / ONE_20;
seriesSum += num / 11;
// 6 Taylor terms are sufficient for 36 decimal precision.
// Finally, we multiply by 2 (non fixed point) to compute ln(remainder)
seriesSum *= 2;
// We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both
// with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal
// value.
return (sum + seriesSum) / 100;
}
}
/**
* @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,
* for x close to one.
*
* Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.
*/
function _ln_36(int256 x) private pure returns (int256) {
unchecked {
// Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits
// worthwhile.
// First, we transform x to a 36 digit fixed point value.
x *= ONE_18;
// We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).
// ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))
// Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires
// division by ONE_36.
int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36);
int256 z_squared = (z * z) / ONE_36;
// num is the numerator of the series: the z^(2 * n + 1) term
int256 num = z;
// seriesSum holds the accumulated sum of each term in the series, starting with the initial z
int256 seriesSum = num;
// In each step, the numerator is multiplied by z^2
num = (num * z_squared) / ONE_36;
seriesSum += num / 3;
num = (num * z_squared) / ONE_36;
seriesSum += num / 5;
num = (num * z_squared) / ONE_36;
seriesSum += num / 7;
num = (num * z_squared) / ONE_36;
seriesSum += num / 9;
num = (num * z_squared) / ONE_36;
seriesSum += num / 11;
num = (num * z_squared) / ONE_36;
seriesSum += num / 13;
num = (num * z_squared) / ONE_36;
seriesSum += num / 15;
// 8 Taylor terms are sufficient for 36 decimal precision.
// All that remains is multiplying by 2 (non fixed point).
return seriesSum * 2;
}
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
import "../../interfaces/IPYieldToken.sol";
import "../../interfaces/IPPrincipalToken.sol";
import "./SYUtils.sol";
import "../libraries/math/PMath.sol";
type PYIndex is uint256;
library PYIndexLib {
using PMath for uint256;
using PMath for int256;
function newIndex(IPYieldToken YT) internal returns (PYIndex) {
return PYIndex.wrap(YT.pyIndexCurrent());
}
function syToAsset(PYIndex index, uint256 syAmount) internal pure returns (uint256) {
return SYUtils.syToAsset(PYIndex.unwrap(index), syAmount);
}
function assetToSy(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {
return SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount);
}
function assetToSyUp(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {
return SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount);
}
function syToAssetUp(PYIndex index, uint256 syAmount) internal pure returns (uint256) {
uint256 _index = PYIndex.unwrap(index);
return SYUtils.syToAssetUp(_index, syAmount);
}
function syToAsset(PYIndex index, int256 syAmount) internal pure returns (int256) {
int256 sign = syAmount < 0 ? int256(-1) : int256(1);
return sign * (SYUtils.syToAsset(PYIndex.unwrap(index), syAmount.abs())).Int();
}
function assetToSy(PYIndex index, int256 assetAmount) internal pure returns (int256) {
int256 sign = assetAmount < 0 ? int256(-1) : int256(1);
return sign * (SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount.abs())).Int();
}
function assetToSyUp(PYIndex index, int256 assetAmount) internal pure returns (int256) {
int256 sign = assetAmount < 0 ? int256(-1) : int256(1);
return sign * (SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount.abs())).Int();
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
library MiniHelpers {
function isCurrentlyExpired(uint256 expiry) internal view returns (bool) {
return (expiry <= block.timestamp);
}
function isExpired(uint256 expiry, uint256 blockTime) internal pure returns (bool) {
return (expiry <= blockTime);
}
function isTimeInThePast(uint256 timestamp) internal view returns (bool) {
return (timestamp <= block.timestamp); // same definition as isCurrentlyExpired
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
library Errors {
// BulkSeller
error BulkInsufficientSyForTrade(uint256 currentAmount, uint256 requiredAmount);
error BulkInsufficientTokenForTrade(uint256 currentAmount, uint256 requiredAmount);
error BulkInSufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);
error BulkInSufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
error BulkInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);
error BulkNotMaintainer();
error BulkNotAdmin();
error BulkSellerAlreadyExisted(address token, address SY, address bulk);
error BulkSellerInvalidToken(address token, address SY);
error BulkBadRateTokenToSy(uint256 actualRate, uint256 currentRate, uint256 eps);
error BulkBadRateSyToToken(uint256 actualRate, uint256 currentRate, uint256 eps);
// APPROX
error ApproxFail();
error ApproxParamsInvalid(uint256 guessMin, uint256 guessMax, uint256 eps);
error ApproxBinarySearchInputInvalid(
uint256 approxGuessMin,
uint256 approxGuessMax,
uint256 minGuessMin,
uint256 maxGuessMax
);
// MARKET + MARKET MATH CORE
error MarketExpired();
error MarketZeroAmountsInput();
error MarketZeroAmountsOutput();
error MarketZeroLnImpliedRate();
error MarketInsufficientPtForTrade(int256 currentAmount, int256 requiredAmount);
error MarketInsufficientPtReceived(uint256 actualBalance, uint256 requiredBalance);
error MarketInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);
error MarketZeroTotalPtOrTotalAsset(int256 totalPt, int256 totalAsset);
error MarketExchangeRateBelowOne(int256 exchangeRate);
error MarketProportionMustNotEqualOne();
error MarketRateScalarBelowZero(int256 rateScalar);
error MarketScalarRootBelowZero(int256 scalarRoot);
error MarketProportionTooHigh(int256 proportion, int256 maxProportion);
error OracleUninitialized();
error OracleTargetTooOld(uint32 target, uint32 oldest);
error OracleZeroCardinality();
error MarketFactoryExpiredPt();
error MarketFactoryInvalidPt();
error MarketFactoryMarketExists();
error MarketFactoryLnFeeRateRootTooHigh(uint80 lnFeeRateRoot, uint256 maxLnFeeRateRoot);
error MarketFactoryOverriddenFeeTooHigh(uint80 overriddenFee, uint256 marketLnFeeRateRoot);
error MarketFactoryReserveFeePercentTooHigh(uint8 reserveFeePercent, uint8 maxReserveFeePercent);
error MarketFactoryZeroTreasury();
error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor);
error MFNotPendleMarket(address addr);
// ROUTER
error RouterInsufficientLpOut(uint256 actualLpOut, uint256 requiredLpOut);
error RouterInsufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);
error RouterInsufficientPtOut(uint256 actualPtOut, uint256 requiredPtOut);
error RouterInsufficientYtOut(uint256 actualYtOut, uint256 requiredYtOut);
error RouterInsufficientPYOut(uint256 actualPYOut, uint256 requiredPYOut);
error RouterInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
error RouterInsufficientSyRepay(uint256 actualSyRepay, uint256 requiredSyRepay);
error RouterInsufficientPtRepay(uint256 actualPtRepay, uint256 requiredPtRepay);
error RouterNotAllSyUsed(uint256 netSyDesired, uint256 netSyUsed);
error RouterTimeRangeZero();
error RouterCallbackNotPendleMarket(address caller);
error RouterInvalidAction(bytes4 selector);
error RouterInvalidFacet(address facet);
error RouterKyberSwapDataZero();
error SimulationResults(bool success, bytes res);
// YIELD CONTRACT
error YCExpired();
error YCNotExpired();
error YieldContractInsufficientSy(uint256 actualSy, uint256 requiredSy);
error YCNothingToRedeem();
error YCPostExpiryDataNotSet();
error YCNoFloatingSy();
// YieldFactory
error YCFactoryInvalidExpiry();
error YCFactoryYieldContractExisted();
error YCFactoryZeroExpiryDivisor();
error YCFactoryZeroTreasury();
error YCFactoryInterestFeeRateTooHigh(uint256 interestFeeRate, uint256 maxInterestFeeRate);
error YCFactoryRewardFeeRateTooHigh(uint256 newRewardFeeRate, uint256 maxRewardFeeRate);
// SY
error SYInvalidTokenIn(address token);
error SYInvalidTokenOut(address token);
error SYZeroDeposit();
error SYZeroRedeem();
error SYInsufficientSharesOut(uint256 actualSharesOut, uint256 requiredSharesOut);
error SYInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);
// SY-specific
error SYQiTokenMintFailed(uint256 errCode);
error SYQiTokenRedeemFailed(uint256 errCode);
error SYQiTokenRedeemRewardsFailed(uint256 rewardAccruedType0, uint256 rewardAccruedType1);
error SYQiTokenBorrowRateTooHigh(uint256 borrowRate, uint256 borrowRateMax);
error SYCurveInvalidPid();
error SYCurve3crvPoolNotFound();
error SYApeDepositAmountTooSmall(uint256 amountDeposited);
error SYBalancerInvalidPid();
error SYInvalidRewardToken(address token);
error SYStargateRedeemCapExceeded(uint256 amountLpDesired, uint256 amountLpRedeemable);
error SYBalancerReentrancy();
error NotFromTrustedRemote(uint16 srcChainId, bytes path);
error ApxETHNotEnoughBuffer();
// Liquidity Mining
error VCInactivePool(address pool);
error VCPoolAlreadyActive(address pool);
error VCZeroVePendle(address user);
error VCExceededMaxWeight(uint256 totalWeight, uint256 maxWeight);
error VCEpochNotFinalized(uint256 wTime);
error VCPoolAlreadyAddAndRemoved(address pool);
error VEInvalidNewExpiry(uint256 newExpiry);
error VEExceededMaxLockTime();
error VEInsufficientLockTime();
error VENotAllowedReduceExpiry();
error VEZeroAmountLocked();
error VEPositionNotExpired();
error VEZeroPosition();
error VEZeroSlope(uint128 bias, uint128 slope);
error VEReceiveOldSupply(uint256 msgTime);
error GCNotPendleMarket(address caller);
error GCNotVotingController(address caller);
error InvalidWTime(uint256 wTime);
error ExpiryInThePast(uint256 expiry);
error ChainNotSupported(uint256 chainId);
error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount);
error FDEpochLengthMismatch();
error FDInvalidPool(address pool);
error FDPoolAlreadyExists(address pool);
error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch);
error FDInvalidStartEpoch(uint256 startEpoch);
error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime);
error FDFutureFunding(uint256 lastFunded, uint256 currentWTime);
error BDInvalidEpoch(uint256 epoch, uint256 startTime);
// Cross-Chain
error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path);
error MsgNotFromReceiveEndpoint(address sender);
error InsufficientFeeToSendMsg(uint256 currentFee, uint256 requiredFee);
error ApproxDstExecutionGasNotSet();
error InvalidRetryData();
// GENERIC MSG
error ArrayLengthMismatch();
error ArrayEmpty();
error ArrayOutOfBounds();
error ZeroAddress();
error FailedToSendEther();
error InvalidMerkleProof();
error OnlyLayerZeroEndpoint();
error OnlyYT();
error OnlyYCFactory();
error OnlyWhitelisted();
// Swap Aggregator
error SAInsufficientTokenIn(address tokenIn, uint256 amountExpected, uint256 amountActual);
error UnsupportedSelector(uint256 aggregatorType, bytes4 selector);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
library SYUtils {
uint256 internal constant ONE = 1e18;
function syToAsset(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {
return (syAmount * exchangeRate) / ONE;
}
function syToAssetUp(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {
return (syAmount * exchangeRate + ONE - 1) / ONE;
}
function assetToSy(uint256 exchangeRate, uint256 assetAmount) internal pure returns (uint256) {
return (assetAmount * ONE) / exchangeRate;
}
function assetToSyUp(uint256 exchangeRate, uint256 assetAmount) internal pure returns (uint256) {
return (assetAmount * ONE + exchangeRate - 1) / exchangeRate;
}
}{
"remappings": [
"lib/euler-price-oracle:@openzeppelin/contracts/=lib/euler-price-oracle/lib/openzeppelin-contracts/contracts/",
"lib/euler-earn:@openzeppelin/=lib/euler-earn/lib/openzeppelin-contracts/",
"lib/euler-earn:@openzeppelin-upgradeable/=lib/euler-earn/lib/openzeppelin-contracts-upgradeable/contracts/",
"lib/euler-earn:ethereum-vault-connector/=lib/euler-earn/lib/ethereum-vault-connector/src/",
"lib/layerzero-devtools/packages/oft-evm/contracts:@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts/contracts/",
"lib/layerzero-devtools/packages/oft-evm-upgradeable/contracts:@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"lib/layerzero-devtools/packages/oapp-evm-upgradeable/contracts:@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@layerzerolabs/oft-evm/=lib/layerzero-devtools/packages/oft-evm/",
"@layerzerolabs/oapp-evm/=lib/layerzero-devtools/packages/oapp-evm/",
"@layerzerolabs/oapp-evm-upgradeable/=lib/layerzero-devtools/packages/oapp-evm-upgradeable/",
"@layerzerolabs/lz-evm-protocol-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/protocol/",
"@layerzerolabs/lz-evm-messagelib-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/messagelib/",
"@layerzerolabs/lz-evm-oapp-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/oapp/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"ethereum-vault-connector/=lib/ethereum-vault-connector/src/",
"evc/=lib/ethereum-vault-connector/src/",
"evk/=lib/euler-vault-kit/src/",
"evk-test/=lib/euler-vault-kit/test/",
"euler-price-oracle/=lib/euler-price-oracle/src/",
"euler-price-oracle-test/=lib/euler-price-oracle/test/",
"fee-flow/=lib/fee-flow/src/",
"reward-streams/=lib/reward-streams/src/",
"@openzeppelin/=lib/openzeppelin-contracts/contracts/",
"euler-earn/=lib/euler-earn/src/",
"layerzero/oft-evm/=lib/layerzero-devtools/packages/oft-evm/contracts/",
"layerzero/oft-evm-upgradeable/=lib/layerzero-devtools/packages/oft-evm-upgradeable/contracts/",
"solidity-bytes-utils/=lib/solidity-bytes-utils/",
"@axiom-crypto/v2-periphery/=lib/euler-price-oracle/lib/axiom-std/lib/axiom-v2-periphery/src/",
"@openzeppelin-upgradeable/=lib/euler-earn/lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@pendle/core-v2/=lib/euler-price-oracle/lib/pendle-core-v2-public/contracts/",
"@pyth/=lib/euler-price-oracle/lib/pyth-sdk-solidity/",
"@redstone/evm-connector/=lib/euler-price-oracle/lib/redstone-oracles-monorepo/packages/evm-connector/contracts/",
"@solady/=lib/euler-price-oracle/lib/solady/src/",
"@uniswap/v3-core/=lib/euler-price-oracle/lib/v3-core/",
"@uniswap/v3-periphery/=lib/euler-price-oracle/lib/v3-periphery/",
"ERC4626/=lib/euler-earn/lib/properties/lib/ERC4626/contracts/",
"axiom-std/=lib/euler-price-oracle/lib/axiom-std/src/",
"axiom-v2-periphery/=lib/euler-price-oracle/lib/axiom-v2-periphery/src/",
"crytic-properties/=lib/euler-earn/lib/properties/contracts/",
"ds-test/=lib/ethereum-vault-connector/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"euler-vault-kit/=lib/euler-vault-kit/",
"forge-gas-snapshot/=lib/euler-vault-kit/lib/permit2/lib/forge-gas-snapshot/src/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"layerzero-devtools/=lib/layerzero-devtools/packages/toolbox-foundry/src/",
"layerzero-v2/=lib/layerzero-v2/",
"morpho-blue-irm/=lib/morpho-blue-irm/src/",
"morpho-blue/=lib/morpho-blue-irm/lib/morpho-blue/",
"native-token-transfers/=lib/native-token-transfers/",
"openzeppelin/=lib/ethereum-vault-connector/lib/openzeppelin-contracts/contracts/",
"pendle-core-v2-public/=lib/euler-price-oracle/lib/pendle-core-v2-public/contracts/",
"permit2/=lib/euler-vault-kit/lib/permit2/",
"properties/=lib/euler-earn/lib/properties/contracts/",
"pyth-sdk-solidity/=lib/euler-price-oracle/lib/pyth-sdk-solidity/",
"redstone-oracles-monorepo/=lib/euler-price-oracle/lib/",
"solady/=lib/euler-price-oracle/lib/solady/src/",
"solmate/=lib/fee-flow/lib/solmate/src/",
"v3-core/=lib/euler-price-oracle/lib/v3-core/contracts/",
"v3-periphery/=lib/euler-price-oracle/lib/v3-periphery/contracts/",
"wormhole-solidity-sdk/=lib/native-token-transfers/evm/lib/wormhole-solidity-sdk/src/"
],
"optimizer": {
"enabled": true,
"runs": 20000
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": false,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_pendleOracle","type":"address"},{"internalType":"address","name":"_pendleMarket","type":"address"},{"internalType":"address","name":"_base","type":"address"},{"internalType":"address","name":"_quote","type":"address"},{"internalType":"uint32","name":"_twapWindow","type":"uint32"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"int256","name":"exchangeRate","type":"int256"}],"name":"MarketExchangeRateBelowOne","type":"error"},{"inputs":[],"name":"MarketExpired","type":"error"},{"inputs":[],"name":"MarketProportionMustNotEqualOne","type":"error"},{"inputs":[{"internalType":"int256","name":"rateScalar","type":"int256"}],"name":"MarketRateScalarBelowZero","type":"error"},{"inputs":[{"internalType":"int256","name":"totalPt","type":"int256"},{"internalType":"int256","name":"totalAsset","type":"int256"}],"name":"MarketZeroTotalPtOrTotalAsset","type":"error"},{"inputs":[],"name":"PriceOracle_InvalidConfiguration","type":"error"},{"inputs":[{"internalType":"address","name":"base","type":"address"},{"internalType":"address","name":"quote","type":"address"}],"name":"PriceOracle_NotSupported","type":"error"},{"inputs":[],"name":"PriceOracle_Overflow","type":"error"},{"inputs":[],"name":"base","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"inAmount","type":"uint256"},{"internalType":"address","name":"base","type":"address"},{"internalType":"address","name":"quote","type":"address"}],"name":"getQuote","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"inAmount","type":"uint256"},{"internalType":"address","name":"base","type":"address"},{"internalType":"address","name":"quote","type":"address"}],"name":"getQuotes","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendleMarket","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"quote","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"twapWindow","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"}]Contract Creation Code
0x61014060405234801562000011575f80fd5b506040516200433e3803806200433e83398101604081905262000034916200199d565b61012c63ffffffff82161080620000525750610e1063ffffffff8216115b1562000071576040516301a4c16560e21b815260040160405180910390fd5b60405162439f4b60e91b81526001600160a01b03858116600483015263ffffffff831660248301525f91829188169063873e960090604401606060405180830381865afa158015620000c5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620000eb919062001a30565b92505091508180620000fb575080155b156200011a576040516301a4c16560e21b815260040160405180910390fd5b5f80876001600160a01b0316632c8ce6bc6040518163ffffffff1660e01b8152600401606060405180830381865afa15801562000159573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200017f919062001a7e565b5091509150806001600160a01b0316876001600160a01b031603620001f657816001600160a01b0316866001600160a01b031603620001d7576001600160401b036200021b620002f060201b17166101005262000281565b6001600160401b03620002666200034660201b17166101005262000281565b876001600160a01b0316876001600160a01b0316036200026857816001600160a01b0316866001600160a01b03160362000249576001600160401b03620002a76200039260201b17166101005262000281565b6001600160401b0362000300620003e960201b17166101005262000281565b6040516301a4c16560e21b815260040160405180910390fd5b6001600160a01b0380891660805287811660c081905290871660e05263ffffffff861660a0525f90620002b49062000441565b90505f620002ca60e0516200044160201b60201c565b9050620002da8282601262000521565b61012052506200203b9950505050505050505050565b5f8080620002fe8562000539565b915091508082106200032c5762000322826200031b878762000770565b906200084f565b9250505062000340565b62000322816200031b878762000770565b50505b92915050565b5f8080620003548562000539565b915091508082106200036c5762000322858562000770565b80826200037a878762000770565b62000386919062001ae3565b62000322919062001b11565b5f8080620003a96001600160a01b03861662000539565b90925090505f620003bc86868462000882565b9050818310620003dd57620003d281846200084f565b935050505062000340565b620003d281836200084f565b5f8080620004006001600160a01b03861662000539565b90925090505f6200041386868462000882565b90508183106200042857925062000340915050565b8162000435848362001ae3565b620003d2919062001b11565b5f63ffffffff826001600160a01b0316116200045f57506012919050565b60408051600481526024810182526020810180516001600160e01b031663313ce56760e01b17905290515f9182916001600160a01b03861691620004a39162001b27565b5f60405180830381855afa9150503d805f8114620004dd576040519150601f19603f3d011682016040523d82523d5f602084013e620004e2565b606091505b5091509150818015620004f6575080516020145b6200050357601262000519565b8080602001905181019062000519919062001b55565b949350505050565b5f620005198362000533868562001b77565b62000a31565b5f805f80846001600160a01b0316632c8ce6bc6040518163ffffffff1660e01b8152600401606060405180830381865afa1580156200057a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620005a0919062001a7e565b9250509150816001600160a01b0316633ba0b9a96040518163ffffffff1660e01b8152600401602060405180830381865afa158015620005e2573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000608919062001b93565b93505f816001600160a01b031663d2a3584e6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000648573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200066e919062001b93565b9050816001600160a01b031663516399df6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620006ad573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620006d3919062001bab565b80156200074a575043826001600160a01b03166360e0a9e16040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000719573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200073f919062001bc7565b6001600160801b0316145b15620007595780935062000768565b62000765858262000a8d565b93505b505050915091565b5f80836001600160a01b031663e184c9be6040518163ffffffff1660e01b8152600401602060405180830381865afa158015620007af573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620007d5919062001b93565b9050428111620007f157670de0b6b3a764000091505062000340565b5f620007fe858562000aa6565b90505f6200080d428462001bef565b90505f6200082662000820848462000bd7565b62000c13565b90506200083c670de0b6b3a7640000826200084f565b94505050505062000340565b5092915050565b5f8062000865670de0b6b3a76400008562001ae3565b905082818162000879576200087962001afd565b04949350505050565b60405163794052f360e01b81525f600482018190529081906001600160a01b0386169063794052f39060240161012060405180830381865afa158015620008cb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620008f1919062001c78565b90505f428260a00151116200092c576200091684836020015162000c2560201b60201c565b825162000924919062001cfd565b905062000a10565b5f6200093a83864262000c68565b90505f806200094b89868a62000d75565b915091505f62000979620009738560400151856200096a919062001d1f565b86519062000df3565b62000e17565b90505f620009c76200098c838562001241565b620009a090670de0b6b3a764000062001cfd565b88516020880151620009b490869062000df3565b620009c0919062001d1f565b9062001241565b9050620009df8482895f0151620009c0919062001cfd565b620009eb828562001241565b8660200151620009fc919062001d1f565b62000a08919062001cfd565b955050505050505b604082015162000a27906200082090839062001241565b9695505050505050565b5f60268360ff16118062000a48575060268260ff16115b1562000a67576040516302950f9560e51b815260040160405180910390fd5b62000a7483600a62001e3a565b608062000a8384600a62001e3a565b901b179392505050565b5f81831162000a9d578162000a9f565b825b9392505050565b6040805160028082526060820183525f928392919060208301908036833701905050905082815f8151811062000ae05762000ae062001e4a565b63ffffffff9092166020928302919091019091015260405163883bdbfd60e01b81525f906001600160a01b0386169063883bdbfd9062000b2590859060040162001e5e565b5f60405180830381865afa15801562000b40573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405262000b69919081019062001ea9565b90508363ffffffff16815f8151811062000b875762000b8762001e4a565b60200260200101518260018151811062000ba55762000ba562001e4a565b602002602001015162000bb9919062001f6c565b62000bc5919062001f8f565b6001600160d81b031695945050505050565b5f8062000bea6201518061016d62001ae3565b62000bf6848662001ae3565b62000c02919062001b11565b90506200051962000973826200126b565b5f8082121562000c21575f80fd5b5090565b5f805f831262000c3757600162000c3a565b5f195b905062000c5c62000c568562000c508662001280565b62001294565b6200126b565b62000519908262001fb7565b62000c9060405180608001604052805f81526020015f81526020015f81526020015f81525090565b60a0840151821062000cb55760405163b2094b5960e01b815260040160405180910390fd5b5f828560a0015162000cc8919062001bef565b905062000cd68582620012b6565b8252602085015162000cea90859062000c25565b60208301528451158062000d0057506020820151155b1562000d34578451602083015160405163b1c4aefb60e01b8152600481019290925260248201526044015b60405180910390fd5b84516101008601516020840151845162000d5293929190856200131b565b604083015260c085015162000d68908262000bd7565b6060830152509392505050565b5f808062000d8d6001600160a01b0387168562000aa6565b90505f428660a0015162000da2919062001bef565b905062000db0828262000bd7565b93505f62000dca8761010001518362000bd760201b60201c565b9050600262000dda868362001cfd565b62000de6919062001fec565b9350505050935093915050565b5f8062000e01838562001fb7565b9050670de0b6b3a7640000815b05949350505050565b5f680238fd42c5cf03ffff19821215801562000e3c575068070c1cc73b00c800008213155b62000e7d5760405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a5908195e1c1bdb995b9d60821b604482015260640162000d2b565b5f82121562000ebb5762000e945f83900362000e17565b6ec097ce7bc90715b34b9f10000000008162000eb45762000eb462001afd565b0592915050565b5f6806f05b59d3b2000000831262000efc57506806f05b59d3b1ffffff1990910190770195e54c5dd42177f53a27172fa9ec63026282700000000062000f34565b6803782dace9d9000000831262000f3057506803782dace9d8ffffff19909101906b1425982cf597cd205cef738062000f34565b5060015b6064929092029168056bc75e2d6310000068ad78ebc5ac62000000841262000f855768ad78ebc5ac61ffffff199093019268056bc75e2d631000006e01855144814a7ff805980ff008400082020590505b6856bc75e2d631000000841262000fc2576856bc75e2d630ffffff199093019268056bc75e2d631000006b02df0ab5a80a22c61ab5a70082020590505b682b5e3af16b18800000841262000ffd57682b5e3af16b187fffff199093019268056bc75e2d63100000693f1fce3da636ea5cf85082020590505b6815af1d78b58c400000841262001038576815af1d78b58c3fffff199093019268056bc75e2d63100000690127fa27722cc06cc5e282020590505b680ad78ebc5ac620000084126200107257680ad78ebc5ac61fffff199093019268056bc75e2d6310000068280e60114edb805d0382020590505b68056bc75e2d631000008412620010ac5768056bc75e2d630fffff199093019268056bc75e2d63100000680ebc5fb4174612111082020590505b6802b5e3af16b18800008412620010e6576802b5e3af16b187ffff199093019268056bc75e2d631000006808f00f760a4b2db55d82020590505b68015af1d78b58c400008412620011205768015af1d78b58c3ffff199093019268056bc75e2d631000006806f5f177578893793782020590505b68056bc75e2d631000008481019085906002908280020505918201919050600368056bc75e2d631000008783020505918201919050600468056bc75e2d631000008783020505918201919050600568056bc75e2d631000008783020505918201919050600668056bc75e2d631000008783020505918201919050600768056bc75e2d631000008783020505918201919050600868056bc75e2d631000008783020505918201919050600968056bc75e2d631000008783020505918201919050600a68056bc75e2d631000008783020505918201919050600b68056bc75e2d631000008783020505918201919050600c68056bc75e2d631000008783020505918201919050606468056bc75e2d63100000848402058502059695505050505050565b5f8062001257670de0b6b3a76400008562001fb7565b905082818162000e0e5762000e0e62001afd565b5f6001600160ff1b0382111562000c21575f80fd5b5f80821362000c215762000340826200201e565b5f670de0b6b3a7640000620012aa848462001ae3565b62000a9f919062001b11565b5f620012c2826200126b565b620012d762000c566201518061016d62001ae3565b8460800151620012e8919062001fb7565b620012f4919062001fec565b90505f81136200034057604051630e520c3b60e11b81526004810182905260240162000d2b565b5f8062001329868462000bd7565b9050670de0b6b3a7640000811215620013595760405163329e322960e21b81526004810182905260240162000d2b565b5f620013726200136a878a62001cfd565b899062001241565b90505f6200138082620013a7565b90506200138e818762001241565b6200139a908462001d1f565b9998505050505050505050565b5f670de0b6b3a76400008203620013d15760405163a9c8b14d60e01b815260040160405180910390fd5b5f620013f2620013ea84670de0b6b3a764000062001d1f565b849062001241565b905062000a9f815f8082136200143b5760405162461bcd60e51b815260206004820152600d60248201526c6f7574206f6620626f756e647360981b604482015260640162000d2b565b670c7d713b49da0000821380156200145a5750670f43fc2c04ee000082125b156200148457670de0b6b3a7640000620014748362001494565b8162000eb45762000eb462001afd565b6200034082620015bd565b919050565b670de0b6b3a7640000025f806ec097ce7bc90715b34b9f1000000000808401906ec097ce7bc90715b34b9f0fffffffff1985010281620014d857620014d862001afd565b0590505f6ec097ce7bc90715b34b9f100000000082800205905081806ec097ce7bc90715b34b9f100000000081840205915060038205016ec097ce7bc90715b34b9f100000000082840205915060058205016ec097ce7bc90715b34b9f100000000082840205915060078205016ec097ce7bc90715b34b9f100000000082840205915060098205016ec097ce7bc90715b34b9f1000000000828402059150600b8205016ec097ce7bc90715b34b9f1000000000828402059150600d8205016ec097ce7bc90715b34b9f1000000000828402059150600f82050160020295945050505050565b5f670de0b6b3a76400008212156200160357620015fb826ec097ce7bc90715b34b9f100000000081620015f457620015f462001afd565b05620015bd565b5f0392915050565b5f7e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c000000000000083126200165457770195e54c5dd42177f53a27172fa9ec630262827000000000830592506806f05b59d3b2000000015b73011798004d755d3c8bc8e03204cf44619e00000083126200168d576b1425982cf597cd205cef7380830592506803782dace9d9000000015b606492830292026e01855144814a7ff805980ff00840008312620016d6576e01855144814a7ff805980ff008400068056bc75e2d63100000840205925068ad78ebc5ac62000000015b6b02df0ab5a80a22c61ab5a700831262001712576b02df0ab5a80a22c61ab5a70068056bc75e2d6310000084020592506856bc75e2d631000000015b693f1fce3da636ea5cf85083126200174a57693f1fce3da636ea5cf85068056bc75e2d631000008402059250682b5e3af16b18800000015b690127fa27722cc06cc5e283126200178257690127fa27722cc06cc5e268056bc75e2d6310000084020592506815af1d78b58c400000015b68280e60114edb805d038312620017b85768280e60114edb805d0368056bc75e2d631000008402059250680ad78ebc5ac6200000015b680ebc5fb417461211108312620017e457680ebc5fb4174612111068056bc75e2d631000009384020592015b6808f00f760a4b2db55d83126200181a576808f00f760a4b2db55d68056bc75e2d6310000084020592506802b5e3af16b1880000015b6806f5f1775788937937831262001850576806f5f177578893793768056bc75e2d63100000840205925068015af1d78b58c40000015b6806248f33704b286603831262001885576806248f33704b28660368056bc75e2d63100000840205925067ad78ebc5ac620000015b6805c548670b9510e7ac8312620018ba576805c548670b9510e7ac68056bc75e2d6310000084020592506756bc75e2d6310000015b5f68056bc75e2d63100000840168056bc75e2d631000008086030281620018e557620018e562001afd565b0590505f68056bc75e2d63100000828002059050818068056bc75e2d63100000818402059150600382050168056bc75e2d63100000828402059150600582050168056bc75e2d63100000828402059150600782050168056bc75e2d63100000828402059150600982050168056bc75e2d63100000828402059150600b820501600202606485820105979650505050505050565b6001600160a01b03811681146200198d575f80fd5b50565b80516200148f8162001978565b5f805f805f60a08688031215620019b2575f80fd5b8551620019bf8162001978565b6020870151909550620019d28162001978565b6040870151909450620019e58162001978565b6060870151909350620019f88162001978565b608087015190925063ffffffff8116811462001a12575f80fd5b809150509295509295909350565b805180151581146200148f575f80fd5b5f805f6060848603121562001a43575f80fd5b62001a4e8462001a20565b9250602084015161ffff8116811462001a65575f80fd5b915062001a756040850162001a20565b90509250925092565b5f805f6060848603121562001a91575f80fd5b835162001a9e8162001978565b602085015190935062001ab18162001978565b604085015190925062001ac48162001978565b809150509250925092565b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141762000340576200034062001acf565b634e487b7160e01b5f52601260045260245ffd5b5f8262001b225762001b2262001afd565b500490565b5f82515f5b8181101562001b48576020818601810151858301520162001b2c565b505f920191825250919050565b5f6020828403121562001b66575f80fd5b815160ff8116811462000a9f575f80fd5b60ff818116838216019081111562000340576200034062001acf565b5f6020828403121562001ba4575f80fd5b5051919050565b5f6020828403121562001bbc575f80fd5b62000a9f8262001a20565b5f6020828403121562001bd8575f80fd5b81516001600160801b038116811462000a9f575f80fd5b8181038181111562000340576200034062001acf565b634e487b7160e01b5f52604160045260245ffd5b60405161012081016001600160401b038111828210171562001c3f5762001c3f62001c05565b60405290565b604051601f8201601f191681016001600160401b038111828210171562001c705762001c7062001c05565b604052919050565b5f610120828403121562001c8a575f80fd5b62001c9462001c19565b82518152602083015160208201526040830151604082015262001cba6060840162001990565b60608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e08201526101008084015181830152508091505092915050565b8082018281125f8312801582168215821617156200033d576200033d62001acf565b8181035f83128015838313168383128216171562000848576200084862001acf565b600181815b8085111562001d8157815f190482111562001d655762001d6562001acf565b8085161562001d7357918102915b93841c939080029062001d46565b509250929050565b5f8262001d995750600162000340565b8162001da757505f62000340565b816001811462001dc0576002811462001dcb5762001deb565b600191505062000340565b60ff84111562001ddf5762001ddf62001acf565b50506001821b62000340565b5060208310610133831016604e8410600b841016171562001e10575081810a62000340565b62001e1c838362001d41565b805f190482111562001e325762001e3262001acf565b029392505050565b5f62000a9f60ff84168362001d89565b634e487b7160e01b5f52603260045260245ffd5b602080825282518282018190525f9190848201906040850190845b8181101562001e9d57835163ffffffff168352928401929184019160010162001e79565b50909695505050505050565b5f602080838503121562001ebb575f80fd5b82516001600160401b038082111562001ed2575f80fd5b818501915085601f83011262001ee6575f80fd5b81518181111562001efb5762001efb62001c05565b8060051b915062001f0e84830162001c45565b818152918301840191848101908884111562001f28575f80fd5b938501935b8385101562001f6057845192506001600160d81b038316831462001f4f575f80fd5b828252938501939085019062001f2d565b98975050505050505050565b6001600160d81b0382811682821603908082111562000848576200084862001acf565b5f6001600160d81b038381168062001fab5762001fab62001afd565b92169190910492915050565b8082025f8212600160ff1b8414161562001fd55762001fd562001acf565b818105831482151762000340576200034062001acf565b5f8262001ffd5762001ffd62001afd565b600160ff1b82145f198414161562002019576200201962001acf565b500590565b5f600160ff1b820162002035576200203562001acf565b505f0390565b60805160a05160c05160e05161010051610120516122a06200209e5f395f61042201525f6103f201525f8181610181015261038401525f818160f9015261036201525f818161014501526103d101525f81816101a801526103b001526122a05ff3fe608060405234801561000f575f80fd5b506004361061007a575f3560e01c80638107e133116100585780638107e13314610140578063999b93af1461017c57806399d9a71f146101a3578063ae68676c146101ca575f80fd5b80630579e61f1461007e57806306fdde03146100ab5780635001f3b5146100f4575b5f80fd5b61009161008c366004611c80565b6101eb565b604080519283526020830191909152015b60405180910390f35b6100e76040518060400160405280601581526020017f50656e646c65556e6976657273616c4f7261636c65000000000000000000000081525081565b6040516100a29190611cbf565b61011b7f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100a2565b6101677f000000000000000000000000000000000000000000000000000000000000000081565b60405163ffffffff90911681526020016100a2565b61011b7f000000000000000000000000000000000000000000000000000000000000000081565b61011b7f000000000000000000000000000000000000000000000000000000000000000081565b6101dd6101d8366004611c80565b610205565b6040519081526020016100a2565b5f805f6101f986868661035a565b96879650945050505050565b5f61021184848461035a565b90505b9392505050565b5f805f61022785610451565b9150915080821061024f576102468261024087876106be565b9061079a565b92505050610260565b6102468161024087876106be565b50505b92915050565b5f805f61027285610451565b915091508082106102875761024685856106be565b808261029387876106be565b61029d9190611d56565b6102469190611d9a565b5f805f6102c98573ffffffffffffffffffffffffffffffffffffffff16610451565b915091505f6102d98686846107c8565b90508183106102f6576102ec818461079a565b9350505050610260565b6102ec818361079a565b5f805f6103228573ffffffffffffffffffffffffffffffffffffffff16610451565b915091505f6103328686846107c8565b9050818310610345579250610260915050565b816103508483611d56565b6102ec9190611d9a565b5f806103a8847f0000000000000000000000000000000000000000000000000000000000000000857f000000000000000000000000000000000000000000000000000000000000000061096a565b90505f6104197f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000063ffffffff16565b905061044786827f000000000000000000000000000000000000000000000000000000000000000085610aaf565b9695505050505050565b5f805f808473ffffffffffffffffffffffffffffffffffffffff16632c8ce6bc6040518163ffffffff1660e01b8152600401606060405180830381865afa15801561049e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104c29190611dad565b92505091508173ffffffffffffffffffffffffffffffffffffffff16633ba0b9a96040518163ffffffff1660e01b8152600401602060405180830381865afa158015610510573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105349190611dec565b93505f8173ffffffffffffffffffffffffffffffffffffffff1663d2a3584e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610580573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105a49190611dec565b90508173ffffffffffffffffffffffffffffffffffffffff1663516399df6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105ef573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106139190611e03565b801561069c5750438273ffffffffffffffffffffffffffffffffffffffff166360e0a9e16040518163ffffffff1660e01b8152600401602060405180830381865afa158015610664573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106889190611e22565b6fffffffffffffffffffffffffffffffff16145b156106a9578093506106b6565b6106b38582610aff565b93505b505050915091565b5f808373ffffffffffffffffffffffffffffffffffffffff1663e184c9be6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610709573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061072d9190611dec565b905042811161074757670de0b6b3a7640000915050610260565b5f6107528585610b14565b90505f61075f4284611e51565b90505f61077461076f8484610c8b565b610cbe565b9050610788670de0b6b3a76400008261079a565b945050505050610260565b5092915050565b5f806107ae670de0b6b3a764000085611d56565b90508281816107bf576107bf611d6d565b04949350505050565b6040517f794052f30000000000000000000000000000000000000000000000000000000081525f6004820181905290819073ffffffffffffffffffffffffffffffffffffffff86169063794052f39060240161012060405180830381865afa158015610836573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061085a9190611f15565b90505f428260a001511161088957610876848360200151610ccf565b82516108829190611f95565b9050610950565b5f610895838642610d27565b90505f806108a489868a610e53565b915091505f6108cc6108c78560400151856108bf9190611fb4565b865190610ecc565b610eee565b90505f6109106108dc838561141b565b6108ee90670de0b6b3a7640000611f95565b88516020880151610900908690610ecc565b61090a9190611fb4565b9061141b565b90506109258482895f015161090a9190611f95565b61092f828561141b565b866020015161093e9190611fb4565b6109489190611f95565b955050505050505b61044761076f83604001518361141b90919063ffffffff16565b5f8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161480156109d157508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b156109dd57505f610aa7565b8173ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16148015610a4357508373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b15610a5057506001610aa7565b6040517f4ca22af000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8087166004830152841660248201526044015b60405180910390fd5b949350505050565b5f6fffffffffffffffffffffffffffffffff8316608084901c8315610aeb57610ae28782610add8986611d56565b611440565b92505050610aa7565b610ae287610af98885611d56565b83611440565b5f818311610b0d5781610214565b5090919050565b6040805160028082526060820183525f928392919060208301908036833701905050905082815f81518110610b4b57610b4b611fd3565b63ffffffff909216602092830291909101909101526040517f883bdbfd0000000000000000000000000000000000000000000000000000000081525f9073ffffffffffffffffffffffffffffffffffffffff86169063883bdbfd90610bb4908590600401612000565b5f60405180830381865afa158015610bce573d5f803e3d5ffd5b505050506040513d5f823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052610c139190810190612049565b90508363ffffffff16815f81518110610c2e57610c2e611fd3565b602002602001015182600181518110610c4957610c49611fd3565b6020026020010151610c5b9190612115565b610c659190612149565b7affffffffffffffffffffffffffffffffffffffffffffffffffffff1695945050505050565b5f80610c9c6201518061016d611d56565b610ca68486611d56565b610cb09190611d9a565b9050610aa76108c7826114fb565b5f80821215610ccb575f80fd5b5090565b5f805f8312610cdf576001610d01565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5b9050610d1d610d1885610d1386611528565b611539565b6114fb565b610aa79082612182565b610d4e60405180608001604052805f81526020015f81526020015f81526020015f81525090565b60a08401518210610d8b576040517fb2094b5900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f828560a00151610d9c9190611e51565b9050610da88582611557565b82526020850151610dba908590610ccf565b602083015284511580610dcf57506020820151155b15610e1657845160208301516040517fb1c4aefb00000000000000000000000000000000000000000000000000000000815260048101929092526024820152604401610a9e565b610e32855f01518661010001518460200151855f0151856115ca565b604083015260c0850151610e469082610c8b565b6060830152509392505050565b5f8080610e7673ffffffffffffffffffffffffffffffffffffffff871685610b14565b90505f428660a00151610e899190611e51565b9050610e958282610c8b565b93505f610ea787610100015183610c8b565b90506002610eb58683611f95565b610ebf91906121cd565b9350505050935093915050565b5f80610ed88385612182565b9050670de0b6b3a7640000815b05949350505050565b5f7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008212158015610f28575068070c1cc73b00c800008213155b610f8e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f496e76616c6964206578706f6e656e74000000000000000000000000000000006044820152606401610a9e565b5f821215610fc557610fa1825f03610eee565b6ec097ce7bc90715b34b9f100000000081610fbe57610fbe611d6d565b0592915050565b5f6806f05b59d3b2000000831261101a57507ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e00000090910190770195e54c5dd42177f53a27172fa9ec630262827000000000611066565b6803782dace9d9000000831261106257507ffffffffffffffffffffffffffffffffffffffffffffffffc87d2531627000000909101906b1425982cf597cd205cef7380611066565b5060015b6064929092029168056bc75e2d6310000068ad78ebc5ac6200000084126110cc577fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000009093019268056bc75e2d631000006e01855144814a7ff805980ff008400082020590505b6856bc75e2d631000000841261111e577fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000009093019268056bc75e2d631000006b02df0ab5a80a22c61ab5a70082020590505b682b5e3af16b18800000841261116e577fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000009093019268056bc75e2d63100000693f1fce3da636ea5cf85082020590505b6815af1d78b58c40000084126111be577fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000009093019268056bc75e2d63100000690127fa27722cc06cc5e282020590505b680ad78ebc5ac6200000841261120d577ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000009093019268056bc75e2d6310000068280e60114edb805d0382020590505b68056bc75e2d63100000841261125c577ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000009093019268056bc75e2d63100000680ebc5fb4174612111082020590505b6802b5e3af16b188000084126112ab577ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800009093019268056bc75e2d631000006808f00f760a4b2db55d82020590505b68015af1d78b58c4000084126112fa577ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c00009093019268056bc75e2d631000006806f5f177578893793782020590505b68056bc75e2d631000008481019085906002908280020505918201919050600368056bc75e2d631000008783020505918201919050600468056bc75e2d631000008783020505918201919050600568056bc75e2d631000008783020505918201919050600668056bc75e2d631000008783020505918201919050600768056bc75e2d631000008783020505918201919050600868056bc75e2d631000008783020505918201919050600968056bc75e2d631000008783020505918201919050600a68056bc75e2d631000008783020505918201919050600b68056bc75e2d631000008783020505918201919050600c68056bc75e2d631000008783020505918201919050606468056bc75e2d63100000848402058502059695505050505050565b5f8061142f670de0b6b3a764000085612182565b9050828181610ee557610ee5611d6d565b8282027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff838509818110820190038061148e57826114855763ae47f7025f526004601cfd5b50819004610214565b8083116114a25763ae47f7025f526004601cfd5b828486095f84810385169485900494848311909303908390038390046001010292030417600260038302811880840282030280840282030280840282030280840282030280840282030280840290910302029392505050565b5f7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821115610ccb575f80fd5b5f808213610ccb5761026082612234565b5f670de0b6b3a764000061154d8484611d56565b6102149190611d9a565b5f611561826114fb565b611573610d186201518061016d611d56565b84608001516115829190612182565b61158c91906121cd565b90505f8113610260576040517f1ca4187600000000000000000000000000000000000000000000000000000000815260048101829052602401610a9e565b5f806115d68684610c8b565b9050670de0b6b3a764000081121561161d576040517fca78c8a400000000000000000000000000000000000000000000000000000000815260048101829052602401610a9e565b5f61163261162b878a611f95565b899061141b565b90505f61163e82611661565b905061164a818761141b565b6116549084611fb4565b9998505050505050505050565b5f670de0b6b3a764000082036116a3576040517fa9c8b14d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6116c06116b984670de0b6b3a7640000611fb4565b849061141b565b9050610214815f808213611730576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6f7574206f6620626f756e6473000000000000000000000000000000000000006044820152606401610a9e565b670c7d713b49da00008213801561174e5750670f43fc2c04ee000082125b1561177257670de0b6b3a764000061176583611780565b81610fbe57610fbe611d6d565b610260826118b6565b919050565b670de0b6b3a7640000025f806ec097ce7bc90715b34b9f1000000000808401907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f000000000850102816117d1576117d1611d6d565b0590505f6ec097ce7bc90715b34b9f100000000082800205905081806ec097ce7bc90715b34b9f100000000081840205915060038205016ec097ce7bc90715b34b9f100000000082840205915060058205016ec097ce7bc90715b34b9f100000000082840205915060078205016ec097ce7bc90715b34b9f100000000082840205915060098205016ec097ce7bc90715b34b9f1000000000828402059150600b8205016ec097ce7bc90715b34b9f1000000000828402059150600d8205016ec097ce7bc90715b34b9f1000000000828402059150600f82050160020295945050505050565b5f670de0b6b3a76400008212156118f6576118ee826ec097ce7bc90715b34b9f1000000000816118e8576118e8611d6d565b056118b6565b5f0392915050565b5f7e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c0000000000000831261194657770195e54c5dd42177f53a27172fa9ec630262827000000000830592506806f05b59d3b2000000015b73011798004d755d3c8bc8e03204cf44619e000000831261197e576b1425982cf597cd205cef7380830592506803782dace9d9000000015b606492830292026e01855144814a7ff805980ff008400083126119c6576e01855144814a7ff805980ff008400068056bc75e2d63100000840205925068ad78ebc5ac62000000015b6b02df0ab5a80a22c61ab5a7008312611a01576b02df0ab5a80a22c61ab5a70068056bc75e2d6310000084020592506856bc75e2d631000000015b693f1fce3da636ea5cf8508312611a3857693f1fce3da636ea5cf85068056bc75e2d631000008402059250682b5e3af16b18800000015b690127fa27722cc06cc5e28312611a6f57690127fa27722cc06cc5e268056bc75e2d6310000084020592506815af1d78b58c400000015b68280e60114edb805d038312611aa45768280e60114edb805d0368056bc75e2d631000008402059250680ad78ebc5ac6200000015b680ebc5fb417461211108312611acf57680ebc5fb4174612111068056bc75e2d631000009384020592015b6808f00f760a4b2db55d8312611b04576808f00f760a4b2db55d68056bc75e2d6310000084020592506802b5e3af16b1880000015b6806f5f17757889379378312611b39576806f5f177578893793768056bc75e2d63100000840205925068015af1d78b58c40000015b6806248f33704b2866038312611b6d576806248f33704b28660368056bc75e2d63100000840205925067ad78ebc5ac620000015b6805c548670b9510e7ac8312611ba1576805c548670b9510e7ac68056bc75e2d6310000084020592506756bc75e2d6310000015b5f68056bc75e2d63100000840168056bc75e2d631000008086030281611bc957611bc9611d6d565b0590505f68056bc75e2d63100000828002059050818068056bc75e2d63100000818402059150600382050168056bc75e2d63100000828402059150600582050168056bc75e2d63100000828402059150600782050168056bc75e2d63100000828402059150600982050168056bc75e2d63100000828402059150600b820501600202606485820105979650505050505050565b73ffffffffffffffffffffffffffffffffffffffff81168114611c7d575f80fd5b50565b5f805f60608486031215611c92575f80fd5b833592506020840135611ca481611c5c565b91506040840135611cb481611c5c565b809150509250925092565b5f602080835283518060208501525f5b81811015611ceb57858101830151858201604001528201611ccf565b505f6040828601015260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8301168501019250505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b808202811582820484141761026057610260611d29565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f82611da857611da8611d6d565b500490565b5f805f60608486031215611dbf575f80fd5b8351611dca81611c5c565b6020850151909350611ddb81611c5c565b6040850151909250611cb481611c5c565b5f60208284031215611dfc575f80fd5b5051919050565b5f60208284031215611e13575f80fd5b81518015158114610214575f80fd5b5f60208284031215611e32575f80fd5b81516fffffffffffffffffffffffffffffffff81168114610214575f80fd5b8181038181111561026057610260611d29565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b604051610120810167ffffffffffffffff81118282101715611eb557611eb5611e64565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715611f0257611f02611e64565b604052919050565b805161177b81611c5c565b5f6101208284031215611f26575f80fd5b611f2e611e91565b825181526020830151602082015260408301516040820152611f5260608401611f0a565b60608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e08201526101008084015181830152508091505092915050565b8082018281125f83128015821682158216171561025d5761025d611d29565b8181035f83128015838313168383128216171561079357610793611d29565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b602080825282518282018190525f9190848201906040850190845b8181101561203d57835163ffffffff168352928401929184019160010161201b565b50909695505050505050565b5f602080838503121561205a575f80fd5b825167ffffffffffffffff80821115612071575f80fd5b818501915085601f830112612084575f80fd5b81518181111561209657612096611e64565b8060051b91506120a7848301611ebb565b81815291830184019184810190888411156120c0575f80fd5b938501935b8385101561210957845192507affffffffffffffffffffffffffffffffffffffffffffffffffffff831683146120f9575f80fd5b82825293850193908501906120c5565b98975050505050505050565b7affffffffffffffffffffffffffffffffffffffffffffffffffffff82811682821603908082111561079357610793611d29565b5f7affffffffffffffffffffffffffffffffffffffffffffffffffffff8084168061217657612176611d6d565b92169190910492915050565b8082025f82127f8000000000000000000000000000000000000000000000000000000000000000841416156121b9576121b9611d29565b818105831482151761026057610260611d29565b5f826121db576121db611d6d565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83147f80000000000000000000000000000000000000000000000000000000000000008314161561222f5761222f611d29565b500590565b5f7f8000000000000000000000000000000000000000000000000000000000000000820361226457612264611d29565b505f039056fea264697066735822122045d742e7b9ae55402108a9e67b0fca704eb81acbd9384323edd31ea4f0fdfa3a64736f6c634300081800330000000000000000000000009a9fa8338dd5e5b2188006f1cd2ef26d921650c2000000000000000000000000e467c5c54748f0125d729280f90ded77c4e720a400000000000000000000000066526197a4baf496d97e1004e43c2c374fb7d2e70000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d0000000000000000000000000000000000000000000000000000000000000384
Deployed Bytecode
0x608060405234801561000f575f80fd5b506004361061007a575f3560e01c80638107e133116100585780638107e13314610140578063999b93af1461017c57806399d9a71f146101a3578063ae68676c146101ca575f80fd5b80630579e61f1461007e57806306fdde03146100ab5780635001f3b5146100f4575b5f80fd5b61009161008c366004611c80565b6101eb565b604080519283526020830191909152015b60405180910390f35b6100e76040518060400160405280601581526020017f50656e646c65556e6976657273616c4f7261636c65000000000000000000000081525081565b6040516100a29190611cbf565b61011b7f00000000000000000000000066526197a4baf496d97e1004e43c2c374fb7d2e781565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100a2565b6101677f000000000000000000000000000000000000000000000000000000000000038481565b60405163ffffffff90911681526020016100a2565b61011b7f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d81565b61011b7f000000000000000000000000e467c5c54748f0125d729280f90ded77c4e720a481565b6101dd6101d8366004611c80565b610205565b6040519081526020016100a2565b5f805f6101f986868661035a565b96879650945050505050565b5f61021184848461035a565b90505b9392505050565b5f805f61022785610451565b9150915080821061024f576102468261024087876106be565b9061079a565b92505050610260565b6102468161024087876106be565b50505b92915050565b5f805f61027285610451565b915091508082106102875761024685856106be565b808261029387876106be565b61029d9190611d56565b6102469190611d9a565b5f805f6102c98573ffffffffffffffffffffffffffffffffffffffff16610451565b915091505f6102d98686846107c8565b90508183106102f6576102ec818461079a565b9350505050610260565b6102ec818361079a565b5f805f6103228573ffffffffffffffffffffffffffffffffffffffff16610451565b915091505f6103328686846107c8565b9050818310610345579250610260915050565b816103508483611d56565b6102ec9190611d9a565b5f806103a8847f00000000000000000000000066526197a4baf496d97e1004e43c2c374fb7d2e7857f0000000000000000000000006440f144b7e50d6a8439336510312d2f54beb01d61096a565b90505f6104197f000000000000000000000000e467c5c54748f0125d729280f90ded77c4e720a47f00000000000000000000000000000000000000000000000000000000000003847f000000000000000000000000000000000000000000000000000003460000026663ffffffff16565b905061044786827f00c097ce7bc90715b34b9f100000000000000000000000000de0b6b3a764000085610aaf565b9695505050505050565b5f805f808473ffffffffffffffffffffffffffffffffffffffff16632c8ce6bc6040518163ffffffff1660e01b8152600401606060405180830381865afa15801561049e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104c29190611dad565b92505091508173ffffffffffffffffffffffffffffffffffffffff16633ba0b9a96040518163ffffffff1660e01b8152600401602060405180830381865afa158015610510573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105349190611dec565b93505f8173ffffffffffffffffffffffffffffffffffffffff1663d2a3584e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610580573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105a49190611dec565b90508173ffffffffffffffffffffffffffffffffffffffff1663516399df6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156105ef573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106139190611e03565b801561069c5750438273ffffffffffffffffffffffffffffffffffffffff166360e0a9e16040518163ffffffff1660e01b8152600401602060405180830381865afa158015610664573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106889190611e22565b6fffffffffffffffffffffffffffffffff16145b156106a9578093506106b6565b6106b38582610aff565b93505b505050915091565b5f808373ffffffffffffffffffffffffffffffffffffffff1663e184c9be6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610709573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061072d9190611dec565b905042811161074757670de0b6b3a7640000915050610260565b5f6107528585610b14565b90505f61075f4284611e51565b90505f61077461076f8484610c8b565b610cbe565b9050610788670de0b6b3a76400008261079a565b945050505050610260565b5092915050565b5f806107ae670de0b6b3a764000085611d56565b90508281816107bf576107bf611d6d565b04949350505050565b6040517f794052f30000000000000000000000000000000000000000000000000000000081525f6004820181905290819073ffffffffffffffffffffffffffffffffffffffff86169063794052f39060240161012060405180830381865afa158015610836573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061085a9190611f15565b90505f428260a001511161088957610876848360200151610ccf565b82516108829190611f95565b9050610950565b5f610895838642610d27565b90505f806108a489868a610e53565b915091505f6108cc6108c78560400151856108bf9190611fb4565b865190610ecc565b610eee565b90505f6109106108dc838561141b565b6108ee90670de0b6b3a7640000611f95565b88516020880151610900908690610ecc565b61090a9190611fb4565b9061141b565b90506109258482895f015161090a9190611f95565b61092f828561141b565b866020015161093e9190611fb4565b6109489190611f95565b955050505050505b61044761076f83604001518361141b90919063ffffffff16565b5f8373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161480156109d157508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b156109dd57505f610aa7565b8173ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff16148015610a4357508373ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16145b15610a5057506001610aa7565b6040517f4ca22af000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8087166004830152841660248201526044015b60405180910390fd5b949350505050565b5f6fffffffffffffffffffffffffffffffff8316608084901c8315610aeb57610ae28782610add8986611d56565b611440565b92505050610aa7565b610ae287610af98885611d56565b83611440565b5f818311610b0d5781610214565b5090919050565b6040805160028082526060820183525f928392919060208301908036833701905050905082815f81518110610b4b57610b4b611fd3565b63ffffffff909216602092830291909101909101526040517f883bdbfd0000000000000000000000000000000000000000000000000000000081525f9073ffffffffffffffffffffffffffffffffffffffff86169063883bdbfd90610bb4908590600401612000565b5f60405180830381865afa158015610bce573d5f803e3d5ffd5b505050506040513d5f823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052610c139190810190612049565b90508363ffffffff16815f81518110610c2e57610c2e611fd3565b602002602001015182600181518110610c4957610c49611fd3565b6020026020010151610c5b9190612115565b610c659190612149565b7affffffffffffffffffffffffffffffffffffffffffffffffffffff1695945050505050565b5f80610c9c6201518061016d611d56565b610ca68486611d56565b610cb09190611d9a565b9050610aa76108c7826114fb565b5f80821215610ccb575f80fd5b5090565b5f805f8312610cdf576001610d01565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5b9050610d1d610d1885610d1386611528565b611539565b6114fb565b610aa79082612182565b610d4e60405180608001604052805f81526020015f81526020015f81526020015f81525090565b60a08401518210610d8b576040517fb2094b5900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f828560a00151610d9c9190611e51565b9050610da88582611557565b82526020850151610dba908590610ccf565b602083015284511580610dcf57506020820151155b15610e1657845160208301516040517fb1c4aefb00000000000000000000000000000000000000000000000000000000815260048101929092526024820152604401610a9e565b610e32855f01518661010001518460200151855f0151856115ca565b604083015260c0850151610e469082610c8b565b6060830152509392505050565b5f8080610e7673ffffffffffffffffffffffffffffffffffffffff871685610b14565b90505f428660a00151610e899190611e51565b9050610e958282610c8b565b93505f610ea787610100015183610c8b565b90506002610eb58683611f95565b610ebf91906121cd565b9350505050935093915050565b5f80610ed88385612182565b9050670de0b6b3a7640000815b05949350505050565b5f7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008212158015610f28575068070c1cc73b00c800008213155b610f8e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f496e76616c6964206578706f6e656e74000000000000000000000000000000006044820152606401610a9e565b5f821215610fc557610fa1825f03610eee565b6ec097ce7bc90715b34b9f100000000081610fbe57610fbe611d6d565b0592915050565b5f6806f05b59d3b2000000831261101a57507ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e00000090910190770195e54c5dd42177f53a27172fa9ec630262827000000000611066565b6803782dace9d9000000831261106257507ffffffffffffffffffffffffffffffffffffffffffffffffc87d2531627000000909101906b1425982cf597cd205cef7380611066565b5060015b6064929092029168056bc75e2d6310000068ad78ebc5ac6200000084126110cc577fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000009093019268056bc75e2d631000006e01855144814a7ff805980ff008400082020590505b6856bc75e2d631000000841261111e577fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000009093019268056bc75e2d631000006b02df0ab5a80a22c61ab5a70082020590505b682b5e3af16b18800000841261116e577fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000009093019268056bc75e2d63100000693f1fce3da636ea5cf85082020590505b6815af1d78b58c40000084126111be577fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000009093019268056bc75e2d63100000690127fa27722cc06cc5e282020590505b680ad78ebc5ac6200000841261120d577ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000009093019268056bc75e2d6310000068280e60114edb805d0382020590505b68056bc75e2d63100000841261125c577ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000009093019268056bc75e2d63100000680ebc5fb4174612111082020590505b6802b5e3af16b188000084126112ab577ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800009093019268056bc75e2d631000006808f00f760a4b2db55d82020590505b68015af1d78b58c4000084126112fa577ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c00009093019268056bc75e2d631000006806f5f177578893793782020590505b68056bc75e2d631000008481019085906002908280020505918201919050600368056bc75e2d631000008783020505918201919050600468056bc75e2d631000008783020505918201919050600568056bc75e2d631000008783020505918201919050600668056bc75e2d631000008783020505918201919050600768056bc75e2d631000008783020505918201919050600868056bc75e2d631000008783020505918201919050600968056bc75e2d631000008783020505918201919050600a68056bc75e2d631000008783020505918201919050600b68056bc75e2d631000008783020505918201919050600c68056bc75e2d631000008783020505918201919050606468056bc75e2d63100000848402058502059695505050505050565b5f8061142f670de0b6b3a764000085612182565b9050828181610ee557610ee5611d6d565b8282027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff838509818110820190038061148e57826114855763ae47f7025f526004601cfd5b50819004610214565b8083116114a25763ae47f7025f526004601cfd5b828486095f84810385169485900494848311909303908390038390046001010292030417600260038302811880840282030280840282030280840282030280840282030280840282030280840290910302029392505050565b5f7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821115610ccb575f80fd5b5f808213610ccb5761026082612234565b5f670de0b6b3a764000061154d8484611d56565b6102149190611d9a565b5f611561826114fb565b611573610d186201518061016d611d56565b84608001516115829190612182565b61158c91906121cd565b90505f8113610260576040517f1ca4187600000000000000000000000000000000000000000000000000000000815260048101829052602401610a9e565b5f806115d68684610c8b565b9050670de0b6b3a764000081121561161d576040517fca78c8a400000000000000000000000000000000000000000000000000000000815260048101829052602401610a9e565b5f61163261162b878a611f95565b899061141b565b90505f61163e82611661565b905061164a818761141b565b6116549084611fb4565b9998505050505050505050565b5f670de0b6b3a764000082036116a3576040517fa9c8b14d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6116c06116b984670de0b6b3a7640000611fb4565b849061141b565b9050610214815f808213611730576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6f7574206f6620626f756e6473000000000000000000000000000000000000006044820152606401610a9e565b670c7d713b49da00008213801561174e5750670f43fc2c04ee000082125b1561177257670de0b6b3a764000061176583611780565b81610fbe57610fbe611d6d565b610260826118b6565b919050565b670de0b6b3a7640000025f806ec097ce7bc90715b34b9f1000000000808401907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f000000000850102816117d1576117d1611d6d565b0590505f6ec097ce7bc90715b34b9f100000000082800205905081806ec097ce7bc90715b34b9f100000000081840205915060038205016ec097ce7bc90715b34b9f100000000082840205915060058205016ec097ce7bc90715b34b9f100000000082840205915060078205016ec097ce7bc90715b34b9f100000000082840205915060098205016ec097ce7bc90715b34b9f1000000000828402059150600b8205016ec097ce7bc90715b34b9f1000000000828402059150600d8205016ec097ce7bc90715b34b9f1000000000828402059150600f82050160020295945050505050565b5f670de0b6b3a76400008212156118f6576118ee826ec097ce7bc90715b34b9f1000000000816118e8576118e8611d6d565b056118b6565b5f0392915050565b5f7e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c0000000000000831261194657770195e54c5dd42177f53a27172fa9ec630262827000000000830592506806f05b59d3b2000000015b73011798004d755d3c8bc8e03204cf44619e000000831261197e576b1425982cf597cd205cef7380830592506803782dace9d9000000015b606492830292026e01855144814a7ff805980ff008400083126119c6576e01855144814a7ff805980ff008400068056bc75e2d63100000840205925068ad78ebc5ac62000000015b6b02df0ab5a80a22c61ab5a7008312611a01576b02df0ab5a80a22c61ab5a70068056bc75e2d6310000084020592506856bc75e2d631000000015b693f1fce3da636ea5cf8508312611a3857693f1fce3da636ea5cf85068056bc75e2d631000008402059250682b5e3af16b18800000015b690127fa27722cc06cc5e28312611a6f57690127fa27722cc06cc5e268056bc75e2d6310000084020592506815af1d78b58c400000015b68280e60114edb805d038312611aa45768280e60114edb805d0368056bc75e2d631000008402059250680ad78ebc5ac6200000015b680ebc5fb417461211108312611acf57680ebc5fb4174612111068056bc75e2d631000009384020592015b6808f00f760a4b2db55d8312611b04576808f00f760a4b2db55d68056bc75e2d6310000084020592506802b5e3af16b1880000015b6806f5f17757889379378312611b39576806f5f177578893793768056bc75e2d63100000840205925068015af1d78b58c40000015b6806248f33704b2866038312611b6d576806248f33704b28660368056bc75e2d63100000840205925067ad78ebc5ac620000015b6805c548670b9510e7ac8312611ba1576805c548670b9510e7ac68056bc75e2d6310000084020592506756bc75e2d6310000015b5f68056bc75e2d63100000840168056bc75e2d631000008086030281611bc957611bc9611d6d565b0590505f68056bc75e2d63100000828002059050818068056bc75e2d63100000818402059150600382050168056bc75e2d63100000828402059150600582050168056bc75e2d63100000828402059150600782050168056bc75e2d63100000828402059150600982050168056bc75e2d63100000828402059150600b820501600202606485820105979650505050505050565b73ffffffffffffffffffffffffffffffffffffffff81168114611c7d575f80fd5b50565b5f805f60608486031215611c92575f80fd5b833592506020840135611ca481611c5c565b91506040840135611cb481611c5c565b809150509250925092565b5f602080835283518060208501525f5b81811015611ceb57858101830151858201604001528201611ccf565b505f6040828601015260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8301168501019250505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b808202811582820484141761026057610260611d29565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f82611da857611da8611d6d565b500490565b5f805f60608486031215611dbf575f80fd5b8351611dca81611c5c565b6020850151909350611ddb81611c5c565b6040850151909250611cb481611c5c565b5f60208284031215611dfc575f80fd5b5051919050565b5f60208284031215611e13575f80fd5b81518015158114610214575f80fd5b5f60208284031215611e32575f80fd5b81516fffffffffffffffffffffffffffffffff81168114610214575f80fd5b8181038181111561026057610260611d29565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b604051610120810167ffffffffffffffff81118282101715611eb557611eb5611e64565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715611f0257611f02611e64565b604052919050565b805161177b81611c5c565b5f6101208284031215611f26575f80fd5b611f2e611e91565b825181526020830151602082015260408301516040820152611f5260608401611f0a565b60608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e08201526101008084015181830152508091505092915050565b8082018281125f83128015821682158216171561025d5761025d611d29565b8181035f83128015838313168383128216171561079357610793611d29565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b602080825282518282018190525f9190848201906040850190845b8181101561203d57835163ffffffff168352928401929184019160010161201b565b50909695505050505050565b5f602080838503121561205a575f80fd5b825167ffffffffffffffff80821115612071575f80fd5b818501915085601f830112612084575f80fd5b81518181111561209657612096611e64565b8060051b91506120a7848301611ebb565b81815291830184019184810190888411156120c0575f80fd5b938501935b8385101561210957845192507affffffffffffffffffffffffffffffffffffffffffffffffffffff831683146120f9575f80fd5b82825293850193908501906120c5565b98975050505050505050565b7affffffffffffffffffffffffffffffffffffffffffffffffffffff82811682821603908082111561079357610793611d29565b5f7affffffffffffffffffffffffffffffffffffffffffffffffffffff8084168061217657612176611d6d565b92169190910492915050565b8082025f82127f8000000000000000000000000000000000000000000000000000000000000000841416156121b9576121b9611d29565b818105831482151761026057610260611d29565b5f826121db576121db611d6d565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83147f80000000000000000000000000000000000000000000000000000000000000008314161561222f5761222f611d29565b500590565b5f7f8000000000000000000000000000000000000000000000000000000000000000820361226457612264611d29565b505f039056fea264697066735822122045d742e7b9ae55402108a9e67b0fca704eb81acbd9384323edd31ea4f0fdfa3a64736f6c63430008180033
Deployed Bytecode Sourcemap
853:4433:21:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1003:215:20;;;;;;:::i;:::-;;:::i;:::-;;;;808:25:26;;;864:2;849:18;;842:34;;;;781:18;1003:215:20;;;;;;;;938:53:21;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;1581:29::-;;;;;;;;1675:42:26;1663:55;;;1645:74;;1633:2;1618:18;1581:29:21;1499:226:26;1478:34:21;;;;;;;;1904:10:26;1892:23;;;1874:42;;1862:2;1847:18;1478:34:21;1730:192:26;1694:30:21;;;;;1380:37;;;;;759:153:20;;;;;;:::i;:::-;;:::i;:::-;;;2073:25:26;;;2061:2;2046:18;759:153:20;1927:177:26;1003:215:20;1092:7;1101;1120:17;1140:32;1150:8;1160:4;1166:5;1140:9;:32::i;:::-;1120:52;;;-1:-1:-1;1003:215:20;-1:-1:-1;;;;;1003:215:20:o;759:153::-;847:7;873:32;883:8;893:4;899:5;873:9;:32::i;:::-;866:39;;759:153;;;;;;:::o;1925:384:18:-;2005:7;2025:15;2042;2061:30;2084:6;2061:22;:30::i;:::-;2024:67;;;;2116:7;2105;:18;2101:202;;2146:54;2192:7;2146:37;2166:6;2174:8;2146:19;:37::i;:::-;:45;;:54::i;:::-;2139:61;;;;;;2101:202;2238:54;2284:7;2238:37;2258:6;2266:8;2238:19;:37::i;2101:202::-;2014:295;;1925:384;;;;;:::o;767:375::-;850:7;870:15;887;906:30;929:6;906:22;:30::i;:::-;869:67;;;;961:7;950;:18;946:190;;991:37;1011:6;1019:8;991:19;:37::i;946:190::-;1118:7;1107;1067:37;1087:6;1095:8;1067:19;:37::i;:::-;:47;;;;:::i;:::-;1066:59;;;;:::i;1373:427:17:-;1453:7;1473:15;1490;1509:31;:6;:29;;;:31::i;:::-;1472:68;;;;1550:24;1577:47;1598:6;1606:8;1616:7;1577:20;:47::i;:::-;1550:74;;1649:7;1638;:18;1634:160;;1679:33;:16;1704:7;1679:24;:33::i;:::-;1672:40;;;;;;;1634:160;1750:33;:16;1775:7;1750:24;:33::i;614:418::-;697:7;717:15;734;753:31;:6;:29;;;:31::i;:::-;716:68;;;;794:24;821:47;842:6;850:8;860:7;821:20;:47::i;:::-;794:74;;893:7;882;:18;878:148;;923:16;-1:-1:-1;916:23:17;;-1:-1:-1;;916:23:17;878:148;1008:7;978:26;997:7;978:16;:26;:::i;:::-;977:38;;;;:::i;4933:351:21:-;5033:7;5052:12;5067:59;5099:5;5106:4;5112:6;5120:5;5067:31;:59::i;:::-;5052:74;;5136:17;5156:43;5173:12;5188:10;5156:7;:43;;:::i;:::-;5136:63;;5216:61;5241:8;5251:9;5262:5;5269:7;5216:24;:61::i;:::-;5209:68;4933:351;-1:-1:-1;;;;;;4933:351:21:o;3689:489:18:-;3761:15;3778;3806:21;3831:15;3850:6;:17;;;:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;3805:64;;;;;3890:2;:15;;;:17;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;3880:27;;3917:21;3941:2;:16;;;:18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;3917:42;;3974:2;:24;;;:26;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:74;;;;;4036:12;4004:2;:26;;;:28;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:44;;;3974:74;3970:202;;;4074:13;4064:23;;3970:202;;;4128:33;4138:7;4147:13;4128:9;:33::i;:::-;4118:43;;3970:202;3795:383;;;3689:489;;;:::o;2867:555::-;2953:7;2972:14;2989:6;:13;;;:15;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2972:32;;3029:15;3019:6;:25;3015:401;;835:4:8;3060:16:18;;;;;3015:401;3107:21;3131:40;3154:6;3162:8;3131:22;:40::i;:::-;3107:64;-1:-1:-1;3185:20:18;3208:24;3217:15;3208:6;:24;:::i;:::-;3185:47;;3246:21;3270:82;:75;3317:13;3332:12;3270:46;:75::i;:::-;:80;:82::i;:::-;3246:106;-1:-1:-1;3373:32:18;835:4:8;3246:106:18;3373:17;:32::i;:::-;3366:39;;;;;;;;3015:401;2962:460;2867:555;;;;:::o;1651:179:8:-;1713:7;;1752;835:4;1752:1;:7;:::i;:::-;1732:27;;1812:1;1800:9;:13;;;;;:::i;:::-;;;1651:179;-1:-1:-1;;;;1651:179:8:o;1806:1241:17:-;2002:28;;;;;1939:24;2002:28;;;1645:74:26;;;1939:24:17;;;2002:16;;;;;;1618:18:26;;2002:28:17;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;1975:55;;2041:29;2100:15;2084:5;:12;;;:31;2080:879;;2214:58;2248:7;2258:5;:13;;;2214:20;:58::i;:::-;2198:13;;:74;;;;:::i;:::-;2173:99;;2080:879;;;2303:28;2334:65;:5;2373:7;2383:15;2334:25;:65::i;:::-;2303:96;;2415:17;2434:19;2457:39;2472:6;2480:5;2487:8;2457:14;:39::i;:::-;2414:82;;;;2510:13;2526:71;2541:55;2579:4;:15;;;2566:10;:28;;;;:::i;:::-;2541:15;;;:23;:55::i;:::-;2526:14;:71::i;:::-;2510:87;-1:-1:-1;2612:16:17;2631:130;2719:28;2510:87;2734:12;2719:14;:28::i;:::-;2706:41;;898:4:8;2706:41:17;:::i;:::-;2666:13;;2647:15;;;;2632:31;;:6;;:14;:31::i;:::-;:47;;;;:::i;:::-;2631:57;;:130::i;:::-;2612:149;;2901:47;2937:10;2918:9;2902:5;:13;;;:25;;;;:::i;2901:47::-;2851:31;:9;2869:12;2851:17;:31::i;:::-;2817:4;:15;;;:65;;;;:::i;:::-;:131;;;;:::i;:::-;2776:172;;2289:670;;;;;2080:879;2988:52;:45;3019:5;:13;;;2988:22;:30;;:45;;;;:::i;1829:368:24:-;1974:4;2011;1998:17;;:9;:17;;;:40;;;;;2033:5;2019:19;;:10;:19;;;1998:40;1994:58;;;-1:-1:-1;2047:5:24;2040:12;;1994:58;2079:5;2066:18;;:9;:18;;;:40;;;;;2102:4;2088:18;;:10;:18;;;2066:40;2062:57;;;-1:-1:-1;2115:4:24;2108:11;;2062:57;2136:54;;;;;6643:42:26;6712:15;;;2136:54:24;;;6694:34:26;6764:15;;6744:18;;;6737:43;6606:18;;2136:54:24;;;;;;;;1829:368;;;;;;;:::o;3090:645::-;3224:7;470:66;3268:38;;3359:3;3336:26;;;3372:357;;;;3471:73;3500:8;3510:9;3521:22;3534:9;3521:10;:22;:::i;:::-;3471:28;:73::i;:::-;3464:80;;;;;;3372:357;3645:73;3674:8;3684:22;3697:9;3684:10;:22;:::i;:::-;3708:9;3645:28;:73::i;3337:106:8:-;3395:7;3426:1;3422;:5;:13;;3434:1;3422:13;;;-1:-1:-1;3430:1:8;;3414:22;-1:-1:-1;3337:106:8:o;4184:355:18:-;4320:15;;;4333:1;4320:15;;;;;;;;4273:7;;;;4320:15;4333:1;4320:15;;;;;;;;;;-1:-1:-1;4320:15:18;4292:43;;4360:8;4345:9;4355:1;4345:12;;;;;;;;:::i;:::-;:23;;;;:12;;;;;;;;;;;:23;4422:25;;;;;4379:40;;4422:14;;;;;;:25;;4437:9;;4422:25;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;4379:68;;4524:8;4464:68;;4494:23;4518:1;4494:26;;;;;;;;:::i;:::-;;;;;;;4465:23;4489:1;4465:26;;;;;;;;:::i;:::-;;;;;;;:55;;;;:::i;:::-;4464:68;;;;:::i;:::-;4457:75;;;4184:355;-1:-1:-1;;;;;4184:355:18:o;12797:282:2:-;12928:19;;1174:9;1117:5;1174:3;:9;:::i;:::-;12973:28;12989:12;12973:13;:28;:::i;:::-;12972:50;;;;:::i;:::-;12959:63;;13048:24;13063:8;:2;:6;:8::i;4555:115:8:-;4602:7;4634:1;4629;:6;;4621:15;;;;;;-1:-1:-1;4661:1:8;4555:115::o;1168:238:3:-;1242:6;1260:11;1285:1;1274:8;:12;:37;;1309:1;1274:37;;;1296:2;1274:37;1260:51;;1335:64;1336:56;1369:5;1377:14;:8;:12;:14::i;:::-;1336:17;:56::i;:::-;1335:62;:64::i;:::-;1328:71;;:4;:71;:::i;8284:889:2:-;8427:27;-1:-1:-1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8427:27:2;8492:13;;;;-1:-1:-1;;8466:82:2;;8526:22;;;;;;;;;;;;;;8466:82;8559:20;8598:9;8582:6;:13;;;:25;;;;:::i;:::-;8559:48;;8635:36;8650:6;8658:12;8635:14;:36::i;:::-;8618:53;;8714:14;;;;8698:31;;:5;;:15;:31::i;:::-;8681:14;;;:48;8744:14;;:19;;:42;;-1:-1:-1;8767:14:2;;;;:19;8744:42;8740:135;;;8844:14;;8860;;;;8807:68;;;;;;;;808:25:26;;;;849:18;;;842:34;781:18;;8807:68:2;634:248:26;8740:135:2;8903:172;8931:6;:14;;;8959:6;:24;;;8997:3;:14;;;9025:3;:14;;;9053:12;8903:14;:172::i;:::-;8886:14;;;:189;9131:20;;;;9099:67;;9153:12;9099:31;:67::i;:::-;9085:11;;;:81;-1:-1:-1;9085:3:2;8284:889;-1:-1:-1;;;8284:889:2:o;3053:593:17:-;3189:17;;;3263:39;:29;;;3293:8;3263:29;:39::i;:::-;3239:63;;3312:20;3350:15;3335:5;:12;;;:30;;;;:::i;:::-;3312:53;;3388:75;3435:13;3450:12;3388:46;:75::i;:::-;3375:88;;3474:20;3497:85;3544:5;:23;;;3569:12;3497:46;:85::i;:::-;3474:108;-1:-1:-1;3638:1:17;3608:26;3624:10;3474:108;3608:26;:::i;:::-;3607:32;;;;:::i;:::-;3592:47;;3229:417;;;3053:593;;;;;;:::o;1473:172:8:-;1533:6;;1568:5;1572:1;1568;:5;:::i;:::-;1551:22;-1:-1:-1;898:4:8;1551:22;1614:14;;;1473:172;-1:-1:-1;;;;1473:172:8:o;4828:5831:7:-;4874:6;2743;4924:1;:25;;:54;;;;;2692:6;4953:1;:25;;4924:54;4916:83;;;;;;;10255:2:26;4916:83:7;;;10237:21:26;10294:2;10274:18;;;10267:30;10333:18;10313;;;10306:46;10369:18;;4916:83:7;10053:340:26;4916:83:7;5022:1;5018;:5;5014:373;;;5364:7;5369:1;5368:2;;5364:3;:7::i;:::-;5345:15;5344:27;;;;;:::i;:::-;;;4828:5831;-1:-1:-1;;4828:5831:7:o;5014:373::-;6748:14;3132:21;6780:1;:7;6776:252;;-1:-1:-1;6807:7:7;;;;;3188:56;6776:252;;;3296:20;6869:1;:7;6865:163;;-1:-1:-1;6896:7:7;;;;;3351:28;6865:163;;;-1:-1:-1;6982:1:7;6865:163;7195:3;7190:8;;;;;2097:4;3460:22;7465:7;;7461:104;;7492:7;;;;;2097:4;3517:34;7528:12;;7527:23;7517:33;;7461:104;3589:22;7582:1;:7;7578:104;;7609:7;;;;;2097:4;3646:27;7645:12;;7644:23;7634:33;;7578:104;3711:21;7699:1;:7;7695:104;;7726:7;;;;;2097:4;3767:24;7762:12;;7761:23;7751:33;;7695:104;3829:21;7816:1;:7;7812:104;;7843:7;;;;;2097:4;3885:22;7879:12;;7878:23;7868:33;;7812:104;3945:21;7933:1;:7;7929:104;;7960:7;;;;;2097:4;4001:21;7996:12;;7995:23;7985:33;;7929:104;4060:21;8050:1;:7;8046:104;;8077:7;;;;;4060:21;4116;8113:12;;8112:23;8102:33;;8046:104;4175:20;8167:1;:7;8163:104;;8194:7;;;;;2097:4;4231:21;8230:12;;8229:23;8219:33;;8163:104;4290:20;8284:1;:7;8280:104;;8311:7;;;;;2097:4;4346:21;8347:12;;8346:23;8336:33;;8280:104;2097:4;8948:17;;;;;;9245:1;;9223:8;;;9222:19;9221:25;9260:17;;;;9221:25;-1:-1:-1;9323:1:7;2097:4;9301:8;;;9300:19;9299:25;9338:17;;;;9299:25;-1:-1:-1;9401:1:7;2097:4;9379:8;;;9378:19;9377:25;9416:17;;;;9377:25;-1:-1:-1;9479:1:7;2097:4;9457:8;;;9456:19;9455:25;9494:17;;;;9455:25;-1:-1:-1;9557:1:7;2097:4;9535:8;;;9534:19;9533:25;9572:17;;;;9533:25;-1:-1:-1;9635:1:7;2097:4;9613:8;;;9612:19;9611:25;9650:17;;;;9611:25;-1:-1:-1;9713:1:7;2097:4;9691:8;;;9690:19;9689:25;9728:17;;;;9689:25;-1:-1:-1;9791:1:7;2097:4;9769:8;;;9768:19;9767:25;9806:17;;;;9767:25;-1:-1:-1;9869:2:7;2097:4;9847:8;;;9846:19;9845:26;9885:17;;;;9845:26;-1:-1:-1;9948:2:7;2097:4;9926:8;;;9925:19;9924:26;9964:17;;;;9924:26;-1:-1:-1;10027:2:7;2097:4;10005:8;;;10004:19;10003:26;10043:17;;;;10003:26;-1:-1:-1;10639:3:7;2097:4;10595:19;;;10594:30;10593:42;;10592:50;;4828:5831;-1:-1:-1;;;;;;4828:5831:7:o;1836:176:8:-;1896:6;;1933:8;898:4;1933:1;:8;:::i;:::-;1914:27;;1994:1;1982:9;:13;;;;;:::i;20285:3569:19:-;20897:9;;;20995:6;20904:1;20901;20982:20;21110:14;;;21098:27;;21090:36;;;21211:278;;21257:1;21247:153;;21299:10;21293:4;21286:24;21373:4;21367;21360:18;21247:153;-1:-1:-1;21431:14:19;;;21466:5;;21211:278;21610:2;21607:1;21604:9;21594:149;;21650:10;21644:4;21637:24;21720:4;21714;21707:18;21594:149;22000:1;21997;21994;21987:15;22148:1;22144:9;;;22137:17;;22239:9;;;;;23559:13;;;23551:22;;;23583:9;;;;23579:17;;;23598:1;23575:25;23547:54;23635:14;;23631:22;23515:164;22614:1;22621;22617:9;;22610:17;;22896:11;;;22889:19;;22880:29;22969:11;;;22962:19;;22953:29;23043:11;;;23036:19;;23027:29;23117:11;;;23110:19;;23101:29;23191:11;;;23184:19;;23175:29;23767:11;;;23760:19;;;23751:29;23273:529;20285:3569;;;;;:::o;3963:137:8:-;4010:6;4049:16;4036:1;:30;;4028:39;;;;;3039:102;3085:7;3123:1;3119;:5;:14;;3131:2;3132:1;3131:2;:::i;135:146:4:-;217:7;124:4;244:23;255:12;244:8;:23;:::i;:::-;243:31;;;;:::i;14080:293:2:-;14176:17;14266:18;:12;:16;:18::i;:::-;14239:23;1174:9;1117:5;1174:3;:9;:::i;14239:23::-;14219:6;:17;;;:43;;;;:::i;:::-;14218:66;;;;:::i;:::-;14205:79;;14312:1;14298:10;:15;14294:72;;14322:44;;;;;;;;2073:25:26;;;2046:18;;14322:44:2;1927:177:26;11363:656:2;11559:17;11588:22;11613:64;11645:17;11664:12;11613:31;:64::i;:::-;11588:89;;898:4:8;11692:15:2;:28;11688:91;;;11729:50;;;;;;;;2073:25:26;;;2046:18;;11729:50:2;1927:177:26;11688:91:2;11804:17;11824:37;11840:20;11850:10;11840:7;:20;:::i;:::-;11824:7;;:15;:37::i;:::-;11804:57;;11876:19;11898:26;11913:10;11898:14;:26::i;:::-;11876:48;-1:-1:-1;11970:32:2;11876:48;11991:10;11970:20;:32::i;:::-;11952:50;;:15;:50;:::i;:::-;11939:63;11363:656;-1:-1:-1;;;;;;;;;11363:656:2:o;13804:270::-;13870:10;898:4:8;13896:10:2;:24;13892:77;;13929:40;;;;;;;;;;;;;;13892:77;13980:13;13996:43;14015:23;14028:10;898:4:8;14015:23:2;:::i;:::-;13996:10;;:18;:43::i;:::-;13980:59;;14056:11;:6;10809::7;10950:1;10946;:5;10938:31;;;;;;;10976:2:26;10938:31:7;;;10958:21:26;11015:2;10995:18;;;10988:30;11054:15;11034:18;;;11027:43;11087:18;;10938:31:7;10774:337:26;10938:31:7;2936:13;10987:21;-1:-1:-1;10987:46:7;;;;-1:-1:-1;2991:13:7;11012:21;;10987:46;10983:162;;;1907:4;11060:9;11067:1;11060:6;:9::i;:::-;:18;;;;;:::i;10983:162::-;11124:6;11128:1;11124:3;:6::i;10983:162::-;10764:397;;;:::o;19514:1872::-;1907:4;19820:11;19562:6;;2132:4;20250:10;;;;20225;;;20224:21;20250:10;20223:38;;;;:::i;:::-;;;-1:-1:-1;20275:16:7;2132:4;20295:5;;;20294:16;;-1:-1:-1;20412:1:7;;2132:4;20643:15;;;20642:26;;-1:-1:-1;20701:1:7;20642:26;20695:7;20682:20;2132:4;20724:15;;;20723:26;;-1:-1:-1;20782:1:7;20723:26;20776:7;20763:20;2132:4;20805:15;;;20804:26;;-1:-1:-1;20863:1:7;20804:26;20857:7;20844:20;2132:4;20886:15;;;20885:26;;-1:-1:-1;20944:1:7;20885:26;20938:7;20925:20;2132:4;20967:15;;;20966:26;;-1:-1:-1;21025:2:7;20966:26;21019:8;21006:21;2132:4;21049:15;;;21048:26;;-1:-1:-1;21107:2:7;21048:26;21101:8;21088:21;2132:4;21131:15;;;21130:26;;-1:-1:-1;21189:2:7;21130:26;21183:8;21170:21;21368:1;21356:13;;;-1:-1:-1;;;;;19514:1872:7:o;13851:5397::-;13896:6;1907:4;13942:1;:10;13938:402;;;14298:26;14322:1;14303:15;14322:1;14302:21;;;;:::i;:::-;;14298:3;:26::i;:::-;14297:27;;;13851:5397;-1:-1:-1;;13851:5397:7:o;13938:402::-;15721:10;15758:11;15753:16;;15749:126;;3188:56;15789:7;;;-1:-1:-1;3132:21:7;15851:9;15749:126;15898:11;15893:16;;15889:126;;3351:28;15929:7;;;-1:-1:-1;3296:20:7;15991:9;15889:126;16161:3;16178:8;;;;16154:10;3517:34;16321:7;;16317:94;;3517:34;2097:4;16353:10;;16352:17;;-1:-1:-1;3460:22:7;16387:9;16317:94;3646:27;16429:1;:7;16425:94;;3646:27;2097:4;16461:10;;16460:17;;-1:-1:-1;3589:22:7;16495:9;16425:94;3767:24;16537:1;:7;16533:94;;3767:24;2097:4;16569:10;;16568:17;;-1:-1:-1;3711:21:7;16603:9;16533:94;3885:22;16645:1;:7;16641:94;;3885:22;2097:4;16677:10;;16676:17;;-1:-1:-1;3829:21:7;16711:9;16641:94;4001:21;16753:1;:7;16749:94;;4001:21;2097:4;16785:10;;16784:17;;-1:-1:-1;3945:21:7;16819:9;16749:94;4116:21;16861:1;:7;16857:94;;4116:21;2097:4;16893:10;;;16892:17;;16927:9;16857:94;4231:21;16969:1;:7;16965:94;;4231:21;2097:4;17001:10;;17000:17;;-1:-1:-1;4175:20:7;17035:9;16965:94;4346:21;17077:1;:7;17073:94;;4346:21;2097:4;17109:10;;17108:17;;-1:-1:-1;4290:20:7;17143:9;17073:94;4463:21;17185:1;:8;17181:97;;4463:21;2097:4;17218:10;;17217:18;;-1:-1:-1;4406:20:7;17253:10;17181:97;4580:21;17296:1;:8;17292:97;;4580:21;2097:4;17329:10;;17328:18;;-1:-1:-1;4524:19:7;17364:10;17292:97;17919:8;2097:4;17957:1;:10;2097:4;;17932:1;:10;17931:21;17930:38;;;;;:::i;:::-;;;-1:-1:-1;17982:16:7;2097:4;18002:5;;;18001:16;;-1:-1:-1;18119:1:7;;2097:4;18350:15;;;18349:26;;-1:-1:-1;18408:1:7;18349:26;18402:7;18389:20;2097:4;18431:15;;;18430:26;;-1:-1:-1;18489:1:7;18430:26;18483:7;18470:20;2097:4;18512:15;;;18511:26;;-1:-1:-1;18570:1:7;18511:26;18564:7;18551:20;2097:4;18593:15;;;18592:26;;-1:-1:-1;18651:1:7;18592:26;18645:7;18632:20;2097:4;18674:15;;;18673:26;;-1:-1:-1;18732:2:7;18673:26;18726:8;18713:21;18918:1;18905:14;19228:3;19209:15;;;19208:23;;13851:5397;-1:-1:-1;;;;;;;13851:5397:7:o;14:154:26:-;100:42;93:5;89:54;82:5;79:65;69:93;;158:1;155;148:12;69:93;14:154;:::o;173:456::-;250:6;258;266;319:2;307:9;298:7;294:23;290:32;287:52;;;335:1;332;325:12;287:52;371:9;358:23;348:33;;431:2;420:9;416:18;403:32;444:31;469:5;444:31;:::i;:::-;494:5;-1:-1:-1;551:2:26;536:18;;523:32;564:33;523:32;564:33;:::i;:::-;616:7;606:17;;;173:456;;;;;:::o;887:607::-;999:4;1028:2;1057;1046:9;1039:21;1089:6;1083:13;1132:6;1127:2;1116:9;1112:18;1105:34;1157:1;1167:140;1181:6;1178:1;1175:13;1167:140;;;1276:14;;;1272:23;;1266:30;1242:17;;;1261:2;1238:26;1231:66;1196:10;;1167:140;;;1171:3;1356:1;1351:2;1342:6;1331:9;1327:22;1323:31;1316:42;1485:2;1415:66;1410:2;1402:6;1398:15;1394:88;1383:9;1379:104;1375:113;1367:121;;;;887:607;;;;:::o;2109:184::-;2161:77;2158:1;2151:88;2258:4;2255:1;2248:15;2282:4;2279:1;2272:15;2298:168;2371:9;;;2402;;2419:15;;;2413:22;;2399:37;2389:71;;2440:18;;:::i;2471:184::-;2523:77;2520:1;2513:88;2620:4;2617:1;2610:15;2644:4;2641:1;2634:15;2660:120;2700:1;2726;2716:35;;2731:18;;:::i;:::-;-1:-1:-1;2765:9:26;;2660:120::o;2785:592::-;2946:6;2954;2962;3015:2;3003:9;2994:7;2990:23;2986:32;2983:52;;;3031:1;3028;3021:12;2983:52;3063:9;3057:16;3082:31;3107:5;3082:31;:::i;:::-;3182:2;3167:18;;3161:25;3132:5;;-1:-1:-1;3195:33:26;3161:25;3195:33;:::i;:::-;3299:2;3284:18;;3278:25;3247:7;;-1:-1:-1;3312:33:26;3278:25;3312:33;:::i;3382:184::-;3452:6;3505:2;3493:9;3484:7;3480:23;3476:32;3473:52;;;3521:1;3518;3511:12;3473:52;-1:-1:-1;3544:16:26;;3382:184;-1:-1:-1;3382:184:26:o;3571:277::-;3638:6;3691:2;3679:9;3670:7;3666:23;3662:32;3659:52;;;3707:1;3704;3697:12;3659:52;3739:9;3733:16;3792:5;3785:13;3778:21;3771:5;3768:32;3758:60;;3814:1;3811;3804:12;3853:305;3923:6;3976:2;3964:9;3955:7;3951:23;3947:32;3944:52;;;3992:1;3989;3982:12;3944:52;4024:9;4018:16;4074:34;4067:5;4063:46;4056:5;4053:57;4043:85;;4124:1;4121;4114:12;4163:128;4230:9;;;4251:11;;;4248:37;;;4265:18;;:::i;4296:184::-;4348:77;4345:1;4338:88;4445:4;4442:1;4435:15;4469:4;4466:1;4459:15;4485:252;4557:2;4551:9;4599:3;4587:16;;4633:18;4618:34;;4654:22;;;4615:62;4612:88;;;4680:18;;:::i;:::-;4716:2;4709:22;4485:252;:::o;4742:334::-;4813:2;4807:9;4869:2;4859:13;;4874:66;4855:86;4843:99;;4972:18;4957:34;;4993:22;;;4954:62;4951:88;;;5019:18;;:::i;:::-;5055:2;5048:22;4742:334;;-1:-1:-1;4742:334:26:o;5081:138::-;5160:13;;5182:31;5160:13;5182:31;:::i;5224:804::-;5322:6;5375:3;5363:9;5354:7;5350:23;5346:33;5343:53;;;5392:1;5389;5382:12;5343:53;5418:22;;:::i;:::-;5469:9;5463:16;5456:5;5449:31;5533:2;5522:9;5518:18;5512:25;5507:2;5500:5;5496:14;5489:49;5591:2;5580:9;5576:18;5570:25;5565:2;5558:5;5554:14;5547:49;5628;5673:2;5662:9;5658:18;5628:49;:::i;:::-;5623:2;5616:5;5612:14;5605:73;5732:3;5721:9;5717:19;5711:26;5705:3;5698:5;5694:15;5687:51;5792:3;5781:9;5777:19;5771:26;5765:3;5758:5;5754:15;5747:51;5852:3;5841:9;5837:19;5831:26;5825:3;5818:5;5814:15;5807:51;5912:3;5901:9;5897:19;5891:26;5885:3;5878:5;5874:15;5867:51;5937:3;5993:2;5982:9;5978:18;5972:25;5967:2;5960:5;5956:14;5949:49;;6017:5;6007:15;;;5224:804;;;;:::o;6033:216::-;6097:9;;;6125:11;;;6072:3;6155:9;;6183:10;;6179:19;;6208:10;;6200:19;;6176:44;6173:70;;;6223:18;;:::i;6254:200::-;6320:9;;;6293:4;6348:9;;6376:10;;6388:12;;;6372:29;6411:12;;;6403:21;;6369:56;6366:82;;;6428:18;;:::i;6791:184::-;6843:77;6840:1;6833:88;6940:4;6937:1;6930:15;6964:4;6961:1;6954:15;6980:647;7149:2;7201:21;;;7271:13;;7174:18;;;7293:22;;;7120:4;;7149:2;7372:15;;;;7346:2;7331:18;;;7120:4;7415:186;7429:6;7426:1;7423:13;7415:186;;;7494:13;;7509:10;7490:30;7478:43;;7576:15;;;;7541:12;;;;7451:1;7444:9;7415:186;;;-1:-1:-1;7618:3:26;;6980:647;-1:-1:-1;;;;;;6980:647:26:o;7632:1087::-;7727:6;7758:2;7801;7789:9;7780:7;7776:23;7772:32;7769:52;;;7817:1;7814;7807:12;7769:52;7850:9;7844:16;7879:18;7920:2;7912:6;7909:14;7906:34;;;7936:1;7933;7926:12;7906:34;7974:6;7963:9;7959:22;7949:32;;8019:7;8012:4;8008:2;8004:13;8000:27;7990:55;;8041:1;8038;8031:12;7990:55;8070:2;8064:9;8092:2;8088;8085:10;8082:36;;;8098:18;;:::i;:::-;8144:2;8141:1;8137:10;8127:20;;8167:28;8191:2;8187;8183:11;8167:28;:::i;:::-;8229:15;;;8299:11;;;8295:20;;;8260:12;;;;8327:19;;;8324:39;;;8359:1;8356;8349:12;8324:39;8383:11;;;;8403:286;8419:6;8414:3;8411:15;8403:286;;;8492:3;8486:10;8473:23;;8540:56;8533:5;8529:68;8522:5;8519:79;8509:107;;8612:1;8609;8602:12;8509:107;8629:18;;;8436:12;;;;8667;;;;8403:286;;;8708:5;7632:1087;-1:-1:-1;;;;;;;;7632:1087:26:o;8724:222::-;8793:56;8882:10;;;8870;;;8866:27;;8905:12;;;8902:38;;;8920:18;;:::i;8951:238::-;8991:1;9017:56;9100:2;9097:1;9093:10;9122:3;9112:37;;9129:18;;:::i;:::-;9167:10;;9163:20;;;;;8951:238;-1:-1:-1;;8951:238:26:o;9194:292::-;9266:9;;;9233:7;9291:9;;9308:66;9302:73;;9287:89;9284:115;;;9379:18;;:::i;:::-;9452:1;9443:7;9438:16;9435:1;9432:23;9428:1;9421:9;9418:38;9408:72;;9460:18;;:::i;9740:308::-;9779:1;9805;9795:35;;9810:18;;:::i;:::-;9927:66;9924:1;9921:73;9852:66;9849:1;9846:73;9842:153;9839:179;;;9998:18;;:::i;:::-;-1:-1:-1;10032:10:26;;9740:308::o;10398:191::-;10433:3;10464:66;10457:5;10454:77;10451:103;;10534:18;;:::i;:::-;-1:-1:-1;10574:1:26;10570:13;;10398:191::o
Swarm Source
ipfs://45d742e7b9ae55402108a9e67b0fca704eb81acbd9384323edd31ea4f0fdfa3a
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 33 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.