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 | |||
---|---|---|---|---|---|---|
16675144 | 614 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Contract Name:
ActionAddRemoveLiq
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 1000000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.17; import "./base/ActionBaseMintRedeem.sol"; import "../interfaces/IPActionAddRemoveLiq.sol"; import "../interfaces/IPMarket.sol"; import "../core/libraries/Errors.sol"; /** * @dev If market is expired, all actions will revert, except for the following: * - removeLiquidityDualSyAndPt() * - removeLiquidityDualTokenAndPt() * - removeLiquiditySingleSy() * - removeLiquiditySingleToken() * This is because swapping and adding liquidity are not allowed on an expired market. */ contract ActionAddRemoveLiq is IPActionAddRemoveLiq, ActionBaseMintRedeem { using Math for uint256; using Math for int256; using MarketMathCore for MarketState; using MarketApproxPtInLib for MarketState; using MarketApproxPtOutLib for MarketState; using PYIndexLib for IPYieldToken; using PYIndexLib for PYIndex; using BulkSellerMathCore for BulkSellerState; /** * @notice Adds liquidity to the SY/PT market, granting LP tokens in return * @dev Will mint as much LP as possible given no more than `netSyDesired` and `netPtDesired`, * while not changing the market's price * @dev Only the necessary SY/PT amount will be transferred * @dev Reverts if market is expired */ function addLiquidityDualSyAndPt( address receiver, address market, uint256 netSyDesired, uint256 netPtDesired, uint256 minLpOut ) external returns ( uint256 netLpOut, uint256 netSyUsed, uint256 netPtUsed ) { (IStandardizedYield SY, IPPrincipalToken PT, ) = IPMarket(market).readTokens(); // calculate the amount of SY and PT to be used MarketState memory state = IPMarket(market).readState(address(this)); (, netLpOut, netSyUsed, netPtUsed) = state.addLiquidity( netSyDesired, netPtDesired, block.timestamp ); // early-check if (netLpOut < minLpOut) revert Errors.RouterInsufficientLpOut(netLpOut, minLpOut); // execute the addLiquidity _transferFrom(IERC20(SY), msg.sender, market, netSyUsed); _transferFrom(IERC20(PT), msg.sender, market, netPtUsed); (netLpOut, , ) = IPMarket(market).mint(receiver, netSyUsed, netPtUsed); // fail-safe if (netLpOut < minLpOut) assert(false); emit AddLiquidityDualSyAndPt(msg.sender, market, receiver, netSyUsed, netPtUsed, netLpOut); } /** * @notice Adds liquidity to SY/PT market using PT + any token. * @dev Input token is first swapped to SY-mintable token using Kyber, then SY is minted from * such. Finally the SY/PT pair is added to the market * @param input data for input token, see {`./kyberswap/KyberSwapHelper.sol`} * @param netPtDesired maximum PT to be used * @dev Only the necessary PT amount will be transferred * @dev All SY minted must be used, otherwise the call will revert. Therefore it is recommended * that `netPtDesired` is slightly higher than actual expected. * @dev Reverts if market is expired */ function addLiquidityDualTokenAndPt( address receiver, address market, TokenInput calldata input, uint256 netPtDesired, uint256 minLpOut ) external payable returns ( uint256 netLpOut, uint256 netTokenUsed, uint256 netPtUsed ) { (IStandardizedYield SY, IPPrincipalToken PT, ) = IPMarket(market).readTokens(); uint256 netSyDesired = _mintSyFromToken(market, address(SY), 1, input); uint256 netSyUsed; { // calc the amount of SY and PT to be used MarketState memory state = IPMarket(market).readState(address(this)); (, netLpOut, netSyUsed, netPtUsed) = state.addLiquidity( netSyDesired, netPtDesired, block.timestamp ); if (netSyDesired != netSyUsed) revert Errors.RouterNotAllSyUsed(netSyDesired, netSyUsed); if (netLpOut < minLpOut) revert Errors.RouterInsufficientLpOut(netLpOut, minLpOut); netTokenUsed = input.netTokenIn; } // SY has been minted and transferred to the market _transferFrom(IERC20(PT), msg.sender, market, netPtUsed); (netLpOut, , ) = IPMarket(market).mint(receiver, netSyUsed, netPtUsed); // fail-safe if (netLpOut < minLpOut) assert(false); emit AddLiquidityDualTokenAndPt( msg.sender, market, input.tokenIn, receiver, netTokenUsed, netPtUsed, netLpOut ); } /** * @notice Swaps partial PT to SY, then use them to add liquidity to SY/PT pair * @param netPtIn amount of PT to be transferred in from caller * @param guessPtSwapToSy approximate info for the swap * @return netLpOut actual LP output, will not be lower than `minLpOut` * @return netSyFee amount of SY fee incurred from the swap * @dev Reverts if market is expired */ function addLiquiditySinglePt( address receiver, address market, uint256 netPtIn, uint256 minLpOut, ApproxParams calldata guessPtSwapToSy ) external returns (uint256 netLpOut, uint256 netSyFee) { (, IPPrincipalToken PT, IPYieldToken YT) = IPMarket(market).readTokens(); // calculate the amount of PT to swap MarketState memory state = IPMarket(market).readState(address(this)); (uint256 netPtSwap, , ) = state.approxSwapPtToAddLiquidity( YT.newIndex(), netPtIn, block.timestamp, guessPtSwapToSy ); // execute the swap _transferFrom(IERC20(PT), msg.sender, market, netPtIn); uint256 netSyReceived; (netSyReceived, netSyFee) = IPMarket(market).swapExactPtForSy( market, netPtSwap, EMPTY_BYTES ); // execute the addLiquidity (netLpOut, , ) = IPMarket(market).mint(receiver, netSyReceived, netPtIn - netPtSwap); if (netLpOut < minLpOut) revert Errors.RouterInsufficientLpOut(netLpOut, minLpOut); emit AddLiquiditySinglePt(msg.sender, market, receiver, netPtIn, netLpOut); } /** * @notice Swaps partial SY to PT, then use them to add liquidity to SY/PT pair * @param netSyIn amount of SY to be transferred in from caller * @param guessPtReceivedFromSy approx. output PT from the swap * @return netLpOut actual LP output, will not be lower than `minLpOut` * @return netSyFee amount of SY fee incurred from the swap * @dev Reverts if market is expired */ function addLiquiditySingleSy( address receiver, address market, uint256 netSyIn, uint256 minLpOut, ApproxParams calldata guessPtReceivedFromSy ) external returns (uint256 netLpOut, uint256 netSyFee) { (IStandardizedYield SY, , IPYieldToken YT) = IPMarket(market).readTokens(); // transfer SY to market _transferFrom(IERC20(SY), msg.sender, market, netSyIn); // mint LP (netLpOut, netSyFee) = _addLiquiditySingleSy( receiver, market, YT, netSyIn, minLpOut, guessPtReceivedFromSy ); emit AddLiquiditySingleSy(msg.sender, market, receiver, netSyIn, netLpOut); } /** * @notice Adds liquidity using a single token input. The input token is first swapped through * Kyberswap to a SY-mintable token, the rest is the same as `addLiquiditySingleSy()` * @param guessPtReceivedFromSy approximate PT output for the SY-to-PT swap * @param input data for input token, see {`./kyberswap/KyberSwapHelper.sol`} * @return netLpOut actual LP output, will not be lower than `minLpOut` * @return netSyFee amount of SY fee incurred from the swap * @dev Reverts if market is expired */ function addLiquiditySingleToken( address receiver, address market, uint256 minLpOut, ApproxParams calldata guessPtReceivedFromSy, TokenInput calldata input ) external payable returns (uint256 netLpOut, uint256 netSyFee) { (IStandardizedYield SY, , IPYieldToken YT) = IPMarket(market).readTokens(); // mint SY directly to the market uint256 netSyUsed = _mintSyFromToken(market, address(SY), 1, input); // mint LP (netLpOut, netSyFee) = _addLiquiditySingleSy( receiver, market, YT, netSyUsed, minLpOut, guessPtReceivedFromSy ); emit AddLiquiditySingleToken( msg.sender, market, input.tokenIn, receiver, input.netTokenIn, netLpOut ); } /** * @notice Mints partial SY to PT+YT, returns YT to user, then uses PT+SY to add liquidity * @param netSyIn amount of SY to be transferred in from caller * @return netLpOut actual LP output, will not be lower than `minLpOut` * @return netYtOut actual YT output, will not be lower than `minYtOut` * @dev Reverts if market is expired */ function addLiquiditySingleSyKeepYt( address receiver, address market, uint256 netSyIn, uint256 minLpOut, uint256 minYtOut ) external returns (uint256 netLpOut, uint256 netYtOut) { (IStandardizedYield SY, , IPYieldToken YT) = IPMarket(market).readTokens(); _transferIn(address(SY), msg.sender, netSyIn); (netLpOut, netYtOut) = _addLiquiditySingleSyKeepYt( receiver, market, SY, YT, netSyIn, minLpOut, minYtOut ); emit AddLiquiditySingleSyKeepYt(msg.sender, market, receiver, netSyIn, netLpOut, netYtOut); } /** * @notice Adds liquidity and returns leftover YT using a single token input. The input token * is first swapped through Kyberswap to a SY-mintable token, the rest is the same as * `addLiquiditySingleSyKeepYt()` * @param input data for input token, see {`./kyberswap/KyberSwapHelper.sol`} * @return netLpOut actual LP output, will not be lower than `minLpOut` * @return netYtOut actual YT output, will not be lower than `minYtOut` * @dev Reverts if market is expired */ function addLiquiditySingleTokenKeepYt( address receiver, address market, uint256 minLpOut, uint256 minYtOut, TokenInput calldata input ) external returns (uint256 netLpOut, uint256 netYtOut) { (IStandardizedYield SY, , IPYieldToken YT) = IPMarket(market).readTokens(); uint256 netSyUsed = _mintSyFromToken(address(this), address(SY), 1, input); (netLpOut, netYtOut) = _addLiquiditySingleSyKeepYt( receiver, market, SY, YT, netSyUsed, minLpOut, minYtOut ); emit AddLiquiditySingleTokenKeepYt( msg.sender, market, input.tokenIn, receiver, input.netTokenIn, netLpOut, netYtOut ); } /** * @notice Burns LP token to remove SY/PT liquidity * @param netLpToRemove amount of LP to be burned from caller * @dev Will work even if market is expired */ function removeLiquidityDualSyAndPt( address receiver, address market, uint256 netLpToRemove, uint256 minSyOut, uint256 minPtOut ) external returns (uint256 netSyOut, uint256 netPtOut) { _transferFrom(IERC20(market), msg.sender, market, netLpToRemove); (netSyOut, netPtOut) = IPMarket(market).burn(receiver, receiver, netLpToRemove); if (netSyOut < minSyOut) revert Errors.RouterInsufficientSyOut(netSyOut, minSyOut); if (netPtOut < minPtOut) revert Errors.RouterInsufficientPtOut(netPtOut, minPtOut); emit RemoveLiquidityDualSyAndPt( msg.sender, market, receiver, netLpToRemove, netPtOut, netSyOut ); } /** * @notice Burns LP token to remove SY/PT liquidity, then redeems SY, finally (if needed) * swaps SY redeemings through Kyberswap to desired output token. * @param netLpToRemove amount of LP to be burned from caller * @param output data for desired output token, see {`./kyberswap/KyberSwapHelper.sol`} * @dev Will work even if market is expired */ function removeLiquidityDualTokenAndPt( address receiver, address market, uint256 netLpToRemove, TokenOutput calldata output, uint256 minPtOut ) external returns (uint256 netTokenOut, uint256 netPtOut) { (IStandardizedYield SY, , ) = IPMarket(market).readTokens(); // burn LP, SY sent to either SY or bulk, PT sent to receiver _transferFrom(IERC20(market), msg.sender, market, netLpToRemove); uint256 netSyOut; (netSyOut, netPtOut) = IPMarket(market).burn( _syOrBulk(address(SY), output), receiver, netLpToRemove ); if (netPtOut < minPtOut) revert Errors.RouterInsufficientPtOut(netPtOut, minPtOut); // redeem SY to token netTokenOut = _redeemSyToToken(receiver, address(SY), netSyOut, output, false); emit RemoveLiquidityDualTokenAndPt( msg.sender, market, output.tokenOut, receiver, netLpToRemove, netPtOut, netTokenOut ); } /** * @notice Removes SY/PT liquidity, then swaps all resulting SY to return only PT * @param netLpToRemove amount of LP to be burned from caller * @param guessPtReceivedFromSy approximate info for the swap * @return netPtOut total PT output, will not be lower than `minPtOut` * @return netSyFee amount of SY fee incurred from the swap * @dev Reverts if market is expired */ function removeLiquiditySinglePt( address receiver, address market, uint256 netLpToRemove, uint256 minPtOut, ApproxParams calldata guessPtReceivedFromSy ) external returns (uint256 netPtOut, uint256 netSyFee) { (, , IPYieldToken YT) = IPMarket(market).readTokens(); // calculate the total amount of PT received from burning & selling SY MarketState memory state = IPMarket(market).readState(address(this)); (uint256 syFromBurn, uint256 ptFromBurn) = state.removeLiquidity(netLpToRemove); (uint256 ptFromSwap, ) = state.approxSwapExactSyForPt( YT.newIndex(), syFromBurn, block.timestamp, guessPtReceivedFromSy ); if (ptFromBurn + ptFromSwap < minPtOut) revert Errors.RouterInsufficientPtOut(ptFromBurn + ptFromSwap, minPtOut); // execute the burn & the swap _transferFrom(IERC20(market), msg.sender, market, netLpToRemove); (, ptFromBurn) = IPMarket(market).burn(market, receiver, netLpToRemove); (, netSyFee) = IPMarket(market).swapSyForExactPt(receiver, ptFromSwap, EMPTY_BYTES); netPtOut = ptFromBurn + ptFromSwap; // fail-safe if (netPtOut < minPtOut) assert(false); emit RemoveLiquiditySinglePt(msg.sender, market, receiver, netLpToRemove, netPtOut); } /** * @notice Removes SY/PT liquidity, then converts all resulting PT to return only SY * @dev Conversion is done with market swap if not expired, or with PT redeeming if expired * @param netLpToRemove amount of LP to be burned from caller * @return netSyOut total SY output, will not be lower than `minSyOut` * @return netSyFee amount of SY fee incurred from the swap * @dev Will work even if market is expired */ function removeLiquiditySingleSy( address receiver, address market, uint256 netLpToRemove, uint256 minSyOut ) external returns (uint256 netSyOut, uint256 netSyFee) { // transfer LP to market _transferFrom(IERC20(market), msg.sender, market, netLpToRemove); // burn LP, SY sent to receiver (netSyOut, netSyFee) = _removeLiquiditySingleSy(receiver, market, netLpToRemove, minSyOut); emit RemoveLiquiditySingleSy(msg.sender, market, receiver, netLpToRemove, netSyOut); } /** * @notice Removes SY/PT liquidity, then converts all to desired output token. * @dev inner workings of this function: - Removes SY/PT liquidity to only SY (see `removeLiquiditySingleSy()`) - Burns SY to redeem SY-mintable tokens - (If needed) swaps resulting tokens to desired output token using Kyberswap * @param netLpToRemove amount of LP to be burned from caller * @param output data for desired output token, see {`./kyberswap/KyberSwapHelper.sol`} * @return netTokenOut total token output, will not be lower than `output.minTokenOut` * @return netSyFee amount of SY fee incurred from the swap * @dev Will work even if market is expired */ function removeLiquiditySingleToken( address receiver, address market, uint256 netLpToRemove, TokenOutput calldata output ) external returns (uint256 netTokenOut, uint256 netSyFee) { (IStandardizedYield SY, , ) = IPMarket(market).readTokens(); // transfer LP to market, burn LP, SY sent to either SY or bulk _transferFrom(IERC20(market), msg.sender, market, netLpToRemove); uint256 netSyReceived; (netSyReceived, netSyFee) = _removeLiquiditySingleSy( _syOrBulk(address(SY), output), market, netLpToRemove, 1 ); // redeem SY to token netTokenOut = _redeemSyToToken(receiver, address(SY), netSyReceived, output, false); emit RemoveLiquiditySingleToken( msg.sender, market, output.tokenOut, receiver, netLpToRemove, netTokenOut ); } /// @dev swaps SY to PT, then adds liquidity function _addLiquiditySingleSy( address receiver, address market, IPYieldToken YT, uint256 netSyIn, uint256 minLpOut, ApproxParams calldata guessPtReceivedFromSy ) internal returns (uint256 netLpOut, uint256 netSyFee) { MarketState memory state = IPMarket(market).readState(address(this)); // calculate the PT amount needed to add liquidity (uint256 netPtFromSwap, , ) = state.approxSwapSyToAddLiquidity( YT.newIndex(), netSyIn, block.timestamp, guessPtReceivedFromSy ); // execute the swap & the addLiquidity uint256 netSySwapped; (netSySwapped, netSyFee) = IPMarket(market).swapSyForExactPt( market, netPtFromSwap, EMPTY_BYTES ); (netLpOut, , ) = IPMarket(market).mint(receiver, netSyIn - netSySwapped, netPtFromSwap); if (netLpOut < minLpOut) revert Errors.RouterInsufficientLpOut(netLpOut, minLpOut); } /** * @dev algorithm: - Split SY into a SY and b SY (with a + b = netSyIn) - Mint PY with a SY ---> gives (a * pyIndex / ONE) PT + YT - Mint LP with (a * pyIndex / ONE) PT and b SY -> We want (a * pyIndex / ONE) / totalPt = b / totalSy -> a * (1 + pyIndex * totalSy / ONE / totalPt) = netSyIn -> a = (netSyIn * totalPt) / (totalPt + (pyIndex * totalSy / ONE)) -> a = (netSyIn * totalPt) / (totalPt + totalAsset) */ function _addLiquiditySingleSyKeepYt( address receiver, address market, IStandardizedYield SY, IPYieldToken YT, uint256 netSyIn, uint256 minLpOut, uint256 minYtOut ) internal returns (uint256 netLpOut, uint256 netYtOut) { MarketState memory state = IPMarket(market).readState(address(this)); PYIndex pyIndex = YT.newIndex(); uint256 netSyToPt = (netSyIn * state.totalPt.Uint()) / (state.totalPt.Uint() + pyIndex.syToAsset(state.totalSy.Uint())); // transfer SY to mint PY _transferOut(address(SY), address(YT), netSyToPt); // the rest of SY goes to market _transferOut(address(SY), market, netSyIn - netSyToPt); // PT goes to market, YT goes to receiver netYtOut = YT.mintPY(market, receiver); (netLpOut, , ) = IPMarket(market).mint(receiver, netSyIn - netSyToPt, netYtOut); if (netLpOut < minLpOut) revert Errors.RouterInsufficientLpOut(netLpOut, minLpOut); if (netYtOut < minYtOut) revert Errors.RouterInsufficientYtOut(netYtOut, minYtOut); } /// @dev removes SY/PT liquidity, then converts PT to SY function _removeLiquiditySingleSy( address receiver, address market, uint256 netLpToRemove, uint256 minSyOut ) internal returns (uint256 netSyOut, uint256 netSyFee) { if (IPMarket(market).isExpired()) { netSyOut = __removeLpToSyAfterExpiry(receiver, market, netLpToRemove); } else { (netSyOut, netSyFee) = __removeLpToSyBeforeExpiry(receiver, market, netLpToRemove); } if (netSyOut < minSyOut) revert Errors.RouterInsufficientSyOut(netSyOut, minSyOut); } /// @dev converts PT to SY post-expiry function __removeLpToSyAfterExpiry( address receiver, address market, uint256 netLpToRemove ) internal returns (uint256 netSyOut) { (, , IPYieldToken YT) = IPMarket(market).readTokens(); (uint256 syFromBurn, ) = IPMarket(market).burn(receiver, address(YT), netLpToRemove); netSyOut = syFromBurn + YT.redeemPY(receiver); } /// @dev swaps PT to SY pre-expiry function __removeLpToSyBeforeExpiry( address receiver, address market, uint256 netLpToRemove ) internal returns (uint256 netSyOut, uint256 netSyFee) { (uint256 syFromBurn, uint256 ptFromBurn) = IPMarket(market).burn( receiver, market, netLpToRemove ); uint256 syFromSwap; (syFromSwap, netSyFee) = IPMarket(market).swapExactPtForSy( receiver, ptFromBurn, EMPTY_BYTES ); netSyOut = syFromBurn + syFromSwap; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-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 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.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-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; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } 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)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } 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"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } 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"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "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"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(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) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason 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 { // 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.17; import "../libraries/TokenHelper.sol"; import "../libraries/math/Math.sol"; import "../libraries/Errors.sol"; struct BulkSellerState { uint256 rateTokenToSy; uint256 rateSyToToken; uint256 totalToken; uint256 totalSy; uint256 feeRate; } library BulkSellerMathCore { using Math for uint256; function swapExactTokenForSy(BulkSellerState memory state, uint256 netTokenIn) internal pure returns (uint256 netSyOut) { netSyOut = calcSwapExactTokenForSy(state, netTokenIn); state.totalToken += netTokenIn; state.totalSy -= netSyOut; } function swapExactSyForToken(BulkSellerState memory state, uint256 netSyIn) internal pure returns (uint256 netTokenOut) { netTokenOut = calcSwapExactSyForToken(state, netSyIn); state.totalSy += netSyIn; state.totalToken -= netTokenOut; } function calcSwapExactTokenForSy(BulkSellerState memory state, uint256 netTokenIn) internal pure returns (uint256 netSyOut) { uint256 postFeeRate = state.rateTokenToSy.mulDown(Math.ONE - state.feeRate); assert(postFeeRate != 0); netSyOut = netTokenIn.mulDown(postFeeRate); if (netSyOut > state.totalSy) revert Errors.BulkInsufficientSyForTrade(state.totalSy, netSyOut); } function calcSwapExactSyForToken(BulkSellerState memory state, uint256 netSyIn) internal pure returns (uint256 netTokenOut) { uint256 postFeeRate = state.rateSyToToken.mulDown(Math.ONE - state.feeRate); assert(postFeeRate != 0); netTokenOut = netSyIn.mulDown(postFeeRate); if (netTokenOut > state.totalToken) revert Errors.BulkInsufficientTokenForTrade(state.totalToken, netTokenOut); } function getTokenProp(BulkSellerState memory state) internal pure returns (uint256) { uint256 totalToken = state.totalToken; uint256 totalTokenFromSy = state.totalSy.mulDown(state.rateSyToToken); return totalToken.divDown(totalToken + totalTokenFromSy); } function getReBalanceParams(BulkSellerState memory state, uint256 targetTokenProp) internal pure returns (uint256 netTokenToDeposit, uint256 netSyToRedeem) { uint256 currentTokenProp = getTokenProp(state); if (currentTokenProp > targetTokenProp) { netTokenToDeposit = state .totalToken .mulDown(currentTokenProp - targetTokenProp) .divDown(currentTokenProp); } else { uint256 currentSyProp = Math.ONE - currentTokenProp; netSyToRedeem = state.totalSy.mulDown(targetTokenProp - currentTokenProp).divDown( currentSyProp ); } } function reBalanceTokenToSy( BulkSellerState memory state, uint256 netTokenToDeposit, uint256 netSyFromToken, uint256 maxDiff ) internal pure { uint256 rate = netSyFromToken.divDown(netTokenToDeposit); if (!Math.isAApproxB(rate, state.rateTokenToSy, maxDiff)) revert Errors.BulkBadRateTokenToSy(rate, state.rateTokenToSy, maxDiff); state.totalToken -= netTokenToDeposit; state.totalSy += netSyFromToken; } function reBalanceSyToToken( BulkSellerState memory state, uint256 netSyToRedeem, uint256 netTokenFromSy, uint256 maxDiff ) internal pure { uint256 rate = netTokenFromSy.divDown(netSyToRedeem); if (!Math.isAApproxB(rate, state.rateSyToToken, maxDiff)) revert Errors.BulkBadRateSyToToken(rate, state.rateSyToToken, maxDiff); state.totalToken += netTokenFromSy; state.totalSy -= netSyToRedeem; } function setRate( BulkSellerState memory state, uint256 rateSyToToken, uint256 rateTokenToSy, uint256 maxDiff ) internal pure { if ( state.rateTokenToSy != 0 && !Math.isAApproxB(rateTokenToSy, state.rateTokenToSy, maxDiff) ) { revert Errors.BulkBadRateTokenToSy(rateTokenToSy, state.rateTokenToSy, maxDiff); } if ( state.rateSyToToken != 0 && !Math.isAApproxB(rateSyToToken, state.rateSyToToken, maxDiff) ) { revert Errors.BulkBadRateSyToToken(rateSyToToken, state.rateSyToToken, maxDiff); } state.rateTokenToSy = rateTokenToSy; state.rateSyToToken = rateSyToToken; } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.17; /// Adapted from UniswapV3's Oracle 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 MarketFactoryReserveFeePercentTooHigh( uint8 reserveFeePercent, uint8 maxReserveFeePercent ); error MarketFactoryZeroTreasury(); error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor); // 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 RouterExceededLimitSyIn(uint256 actualSyIn, uint256 limitSyIn); error RouterExceededLimitPtIn(uint256 actualPtIn, uint256 limitPtIn); error RouterExceededLimitYtIn(uint256 actualYtIn, uint256 limitYtIn); 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(); // 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); // 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 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.17; /* 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.17; /* solhint-disable private-vars-leading-underscore, reason-string */ library Math { 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 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 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 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.17; 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.17; 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.17; import "../libraries/math/Math.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 Math for uint256; using Math 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 Math for uint256; using Math 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 = Math.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 < Math.IONE) revert Errors.MarketExchangeRateBelowOne(postFeeExchangeRate); fee = preFeeAssetToAccount.mulDown(Math.IONE - fee); } else { fee = ((preFeeAssetToAccount * (Math.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 < Math.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 < Math.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 < Math.IONE) revert Errors.MarketExchangeRateBelowOne(exchangeRate); } function _logProportion(int256 proportion) internal pure returns (int256 res) { if (proportion == Math.IONE) revert Errors.MarketProportionMustNotEqualOne(); int256 logitP = proportion.divDown(Math.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.17; import "../../interfaces/IPYieldToken.sol"; import "../../interfaces/IPPrincipalToken.sol"; import "./SYUtils.sol"; import "../libraries/math/Math.sol"; type PYIndex is uint256; library PYIndexLib { using Math for uint256; using Math 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.17; 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.17; import "../router/base/MarketApproxLib.sol"; import "../router/base/ActionBaseMintRedeem.sol"; interface IPActionAddRemoveLiq { event AddLiquidityDualSyAndPt( address indexed caller, address indexed market, address indexed receiver, uint256 netSyUsed, uint256 netPtUsed, uint256 netLpOut ); event AddLiquidityDualTokenAndPt( address indexed caller, address indexed market, address indexed tokenIn, address receiver, uint256 netTokenUsed, uint256 netPtUsed, uint256 netLpOut ); event AddLiquiditySinglePt( address indexed caller, address indexed market, address indexed receiver, uint256 netPtIn, uint256 netLpOut ); event AddLiquiditySingleSy( address indexed caller, address indexed market, address indexed receiver, uint256 netSyIn, uint256 netLpOut ); event AddLiquiditySingleToken( address indexed caller, address indexed market, address indexed token, address receiver, uint256 netTokenIn, uint256 netLpOut ); event AddLiquiditySingleSyKeepYt( address indexed caller, address indexed market, address indexed receiver, uint256 netSyIn, uint256 netLpOut, uint256 netYtOut ); event AddLiquiditySingleTokenKeepYt( address indexed caller, address indexed market, address indexed token, address receiver, uint256 netTokenIn, uint256 netLpOut, uint256 netYtOut ); event RemoveLiquidityDualSyAndPt( address indexed caller, address indexed market, address indexed receiver, uint256 netLpToRemove, uint256 netPtOut, uint256 netSyOut ); event RemoveLiquidityDualTokenAndPt( address indexed caller, address indexed market, address indexed tokenOut, address receiver, uint256 netLpToRemove, uint256 netPtOut, uint256 netTokenOut ); event RemoveLiquiditySinglePt( address indexed caller, address indexed market, address indexed receiver, uint256 netLpToRemove, uint256 netPtOut ); event RemoveLiquiditySingleSy( address indexed caller, address indexed market, address indexed receiver, uint256 netLpToRemove, uint256 netSyOut ); event RemoveLiquiditySingleToken( address indexed caller, address indexed market, address indexed token, address receiver, uint256 netLpToRemove, uint256 netTokenOut ); function addLiquidityDualSyAndPt( address receiver, address market, uint256 netSyDesired, uint256 netPtDesired, uint256 minLpOut ) external returns ( uint256 netLpOut, uint256 netSyUsed, uint256 netPtUsed ); function addLiquidityDualTokenAndPt( address receiver, address market, TokenInput calldata input, uint256 netPtDesired, uint256 minLpOut ) external payable returns ( uint256 netLpOut, uint256 netTokenUsed, uint256 netPtUsed ); function addLiquiditySinglePt( address receiver, address market, uint256 netPtIn, uint256 minLpOut, ApproxParams calldata guessPtSwapToSy ) external returns (uint256 netLpOut, uint256 netSyFee); function addLiquiditySingleSy( address receiver, address market, uint256 netSyIn, uint256 minLpOut, ApproxParams calldata guessPtReceivedFromSy ) external returns (uint256 netLpOut, uint256 netSyFee); function addLiquiditySingleToken( address receiver, address market, uint256 minLpOut, ApproxParams calldata guessPtReceivedFromSy, TokenInput calldata input ) external payable returns (uint256 netLpOut, uint256 netSyFee); function addLiquiditySingleSyKeepYt( address receiver, address market, uint256 netSyIn, uint256 minLpOut, uint256 minYtOut ) external returns (uint256 netLpOut, uint256 netYtOut); function addLiquiditySingleTokenKeepYt( address receiver, address market, uint256 minLpOut, uint256 minYtOut, TokenInput calldata input ) external returns (uint256 netLpOut, uint256 netYtOut); function removeLiquidityDualSyAndPt( address receiver, address market, uint256 netLpToRemove, uint256 minSyOut, uint256 minPtOut ) external returns (uint256 netSyOut, uint256 netPtOut); function removeLiquidityDualTokenAndPt( address receiver, address market, uint256 netLpToRemove, TokenOutput calldata output, uint256 minPtOut ) external returns (uint256 netTokenOut, uint256 netPtOut); function removeLiquiditySinglePt( address receiver, address market, uint256 netLpToRemove, uint256 minPtOut, ApproxParams calldata guessPtOut ) external returns (uint256 netPtOut, uint256 netSyFee); function removeLiquiditySingleSy( address receiver, address market, uint256 netLpToRemove, uint256 minSyOut ) external returns (uint256 netSyOut, uint256 netSyFee); function removeLiquiditySingleToken( address receiver, address market, uint256 netLpToRemove, TokenOutput calldata output ) external returns (uint256 netTokenOut, uint256 netSyFee); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.17; import "../core/BulkSeller/BulkSellerMathCore.sol"; interface IPBulkSeller { event SwapExactTokenForSy(address receiver, uint256 netTokenIn, uint256 netSyOut); event SwapExactSyForToken(address receiver, uint256 netSyIn, uint256 netTokenOut); event RateUpdated( uint256 newRateTokenToSy, uint256 newRateSyToToken, uint256 oldRateTokenToSy, uint256 oldRateSyToToken ); event ReBalanceTokenToSy( uint256 netTokenDeposit, uint256 netSyFromToken, uint256 newTokenProp, uint256 oldTokenProp ); event ReBalanceSyToToken( uint256 netSyRedeem, uint256 netTokenFromSy, uint256 newTokenProp, uint256 oldTokenProp ); event ReserveUpdated(uint256 totalToken, uint256 totalSy); event FeeRateUpdated(uint256 newFeeRate, uint256 oldFeeRate); function swapExactTokenForSy( address receiver, uint256 netTokenIn, uint256 minSyOut ) external payable returns (uint256 netSyOut); function swapExactSyForToken( address receiver, uint256 exactSyIn, uint256 minTokenOut, bool swapFromInternalBalance ) external returns (uint256 netTokenOut); function SY() external view returns (address); function token() external view returns (address); function readState() external view returns (BulkSellerState memory); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.17; interface IPGauge { function totalActiveSupply() external view returns (uint256); function activeBalance(address user) external view returns (uint256); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.17; interface IPInterestManagerYT { function userInterest(address user) external view returns (uint128 lastPYIndex, uint128 accruedInterest); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.17; 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); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.17; 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.17; 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 WithdrawFeeToTreasury(uint256[] amountRewardsOut, uint256 syOut); 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); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.17; 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.17; 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: * - (`baseTokenIn`) 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) * @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.17; 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.17; import "../../core/libraries/TokenHelper.sol"; import "../../interfaces/IStandardizedYield.sol"; import "../../interfaces/IPYieldToken.sol"; import "../../interfaces/IPBulkSeller.sol"; import "../../core/libraries/Errors.sol"; import "../swap-aggregator/IPSwapAggregator.sol"; struct TokenInput { // Token/Sy data address tokenIn; uint256 netTokenIn; address tokenMintSy; address bulk; // aggregator data address pendleSwap; SwapData swapData; } struct TokenOutput { // Token/Sy data address tokenOut; uint256 minTokenOut; address tokenRedeemSy; address bulk; // aggregator data address pendleSwap; SwapData swapData; } // solhint-disable no-empty-blocks abstract contract ActionBaseMintRedeem is TokenHelper { bytes internal constant EMPTY_BYTES = abi.encode(); 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 { 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); netTokenMintSy = _selfBalance(inp.tokenMintSy); } // outcome of all branches: satisfy pre-condition of __mintSy netSyOut = __mintSy(receiver, SY, netTokenMintSy, minSyOut, inp); } /// @dev pre-condition: having netTokenMintSy of tokens in this contract function __mintSy( address receiver, address SY, uint256 netTokenMintSy, uint256 minSyOut, TokenInput calldata inp ) private returns (uint256 netSyOut) { uint256 netNative = inp.tokenMintSy == NATIVE ? netTokenMintSy : 0; if (inp.bulk != address(0)) { netSyOut = IPBulkSeller(inp.bulk).swapExactTokenForSy{ value: netNative }( receiver, netTokenMintSy, minSyOut ); } else { 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); } // outcome of all branches: netTokenOut of tokens goes back to receiver 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, _syOrBulk(SY, out), netSyIn); } if (out.bulk != address(0)) { netTokenRedeemed = IPBulkSeller(out.bulk).swapExactSyForToken( receiver, netSyIn, 0, true ); } else { 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); } function _syOrBulk(address SY, TokenOutput calldata output) internal pure returns (address addr) { return output.bulk != address(0) ? output.bulk : SY; } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.17; import "../../core/libraries/math/Math.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 Math for uint256; using Math 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 = Math.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 (Math.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 = Math.max(approx.guessMin, index.syToAsset(exactSyIn)); approx.guessMax = Math.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 (Math.isASmallerApproxB(netSyToPull, 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 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 blockTime, ApproxParams memory approx ) internal pure returns ( uint256, /*netPtSwap*/ uint256, /*netSyFromSwap*/ uint256 /*netSyFee*/ ) { MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime); if (approx.guessOffchain == 0) { // no limit on min approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp)); approx.guessMax = Math.min(approx.guessMax, totalPtIn); validateApprox(approx); require(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(market, index, totalPtIn, comp, guess); if (Math.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, 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 / newTotalSy = netPtRemaining / newTotalPt // which is equivalent to // netSyOut * newTotalPt = netPtRemaining * newTotalSy syNumerator = netSyOut * newTotalPt; ptNumerator = (totalPtIn - guess) * newTotalSy; } struct Args7 { MarketState market; PYIndex index; uint256 exactPtIn; uint256 blockTime; } /** * @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 = Math.max(approx.guessMin, exactPtIn); approx.guessMax = Math.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 (Math.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 > Math.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 = Math.IONE.divDown(comp.rateScalar); return comp.rateAnchor - (part1 - part2).mulDown(part3); } } library MarketApproxPtOutLib { using MarketMathCore for MarketState; using PYIndexLib for PYIndex; using Math for uint256; using Math 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 = Math.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 (Math.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 = Math.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 (Math.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 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 _blockTime, ApproxParams memory _approx ) internal pure returns ( uint256, /*netPtFromSwap*/ uint256, /*netSySwap*/ uint256 /*netSyFee*/ ) { Args6 memory a = Args6(_market, _index, _totalSyIn, _blockTime, _approx); MarketPreCompute memory comp = a.market.getMarketPreCompute(a.index, a.blockTime); if (a.approx.guessOffchain == 0) { // no limit on min a.approx.guessMax = Math.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 / newTotalPt = netSyRemaining / netTotalSy // which is equivalent to // netPtFromSwap * netTotalSy = netSyRemaining * newTotalPt ptNumerator = guess * netTotalSy; syNumerator = (a.totalSyIn - netSyIn) * newTotalPt; } if (Math.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 = Math.max(approx.guessMin, exactYtIn); approx.guessMax = Math.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 (Math.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 + Math.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 > Math.ONE) revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps); } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.17; 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 }, "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":[],"name":"MarketZeroAmountsInput","type":"error"},{"inputs":[],"name":"MarketZeroAmountsOutput","type":"error"},{"inputs":[{"internalType":"int256","name":"totalPt","type":"int256"},{"internalType":"int256","name":"totalAsset","type":"int256"}],"name":"MarketZeroTotalPtOrTotalAsset","type":"error"},{"inputs":[{"internalType":"uint256","name":"actualLpOut","type":"uint256"},{"internalType":"uint256","name":"requiredLpOut","type":"uint256"}],"name":"RouterInsufficientLpOut","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"},{"inputs":[{"internalType":"uint256","name":"netSyDesired","type":"uint256"},{"internalType":"uint256","name":"netSyUsed","type":"uint256"}],"name":"RouterNotAllSyUsed","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":"uint256","name":"netSyUsed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netPtUsed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netLpOut","type":"uint256"}],"name":"AddLiquidityDualSyAndPt","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":"tokenIn","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"netTokenUsed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netPtUsed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netLpOut","type":"uint256"}],"name":"AddLiquidityDualTokenAndPt","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":"uint256","name":"netPtIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netLpOut","type":"uint256"}],"name":"AddLiquiditySinglePt","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":"uint256","name":"netSyIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netLpOut","type":"uint256"}],"name":"AddLiquiditySingleSy","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":"uint256","name":"netSyIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netLpOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netYtOut","type":"uint256"}],"name":"AddLiquiditySingleSyKeepYt","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":"uint256","name":"netTokenIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netLpOut","type":"uint256"}],"name":"AddLiquiditySingleToken","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":"uint256","name":"netTokenIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netLpOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netYtOut","type":"uint256"}],"name":"AddLiquiditySingleTokenKeepYt","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":"uint256","name":"netLpToRemove","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netPtOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netSyOut","type":"uint256"}],"name":"RemoveLiquidityDualSyAndPt","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":"tokenOut","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"netLpToRemove","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netPtOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netTokenOut","type":"uint256"}],"name":"RemoveLiquidityDualTokenAndPt","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":"uint256","name":"netLpToRemove","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netPtOut","type":"uint256"}],"name":"RemoveLiquiditySinglePt","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":"uint256","name":"netLpToRemove","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netSyOut","type":"uint256"}],"name":"RemoveLiquiditySingleSy","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":"uint256","name":"netLpToRemove","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netTokenOut","type":"uint256"}],"name":"RemoveLiquiditySingleToken","type":"event"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"netSyDesired","type":"uint256"},{"internalType":"uint256","name":"netPtDesired","type":"uint256"},{"internalType":"uint256","name":"minLpOut","type":"uint256"}],"name":"addLiquidityDualSyAndPt","outputs":[{"internalType":"uint256","name":"netLpOut","type":"uint256"},{"internalType":"uint256","name":"netSyUsed","type":"uint256"},{"internalType":"uint256","name":"netPtUsed","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"netTokenIn","type":"uint256"},{"internalType":"address","name":"tokenMintSy","type":"address"},{"internalType":"address","name":"bulk","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"},{"internalType":"uint256","name":"netPtDesired","type":"uint256"},{"internalType":"uint256","name":"minLpOut","type":"uint256"}],"name":"addLiquidityDualTokenAndPt","outputs":[{"internalType":"uint256","name":"netLpOut","type":"uint256"},{"internalType":"uint256","name":"netTokenUsed","type":"uint256"},{"internalType":"uint256","name":"netPtUsed","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"netPtIn","type":"uint256"},{"internalType":"uint256","name":"minLpOut","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":"guessPtSwapToSy","type":"tuple"}],"name":"addLiquiditySinglePt","outputs":[{"internalType":"uint256","name":"netLpOut","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":"netSyIn","type":"uint256"},{"internalType":"uint256","name":"minLpOut","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":"guessPtReceivedFromSy","type":"tuple"}],"name":"addLiquiditySingleSy","outputs":[{"internalType":"uint256","name":"netLpOut","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":"netSyIn","type":"uint256"},{"internalType":"uint256","name":"minLpOut","type":"uint256"},{"internalType":"uint256","name":"minYtOut","type":"uint256"}],"name":"addLiquiditySingleSyKeepYt","outputs":[{"internalType":"uint256","name":"netLpOut","type":"uint256"},{"internalType":"uint256","name":"netYtOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"minLpOut","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":"guessPtReceivedFromSy","type":"tuple"},{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"netTokenIn","type":"uint256"},{"internalType":"address","name":"tokenMintSy","type":"address"},{"internalType":"address","name":"bulk","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"}],"name":"addLiquiditySingleToken","outputs":[{"internalType":"uint256","name":"netLpOut","type":"uint256"},{"internalType":"uint256","name":"netSyFee","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"minLpOut","type":"uint256"},{"internalType":"uint256","name":"minYtOut","type":"uint256"},{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"netTokenIn","type":"uint256"},{"internalType":"address","name":"tokenMintSy","type":"address"},{"internalType":"address","name":"bulk","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"}],"name":"addLiquiditySingleTokenKeepYt","outputs":[{"internalType":"uint256","name":"netLpOut","type":"uint256"},{"internalType":"uint256","name":"netYtOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"netLpToRemove","type":"uint256"},{"internalType":"uint256","name":"minSyOut","type":"uint256"},{"internalType":"uint256","name":"minPtOut","type":"uint256"}],"name":"removeLiquidityDualSyAndPt","outputs":[{"internalType":"uint256","name":"netSyOut","type":"uint256"},{"internalType":"uint256","name":"netPtOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"netLpToRemove","type":"uint256"},{"components":[{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"minTokenOut","type":"uint256"},{"internalType":"address","name":"tokenRedeemSy","type":"address"},{"internalType":"address","name":"bulk","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"},{"internalType":"uint256","name":"minPtOut","type":"uint256"}],"name":"removeLiquidityDualTokenAndPt","outputs":[{"internalType":"uint256","name":"netTokenOut","type":"uint256"},{"internalType":"uint256","name":"netPtOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"netLpToRemove","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":"guessPtReceivedFromSy","type":"tuple"}],"name":"removeLiquiditySinglePt","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":"netLpToRemove","type":"uint256"},{"internalType":"uint256","name":"minSyOut","type":"uint256"}],"name":"removeLiquiditySingleSy","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":"netLpToRemove","type":"uint256"},{"components":[{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"minTokenOut","type":"uint256"},{"internalType":"address","name":"tokenRedeemSy","type":"address"},{"internalType":"address","name":"bulk","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"}],"name":"removeLiquiditySingleToken","outputs":[{"internalType":"uint256","name":"netTokenOut","type":"uint256"},{"internalType":"uint256","name":"netSyFee","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
608080604052346100175761570e90816200001d8239f35b600080fdfe608060408181526004918236101561001657600080fd5b600090813560e01c908163015491d11461211d57508063178d29d314611d0c5780633af1f32914611a46578063409c7a8914611731578063690807ad1461121f578063694ab55914610ded578063844384aa14610cf157806397ee279e14610a34578063b7d75b8b14610886578063cb591eb2146104e8578063dfbc814e146103585763e6eaba01146100a857600080fd5b34610351577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc9060a082360112610351576100e161251b565b936100ea612543565b94604435926064359467ffffffffffffffff86116103545760c0908685019636030112610351576084359073ffffffffffffffffffffffffffffffffffffffff91828916948851997f2c8ce6bc000000000000000000000000000000000000000000000000000000008b5260608b83818a5afa9a8b15610347579a8591899a9b9c8692610315575b508980610303575b505016918a8661018a8c86613e13565b6101ea83519c8d9384937ff6b911bc00000000000000000000000000000000000000000000000000000000855288850160409194939294606082019573ffffffffffffffffffffffffffffffffffffffff80921683521660208201520152565b0381878b5af19889156102f95784996102c4575b5080891061028f5750509161024061023a8989947fbcfac3aca0242d70e941905db1a4ffc8b7e15f3375043f5399d640a8ea3007ce9688613b6f565b98612f5a565b1694610280888a519384933397859094939260609273ffffffffffffffffffffffffffffffffffffffff6080840197168352602083015260408201520152565b0390a482519182526020820152f35b60449250888b51927f9cdffc8e0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b9098506102e89193508a3d8c116102f2575b6102e081836126be565b810190612fd2565b92909297386101fe565b503d6102d6565b8b513d86823e3d90fd5b61030e91338b612c12565b388961017a565b61033791925060603d8111610340575b61032f81836126be565b8101906126ff565b50509038610172565b503d610325565b8a513d86823e3d90fd5b80fd5b5080fd5b5091346104e4577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc9060a0823601126104e05761039361251b565b9061039c612543565b906084359067ffffffffffffffff82116104dc5760c08282019583360301126104dc5773ffffffffffffffffffffffffffffffffffffffff90818416936060885180937f2c8ce6bc00000000000000000000000000000000000000000000000000000000825281885afa9182156104d2579189610460927f43eb84d5f21c53e2b7be07b8fc06cbbb55af094a111c91c7ddc6513fed4d035295946104689a9b9c92936104ae575b5060643592604435926104598d88831630613713565b928b61320c565b969097612f5a565b61028087898b51948594169860243398013590859094939260609273ffffffffffffffffffffffffffffffffffffffff6080840197168352602083015260408201520152565b9092506104c9915060603d81116103405761032f81836126be565b92905038610443565b88513d8b823e3d90fd5b8680fd5b8380fd5b8280fd5b507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc9060a0823601126103515761051d61251b565b92610526612543565b936044359267ffffffffffffffff84116103515760c0848801958536030112610351576084359473ffffffffffffffffffffffffffffffffffffffff90818816928551977f2c8ce6bc00000000000000000000000000000000000000000000000000000000895260609889818d81895afa9081156107a3579084869285908693610863575b50926105b99293168d613713565b9088517f794052f30000000000000000000000000000000000000000000000000000000081528d30908201526101209081816024818c5afa91821561085957906106139291879261082c575b505042908460643591612807565b9c9250938481036107f757508481106107c2575060248b9101359c816107ad575b508b91508d6106968a928c5195869485947f156e29f6000000000000000000000000000000000000000000000000000000008652850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b0381868a5af1998a156107a357839a610772575b505088106107465750610742969798506106c390612f5a565b16917f7f646a534401967ac0913451efea28d9e170ffc164efa98e3957cde363c0245f8451806107248a898d3397859094939260609273ffffffffffffffffffffffffffffffffffffffff6080840197168352602083015260408201520152565b0390a451938493846040919493926060820195825260208201520152565b0390f35b8060018b7f4e487b71000000000000000000000000000000000000000000000000000000006024945252fd5b610792929a50803d1061079c575b61078a81836126be565b8101906127ec565b50509738806106aa565b503d610780565b88513d85823e3d90fd5b6107ba9288339116612c12565b388981610634565b8e856044928d51927f6a1dbf1b0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b8f856044928e51927fdea0d1760000000000000000000000000000000000000000000000000000000084528301526024820152fd5b61084b9250803d10610852575b61084381836126be565b81019061274d565b3880610605565b503d610839565b8b513d88823e3d90fd5b6105b9935061087f91508d803d106103405761032f81836126be565b50926105ab565b50823461035457610896366125f7565b909473ffffffffffffffffffffffffffffffffffffffff91828516948480610a22575b50508851967ff6b911bc00000000000000000000000000000000000000000000000000000000885289888061091d888b8089850160409194939294606082019573ffffffffffffffffffffffffffffffffffffffff80921683521660208201520152565b03818c8a5af1978815610a185789986109f3575b508089106109be57508087106109895750507fd9f35a37b64d95edfd8f26adf130ce45f3e9ddf3c7ab8c1fb7224727a339a98e9087519416938061028088883396846040919493926060820195825260208201520152565b60449250868951927f9cdffc8e0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b826044918a8c51927f0a4439e60000000000000000000000000000000000000000000000000000000084528301526024820152fd5b909750610a0e919850893d8b116102f2576102e081836126be565b979097968a610931565b8a513d8b823e3d90fd5b610a2d913388612c12565b89846108b9565b503461035157610a43366125f7565b90959293919473ffffffffffffffffffffffffffffffffffffffff90818616928551987f2c8ce6bc000000000000000000000000000000000000000000000000000000008a52606098898b8d81895afa918215610ce757849b8593610cc1575b5088517f794052f3000000000000000000000000000000000000000000000000000000008152308e820152610120929083816024818c5afa938415610cb75790610afa949392918894610c98575b50504292612807565b9a92509b90848110610c6357509089918c8281610c4e575b50505081610c39575b5087517f156e29f600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8816818e01908152602081018d905260408101929092529150899082908190606001038186895af1988915610c2f578399610c0e575b50508710610be257506107429596975083519216917f9334566f6358cd68e33d423fb1c9119c6837e3a2a7a8affaaa5020ed06aec0693391806107248a898d846040919493926060820195825260208201520152565b8060018a7f4e487b71000000000000000000000000000000000000000000000000000000006024945252fd5b610c25929950803d1061079c5761078a81836126be565b5050963880610b8c565b87513d85823e3d90fd5b610c469286339116612c12565b388781610b1b565b610c5b9289339116612c12565b388c82610b12565b8d856044928c51927f6a1dbf1b0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b610caf929450803d106108525761084381836126be565b913880610af1565b8b513d89823e3d90fd5b909250610cdc919b508a3d8c116103405761032f81836126be565b509a909a9138610aa3565b88513d86823e3d90fd5b5091346104e457610d01366125f7565b9073ffffffffffffffffffffffffffffffffffffffff95868516946060895180937f2c8ce6bc00000000000000000000000000000000000000000000000000000000825281895afa918215610de357918a8692610d999695947fc8437d84f52d1e20cc82487e336feadb2d39ede00af7711b6a58abf39392328f9b9c9d9293610dbf575b50610d938433848f166130ed565b8961320c565b875192835260208301829052604083018190529095909493169233918060608101610280565b909250610dda915060603d81116103405761032f81836126be565b92905038610d85565b89513d8c823e3d90fd5b50903461035457610dfd36612566565b9291958594919451977f2c8ce6bc00000000000000000000000000000000000000000000000000000000895273ffffffffffffffffffffffffffffffffffffffff938481169560608b84818a5afa9a8b1561121557849b6111f2575b5088517f794052f300000000000000000000000000000000000000000000000000000000815230848201526101209081816024818c5afa9182156108595786926111d5575b50507f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8b116111d1578a156111a9576020810151610edc908c612af7565b9b8a82019c8d51610eec91612b36565b908d8d8451610efa91612af7565b9051610f0591612b36565b9d82158f816111a0575b50611178578e818f610f2590610f2e945161318a565b9052845161318a565b8352610f3e82602085015161318a565b60208401528682126104dc57868e126104dc5790610f6b610f63610f73959493613057565b933690612f7b565b924292615264565b509087610f80838d612f4d565b1061113857899a50978489610f9a8c849d9b9c338c612c12565b610ffa83519d8e9384937ff6b911bc00000000000000000000000000000000000000000000000000000000855288850160409194939294606082019573ffffffffffffffffffffffffffffffffffffffff80921683521660208201520152565b0381868a5af1801561112e5761105698999a849161110f575b508a8051858152611023816126a2565b8151809b81927f5b709f17000000000000000000000000000000000000000000000000000000008352868a898501612fe8565b0381878b5af19889156102f95784996110e8575b509061107591612f4d565b9788106110bc575050865193845285602085015216917fac97b87f5422fa3beec99bff8f336310d8ebc7d33d909b7d534cd7c72f61e871863392a482519182526020820152f35b9060016024927f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b61107592919950611105908c8d3d106102f2576102e081836126be565b905098909161106a565b61112691508b3d8d116102f2576102e081836126be565b905038611013565b89513d85823e3d90fd5b509086886111486044948d612f4d565b9051927f9cdffc8e0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b868d517fccbf5468000000000000000000000000000000000000000000000000000000008152fd5b9050158f610f0f565b838a517f25daaec3000000000000000000000000000000000000000000000000000000008152fd5b8480fd5b6111eb9250803d106108525761084381836126be565b3880610e9e565b61120b919b5060603d81116103405761032f81836126be565b9150509938610e59565b89513d86823e3d90fd5b5091346104e4577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc926080843601126103515761125a61251b565b611262612543565b916064359567ffffffffffffffff87116103545760c0908786019736030112610351578451917f2c8ce6bc000000000000000000000000000000000000000000000000000000009485845273ffffffffffffffffffffffffffffffffffffffff90818616936060868381885afa958615611725578196611702575b508260443596876116f1575b16906112f58b83613e13565b9080998b51997f2f13b60c000000000000000000000000000000000000000000000000000000008b5260209a8b8188818d5afa9081156116e757908e929185916116ba575b501561158657505190815260608186818b5afa90811561157c57908691839161155a575b50168b51927ff6b911bc0000000000000000000000000000000000000000000000000000000084528c84806113c28d86868c850160409194939294606082019573ffffffffffffffffffffffffffffffffffffffff80921683521660208201520152565b0381868d5af1938415611550578b918e89928697611529575b5090856024925195869485937fbcb7ea5d000000000000000000000000000000000000000000000000000000008552168b8401525af191821561151e5780926114ec575b505061142a91612f4d565b915b600183106114b65750916114688a6114709a9b937f3fff08e8137afe866dce7ced13ddc12d684db61b80b0ac5cb9e54961c9dd8a219587613b6f565b988992612f5a565b16946114a98a5192839233968460409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b0390a48351928352820152f35b604490838b51917f0a4439e600000000000000000000000000000000000000000000000000000000835282015260016024820152fd5b9091508982813d8311611517575b61150481836126be565b8101031261035157505161142a3861141f565b503d6114fa565b8c51903d90823e3d90fd5b8197506115468791602494933d8b116102f2576102e081836126be565b50979192506113db565b8d513d85823e3d90fd5b611573915060603d6060116103405761032f81836126be565b9150503861135e565b8c513d84823e3d90fd5b81517ff6b911bc00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff80871689830190815292166020830152604082018c9052949c50929392909150829081906060010381858b5af1801561168d578b9083928491611697575b5081519b848d5261160e8d6126a2565b61164383519d8e9384937f29910b110000000000000000000000000000000000000000000000000000000085528a8501612fe8565b0381858b5af1998a1561168d57829a611668575b509061166291612f4d565b9161142c565b611685919a5061166292508b3d8d116102f2576102e081836126be565b999091611657565b8b513d84823e3d90fd5b9050816116b19293503d84116102f2576102e081836126be565b919091386115fe565b6116da91508d803d106116e0575b6116d281836126be565b810190612c83565b3861133a565b503d6116c8565b8e513d86823e3d90fd5b6116fd888a338a612c12565b6112e9565b61171c91965060603d6060116103405761032f81836126be565b505094386112dd565b508851903d90823e3d90fd5b5082346103545761174136612566565b929473ffffffffffffffffffffffffffffffffffffffff9491929492838716948951907f2c8ce6bc000000000000000000000000000000000000000000000000000000008252606091828186818b5afa908115611a3c578b908c92611a1a575b50898b81611a05575b5050508b51907f794052f300000000000000000000000000000000000000000000000000000000825230868301526101209182816024818d5afa9283156119fb57918b916118119594938f946119d4575b5050610f6361180991613057565b9242926153de565b50508a8181519a8c8c526118248c6126a2565b61185983519c8d9384937f5b709f170000000000000000000000000000000000000000000000000000000085528a8501612fe8565b03818d8b5af19889156119ca578a908c8c9b611999575b50509180916118826118dc948b61304a565b8d5194859283927f156e29f60000000000000000000000000000000000000000000000000000000084528a8a850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b03818d8b5af1998a1561198e579961196d575b5050808810611938575050865193845285602085015216917fb51950711c9b21dc7888d41f68a19540231ffb5f0d19d8f75cbccaf90ffa7fa5863392a482519182526020820152f35b60449250878951927f6a1dbf1b0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b611984929950803d1061079c5761078a81836126be565b50509689806118ef565b8b51903d90823e3d90fd5b6118829b508493916118dc959350816119bd92903d106102f2576102e081836126be565b9b9092505091928c611870565b8b513d8c823e3d90fd5b611809929450610f6391816119f492903d106108525761084381836126be565b93916117fb565b8e513d8f823e3d90fd5b611a12928a339116612c12565b8c898b6117aa565b9050611a339150833d85116103405761032f81836126be565b9190508d6117a1565b8c513d8d823e3d90fd5b50823461035457611a5636612566565b929473ffffffffffffffffffffffffffffffffffffffff9491929492838716948951977f2c8ce6bc000000000000000000000000000000000000000000000000000000008952606091828a86818b5afa8015611a3c578b9a8c91611ce8575b508c517f794052f30000000000000000000000000000000000000000000000000000000081523087820152610120919082816024818e5afa928315611cdd57918c918f93611b199695611cb6575b5050610f63611b1191613057565b924292613ed7565b505098888281611ca1575b5050508a898151928c8452611b38846126a2565b611b6d835194859384937f29910b110000000000000000000000000000000000000000000000000000000085528a8501612fe8565b03818d8b5af19889156119ca578a918c8c9b611c6e575b5050918091611b96611bf1948b61304a565b908d5194859283927f156e29f60000000000000000000000000000000000000000000000000000000084528a8a850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b03818d8b5af1998a1561198e5799611c4d575b5050808810611938575050865193845285602085015216917fc87b85efc5055ef177e0092af0d4e624fff4b1d57db748857f65e4b7e4a28a36863392a482519182526020820152f35b611c64929950803d1061079c5761078a81836126be565b5050968980611c04565b849350611bf194929b50611b969181611c9292903d106102f2576102e081836126be565b9190919b92505091928c611b84565b611cae9289339116612c12565b8b8882611b24565b611b11929450610f639181611cd692903d106108525761084381836126be565b9391611b03565b508e513d8f823e3d90fd5b9050611d02919a50833d85116103405761032f81836126be565b9a9150998d611ab5565b508290346103515760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261035157611d4661251b565b91611d4f612543565b90604435906064359473ffffffffffffffffffffffffffffffffffffffff90818516928461210c575b868951967f2f13b60c000000000000000000000000000000000000000000000000000000008852602097888185818a5afa9081156121025783916120e5575b5015611fba575089517f2c8ce6bc0000000000000000000000000000000000000000000000000000000081526060818481895afa90811561168d579085918391611f99575b5016908a51917ff6b911bc0000000000000000000000000000000000000000000000000000000083528b8380611e618b858a8a850160409194939294606082019573ffffffffffffffffffffffffffffffffffffffff80921683521660208201520152565b0381858b5af192831561157c5782918a918e95611f76575b50602483949551809481937fbcb7ea5d0000000000000000000000000000000000000000000000000000000083528b8b168a8401525af191821561151e578092611f44575b5050611ec991612f4d565b975b808910611f0f5750508751938452868585015216917fd31f02c44717b409d13b92ec9d2eaf1427fb4e63f85f4777f1458fb8d9387761873392a48351928352820152f35b60449250888a51927f0a4439e60000000000000000000000000000000000000000000000000000000084528301526024820152fd5b9091508882813d8311611f6f575b611f5c81836126be565b81010312610351575051611ec98c611ebe565b503d611f52565b839450611f91602491873d89116102f2576102e081836126be565b509450611e79565b611fb1915060603d81116103405761032f81836126be565b9150508c611dfc565b8a517ff6b911bc00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff80861685830190815292166020830152604082018890529a99985089908b908190606001038184895af1998a156117255789612078999a9b839284916120c2575b50815190848252612045826126a2565b82519b8c9283927f29910b1100000000000000000000000000000000000000000000000000000000845289898501612fe8565b0381858a5af198891561168d57829961209d575b509061209791612f4d565b97611ecb565b6120ba91995061209792508b3d8d116102f2576102e081836126be565b98909161208c565b9050816120dc9293503d84116102f2576102e081836126be565b9190918d612035565b6120fc9150893d8b116116e0576116d281836126be565b8c611db7565b8c513d85823e3d90fd5b61211885873387612c12565b611d78565b9390506101207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc9181833601126104e05761215661251b565b9261215f612543565b9160a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c36011261251757610104359267ffffffffffffffff928385116125135760c09085360301126104dc577f2c8ce6bc00000000000000000000000000000000000000000000000000000000895273ffffffffffffffffffffffffffffffffffffffff928382169560609a8b8186818b5afa9081156119ca57918a8c9d9492828b839f9e968b9a999794936124e8575b50612226602493948d8b019b8c911689613713565b9e51928380927f794052f3000000000000000000000000000000000000000000000000000000008252308c8301525afa928315611cdd578e936124c3575b505061226f90613057565b8d519260a084019081118482101761249757928e928d6122b9936123019686526064358452608435602085015260a4358685015260c4358985015260e435608085015242926153de565b5050928c848351928284526122cd846126a2565b8451958694859384937f5b709f170000000000000000000000000000000000000000000000000000000085528c8501612fe8565b03918c5af1998a15611a3c578b918d8d9c612465575b50509161232a849392612384959361304a565b8d5194859283927f156e29f60000000000000000000000000000000000000000000000000000000084528d89850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b03818d8b5af1998a1561198e5799612444575b505060443580891061240f575050906123d07ff83776e5b667a2b471f92ddfd482749c61b5328b832d375097638c2c08818f3b92612f5a565b610280888a519384931697602433970135908460409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b60449250888a51927f6a1dbf1b0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b61245b929950803d1061079c5761078a81836126be565b5050963880612397565b8594929c5061238495935061232a918161248a92903d106102f2576102e081836126be565b9c9294509294508d612317565b60248e6041897f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b61226f92935090816124e092903d106108525761084381836126be565b919038612264565b61222694506024935061250790893d8b116103405761032f81836126be565b95919050949350612211565b8780fd5b8580fd5b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361253e57565b600080fd5b6024359073ffffffffffffffffffffffffffffffffffffffff8216820361253e57565b6101207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc82011261253e5773ffffffffffffffffffffffffffffffffffffffff91600435838116810361253e5792602435908116810361253e57916044359160a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7c60643593011261253e57608490565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc60a091011261253e5773ffffffffffffffffffffffffffffffffffffffff90600435828116810361253e5791602435908116810361253e5790604435906064359060843590565b67ffffffffffffffff811161267357604052565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6020810190811067ffffffffffffffff82111761267357604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761267357604052565b9081606091031261253e5780519173ffffffffffffffffffffffffffffffffffffffff92838116810361253e57926020830151818116810361253e57604090930151908116810361253e5790565b8091610120928391031261253e5760405191820182811067ffffffffffffffff82111761267357604052805182526020810151602083015260408101516040830152606081015173ffffffffffffffffffffffffffffffffffffffff8116810361253e5760608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e0830152610100809101519082015290565b9081606091031261253e578051916040602083015192015190565b919293907f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80821161253e5780851161253e5760009582158015612a9d575b612a735760a08501511115612a49576040840195865180156000146129cb5750506128718583612af7565b906000821261253e57600060038311156129bc57508160019080821c82810180911161296d5791905b84831061299c575050505b811161253e577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc18810190811360011661296d57946103e89194935b600087131561294357602081016128f8878251612bf6565b9052612905858251612bf6565b905261291b6129148388612bf6565b8251612bf6565b90526000811261253e57936000811261253e57926000811261253e57916000811261253e5790565b60046040517fccbf5468000000000000000000000000000000000000000000000000000000008152fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b909193506129b3846129ae8184612f43565b612f4d565b821c919061289a565b91156128a557600191506128a5565b869792506129df906129e792949697612af7565b865190612b36565b6129f2825186612af7565b94612a036020880196875190612b36565b80831215612a2b575050612a1d81612a2592989651612af7565b825190612b36565b946128e0565b612a1d91985080979650612a43925097968651612af7565b936128e0565b60046040517fb2094b59000000000000000000000000000000000000000000000000000000008152fd5b60046040517f25daaec3000000000000000000000000000000000000000000000000000000008152fd5b508515612846565b90670de0b6b3a76400009182810292818405149015171561296d57565b9081600003918083057fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff149015171561296d57565b8181029291600082127f800000000000000000000000000000000000000000000000000000000000000082141661296d57818405149015171561296d57565b8115612b8b577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82147f800000000000000000000000000000000000000000000000000000000000000082141661296d570590565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b90670de0b6b3a76400006000838203931281841281169184139015161761296d57565b8181039291600013801582851316918412161761296d57565b9190916000838201938412911290801582169115161761296d57565b6040517f23b872dd00000000000000000000000000000000000000000000000000000000602082015273ffffffffffffffffffffffffffffffffffffffff9283166024820152929091166044830152606480830193909352918152612c8191612c7c6084836126be565b612c9b565b565b9081602091031261253e5751801515810361253e5790565b73ffffffffffffffffffffffffffffffffffffffff1690604051906040820182811067ffffffffffffffff821117612673576040526020928383527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656484840152803b15612dcb5760008281928287612d229796519301915af1612d1c612e29565b90612ee5565b80519081612d2f57505050565b8280612d3f938301019101612c83565b15612d475750565b608490604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b606484604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b3d15612e82573d9067ffffffffffffffff82116126735760405191612e7660207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601846126be565b82523d6000602084013e565b606090565b919082519283825260005b848110612ed15750507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8460006020809697860101520116010190565b602081830181015184830182015201612e92565b90919015612ef1575090565b815115612f015750805190602001fd5b612f3f906040519182917f08c379a0000000000000000000000000000000000000000000000000000000008352602060048401526024830190612e87565b0390fd5b8115612b8b570490565b9190820180921161296d57565b3573ffffffffffffffffffffffffffffffffffffffff8116810361253e5790565b91908260a091031261253e5760405160a0810181811067ffffffffffffffff821117612673576040526080808294803584526020810135602085015260408101356040850152606081013560608501520135910152565b919082604091031261253e576020825192015190565b61301a939273ffffffffffffffffffffffffffffffffffffffff60609316825260208201528160408201520190612e87565b90565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820191821161296d57565b9190820391821161296d57565b602073ffffffffffffffffffffffffffffffffffffffff600460009360405194859384927f1d52edc4000000000000000000000000000000000000000000000000000000008452165af19081156130e1576000916130b3575090565b906020823d82116130d9575b816130cc602093836126be565b8101031261035157505190565b3d91506130bf565b6040513d6000823e3d90fd5b90919073ffffffffffffffffffffffffffffffffffffffff168061317457509050340361311657565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f657468206d69736d6174636800000000000000000000000000000000000000006044820152fd5b8161317f575b505050565b612c81923091612c12565b9080821261319b5761301a91612bdd565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600860248201527f6e656761746976650000000000000000000000000000000000000000000000006044820152fd5b8181029291811591840414171561296d57565b969496959290939573ffffffffffffffffffffffffffffffffffffffff8086169260409485517f794052f30000000000000000000000000000000000000000000000000000000081523060048201526101209081816024818a5afa9182156134df576000926134c2575b505061328183613057565b81516000811261253e57613295908d6131f9565b8251926000841261253e5760200151946000861261253e5760009b6132fe8f96896132e7613304966132e160449a670de0b6b3a76400006132da60209f9c879d6131f9565b0490612f4d565b90612f43565b9a8b92169416976132f9828a876134ea565b61304a565b916134ea565b8751998a9384927fdb74aa15000000000000000000000000000000000000000000000000000000008452896004850152881660248401525af19586156134b75760009661347e575b506133bf9260609260006133628994859c61304a565b918751968795869485937f156e29f60000000000000000000000000000000000000000000000000000000085526004850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b03925af190811561347357600091613453575b50809680821061341f5750508183106133ea57505050565b6044935051917fa59b8c3100000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b60449251917f6a1dbf1b00000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b61346b915060603d811161079c5761078a81836126be565b5050386133d2565b82513d6000823e3d90fd5b909394956020823d82116134af575b8161349a602093836126be565b810103126103515750519493926133bf61334c565b3d915061348d565b84513d6000823e3d90fd5b6134d89250803d106108525761084381836126be565b3880613276565b88513d6000823e3d90fd5b821561317a5773ffffffffffffffffffffffffffffffffffffffff9081169081613587575050600080809381935af1613521612e29565b501561352957565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f6574682073656e64206661696c656400000000000000000000000000000000006044820152fd5b604093919351927fa9059cbb000000000000000000000000000000000000000000000000000000006020850152166024830152604482015260448152608081019181831067ffffffffffffffff84111761267357612c8192604052612c9b565b9035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff818136030182121561253e570190565b9173ffffffffffffffffffffffffffffffffffffffff80921683526020830152606060408301528235600481101561253e576060830152602083013590811680910361253e57608082015260408201357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18336030181121561253e5782016020813591019267ffffffffffffffff821161253e57813603841361253e57606090608060a08501528260e08501528261010095868601376000858486010152013580151580910361253e5760c0830152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016010190565b9060a083019261372384826135e7565b93600094356004811015612517578061389f5750509081613745602093612f5a565b61375584830135809233906130ed565b935b604082019173ffffffffffffffffffffffffffffffffffffffff80948161377d86612f5a565b1661389657606088935b01948261379387612f5a565b16156138315750506137a6606494612f5a565b1660405196879586947fb27670700000000000000000000000000000000000000000000000000000000086521660048501526024840152600160448401525af191821561382557916137f7575b5090565b90506020813d821161381d575b81613811602093836126be565b8101031261253e575190565b3d9150613804565b604051903d90823e3d90fd5b6084955061383e90612f5a565b9782604051998a9889977f20e8c565000000000000000000000000000000000000000000000000000000008952166004880152166024860152604485015260016064850152165af191821561382557916137f7575090565b60608993613787565b6003036138e9575090816138b4602093612f5a565b6138c484830135809233906130ed565b6138e3816138d184612f5a565b6138dd60408601612f5a565b90613ab0565b93613757565b73ffffffffffffffffffffffffffffffffffffffff8061390884612f5a565b166139eb5760208301353403613116575b8061392660808501612f5a565b169061393184612f5a565b166139e4576020830135915b61395061394985612f5a565b91856135e7565b92823b15612513579161399b939188936040518096819582947f2bdb823c00000000000000000000000000000000000000000000000000000000845260208b0135906004850161361a565b03925af180156139d9576139c3575b5090816138e36139be604060209501612f5a565b613a29565b936139d1602093929561265f565b9390916139aa565b6040513d87823e3d90fd5b859161393d565b806139f584612f5a565b16613a0260808501612f5a565b60208501359081613a16575b505050613919565b613a21923390612c12565b388080613a0e565b60009073ffffffffffffffffffffffffffffffffffffffff1680613a4d5750504790565b6020602491604051928380927f70a082310000000000000000000000000000000000000000000000000000000082523060048301525afa918215613825578092613a9657505090565b9091506020823d82116130d957816130cc602093836126be565b73ffffffffffffffffffffffffffffffffffffffff9190821680613b1e575016803b1561253e576000906004604051809481937fd0e30db00000000000000000000000000000000000000000000000000000000083525af180156130e157613b155750565b612c819061265f565b92915050813b1561253e576000916024839260405194859384927f2e1a7d4d00000000000000000000000000000000000000000000000000000000845260048401525af180156130e157613b155750565b93929360a08501613b8081876135e7565b35600481101561253e5780613be4575050602092613b9f928692613d01565b925b0135808310613bad5750565b82604491604051917fc5b5576d00000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b9195929391600303613c305750613c0282613c2b9260209530613d01565b8095613c1d82613c1460408701612f5a565b6138dd87612f5a565b613c2684612f5a565b6134ea565b613ba1565b90613c67613c618473ffffffffffffffffffffffffffffffffffffffff936080820197613c5c89612f5a565b613d01565b94612f5a565b16613c7e613c7760408501612f5a565b92846135e7565b90803b1561253e57613cc49460008094604051978895869485937f2bdb823c0000000000000000000000000000000000000000000000000000000085526004850161361a565b03925af19182156130e157602092613cf2575b50613c2b613ce76139be83612f5a565b8095613c2684612f5a565b613cfb9061265f565b38613cd7565b9190926060810173ffffffffffffffffffffffffffffffffffffffff94859283613d2a84612f5a565b1615613d9a575050613d3b90612f5a565b1692604051927f83f5b766000000000000000000000000000000000000000000000000000000008452166004830152602482015260208160848160008096816044840152600160648401525af1918215613825578092613a9657505090565b60a492509083613db06040602097989401612f5a565b60405197889687957f769f8e5d0000000000000000000000000000000000000000000000000000000087521660048601526024850152166044830152600096879182606485015260016084850152165af1918215613825578092613a9657505090565b9060600173ffffffffffffffffffffffffffffffffffffffff613e3582612f5a565b16156137f35761301a9150612f5a565b15613e4c57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f6e6f206578697374696e67206c700000000000000000000000000000000000006044820152fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811461296d5760010190565b9193949092613ee79084846141bb565b93604086015115614009575b60005b6060870151811015613fdf57613f0c8188615181565b908488613f23613f1b85614dc3565b898b85614e45565b9190613f6f6080613f65613f55613f4e613f3e8c8b51612f4d565b976132f9886020809d015161304a565b96866131f9565b95613f608b8d61304a565b6131f9565b9501518585614df0565b613fcd57505011613f9657506001820180921161296d57613f91918852613eaa565b613ef6565b917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810190811161296d57613f9192890152613eaa565b9a509a50505050509250509150929190565b60046040517ffa711db2000000000000000000000000000000000000000000000000000000008152fd5b6020860151600061401d602088015161301d565b80820361406857508082101561406157505b8181101561405a575b6020870152614046866151e9565b61405560408401511515613e45565b613ef3565b5080614038565b905061402f565b6140728183612f4d565b906001820180921161296d5786516140918360011c60208c0151612bdd565b9061409f818560011c612bf6565b60008313806141b1575b1561415357670de0b6b3a76400006141298d61412461410f61410a6000986140ff6141046140ec8e6140e36141309d60208b015190612bf6565b9060011c612af7565b6140ff6140f9858d612af7565b91612aa5565b614546565b98612aa5565b614932565b604061411b845161452c565b93015195612bdd565b612af7565b0590612bdd565b121561414857506141439060011c61301d565b61401d565b915060011c9061401d565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f696e76616c6964207074546f4d61726b657400000000000000000000000000006044820152fd5b50600081136140a9565b92919260409081516080810181811067ffffffffffffffff82111761267357835260009182825260208201908382528483018481526060840196858852849960a0840181815111156144525790614212915161304a565b936080840151976301e1338096878a0299808b05891490151715614425577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff998a8811614421578761426391612b36565b898113156143f15781526020860151898112156143e9577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff905b8a8113156143db575b6142ba670de0b6b3a76400009687926131f9565b04908b821161439957906142cd91612af7565b808452865190811580156143d3575b61439d575050855191886142fa896101008a015196519451966131f9565b048b81116143995761430b90614550565b94851261436957509261434460c095936140ff61433f61433a866140ff6140f96143539e9d9b61434a9a612bf6565b61447b565b612aa5565b90612bdd565b905201516131f9565b04918211610351575061436590614550565b9052565b8460249151907fca78c8a40000000000000000000000000000000000000000000000000000000082526004820152fd5b8a80fd5b604492508351917fb1c4aefb00000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b5080156142dc565b6143e490614dc3565b6142a6565b60019061429d565b6024908351907f1ca418760000000000000000000000000000000000000000000000000000000082526004820152fd5b8980fd5b6024897f4e487b710000000000000000000000000000000000000000000000000000000081526011600452fd5b600489517fb2094b59000000000000000000000000000000000000000000000000000000008152fd5b670de0b6b3a7640000811461449d5761410a816140ff6140f961301a94612bba565b60046040517fa9c8b14d000000000000000000000000000000000000000000000000000000008152fd5b156144ce57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f496e76616c6964206578706f6e656e74000000000000000000000000000000006044820152fd5b8015612b8b576ec097ce7bc90715b34b9f10000000000590565b8115612b8b570590565b7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008112158061491f575b614583906144c7565b6000811261490a576064906806f05b59d3b200000081126148a7577ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e0000000168056bc75e2d6310000082770195e54c5dd42177f53a27172fa9ec630262827000000000925b0280829168ad78ebc5ac6200000081121561486b575b50806856bc75e2d63100000084921215614831575b682b5e3af16b188000008112156147f9575b6815af1d78b58c4000008112156147c1575b680ad78ebc5ac620000081121561478a575b81811215614753575b6802b5e3af16b188000081121561471c575b68015af1d78b58c400008112156146e5575b60028282800205056003838383020505600484848302050560058585830205056006868683020505600787878302050590600888888402050592600989898602050594600a8a8a8802050596600b8b8b8a02050598600c8c8c8c0205059a0101010101010101010101010205020590565b6806f5f17757889379377ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000083920193020591614674565b6808f00f760a4b2db55d7ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000083920193020591614662565b680ebc5fb417461211107ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000083920193020591614650565b68280e60114edb805d037ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000083920193020591614647565b690127fa27722cc06cc5e27fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c0000083920193020591614635565b693f1fce3da636ea5cf8507fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e780000083920193020591614623565b6b02df0ab5a80a22c61ab5a7007fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf00000083920193020591614611565b6e01855144814a7ff805980ff008400092507fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000000019050826145fc565b6803782dace9d900000081126148f7577ffffffffffffffffffffffffffffffffffffffffffffffffc87d25316270000000168056bc75e2d63100000826b1425982cf597cd205cef7380926145e6565b68056bc75e2d63100000826001926145e6565b61491690600003614550565b61301a9061452c565b5068070c1cc73b00c8000081131561457a565b6000811315614a155780670c7d713b49da00001280614a04575b156149fb57670de0b6b3a7640000906ec097ce7bc90715b34b9f10000000009061499f908302828101907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f000000000018302614546565b9080828002059181838202058284820205838582020591848684020593858786020595808888020597880205600f900596600d900595600b900594600990059360079005926005900591600390050101010101010160011b0590565b61301a90614a73565b50670f43fc2c04ee0000811261494c565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6f7574206f6620626f756e6473000000000000000000000000000000000000006044820152fd5b670de0b6b3a76400008112614dac5760649060007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c0000000000000821215614d81575b73011798004d755d3c8bc8e03204cf44619e000000821215614d60575b8202908202816e01855144814a7ff805980ff00840008281811215614d39575b5050506b02df0ab5a80a22c61ab5a70080821215614d19575b50693f1fce3da636ea5cf85080821215614cf9575b50690127fa27722cc06cc5e280821215614cd9575b5068280e60114edb805d0380821215614cb9575b50680ebc5fb4174612111080821215614ca2575b506808f00f760a4b2db55d80821215614c82575b506806f5f177578893793780821215614c62575b506806248f33704b28660380821215614c43575b506805c548670b9510e7ac80821215614c24575b50614be368056bc75e2d6310000091827ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf00000818301920102614546565b9080828002059181838202058284820205916003600560076009600b888a89020598808b8b02059a8b0205059805960594059205010101010160011b010590565b68056bc75e2d631000006756bc75e2d631000092020591019038614ba7565b68056bc75e2d6310000067ad78ebc5ac62000092020591019038614b93565b68056bc75e2d6310000068015af1d78b58c4000092020591019038614b7f565b68056bc75e2d631000006802b5e3af16b188000092020591019038614b6b565b68056bc75e2d631000008092020591019038614b57565b68056bc75e2d63100000680ad78ebc5ac620000092020591019038614b43565b68056bc75e2d631000006815af1d78b58c40000092020591019038614b2f565b68056bc75e2d63100000682b5e3af16b1880000092020591019038614b1a565b68056bc75e2d631000006856bc75e2d63100000092020591019038614b05565b68056bc75e2d631000009192945068ad78ebc5ac6200000093500205910190388080614aec565b6b1425982cf597cd205cef7380909105906803782dace9d900000001614acc565b50770195e54c5dd42177f53a27172fa9ec63026282700000000090056806f05b59d3b2000000614aaf565b614db8614dbd9161452c565b614a73565b60000390565b7f8000000000000000000000000000000000000000000000000000000000000000811461296d5760000390565b90670de0b6b3a76400009083820382811161296d5782614e118592846131f9565b0411159384614e22575b5050505090565b9091809394500180831161296d57614e39916131f9565b04101538808080614e1b565b9391928451602083015190614e728451916140ff6140f9604088015195614e6c888561318a565b93612bf6565b670d529ae9e86000008082136150a95750614e9c92916140ff61433f614e979361447b565b612bf6565b670de0b6b3a764000090818112615051576060614ec4614ebf836140ff87612aa5565b612ac2565b94015190600080941360001461508257816140ff614ee192612aa5565b828112615051575081614efe614ef860e093612bba565b86612af7565b05965b0151917f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9283811161035457876064614f3d614f449383612af7565b0595612bdd565b918183128015615036571561502e577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff925b82811315615020575b818102918183041490151715614ff35786614f9991612f4d565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101908111614ff35786614fcd91612f43565b9283116103515750614fe661301a9392614fed92612af7565b95856150e0565b936150e0565b6024827f4e487b710000000000000000000000000000000000000000000000000000000081526011600452fd5b61502990614dc3565b614f7f565b600192614f76565b50505061301a92915061504c614fed91866150e0565b614fe6565b602490604051907fca78c8a40000000000000000000000000000000000000000000000000000000082526004820152fd5b506150a3614ebf8261509e61509860e095612bba565b88612af7565b612b36565b96614f01565b60449250604051917ffc68d09e00000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b6000821215615179577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff915b600081131561516a57905b670de0b6b3a76400009182810292818404149015171561296d5761513a91612f43565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161253e5761301a91612af7565b61517390614dc3565b90615117565b60019161510c565b9015806151dc575b6151d55760208151910151808211156151c65760046040517ffa711db2000000000000000000000000000000000000000000000000000000008152fd5b6151cf91612f4d565b60011c90565b6040015190565b5060408101511515615189565b8051602082015191828211801561524f575b61520457505050565b6080612f3f9101516040519384937fb301af04000000000000000000000000000000000000000000000000000000008552600485016040919493926060820195825260208201520152565b50670de0b6b3a76400006080820151116151fb565b949093919261527660009186886141bb565b936040840151156153ab575b815b6060850151811015613fdf5761529a8186615181565b6152b16152a9828a8a8d614e45565b509190614dc3565b84811180159190615343576080890151826152ec575b50506152de575085526152d990613eaa565b615284565b985095505050509250509190565b909150670de0b6b3a76400009081038181116153165761530c90876131f9565b04111538806152c7565b6024887f4e487b710000000000000000000000000000000000000000000000000000000081526011600452fd5b5050507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810190811161537e5760208601526152d990613eaa565b6024847f4e487b710000000000000000000000000000000000000000000000000000000081526011600452fd5b6020840180516153bc895188615648565b808210156153d65750905b526153d1846151e9565b615282565b9050906153c7565b949093919460009560409586519360a0850185811067ffffffffffffffff82111761561b57885283855260209461543186820198848a528a830195865260609481868501526080978885019a8b526141bb565b928688518b810151156155d7575b50508a5b8851828101518210156155ae5789878a61547d8b8f956154668861547392615181565b80978d8c51915191614e45565b9291939093614dc3565b938a888751871161556d57866154b96154b36154cb976132f9846154c0986154aa613f60988a515161304a565b98510151612f4d565b8c6131f9565b985161304a565b955101518585614df0565b6155575750501161551f57600181018091116154f2578951526154ed90613eaa565b615443565b60248d7f4e487b710000000000000000000000000000000000000000000000000000000081526011600452fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81019081116154f25789518901526154ed90613eaa565b9e509e5050509850505050955050505050929190565b96505050505050507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9150019081116154f25789518901526154ed90613eaa565b60048c517ffa711db2000000000000000000000000000000000000000000000000000000008152fd5b01516155e583515186615648565b8082101561561457505b87895101526155fe88516151e9565b61560d8a835101511515613e45565b863861543f565b90506155ef565b60248a7f4e487b710000000000000000000000000000000000000000000000000000000081526041600452fd5b9061567661567c6156626060850151604086015190612bdd565b670de0b6b3a7640000928391865190612af7565b05614550565b92818401908282126000861290801582169115161761296d576156b660206156ad614129946140ff6156bc99612aa5565b92015185612bf6565b90612af7565b6103e79081810291818304149015171561296d576103e890049056fea2646970667358221220df1b330d60718102a79cfa0789da9939134a675d163f8ac5a989c157fe38218f64736f6c63430008110033
Deployed Bytecode
0x608060408181526004918236101561001657600080fd5b600090813560e01c908163015491d11461211d57508063178d29d314611d0c5780633af1f32914611a46578063409c7a8914611731578063690807ad1461121f578063694ab55914610ded578063844384aa14610cf157806397ee279e14610a34578063b7d75b8b14610886578063cb591eb2146104e8578063dfbc814e146103585763e6eaba01146100a857600080fd5b34610351577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc9060a082360112610351576100e161251b565b936100ea612543565b94604435926064359467ffffffffffffffff86116103545760c0908685019636030112610351576084359073ffffffffffffffffffffffffffffffffffffffff91828916948851997f2c8ce6bc000000000000000000000000000000000000000000000000000000008b5260608b83818a5afa9a8b15610347579a8591899a9b9c8692610315575b508980610303575b505016918a8661018a8c86613e13565b6101ea83519c8d9384937ff6b911bc00000000000000000000000000000000000000000000000000000000855288850160409194939294606082019573ffffffffffffffffffffffffffffffffffffffff80921683521660208201520152565b0381878b5af19889156102f95784996102c4575b5080891061028f5750509161024061023a8989947fbcfac3aca0242d70e941905db1a4ffc8b7e15f3375043f5399d640a8ea3007ce9688613b6f565b98612f5a565b1694610280888a519384933397859094939260609273ffffffffffffffffffffffffffffffffffffffff6080840197168352602083015260408201520152565b0390a482519182526020820152f35b60449250888b51927f9cdffc8e0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b9098506102e89193508a3d8c116102f2575b6102e081836126be565b810190612fd2565b92909297386101fe565b503d6102d6565b8b513d86823e3d90fd5b61030e91338b612c12565b388961017a565b61033791925060603d8111610340575b61032f81836126be565b8101906126ff565b50509038610172565b503d610325565b8a513d86823e3d90fd5b80fd5b5080fd5b5091346104e4577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc9060a0823601126104e05761039361251b565b9061039c612543565b906084359067ffffffffffffffff82116104dc5760c08282019583360301126104dc5773ffffffffffffffffffffffffffffffffffffffff90818416936060885180937f2c8ce6bc00000000000000000000000000000000000000000000000000000000825281885afa9182156104d2579189610460927f43eb84d5f21c53e2b7be07b8fc06cbbb55af094a111c91c7ddc6513fed4d035295946104689a9b9c92936104ae575b5060643592604435926104598d88831630613713565b928b61320c565b969097612f5a565b61028087898b51948594169860243398013590859094939260609273ffffffffffffffffffffffffffffffffffffffff6080840197168352602083015260408201520152565b9092506104c9915060603d81116103405761032f81836126be565b92905038610443565b88513d8b823e3d90fd5b8680fd5b8380fd5b8280fd5b507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc9060a0823601126103515761051d61251b565b92610526612543565b936044359267ffffffffffffffff84116103515760c0848801958536030112610351576084359473ffffffffffffffffffffffffffffffffffffffff90818816928551977f2c8ce6bc00000000000000000000000000000000000000000000000000000000895260609889818d81895afa9081156107a3579084869285908693610863575b50926105b99293168d613713565b9088517f794052f30000000000000000000000000000000000000000000000000000000081528d30908201526101209081816024818c5afa91821561085957906106139291879261082c575b505042908460643591612807565b9c9250938481036107f757508481106107c2575060248b9101359c816107ad575b508b91508d6106968a928c5195869485947f156e29f6000000000000000000000000000000000000000000000000000000008652850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b0381868a5af1998a156107a357839a610772575b505088106107465750610742969798506106c390612f5a565b16917f7f646a534401967ac0913451efea28d9e170ffc164efa98e3957cde363c0245f8451806107248a898d3397859094939260609273ffffffffffffffffffffffffffffffffffffffff6080840197168352602083015260408201520152565b0390a451938493846040919493926060820195825260208201520152565b0390f35b8060018b7f4e487b71000000000000000000000000000000000000000000000000000000006024945252fd5b610792929a50803d1061079c575b61078a81836126be565b8101906127ec565b50509738806106aa565b503d610780565b88513d85823e3d90fd5b6107ba9288339116612c12565b388981610634565b8e856044928d51927f6a1dbf1b0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b8f856044928e51927fdea0d1760000000000000000000000000000000000000000000000000000000084528301526024820152fd5b61084b9250803d10610852575b61084381836126be565b81019061274d565b3880610605565b503d610839565b8b513d88823e3d90fd5b6105b9935061087f91508d803d106103405761032f81836126be565b50926105ab565b50823461035457610896366125f7565b909473ffffffffffffffffffffffffffffffffffffffff91828516948480610a22575b50508851967ff6b911bc00000000000000000000000000000000000000000000000000000000885289888061091d888b8089850160409194939294606082019573ffffffffffffffffffffffffffffffffffffffff80921683521660208201520152565b03818c8a5af1978815610a185789986109f3575b508089106109be57508087106109895750507fd9f35a37b64d95edfd8f26adf130ce45f3e9ddf3c7ab8c1fb7224727a339a98e9087519416938061028088883396846040919493926060820195825260208201520152565b60449250868951927f9cdffc8e0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b826044918a8c51927f0a4439e60000000000000000000000000000000000000000000000000000000084528301526024820152fd5b909750610a0e919850893d8b116102f2576102e081836126be565b979097968a610931565b8a513d8b823e3d90fd5b610a2d913388612c12565b89846108b9565b503461035157610a43366125f7565b90959293919473ffffffffffffffffffffffffffffffffffffffff90818616928551987f2c8ce6bc000000000000000000000000000000000000000000000000000000008a52606098898b8d81895afa918215610ce757849b8593610cc1575b5088517f794052f3000000000000000000000000000000000000000000000000000000008152308e820152610120929083816024818c5afa938415610cb75790610afa949392918894610c98575b50504292612807565b9a92509b90848110610c6357509089918c8281610c4e575b50505081610c39575b5087517f156e29f600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8816818e01908152602081018d905260408101929092529150899082908190606001038186895af1988915610c2f578399610c0e575b50508710610be257506107429596975083519216917f9334566f6358cd68e33d423fb1c9119c6837e3a2a7a8affaaa5020ed06aec0693391806107248a898d846040919493926060820195825260208201520152565b8060018a7f4e487b71000000000000000000000000000000000000000000000000000000006024945252fd5b610c25929950803d1061079c5761078a81836126be565b5050963880610b8c565b87513d85823e3d90fd5b610c469286339116612c12565b388781610b1b565b610c5b9289339116612c12565b388c82610b12565b8d856044928c51927f6a1dbf1b0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b610caf929450803d106108525761084381836126be565b913880610af1565b8b513d89823e3d90fd5b909250610cdc919b508a3d8c116103405761032f81836126be565b509a909a9138610aa3565b88513d86823e3d90fd5b5091346104e457610d01366125f7565b9073ffffffffffffffffffffffffffffffffffffffff95868516946060895180937f2c8ce6bc00000000000000000000000000000000000000000000000000000000825281895afa918215610de357918a8692610d999695947fc8437d84f52d1e20cc82487e336feadb2d39ede00af7711b6a58abf39392328f9b9c9d9293610dbf575b50610d938433848f166130ed565b8961320c565b875192835260208301829052604083018190529095909493169233918060608101610280565b909250610dda915060603d81116103405761032f81836126be565b92905038610d85565b89513d8c823e3d90fd5b50903461035457610dfd36612566565b9291958594919451977f2c8ce6bc00000000000000000000000000000000000000000000000000000000895273ffffffffffffffffffffffffffffffffffffffff938481169560608b84818a5afa9a8b1561121557849b6111f2575b5088517f794052f300000000000000000000000000000000000000000000000000000000815230848201526101209081816024818c5afa9182156108595786926111d5575b50507f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8b116111d1578a156111a9576020810151610edc908c612af7565b9b8a82019c8d51610eec91612b36565b908d8d8451610efa91612af7565b9051610f0591612b36565b9d82158f816111a0575b50611178578e818f610f2590610f2e945161318a565b9052845161318a565b8352610f3e82602085015161318a565b60208401528682126104dc57868e126104dc5790610f6b610f63610f73959493613057565b933690612f7b565b924292615264565b509087610f80838d612f4d565b1061113857899a50978489610f9a8c849d9b9c338c612c12565b610ffa83519d8e9384937ff6b911bc00000000000000000000000000000000000000000000000000000000855288850160409194939294606082019573ffffffffffffffffffffffffffffffffffffffff80921683521660208201520152565b0381868a5af1801561112e5761105698999a849161110f575b508a8051858152611023816126a2565b8151809b81927f5b709f17000000000000000000000000000000000000000000000000000000008352868a898501612fe8565b0381878b5af19889156102f95784996110e8575b509061107591612f4d565b9788106110bc575050865193845285602085015216917fac97b87f5422fa3beec99bff8f336310d8ebc7d33d909b7d534cd7c72f61e871863392a482519182526020820152f35b9060016024927f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b61107592919950611105908c8d3d106102f2576102e081836126be565b905098909161106a565b61112691508b3d8d116102f2576102e081836126be565b905038611013565b89513d85823e3d90fd5b509086886111486044948d612f4d565b9051927f9cdffc8e0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b868d517fccbf5468000000000000000000000000000000000000000000000000000000008152fd5b9050158f610f0f565b838a517f25daaec3000000000000000000000000000000000000000000000000000000008152fd5b8480fd5b6111eb9250803d106108525761084381836126be565b3880610e9e565b61120b919b5060603d81116103405761032f81836126be565b9150509938610e59565b89513d86823e3d90fd5b5091346104e4577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc926080843601126103515761125a61251b565b611262612543565b916064359567ffffffffffffffff87116103545760c0908786019736030112610351578451917f2c8ce6bc000000000000000000000000000000000000000000000000000000009485845273ffffffffffffffffffffffffffffffffffffffff90818616936060868381885afa958615611725578196611702575b508260443596876116f1575b16906112f58b83613e13565b9080998b51997f2f13b60c000000000000000000000000000000000000000000000000000000008b5260209a8b8188818d5afa9081156116e757908e929185916116ba575b501561158657505190815260608186818b5afa90811561157c57908691839161155a575b50168b51927ff6b911bc0000000000000000000000000000000000000000000000000000000084528c84806113c28d86868c850160409194939294606082019573ffffffffffffffffffffffffffffffffffffffff80921683521660208201520152565b0381868d5af1938415611550578b918e89928697611529575b5090856024925195869485937fbcb7ea5d000000000000000000000000000000000000000000000000000000008552168b8401525af191821561151e5780926114ec575b505061142a91612f4d565b915b600183106114b65750916114688a6114709a9b937f3fff08e8137afe866dce7ced13ddc12d684db61b80b0ac5cb9e54961c9dd8a219587613b6f565b988992612f5a565b16946114a98a5192839233968460409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b0390a48351928352820152f35b604490838b51917f0a4439e600000000000000000000000000000000000000000000000000000000835282015260016024820152fd5b9091508982813d8311611517575b61150481836126be565b8101031261035157505161142a3861141f565b503d6114fa565b8c51903d90823e3d90fd5b8197506115468791602494933d8b116102f2576102e081836126be565b50979192506113db565b8d513d85823e3d90fd5b611573915060603d6060116103405761032f81836126be565b9150503861135e565b8c513d84823e3d90fd5b81517ff6b911bc00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff80871689830190815292166020830152604082018c9052949c50929392909150829081906060010381858b5af1801561168d578b9083928491611697575b5081519b848d5261160e8d6126a2565b61164383519d8e9384937f29910b110000000000000000000000000000000000000000000000000000000085528a8501612fe8565b0381858b5af1998a1561168d57829a611668575b509061166291612f4d565b9161142c565b611685919a5061166292508b3d8d116102f2576102e081836126be565b999091611657565b8b513d84823e3d90fd5b9050816116b19293503d84116102f2576102e081836126be565b919091386115fe565b6116da91508d803d106116e0575b6116d281836126be565b810190612c83565b3861133a565b503d6116c8565b8e513d86823e3d90fd5b6116fd888a338a612c12565b6112e9565b61171c91965060603d6060116103405761032f81836126be565b505094386112dd565b508851903d90823e3d90fd5b5082346103545761174136612566565b929473ffffffffffffffffffffffffffffffffffffffff9491929492838716948951907f2c8ce6bc000000000000000000000000000000000000000000000000000000008252606091828186818b5afa908115611a3c578b908c92611a1a575b50898b81611a05575b5050508b51907f794052f300000000000000000000000000000000000000000000000000000000825230868301526101209182816024818d5afa9283156119fb57918b916118119594938f946119d4575b5050610f6361180991613057565b9242926153de565b50508a8181519a8c8c526118248c6126a2565b61185983519c8d9384937f5b709f170000000000000000000000000000000000000000000000000000000085528a8501612fe8565b03818d8b5af19889156119ca578a908c8c9b611999575b50509180916118826118dc948b61304a565b8d5194859283927f156e29f60000000000000000000000000000000000000000000000000000000084528a8a850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b03818d8b5af1998a1561198e579961196d575b5050808810611938575050865193845285602085015216917fb51950711c9b21dc7888d41f68a19540231ffb5f0d19d8f75cbccaf90ffa7fa5863392a482519182526020820152f35b60449250878951927f6a1dbf1b0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b611984929950803d1061079c5761078a81836126be565b50509689806118ef565b8b51903d90823e3d90fd5b6118829b508493916118dc959350816119bd92903d106102f2576102e081836126be565b9b9092505091928c611870565b8b513d8c823e3d90fd5b611809929450610f6391816119f492903d106108525761084381836126be565b93916117fb565b8e513d8f823e3d90fd5b611a12928a339116612c12565b8c898b6117aa565b9050611a339150833d85116103405761032f81836126be565b9190508d6117a1565b8c513d8d823e3d90fd5b50823461035457611a5636612566565b929473ffffffffffffffffffffffffffffffffffffffff9491929492838716948951977f2c8ce6bc000000000000000000000000000000000000000000000000000000008952606091828a86818b5afa8015611a3c578b9a8c91611ce8575b508c517f794052f30000000000000000000000000000000000000000000000000000000081523087820152610120919082816024818e5afa928315611cdd57918c918f93611b199695611cb6575b5050610f63611b1191613057565b924292613ed7565b505098888281611ca1575b5050508a898151928c8452611b38846126a2565b611b6d835194859384937f29910b110000000000000000000000000000000000000000000000000000000085528a8501612fe8565b03818d8b5af19889156119ca578a918c8c9b611c6e575b5050918091611b96611bf1948b61304a565b908d5194859283927f156e29f60000000000000000000000000000000000000000000000000000000084528a8a850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b03818d8b5af1998a1561198e5799611c4d575b5050808810611938575050865193845285602085015216917fc87b85efc5055ef177e0092af0d4e624fff4b1d57db748857f65e4b7e4a28a36863392a482519182526020820152f35b611c64929950803d1061079c5761078a81836126be565b5050968980611c04565b849350611bf194929b50611b969181611c9292903d106102f2576102e081836126be565b9190919b92505091928c611b84565b611cae9289339116612c12565b8b8882611b24565b611b11929450610f639181611cd692903d106108525761084381836126be565b9391611b03565b508e513d8f823e3d90fd5b9050611d02919a50833d85116103405761032f81836126be565b9a9150998d611ab5565b508290346103515760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261035157611d4661251b565b91611d4f612543565b90604435906064359473ffffffffffffffffffffffffffffffffffffffff90818516928461210c575b868951967f2f13b60c000000000000000000000000000000000000000000000000000000008852602097888185818a5afa9081156121025783916120e5575b5015611fba575089517f2c8ce6bc0000000000000000000000000000000000000000000000000000000081526060818481895afa90811561168d579085918391611f99575b5016908a51917ff6b911bc0000000000000000000000000000000000000000000000000000000083528b8380611e618b858a8a850160409194939294606082019573ffffffffffffffffffffffffffffffffffffffff80921683521660208201520152565b0381858b5af192831561157c5782918a918e95611f76575b50602483949551809481937fbcb7ea5d0000000000000000000000000000000000000000000000000000000083528b8b168a8401525af191821561151e578092611f44575b5050611ec991612f4d565b975b808910611f0f5750508751938452868585015216917fd31f02c44717b409d13b92ec9d2eaf1427fb4e63f85f4777f1458fb8d9387761873392a48351928352820152f35b60449250888a51927f0a4439e60000000000000000000000000000000000000000000000000000000084528301526024820152fd5b9091508882813d8311611f6f575b611f5c81836126be565b81010312610351575051611ec98c611ebe565b503d611f52565b839450611f91602491873d89116102f2576102e081836126be565b509450611e79565b611fb1915060603d81116103405761032f81836126be565b9150508c611dfc565b8a517ff6b911bc00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff80861685830190815292166020830152604082018890529a99985089908b908190606001038184895af1998a156117255789612078999a9b839284916120c2575b50815190848252612045826126a2565b82519b8c9283927f29910b1100000000000000000000000000000000000000000000000000000000845289898501612fe8565b0381858a5af198891561168d57829961209d575b509061209791612f4d565b97611ecb565b6120ba91995061209792508b3d8d116102f2576102e081836126be565b98909161208c565b9050816120dc9293503d84116102f2576102e081836126be565b9190918d612035565b6120fc9150893d8b116116e0576116d281836126be565b8c611db7565b8c513d85823e3d90fd5b61211885873387612c12565b611d78565b9390506101207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc9181833601126104e05761215661251b565b9261215f612543565b9160a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c36011261251757610104359267ffffffffffffffff928385116125135760c09085360301126104dc577f2c8ce6bc00000000000000000000000000000000000000000000000000000000895273ffffffffffffffffffffffffffffffffffffffff928382169560609a8b8186818b5afa9081156119ca57918a8c9d9492828b839f9e968b9a999794936124e8575b50612226602493948d8b019b8c911689613713565b9e51928380927f794052f3000000000000000000000000000000000000000000000000000000008252308c8301525afa928315611cdd578e936124c3575b505061226f90613057565b8d519260a084019081118482101761249757928e928d6122b9936123019686526064358452608435602085015260a4358685015260c4358985015260e435608085015242926153de565b5050928c848351928284526122cd846126a2565b8451958694859384937f5b709f170000000000000000000000000000000000000000000000000000000085528c8501612fe8565b03918c5af1998a15611a3c578b918d8d9c612465575b50509161232a849392612384959361304a565b8d5194859283927f156e29f60000000000000000000000000000000000000000000000000000000084528d89850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b03818d8b5af1998a1561198e5799612444575b505060443580891061240f575050906123d07ff83776e5b667a2b471f92ddfd482749c61b5328b832d375097638c2c08818f3b92612f5a565b610280888a519384931697602433970135908460409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b60449250888a51927f6a1dbf1b0000000000000000000000000000000000000000000000000000000084528301526024820152fd5b61245b929950803d1061079c5761078a81836126be565b5050963880612397565b8594929c5061238495935061232a918161248a92903d106102f2576102e081836126be565b9c9294509294508d612317565b60248e6041897f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b61226f92935090816124e092903d106108525761084381836126be565b919038612264565b61222694506024935061250790893d8b116103405761032f81836126be565b95919050949350612211565b8780fd5b8580fd5b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361253e57565b600080fd5b6024359073ffffffffffffffffffffffffffffffffffffffff8216820361253e57565b6101207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc82011261253e5773ffffffffffffffffffffffffffffffffffffffff91600435838116810361253e5792602435908116810361253e57916044359160a07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7c60643593011261253e57608490565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc60a091011261253e5773ffffffffffffffffffffffffffffffffffffffff90600435828116810361253e5791602435908116810361253e5790604435906064359060843590565b67ffffffffffffffff811161267357604052565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6020810190811067ffffffffffffffff82111761267357604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761267357604052565b9081606091031261253e5780519173ffffffffffffffffffffffffffffffffffffffff92838116810361253e57926020830151818116810361253e57604090930151908116810361253e5790565b8091610120928391031261253e5760405191820182811067ffffffffffffffff82111761267357604052805182526020810151602083015260408101516040830152606081015173ffffffffffffffffffffffffffffffffffffffff8116810361253e5760608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e0830152610100809101519082015290565b9081606091031261253e578051916040602083015192015190565b919293907f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80821161253e5780851161253e5760009582158015612a9d575b612a735760a08501511115612a49576040840195865180156000146129cb5750506128718583612af7565b906000821261253e57600060038311156129bc57508160019080821c82810180911161296d5791905b84831061299c575050505b811161253e577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc18810190811360011661296d57946103e89194935b600087131561294357602081016128f8878251612bf6565b9052612905858251612bf6565b905261291b6129148388612bf6565b8251612bf6565b90526000811261253e57936000811261253e57926000811261253e57916000811261253e5790565b60046040517fccbf5468000000000000000000000000000000000000000000000000000000008152fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b909193506129b3846129ae8184612f43565b612f4d565b821c919061289a565b91156128a557600191506128a5565b869792506129df906129e792949697612af7565b865190612b36565b6129f2825186612af7565b94612a036020880196875190612b36565b80831215612a2b575050612a1d81612a2592989651612af7565b825190612b36565b946128e0565b612a1d91985080979650612a43925097968651612af7565b936128e0565b60046040517fb2094b59000000000000000000000000000000000000000000000000000000008152fd5b60046040517f25daaec3000000000000000000000000000000000000000000000000000000008152fd5b508515612846565b90670de0b6b3a76400009182810292818405149015171561296d57565b9081600003918083057fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff149015171561296d57565b8181029291600082127f800000000000000000000000000000000000000000000000000000000000000082141661296d57818405149015171561296d57565b8115612b8b577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82147f800000000000000000000000000000000000000000000000000000000000000082141661296d570590565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b90670de0b6b3a76400006000838203931281841281169184139015161761296d57565b8181039291600013801582851316918412161761296d57565b9190916000838201938412911290801582169115161761296d57565b6040517f23b872dd00000000000000000000000000000000000000000000000000000000602082015273ffffffffffffffffffffffffffffffffffffffff9283166024820152929091166044830152606480830193909352918152612c8191612c7c6084836126be565b612c9b565b565b9081602091031261253e5751801515810361253e5790565b73ffffffffffffffffffffffffffffffffffffffff1690604051906040820182811067ffffffffffffffff821117612673576040526020928383527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656484840152803b15612dcb5760008281928287612d229796519301915af1612d1c612e29565b90612ee5565b80519081612d2f57505050565b8280612d3f938301019101612c83565b15612d475750565b608490604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152fd5b606484604051907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152fd5b3d15612e82573d9067ffffffffffffffff82116126735760405191612e7660207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601846126be565b82523d6000602084013e565b606090565b919082519283825260005b848110612ed15750507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8460006020809697860101520116010190565b602081830181015184830182015201612e92565b90919015612ef1575090565b815115612f015750805190602001fd5b612f3f906040519182917f08c379a0000000000000000000000000000000000000000000000000000000008352602060048401526024830190612e87565b0390fd5b8115612b8b570490565b9190820180921161296d57565b3573ffffffffffffffffffffffffffffffffffffffff8116810361253e5790565b91908260a091031261253e5760405160a0810181811067ffffffffffffffff821117612673576040526080808294803584526020810135602085015260408101356040850152606081013560608501520135910152565b919082604091031261253e576020825192015190565b61301a939273ffffffffffffffffffffffffffffffffffffffff60609316825260208201528160408201520190612e87565b90565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820191821161296d57565b9190820391821161296d57565b602073ffffffffffffffffffffffffffffffffffffffff600460009360405194859384927f1d52edc4000000000000000000000000000000000000000000000000000000008452165af19081156130e1576000916130b3575090565b906020823d82116130d9575b816130cc602093836126be565b8101031261035157505190565b3d91506130bf565b6040513d6000823e3d90fd5b90919073ffffffffffffffffffffffffffffffffffffffff168061317457509050340361311657565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f657468206d69736d6174636800000000000000000000000000000000000000006044820152fd5b8161317f575b505050565b612c81923091612c12565b9080821261319b5761301a91612bdd565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600860248201527f6e656761746976650000000000000000000000000000000000000000000000006044820152fd5b8181029291811591840414171561296d57565b969496959290939573ffffffffffffffffffffffffffffffffffffffff8086169260409485517f794052f30000000000000000000000000000000000000000000000000000000081523060048201526101209081816024818a5afa9182156134df576000926134c2575b505061328183613057565b81516000811261253e57613295908d6131f9565b8251926000841261253e5760200151946000861261253e5760009b6132fe8f96896132e7613304966132e160449a670de0b6b3a76400006132da60209f9c879d6131f9565b0490612f4d565b90612f43565b9a8b92169416976132f9828a876134ea565b61304a565b916134ea565b8751998a9384927fdb74aa15000000000000000000000000000000000000000000000000000000008452896004850152881660248401525af19586156134b75760009661347e575b506133bf9260609260006133628994859c61304a565b918751968795869485937f156e29f60000000000000000000000000000000000000000000000000000000085526004850160409194939273ffffffffffffffffffffffffffffffffffffffff606083019616825260208201520152565b03925af190811561347357600091613453575b50809680821061341f5750508183106133ea57505050565b6044935051917fa59b8c3100000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b60449251917f6a1dbf1b00000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b61346b915060603d811161079c5761078a81836126be565b5050386133d2565b82513d6000823e3d90fd5b909394956020823d82116134af575b8161349a602093836126be565b810103126103515750519493926133bf61334c565b3d915061348d565b84513d6000823e3d90fd5b6134d89250803d106108525761084381836126be565b3880613276565b88513d6000823e3d90fd5b821561317a5773ffffffffffffffffffffffffffffffffffffffff9081169081613587575050600080809381935af1613521612e29565b501561352957565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f6574682073656e64206661696c656400000000000000000000000000000000006044820152fd5b604093919351927fa9059cbb000000000000000000000000000000000000000000000000000000006020850152166024830152604482015260448152608081019181831067ffffffffffffffff84111761267357612c8192604052612c9b565b9035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff818136030182121561253e570190565b9173ffffffffffffffffffffffffffffffffffffffff80921683526020830152606060408301528235600481101561253e576060830152602083013590811680910361253e57608082015260408201357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18336030181121561253e5782016020813591019267ffffffffffffffff821161253e57813603841361253e57606090608060a08501528260e08501528261010095868601376000858486010152013580151580910361253e5760c0830152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016010190565b9060a083019261372384826135e7565b93600094356004811015612517578061389f5750509081613745602093612f5a565b61375584830135809233906130ed565b935b604082019173ffffffffffffffffffffffffffffffffffffffff80948161377d86612f5a565b1661389657606088935b01948261379387612f5a565b16156138315750506137a6606494612f5a565b1660405196879586947fb27670700000000000000000000000000000000000000000000000000000000086521660048501526024840152600160448401525af191821561382557916137f7575b5090565b90506020813d821161381d575b81613811602093836126be565b8101031261253e575190565b3d9150613804565b604051903d90823e3d90fd5b6084955061383e90612f5a565b9782604051998a9889977f20e8c565000000000000000000000000000000000000000000000000000000008952166004880152166024860152604485015260016064850152165af191821561382557916137f7575090565b60608993613787565b6003036138e9575090816138b4602093612f5a565b6138c484830135809233906130ed565b6138e3816138d184612f5a565b6138dd60408601612f5a565b90613ab0565b93613757565b73ffffffffffffffffffffffffffffffffffffffff8061390884612f5a565b166139eb5760208301353403613116575b8061392660808501612f5a565b169061393184612f5a565b166139e4576020830135915b61395061394985612f5a565b91856135e7565b92823b15612513579161399b939188936040518096819582947f2bdb823c00000000000000000000000000000000000000000000000000000000845260208b0135906004850161361a565b03925af180156139d9576139c3575b5090816138e36139be604060209501612f5a565b613a29565b936139d1602093929561265f565b9390916139aa565b6040513d87823e3d90fd5b859161393d565b806139f584612f5a565b16613a0260808501612f5a565b60208501359081613a16575b505050613919565b613a21923390612c12565b388080613a0e565b60009073ffffffffffffffffffffffffffffffffffffffff1680613a4d5750504790565b6020602491604051928380927f70a082310000000000000000000000000000000000000000000000000000000082523060048301525afa918215613825578092613a9657505090565b9091506020823d82116130d957816130cc602093836126be565b73ffffffffffffffffffffffffffffffffffffffff9190821680613b1e575016803b1561253e576000906004604051809481937fd0e30db00000000000000000000000000000000000000000000000000000000083525af180156130e157613b155750565b612c819061265f565b92915050813b1561253e576000916024839260405194859384927f2e1a7d4d00000000000000000000000000000000000000000000000000000000845260048401525af180156130e157613b155750565b93929360a08501613b8081876135e7565b35600481101561253e5780613be4575050602092613b9f928692613d01565b925b0135808310613bad5750565b82604491604051917fc5b5576d00000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b9195929391600303613c305750613c0282613c2b9260209530613d01565b8095613c1d82613c1460408701612f5a565b6138dd87612f5a565b613c2684612f5a565b6134ea565b613ba1565b90613c67613c618473ffffffffffffffffffffffffffffffffffffffff936080820197613c5c89612f5a565b613d01565b94612f5a565b16613c7e613c7760408501612f5a565b92846135e7565b90803b1561253e57613cc49460008094604051978895869485937f2bdb823c0000000000000000000000000000000000000000000000000000000085526004850161361a565b03925af19182156130e157602092613cf2575b50613c2b613ce76139be83612f5a565b8095613c2684612f5a565b613cfb9061265f565b38613cd7565b9190926060810173ffffffffffffffffffffffffffffffffffffffff94859283613d2a84612f5a565b1615613d9a575050613d3b90612f5a565b1692604051927f83f5b766000000000000000000000000000000000000000000000000000000008452166004830152602482015260208160848160008096816044840152600160648401525af1918215613825578092613a9657505090565b60a492509083613db06040602097989401612f5a565b60405197889687957f769f8e5d0000000000000000000000000000000000000000000000000000000087521660048601526024850152166044830152600096879182606485015260016084850152165af1918215613825578092613a9657505090565b9060600173ffffffffffffffffffffffffffffffffffffffff613e3582612f5a565b16156137f35761301a9150612f5a565b15613e4c57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f6e6f206578697374696e67206c700000000000000000000000000000000000006044820152fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811461296d5760010190565b9193949092613ee79084846141bb565b93604086015115614009575b60005b6060870151811015613fdf57613f0c8188615181565b908488613f23613f1b85614dc3565b898b85614e45565b9190613f6f6080613f65613f55613f4e613f3e8c8b51612f4d565b976132f9886020809d015161304a565b96866131f9565b95613f608b8d61304a565b6131f9565b9501518585614df0565b613fcd57505011613f9657506001820180921161296d57613f91918852613eaa565b613ef6565b917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810190811161296d57613f9192890152613eaa565b9a509a50505050509250509150929190565b60046040517ffa711db2000000000000000000000000000000000000000000000000000000008152fd5b6020860151600061401d602088015161301d565b80820361406857508082101561406157505b8181101561405a575b6020870152614046866151e9565b61405560408401511515613e45565b613ef3565b5080614038565b905061402f565b6140728183612f4d565b906001820180921161296d5786516140918360011c60208c0151612bdd565b9061409f818560011c612bf6565b60008313806141b1575b1561415357670de0b6b3a76400006141298d61412461410f61410a6000986140ff6141046140ec8e6140e36141309d60208b015190612bf6565b9060011c612af7565b6140ff6140f9858d612af7565b91612aa5565b614546565b98612aa5565b614932565b604061411b845161452c565b93015195612bdd565b612af7565b0590612bdd565b121561414857506141439060011c61301d565b61401d565b915060011c9061401d565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f696e76616c6964207074546f4d61726b657400000000000000000000000000006044820152fd5b50600081136140a9565b92919260409081516080810181811067ffffffffffffffff82111761267357835260009182825260208201908382528483018481526060840196858852849960a0840181815111156144525790614212915161304a565b936080840151976301e1338096878a0299808b05891490151715614425577f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff998a8811614421578761426391612b36565b898113156143f15781526020860151898112156143e9577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff905b8a8113156143db575b6142ba670de0b6b3a76400009687926131f9565b04908b821161439957906142cd91612af7565b808452865190811580156143d3575b61439d575050855191886142fa896101008a015196519451966131f9565b048b81116143995761430b90614550565b94851261436957509261434460c095936140ff61433f61433a866140ff6140f96143539e9d9b61434a9a612bf6565b61447b565b612aa5565b90612bdd565b905201516131f9565b04918211610351575061436590614550565b9052565b8460249151907fca78c8a40000000000000000000000000000000000000000000000000000000082526004820152fd5b8a80fd5b604492508351917fb1c4aefb00000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b5080156142dc565b6143e490614dc3565b6142a6565b60019061429d565b6024908351907f1ca418760000000000000000000000000000000000000000000000000000000082526004820152fd5b8980fd5b6024897f4e487b710000000000000000000000000000000000000000000000000000000081526011600452fd5b600489517fb2094b59000000000000000000000000000000000000000000000000000000008152fd5b670de0b6b3a7640000811461449d5761410a816140ff6140f961301a94612bba565b60046040517fa9c8b14d000000000000000000000000000000000000000000000000000000008152fd5b156144ce57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f496e76616c6964206578706f6e656e74000000000000000000000000000000006044820152fd5b8015612b8b576ec097ce7bc90715b34b9f10000000000590565b8115612b8b570590565b7ffffffffffffffffffffffffffffffffffffffffffffffffdc702bd3a30fc00008112158061491f575b614583906144c7565b6000811261490a576064906806f05b59d3b200000081126148a7577ffffffffffffffffffffffffffffffffffffffffffffffff90fa4a62c4e0000000168056bc75e2d6310000082770195e54c5dd42177f53a27172fa9ec630262827000000000925b0280829168ad78ebc5ac6200000081121561486b575b50806856bc75e2d63100000084921215614831575b682b5e3af16b188000008112156147f9575b6815af1d78b58c4000008112156147c1575b680ad78ebc5ac620000081121561478a575b81811215614753575b6802b5e3af16b188000081121561471c575b68015af1d78b58c400008112156146e5575b60028282800205056003838383020505600484848302050560058585830205056006868683020505600787878302050590600888888402050592600989898602050594600a8a8a8802050596600b8b8b8a02050598600c8c8c8c0205059a0101010101010101010101010205020590565b6806f5f17757889379377ffffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c000083920193020591614674565b6808f00f760a4b2db55d7ffffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e78000083920193020591614662565b680ebc5fb417461211107ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf0000083920193020591614650565b68280e60114edb805d037ffffffffffffffffffffffffffffffffffffffffffffffff5287143a539e0000083920193020591614647565b690127fa27722cc06cc5e27fffffffffffffffffffffffffffffffffffffffffffffffea50e2874a73c0000083920193020591614635565b693f1fce3da636ea5cf8507fffffffffffffffffffffffffffffffffffffffffffffffd4a1c50e94e780000083920193020591614623565b6b02df0ab5a80a22c61ab5a7007fffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf00000083920193020591614611565b6e01855144814a7ff805980ff008400092507fffffffffffffffffffffffffffffffffffffffffffffff5287143a539e000000019050826145fc565b6803782dace9d900000081126148f7577ffffffffffffffffffffffffffffffffffffffffffffffffc87d25316270000000168056bc75e2d63100000826b1425982cf597cd205cef7380926145e6565b68056bc75e2d63100000826001926145e6565b61491690600003614550565b61301a9061452c565b5068070c1cc73b00c8000081131561457a565b6000811315614a155780670c7d713b49da00001280614a04575b156149fb57670de0b6b3a7640000906ec097ce7bc90715b34b9f10000000009061499f908302828101907fffffffffffffffffffffffffffffffffff3f68318436f8ea4cb460f000000000018302614546565b9080828002059181838202058284820205838582020591848684020593858786020595808888020597880205600f900596600d900595600b900594600990059360079005926005900591600390050101010101010160011b0590565b61301a90614a73565b50670f43fc2c04ee0000811261494c565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f6f7574206f6620626f756e6473000000000000000000000000000000000000006044820152fd5b670de0b6b3a76400008112614dac5760649060007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c0000000000000821215614d81575b73011798004d755d3c8bc8e03204cf44619e000000821215614d60575b8202908202816e01855144814a7ff805980ff00840008281811215614d39575b5050506b02df0ab5a80a22c61ab5a70080821215614d19575b50693f1fce3da636ea5cf85080821215614cf9575b50690127fa27722cc06cc5e280821215614cd9575b5068280e60114edb805d0380821215614cb9575b50680ebc5fb4174612111080821215614ca2575b506808f00f760a4b2db55d80821215614c82575b506806f5f177578893793780821215614c62575b506806248f33704b28660380821215614c43575b506805c548670b9510e7ac80821215614c24575b50614be368056bc75e2d6310000091827ffffffffffffffffffffffffffffffffffffffffffffffffa9438a1d29cf00000818301920102614546565b9080828002059181838202058284820205916003600560076009600b888a89020598808b8b02059a8b0205059805960594059205010101010160011b010590565b68056bc75e2d631000006756bc75e2d631000092020591019038614ba7565b68056bc75e2d6310000067ad78ebc5ac62000092020591019038614b93565b68056bc75e2d6310000068015af1d78b58c4000092020591019038614b7f565b68056bc75e2d631000006802b5e3af16b188000092020591019038614b6b565b68056bc75e2d631000008092020591019038614b57565b68056bc75e2d63100000680ad78ebc5ac620000092020591019038614b43565b68056bc75e2d631000006815af1d78b58c40000092020591019038614b2f565b68056bc75e2d63100000682b5e3af16b1880000092020591019038614b1a565b68056bc75e2d631000006856bc75e2d63100000092020591019038614b05565b68056bc75e2d631000009192945068ad78ebc5ac6200000093500205910190388080614aec565b6b1425982cf597cd205cef7380909105906803782dace9d900000001614acc565b50770195e54c5dd42177f53a27172fa9ec63026282700000000090056806f05b59d3b2000000614aaf565b614db8614dbd9161452c565b614a73565b60000390565b7f8000000000000000000000000000000000000000000000000000000000000000811461296d5760000390565b90670de0b6b3a76400009083820382811161296d5782614e118592846131f9565b0411159384614e22575b5050505090565b9091809394500180831161296d57614e39916131f9565b04101538808080614e1b565b9391928451602083015190614e728451916140ff6140f9604088015195614e6c888561318a565b93612bf6565b670d529ae9e86000008082136150a95750614e9c92916140ff61433f614e979361447b565b612bf6565b670de0b6b3a764000090818112615051576060614ec4614ebf836140ff87612aa5565b612ac2565b94015190600080941360001461508257816140ff614ee192612aa5565b828112615051575081614efe614ef860e093612bba565b86612af7565b05965b0151917f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9283811161035457876064614f3d614f449383612af7565b0595612bdd565b918183128015615036571561502e577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff925b82811315615020575b818102918183041490151715614ff35786614f9991612f4d565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8101908111614ff35786614fcd91612f43565b9283116103515750614fe661301a9392614fed92612af7565b95856150e0565b936150e0565b6024827f4e487b710000000000000000000000000000000000000000000000000000000081526011600452fd5b61502990614dc3565b614f7f565b600192614f76565b50505061301a92915061504c614fed91866150e0565b614fe6565b602490604051907fca78c8a40000000000000000000000000000000000000000000000000000000082526004820152fd5b506150a3614ebf8261509e61509860e095612bba565b88612af7565b612b36565b96614f01565b60449250604051917ffc68d09e00000000000000000000000000000000000000000000000000000000835260048301526024820152fd5b6000821215615179577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff915b600081131561516a57905b670de0b6b3a76400009182810292818404149015171561296d5761513a91612f43565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811161253e5761301a91612af7565b61517390614dc3565b90615117565b60019161510c565b9015806151dc575b6151d55760208151910151808211156151c65760046040517ffa711db2000000000000000000000000000000000000000000000000000000008152fd5b6151cf91612f4d565b60011c90565b6040015190565b5060408101511515615189565b8051602082015191828211801561524f575b61520457505050565b6080612f3f9101516040519384937fb301af04000000000000000000000000000000000000000000000000000000008552600485016040919493926060820195825260208201520152565b50670de0b6b3a76400006080820151116151fb565b949093919261527660009186886141bb565b936040840151156153ab575b815b6060850151811015613fdf5761529a8186615181565b6152b16152a9828a8a8d614e45565b509190614dc3565b84811180159190615343576080890151826152ec575b50506152de575085526152d990613eaa565b615284565b985095505050509250509190565b909150670de0b6b3a76400009081038181116153165761530c90876131f9565b04111538806152c7565b6024887f4e487b710000000000000000000000000000000000000000000000000000000081526011600452fd5b5050507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810190811161537e5760208601526152d990613eaa565b6024847f4e487b710000000000000000000000000000000000000000000000000000000081526011600452fd5b6020840180516153bc895188615648565b808210156153d65750905b526153d1846151e9565b615282565b9050906153c7565b949093919460009560409586519360a0850185811067ffffffffffffffff82111761561b57885283855260209461543186820198848a528a830195865260609481868501526080978885019a8b526141bb565b928688518b810151156155d7575b50508a5b8851828101518210156155ae5789878a61547d8b8f956154668861547392615181565b80978d8c51915191614e45565b9291939093614dc3565b938a888751871161556d57866154b96154b36154cb976132f9846154c0986154aa613f60988a515161304a565b98510151612f4d565b8c6131f9565b985161304a565b955101518585614df0565b6155575750501161551f57600181018091116154f2578951526154ed90613eaa565b615443565b60248d7f4e487b710000000000000000000000000000000000000000000000000000000081526011600452fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81019081116154f25789518901526154ed90613eaa565b9e509e5050509850505050955050505050929190565b96505050505050507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9150019081116154f25789518901526154ed90613eaa565b60048c517ffa711db2000000000000000000000000000000000000000000000000000000008152fd5b01516155e583515186615648565b8082101561561457505b87895101526155fe88516151e9565b61560d8a835101511515613e45565b863861543f565b90506155ef565b60248a7f4e487b710000000000000000000000000000000000000000000000000000000081526041600452fd5b9061567661567c6156626060850151604086015190612bdd565b670de0b6b3a7640000928391865190612af7565b05614550565b92818401908282126000861290801582169115161761296d576156b660206156ad614129946140ff6156bc99612aa5565b92015185612bf6565b90612af7565b6103e79081810291818304149015171561296d576103e890049056fea2646970667358221220df1b330d60718102a79cfa0789da9939134a675d163f8ac5a989c157fe38218f64736f6c63430008110033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 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.