Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00| Transaction Hash |
Method
|
Block
|
From
|
|
To
|
||||
|---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Advanced mode:
| Parent Transaction Hash | Method | Block |
From
|
|
To
|
||
|---|---|---|---|---|---|---|---|
| 0x61016080 | 23238394 | 87 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x68E07c01...E3D502645 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
PendleChainlinkOracle
Compiler Version
v0.8.24+commit.e11b9ed9
Optimization Enabled:
Yes with 1000000 runs
Other Settings:
shanghai EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;
import "../../../interfaces/IPChainlinkOracle.sol";
import "../PendleLpOracleLib.sol";
/**
* @dev The round data returned from this contract will follow:
* - There will be only one round (roundId=0)
* - startedAt=0, updatedAt=block.timestamp
*/
contract PendleChainlinkOracle is IPChainlinkOracle {
error InvalidRoundId();
// solhint-disable immutable-vars-naming
address public immutable factory;
address public immutable market;
uint32 public immutable twapDuration;
PendleOracleType public immutable baseOracleType;
uint256 public immutable fromTokenScale;
uint256 public immutable toTokenScale;
function(IPMarket, uint32) internal view returns (uint256) private immutable _getRawPendlePrice;
modifier roundIdIsZero(uint80 roundId) {
if (roundId != 0) {
revert InvalidRoundId();
}
_;
}
constructor(address _market, uint32 _twapDuration, PendleOracleType _baseOracleType) {
factory = msg.sender;
market = _market;
twapDuration = _twapDuration;
baseOracleType = _baseOracleType;
(uint256 fromTokenDecimals, uint256 toTokenDecimals) = _readDecimals(_market, _baseOracleType);
(fromTokenScale, toTokenScale) = (10 ** fromTokenDecimals, 10 ** toTokenDecimals);
_getRawPendlePrice = _getRawPendlePriceFunc();
}
// =================================================================
// CHAINLINK INTERFACE
// =================================================================
/**
* @notice The round data returned from this contract will follow:
* - answer will satisfy 1 natural unit of PendleToken = (answer/1e18) natural unit of OutputToken
* - In other words, 10**(PendleToken.decimals) = (answer/1e18) * 10**(OutputToken.decimals)
* @param roundId always 0 for this contract
* @param answer The answer (in 18 decimals)
* @param startedAt always 0 for this contract
* @param updatedAt always block.timestamp for this contract
* @param answeredInRound always 0 for this contract
*/
function latestRoundData()
public
view
virtual
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
{
roundId = 0;
answer = _getPendleTokenPrice();
startedAt = 0;
updatedAt = block.timestamp;
answeredInRound = 0;
}
function getRoundData(
uint80 roundId
) external view roundIdIsZero(roundId) returns (uint80, int256, uint256, uint256, uint80) {
return latestRoundData();
}
function decimals() external pure returns (uint8) {
return 18;
}
function description() external pure returns (string memory) {
return "Pendle Chainlink-compatible Oracle";
}
function version() external pure returns (uint256) {
return 1;
}
// =================================================================
// PRICING FUNCTIONS
// =================================================================
function _getPendleTokenPrice() internal view returns (int256) {
return _descalePrice(_getRawPendlePrice(IPMarket(market), twapDuration));
}
function _descalePrice(uint256 price) private view returns (int256 unwrappedPrice) {
return PMath.Int((price * fromTokenScale) / toTokenScale);
}
// =================================================================
// USE ONLY AT INITIALIZATION
// =================================================================
function _getRawPendlePriceFunc()
internal
view
returns (function(IPMarket, uint32) internal view returns (uint256))
{
if (baseOracleType == PendleOracleType.PT_TO_SY) {
return PendlePYOracleLib.getPtToSyRate;
} else if (baseOracleType == PendleOracleType.PT_TO_ASSET) {
return PendlePYOracleLib.getPtToAssetRate;
} else if (baseOracleType == PendleOracleType.LP_TO_SY) {
return PendleLpOracleLib.getLpToSyRate;
} else if (baseOracleType == PendleOracleType.LP_TO_ASSET) {
return PendleLpOracleLib.getLpToAssetRate;
} else {
revert("not supported");
}
}
function _readDecimals(
address _market,
PendleOracleType _oracleType
) internal view returns (uint8 _fromDecimals, uint8 _toDecimals) {
(IStandardizedYield SY, , ) = IPMarket(_market).readTokens();
uint8 syDecimals = SY.decimals();
(, , uint8 assetDecimals) = SY.assetInfo();
if (_oracleType == PendleOracleType.PT_TO_ASSET) {
return (assetDecimals, assetDecimals);
} else if (_oracleType == PendleOracleType.PT_TO_SY) {
return (assetDecimals, syDecimals);
} else if (_oracleType == PendleOracleType.LP_TO_ASSET) {
return (18, assetDecimals);
} else if (_oracleType == PendleOracleType.LP_TO_SY) {
return (18, syDecimals);
} else {
revert("not supported");
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(
uint80 _roundId
) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
function latestRoundData()
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated 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;
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
// 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
// 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 tweakUp(uint256 a, uint256 factor) internal pure returns (uint256) {
return mulDown(a, ONE + factor);
}
function tweakDown(uint256 a, uint256 factor) internal pure returns (uint256) {
return mulDown(a, ONE - factor);
}
/// @return res = min(a + b, bound)
/// @dev This function should handle arithmetic operation and bound check without overflow/underflow
function addWithUpperBound(uint256 a, uint256 b, uint256 bound) internal pure returns (uint256 res) {
unchecked {
if (type(uint256).max - b < a) res = bound;
else res = min(bound, a + b);
}
}
/// @return res = max(a - b, bound)
/// @dev This function should handle arithmetic operation and bound check without overflow/underflow
function subWithLowerBound(uint256 a, uint256 b, uint256 bound) internal pure returns (uint256 res) {
unchecked {
if (b > a) res = bound;
else res = max(a - b, bound);
}
}
function clamp(uint256 x, uint256 lower, uint256 upper) internal pure returns (uint256 res) {
res = x;
if (x < lower) res = lower;
else if (x > upper) res = upper;
}
// @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 Uint80(uint256 x) internal pure returns (uint80) {
require(x <= type(uint80).max);
return uint80(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: 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;
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
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 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;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
enum PendleOracleType {
PT_TO_SY,
PT_TO_ASSET,
LP_TO_SY,
LP_TO_ASSET
}
interface IPChainlinkOracle is AggregatorV3Interface {}// 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;
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
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;
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 IRewardManager {
function userReward(address token, address user) external view returns (uint128 index, uint128 accrued);
}// 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 "./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-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) {
if (duration == 0) {
(,,uint96 lnImpliedRate,,,) = IPMarket(market)._storage();
return uint256(lnImpliedRate);
}
uint32[] memory durations = new uint32[](2);
durations[0] = duration;
uint216[] memory lnImpliedRateCumulative = market.observe(durations);
return (lnImpliedRateCumulative[1] - lnImpliedRateCumulative[0]) / duration;
}
}{
"optimizer": {
"enabled": true,
"runs": 1000000
},
"viaIR": true,
"evmVersion": "shanghai",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint32","name":"_twapDuration","type":"uint32"},{"internalType":"enum PendleOracleType","name":"_baseOracleType","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidRoundId","type":"error"},{"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":"baseOracleType","outputs":[{"internalType":"enum PendleOracleType","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"description","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fromTokenScale","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint80","name":"roundId","type":"uint80"}],"name":"getRoundData","outputs":[{"internalType":"uint80","name":"","type":"uint80"},{"internalType":"int256","name":"","type":"int256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint80","name":"","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"market","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"toTokenScale","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"twapDuration","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]Contract Creation Code
0x610160806040523462000116576060816200255a80380380916200002482856200011a565b83398101031262000116576200003a8162000152565b9060208101519063ffffffff821682036200011657604001516004811015620001165760ff6200008c620000846200009493868496336080528160a05260c0528160e05262000199565b941662000167565b921662000167565b610120908152610100918252620000aa620003d9565b610140908152604051916120f3938462000467853960805184610196015260a05184818161028001526111d3015260c0518481816104d901526111f5015260e0518461052d015251838181610443015261129301525182818161012901526112ba015251816112160152f35b5f80fd5b601f909101601f19168101906001600160401b038211908210176200013e57604052565b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036200011657565b604d81116200017657600a0a90565b634e487b7160e01b5f52601160045260245ffd5b519060ff821682036200011657565b60408051630b2339af60e21b81526060949392600492916001600160a01b0391879082908690829086165afa9081156200032e575f9162000380575b50825163313ce56760e01b81529491166020858581845afa9485156200032e579087915f9662000338575b508351630a40bee560e41b815291908290869082905afa9687156200032e575f97620002d2575b505082811015620002bf57600181036200024357505050508190565b9294928062000253575050509190565b9294926003810362000269575050505060129190565b92945090916002036200027e57505060129190565b620002bb92505191829162461bcd60e51b8352820160609060208152600d60208201526c1b9bdd081cdd5c1c1bdc9d1959609a1b60408201520190565b0390fd5b602183634e487b7160e01b5f525260245ffd5b9080929750813d831162000326575b620002ed81836200011a565b810103126200011657600281511015620001165781816200031560206200031d940162000152565b50016200018a565b945f8062000227565b503d620002e1565b83513d5f823e3d90fd5b915094506020813d60201162000377575b8162000358602093836200011a565b810103126200011657866200036e85926200018a565b95909162000200565b3d915062000349565b90508681813d8311620003d1575b6200039a81836200011a565b8101031262000116578051908282168203620001165760208101518381160362000116578301518281160362000116575f620001d5565b503d6200038e565b60e0516004811015620004525780620003f25750600490565b60018103620004015750600390565b60028103620004105750600290565b6003036200041d57600190565b60405162461bcd60e51b815260206004820152600d60248201526c1b9bdd081cdd5c1c1bdc9d1959609a1b6044820152606490fd5b634e487b7160e01b5f52602160045260245ffdfe6080604090808252600480361015610015575f80fd5b5f3560e01c9182630aa33a24146104fd5750816326d895451461049f578163313ce567146104665781634ae5fa9b1461040e57816354fd4d50146103d55781637284e416146102a457816380f55605146102365781639a6fc8f5146101ba57508063c45a01551461014c578063ee81d997146100f45763feaf968c14610099575f80fd5b346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f05760a0905f6100d36111bc565b9180519282845260208401528201524260608201525f6080820152f35b5f80fd5b50346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b82346100f05760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057813569ffffffffffffffffffff81168091036100f0576102105760a0905f6100d36111bc565b517fbfbe031f000000000000000000000000000000000000000000000000000000008152fd5b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057805191606083019083821067ffffffffffffffff8311176103a9575081526022825260207f50656e646c6520436861696e6c696e6b2d636f6d70617469626c65204f72616360208401527f6c65000000000000000000000000000000000000000000000000000000000000828401528151928391602083528151918260208501525f5b8381106103935750505f83830185015250601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168101030190f35b8181018301518782018701528694508201610356565b6041907f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905160018152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905160128152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905163ffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0577f00000000000000000000000000000000000000000000000000000000000000008281101561055c57602092508152f35b6021837f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b90670de0b6b3a7640000918281029281840414901517156105a557565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b818102929181159184041417156105a557565b81156105ef570490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b9061063261062983610762565b92839194610a89565b9181811061063f57505090565b61064c90610651936105d2565b6105e5565b90565b61066961066082610762565b93849193610a89565b9180821061067e575061064c61065192610588565b905061064c61065192610588565b9061069682610762565b908181106106a9575050610651916110a0565b6106ba61064c9293610651956110a0565b6105d2565b6106c881610762565b9091908083106106e55750610651926106e0916110a0565b61106f565b9150610651926106e0916110a0565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761073557604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b9073ffffffffffffffffffffffffffffffffffffffff80606060409460048651809481937f2c8ce6bc000000000000000000000000000000000000000000000000000000008352165afa938415610948575f915f956109fb575b50828151927f3ba0b9a9000000000000000000000000000000000000000000000000000000008452836004816020978894165afa9283156109c2575f936109cc575b50829516908051937fd2a3584e0000000000000000000000000000000000000000000000000000000085528085600481865afa9485156109c2575f95610993575b508151927f516399df0000000000000000000000000000000000000000000000000000000084528184600481845afa938415610989575f94610951575b50836108a2575b5050505f14610890575090565b908082111561089d575090565b905090565b829350819060049351938480927f60e0a9e10000000000000000000000000000000000000000000000000000000082525afa92831561094857505f92610901575b50506fffffffffffffffffffffffffffffffff1643145f8080610883565b90809250813d8311610941575b61091881836106f4565b810103126100f057516fffffffffffffffffffffffffffffffff811681036100f0575f806108e3565b503d61090e565b513d5f823e3d90fd5b9093508181813d8311610982575b61096981836106f4565b810103126100f0575180151581036100f057925f61087c565b503d61095f565b83513d5f823e3d90fd5b9080955081813d83116109bb575b6109ab81836106f4565b810103126100f05751935f61083f565b503d6109a1565b82513d5f823e3d90fd5b9092508381813d83116109f4575b6109e481836106f4565b810103126100f05751915f6107fe565b503d6109da565b915093506060813d606011610a4e575b81610a18606093836106f4565b810103126100f05780519082821682036100f0576020810151838116036100f0578401519082821682036100f05790935f6107bc565b3d9150610a0b565b81810392915f1380158285131691841216176105a557565b9190915f83820193841291129080158216911516176105a557565b909173ffffffffffffffffffffffffffffffffffffffff9260409283517f794052f30000000000000000000000000000000000000000000000000000000081526004905f82820152610120602491818184818c89165afa988915611065575f99610f92575b50505060a0870180519093904210610b415750505050508291610b28610b3292610b22610b379651916020870151906117ff565b90610a6e565b925b015191611341565b6113b6565b5f81126100f05790565b86519495936080860167ffffffffffffffff811187821017610f675788525f865260208601965f8852888701925f84525f60608901524283511115610f3f57610b8b428451611093565b9660808c01516301e1338090818102918183051490151715610ee9577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff89116100f0578815610f14577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff89147f8000000000000000000000000000000000000000000000000000000000000000821416610ee9578890055f811315610ebb57895260208c0151610c3a916117ff565b808a528b5180158015610eb3575b610e7f5750508a51966101008c0151978a5198610c67838c5192611bf3565b91670de0b6b3a76400009a8b8412610e505790610b32610c8a610c909383610a6e565b91611341565b8a8114610e2857808b03905f81128c83128116908d841390151617610dfd578f90610d5a98610d346101009f9e9d9c9b978f8f9b610d549b610d24926060610d1c610d2d968f610d4e9f60029f90610d439f610d1092610d3e9f610d05610d00610d0a94610b32610b3294611341565b611c33565b611341565b90610a56565b905260c08c0151611bf3565b910152611911565b92429051611093565b8092611bf3565b9e8f930151611bf3565b610a6e565b05985191518a610a56565b9061135e565b05611425565b91610d8085610b32610d7a87610d718c518961135e565b058d5190610a56565b95611341565b809401938412600116610dd3575050610b37969593610b32610d05610dc5610dcd96610d0a610db9610b329b98610b32610b2299611341565b975191610b3289611341565b948951610a6e565b92610b2a565b6011907f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b8960118c7f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b898e517fa9c8b14d000000000000000000000000000000000000000000000000000000008152fd5b898f858d9151917fca78c8a4000000000000000000000000000000000000000000000000000000008352820152fd5b6044918789928e51937fb1c4aefb000000000000000000000000000000000000000000000000000000008552840152820152fd5b508115610c48565b8787918d51917f1ca41876000000000000000000000000000000000000000000000000000000008352820152fd5b866011897f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b866012897f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b858a517fb2094b59000000000000000000000000000000000000000000000000000000008152fd5b836041867f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b90918093995082813d831161105e575b610fac81836106f4565b810103126100f057875192830183811067ffffffffffffffff82111761103357885281518352602082015160208401528782015188840152606082015190811681036100f05760608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e08301526101008091015190820152955f8080610aee565b896041867f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b503d610fa2565b88513d5f823e3d90fd5b90670de0b6b3a7640000918281029281840414901517156105a557610651916105e5565b919082039182116105a557565b6040517fe184c9be00000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff86165afa9081156111b1575f9161117f575b5042811161110a57505050670de0b6b3a764000090565b61112761111f6301e133809461112d94611911565b914290611093565b906105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05761115e90611425565b5f81126100f05780156105ef576ec097ce7bc90715b34b9f10000000000490565b90506020813d6020116111a9575b8161119a602093836106f4565b810103126100f057515f6110f3565b3d915061118d565b6040513d5f823e3d90fd5b73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000167f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000080600114611330578060021461131f578060031461130957600414611281577f4e487b71000000000000000000000000000000000000000000000000000000005f52605160045260245ffd5b6112916112b8916112df936106bf565b7f0000000000000000000000000000000000000000000000000000000000000000906105d2565b7f0000000000000000000000000000000000000000000000000000000000000000906105e5565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05790565b5061131a6112b8916112df9361068c565b611291565b5061131a6112b8916112df93610654565b5061131a6112b8916112df9361061c565b90670de0b6b3a7640000918281029281840514901517156105a557565b81810292915f82127f80000000000000000000000000000000000000000000000000000000000000008214166105a55781840514901517156105a557565b80156105ef576ec097ce7bc90715b34b9f10000000000590565b81156105ef570590565b156113c757565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f496e76616c6964206578706f6e656e74000000000000000000000000000000006044820152fd5b7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc0000811215806117ec575b611458906113c0565b5f81126117d8576064906806f05b59d3b20000008112611775577ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e0000000168056bc75e2d6310000082770195e54c5dd42177f53a27172fa9ec630262827000000000925b02819068ad78ebc5ac6200000081121561173c575b6856bc75e2d631000000811215611702575b682b5e3af16b188000008112156116ca575b6815af1d78b58c400000811215611692575b680ad78ebc5ac620000081121561165b575b82811215611624575b6802b5e3af16b18800008112156115ed575b68015af1d78b58c400008112156115b6575b60028382800205056003848383020505600485848302050585600581868402050560068287830205056007838883020505906008848984020505926009858a8602050595600a868b8902050597600b878c8b02050599600c888d8d0205059b0101010101010101010101010205020590565b6806f5f17757889379377ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000084920192020590611544565b6808f00f760a4b2db55d7ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000084920192020590611532565b680ebc5fb417461211107ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000084920192020590611520565b68280e60114edb805d037ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000084920192020590611517565b690127fa27722cc06cc5e27fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c0000084920192020590611505565b693f1fce3da636ea5cf8507fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800000849201920205906114f3565b6b02df0ab5a80a22c61ab5a7007fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000000849201920205906114e1565b6e01855144814a7ff805980ff008400091507fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000000016114cf565b6803782dace9d900000081126117c5577ffffffffffffffffffffffffffffffffffffffffffffffffc87d25316270000000168056bc75e2d63100000826b1425982cf597cd205cef7380926114ba565b68056bc75e2d63100000826001926114ba565b6117e3905f03611425565b6106519061139c565b5068070c1cc73b00c8000081131561144f565b5f8212156118b2577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff915b5f81131561187657670de0b6b3a764000091611845916105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f0576106519161135e565b7f800000000000000000000000000000000000000000000000000000000000000081146105a557670de0b6b3a764000091611845915f036105d2565b60019161182a565b519081600f0b82036100f057565b519061ffff821682036100f057565b8051156118e45760200190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b9063ffffffff809116908115611af6576040928351606081019167ffffffffffffffff928281108482111761073557865260028252602091828101873682378661195a836118d7565b5287519586927f883bdbfd0000000000000000000000000000000000000000000000000000000084526024840190866004860152518091526044840192915f905b87838310611ad9575050505050918173ffffffffffffffffffffffffffffffffffffffff815f950392165afa928315611acf575f93611a22575b5050508051600110156118e457611a10927affffffffffffffffffffffffffffffffffffffffffffffffffffff9384809284015116926118d7565b511690038281116105a5578216041690565b909192503d805f833e611a3581836106f4565b81019082818303126100f0578051908482116100f0570181601f820112156100f0578051938411610735578360051b90865194611a74858401876106f4565b855283808601928201019283116100f0578301905b828210611a9c57505050505f80806119d5565b81517affffffffffffffffffffffffffffffffffffffffffffffffffffff811681036100f0578152908301908301611a89565b85513d5f823e3d90fd5b8451821686528a965094850194909301926001919091019061199b565b505060c073ffffffffffffffffffffffffffffffffffffffff916004604051809481937fc3fb90d6000000000000000000000000000000000000000000000000000000008352165afa80156111b1575f90611b5f575b6bffffffffffffffffffffffff91501690565b5060c0813d60c011611beb575b81611b7960c093836106f4565b810103126100f057611b8a816118ba565b50611b97602082016118ba565b5060408101516bffffffffffffffffffffffff811681036100f057611be560a083611bd160606bffffffffffffffffffffffff96016118c8565b50611bde608082016118c8565b50016118c8565b50611b4c565b3d9150611b6c565b6301e1338091611c02916105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05761065190611425565b5f811315611d155780670c7d713b49da00001280611d04575b15611cfb57670de0b6b3a7640000906ec097ce7bc90715b34b9f100000000090611c9f908302828101907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f0000000000183026113b6565b9080828002059181838202058284820205838582020591848684020593858786020595808888020597880205600f900596600d900595600b900594600990059360079005926005900591600390050101010101010160011b0590565b61065190611d73565b50670f43fc2c04ee00008112611c4c565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6f7574206f6620626f756e6473000000000000000000000000000000000000006044820152fd5b670de0b6b3a764000081126120a7576064905f7e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c000000000000082121561207c575b73011798004d755d3c8bc8e03204cf44619e00000082121561205b575b820290808302906e01855144814a7ff805980ff00840009081831215612038575b50506b02df0ab5a80a22c61ab5a70080821215612018575b50693f1fce3da636ea5cf85080821215611ff8575b50690127fa27722cc06cc5e280821215611fd8575b5068280e60114edb805d0380821215611fb8575b50680ebc5fb4174612111080821215611fa1575b506808f00f760a4b2db55d80821215611f81575b506806f5f177578893793780821215611f61575b506806248f33704b28660380821215611f42575b506805c548670b9510e7ac80821215611f23575b50611ee268056bc75e2d6310000091827ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000008183019201026113b6565b9080828002059181838202058284820205916003600560076009600b888a89020598808b8b02059a8b0205059805960594059205010101010160011b010590565b68056bc75e2d631000006756bc75e2d63100009202059101905f611ea6565b68056bc75e2d6310000067ad78ebc5ac6200009202059101905f611e92565b68056bc75e2d6310000068015af1d78b58c400009202059101905f611e7e565b68056bc75e2d631000006802b5e3af16b18800009202059101905f611e6a565b68056bc75e2d63100000809202059101905f611e56565b68056bc75e2d63100000680ad78ebc5ac62000009202059101905f611e42565b68056bc75e2d631000006815af1d78b58c4000009202059101905f611e2e565b68056bc75e2d63100000682b5e3af16b188000009202059101905f611e19565b68056bc75e2d631000006856bc75e2d6310000009202059101905f611e04565b68ad78ebc5ac62000000925069021e19e0c9bab240000002059101905f80611dec565b906b1425982cf597cd205cef73806803782dace9d900000091059101611dcb565b50770195e54c5dd42177f53a27172fa9ec63026282700000000090056806f05b59d3b2000000611dae565b6120b36120b89161139c565b611d73565b5f039056fea26469706673582212209ff8249c142f6e0885939c4c49a82698a874e81534c962938dd51150f70e839d64736f6c634300081800330000000000000000000000003a4204255257698e379245ef94274ef3b290729600000000000000000000000000000000000000000000000000000000000007080000000000000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x6080604090808252600480361015610015575f80fd5b5f3560e01c9182630aa33a24146104fd5750816326d895451461049f578163313ce567146104665781634ae5fa9b1461040e57816354fd4d50146103d55781637284e416146102a457816380f55605146102365781639a6fc8f5146101ba57508063c45a01551461014c578063ee81d997146100f45763feaf968c14610099575f80fd5b346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f05760a0905f6100d36111bc565b9180519282845260208401528201524260608201525f6080820152f35b5f80fd5b50346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057602090517f0000000000000000000000000000000000000000000000000de0b6b3a76400008152f35b50346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000009e5129dcc15d39625617dcd7f0f44fb0bb957ffd168152f35b82346100f05760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057813569ffffffffffffffffffff81168091036100f0576102105760a0905f6100d36111bc565b517fbfbe031f000000000000000000000000000000000000000000000000000000008152fd5b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000003a4204255257698e379245ef94274ef3b2907296168152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057805191606083019083821067ffffffffffffffff8311176103a9575081526022825260207f50656e646c6520436861696e6c696e6b2d636f6d70617469626c65204f72616360208401527f6c65000000000000000000000000000000000000000000000000000000000000828401528151928391602083528151918260208501525f5b8381106103935750505f83830185015250601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168101030190f35b8181018301518782018701528694508201610356565b6041907f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905160018152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f057602090517f00000000000000000000000000000000000000000000000000000000000f42408152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905160128152f35b82346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0576020905163ffffffff7f0000000000000000000000000000000000000000000000000000000000000708168152f35b346100f0575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100f0577f00000000000000000000000000000000000000000000000000000000000000008281101561055c57602092508152f35b6021837f4e487b71000000000000000000000000000000000000000000000000000000005f525260245ffd5b90670de0b6b3a7640000918281029281840414901517156105a557565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b818102929181159184041417156105a557565b81156105ef570490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b9061063261062983610762565b92839194610a89565b9181811061063f57505090565b61064c90610651936105d2565b6105e5565b90565b61066961066082610762565b93849193610a89565b9180821061067e575061064c61065192610588565b905061064c61065192610588565b9061069682610762565b908181106106a9575050610651916110a0565b6106ba61064c9293610651956110a0565b6105d2565b6106c881610762565b9091908083106106e55750610651926106e0916110a0565b61106f565b9150610651926106e0916110a0565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761073557604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b9073ffffffffffffffffffffffffffffffffffffffff80606060409460048651809481937f2c8ce6bc000000000000000000000000000000000000000000000000000000008352165afa938415610948575f915f956109fb575b50828151927f3ba0b9a9000000000000000000000000000000000000000000000000000000008452836004816020978894165afa9283156109c2575f936109cc575b50829516908051937fd2a3584e0000000000000000000000000000000000000000000000000000000085528085600481865afa9485156109c2575f95610993575b508151927f516399df0000000000000000000000000000000000000000000000000000000084528184600481845afa938415610989575f94610951575b50836108a2575b5050505f14610890575090565b908082111561089d575090565b905090565b829350819060049351938480927f60e0a9e10000000000000000000000000000000000000000000000000000000082525afa92831561094857505f92610901575b50506fffffffffffffffffffffffffffffffff1643145f8080610883565b90809250813d8311610941575b61091881836106f4565b810103126100f057516fffffffffffffffffffffffffffffffff811681036100f0575f806108e3565b503d61090e565b513d5f823e3d90fd5b9093508181813d8311610982575b61096981836106f4565b810103126100f0575180151581036100f057925f61087c565b503d61095f565b83513d5f823e3d90fd5b9080955081813d83116109bb575b6109ab81836106f4565b810103126100f05751935f61083f565b503d6109a1565b82513d5f823e3d90fd5b9092508381813d83116109f4575b6109e481836106f4565b810103126100f05751915f6107fe565b503d6109da565b915093506060813d606011610a4e575b81610a18606093836106f4565b810103126100f05780519082821682036100f0576020810151838116036100f0578401519082821682036100f05790935f6107bc565b3d9150610a0b565b81810392915f1380158285131691841216176105a557565b9190915f83820193841291129080158216911516176105a557565b909173ffffffffffffffffffffffffffffffffffffffff9260409283517f794052f30000000000000000000000000000000000000000000000000000000081526004905f82820152610120602491818184818c89165afa988915611065575f99610f92575b50505060a0870180519093904210610b415750505050508291610b28610b3292610b22610b379651916020870151906117ff565b90610a6e565b925b015191611341565b6113b6565b5f81126100f05790565b86519495936080860167ffffffffffffffff811187821017610f675788525f865260208601965f8852888701925f84525f60608901524283511115610f3f57610b8b428451611093565b9660808c01516301e1338090818102918183051490151715610ee9577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff89116100f0578815610f14577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff89147f8000000000000000000000000000000000000000000000000000000000000000821416610ee9578890055f811315610ebb57895260208c0151610c3a916117ff565b808a528b5180158015610eb3575b610e7f5750508a51966101008c0151978a5198610c67838c5192611bf3565b91670de0b6b3a76400009a8b8412610e505790610b32610c8a610c909383610a6e565b91611341565b8a8114610e2857808b03905f81128c83128116908d841390151617610dfd578f90610d5a98610d346101009f9e9d9c9b978f8f9b610d549b610d24926060610d1c610d2d968f610d4e9f60029f90610d439f610d1092610d3e9f610d05610d00610d0a94610b32610b3294611341565b611c33565b611341565b90610a56565b905260c08c0151611bf3565b910152611911565b92429051611093565b8092611bf3565b9e8f930151611bf3565b610a6e565b05985191518a610a56565b9061135e565b05611425565b91610d8085610b32610d7a87610d718c518961135e565b058d5190610a56565b95611341565b809401938412600116610dd3575050610b37969593610b32610d05610dc5610dcd96610d0a610db9610b329b98610b32610b2299611341565b975191610b3289611341565b948951610a6e565b92610b2a565b6011907f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b8960118c7f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b898e517fa9c8b14d000000000000000000000000000000000000000000000000000000008152fd5b898f858d9151917fca78c8a4000000000000000000000000000000000000000000000000000000008352820152fd5b6044918789928e51937fb1c4aefb000000000000000000000000000000000000000000000000000000008552840152820152fd5b508115610c48565b8787918d51917f1ca41876000000000000000000000000000000000000000000000000000000008352820152fd5b866011897f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b866012897f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b858a517fb2094b59000000000000000000000000000000000000000000000000000000008152fd5b836041867f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b90918093995082813d831161105e575b610fac81836106f4565b810103126100f057875192830183811067ffffffffffffffff82111761103357885281518352602082015160208401528782015188840152606082015190811681036100f05760608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e08301526101008091015190820152955f8080610aee565b896041867f4e487b71000000000000000000000000000000000000000000000000000000005f52525ffd5b503d610fa2565b88513d5f823e3d90fd5b90670de0b6b3a7640000918281029281840414901517156105a557610651916105e5565b919082039182116105a557565b6040517fe184c9be00000000000000000000000000000000000000000000000000000000815260208160048173ffffffffffffffffffffffffffffffffffffffff86165afa9081156111b1575f9161117f575b5042811161110a57505050670de0b6b3a764000090565b61112761111f6301e133809461112d94611911565b914290611093565b906105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05761115e90611425565b5f81126100f05780156105ef576ec097ce7bc90715b34b9f10000000000490565b90506020813d6020116111a9575b8161119a602093836106f4565b810103126100f057515f6110f3565b3d915061118d565b6040513d5f823e3d90fd5b73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000003a4204255257698e379245ef94274ef3b2907296167f00000000000000000000000000000000000000000000000000000000000007087f000000000000000000000000000000000000000000000000000000000000000480600114611330578060021461131f578060031461130957600414611281577f4e487b71000000000000000000000000000000000000000000000000000000005f52605160045260245ffd5b6112916112b8916112df936106bf565b7f00000000000000000000000000000000000000000000000000000000000f4240906105d2565b7f0000000000000000000000000000000000000000000000000de0b6b3a7640000906105e5565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05790565b5061131a6112b8916112df9361068c565b611291565b5061131a6112b8916112df93610654565b5061131a6112b8916112df9361061c565b90670de0b6b3a7640000918281029281840514901517156105a557565b81810292915f82127f80000000000000000000000000000000000000000000000000000000000000008214166105a55781840514901517156105a557565b80156105ef576ec097ce7bc90715b34b9f10000000000590565b81156105ef570590565b156113c757565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f496e76616c6964206578706f6e656e74000000000000000000000000000000006044820152fd5b7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc0000811215806117ec575b611458906113c0565b5f81126117d8576064906806f05b59d3b20000008112611775577ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e0000000168056bc75e2d6310000082770195e54c5dd42177f53a27172fa9ec630262827000000000925b02819068ad78ebc5ac6200000081121561173c575b6856bc75e2d631000000811215611702575b682b5e3af16b188000008112156116ca575b6815af1d78b58c400000811215611692575b680ad78ebc5ac620000081121561165b575b82811215611624575b6802b5e3af16b18800008112156115ed575b68015af1d78b58c400008112156115b6575b60028382800205056003848383020505600485848302050585600581868402050560068287830205056007838883020505906008848984020505926009858a8602050595600a868b8902050597600b878c8b02050599600c888d8d0205059b0101010101010101010101010205020590565b6806f5f17757889379377ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000084920192020590611544565b6808f00f760a4b2db55d7ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000084920192020590611532565b680ebc5fb417461211107ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000084920192020590611520565b68280e60114edb805d037ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000084920192020590611517565b690127fa27722cc06cc5e27fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c0000084920192020590611505565b693f1fce3da636ea5cf8507fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e7800000849201920205906114f3565b6b02df0ab5a80a22c61ab5a7007fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000000849201920205906114e1565b6e01855144814a7ff805980ff008400091507fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000000016114cf565b6803782dace9d900000081126117c5577ffffffffffffffffffffffffffffffffffffffffffffffffc87d25316270000000168056bc75e2d63100000826b1425982cf597cd205cef7380926114ba565b68056bc75e2d63100000826001926114ba565b6117e3905f03611425565b6106519061139c565b5068070c1cc73b00c8000081131561144f565b5f8212156118b2577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff915b5f81131561187657670de0b6b3a764000091611845916105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f0576106519161135e565b7f800000000000000000000000000000000000000000000000000000000000000081146105a557670de0b6b3a764000091611845915f036105d2565b60019161182a565b519081600f0b82036100f057565b519061ffff821682036100f057565b8051156118e45760200190565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b9063ffffffff809116908115611af6576040928351606081019167ffffffffffffffff928281108482111761073557865260028252602091828101873682378661195a836118d7565b5287519586927f883bdbfd0000000000000000000000000000000000000000000000000000000084526024840190866004860152518091526044840192915f905b87838310611ad9575050505050918173ffffffffffffffffffffffffffffffffffffffff815f950392165afa928315611acf575f93611a22575b5050508051600110156118e457611a10927affffffffffffffffffffffffffffffffffffffffffffffffffffff9384809284015116926118d7565b511690038281116105a5578216041690565b909192503d805f833e611a3581836106f4565b81019082818303126100f0578051908482116100f0570181601f820112156100f0578051938411610735578360051b90865194611a74858401876106f4565b855283808601928201019283116100f0578301905b828210611a9c57505050505f80806119d5565b81517affffffffffffffffffffffffffffffffffffffffffffffffffffff811681036100f0578152908301908301611a89565b85513d5f823e3d90fd5b8451821686528a965094850194909301926001919091019061199b565b505060c073ffffffffffffffffffffffffffffffffffffffff916004604051809481937fc3fb90d6000000000000000000000000000000000000000000000000000000008352165afa80156111b1575f90611b5f575b6bffffffffffffffffffffffff91501690565b5060c0813d60c011611beb575b81611b7960c093836106f4565b810103126100f057611b8a816118ba565b50611b97602082016118ba565b5060408101516bffffffffffffffffffffffff811681036100f057611be560a083611bd160606bffffffffffffffffffffffff96016118c8565b50611bde608082016118c8565b50016118c8565b50611b4c565b3d9150611b6c565b6301e1338091611c02916105d2565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116100f05761065190611425565b5f811315611d155780670c7d713b49da00001280611d04575b15611cfb57670de0b6b3a7640000906ec097ce7bc90715b34b9f100000000090611c9f908302828101907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f0000000000183026113b6565b9080828002059181838202058284820205838582020591848684020593858786020595808888020597880205600f900596600d900595600b900594600990059360079005926005900591600390050101010101010160011b0590565b61065190611d73565b50670f43fc2c04ee00008112611c4c565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6f7574206f6620626f756e6473000000000000000000000000000000000000006044820152fd5b670de0b6b3a764000081126120a7576064905f7e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c000000000000082121561207c575b73011798004d755d3c8bc8e03204cf44619e00000082121561205b575b820290808302906e01855144814a7ff805980ff00840009081831215612038575b50506b02df0ab5a80a22c61ab5a70080821215612018575b50693f1fce3da636ea5cf85080821215611ff8575b50690127fa27722cc06cc5e280821215611fd8575b5068280e60114edb805d0380821215611fb8575b50680ebc5fb4174612111080821215611fa1575b506808f00f760a4b2db55d80821215611f81575b506806f5f177578893793780821215611f61575b506806248f33704b28660380821215611f42575b506805c548670b9510e7ac80821215611f23575b50611ee268056bc75e2d6310000091827ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf000008183019201026113b6565b9080828002059181838202058284820205916003600560076009600b888a89020598808b8b02059a8b0205059805960594059205010101010160011b010590565b68056bc75e2d631000006756bc75e2d63100009202059101905f611ea6565b68056bc75e2d6310000067ad78ebc5ac6200009202059101905f611e92565b68056bc75e2d6310000068015af1d78b58c400009202059101905f611e7e565b68056bc75e2d631000006802b5e3af16b18800009202059101905f611e6a565b68056bc75e2d63100000809202059101905f611e56565b68056bc75e2d63100000680ad78ebc5ac62000009202059101905f611e42565b68056bc75e2d631000006815af1d78b58c4000009202059101905f611e2e565b68056bc75e2d63100000682b5e3af16b188000009202059101905f611e19565b68056bc75e2d631000006856bc75e2d6310000009202059101905f611e04565b68ad78ebc5ac62000000925069021e19e0c9bab240000002059101905f80611dec565b906b1425982cf597cd205cef73806803782dace9d900000091059101611dcb565b50770195e54c5dd42177f53a27172fa9ec63026282700000000090056806f05b59d3b2000000611dae565b6120b36120b89161139c565b611d73565b5f039056fea26469706673582212209ff8249c142f6e0885939c4c49a82698a874e81534c962938dd51150f70e839d64736f6c63430008180033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 33 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.