Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 1 internal transaction
Advanced mode:
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
18810010 | 213 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
ActionSwapYTV3
Compiler Version
v0.8.23+commit.f704f362
Optimization Enabled:
Yes with 1000000 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.17; import "./base/ActionBase.sol"; import "./base/CallbackHelper.sol"; import "../interfaces/IPActionSwapYTV3.sol"; contract ActionSwapYTV3 is CallbackHelper, IPActionSwapYTV3, ActionBase { using PMath for uint256; using MarketApproxPtInLib for MarketState; using MarketApproxPtOutLib for MarketState; using PYIndexLib for IPYieldToken; // ------------------ SWAP TOKEN FOR YT ------------------ function swapExactTokenForYt( address receiver, address market, uint256 minYtOut, ApproxParams calldata guessYtOut, TokenInput calldata input, LimitOrderData calldata limit ) external payable returns (uint256 netYtOut, uint256 netSyFee, uint256 netSyInterm) { (IStandardizedYield SY, , IPYieldToken YT) = IPMarket(market).readTokens(); netSyInterm = _mintSyFromToken(_entry_swapExactSyForYt(YT, limit), address(SY), 1, input); (netYtOut, netSyFee) = _swapExactSyForYt(receiver, market, SY, YT, netSyInterm, minYtOut, guessYtOut, limit); emit SwapYtAndToken( msg.sender, market, input.tokenIn, receiver, netYtOut.Int(), input.netTokenIn.neg(), netSyInterm ); } function swapExactSyForYt( address receiver, address market, uint256 exactSyIn, uint256 minYtOut, ApproxParams calldata guessYtOut, LimitOrderData calldata limit ) external returns (uint256 netYtOut, uint256 netSyFee) { (IStandardizedYield SY, , IPYieldToken YT) = IPMarket(market).readTokens(); _transferFrom(SY, msg.sender, _entry_swapExactSyForYt(YT, limit), exactSyIn); (netYtOut, netSyFee) = _swapExactSyForYt(receiver, market, SY, YT, exactSyIn, minYtOut, guessYtOut, limit); emit SwapYtAndSy(msg.sender, market, receiver, netYtOut.Int(), exactSyIn.neg()); } function _entry_swapExactSyForYt(IPYieldToken YT, LimitOrderData calldata limit) internal view returns (address) { return !_isEmptyLimit(limit) ? address(this) : address(YT); } function _swapExactSyForYt( address receiver, address market, IStandardizedYield SY, IPYieldToken YT, uint256 exactSyIn, uint256 minYtOut, ApproxParams calldata guessYtOut, LimitOrderData calldata limit ) internal returns (uint256 netYtOut, uint256 netSyFee) { uint256 netSyLeft = exactSyIn; bool doMarketOrder = true; if (!_isEmptyLimit(limit)) { (netSyLeft, netYtOut, netSyFee, doMarketOrder) = _fillLimit(receiver, SY, netSyLeft, limit); if (doMarketOrder) { _transferOut(address(SY), address(YT), netSyLeft); } } if (doMarketOrder) { (uint256 netYtOutMarket, ) = _readMarket(market).approxSwapExactSyForYt( YT.newIndex(), netSyLeft, block.timestamp, guessYtOut ); (, uint256 netSyFeeMarket) = IPMarket(market).swapExactPtForSy( address(YT), netYtOutMarket, // exactPtIn = netYtOut _encodeSwapExactSyForYt(receiver, YT) ); netYtOut += netYtOutMarket; netSyFee += netSyFeeMarket; } if (netYtOut < minYtOut) revert Errors.RouterInsufficientYtOut(netYtOut, minYtOut); } // ------------------ SWAP TOKEN FOR TOKEN ------------------ function swapExactYtForToken( address receiver, address market, uint256 exactYtIn, TokenOutput calldata output, LimitOrderData calldata limit ) external returns (uint256 netTokenOut, uint256 netSyFee, uint256 netSyInterm) { (IStandardizedYield SY, , IPYieldToken YT) = IPMarket(market).readTokens(); _transferFrom(YT, msg.sender, _entry_swapExactYtForSy(YT, limit), exactYtIn); (netSyInterm, netSyFee) = _swapExactYtForSy(address(SY), market, SY, YT, exactYtIn, 0, limit); netTokenOut = _redeemSyToToken(receiver, address(SY), netSyInterm, output, false); emit SwapYtAndToken( msg.sender, market, output.tokenOut, receiver, exactYtIn.neg(), netTokenOut.Int(), netSyInterm ); } function swapExactYtForSy( address receiver, address market, uint256 exactYtIn, uint256 minSyOut, LimitOrderData calldata limit ) external returns (uint256 netSyOut, uint256 netSyFee) { (IStandardizedYield SY, , IPYieldToken YT) = IPMarket(market).readTokens(); _transferFrom(YT, msg.sender, _entry_swapExactYtForSy(YT, limit), exactYtIn); (netSyOut, netSyFee) = _swapExactYtForSy(receiver, market, SY, YT, exactYtIn, minSyOut, limit); emit SwapYtAndSy(msg.sender, market, receiver, exactYtIn.neg(), netSyOut.Int()); } function _entry_swapExactYtForSy(IPYieldToken YT, LimitOrderData calldata limit) internal view returns (address) { return !_isEmptyLimit(limit) ? address(this) : address(YT); } function _swapExactYtForSy( address receiver, address market, IStandardizedYield SY, IPYieldToken YT, uint256 exactYtIn, uint256 minSyOut, LimitOrderData calldata limit ) internal returns (uint256 netSyOut, uint256 netSyFee) { uint256 netYtLeft = exactYtIn; bool doMarketOrder = true; if (!_isEmptyLimit(limit)) { (netYtLeft, netSyOut, netSyFee, doMarketOrder) = _fillLimit(receiver, YT, netYtLeft, limit); if (doMarketOrder) { _transferOut(address(YT), address(YT), netYtLeft); } } if (doMarketOrder) { uint256 preSyBalance = SY.balanceOf(receiver); (, uint256 netSyFeeMarket) = IPMarket(market).swapSyForExactPt( address(YT), netYtLeft, // exactPtOut = netYtLeft _encodeSwapYtForSy(receiver, YT) ); // avoid stack issue netSyFee += netSyFeeMarket; netSyOut += SY.balanceOf(receiver) - preSyBalance; } if (netSyOut < minSyOut) revert Errors.RouterInsufficientSyOut(netSyOut, minSyOut); } // ------------------ SWAP PT FOR YT ------------------ function swapExactPtForYt( address receiver, address market, uint256 exactPtIn, uint256 minYtOut, ApproxParams calldata guessTotalPtToSwap ) external returns (uint256 netYtOut, uint256 netSyFee) { (, IPPrincipalToken PT, IPYieldToken YT) = IPMarket(market).readTokens(); uint256 totalPtToSwap; (netYtOut, totalPtToSwap, netSyFee) = _readMarket(market).approxSwapExactPtForYt( YT.newIndex(), exactPtIn, block.timestamp, guessTotalPtToSwap ); _transferFrom(IERC20(PT), msg.sender, market, exactPtIn); IPMarket(market).swapExactPtForSy( address(YT), totalPtToSwap, _encodeSwapExactPtForYt(receiver, exactPtIn, minYtOut, YT) ); emit SwapPtAndYt(msg.sender, market, receiver, exactPtIn.neg(), netYtOut.Int()); } // ------------------ SWAP YT FOR PT ------------------ function swapExactYtForPt( address receiver, address market, uint256 exactYtIn, uint256 minPtOut, ApproxParams calldata guessTotalPtFromSwap ) external returns (uint256 netPtOut, uint256 netSyFee) { (, IPPrincipalToken PT, IPYieldToken YT) = IPMarket(market).readTokens(); uint256 totalPtFromSwap; (netPtOut, totalPtFromSwap, netSyFee) = _readMarket(market).approxSwapExactYtForPt( YT.newIndex(), exactYtIn, block.timestamp, guessTotalPtFromSwap ); if (netPtOut < minPtOut) revert Errors.RouterInsufficientPtOut(netPtOut, minPtOut); _transferFrom(IERC20(YT), msg.sender, address(YT), exactYtIn); IPMarket(market).swapSyForExactPt( address(this), totalPtFromSwap, _encodeSwapExactYtForPt(receiver, netPtOut, PT, YT) ); emit SwapPtAndYt(msg.sender, market, receiver, netPtOut.Int(), exactYtIn.neg()); } }
// 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/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated 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: MIT // OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value)); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value)); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0)); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: 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); // 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; } // @author Uniswap function sqrt(uint256 y) internal pure returns (uint256 z) { if (y > 3) { z = y; uint256 x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } } else if (y != 0) { z = 1; } } function square(uint256 x) internal pure returns (uint256) { return x * x; } function squareDown(uint256 x) internal pure returns (uint256) { return mulDown(x, x); } function abs(int256 x) internal pure returns (uint256) { return uint256(x > 0 ? x : -x); } function neg(int256 x) internal pure returns (int256) { return x * (-1); } function neg(uint256 x) internal pure returns (int256) { return Int(x) * (-1); } function max(uint256 x, uint256 y) internal pure returns (uint256) { return (x > y ? x : y); } function max(int256 x, int256 y) internal pure returns (int256) { return (x > y ? x : y); } function min(uint256 x, uint256 y) internal pure returns (uint256) { return (x < y ? x : y); } function min(int256 x, int256 y) internal pure returns (int256) { return (x < y ? x : y); } /*/////////////////////////////////////////////////////////////// SIGNED CASTS //////////////////////////////////////////////////////////////*/ function Int(uint256 x) internal pure returns (int256) { require(x <= uint256(type(int256).max)); return int256(x); } function Int128(int256 x) internal pure returns (int128) { require(type(int128).min <= x && x <= type(int128).max); return int128(x); } function Int128(uint256 x) internal pure returns (int128) { return Int128(Int(x)); } /*/////////////////////////////////////////////////////////////// UNSIGNED CASTS //////////////////////////////////////////////////////////////*/ function Uint(int256 x) internal pure returns (uint256) { require(x >= 0); return uint256(x); } function Uint32(uint256 x) internal pure returns (uint32) { require(x <= type(uint32).max); return uint32(x); } function Uint64(uint256 x) internal pure returns (uint64) { require(x <= type(uint64).max); return uint64(x); } function Uint112(uint256 x) internal pure returns (uint112) { require(x <= type(uint112).max); return uint112(x); } function Uint96(uint256 x) internal pure returns (uint96) { require(x <= type(uint96).max); return uint96(x); } function Uint128(uint256 x) internal pure returns (uint128) { require(x <= type(uint128).max); return uint128(x); } function Uint192(uint256 x) internal pure returns (uint192) { require(x <= type(uint192).max); return uint192(x); } function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) { return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps); } function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) { return a >= b && a <= mulDown(b, ONE + eps); } function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) { return a <= b && a >= mulDown(b, ONE - eps); } }
// SPDX-License-Identifier: 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 "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "../../interfaces/IWETH.sol"; abstract contract TokenHelper { using SafeERC20 for IERC20; address internal constant NATIVE = address(0); uint256 internal constant LOWER_BOUND_APPROVAL = type(uint96).max / 2; // some tokens use 96 bits for approval function _transferIn(address token, address from, uint256 amount) internal { if (token == NATIVE) require(msg.value == amount, "eth mismatch"); else if (amount != 0) IERC20(token).safeTransferFrom(from, address(this), amount); } function _transferFrom(IERC20 token, address from, address to, uint256 amount) internal { if (amount != 0) token.safeTransferFrom(from, to, amount); } function _transferOut(address token, address to, uint256 amount) internal { if (amount == 0) return; if (token == NATIVE) { (bool success, ) = to.call{value: amount}(""); require(success, "eth send failed"); } else { IERC20(token).safeTransfer(to, amount); } } function _transferOut(address[] memory tokens, address to, uint256[] memory amounts) internal { uint256 numTokens = tokens.length; require(numTokens == amounts.length, "length mismatch"); for (uint256 i = 0; i < numTokens; ) { _transferOut(tokens[i], to, amounts[i]); unchecked { i++; } } } function _selfBalance(address token) internal view returns (uint256) { return (token == NATIVE) ? address(this).balance : IERC20(token).balanceOf(address(this)); } function _selfBalance(IERC20 token) internal view returns (uint256) { return token.balanceOf(address(this)); } /// @notice Approves the stipulated contract to spend the given allowance in the given token /// @dev PLS PAY ATTENTION to tokens that requires the approval to be set to 0 before changing it function _safeApprove(address token, address to, uint256 value) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), "Safe Approve"); } function _safeApproveInf(address token, address to) internal { if (token == NATIVE) return; if (IERC20(token).allowance(address(this), to) < LOWER_BOUND_APPROVAL) { _safeApprove(token, to, 0); _safeApprove(token, to, type(uint256).max); } } function _wrap_unwrap_ETH(address tokenIn, address tokenOut, uint256 netTokenIn) internal { if (tokenIn == NATIVE) IWETH(tokenOut).deposit{value: netTokenIn}(); else IWETH(tokenIn).withdraw(netTokenIn); } }
// 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) / market.totalLp; } else { lpToAccount = netLpBySy; syUsed = syDesired; ptUsed = (market.totalPt * lpToAccount) / market.totalLp; } } if (lpToAccount <= 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: GPL-3.0-or-later pragma solidity ^0.8.0; import "../router/base/MarketApproxLib.sol"; import "./IPAllActionTypeV3.sol"; interface IPActionSwapYTV3 { event SwapYtAndSy( address indexed caller, address indexed market, address indexed receiver, int256 netYtToAccount, int256 netSyToAccount ); event SwapYtAndToken( address indexed caller, address indexed market, address indexed token, address receiver, int256 netYtToAccount, int256 netTokenToAccount, uint256 netSyInterm ); event SwapPtAndYt( address indexed caller, address indexed market, address indexed receiver, int256 netPtToAccount, int256 netYtToAccount ); function swapExactTokenForYt( address receiver, address market, uint256 minYtOut, ApproxParams calldata guessYtOut, TokenInput calldata input, LimitOrderData calldata limit ) external payable returns (uint256 netYtOut, uint256 netSyFee, uint256 netSyInterm); function swapExactSyForYt( address receiver, address market, uint256 exactSyIn, uint256 minYtOut, ApproxParams calldata guessYtOut, LimitOrderData calldata limit ) external returns (uint256 netYtOut, uint256 netSyFee); function swapExactYtForToken( address receiver, address market, uint256 exactYtIn, TokenOutput calldata output, LimitOrderData calldata limit ) external returns (uint256 netTokenOut, uint256 netSyFee, uint256 netSyInterm); function swapExactYtForSy( address receiver, address market, uint256 exactYtIn, uint256 minSyOut, LimitOrderData calldata limit ) external returns (uint256 netSyOut, uint256 netSyFee); function swapExactPtForYt( address receiver, address market, uint256 exactPtIn, uint256 minYtOut, ApproxParams calldata guessTotalPtToSwap ) external returns (uint256 netYtOut, uint256 netSyFee); function swapExactYtForPt( address receiver, address market, uint256 exactYtIn, uint256 minPtOut, ApproxParams calldata guessTotalPtFromSwap ) external returns (uint256 netPtOut, uint256 netSyFee); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "../router/swap-aggregator/IPSwapAggregator.sol"; import "./IPLimitRouter.sol"; struct TokenInput { // Token/Sy data address tokenIn; uint256 netTokenIn; address tokenMintSy; // aggregator data address pendleSwap; SwapData swapData; } struct TokenOutput { // Token/Sy data address tokenOut; uint256 minTokenOut; address tokenRedeemSy; // aggregator data address pendleSwap; SwapData swapData; } struct LimitOrderData { address limitRouter; uint256 epsSkipMarket; // only used for swap operations, will be ignored otherwise FillOrderParams[] normalFills; FillOrderParams[] flashFills; bytes optData; }
// 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 "../core/StandardizedYield/PYIndex.sol"; interface IPLimitOrderType { enum OrderType { SY_FOR_PT, PT_FOR_SY, SY_FOR_YT, YT_FOR_SY } // Fixed-size order part with core information struct StaticOrder { uint256 salt; uint256 expiry; uint256 nonce; OrderType orderType; address token; address YT; address maker; address receiver; uint256 makingAmount; uint256 lnImpliedRate; uint256 failSafeRate; } struct FillResults { uint256 totalMaking; uint256 totalTaking; uint256 totalFee; uint256 totalNotionalVolume; uint256[] netMakings; uint256[] netTakings; uint256[] netFees; uint256[] notionalVolumes; } } struct Order { uint256 salt; uint256 expiry; uint256 nonce; IPLimitOrderType.OrderType orderType; address token; address YT; address maker; address receiver; uint256 makingAmount; uint256 lnImpliedRate; uint256 failSafeRate; bytes permit; } struct FillOrderParams { Order order; bytes signature; uint256 makingAmount; } interface IPLimitRouterCallback is IPLimitOrderType { function limitRouterCallback( uint256 actualMaking, uint256 actualTaking, uint256 totalFee, bytes memory data ) external returns (bytes memory); } interface IPLimitRouter is IPLimitOrderType { struct OrderStatus { uint128 filledAmount; uint128 remaining; } event OrderCanceled(address indexed maker, bytes32 indexed orderHash); event OrderFilled( bytes32 indexed orderHash, OrderType indexed orderType, address indexed YT, address token, uint256 netInputFromMaker, uint256 netOutputToMaker, uint256 feeAmount, uint256 notionalVolume ); // @dev actualMaking, actualTaking are in the SY form function fill( FillOrderParams[] memory params, address receiver, uint256 maxTaking, bytes calldata optData, bytes calldata callback ) external returns (uint256 actualMaking, uint256 actualTaking, uint256 totalFee, bytes memory callbackReturn); function feeRecipient() external view returns (address); function hashOrder(Order memory order) external view returns (bytes32); function cancelSingle(Order calldata order) external; function cancelBatch(Order[] calldata orders) external; function orderStatusesRaw( bytes32[] memory orderHashes ) external view returns (uint256[] memory remainingsRaw, uint256[] memory filledAmounts); function orderStatuses( bytes32[] memory orderHashes ) external view returns (uint256[] memory remainings, uint256[] memory filledAmounts); function DOMAIN_SEPARATOR() external view returns (bytes32); function simulate(address target, bytes calldata data) external payable; }
// 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 /* * 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/IERC20.sol"; interface IWETH is IERC20 { event Deposit(address indexed dst, uint256 wad); event Withdrawal(address indexed src, uint256 wad); function deposit() external payable; function withdraw(uint256 wad) external; }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "../../core/libraries/TokenHelper.sol"; import "../../interfaces/IStandardizedYield.sol"; import "../../interfaces/IPYieldToken.sol"; import "../../interfaces/IPAllActionTypeV3.sol"; import "../../interfaces/IPMarket.sol"; import "../../router/base/MarketApproxLib.sol"; import "../../core/libraries/Errors.sol"; import "../swap-aggregator/IPSwapAggregator.sol"; abstract contract ActionBase is TokenHelper, IPLimitOrderType { using MarketApproxPtOutLib for MarketState; using PMath for uint256; using PYIndexLib for IPYieldToken; using PYIndexLib for PYIndex; bytes internal constant EMPTY_BYTES = abi.encode(); // ----------------- MINT REDEEM SY PY ----------------- function _mintSyFromToken( address receiver, address SY, uint256 minSyOut, TokenInput calldata inp ) internal returns (uint256 netSyOut) { SwapType swapType = inp.swapData.swapType; uint256 netTokenMintSy; if (swapType == SwapType.NONE) { _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn); netTokenMintSy = inp.netTokenIn; } else if (swapType == SwapType.ETH_WETH) { _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn); _wrap_unwrap_ETH(inp.tokenIn, inp.tokenMintSy, inp.netTokenIn); netTokenMintSy = inp.netTokenIn; } else { _swapTokenInput(inp); netTokenMintSy = _selfBalance(inp.tokenMintSy); } netSyOut = __mintSy(receiver, SY, netTokenMintSy, minSyOut, inp); } function _swapTokenInput(TokenInput calldata inp) internal { if (inp.tokenIn == NATIVE) _transferIn(NATIVE, msg.sender, inp.netTokenIn); else _transferFrom(IERC20(inp.tokenIn), msg.sender, inp.pendleSwap, inp.netTokenIn); IPSwapAggregator(inp.pendleSwap).swap{value: inp.tokenIn == NATIVE ? inp.netTokenIn : 0}( inp.tokenIn, inp.netTokenIn, inp.swapData ); } function __mintSy( address receiver, address SY, uint256 netTokenMintSy, uint256 minSyOut, TokenInput calldata inp ) private returns (uint256 netSyOut) { uint256 netNative = inp.tokenMintSy == NATIVE ? netTokenMintSy : 0; _safeApproveInf(inp.tokenMintSy, SY); netSyOut = IStandardizedYield(SY).deposit{value: netNative}( receiver, inp.tokenMintSy, netTokenMintSy, minSyOut ); } function _redeemSyToToken( address receiver, address SY, uint256 netSyIn, TokenOutput calldata out, bool doPull ) internal returns (uint256 netTokenOut) { SwapType swapType = out.swapData.swapType; if (swapType == SwapType.NONE) { netTokenOut = __redeemSy(receiver, SY, netSyIn, out, doPull); } else if (swapType == SwapType.ETH_WETH) { netTokenOut = __redeemSy(address(this), SY, netSyIn, out, doPull); // ETH:WETH is 1:1 _wrap_unwrap_ETH(out.tokenRedeemSy, out.tokenOut, netTokenOut); _transferOut(out.tokenOut, receiver, netTokenOut); } else { uint256 netTokenRedeemed = __redeemSy(out.pendleSwap, SY, netSyIn, out, doPull); IPSwapAggregator(out.pendleSwap).swap(out.tokenRedeemSy, netTokenRedeemed, out.swapData); netTokenOut = _selfBalance(out.tokenOut); _transferOut(out.tokenOut, receiver, netTokenOut); } if (netTokenOut < out.minTokenOut) { revert Errors.RouterInsufficientTokenOut(netTokenOut, out.minTokenOut); } } function __redeemSy( address receiver, address SY, uint256 netSyIn, TokenOutput calldata out, bool doPull ) private returns (uint256 netTokenRedeemed) { if (doPull) { _transferFrom(IERC20(SY), msg.sender, SY, netSyIn); } netTokenRedeemed = IStandardizedYield(SY).redeem(receiver, netSyIn, out.tokenRedeemSy, 0, true); } function _mintPyFromSy( address receiver, address SY, address YT, uint256 netSyIn, uint256 minPyOut, bool doPull ) internal returns (uint256 netPyOut) { if (doPull) { _transferFrom(IERC20(SY), msg.sender, YT, netSyIn); } netPyOut = IPYieldToken(YT).mintPY(receiver, receiver); if (netPyOut < minPyOut) revert Errors.RouterInsufficientPYOut(netPyOut, minPyOut); } function _redeemPyToSy( address receiver, address YT, uint256 netPyIn, uint256 minSyOut ) internal returns (uint256 netSyOut) { address PT = IPYieldToken(YT).PT(); _transferFrom(IERC20(PT), msg.sender, YT, netPyIn); bool needToBurnYt = (!IPYieldToken(YT).isExpired()); if (needToBurnYt) _transferFrom(IERC20(YT), msg.sender, YT, netPyIn); netSyOut = IPYieldToken(YT).redeemPY(receiver); if (netSyOut < minSyOut) revert Errors.RouterInsufficientSyOut(netSyOut, minSyOut); } // ----------------- HELPER ----------------- function _readMarket(address market) internal view returns (MarketState memory) { return IPMarket(market).readState(address(this)); } // ----------------- PT SWAP ----------------- function _entry_swapExactPtForSy(address market, LimitOrderData calldata limit) internal view returns (address) { return !_isEmptyLimit(limit) ? address(this) : market; } function _swapExactPtForSy( address receiver, address market, uint256 exactPtIn, uint256 minSyOut, LimitOrderData calldata limit ) internal returns (uint256 netSyOut, uint256 netSyFee) { (, IPPrincipalToken PT, ) = IPMarket(market).readTokens(); uint256 netPtLeft = exactPtIn; bool doMarketOrder = true; if (!_isEmptyLimit(limit)) { (netPtLeft, netSyOut, netSyFee, doMarketOrder) = _fillLimit(receiver, PT, netPtLeft, limit); if (doMarketOrder) { _transferOut(address(PT), market, netPtLeft); } } if (doMarketOrder) { (uint256 netSyOutMarket, uint256 netSyFeeMarket) = IPMarket(market).swapExactPtForSy( receiver, netPtLeft, EMPTY_BYTES ); netSyOut += netSyOutMarket; netSyFee += netSyFeeMarket; } if (netSyOut < minSyOut) revert Errors.RouterInsufficientSyOut(netSyOut, minSyOut); } function _entry_swapExactSyForPt(address market, LimitOrderData calldata limit) internal view returns (address) { return !_isEmptyLimit(limit) ? address(this) : market; } function _swapExactSyForPt( address receiver, address market, uint256 exactSyIn, uint256 minPtOut, ApproxParams calldata guessPtOut, LimitOrderData calldata limit ) internal returns (uint256 netPtOut, uint256 netSyFee) { (IStandardizedYield SY, , IPYieldToken YT) = IPMarket(market).readTokens(); uint256 netSyLeft = exactSyIn; bool doMarketOrder = true; if (!_isEmptyLimit(limit)) { (netSyLeft, netPtOut, netSyFee, doMarketOrder) = _fillLimit(receiver, SY, netSyLeft, limit); if (doMarketOrder) { _transferOut(address(SY), market, netSyLeft); } } if (doMarketOrder) { (uint256 netPtOutMarket, ) = _readMarket(market).approxSwapExactSyForPt( YT.newIndex(), netSyLeft, block.timestamp, guessPtOut ); (, uint256 netSyFeeMarket) = IPMarket(market).swapSyForExactPt(receiver, netPtOutMarket, EMPTY_BYTES); netPtOut += netPtOutMarket; netSyFee += netSyFeeMarket; } if (netPtOut < minPtOut) revert Errors.RouterInsufficientPtOut(netPtOut, minPtOut); } // ----------------- LIMIT ORDERS ----------------- function _fillLimit( address receiver, IERC20 tokenIn, uint256 netInput, LimitOrderData calldata lim ) internal returns (uint256 netLeft, uint256 netOut, uint256 netSyFee, bool doMarketOrder) { IPLimitRouter router = IPLimitRouter(lim.limitRouter); netLeft = netInput; if (lim.normalFills.length != 0) { _safeApproveInf(address(tokenIn), lim.limitRouter); (uint256 actualMaking, uint256 actualTaking, uint256 totalFee, ) = router.fill( lim.normalFills, receiver, netLeft, lim.optData, EMPTY_BYTES ); netOut += actualMaking; netLeft -= actualTaking; netSyFee += totalFee; } if (lim.flashFills.length != 0) { address YT = lim.flashFills[0].order.YT; OrderType orderType = lim.flashFills[0].order.orderType; (, , uint256 totalFee, bytes memory ret) = router.fill( lim.flashFills, YT, type(uint256).max, lim.optData, abi.encode(orderType, YT, netLeft, receiver) ); (uint256 netUse, uint256 netReceived) = abi.decode(ret, (uint256, uint256)); netOut += netReceived; netLeft -= netUse; netSyFee += totalFee; } doMarketOrder = netLeft > netInput.mulDown(lim.epsSkipMarket); } function _isEmptyLimit(LimitOrderData calldata a) internal pure returns (bool) { return a.normalFills.length == 0 && a.flashFills.length == 0; } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "../../interfaces/IPYieldToken.sol"; import "../../interfaces/IPPrincipalToken.sol"; import "../../interfaces/IStandardizedYield.sol"; abstract contract CallbackHelper { enum ActionType { SwapExactSyForYt, SwapYtForSy, SwapExactYtForPt, SwapExactPtForYt } /// ------------------------------------------------------------ /// SwapExactSyForYt /// ------------------------------------------------------------ function _encodeSwapExactSyForYt(address receiver, IPYieldToken YT) internal pure returns (bytes memory res) { res = new bytes(96); uint256 actionType = uint256(ActionType.SwapExactSyForYt); assembly { mstore(add(res, 32), actionType) mstore(add(res, 64), receiver) mstore(add(res, 96), YT) } } function _decodeSwapExactSyForYt(bytes calldata data) internal pure returns (address receiver, IPYieldToken YT) { assembly { // first 32 bytes is ActionType receiver := calldataload(add(data.offset, 32)) YT := calldataload(add(data.offset, 64)) } } /// ------------------------------------------------------------ /// SwapYtForSy (common encode & decode) /// ------------------------------------------------------------ function _encodeSwapYtForSy(address receiver, IPYieldToken YT) internal pure returns (bytes memory res) { res = new bytes(96); uint256 actionType = uint256(ActionType.SwapYtForSy); assembly { mstore(add(res, 32), actionType) mstore(add(res, 64), receiver) mstore(add(res, 96), YT) } } function _decodeSwapYtForSy(bytes calldata data) internal pure returns (address receiver, IPYieldToken YT) { assembly { // first 32 bytes is ActionType receiver := calldataload(add(data.offset, 32)) YT := calldataload(add(data.offset, 64)) } } function _encodeSwapExactYtForPt( address receiver, uint256 netPtOut, IPPrincipalToken PT, IPYieldToken YT ) internal pure returns (bytes memory res) { res = new bytes(160); uint256 actionType = uint256(ActionType.SwapExactYtForPt); assembly { mstore(add(res, 32), actionType) mstore(add(res, 64), receiver) mstore(add(res, 96), netPtOut) mstore(add(res, 128), PT) mstore(add(res, 160), YT) } } function _decodeSwapExactYtForPt( bytes calldata data ) internal pure returns (address receiver, uint256 netPtOut, IPPrincipalToken PT, IPYieldToken YT) { assembly { // first 32 bytes is ActionType receiver := calldataload(add(data.offset, 32)) netPtOut := calldataload(add(data.offset, 64)) PT := calldataload(add(data.offset, 96)) YT := calldataload(add(data.offset, 128)) } } function _encodeSwapExactPtForYt( address receiver, uint256 exactPtIn, uint256 minYtOut, IPYieldToken YT ) internal pure returns (bytes memory res) { res = new bytes(160); uint256 actionType = uint256(ActionType.SwapExactPtForYt); assembly { mstore(add(res, 32), actionType) mstore(add(res, 64), receiver) mstore(add(res, 96), exactPtIn) mstore(add(res, 128), minYtOut) mstore(add(res, 160), YT) } } function _decodeSwapExactPtForYt( bytes calldata data ) internal pure returns (address receiver, uint256 exactPtIn, uint256 minYtOut, IPYieldToken YT) { assembly { // first 32 bytes is ActionType receiver := calldataload(add(data.offset, 32)) exactPtIn := calldataload(add(data.offset, 64)) minYtOut := calldataload(add(data.offset, 96)) YT := calldataload(add(data.offset, 128)) } } /// ------------------------------------------------------------ /// Misc functions /// ------------------------------------------------------------ function _getActionType(bytes calldata data) internal pure returns (ActionType actionType) { assembly { actionType := calldataload(data.offset) } } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "../../core/libraries/math/PMath.sol"; import "../../core/Market/MarketMathCore.sol"; struct ApproxParams { uint256 guessMin; uint256 guessMax; uint256 guessOffchain; // pass 0 in to skip this variable uint256 maxIteration; // every iteration, the diff between guessMin and guessMax will be divided by 2 uint256 eps; // the max eps between the returned result & the correct result, base 1e18. Normally this number will be set // to 1e15 (1e18/1000 = 0.1%) } /// Further explanation of the eps. Take swapExactSyForPt for example. To calc the corresponding amount of Pt to swap out, /// it's necessary to run an approximation algorithm, because by default there only exists the Pt to Sy formula /// To approx, the 5 values above will have to be provided, and the approx process will run as follows: /// mid = (guessMin + guessMax) / 2 // mid here is the current guess of the amount of Pt out /// netSyNeed = calcSwapSyForExactPt(mid) /// if (netSyNeed > exactSyIn) guessMax = mid - 1 // since the maximum Sy in can't exceed the exactSyIn /// else guessMin = mid (1) /// For the (1), since netSyNeed <= exactSyIn, the result might be usable. If the netSyNeed is within eps of /// exactSyIn (ex eps=0.1% => we have used 99.9% the amount of Sy specified), mid will be chosen as the final guess result /// for guessOffchain, this is to provide a shortcut to guessing. The offchain SDK can precalculate the exact result /// before the tx is sent. When the tx reaches the contract, the guessOffchain will be checked first, and if it satisfies the /// approximation, it will be used (and save all the guessing). It's expected that this shortcut will be used in most cases /// except in cases that there is a trade in the same market right before the tx library MarketApproxPtInLib { using MarketMathCore for MarketState; using PYIndexLib for PYIndex; using PMath for uint256; using PMath for int256; using LogExpMath for int256; /** * @dev algorithm: * - Bin search the amount of PT to swap in * - Try swapping & get netSyOut * - Stop when netSyOut greater & approx minSyOut * - guess & approx is for netPtIn */ function approxSwapPtForExactSy( MarketState memory market, PYIndex index, uint256 minSyOut, uint256 blockTime, ApproxParams memory approx ) internal pure returns (uint256, /*netPtIn*/ uint256, /*netSyOut*/ uint256 /*netSyFee*/) { MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime); if (approx.guessOffchain == 0) { // no limit on min approx.guessMax = PMath.min(approx.guessMax, calcMaxPtIn(market, comp)); validateApprox(approx); } for (uint256 iter = 0; iter < approx.maxIteration; ++iter) { uint256 guess = nextGuess(approx, iter); (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess); if (netSyOut >= minSyOut) { if (PMath.isAGreaterApproxB(netSyOut, minSyOut, approx.eps)) { return (guess, netSyOut, netSyFee); } approx.guessMax = guess; } else { approx.guessMin = guess; } } revert Errors.ApproxFail(); } /** * @dev algorithm: * - Bin search the amount of PT to swap in * - Flashswap the corresponding amount of SY out * - Pair those amount with exactSyIn SY to tokenize into PT & YT * - PT to repay the flashswap, YT transferred to user * - Stop when the amount of SY to be pulled to tokenize PT to repay loan approx the exactSyIn * - guess & approx is for netYtOut (also netPtIn) */ function approxSwapExactSyForYt( MarketState memory market, PYIndex index, uint256 exactSyIn, uint256 blockTime, ApproxParams memory approx ) internal pure returns (uint256, /*netYtOut*/ uint256 /*netSyFee*/) { MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime); if (approx.guessOffchain == 0) { approx.guessMin = PMath.max(approx.guessMin, index.syToAsset(exactSyIn)); approx.guessMax = PMath.min(approx.guessMax, calcMaxPtIn(market, comp)); validateApprox(approx); } // at minimum we will flashswap exactSyIn since we have enough SY to payback the PT loan for (uint256 iter = 0; iter < approx.maxIteration; ++iter) { uint256 guess = nextGuess(approx, iter); (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess); uint256 netSyToTokenizePt = index.assetToSyUp(guess); // for sure netSyToTokenizePt >= netSyOut since we are swapping PT to SY uint256 netSyToPull = netSyToTokenizePt - netSyOut; if (netSyToPull <= exactSyIn) { if (PMath.isASmallerApproxB(netSyToPull, exactSyIn, approx.eps)) { return (guess, netSyFee); } approx.guessMin = guess; } else { approx.guessMax = guess - 1; } } revert Errors.ApproxFail(); } struct Args5 { MarketState market; PYIndex index; uint256 totalPtIn; uint256 netSyHolding; uint256 blockTime; ApproxParams approx; } /** * @dev algorithm: * - Bin search the amount of PT to swap to SY * - Swap PT to SY * - Pair the remaining PT with the SY to add liquidity * - Stop when the ratio of PT / totalPt & SY / totalSy is approx * - guess & approx is for netPtSwap */ function approxSwapPtToAddLiquidity( MarketState memory _market, PYIndex _index, uint256 _totalPtIn, uint256 _netSyHolding, uint256 _blockTime, ApproxParams memory approx ) internal pure returns (uint256, /*netPtSwap*/ uint256, /*netSyFromSwap*/ uint256 /*netSyFee*/) { Args5 memory a = Args5(_market, _index, _totalPtIn, _netSyHolding, _blockTime, approx); MarketPreCompute memory comp = a.market.getMarketPreCompute(a.index, a.blockTime); if (approx.guessOffchain == 0) { // no limit on min approx.guessMax = PMath.min(approx.guessMax, calcMaxPtIn(a.market, comp)); approx.guessMax = PMath.min(approx.guessMax, a.totalPtIn); validateApprox(approx); require(a.market.totalLp != 0, "no existing lp"); } for (uint256 iter = 0; iter < approx.maxIteration; ++iter) { uint256 guess = nextGuess(approx, iter); (uint256 syNumerator, uint256 ptNumerator, uint256 netSyOut, uint256 netSyFee, ) = calcNumerators( a.market, a.index, a.totalPtIn, a.netSyHolding, comp, guess ); if (PMath.isAApproxB(syNumerator, ptNumerator, approx.eps)) { return (guess, netSyOut, netSyFee); } if (syNumerator <= ptNumerator) { // needs more SY --> swap more PT approx.guessMin = guess + 1; } else { // needs less SY --> swap less PT approx.guessMax = guess - 1; } } revert Errors.ApproxFail(); } function calcNumerators( MarketState memory market, PYIndex index, uint256 totalPtIn, uint256 netSyHolding, MarketPreCompute memory comp, uint256 guess ) internal pure returns (uint256 syNumerator, uint256 ptNumerator, uint256 netSyOut, uint256 netSyFee, uint256 netSyToReserve) { (netSyOut, netSyFee, netSyToReserve) = calcSyOut(market, comp, index, guess); uint256 newTotalPt = uint256(market.totalPt) + guess; uint256 newTotalSy = (uint256(market.totalSy) - netSyOut - netSyToReserve); // it is desired that // (netSyOut + netSyHolding) / newTotalSy = netPtRemaining / newTotalPt // which is equivalent to // (netSyOut + netSyHolding) * newTotalPt = netPtRemaining * newTotalSy syNumerator = (netSyOut + netSyHolding) * newTotalPt; ptNumerator = (totalPtIn - guess) * newTotalSy; } /** * @dev algorithm: * - Bin search the amount of PT to swap to SY * - Flashswap the corresponding amount of SY out * - Tokenize all the SY into PT + YT * - PT to repay the flashswap, YT transferred to user * - Stop when the additional amount of PT to pull to repay the loan approx the exactPtIn * - guess & approx is for totalPtToSwap */ function approxSwapExactPtForYt( MarketState memory market, PYIndex index, uint256 exactPtIn, uint256 blockTime, ApproxParams memory approx ) internal pure returns (uint256, /*netYtOut*/ uint256, /*totalPtToSwap*/ uint256 /*netSyFee*/) { MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime); if (approx.guessOffchain == 0) { approx.guessMin = PMath.max(approx.guessMin, exactPtIn); approx.guessMax = PMath.min(approx.guessMax, calcMaxPtIn(market, comp)); validateApprox(approx); } for (uint256 iter = 0; iter < approx.maxIteration; ++iter) { uint256 guess = nextGuess(approx, iter); (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess); uint256 netAssetOut = index.syToAsset(netSyOut); // guess >= netAssetOut since we are swapping PT to SY uint256 netPtToPull = guess - netAssetOut; if (netPtToPull <= exactPtIn) { if (PMath.isASmallerApproxB(netPtToPull, exactPtIn, approx.eps)) { return (netAssetOut, guess, netSyFee); } approx.guessMin = guess; } else { approx.guessMax = guess - 1; } } revert Errors.ApproxFail(); } //////////////////////////////////////////////////////////////////////////////// function calcSyOut( MarketState memory market, MarketPreCompute memory comp, PYIndex index, uint256 netPtIn ) internal pure returns (uint256 netSyOut, uint256 netSyFee, uint256 netSyToReserve) { (int256 _netSyOut, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(comp, index, -int256(netPtIn)); netSyOut = uint256(_netSyOut); netSyFee = uint256(_netSyFee); netSyToReserve = uint256(_netSyToReserve); } function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) { if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain; if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2; revert Errors.ApproxFail(); } /// INTENDED TO BE CALLED BY WHEN GUESS.OFFCHAIN == 0 ONLY /// function validateApprox(ApproxParams memory approx) internal pure { if (approx.guessMin > approx.guessMax || approx.eps > PMath.ONE) { revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps); } } function calcMaxPtIn(MarketState memory market, MarketPreCompute memory comp) internal pure returns (uint256) { uint256 low = 0; uint256 hi = uint256(comp.totalAsset) - 1; while (low != hi) { uint256 mid = (low + hi + 1) / 2; if (calcSlope(comp, market.totalPt, int256(mid)) < 0) hi = mid - 1; else low = mid; } return low; } function calcSlope(MarketPreCompute memory comp, int256 totalPt, int256 ptToMarket) internal pure returns (int256) { int256 diffAssetPtToMarket = comp.totalAsset - ptToMarket; int256 sumPt = ptToMarket + totalPt; require(diffAssetPtToMarket > 0 && sumPt > 0, "invalid ptToMarket"); int256 part1 = (ptToMarket * (totalPt + comp.totalAsset)).divDown(sumPt * diffAssetPtToMarket); int256 part2 = sumPt.divDown(diffAssetPtToMarket).ln(); int256 part3 = PMath.IONE.divDown(comp.rateScalar); return comp.rateAnchor - (part1 - part2).mulDown(part3); } } library MarketApproxPtOutLib { using MarketMathCore for MarketState; using PYIndexLib for PYIndex; using PMath for uint256; using PMath for int256; using LogExpMath for int256; /** * @dev algorithm: * - Bin search the amount of PT to swapExactOut * - Calculate the amount of SY needed * - Stop when the netSyIn is smaller approx exactSyIn * - guess & approx is for netSyIn */ function approxSwapExactSyForPt( MarketState memory market, PYIndex index, uint256 exactSyIn, uint256 blockTime, ApproxParams memory approx ) internal pure returns (uint256, /*netPtOut*/ uint256 /*netSyFee*/) { MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime); if (approx.guessOffchain == 0) { // no limit on min approx.guessMax = PMath.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt)); validateApprox(approx); } for (uint256 iter = 0; iter < approx.maxIteration; ++iter) { uint256 guess = nextGuess(approx, iter); (uint256 netSyIn, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess); if (netSyIn <= exactSyIn) { if (PMath.isASmallerApproxB(netSyIn, exactSyIn, approx.eps)) { return (guess, netSyFee); } approx.guessMin = guess; } else { approx.guessMax = guess - 1; } } revert Errors.ApproxFail(); } /** * @dev algorithm: * - Bin search the amount of PT to swapExactOut * - Flashswap that amount of PT & pair with YT to redeem SY * - Use the SY to repay the flashswap debt and the remaining is transferred to user * - Stop when the netSyOut is greater approx the minSyOut * - guess & approx is for netSyOut */ function approxSwapYtForExactSy( MarketState memory market, PYIndex index, uint256 minSyOut, uint256 blockTime, ApproxParams memory approx ) internal pure returns (uint256, /*netYtIn*/ uint256, /*netSyOut*/ uint256 /*netSyFee*/) { MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime); if (approx.guessOffchain == 0) { // no limit on min approx.guessMax = PMath.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt)); validateApprox(approx); } for (uint256 iter = 0; iter < approx.maxIteration; ++iter) { uint256 guess = nextGuess(approx, iter); (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess); uint256 netAssetToRepay = index.syToAssetUp(netSyOwed); uint256 netSyOut = index.assetToSy(guess - netAssetToRepay); if (netSyOut >= minSyOut) { if (PMath.isAGreaterApproxB(netSyOut, minSyOut, approx.eps)) { return (guess, netSyOut, netSyFee); } approx.guessMax = guess; } else { approx.guessMin = guess + 1; } } revert Errors.ApproxFail(); } struct Args6 { MarketState market; PYIndex index; uint256 totalSyIn; uint256 netPtHolding; uint256 blockTime; ApproxParams approx; } /** * @dev algorithm: * - Bin search the amount of PT to swapExactOut * - Swap that amount of PT out * - Pair the remaining PT with the SY to add liquidity * - Stop when the ratio of PT / totalPt & SY / totalSy is approx * - guess & approx is for netPtFromSwap */ function approxSwapSyToAddLiquidity( MarketState memory _market, PYIndex _index, uint256 _totalSyIn, uint256 _netPtHolding, uint256 _blockTime, ApproxParams memory _approx ) internal pure returns (uint256, /*netPtFromSwap*/ uint256, /*netSySwap*/ uint256 /*netSyFee*/) { Args6 memory a = Args6(_market, _index, _totalSyIn, _netPtHolding, _blockTime, _approx); MarketPreCompute memory comp = a.market.getMarketPreCompute(a.index, a.blockTime); if (a.approx.guessOffchain == 0) { // no limit on min a.approx.guessMax = PMath.min(a.approx.guessMax, calcMaxPtOut(comp, a.market.totalPt)); validateApprox(a.approx); require(a.market.totalLp != 0, "no existing lp"); } for (uint256 iter = 0; iter < a.approx.maxIteration; ++iter) { uint256 guess = nextGuess(a.approx, iter); (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) = calcSyIn(a.market, comp, a.index, guess); if (netSyIn > a.totalSyIn) { a.approx.guessMax = guess - 1; continue; } uint256 syNumerator; uint256 ptNumerator; { uint256 newTotalPt = uint256(a.market.totalPt) - guess; uint256 netTotalSy = uint256(a.market.totalSy) + netSyIn - netSyToReserve; // it is desired that // (netPtFromSwap + netPtHolding) / newTotalPt = netSyRemaining / netTotalSy // which is equivalent to // (netPtFromSwap + netPtHolding) * netTotalSy = netSyRemaining * newTotalPt ptNumerator = (guess + a.netPtHolding) * netTotalSy; syNumerator = (a.totalSyIn - netSyIn) * newTotalPt; } if (PMath.isAApproxB(ptNumerator, syNumerator, a.approx.eps)) { return (guess, netSyIn, netSyFee); } if (ptNumerator <= syNumerator) { // needs more PT a.approx.guessMin = guess + 1; } else { // needs less PT a.approx.guessMax = guess - 1; } } revert Errors.ApproxFail(); } /** * @dev algorithm: * - Bin search the amount of PT to swapExactOut * - Flashswap that amount of PT out * - Pair all the PT with the YT to redeem SY * - Use the SY to repay the flashswap debt * - Stop when the amount of YT required to pair with PT is approx exactYtIn * - guess & approx is for netPtFromSwap */ function approxSwapExactYtForPt( MarketState memory market, PYIndex index, uint256 exactYtIn, uint256 blockTime, ApproxParams memory approx ) internal pure returns (uint256, /*netPtOut*/ uint256, /*totalPtSwapped*/ uint256 /*netSyFee*/) { MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime); if (approx.guessOffchain == 0) { approx.guessMin = PMath.max(approx.guessMin, exactYtIn); approx.guessMax = PMath.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt)); validateApprox(approx); } for (uint256 iter = 0; iter < approx.maxIteration; ++iter) { uint256 guess = nextGuess(approx, iter); (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess); uint256 netYtToPull = index.syToAssetUp(netSyOwed); if (netYtToPull <= exactYtIn) { if (PMath.isASmallerApproxB(netYtToPull, exactYtIn, approx.eps)) { return (guess - netYtToPull, guess, netSyFee); } approx.guessMin = guess; } else { approx.guessMax = guess - 1; } } revert Errors.ApproxFail(); } //////////////////////////////////////////////////////////////////////////////// function calcSyIn( MarketState memory market, MarketPreCompute memory comp, PYIndex index, uint256 netPtOut ) internal pure returns (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) { (int256 _netSyIn, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(comp, index, int256(netPtOut)); // all safe since totalPt and totalSy is int128 netSyIn = uint256(-_netSyIn); netSyFee = uint256(_netSyFee); netSyToReserve = uint256(_netSyToReserve); } function calcMaxPtOut(MarketPreCompute memory comp, int256 totalPt) internal pure returns (uint256) { int256 logitP = (comp.feeRate - comp.rateAnchor).mulDown(comp.rateScalar).exp(); int256 proportion = logitP.divDown(logitP + PMath.IONE); int256 numerator = proportion.mulDown(totalPt + comp.totalAsset); int256 maxPtOut = totalPt - numerator; // only get 99.9% of the theoretical max to accommodate some precision issues return (uint256(maxPtOut) * 999) / 1000; } function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) { if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain; if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2; revert Errors.ApproxFail(); } function validateApprox(ApproxParams memory approx) internal pure { if (approx.guessMin > approx.guessMax || approx.eps > PMath.ONE) { revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps); } } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; struct SwapData { SwapType swapType; address extRouter; bytes extCalldata; bool needScale; } enum SwapType { NONE, KYBERSWAP, ONE_INCH, // ETH_WETH not used in Aggregator ETH_WETH } interface IPSwapAggregator { function swap(address tokenIn, uint256 amountIn, SwapData calldata swapData) external payable; }
{ "optimizer": { "enabled": true, "runs": 1000000 }, "evmVersion": "paris", "viaIR": true, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[],"name":"ApproxFail","type":"error"},{"inputs":[{"internalType":"uint256","name":"guessMin","type":"uint256"},{"internalType":"uint256","name":"guessMax","type":"uint256"},{"internalType":"uint256","name":"eps","type":"uint256"}],"name":"ApproxParamsInvalid","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":"proportion","type":"int256"},{"internalType":"int256","name":"maxProportion","type":"int256"}],"name":"MarketProportionTooHigh","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":[{"internalType":"uint256","name":"actualPtOut","type":"uint256"},{"internalType":"uint256","name":"requiredPtOut","type":"uint256"}],"name":"RouterInsufficientPtOut","type":"error"},{"inputs":[{"internalType":"uint256","name":"actualSyOut","type":"uint256"},{"internalType":"uint256","name":"requiredSyOut","type":"uint256"}],"name":"RouterInsufficientSyOut","type":"error"},{"inputs":[{"internalType":"uint256","name":"actualTokenOut","type":"uint256"},{"internalType":"uint256","name":"requiredTokenOut","type":"uint256"}],"name":"RouterInsufficientTokenOut","type":"error"},{"inputs":[{"internalType":"uint256","name":"actualYtOut","type":"uint256"},{"internalType":"uint256","name":"requiredYtOut","type":"uint256"}],"name":"RouterInsufficientYtOut","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"market","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"int256","name":"netPtToAccount","type":"int256"},{"indexed":false,"internalType":"int256","name":"netYtToAccount","type":"int256"}],"name":"SwapPtAndYt","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"market","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"int256","name":"netYtToAccount","type":"int256"},{"indexed":false,"internalType":"int256","name":"netSyToAccount","type":"int256"}],"name":"SwapYtAndSy","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"market","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"int256","name":"netYtToAccount","type":"int256"},{"indexed":false,"internalType":"int256","name":"netTokenToAccount","type":"int256"},{"indexed":false,"internalType":"uint256","name":"netSyInterm","type":"uint256"}],"name":"SwapYtAndToken","type":"event"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"exactPtIn","type":"uint256"},{"internalType":"uint256","name":"minYtOut","type":"uint256"},{"components":[{"internalType":"uint256","name":"guessMin","type":"uint256"},{"internalType":"uint256","name":"guessMax","type":"uint256"},{"internalType":"uint256","name":"guessOffchain","type":"uint256"},{"internalType":"uint256","name":"maxIteration","type":"uint256"},{"internalType":"uint256","name":"eps","type":"uint256"}],"internalType":"struct ApproxParams","name":"guessTotalPtToSwap","type":"tuple"}],"name":"swapExactPtForYt","outputs":[{"internalType":"uint256","name":"netYtOut","type":"uint256"},{"internalType":"uint256","name":"netSyFee","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"exactSyIn","type":"uint256"},{"internalType":"uint256","name":"minYtOut","type":"uint256"},{"components":[{"internalType":"uint256","name":"guessMin","type":"uint256"},{"internalType":"uint256","name":"guessMax","type":"uint256"},{"internalType":"uint256","name":"guessOffchain","type":"uint256"},{"internalType":"uint256","name":"maxIteration","type":"uint256"},{"internalType":"uint256","name":"eps","type":"uint256"}],"internalType":"struct ApproxParams","name":"guessYtOut","type":"tuple"},{"components":[{"internalType":"address","name":"limitRouter","type":"address"},{"internalType":"uint256","name":"epsSkipMarket","type":"uint256"},{"components":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"enum IPLimitOrderType.OrderType","name":"orderType","type":"uint8"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"YT","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"lnImpliedRate","type":"uint256"},{"internalType":"uint256","name":"failSafeRate","type":"uint256"},{"internalType":"bytes","name":"permit","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"}],"internalType":"struct FillOrderParams[]","name":"normalFills","type":"tuple[]"},{"components":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"enum IPLimitOrderType.OrderType","name":"orderType","type":"uint8"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"YT","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"lnImpliedRate","type":"uint256"},{"internalType":"uint256","name":"failSafeRate","type":"uint256"},{"internalType":"bytes","name":"permit","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"}],"internalType":"struct FillOrderParams[]","name":"flashFills","type":"tuple[]"},{"internalType":"bytes","name":"optData","type":"bytes"}],"internalType":"struct LimitOrderData","name":"limit","type":"tuple"}],"name":"swapExactSyForYt","outputs":[{"internalType":"uint256","name":"netYtOut","type":"uint256"},{"internalType":"uint256","name":"netSyFee","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"minYtOut","type":"uint256"},{"components":[{"internalType":"uint256","name":"guessMin","type":"uint256"},{"internalType":"uint256","name":"guessMax","type":"uint256"},{"internalType":"uint256","name":"guessOffchain","type":"uint256"},{"internalType":"uint256","name":"maxIteration","type":"uint256"},{"internalType":"uint256","name":"eps","type":"uint256"}],"internalType":"struct ApproxParams","name":"guessYtOut","type":"tuple"},{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"netTokenIn","type":"uint256"},{"internalType":"address","name":"tokenMintSy","type":"address"},{"internalType":"address","name":"pendleSwap","type":"address"},{"components":[{"internalType":"enum SwapType","name":"swapType","type":"uint8"},{"internalType":"address","name":"extRouter","type":"address"},{"internalType":"bytes","name":"extCalldata","type":"bytes"},{"internalType":"bool","name":"needScale","type":"bool"}],"internalType":"struct SwapData","name":"swapData","type":"tuple"}],"internalType":"struct TokenInput","name":"input","type":"tuple"},{"components":[{"internalType":"address","name":"limitRouter","type":"address"},{"internalType":"uint256","name":"epsSkipMarket","type":"uint256"},{"components":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"enum IPLimitOrderType.OrderType","name":"orderType","type":"uint8"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"YT","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"lnImpliedRate","type":"uint256"},{"internalType":"uint256","name":"failSafeRate","type":"uint256"},{"internalType":"bytes","name":"permit","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"}],"internalType":"struct FillOrderParams[]","name":"normalFills","type":"tuple[]"},{"components":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"enum IPLimitOrderType.OrderType","name":"orderType","type":"uint8"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"YT","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"lnImpliedRate","type":"uint256"},{"internalType":"uint256","name":"failSafeRate","type":"uint256"},{"internalType":"bytes","name":"permit","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"}],"internalType":"struct FillOrderParams[]","name":"flashFills","type":"tuple[]"},{"internalType":"bytes","name":"optData","type":"bytes"}],"internalType":"struct LimitOrderData","name":"limit","type":"tuple"}],"name":"swapExactTokenForYt","outputs":[{"internalType":"uint256","name":"netYtOut","type":"uint256"},{"internalType":"uint256","name":"netSyFee","type":"uint256"},{"internalType":"uint256","name":"netSyInterm","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"exactYtIn","type":"uint256"},{"internalType":"uint256","name":"minPtOut","type":"uint256"},{"components":[{"internalType":"uint256","name":"guessMin","type":"uint256"},{"internalType":"uint256","name":"guessMax","type":"uint256"},{"internalType":"uint256","name":"guessOffchain","type":"uint256"},{"internalType":"uint256","name":"maxIteration","type":"uint256"},{"internalType":"uint256","name":"eps","type":"uint256"}],"internalType":"struct ApproxParams","name":"guessTotalPtFromSwap","type":"tuple"}],"name":"swapExactYtForPt","outputs":[{"internalType":"uint256","name":"netPtOut","type":"uint256"},{"internalType":"uint256","name":"netSyFee","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"exactYtIn","type":"uint256"},{"internalType":"uint256","name":"minSyOut","type":"uint256"},{"components":[{"internalType":"address","name":"limitRouter","type":"address"},{"internalType":"uint256","name":"epsSkipMarket","type":"uint256"},{"components":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"enum IPLimitOrderType.OrderType","name":"orderType","type":"uint8"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"YT","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"lnImpliedRate","type":"uint256"},{"internalType":"uint256","name":"failSafeRate","type":"uint256"},{"internalType":"bytes","name":"permit","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"}],"internalType":"struct FillOrderParams[]","name":"normalFills","type":"tuple[]"},{"components":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"enum IPLimitOrderType.OrderType","name":"orderType","type":"uint8"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"YT","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"lnImpliedRate","type":"uint256"},{"internalType":"uint256","name":"failSafeRate","type":"uint256"},{"internalType":"bytes","name":"permit","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"}],"internalType":"struct FillOrderParams[]","name":"flashFills","type":"tuple[]"},{"internalType":"bytes","name":"optData","type":"bytes"}],"internalType":"struct LimitOrderData","name":"limit","type":"tuple"}],"name":"swapExactYtForSy","outputs":[{"internalType":"uint256","name":"netSyOut","type":"uint256"},{"internalType":"uint256","name":"netSyFee","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"exactYtIn","type":"uint256"},{"components":[{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"minTokenOut","type":"uint256"},{"internalType":"address","name":"tokenRedeemSy","type":"address"},{"internalType":"address","name":"pendleSwap","type":"address"},{"components":[{"internalType":"enum SwapType","name":"swapType","type":"uint8"},{"internalType":"address","name":"extRouter","type":"address"},{"internalType":"bytes","name":"extCalldata","type":"bytes"},{"internalType":"bool","name":"needScale","type":"bool"}],"internalType":"struct SwapData","name":"swapData","type":"tuple"}],"internalType":"struct TokenOutput","name":"output","type":"tuple"},{"components":[{"internalType":"address","name":"limitRouter","type":"address"},{"internalType":"uint256","name":"epsSkipMarket","type":"uint256"},{"components":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"enum IPLimitOrderType.OrderType","name":"orderType","type":"uint8"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"YT","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"lnImpliedRate","type":"uint256"},{"internalType":"uint256","name":"failSafeRate","type":"uint256"},{"internalType":"bytes","name":"permit","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"}],"internalType":"struct FillOrderParams[]","name":"normalFills","type":"tuple[]"},{"components":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"enum IPLimitOrderType.OrderType","name":"orderType","type":"uint8"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"YT","type":"address"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"makingAmount","type":"uint256"},{"internalType":"uint256","name":"lnImpliedRate","type":"uint256"},{"internalType":"uint256","name":"failSafeRate","type":"uint256"},{"internalType":"bytes","name":"permit","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"uint256","name":"makingAmount","type":"uint256"}],"internalType":"struct FillOrderParams[]","name":"flashFills","type":"tuple[]"},{"internalType":"bytes","name":"optData","type":"bytes"}],"internalType":"struct LimitOrderData","name":"limit","type":"tuple"}],"name":"swapExactYtForToken","outputs":[{"internalType":"uint256","name":"netTokenOut","type":"uint256"},{"internalType":"uint256","name":"netSyFee","type":"uint256"},{"internalType":"uint256","name":"netSyInterm","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
6080806040523461001657614d0a908161001c8239f35b600080fdfe6080604052600436101561001257600080fd5b6000803560e01c90816305eb53271461007a57508063448b9b95146100755780637b8b4b951461007057806380c4d5661461006b578063c861a898146100665763ed48907e1461006157600080fd5b610922565b610718565b6105cb565b61044a565b61021f565b346101305760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261013057600435906100b682610137565b602435916100c383610137565b67ffffffffffffffff606435818111610133576100e4903690600401610196565b926084359182116101305761012c61010f8686866101053660048901610196565b9260443591610aea565b604080519384526020840192909252908201529081906060820190565b0390f35b80fd5b8380fd5b73ffffffffffffffffffffffffffffffffffffffff81160361015557565b600080fd5b359061016582610137565b565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7c60a091011261015557608490565b908160a09103126101555790565b6101207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc820112610155576004356101db81610137565b916024356101e881610137565b916044359160a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7c60643593011261015557608490565b346101555761022d366101a4565b91909373ffffffffffffffffffffffffffffffffffffffff91828516906040938451957f2c8ce6bc000000000000000000000000000000000000000000000000000000008752606087600481875afa9788156103c757600097600099610409575b509061029c6102b992611af4565b846102b16102a98c611be3565b933690610eec565b924292611c58565b98919790998089106103cc5750986102e78261031c999a9b6102e087878c9716338161136c565b8b89611df0565b90825198899283927f5b709f170000000000000000000000000000000000000000000000000000000084523060048501610fbf565b03816000875af19081156103c75761012c967fa4519acd6c251a3f533922c5aaf3fbae71546aad6c01f8241e23143519a67ac89261039b575b5061037061036b6103658a611a4b565b94611a4b565b6119ba565b8651938452602084015293909316923391604090a45191825260208201929092529081906040820190565b6103ba90873d89116103c0575b6103b28183610a5d565b810190610f43565b50610355565b503d6103a8565b610ad4565b87517f9cdffc8e000000000000000000000000000000000000000000000000000000008152600481018a90526024810191909152604490fd5b0390fd5b6102b99291995061029c98506104369060603d606011610443575b61042e8183610a5d565b810190610a9e565b999150989991925061028e565b503d610424565b34610155576101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101555760043561048681610137565b60243561049281610137565b6044359161049f36610167565b926101243567ffffffffffffffff8111610155576104c1903690600401610196565b9073ffffffffffffffffffffffffffffffffffffffff9384811692604051967f2c8ce6bc000000000000000000000000000000000000000000000000000000008852606088600481885afa9283156103c75784610567947f05499aba408f669fb848399c146fad5bd604d50b15566bdc19e81c40922fab8d9a6000906000926105a7575b5061055d836105548885611359565b33848f1661136c565b606435938a611fc2565b95909461057961036b61036588611a4b565b604080519485526020850191909152941693339290819081015b0390a4604080519182526020820192909252f35b90506105c2915060603d6060116104435761042e8183610a5d565b91905038610545565b346101555760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101555760043561060681610137565b6024359061061382610137565b6044359060843567ffffffffffffffff811161015557610637903690600401610196565b9273ffffffffffffffffffffffffffffffffffffffff808216916040517f2c8ce6bc000000000000000000000000000000000000000000000000000000008152606081600481875afa80156103c75761036b977f05499aba408f669fb848399c146fad5bd604d50b15566bdc19e81c40922fab8d93886106e2936106ea956000906000926106f4575b506106d8836106cf8785611359565b338c861661136c565b606435938b611417565b979096611a4b565b9161057986611a4b565b905061070f915060603d6060116104435761042e8183610a5d565b919050386106c0565b3461015557610726366101a4565b60409491929451907f2c8ce6bc00000000000000000000000000000000000000000000000000000000825260608260048173ffffffffffffffffffffffffffffffffffffffff89165afa80156103c75785948792866000956000946108ca575b506107e18473ffffffffffffffffffffffffffffffffffffffff946107da6107cc604098966107b761081597611af4565b8b6107c46102a988611be3565b9242926120fa565b9f919e909b8933911661136c565b878a6121dc565b845196879485947f29910b110000000000000000000000000000000000000000000000000000000086521660048501610fbf565b0381600073ffffffffffffffffffffffffffffffffffffffff89165af19081156103c75761084c9261036b926108ac575b50611a4b565b7fa4519acd6c251a3f533922c5aaf3fbae71546aad6c01f8241e23143519a67ac873ffffffffffffffffffffffffffffffffffffffff61088b86611a4b565b60408051948552602085019190915293811694169233929081908101610593565b6108c49060403d6040116103c0576103b28183610a5d565b50610846565b6107b7929650604094506108159173ffffffffffffffffffffffffffffffffffffffff946107da6107cc61090f6107e19560603d6060116104435761042e8183610a5d565b9c91509b99509650505094509150610786565b6101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101555760043561095981610137565b60243561096581610137565b60a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c3601126101555767ffffffffffffffff9061010435828111610155576109b2903690600401610196565b610124359283116101555761012c936109d261010f943690600401610196565b9260443591610ff1565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b67ffffffffffffffff8111610a1f57604052565b6109dc565b610120810190811067ffffffffffffffff821117610a1f57604052565b6040810190811067ffffffffffffffff821117610a1f57604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff821117610a1f57604052565b90816060910312610155578051610ab481610137565b9160406020830151610ac581610137565b920151610ad181610137565b90565b6040513d6000823e3d90fd5b35610ad181610137565b949193929473ffffffffffffffffffffffffffffffffffffffff809216906040928351967f2c8ce6bc000000000000000000000000000000000000000000000000000000008852606088600481875afa80156103c7578998600090600092610e4b575b5083610b598a84611359565b91818416928580610e39575b505016986000926000928592600190610b84610b808261225a565b1590565b610e08575b50610c21575b5050507fa3a2846538c60e47775faa60c6ae79b67dee6d97bb70e386ebbaf4c3a38e8b81939291610bd661036b610365610bd0610c1c959e85809f8c611820565b9e610ae0565b97610be08d611a4b565b905194859416983397859094939260609273ffffffffffffffffffffffffffffffffffffffff6080840197168352602083015260408201520152565b0390a4565b89517f70a082310000000000000000000000000000000000000000000000000000000080825273ffffffffffffffffffffffffffffffffffffffff8e166004830152909d506020979695909490939192909190888f8f81806024810103915afa9e8f156103c75760009f610dd3575b5090610c9d8c928f612e32565b93610cd4835195869384937f5b709f1700000000000000000000000000000000000000000000000000000000855260048501610fbf565b038160008d5af19081156103c757610cf492600092610db2575b506113cb565b885192835273ffffffffffffffffffffffffffffffffffffffff8b1660048401529085836024818e5afa9586156103c757610365610bd08f9e610bd694610d71610d77927fa3a2846538c60e47775faa60c6ae79b67dee6d97bb70e386ebbaf4c3a38e8b819c610c1c9a61036b98600092610d85575b505061140a565b906113cb565b969798505050829350610b8f565b610da49250803d10610dab575b610d9c8183610a5d565b81019061138d565b3880610d6a565b503d610d92565b610dca9192508b3d8d116103c0576103b28183610a5d565b90509038610cee565b8c92919f508e908a3d8c11610e01575b610ded8183610a5d565b8101610df89161138d565b9f919250610c90565b503d610de3565b929550509250610e1b915084838c612a02565b919490939091838115610b8957610e33908380612d2d565b38610b89565b610e44913386612289565b3885610b65565b9050610e66915060603d6060116104435761042e8183610a5d565b91905038610b4d565b6040519061016582610a24565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c60a0910112610155576040519060a0820182811067ffffffffffffffff821117610a1f57604052816064358152608435602082015260a435604082015260c4356060820152608060e435910152565b91908260a09103126101555760405160a0810181811067ffffffffffffffff821117610a1f576040526080808294803584526020810135602085015260408101356040850152606081013560608501520135910152565b9190826040910312610155576020825192015190565b60005b838110610f6c5750506000910152565b8181015183820152602001610f5c565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f602093610fb881518092818752878088019101610f59565b0116010190565b610ad1939273ffffffffffffffffffffffffffffffffffffffff60609316825260208201528160408201520190610f7c565b93949192909473ffffffffffffffffffffffffffffffffffffffff9485871691604051957f2c8ce6bc000000000000000000000000000000000000000000000000000000008752606087600481875afa9889156103c75760009760009a611330575b5061105e838b611359565b996080870161106d8189611664565b3561107781611697565b600090611083816116a1565b8061114e57505050906110e69392916110dd888b7fa3a2846538c60e47775faa60c6ae79b67dee6d97bb70e386ebbaf4c3a38e8b819e8e6110c384610ae0565b6110d46020860135809233906136f5565b925b1690613733565b998a9287611e1a565b9790979688610c1c8861111161036b60206111096111038c610ae0565b96611a4b565b9a0135611a4b565b60405194859416983397859094939260609273ffffffffffffffffffffffffffffffffffffffff6080840197168352602083015260408201520152565b8061115a6003926116a1565b036111cf575050906110e69392916110dd888b7fa3a2846538c60e47775faa60c6ae79b67dee6d97bb70e386ebbaf4c3a38e8b819e8e61119984610ae0565b6111aa6020860135809233906136f5565b6111c9816111b787610ae0565b6111c360408901610ae0565b90612f47565b926110d6565b8b6111df8a979695949397610ae0565b16611303576111f160208a013561368f565b61121c61120361120360608c01610ae0565b73ffffffffffffffffffffffffffffffffffffffff1690565b956112296112038b610ae0565b6112fc5760208a0135965b6112476112408c610ae0565b928c611664565b97813b15610133576020908c61128f6040519b8c96879586947f2bdb823c00000000000000000000000000000000000000000000000000000000865201359060048501611793565b03925af19b8c156103c757888b6110dd927fa3a2846538c60e47775faa60c6ae79b67dee6d97bb70e386ebbaf4c3a38e8b819f8f90996110e69a6112e3575b506111c96112de60408601610ae0565b612ede565b806112f06112f692610a0b565b806116e4565b386112ce565b8196611234565b61132b6113126112038b610ae0565b61131e60608c01610ae0565b60208c013591339061136c565b6111f1565b90995061134d91975060603d6060116104435761042e8183610a5d565b97919050969838611053565b906113639061225a565b61120357503090565b9291908261137b575b50505050565b61138493612289565b38808080611375565b90816020910312610155575190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b919082018092116113d857565b61139c565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82019182116113d857565b919082039182116113d857565b9694939160009760009784600191611431610b808261225a565b611618575b5050611486575b505050505080841061144c5750565b6040517f0a4439e6000000000000000000000000000000000000000000000000000000008152600481018590526024810191909152604490fd5b73ffffffffffffffffffffffffffffffffffffffff989497919293959880931660409889517f70a082310000000000000000000000000000000000000000000000000000000091828252602097888380611500896004830191909173ffffffffffffffffffffffffffffffffffffffff6020820193169052565b0381885afa9788156103c7578d936000996115f9575b50806115228489612e32565b9385519d8e95869485937f5b709f170000000000000000000000000000000000000000000000000000000085521691600484019261155f93610fbf565b0392165a90600091f19788156103c7576115b6988795611586926000926115e157506113cb565b995180988194829383526004830191909173ffffffffffffffffffffffffffffffffffffffff6020820193169052565b03915afa80156103c7576115d694610d7193600092610d8557505061140a565b92388080808061143d565b610dca9192508d803d106103c0576103b28183610a5d565b6116119199508a3d8c11610dab57610d9c8183610a5d565b9738611516565b929a5098505061164391935073ffffffffffffffffffffffffffffffffffffffff851697888a612a02565b94929991988591999a809615611436578161165d92612d2d565b3880611436565b9035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8181360301821215610155570190565b6004111561015557565b600411156116ab57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b35610ad181611697565b600091031261015557565b359061016582611697565b90357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18236030181121561015557016020813591019167ffffffffffffffff821161015557813603831361015557565b601f82602094937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0938186528686013760008582860101520116010190565b8015150361015557565b9173ffffffffffffffffffffffffffffffffffffffff809216835260208301526060604083015282356117c581611697565b6117ce816116a1565b606083015260208301356117e181610137565b16608082015260c0606061180c6117fb60408601866116fa565b608060a087015260e086019161174a565b93013561181881611789565b151591015290565b939293608085016118396118348288611664565b6116da565b611842816116a1565b8061189f575050602092611857928692612e50565b925b01358083106118655750565b6040517fc5b5576d000000000000000000000000000000000000000000000000000000008152600481018490526024810191909152604490fd5b806118b060039298959694986116a1565b036118f557506118c7826118f09260209530612e50565b80956118e2826118d960408701610ae0565b6111c387610ae0565b6118eb84610ae0565b612d2d565b611859565b906112036112036119178561191d9460608201986119128a610ae0565b612e50565b95610ae0565b61193361192c60408501610ae0565b9284611664565b90803b15610155576119799460008094604051978895869485937f2bdb823c00000000000000000000000000000000000000000000000000000000855260048501611793565b03925af19182156103c7576020926119a7575b506118f061199c6112de83610ae0565b80956118eb84610ae0565b806112f06119b492610a0b565b3861198c565b9081600003918083057fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14901517156113d857565b90670de0b6b3a7640000918281029281840514901517156113d857565b8181029291600082127f80000000000000000000000000000000000000000000000000000000000000008214166113d85781840514901517156113d857565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116101555790565b519061016582610137565b908161012091031261015557611a94610e6f565b90805182526020810151602083015260408101516040830152611ab960608201611a75565b60608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e0830152610100809101519082015290565b61010090604051611b0481610a24565b60009281848093528260208201528260408201528260608201528260808201528260a08201528260c08201528260e0820152015260405180917f794052f30000000000000000000000000000000000000000000000000000000082526101209182918173ffffffffffffffffffffffffffffffffffffffff81611ba7306004830191909173ffffffffffffffffffffffffffffffffffffffff6020820193169052565b0392165afa9283156103c75792611bbd57505090565b610ad19250803d10611bdc575b611bd48183610a5d565b810190611a80565b503d611bca565b602073ffffffffffffffffffffffffffffffffffffffff600460009360405194859384927f1d52edc4000000000000000000000000000000000000000000000000000000008452165af19081156103c757600091611c3f575090565b610ad1915060203d602011610dab57610d9c8183610a5d565b9392611c6990959192958386613042565b94604084015115611d29575b60005b6060850151811015611cff57611c8e8186613308565b611ca6611c9d82878b8b61339d565b50919087614320565b848111611ce757611cbc608089015186836133b7565b611cce57505085526001905b01611c78565b949650965096505050611ce291508461140a565b929190565b505090611cf56001926113dd565b6020870152611cc8565b60046040517ffa711db2000000000000000000000000000000000000000000000000000000008152fd5b611d34818551613140565b845260208401611d508151611d4a88518a6131ec565b90613280565b9052611d5b8461328d565b611c75565b67ffffffffffffffff8111610a1f57601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b6040519060c0820182811067ffffffffffffffff821117610a1f5760405260a0808352366020840137565b604051906080820182811067ffffffffffffffff821117610a1f576040526060808352366020840137565b93929190611dfc611d9a565b946002602087015260408601526060850152608084015260a0830152565b9196949395966000976000978092600192611e37610b808261225a565b611f76575b505050611e8c575b50505050808410611e525750565b6040517fa59b8c31000000000000000000000000000000000000000000000000000000008152600481018590526024810191909152604490fd5b918184611ec0600095611ea56040969c98999b9c611af4565b611eae84611be3565b91611eb836610e7c565b9242926133f5565b50948593611ee473ffffffffffffffffffffffffffffffffffffffff9384926134dd565b98611f1e87519a8b97889687947f29910b110000000000000000000000000000000000000000000000000000000086521660048501610fbf565b0393165af19081156103c757611f4793600092611f51575b50611f4191926113cb565b946113cb565b9138808080611e44565b611f419250611f6e9060403d6040116103c0576103b28183610a5d565b905091611f36565b925098509850611fa1915073ffffffffffffffffffffffffffffffffffffffff809816988985612a02565b919990989083908315611e3c57611fba92881690612d2d565b388080611e3c565b929396979590916000986000988092600192611fe0610b808261225a565b6120ae575b505050611ffc575b5050505050808410611e525750565b918461202360009593604095612016859d999a9c9d611af4565b90611eb86102a986611be3565b5094859361204773ffffffffffffffffffffffffffffffffffffffff9384926134dd565b9861208187519a8b97889687947f29910b110000000000000000000000000000000000000000000000000000000086521660048501610fbf565b0393165af19081156103c7576120a393600092611f515750611f4191926113cb565b913880808080611fed565b9250995099506120d9915073ffffffffffffffffffffffffffffffffffffffff809916998a86612a02565b919a90999083908315611fe5576120f292891690612d2d565b388080611fe5565b939261210b90959192958386613042565b946040840151156121ac575b60005b6060850151811015611cff576121308186613308565b84670de0b6b3a764000061215161214984848d8d613674565b5093906131aa565b0461215c818461140a565b85811161219357612173908660808b0151916133b7565b61218557505085526001905b0161211a565b985090965094509192505050565b505050906121a26001926113dd565b602087015261217f565b6121b7818551613140565b8452602084016121cc8151611d4a89896134fb565b90526121d78461328d565b612117565b939291906121e8611d9a565b946003602087015260408601526060850152608084015260a0830152565b9035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe181360301821215610155570180359067ffffffffffffffff821161015557602001918160051b3603831361015557565b6122676040820182612206565b9050159081612274575090565b61228391506060810190612206565b90501590565b9290604051927f23b872dd00000000000000000000000000000000000000000000000000000000602085015273ffffffffffffffffffffffffffffffffffffffff809216602485015216604483015260648201526064815260a081019181831067ffffffffffffffff841117610a1f5761016592604052613800565b9035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe181360301821215610155570180359067ffffffffffffffff82116101555760200191813603831361015557565b604051600081526020810181811067ffffffffffffffff821117610a1f5760405290565b6080818303126101555780519260208201519260408301519260608101519067ffffffffffffffff8211610155570181601f820112156101555780516123bf81611d60565b926123cd6040519485610a5d565b8184526020828401011161015557610ad19160208085019101610f59565b906123f5826116a1565b52565b9594929093919360a0948060a0890160a08a525260c09560c089019260c08360051b8b01019781946000925b8584106124a157505050505050509185949391612460612493946020610ad199019073ffffffffffffffffffffffffffffffffffffffff169052565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040870152858303606087015261174a565b916080818403910152610f7c565b909192939495997fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff408d82030183528a357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa18336030181121561015557820160609080357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe8182360301811215610155578101928281528335838201526020938493608091858101358385015260409283928d84840135908701528201612565906116ef565b8b8601612571916123eb565b810161257c9061015a565b9060e0918286016125a19173ffffffffffffffffffffffffffffffffffffffff169052565b6125ac818e0161015a565b610100908187016125d19173ffffffffffffffffffffffffffffffffffffffff169052565b6125dc828d0161015a565b92610120938488016126029173ffffffffffffffffffffffffffffffffffffffff169052565b820161260d9061015a565b610140908188016126329173ffffffffffffffffffffffffffffffffffffffff169052565b610160918301358288015261018093830135848801528201356101a0870152810161265c916116fa565b90916101c08601526101e08501906126739261174a565b61267f858701866116fa565b85830388870152612690929161174a565b9301359101529b0196959460010193920190612424565b959391979694929060a0988060a0890160a08a525260c09960c089019260c08360051b8b01019b81946000925b8584106127225750505050505050916124939391612710610ad1989994602089019073ffffffffffffffffffffffffffffffffffffffff169052565b6040870152858303606087015261174a565b9091929394959d8e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff408e8303018452357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa18336030181121561015557820160609080357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe8182360301811215610155578101928281528335838201526020938493608091858101358385015260409283928d848401359087015282016127e6906116ef565b8b86016127f2916123eb565b81016127fd9061015a565b9060e0918286016128229173ffffffffffffffffffffffffffffffffffffffff169052565b61282d818e0161015a565b610100908187016128529173ffffffffffffffffffffffffffffffffffffffff169052565b61285d828d0161015a565b92610120938488016128839173ffffffffffffffffffffffffffffffffffffffff169052565b820161288e9061015a565b610140908188016128b39173ffffffffffffffffffffffffffffffffffffffff169052565b610160918301358288015261018093830135848801528201356101a087015281016128dd916116fa565b90916101c08601526101e08501906128f49261174a565b612900858701866116fa565b85830388870152612911929161174a565b9301359101529f01969594600101939201906126d4565b9015612961578035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa181360301821215610155570190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9035907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe8181360301821215610155570190565b6080810195949093606093926129d8816116a1565b855273ffffffffffffffffffffffffffffffffffffffff8093166020860152604085015216910152565b9193909360009360008094612a1961120384610ae0565b849860408501612a298187612206565b9050612c10575b50506060840191612a418386612206565b9050612a6a575b50505050670de0b6b3a7640000916020612a64920135906131aa565b04841190565b918394979998929184928a9795612a81848c612206565b612a8a91612928565b80612a9491612990565b60a001612aa090610ae0565b91612aab858d612206565b612ab491612928565b80612abe91612990565b606001612aca906116da565b94612ad5908d612206565b91612ae360808f018f612305565b9c9097604051928392886020850193612afb946129c3565b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081018252612b2b9082610a5d565b6040517f6122b1730000000000000000000000000000000000000000000000000000000081529b8c9788968795612b6595600488016123f8565b039273ffffffffffffffffffffffffffffffffffffffff165af19384156103c757670de0b6b3a76400009484602093612bd293612a6497928094612bdb575b5050612bc6612bbf848780612bcc9697518301019101610f43565b90926113cb565b9a61140a565b996113cb565b95928294612a48565b612bbf9450612bcc9350612bc691612c04913d8091833e612bfc8183610a5d565b81019061237a565b96925090509350612ba4565b839a508499508692985092849373ffffffffffffffffffffffffffffffffffffffff9283612c3d89610ae0565b911690612c4991613920565b612c539087612206565b909a90612c636080890189612305565b612c6e9d919d612356565b906040519e8f98899788967f6122b1730000000000000000000000000000000000000000000000000000000088526004880196612caa976126a7565b03928a165af19687156103c7578182978399612cd6575b50612ccd90978561140a565b97953880612a30565b9050612ccd9850612cf29197503d8084833e612bfc8183610a5d565b509890979190612cc1565b3d15612d28573d90612d0e82611d60565b91612d1c6040519384610a5d565b82523d6000602084013e565b606090565b8215612e2d5773ffffffffffffffffffffffffffffffffffffffff1680612dc65750600080809381935af1612d60612cfd565b5015612d6857565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f6574682073656e64206661696c656400000000000000000000000000000000006044820152fd5b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000602082015273ffffffffffffffffffffffffffffffffffffffff92909216602483015260448083019390935291815261016591612e28606483610a5d565b613800565b505050565b9190612e3c611dc5565b926001602085015260408401526060830152565b60a49060006020949560409473ffffffffffffffffffffffffffffffffffffffff809681930135612e8081610137565b604051998a9889977f769f8e5d000000000000000000000000000000000000000000000000000000008952166004880152602487015216604485015282606485015260016084850152165af19081156103c757600091611c3f575090565b73ffffffffffffffffffffffffffffffffffffffff1680612efe57504790565b6020602491604051928380927f70a082310000000000000000000000000000000000000000000000000000000082523060048301525afa9081156103c757600091611c3f575090565b73ffffffffffffffffffffffffffffffffffffffff9190821680612fb9575016803b15610155576000906004604051809481937fd0e30db00000000000000000000000000000000000000000000000000000000083525af180156103c757612fac5750565b806112f061016592610a0b565b915050803b15610155576040517f2e1a7d4d00000000000000000000000000000000000000000000000000000000815260048101929092526000908290602490829084905af180156103c757612fac5750565b604051906080820182811067ffffffffffffffff821117610a1f5760405260006060838281528260208201528260408201520152565b92919261304d61300c565b9360a0820161305d828251111590565b613116576130879161306f915161140a565b9261307a8484613b6c565b8652602083015190613bf4565b602085019080825282518015801561310e575b6130d3575050816130c08460c0936130cc969551906101008501519051908a5192613c77565b60408701520151613d1d565b6060830152565b6040517fb1c4aefb00000000000000000000000000000000000000000000000000000000815260048101919091526024810191909152604490fd5b50811561309a565b60046040517fb2094b59000000000000000000000000000000000000000000000000000000008152fd5b908082111561314d575090565b905090565b90670de0b6b3a7640000600083820393128184128116918413901516176113d857565b818103929160001380158285131691841216176113d857565b919091600083820193841291129080158216911516176113d857565b818102929181159184041417156113d857565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b9061321a6132206132066060850151604086015190613175565b670de0b6b3a7640000928391865190611a0c565b05613dfd565b9281840190828212600086129080158216911516176113d857613257602061324e61325d94613264986141da565b9201518561318e565b90611a0c565b0590613175565b6103e7908181029181830414901517156113d8576103e8900490565b908082101561314d575090565b805160208201519182821180156132f3575b6132a857505050565b60806104059101516040519384937fb301af04000000000000000000000000000000000000000000000000000000008552600485016040919493926060820195825260208201520152565b50670de0b6b3a764000060808201511161329f565b901580613363575b61335c57602081519101518082111561334d5760046040517ffa711db2000000000000000000000000000000000000000000000000000000008152fd5b81018091116113d85760011c90565b6040015190565b5060408101511515613310565b7f800000000000000000000000000000000000000000000000000000000000000081146113d85760000390565b91611ce29493916133ad936141e3565b9291939093613370565b90918282111592836133ca575b50505090565b90919250670de0b6b3a76400009182038281116113d8576133ea916131aa565b0411153880806133c4565b939192613406909591958686613042565b92604083015115613499575b60005b6060840151811015611cff5761342b8185613308565b61344c61343a828a898b613674565b509190613447848c614722565b61140a565b8481116134815761346390856080890151916133b7565b613474575084526001905b01613415565b9750945050509250509190565b50509061348f6001926113dd565b602086015261346e565b6134b88351670de0b6b3a76400006134b189856131aa565b0490613140565b8352602083016134cd8151611d4a87896134fb565b90526134d88361328d565b613412565b91906134e7611dc5565b926000602085015260408401526060830152565b600080926020906020810180517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81019081116113d8575b8087036135435750505050505090565b8087018088116113d85760018082018092116113d8571c908651613568838551613175565b613572828561318e565b918882138061366b575b1561360d57916135ea6135cc6135c76135f0946135c26135bc6135ac8f996135a6908e519061318e565b8c611a0c565b6135b68489611a0c565b906141da565b956119ef565b613d77565b61477b565b6135e56135d98a51613d5d565b9160408b015194613175565b613d81565b90613175565b12156136055750613600906113dd565b613533565b965095613533565b606488604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152601260248201527f696e76616c6964207074546f4d61726b657400000000000000000000000000006044820152fd5b5088831361357c565b919061368261368894613370565b926141e3565b9192909190565b340361369757565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f657468206d69736d6174636800000000000000000000000000000000000000006044820152fd5b90919073ffffffffffffffffffffffffffffffffffffffff168061371e57509050340361369757565b8161372857505050565b610165923091612289565b608490604060209495013561374781610137565b73ffffffffffffffffffffffffffffffffffffffff80948183169788156000146137e05761378981945b61377a81610137565b6137848482613920565b610137565b60405198899788967f20e8c5650000000000000000000000000000000000000000000000000000000088521660048701526024860152604485015260016064850152165af19081156103c757600091611c3f575090565b613789600094613771565b908160209103126101555751610ad181611789565b60405161386b9173ffffffffffffffffffffffffffffffffffffffff1661382682610a41565b6000806020958685527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656487860152868151910182855af1613865612cfd565b91614c08565b805190828215928315613908575b505050156138845750565b608490604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b61391893508201810191016137eb565b388281613879565b919073ffffffffffffffffffffffffffffffffffffffff92838116938415613b0b576040519485917fdd62ed3e0000000000000000000000000000000000000000000000000000000083523060048401528416602483015281604460209788935afa80156103c7576b7fffffffffffffffffffffff91600091613aee575b50106139ab575b50509050565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000085820190815273ffffffffffffffffffffffffffffffffffffffff8416602483015260006044830181905291829190613a3381606481015b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282610a5d565b519082855af1613a41612cfd565b81613abe575b5015613a6057613a58929350614353565b8038806139a5565b606484604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152600c60248201527f5361666520417070726f766500000000000000000000000000000000000000006044820152fd5b80518015925086908315613ad6575b50505038613a47565b613ae693508201810191016137eb565b388581613acd565b613b059150863d8811610dab57610d9c8183610a5d565b3861399e565b5050509050565b8115613b67577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82147f80000000000000000000000000000000000000000000000000000000000000008214166113d8570590565b6131bd565b60800151906301e13380918281029281840514901517156113d8577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557613bb791613b12565b906000821315613bc357565b602482604051907f1ca418760000000000000000000000000000000000000000000000000000000082526004820152fd5b613c3b670de0b6b3a76400009160008412600014613c6c57613c367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9461447d565b6131aa565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557610ad191611a0c565b613c3660019461447d565b9193613c88906301e13380926131aa565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557613cb990613dfd565b92670de0b6b3a76400008412613cec5791613ce7613ce2836135b6610ad197966135ea9661318e565b614492565b6141da565b602484604051907fca78c8a40000000000000000000000000000000000000000000000000000000082526004820152fd5b6301e1338091613d2c916131aa565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557610ad190613dfd565b8015613b67576ec097ce7bc90715b34b9f10000000000590565b8115613b67570590565b670de0b6b3a764000091613d9491611a0c565b0590565b15613d9f57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f496e76616c6964206578706f6e656e74000000000000000000000000000000006044820152fd5b7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc0000811215806141c7575b613e3090613d98565b600081126141b2576064906806f05b59d3b2000000811261414f577ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e0000000168056bc75e2d6310000082770195e54c5dd42177f53a27172fa9ec630262827000000000925b02819068ad78ebc5ac62000000811215614116575b806856bc75e2d631000000849212156140dc575b682b5e3af16b188000008112156140a4575b6815af1d78b58c40000081121561406c575b680ad78ebc5ac6200000811215614035575b81811215613ffe575b6802b5e3af16b1880000811215613fc7575b68015af1d78b58c40000811215613f90575b60028282800205056003838383020505600484848302050560058585830205056006868683020505600787878302050590600888888402050592600989898602050594600a8a8a8802050596600b8b8b8a02050598600c8c8c8c0205059a0101010101010101010101010205020590565b6806f5f17757889379377ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000083920193020591613f1f565b6808f00f760a4b2db55d7ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000083920193020591613f0d565b680ebc5fb417461211107ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000083920193020591613efb565b68280e60114edb805d037ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000083920193020591613ef2565b690127fa27722cc06cc5e27fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c0000083920193020591613ee0565b693f1fce3da636ea5cf8507fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e780000083920193020591613ece565b6b02df0ab5a80a22c61ab5a7007fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf00000083920193020591613ebc565b6e01855144814a7ff805980ff008400091507fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e00000001613ea8565b6803782dace9d9000000811261419f577ffffffffffffffffffffffffffffffffffffffffffffffffc87d25316270000000168056bc75e2d63100000826b1425982cf597cd205cef738092613e93565b68056bc75e2d6310000082600192613e93565b6141be90600003613dfd565b610ad190613d5d565b5068070c1cc73b00c80000811315613e27565b613d77906119ef565b90939192614200818351602088015188519060408a0151926144f1565b6000606061421461036b846135c2876119ef565b9701519213156142e357816135c261422b926119ef565b670de0b6b3a764000081126142b057509361429b614281610ad19361427b61427461426e61426361425d60e09c613152565b88613d81565b9a8b945b0151611a4b565b83611a0c565b6064900590565b93613175565b60008112156142a15761429490866146aa565b958561461b565b9361461b565b6142ab908661461b565b614294565b6040517fca78c8a40000000000000000000000000000000000000000000000000000000081526004810191909152602490fd5b509361429b614281610ad19361427b61427461426e61431861036b8c61431361430d60e09f613152565b8b611a0c565b613b12565b9a8b94614267565b614329916131aa565b670de0b6b3a764000090818101908181116113d857670de0b6b3a763ffff019081116113d8570490565b6040517f095ea7b3000000000000000000000000000000000000000000000000000000006020820190815273ffffffffffffffffffffffffffffffffffffffff90931660248201527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff604482015260009283929183906143d68160648101613a07565b51925af16143e2612cfd565b8161444e575b50156143f057565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f5361666520417070726f766500000000000000000000000000000000000000006044820152fd5b8051801592508215614463575b5050386143e8565b61447692506020809183010191016137eb565b388061445b565b60008113156144895790565b610ad190613370565b670de0b6b3a7640000908181146144c757808203916000821280158285131691841216176113d857610ad1916135c7916141da565b60046040517fa9c8b14d000000000000000000000000000000000000000000000000000000008152fd5b909194938082126145bd576145139261450d6135b69284613175565b9261318e565b92670d529ae9e8600000841361457d5761453490613ce76145399495614492565b61318e565b90670de0b6b3a7640000821261454b57565b6040517fca78c8a400000000000000000000000000000000000000000000000000000000815260048101839052602490fd5b6040517ffc68d09e00000000000000000000000000000000000000000000000000000000815260048101859052670d529ae9e86000006024820152604490fd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600860248201527f6e656761746976650000000000000000000000000000000000000000000000006044820152fd5b600082121561469f5761464e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9261447d565b670de0b6b3a7640000908181029181830414901517156113d8578115613b6757047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557610ad191611a0c565b61464e60019261447d565b6146e7906000831215614717576146e17fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9361447d565b90614722565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557610ad191611a0c565b6146e160019361447d565b90670de0b6b3a7640000908181029181830414901517156113d8578181018091116113d8577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81019081116113d8578115613b67570490565b600081131561485e5780670c7d713b49da0000128061484d575b1561484457670de0b6b3a7640000906ec097ce7bc90715b34b9f1000000000906147e8908302828101907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f000000000018302613d77565b9080828002059181838202058284820205838582020591848684020593858786020595808888020597880205600f900596600d900595600b900594600990059360079005926005900591600390050101010101010160011b0590565b610ad1906148bc565b50670f43fc2c04ee00008112614795565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6f7574206f6620626f756e6473000000000000000000000000000000000000006044820152fd5b670de0b6b3a76400008112614bf15760649060007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c0000000000000821215614bc6575b73011798004d755d3c8bc8e03204cf44619e000000821215614ba5575b820290808302906e01855144814a7ff805980ff00840009081831215614b82575b50506b02df0ab5a80a22c61ab5a70080821215614b62575b50693f1fce3da636ea5cf85080821215614b42575b50690127fa27722cc06cc5e280821215614b22575b5068280e60114edb805d0380821215614b02575b50680ebc5fb4174612111080821215614aeb575b506808f00f760a4b2db55d80821215614acb575b506806f5f177578893793780821215614aab575b506806248f33704b28660380821215614a8c575b506805c548670b9510e7ac80821215614a6d575b50614a2c68056bc75e2d6310000091827ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf00000818301920102613d77565b9080828002059181838202058284820205916003600560076009600b888a89020598808b8b02059a8b0205059805960594059205010101010160011b010590565b68056bc75e2d631000006756bc75e2d6310000920205910190386149f0565b68056bc75e2d6310000067ad78ebc5ac620000920205910190386149dc565b68056bc75e2d6310000068015af1d78b58c40000920205910190386149c8565b68056bc75e2d631000006802b5e3af16b1880000920205910190386149b4565b68056bc75e2d6310000080920205910190386149a0565b68056bc75e2d63100000680ad78ebc5ac62000009202059101903861498c565b68056bc75e2d631000006815af1d78b58c40000092020591019038614978565b68056bc75e2d63100000682b5e3af16b1880000092020591019038614963565b68056bc75e2d631000006856bc75e2d6310000009202059101903861494e565b68ad78ebc5ac62000000925069021e19e0c9bab240000002059101903880614936565b906b1425982cf597cd205cef73806803782dace9d900000091059101614915565b50770195e54c5dd42177f53a27172fa9ec63026282700000000090056806f05b59d3b20000006148f8565b614bfd614c0291613d5d565b6148bc565b60000390565b91929015614c835750815115614c1c575090565b3b15614c255790565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b825190915015614c965750805190602001fd5b610405906040519182917f08c379a0000000000000000000000000000000000000000000000000000000008352602060048401526024830190610f7c56fea264697066735822122000bf99e240ef88f53cf4147b7a48747591c1bd636a2ac3dac4cdafa5ec92def164736f6c63430008170033
Deployed Bytecode
0x6080604052600436101561001257600080fd5b6000803560e01c90816305eb53271461007a57508063448b9b95146100755780637b8b4b951461007057806380c4d5661461006b578063c861a898146100665763ed48907e1461006157600080fd5b610922565b610718565b6105cb565b61044a565b61021f565b346101305760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261013057600435906100b682610137565b602435916100c383610137565b67ffffffffffffffff606435818111610133576100e4903690600401610196565b926084359182116101305761012c61010f8686866101053660048901610196565b9260443591610aea565b604080519384526020840192909252908201529081906060820190565b0390f35b80fd5b8380fd5b73ffffffffffffffffffffffffffffffffffffffff81160361015557565b600080fd5b359061016582610137565b565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7c60a091011261015557608490565b908160a09103126101555790565b6101207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc820112610155576004356101db81610137565b916024356101e881610137565b916044359160a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7c60643593011261015557608490565b346101555761022d366101a4565b91909373ffffffffffffffffffffffffffffffffffffffff91828516906040938451957f2c8ce6bc000000000000000000000000000000000000000000000000000000008752606087600481875afa9788156103c757600097600099610409575b509061029c6102b992611af4565b846102b16102a98c611be3565b933690610eec565b924292611c58565b98919790998089106103cc5750986102e78261031c999a9b6102e087878c9716338161136c565b8b89611df0565b90825198899283927f5b709f170000000000000000000000000000000000000000000000000000000084523060048501610fbf565b03816000875af19081156103c75761012c967fa4519acd6c251a3f533922c5aaf3fbae71546aad6c01f8241e23143519a67ac89261039b575b5061037061036b6103658a611a4b565b94611a4b565b6119ba565b8651938452602084015293909316923391604090a45191825260208201929092529081906040820190565b6103ba90873d89116103c0575b6103b28183610a5d565b810190610f43565b50610355565b503d6103a8565b610ad4565b87517f9cdffc8e000000000000000000000000000000000000000000000000000000008152600481018a90526024810191909152604490fd5b0390fd5b6102b99291995061029c98506104369060603d606011610443575b61042e8183610a5d565b810190610a9e565b999150989991925061028e565b503d610424565b34610155576101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101555760043561048681610137565b60243561049281610137565b6044359161049f36610167565b926101243567ffffffffffffffff8111610155576104c1903690600401610196565b9073ffffffffffffffffffffffffffffffffffffffff9384811692604051967f2c8ce6bc000000000000000000000000000000000000000000000000000000008852606088600481885afa9283156103c75784610567947f05499aba408f669fb848399c146fad5bd604d50b15566bdc19e81c40922fab8d9a6000906000926105a7575b5061055d836105548885611359565b33848f1661136c565b606435938a611fc2565b95909461057961036b61036588611a4b565b604080519485526020850191909152941693339290819081015b0390a4604080519182526020820192909252f35b90506105c2915060603d6060116104435761042e8183610a5d565b91905038610545565b346101555760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101555760043561060681610137565b6024359061061382610137565b6044359060843567ffffffffffffffff811161015557610637903690600401610196565b9273ffffffffffffffffffffffffffffffffffffffff808216916040517f2c8ce6bc000000000000000000000000000000000000000000000000000000008152606081600481875afa80156103c75761036b977f05499aba408f669fb848399c146fad5bd604d50b15566bdc19e81c40922fab8d93886106e2936106ea956000906000926106f4575b506106d8836106cf8785611359565b338c861661136c565b606435938b611417565b979096611a4b565b9161057986611a4b565b905061070f915060603d6060116104435761042e8183610a5d565b919050386106c0565b3461015557610726366101a4565b60409491929451907f2c8ce6bc00000000000000000000000000000000000000000000000000000000825260608260048173ffffffffffffffffffffffffffffffffffffffff89165afa80156103c75785948792866000956000946108ca575b506107e18473ffffffffffffffffffffffffffffffffffffffff946107da6107cc604098966107b761081597611af4565b8b6107c46102a988611be3565b9242926120fa565b9f919e909b8933911661136c565b878a6121dc565b845196879485947f29910b110000000000000000000000000000000000000000000000000000000086521660048501610fbf565b0381600073ffffffffffffffffffffffffffffffffffffffff89165af19081156103c75761084c9261036b926108ac575b50611a4b565b7fa4519acd6c251a3f533922c5aaf3fbae71546aad6c01f8241e23143519a67ac873ffffffffffffffffffffffffffffffffffffffff61088b86611a4b565b60408051948552602085019190915293811694169233929081908101610593565b6108c49060403d6040116103c0576103b28183610a5d565b50610846565b6107b7929650604094506108159173ffffffffffffffffffffffffffffffffffffffff946107da6107cc61090f6107e19560603d6060116104435761042e8183610a5d565b9c91509b99509650505094509150610786565b6101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101555760043561095981610137565b60243561096581610137565b60a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c3601126101555767ffffffffffffffff9061010435828111610155576109b2903690600401610196565b610124359283116101555761012c936109d261010f943690600401610196565b9260443591610ff1565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b67ffffffffffffffff8111610a1f57604052565b6109dc565b610120810190811067ffffffffffffffff821117610a1f57604052565b6040810190811067ffffffffffffffff821117610a1f57604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff821117610a1f57604052565b90816060910312610155578051610ab481610137565b9160406020830151610ac581610137565b920151610ad181610137565b90565b6040513d6000823e3d90fd5b35610ad181610137565b949193929473ffffffffffffffffffffffffffffffffffffffff809216906040928351967f2c8ce6bc000000000000000000000000000000000000000000000000000000008852606088600481875afa80156103c7578998600090600092610e4b575b5083610b598a84611359565b91818416928580610e39575b505016986000926000928592600190610b84610b808261225a565b1590565b610e08575b50610c21575b5050507fa3a2846538c60e47775faa60c6ae79b67dee6d97bb70e386ebbaf4c3a38e8b81939291610bd661036b610365610bd0610c1c959e85809f8c611820565b9e610ae0565b97610be08d611a4b565b905194859416983397859094939260609273ffffffffffffffffffffffffffffffffffffffff6080840197168352602083015260408201520152565b0390a4565b89517f70a082310000000000000000000000000000000000000000000000000000000080825273ffffffffffffffffffffffffffffffffffffffff8e166004830152909d506020979695909490939192909190888f8f81806024810103915afa9e8f156103c75760009f610dd3575b5090610c9d8c928f612e32565b93610cd4835195869384937f5b709f1700000000000000000000000000000000000000000000000000000000855260048501610fbf565b038160008d5af19081156103c757610cf492600092610db2575b506113cb565b885192835273ffffffffffffffffffffffffffffffffffffffff8b1660048401529085836024818e5afa9586156103c757610365610bd08f9e610bd694610d71610d77927fa3a2846538c60e47775faa60c6ae79b67dee6d97bb70e386ebbaf4c3a38e8b819c610c1c9a61036b98600092610d85575b505061140a565b906113cb565b969798505050829350610b8f565b610da49250803d10610dab575b610d9c8183610a5d565b81019061138d565b3880610d6a565b503d610d92565b610dca9192508b3d8d116103c0576103b28183610a5d565b90509038610cee565b8c92919f508e908a3d8c11610e01575b610ded8183610a5d565b8101610df89161138d565b9f919250610c90565b503d610de3565b929550509250610e1b915084838c612a02565b919490939091838115610b8957610e33908380612d2d565b38610b89565b610e44913386612289565b3885610b65565b9050610e66915060603d6060116104435761042e8183610a5d565b91905038610b4d565b6040519061016582610a24565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c60a0910112610155576040519060a0820182811067ffffffffffffffff821117610a1f57604052816064358152608435602082015260a435604082015260c4356060820152608060e435910152565b91908260a09103126101555760405160a0810181811067ffffffffffffffff821117610a1f576040526080808294803584526020810135602085015260408101356040850152606081013560608501520135910152565b9190826040910312610155576020825192015190565b60005b838110610f6c5750506000910152565b8181015183820152602001610f5c565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f602093610fb881518092818752878088019101610f59565b0116010190565b610ad1939273ffffffffffffffffffffffffffffffffffffffff60609316825260208201528160408201520190610f7c565b93949192909473ffffffffffffffffffffffffffffffffffffffff9485871691604051957f2c8ce6bc000000000000000000000000000000000000000000000000000000008752606087600481875afa9889156103c75760009760009a611330575b5061105e838b611359565b996080870161106d8189611664565b3561107781611697565b600090611083816116a1565b8061114e57505050906110e69392916110dd888b7fa3a2846538c60e47775faa60c6ae79b67dee6d97bb70e386ebbaf4c3a38e8b819e8e6110c384610ae0565b6110d46020860135809233906136f5565b925b1690613733565b998a9287611e1a565b9790979688610c1c8861111161036b60206111096111038c610ae0565b96611a4b565b9a0135611a4b565b60405194859416983397859094939260609273ffffffffffffffffffffffffffffffffffffffff6080840197168352602083015260408201520152565b8061115a6003926116a1565b036111cf575050906110e69392916110dd888b7fa3a2846538c60e47775faa60c6ae79b67dee6d97bb70e386ebbaf4c3a38e8b819e8e61119984610ae0565b6111aa6020860135809233906136f5565b6111c9816111b787610ae0565b6111c360408901610ae0565b90612f47565b926110d6565b8b6111df8a979695949397610ae0565b16611303576111f160208a013561368f565b61121c61120361120360608c01610ae0565b73ffffffffffffffffffffffffffffffffffffffff1690565b956112296112038b610ae0565b6112fc5760208a0135965b6112476112408c610ae0565b928c611664565b97813b15610133576020908c61128f6040519b8c96879586947f2bdb823c00000000000000000000000000000000000000000000000000000000865201359060048501611793565b03925af19b8c156103c757888b6110dd927fa3a2846538c60e47775faa60c6ae79b67dee6d97bb70e386ebbaf4c3a38e8b819f8f90996110e69a6112e3575b506111c96112de60408601610ae0565b612ede565b806112f06112f692610a0b565b806116e4565b386112ce565b8196611234565b61132b6113126112038b610ae0565b61131e60608c01610ae0565b60208c013591339061136c565b6111f1565b90995061134d91975060603d6060116104435761042e8183610a5d565b97919050969838611053565b906113639061225a565b61120357503090565b9291908261137b575b50505050565b61138493612289565b38808080611375565b90816020910312610155575190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b919082018092116113d857565b61139c565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82019182116113d857565b919082039182116113d857565b9694939160009760009784600191611431610b808261225a565b611618575b5050611486575b505050505080841061144c5750565b6040517f0a4439e6000000000000000000000000000000000000000000000000000000008152600481018590526024810191909152604490fd5b73ffffffffffffffffffffffffffffffffffffffff989497919293959880931660409889517f70a082310000000000000000000000000000000000000000000000000000000091828252602097888380611500896004830191909173ffffffffffffffffffffffffffffffffffffffff6020820193169052565b0381885afa9788156103c7578d936000996115f9575b50806115228489612e32565b9385519d8e95869485937f5b709f170000000000000000000000000000000000000000000000000000000085521691600484019261155f93610fbf565b0392165a90600091f19788156103c7576115b6988795611586926000926115e157506113cb565b995180988194829383526004830191909173ffffffffffffffffffffffffffffffffffffffff6020820193169052565b03915afa80156103c7576115d694610d7193600092610d8557505061140a565b92388080808061143d565b610dca9192508d803d106103c0576103b28183610a5d565b6116119199508a3d8c11610dab57610d9c8183610a5d565b9738611516565b929a5098505061164391935073ffffffffffffffffffffffffffffffffffffffff851697888a612a02565b94929991988591999a809615611436578161165d92612d2d565b3880611436565b9035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8181360301821215610155570190565b6004111561015557565b600411156116ab57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b35610ad181611697565b600091031261015557565b359061016582611697565b90357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18236030181121561015557016020813591019167ffffffffffffffff821161015557813603831361015557565b601f82602094937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0938186528686013760008582860101520116010190565b8015150361015557565b9173ffffffffffffffffffffffffffffffffffffffff809216835260208301526060604083015282356117c581611697565b6117ce816116a1565b606083015260208301356117e181610137565b16608082015260c0606061180c6117fb60408601866116fa565b608060a087015260e086019161174a565b93013561181881611789565b151591015290565b939293608085016118396118348288611664565b6116da565b611842816116a1565b8061189f575050602092611857928692612e50565b925b01358083106118655750565b6040517fc5b5576d000000000000000000000000000000000000000000000000000000008152600481018490526024810191909152604490fd5b806118b060039298959694986116a1565b036118f557506118c7826118f09260209530612e50565b80956118e2826118d960408701610ae0565b6111c387610ae0565b6118eb84610ae0565b612d2d565b611859565b906112036112036119178561191d9460608201986119128a610ae0565b612e50565b95610ae0565b61193361192c60408501610ae0565b9284611664565b90803b15610155576119799460008094604051978895869485937f2bdb823c00000000000000000000000000000000000000000000000000000000855260048501611793565b03925af19182156103c7576020926119a7575b506118f061199c6112de83610ae0565b80956118eb84610ae0565b806112f06119b492610a0b565b3861198c565b9081600003918083057fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14901517156113d857565b90670de0b6b3a7640000918281029281840514901517156113d857565b8181029291600082127f80000000000000000000000000000000000000000000000000000000000000008214166113d85781840514901517156113d857565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81116101555790565b519061016582610137565b908161012091031261015557611a94610e6f565b90805182526020810151602083015260408101516040830152611ab960608201611a75565b60608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e0830152610100809101519082015290565b61010090604051611b0481610a24565b60009281848093528260208201528260408201528260608201528260808201528260a08201528260c08201528260e0820152015260405180917f794052f30000000000000000000000000000000000000000000000000000000082526101209182918173ffffffffffffffffffffffffffffffffffffffff81611ba7306004830191909173ffffffffffffffffffffffffffffffffffffffff6020820193169052565b0392165afa9283156103c75792611bbd57505090565b610ad19250803d10611bdc575b611bd48183610a5d565b810190611a80565b503d611bca565b602073ffffffffffffffffffffffffffffffffffffffff600460009360405194859384927f1d52edc4000000000000000000000000000000000000000000000000000000008452165af19081156103c757600091611c3f575090565b610ad1915060203d602011610dab57610d9c8183610a5d565b9392611c6990959192958386613042565b94604084015115611d29575b60005b6060850151811015611cff57611c8e8186613308565b611ca6611c9d82878b8b61339d565b50919087614320565b848111611ce757611cbc608089015186836133b7565b611cce57505085526001905b01611c78565b949650965096505050611ce291508461140a565b929190565b505090611cf56001926113dd565b6020870152611cc8565b60046040517ffa711db2000000000000000000000000000000000000000000000000000000008152fd5b611d34818551613140565b845260208401611d508151611d4a88518a6131ec565b90613280565b9052611d5b8461328d565b611c75565b67ffffffffffffffff8111610a1f57601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01660200190565b6040519060c0820182811067ffffffffffffffff821117610a1f5760405260a0808352366020840137565b604051906080820182811067ffffffffffffffff821117610a1f576040526060808352366020840137565b93929190611dfc611d9a565b946002602087015260408601526060850152608084015260a0830152565b9196949395966000976000978092600192611e37610b808261225a565b611f76575b505050611e8c575b50505050808410611e525750565b6040517fa59b8c31000000000000000000000000000000000000000000000000000000008152600481018590526024810191909152604490fd5b918184611ec0600095611ea56040969c98999b9c611af4565b611eae84611be3565b91611eb836610e7c565b9242926133f5565b50948593611ee473ffffffffffffffffffffffffffffffffffffffff9384926134dd565b98611f1e87519a8b97889687947f29910b110000000000000000000000000000000000000000000000000000000086521660048501610fbf565b0393165af19081156103c757611f4793600092611f51575b50611f4191926113cb565b946113cb565b9138808080611e44565b611f419250611f6e9060403d6040116103c0576103b28183610a5d565b905091611f36565b925098509850611fa1915073ffffffffffffffffffffffffffffffffffffffff809816988985612a02565b919990989083908315611e3c57611fba92881690612d2d565b388080611e3c565b929396979590916000986000988092600192611fe0610b808261225a565b6120ae575b505050611ffc575b5050505050808410611e525750565b918461202360009593604095612016859d999a9c9d611af4565b90611eb86102a986611be3565b5094859361204773ffffffffffffffffffffffffffffffffffffffff9384926134dd565b9861208187519a8b97889687947f29910b110000000000000000000000000000000000000000000000000000000086521660048501610fbf565b0393165af19081156103c7576120a393600092611f515750611f4191926113cb565b913880808080611fed565b9250995099506120d9915073ffffffffffffffffffffffffffffffffffffffff809916998a86612a02565b919a90999083908315611fe5576120f292891690612d2d565b388080611fe5565b939261210b90959192958386613042565b946040840151156121ac575b60005b6060850151811015611cff576121308186613308565b84670de0b6b3a764000061215161214984848d8d613674565b5093906131aa565b0461215c818461140a565b85811161219357612173908660808b0151916133b7565b61218557505085526001905b0161211a565b985090965094509192505050565b505050906121a26001926113dd565b602087015261217f565b6121b7818551613140565b8452602084016121cc8151611d4a89896134fb565b90526121d78461328d565b612117565b939291906121e8611d9a565b946003602087015260408601526060850152608084015260a0830152565b9035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe181360301821215610155570180359067ffffffffffffffff821161015557602001918160051b3603831361015557565b6122676040820182612206565b9050159081612274575090565b61228391506060810190612206565b90501590565b9290604051927f23b872dd00000000000000000000000000000000000000000000000000000000602085015273ffffffffffffffffffffffffffffffffffffffff809216602485015216604483015260648201526064815260a081019181831067ffffffffffffffff841117610a1f5761016592604052613800565b9035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe181360301821215610155570180359067ffffffffffffffff82116101555760200191813603831361015557565b604051600081526020810181811067ffffffffffffffff821117610a1f5760405290565b6080818303126101555780519260208201519260408301519260608101519067ffffffffffffffff8211610155570181601f820112156101555780516123bf81611d60565b926123cd6040519485610a5d565b8184526020828401011161015557610ad19160208085019101610f59565b906123f5826116a1565b52565b9594929093919360a0948060a0890160a08a525260c09560c089019260c08360051b8b01019781946000925b8584106124a157505050505050509185949391612460612493946020610ad199019073ffffffffffffffffffffffffffffffffffffffff169052565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6040870152858303606087015261174a565b916080818403910152610f7c565b909192939495997fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff408d82030183528a357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa18336030181121561015557820160609080357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe8182360301811215610155578101928281528335838201526020938493608091858101358385015260409283928d84840135908701528201612565906116ef565b8b8601612571916123eb565b810161257c9061015a565b9060e0918286016125a19173ffffffffffffffffffffffffffffffffffffffff169052565b6125ac818e0161015a565b610100908187016125d19173ffffffffffffffffffffffffffffffffffffffff169052565b6125dc828d0161015a565b92610120938488016126029173ffffffffffffffffffffffffffffffffffffffff169052565b820161260d9061015a565b610140908188016126329173ffffffffffffffffffffffffffffffffffffffff169052565b610160918301358288015261018093830135848801528201356101a0870152810161265c916116fa565b90916101c08601526101e08501906126739261174a565b61267f858701866116fa565b85830388870152612690929161174a565b9301359101529b0196959460010193920190612424565b959391979694929060a0988060a0890160a08a525260c09960c089019260c08360051b8b01019b81946000925b8584106127225750505050505050916124939391612710610ad1989994602089019073ffffffffffffffffffffffffffffffffffffffff169052565b6040870152858303606087015261174a565b9091929394959d8e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff408e8303018452357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa18336030181121561015557820160609080357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe8182360301811215610155578101928281528335838201526020938493608091858101358385015260409283928d848401359087015282016127e6906116ef565b8b86016127f2916123eb565b81016127fd9061015a565b9060e0918286016128229173ffffffffffffffffffffffffffffffffffffffff169052565b61282d818e0161015a565b610100908187016128529173ffffffffffffffffffffffffffffffffffffffff169052565b61285d828d0161015a565b92610120938488016128839173ffffffffffffffffffffffffffffffffffffffff169052565b820161288e9061015a565b610140908188016128b39173ffffffffffffffffffffffffffffffffffffffff169052565b610160918301358288015261018093830135848801528201356101a087015281016128dd916116fa565b90916101c08601526101e08501906128f49261174a565b612900858701866116fa565b85830388870152612911929161174a565b9301359101529f01969594600101939201906126d4565b9015612961578035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa181360301821215610155570190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9035907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe8181360301821215610155570190565b6080810195949093606093926129d8816116a1565b855273ffffffffffffffffffffffffffffffffffffffff8093166020860152604085015216910152565b9193909360009360008094612a1961120384610ae0565b849860408501612a298187612206565b9050612c10575b50506060840191612a418386612206565b9050612a6a575b50505050670de0b6b3a7640000916020612a64920135906131aa565b04841190565b918394979998929184928a9795612a81848c612206565b612a8a91612928565b80612a9491612990565b60a001612aa090610ae0565b91612aab858d612206565b612ab491612928565b80612abe91612990565b606001612aca906116da565b94612ad5908d612206565b91612ae360808f018f612305565b9c9097604051928392886020850193612afb946129c3565b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081018252612b2b9082610a5d565b6040517f6122b1730000000000000000000000000000000000000000000000000000000081529b8c9788968795612b6595600488016123f8565b039273ffffffffffffffffffffffffffffffffffffffff165af19384156103c757670de0b6b3a76400009484602093612bd293612a6497928094612bdb575b5050612bc6612bbf848780612bcc9697518301019101610f43565b90926113cb565b9a61140a565b996113cb565b95928294612a48565b612bbf9450612bcc9350612bc691612c04913d8091833e612bfc8183610a5d565b81019061237a565b96925090509350612ba4565b839a508499508692985092849373ffffffffffffffffffffffffffffffffffffffff9283612c3d89610ae0565b911690612c4991613920565b612c539087612206565b909a90612c636080890189612305565b612c6e9d919d612356565b906040519e8f98899788967f6122b1730000000000000000000000000000000000000000000000000000000088526004880196612caa976126a7565b03928a165af19687156103c7578182978399612cd6575b50612ccd90978561140a565b97953880612a30565b9050612ccd9850612cf29197503d8084833e612bfc8183610a5d565b509890979190612cc1565b3d15612d28573d90612d0e82611d60565b91612d1c6040519384610a5d565b82523d6000602084013e565b606090565b8215612e2d5773ffffffffffffffffffffffffffffffffffffffff1680612dc65750600080809381935af1612d60612cfd565b5015612d6857565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f6574682073656e64206661696c656400000000000000000000000000000000006044820152fd5b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000602082015273ffffffffffffffffffffffffffffffffffffffff92909216602483015260448083019390935291815261016591612e28606483610a5d565b613800565b505050565b9190612e3c611dc5565b926001602085015260408401526060830152565b60a49060006020949560409473ffffffffffffffffffffffffffffffffffffffff809681930135612e8081610137565b604051998a9889977f769f8e5d000000000000000000000000000000000000000000000000000000008952166004880152602487015216604485015282606485015260016084850152165af19081156103c757600091611c3f575090565b73ffffffffffffffffffffffffffffffffffffffff1680612efe57504790565b6020602491604051928380927f70a082310000000000000000000000000000000000000000000000000000000082523060048301525afa9081156103c757600091611c3f575090565b73ffffffffffffffffffffffffffffffffffffffff9190821680612fb9575016803b15610155576000906004604051809481937fd0e30db00000000000000000000000000000000000000000000000000000000083525af180156103c757612fac5750565b806112f061016592610a0b565b915050803b15610155576040517f2e1a7d4d00000000000000000000000000000000000000000000000000000000815260048101929092526000908290602490829084905af180156103c757612fac5750565b604051906080820182811067ffffffffffffffff821117610a1f5760405260006060838281528260208201528260408201520152565b92919261304d61300c565b9360a0820161305d828251111590565b613116576130879161306f915161140a565b9261307a8484613b6c565b8652602083015190613bf4565b602085019080825282518015801561310e575b6130d3575050816130c08460c0936130cc969551906101008501519051908a5192613c77565b60408701520151613d1d565b6060830152565b6040517fb1c4aefb00000000000000000000000000000000000000000000000000000000815260048101919091526024810191909152604490fd5b50811561309a565b60046040517fb2094b59000000000000000000000000000000000000000000000000000000008152fd5b908082111561314d575090565b905090565b90670de0b6b3a7640000600083820393128184128116918413901516176113d857565b818103929160001380158285131691841216176113d857565b919091600083820193841291129080158216911516176113d857565b818102929181159184041417156113d857565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b9061321a6132206132066060850151604086015190613175565b670de0b6b3a7640000928391865190611a0c565b05613dfd565b9281840190828212600086129080158216911516176113d857613257602061324e61325d94613264986141da565b9201518561318e565b90611a0c565b0590613175565b6103e7908181029181830414901517156113d8576103e8900490565b908082101561314d575090565b805160208201519182821180156132f3575b6132a857505050565b60806104059101516040519384937fb301af04000000000000000000000000000000000000000000000000000000008552600485016040919493926060820195825260208201520152565b50670de0b6b3a764000060808201511161329f565b901580613363575b61335c57602081519101518082111561334d5760046040517ffa711db2000000000000000000000000000000000000000000000000000000008152fd5b81018091116113d85760011c90565b6040015190565b5060408101511515613310565b7f800000000000000000000000000000000000000000000000000000000000000081146113d85760000390565b91611ce29493916133ad936141e3565b9291939093613370565b90918282111592836133ca575b50505090565b90919250670de0b6b3a76400009182038281116113d8576133ea916131aa565b0411153880806133c4565b939192613406909591958686613042565b92604083015115613499575b60005b6060840151811015611cff5761342b8185613308565b61344c61343a828a898b613674565b509190613447848c614722565b61140a565b8481116134815761346390856080890151916133b7565b613474575084526001905b01613415565b9750945050509250509190565b50509061348f6001926113dd565b602086015261346e565b6134b88351670de0b6b3a76400006134b189856131aa565b0490613140565b8352602083016134cd8151611d4a87896134fb565b90526134d88361328d565b613412565b91906134e7611dc5565b926000602085015260408401526060830152565b600080926020906020810180517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81019081116113d8575b8087036135435750505050505090565b8087018088116113d85760018082018092116113d8571c908651613568838551613175565b613572828561318e565b918882138061366b575b1561360d57916135ea6135cc6135c76135f0946135c26135bc6135ac8f996135a6908e519061318e565b8c611a0c565b6135b68489611a0c565b906141da565b956119ef565b613d77565b61477b565b6135e56135d98a51613d5d565b9160408b015194613175565b613d81565b90613175565b12156136055750613600906113dd565b613533565b965095613533565b606488604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152601260248201527f696e76616c6964207074546f4d61726b657400000000000000000000000000006044820152fd5b5088831361357c565b919061368261368894613370565b926141e3565b9192909190565b340361369757565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f657468206d69736d6174636800000000000000000000000000000000000000006044820152fd5b90919073ffffffffffffffffffffffffffffffffffffffff168061371e57509050340361369757565b8161372857505050565b610165923091612289565b608490604060209495013561374781610137565b73ffffffffffffffffffffffffffffffffffffffff80948183169788156000146137e05761378981945b61377a81610137565b6137848482613920565b610137565b60405198899788967f20e8c5650000000000000000000000000000000000000000000000000000000088521660048701526024860152604485015260016064850152165af19081156103c757600091611c3f575090565b613789600094613771565b908160209103126101555751610ad181611789565b60405161386b9173ffffffffffffffffffffffffffffffffffffffff1661382682610a41565b6000806020958685527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656487860152868151910182855af1613865612cfd565b91614c08565b805190828215928315613908575b505050156138845750565b608490604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b61391893508201810191016137eb565b388281613879565b919073ffffffffffffffffffffffffffffffffffffffff92838116938415613b0b576040519485917fdd62ed3e0000000000000000000000000000000000000000000000000000000083523060048401528416602483015281604460209788935afa80156103c7576b7fffffffffffffffffffffff91600091613aee575b50106139ab575b50509050565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000085820190815273ffffffffffffffffffffffffffffffffffffffff8416602483015260006044830181905291829190613a3381606481015b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282610a5d565b519082855af1613a41612cfd565b81613abe575b5015613a6057613a58929350614353565b8038806139a5565b606484604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152600c60248201527f5361666520417070726f766500000000000000000000000000000000000000006044820152fd5b80518015925086908315613ad6575b50505038613a47565b613ae693508201810191016137eb565b388581613acd565b613b059150863d8811610dab57610d9c8183610a5d565b3861399e565b5050509050565b8115613b67577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82147f80000000000000000000000000000000000000000000000000000000000000008214166113d8570590565b6131bd565b60800151906301e13380918281029281840514901517156113d8577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557613bb791613b12565b906000821315613bc357565b602482604051907f1ca418760000000000000000000000000000000000000000000000000000000082526004820152fd5b613c3b670de0b6b3a76400009160008412600014613c6c57613c367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9461447d565b6131aa565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557610ad191611a0c565b613c3660019461447d565b9193613c88906301e13380926131aa565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557613cb990613dfd565b92670de0b6b3a76400008412613cec5791613ce7613ce2836135b6610ad197966135ea9661318e565b614492565b6141da565b602484604051907fca78c8a40000000000000000000000000000000000000000000000000000000082526004820152fd5b6301e1338091613d2c916131aa565b047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557610ad190613dfd565b8015613b67576ec097ce7bc90715b34b9f10000000000590565b8115613b67570590565b670de0b6b3a764000091613d9491611a0c565b0590565b15613d9f57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f496e76616c6964206578706f6e656e74000000000000000000000000000000006044820152fd5b7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc0000811215806141c7575b613e3090613d98565b600081126141b2576064906806f05b59d3b2000000811261414f577ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e0000000168056bc75e2d6310000082770195e54c5dd42177f53a27172fa9ec630262827000000000925b02819068ad78ebc5ac62000000811215614116575b806856bc75e2d631000000849212156140dc575b682b5e3af16b188000008112156140a4575b6815af1d78b58c40000081121561406c575b680ad78ebc5ac6200000811215614035575b81811215613ffe575b6802b5e3af16b1880000811215613fc7575b68015af1d78b58c40000811215613f90575b60028282800205056003838383020505600484848302050560058585830205056006868683020505600787878302050590600888888402050592600989898602050594600a8a8a8802050596600b8b8b8a02050598600c8c8c8c0205059a0101010101010101010101010205020590565b6806f5f17757889379377ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000083920193020591613f1f565b6808f00f760a4b2db55d7ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000083920193020591613f0d565b680ebc5fb417461211107ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000083920193020591613efb565b68280e60114edb805d037ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000083920193020591613ef2565b690127fa27722cc06cc5e27fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c0000083920193020591613ee0565b693f1fce3da636ea5cf8507fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e780000083920193020591613ece565b6b02df0ab5a80a22c61ab5a7007fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf00000083920193020591613ebc565b6e01855144814a7ff805980ff008400091507fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e00000001613ea8565b6803782dace9d9000000811261419f577ffffffffffffffffffffffffffffffffffffffffffffffffc87d25316270000000168056bc75e2d63100000826b1425982cf597cd205cef738092613e93565b68056bc75e2d6310000082600192613e93565b6141be90600003613dfd565b610ad190613d5d565b5068070c1cc73b00c80000811315613e27565b613d77906119ef565b90939192614200818351602088015188519060408a0151926144f1565b6000606061421461036b846135c2876119ef565b9701519213156142e357816135c261422b926119ef565b670de0b6b3a764000081126142b057509361429b614281610ad19361427b61427461426e61426361425d60e09c613152565b88613d81565b9a8b945b0151611a4b565b83611a0c565b6064900590565b93613175565b60008112156142a15761429490866146aa565b958561461b565b9361461b565b6142ab908661461b565b614294565b6040517fca78c8a40000000000000000000000000000000000000000000000000000000081526004810191909152602490fd5b509361429b614281610ad19361427b61427461426e61431861036b8c61431361430d60e09f613152565b8b611a0c565b613b12565b9a8b94614267565b614329916131aa565b670de0b6b3a764000090818101908181116113d857670de0b6b3a763ffff019081116113d8570490565b6040517f095ea7b3000000000000000000000000000000000000000000000000000000006020820190815273ffffffffffffffffffffffffffffffffffffffff90931660248201527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff604482015260009283929183906143d68160648101613a07565b51925af16143e2612cfd565b8161444e575b50156143f057565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f5361666520417070726f766500000000000000000000000000000000000000006044820152fd5b8051801592508215614463575b5050386143e8565b61447692506020809183010191016137eb565b388061445b565b60008113156144895790565b610ad190613370565b670de0b6b3a7640000908181146144c757808203916000821280158285131691841216176113d857610ad1916135c7916141da565b60046040517fa9c8b14d000000000000000000000000000000000000000000000000000000008152fd5b909194938082126145bd576145139261450d6135b69284613175565b9261318e565b92670d529ae9e8600000841361457d5761453490613ce76145399495614492565b61318e565b90670de0b6b3a7640000821261454b57565b6040517fca78c8a400000000000000000000000000000000000000000000000000000000815260048101839052602490fd5b6040517ffc68d09e00000000000000000000000000000000000000000000000000000000815260048101859052670d529ae9e86000006024820152604490fd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600860248201527f6e656761746976650000000000000000000000000000000000000000000000006044820152fd5b600082121561469f5761464e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9261447d565b670de0b6b3a7640000908181029181830414901517156113d8578115613b6757047f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557610ad191611a0c565b61464e60019261447d565b6146e7906000831215614717576146e17fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9361447d565b90614722565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161015557610ad191611a0c565b6146e160019361447d565b90670de0b6b3a7640000908181029181830414901517156113d8578181018091116113d8577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81019081116113d8578115613b67570490565b600081131561485e5780670c7d713b49da0000128061484d575b1561484457670de0b6b3a7640000906ec097ce7bc90715b34b9f1000000000906147e8908302828101907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f000000000018302613d77565b9080828002059181838202058284820205838582020591848684020593858786020595808888020597880205600f900596600d900595600b900594600990059360079005926005900591600390050101010101010160011b0590565b610ad1906148bc565b50670f43fc2c04ee00008112614795565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6f7574206f6620626f756e6473000000000000000000000000000000000000006044820152fd5b670de0b6b3a76400008112614bf15760649060007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c0000000000000821215614bc6575b73011798004d755d3c8bc8e03204cf44619e000000821215614ba5575b820290808302906e01855144814a7ff805980ff00840009081831215614b82575b50506b02df0ab5a80a22c61ab5a70080821215614b62575b50693f1fce3da636ea5cf85080821215614b42575b50690127fa27722cc06cc5e280821215614b22575b5068280e60114edb805d0380821215614b02575b50680ebc5fb4174612111080821215614aeb575b506808f00f760a4b2db55d80821215614acb575b506806f5f177578893793780821215614aab575b506806248f33704b28660380821215614a8c575b506805c548670b9510e7ac80821215614a6d575b50614a2c68056bc75e2d6310000091827ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf00000818301920102613d77565b9080828002059181838202058284820205916003600560076009600b888a89020598808b8b02059a8b0205059805960594059205010101010160011b010590565b68056bc75e2d631000006756bc75e2d6310000920205910190386149f0565b68056bc75e2d6310000067ad78ebc5ac620000920205910190386149dc565b68056bc75e2d6310000068015af1d78b58c40000920205910190386149c8565b68056bc75e2d631000006802b5e3af16b1880000920205910190386149b4565b68056bc75e2d6310000080920205910190386149a0565b68056bc75e2d63100000680ad78ebc5ac62000009202059101903861498c565b68056bc75e2d631000006815af1d78b58c40000092020591019038614978565b68056bc75e2d63100000682b5e3af16b1880000092020591019038614963565b68056bc75e2d631000006856bc75e2d6310000009202059101903861494e565b68ad78ebc5ac62000000925069021e19e0c9bab240000002059101903880614936565b906b1425982cf597cd205cef73806803782dace9d900000091059101614915565b50770195e54c5dd42177f53a27172fa9ec63026282700000000090056806f05b59d3b20000006148f8565b614bfd614c0291613d5d565b6148bc565b60000390565b91929015614c835750815115614c1c575090565b3b15614c255790565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b825190915015614c965750805190602001fd5b610405906040519182917f08c379a0000000000000000000000000000000000000000000000000000000008352602060048401526024830190610f7c56fea264697066735822122000bf99e240ef88f53cf4147b7a48747591c1bd636a2ac3dac4cdafa5ec92def164736f6c63430008170033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 26 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
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.