More Info
Private Name Tags
ContractCreator
TokenTracker
Multichain Info
No addresses found
Latest 25 from a total of 246 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Approve | 17570699 | 16 days ago | IN | 0 ETH | 0 | ||||
Approve | 17305487 | 23 days ago | IN | 0 ETH | 0 | ||||
Approve | 16991395 | 30 days ago | IN | 0 ETH | 0.00000006 | ||||
Approve | 16613524 | 39 days ago | IN | 0 ETH | 0.00000002 | ||||
Approve | 12489530 | 134 days ago | IN | 0 ETH | 0.00000018 | ||||
Approve | 12424552 | 136 days ago | IN | 0 ETH | 0.00000004 | ||||
Approve | 11970865 | 146 days ago | IN | 0 ETH | 0.00000005 | ||||
Approve | 9207165 | 210 days ago | IN | 0 ETH | 0.00000014 | ||||
Approve | 9047399 | 214 days ago | IN | 0 ETH | 0.00000007 | ||||
Approve | 7508579 | 249 days ago | IN | 0 ETH | 0.0000001 | ||||
Approve | 7437847 | 251 days ago | IN | 0 ETH | 0.00000004 | ||||
Approve | 7404869 | 252 days ago | IN | 0 ETH | 0.00000006 | ||||
Approve | 7240965 | 256 days ago | IN | 0 ETH | 0.00000009 | ||||
Approve | 6864993 | 264 days ago | IN | 0 ETH | 0.00000014 | ||||
Approve | 6447318 | 274 days ago | IN | 0 ETH | 0 | ||||
Approve | 6377019 | 276 days ago | IN | 0 ETH | 0 | ||||
Approve | 6234276 | 279 days ago | IN | 0 ETH | 0 | ||||
Approve | 6221839 | 279 days ago | IN | 0 ETH | 0.00000005 | ||||
Approve | 6191447 | 280 days ago | IN | 0 ETH | 0.00000004 | ||||
Approve | 6157779 | 281 days ago | IN | 0 ETH | 0.00000009 | ||||
Approve | 6036254 | 283 days ago | IN | 0 ETH | 0.0000001 | ||||
Approve | 5975314 | 285 days ago | IN | 0 ETH | 0.00000015 | ||||
Approve | 5910454 | 286 days ago | IN | 0 ETH | 0.0000004 | ||||
Approve | 5811824 | 289 days ago | IN | 0 ETH | 0.00000041 | ||||
Approve | 5778286 | 289 days ago | IN | 0 ETH | 0.00000003 |
Latest 1 internal transaction
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
1850303 | 380 days ago | Contract Creation | 0 ETH |
Loading...
Loading
This contract contains unverified libraries: OracleLib
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
PendleMarketV3
Compiler Version
v0.8.22+commit.4fc1097e
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.17; import "../../../interfaces/IPMarketV3.sol"; import "../../../interfaces/IPMarketFactoryV3.sol"; import "../../../interfaces/IPMarketSwapCallback.sol"; import "../../erc20/PendleERC20Permit.sol"; import "../PendleGauge.sol"; import "../OracleLib.sol"; /** Invariance to maintain: - Internal balances totalPt & totalSy not interfered by people transferring tokens in directly - address(0) & address(this) should never have any rewards & activeBalance accounting done. This is guaranteed by address(0) & address(this) check in each updateForTwo function */ contract PendleMarketV3 is PendleERC20Permit, PendleGauge, IPMarketV3 { using PMath for uint256; using PMath for int256; using MarketMathCore for MarketState; using SafeERC20 for IERC20; using PYIndexLib for IPYieldToken; using OracleLib for OracleLib.Observation[65535]; struct MarketStorage { int128 totalPt; int128 totalSy; // 1 SLOT = 256 bits uint96 lastLnImpliedRate; uint16 observationIndex; uint16 observationCardinality; uint16 observationCardinalityNext; // 1 SLOT = 144 bits } string private constant NAME = "Hyper Market"; string private constant SYMBOL = "HYPER-LPT"; IPPrincipalToken internal immutable PT; IStandardizedYield internal immutable SY; IPYieldToken internal immutable YT; address public immutable factory; uint256 public immutable expiry; int256 internal immutable scalarRoot; int256 internal immutable initialAnchor; uint80 internal immutable lnFeeRateRoot; MarketStorage public _storage; OracleLib.Observation[65535] public observations; modifier notExpired() { if (isExpired()) revert Errors.MarketExpired(); _; } constructor( address _PT, int256 _scalarRoot, int256 _initialAnchor, uint80 _lnFeeRateRoot, address _vePendle, address _gaugeController ) PendleERC20Permit(NAME, SYMBOL, 18) PendleGauge(IPPrincipalToken(_PT).SY(), _vePendle, _gaugeController) { PT = IPPrincipalToken(_PT); SY = IStandardizedYield(PT.SY()); YT = IPYieldToken(PT.YT()); (_storage.observationCardinality, _storage.observationCardinalityNext) = observations.initialize( uint32(block.timestamp) ); if (_scalarRoot <= 0) revert Errors.MarketScalarRootBelowZero(_scalarRoot); scalarRoot = _scalarRoot; initialAnchor = _initialAnchor; lnFeeRateRoot = _lnFeeRateRoot; expiry = IPPrincipalToken(_PT).expiry(); factory = msg.sender; } /** * @notice PendleMarket allows users to provide in PT & SY in exchange for LPs, which * will grant LP holders more exchange fee over time * @dev will mint as much LP as possible such that the corresponding SY and PT used do * not exceed `netSyDesired` and `netPtDesired`, respectively * @dev PT and SY should be transferred to this contract prior to calling * @dev will revert if PT is expired */ function mint( address receiver, uint256 netSyDesired, uint256 netPtDesired ) external nonReentrant notExpired returns (uint256 netLpOut, uint256 netSyUsed, uint256 netPtUsed) { MarketState memory market = readState(msg.sender); PYIndex index = YT.newIndex(); uint256 lpToReserve; (lpToReserve, netLpOut, netSyUsed, netPtUsed) = market.addLiquidity( netSyDesired, netPtDesired, block.timestamp ); // initializing the market if (lpToReserve != 0) { market.setInitialLnImpliedRate(index, initialAnchor, block.timestamp); _mint(address(1), lpToReserve); } _mint(receiver, netLpOut); _writeState(market); if (_selfBalance(SY) < market.totalSy.Uint()) revert Errors.MarketInsufficientSyReceived(_selfBalance(SY), market.totalSy.Uint()); if (_selfBalance(PT) < market.totalPt.Uint()) revert Errors.MarketInsufficientPtReceived(_selfBalance(PT), market.totalPt.Uint()); emit Mint(receiver, netLpOut, netSyUsed, netPtUsed); } /** * @notice LP Holders can burn their LP to receive back SY & PT proportionally * to their share of the market */ function burn( address receiverSy, address receiverPt, uint256 netLpToBurn ) external nonReentrant returns (uint256 netSyOut, uint256 netPtOut) { MarketState memory market = readState(msg.sender); _burn(address(this), netLpToBurn); (netSyOut, netPtOut) = market.removeLiquidity(netLpToBurn); if (receiverSy != address(this)) IERC20(SY).safeTransfer(receiverSy, netSyOut); if (receiverPt != address(this)) IERC20(PT).safeTransfer(receiverPt, netPtOut); _writeState(market); emit Burn(receiverSy, receiverPt, netLpToBurn, netSyOut, netPtOut); } /** * @notice Pendle Market allows swaps between PT & SY it is holding. This function * aims to swap an exact amount of PT to SY. * @dev steps working of this contract - The outcome amount of SY will be precomputed by MarketMathLib - Release the calculated amount of SY to receiver - Callback to msg.sender if data.length > 0 - Ensure exactPtIn amount of PT has been transferred to this address * @dev will revert if PT is expired * @param data bytes data to be sent in the callback (if any) */ function swapExactPtForSy( address receiver, uint256 exactPtIn, bytes calldata data ) external nonReentrant notExpired returns (uint256 netSyOut, uint256 netSyFee) { MarketState memory market = readState(msg.sender); uint256 netSyToReserve; (netSyOut, netSyFee, netSyToReserve) = market.swapExactPtForSy(YT.newIndex(), exactPtIn, block.timestamp); if (receiver != address(this)) IERC20(SY).safeTransfer(receiver, netSyOut); IERC20(SY).safeTransfer(market.treasury, netSyToReserve); _writeState(market); if (data.length > 0) { IPMarketSwapCallback(msg.sender).swapCallback(exactPtIn.neg(), netSyOut.Int(), data); } if (_selfBalance(PT) < market.totalPt.Uint()) revert Errors.MarketInsufficientPtReceived(_selfBalance(PT), market.totalPt.Uint()); emit Swap(msg.sender, receiver, exactPtIn.neg(), netSyOut.Int(), netSyFee, netSyToReserve); } /** * @notice Pendle Market allows swaps between PT & SY it is holding. This function * aims to swap SY for an exact amount of PT. * @dev steps working of this function - The exact outcome amount of PT will be transferred to receiver - Callback to msg.sender if data.length > 0 - Ensure the calculated required amount of SY is transferred to this address * @dev will revert if PT is expired * @param data bytes data to be sent in the callback (if any) */ function swapSyForExactPt( address receiver, uint256 exactPtOut, bytes calldata data ) external nonReentrant notExpired returns (uint256 netSyIn, uint256 netSyFee) { MarketState memory market = readState(msg.sender); uint256 netSyToReserve; (netSyIn, netSyFee, netSyToReserve) = market.swapSyForExactPt(YT.newIndex(), exactPtOut, block.timestamp); if (receiver != address(this)) IERC20(PT).safeTransfer(receiver, exactPtOut); IERC20(SY).safeTransfer(market.treasury, netSyToReserve); _writeState(market); if (data.length > 0) { IPMarketSwapCallback(msg.sender).swapCallback(exactPtOut.Int(), netSyIn.neg(), data); } // have received enough SY if (_selfBalance(SY) < market.totalSy.Uint()) revert Errors.MarketInsufficientSyReceived(_selfBalance(SY), market.totalSy.Uint()); emit Swap(msg.sender, receiver, exactPtOut.Int(), netSyIn.neg(), netSyFee, netSyToReserve); } /// @notice forces balances to match reserves function skim() external nonReentrant { MarketState memory market = readState(msg.sender); uint256 excessPt = _selfBalance(PT) - market.totalPt.Uint(); uint256 excessSy = _selfBalance(SY) - market.totalSy.Uint(); if (excessPt != 0) IERC20(PT).safeTransfer(market.treasury, excessPt); if (excessSy != 0) IERC20(SY).safeTransfer(market.treasury, excessSy); } /** * @notice redeems the user's reward * @return amount of reward token redeemed, in the same order as `getRewardTokens()` */ function redeemRewards(address user) external nonReentrant returns (uint256[] memory) { return _redeemRewards(user); } /// @notice returns the list of reward tokens function getRewardTokens() external view returns (address[] memory) { return _getRewardTokens(); } /*/////////////////////////////////////////////////////////////// ORACLE //////////////////////////////////////////////////////////////*/ function observe(uint32[] memory secondsAgos) external view returns (uint216[] memory lnImpliedRateCumulative) { return observations.observe( uint32(block.timestamp), secondsAgos, _storage.lastLnImpliedRate, _storage.observationIndex, _storage.observationCardinality ); } function increaseObservationsCardinalityNext(uint16 cardinalityNext) external nonReentrant { uint16 cardinalityNextOld = _storage.observationCardinalityNext; uint16 cardinalityNextNew = observations.grow(cardinalityNextOld, cardinalityNext); if (cardinalityNextOld != cardinalityNextNew) { _storage.observationCardinalityNext = cardinalityNextNew; emit IncreaseObservationCardinalityNext(cardinalityNextOld, cardinalityNextNew); } } /*/////////////////////////////////////////////////////////////// READ/WRITE STATES //////////////////////////////////////////////////////////////*/ /** * @notice read the state of the market from storage into memory for gas-efficient manipulation */ function readState(address router) public view returns (MarketState memory market) { market.totalPt = _storage.totalPt; market.totalSy = _storage.totalSy; market.totalLp = totalSupply().Int(); uint80 overriddenFee; (market.treasury, overriddenFee, market.reserveFeePercent) = IPMarketFactoryV3(factory).getMarketConfig( address(this), router ); market.lnFeeRateRoot = overriddenFee == 0 ? lnFeeRateRoot : overriddenFee; market.scalarRoot = scalarRoot; market.expiry = expiry; market.lastLnImpliedRate = _storage.lastLnImpliedRate; } /// @notice write back the state of the market from memory to storage function _writeState(MarketState memory market) internal { uint96 lastLnImpliedRate96 = market.lastLnImpliedRate.Uint96(); int128 totalPt128 = market.totalPt.Int128(); int128 totalSy128 = market.totalSy.Int128(); (uint16 observationIndex, uint16 observationCardinality) = observations.write( _storage.observationIndex, uint32(block.timestamp), _storage.lastLnImpliedRate, _storage.observationCardinality, _storage.observationCardinalityNext ); _storage.totalPt = totalPt128; _storage.totalSy = totalSy128; _storage.lastLnImpliedRate = lastLnImpliedRate96; _storage.observationIndex = observationIndex; _storage.observationCardinality = observationCardinality; emit UpdateImpliedRate(block.timestamp, market.lastLnImpliedRate); } function getNonOverrideLnFeeRateRoot() external view returns (uint80) { return lnFeeRateRoot; } /*/////////////////////////////////////////////////////////////// TRIVIAL FUNCTIONS //////////////////////////////////////////////////////////////*/ function readTokens() external view returns (IStandardizedYield _SY, IPPrincipalToken _PT, IPYieldToken _YT) { _SY = SY; _PT = PT; _YT = YT; } function isExpired() public view returns (bool) { return MiniHelpers.isCurrentlyExpired(expiry); } /*/////////////////////////////////////////////////////////////// PENDLE GAUGE - RELATED //////////////////////////////////////////////////////////////*/ function _stakedBalance(address user) internal view override returns (uint256) { return balanceOf(user); } function _totalStaked() internal view override returns (uint256) { return totalSupply(); } // solhint-disable-next-line ordering function _beforeTokenTransfer( address from, address to, uint256 amount ) internal override(PendleERC20, PendleGauge) { PendleGauge._beforeTokenTransfer(from, to, amount); } // solhint-disable-next-line ordering function _afterTokenTransfer(address from, address to, uint256 amount) internal override(PendleERC20, PendleGauge) { PendleGauge._afterTokenTransfer(from, to, amount); } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "./IPMarket.sol"; interface IPMarketV3 is IPMarket { function getNonOverrideLnFeeRateRoot() external view returns (uint80); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; interface IPMarketFactoryV3 { event SetOverriddenFee(address indexed router, address indexed market, uint80 lnFeeRateRoot); event CreateNewMarket( address indexed market, address indexed PT, int256 scalarRoot, int256 initialAnchor, uint256 lnFeeRateRoot ); event NewTreasuryAndFeeReserve(address indexed treasury, uint8 reserveFeePercent); function isValidMarket(address market) external view returns (bool); // If this is changed, change the readState function in market as well function getMarketConfig( address market, address router ) external view returns (address treasury, uint80 overriddenFee, uint8 reserveFeePercent); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; interface IPMarketSwapCallback { function swapCallback(int256 ptToAccount, int256 syToAccount, bytes calldata data) external; }
// SPDX-License-Identifier: GPL-3.0-or-later // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./PendleERC20.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "@openzeppelin/contracts/utils/Context.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol"; import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol"; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; /// @dev forked from OZ's ERC20Permit contract PendleERC20Permit is PendleERC20, IERC20Permit, EIP712 { using Counters for Counters.Counter; mapping(address => Counters.Counter) private _nonces; // solhint-disable-next-line var-name-mixedcase bytes32 private constant _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); constructor( string memory name_, string memory symbol_, uint8 decimals_ ) PendleERC20(name_, symbol_, decimals_) EIP712(name_, "1") {} /** * @dev See {IERC20Permit-permit}. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual override { require(block.timestamp <= deadline, "ERC20Permit: expired deadline"); bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline)); bytes32 hash = _hashTypedDataV4(structHash); address signer = ECDSA.recover(hash, v, r, s); require(signer == owner, "ERC20Permit: invalid signature"); _approve(owner, spender, value); } /** * @dev See {IERC20Permit-nonces}. */ function nonces(address owner) public view virtual override returns (uint256) { return _nonces[owner].current(); } /** * @dev See {IERC20Permit-DOMAIN_SEPARATOR}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view override returns (bytes32) { return _domainSeparatorV4(); } /** * @dev "Consume a nonce": return the current value and increment. * * _Available since v4.1._ */ function _useNonce(address owner) internal virtual returns (uint256 current) { Counters.Counter storage nonce = _nonces[owner]; current = nonce.current(); nonce.increment(); } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "../../interfaces/IPGauge.sol"; import "../../interfaces/IPVeToken.sol"; import "../../interfaces/IPGaugeController.sol"; import "../../interfaces/IStandardizedYield.sol"; import "../RewardManager/RewardManager.sol"; /** Invariants to maintain: - before any changes to active balance, updateAndDistributeRewards() must be called */ abstract contract PendleGauge is RewardManager, IPGauge { using PMath for uint256; using SafeERC20 for IERC20; using ArrayLib for address[]; address private immutable SY; uint256 internal constant TOKENLESS_PRODUCTION = 40; address internal immutable PENDLE; IPVeToken internal immutable vePENDLE; address internal immutable gaugeController; uint256 public totalActiveSupply; mapping(address => uint256) public activeBalance; constructor(address _SY, address _vePendle, address _gaugeController) { SY = _SY; vePENDLE = IPVeToken(_vePendle); gaugeController = _gaugeController; PENDLE = IPGaugeController(gaugeController).pendle(); } /** * @dev Since rewardShares is based on activeBalance, user's activeBalance must be updated AFTER rewards is updated * @dev It's intended to have user's activeBalance updated when rewards is redeemed */ function _redeemRewards(address user) internal virtual returns (uint256[] memory rewardsOut) { _updateAndDistributeRewards(user); _updateUserActiveBalance(user); rewardsOut = _doTransferOutRewards(user, user); emit RedeemRewards(user, rewardsOut); } function _updateUserActiveBalance(address user) internal virtual { _updateUserActiveBalanceForTwo(user, address(0)); } function _updateUserActiveBalanceForTwo(address user1, address user2) internal virtual { if (user1 != address(0) && user1 != address(this)) _updateUserActiveBalancePrivate(user1); if (user2 != address(0) && user2 != address(this)) _updateUserActiveBalancePrivate(user2); } /** * @dev should only be callable from `_updateUserActiveBalanceForTwo` to guarantee user != address(0) && user != address(this) */ function _updateUserActiveBalancePrivate(address user) private { assert(user != address(0) && user != address(this)); uint256 lpBalance = _stakedBalance(user); uint256 veBoostedLpBalance = _calcVeBoostedLpBalance(user, lpBalance); uint256 newActiveBalance = PMath.min(veBoostedLpBalance, lpBalance); totalActiveSupply = totalActiveSupply - activeBalance[user] + newActiveBalance; activeBalance[user] = newActiveBalance; } function _calcVeBoostedLpBalance(address user, uint256 lpBalance) internal virtual returns (uint256) { (uint256 vePendleSupply, uint256 vePendleBalance) = vePENDLE.totalSupplyAndBalanceCurrent(user); // Inspired by Curve's Gauge uint256 veBoostedLpBalance = (lpBalance * TOKENLESS_PRODUCTION) / 100; if (vePendleSupply > 0) { veBoostedLpBalance += (((_totalStaked() * vePendleBalance) / vePendleSupply) * (100 - TOKENLESS_PRODUCTION)) / 100; } return veBoostedLpBalance; } function _redeemExternalReward() internal virtual override { IStandardizedYield(SY).claimRewards(address(this)); IPGaugeController(gaugeController).redeemMarketReward(); } function _stakedBalance(address user) internal view virtual returns (uint256); function _totalStaked() internal view virtual returns (uint256); function _rewardSharesTotal() internal view virtual override returns (uint256) { return totalActiveSupply; } function _rewardSharesUser(address user) internal view virtual override returns (uint256) { return activeBalance[user]; } function _getRewardTokens() internal view virtual override returns (address[] memory) { address[] memory SYRewards = IStandardizedYield(SY).getRewardTokens(); if (SYRewards.contains(PENDLE)) return SYRewards; return SYRewards.append(PENDLE); } function _beforeTokenTransfer(address from, address to, uint256) internal virtual { _updateAndDistributeRewardsForTwo(from, to); } function _afterTokenTransfer(address from, address to, uint256) internal virtual { _updateUserActiveBalanceForTwo(from, to); } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "../libraries/Errors.sol"; /// Adapted from UniswapV3's Oracle library OracleLib { struct Observation { uint32 blockTimestamp; uint216 lnImpliedRateCumulative; bool initialized; // 1 SLOT = 256 bits } function transform( Observation memory last, uint32 blockTimestamp, uint96 lnImpliedRate ) public pure returns (Observation memory) { return Observation({ blockTimestamp: blockTimestamp, lnImpliedRateCumulative: last.lnImpliedRateCumulative + uint216(lnImpliedRate) * (blockTimestamp - last.blockTimestamp), initialized: true }); } function initialize( Observation[65535] storage self, uint32 time ) public returns (uint16 cardinality, uint16 cardinalityNext) { self[0] = Observation({blockTimestamp: time, lnImpliedRateCumulative: 0, initialized: true}); return (1, 1); } function write( Observation[65535] storage self, uint16 index, uint32 blockTimestamp, uint96 lnImpliedRate, uint16 cardinality, uint16 cardinalityNext ) public returns (uint16 indexUpdated, uint16 cardinalityUpdated) { Observation memory last = self[index]; // early return if we've already written an observation this block if (last.blockTimestamp == blockTimestamp) return (index, cardinality); // if the conditions are right, we can bump the cardinality if (cardinalityNext > cardinality && index == (cardinality - 1)) { cardinalityUpdated = cardinalityNext; } else { cardinalityUpdated = cardinality; } indexUpdated = (index + 1) % cardinalityUpdated; self[indexUpdated] = transform(last, blockTimestamp, lnImpliedRate); } function grow(Observation[65535] storage self, uint16 current, uint16 next) public returns (uint16) { if (current == 0) revert Errors.OracleUninitialized(); // no-op if the passed next value isn't greater than the current next value if (next <= current) return current; // store in each slot to prevent fresh SSTOREs in swaps // this data will not be used because the initialized boolean is still false for (uint16 i = current; i != next; ) { self[i].blockTimestamp = 1; unchecked { ++i; } } return next; } function binarySearch( Observation[65535] storage self, uint32 target, uint16 index, uint16 cardinality ) public view returns (Observation memory beforeOrAt, Observation memory atOrAfter) { uint256 l = (index + 1) % cardinality; // oldest observation uint256 r = l + cardinality - 1; // newest observation uint256 i; while (true) { i = (l + r) / 2; beforeOrAt = self[i % cardinality]; // we've landed on an uninitialized observation, keep searching higher (more recently) if (!beforeOrAt.initialized) { l = i + 1; continue; } atOrAfter = self[(i + 1) % cardinality]; bool targetAtOrAfter = beforeOrAt.blockTimestamp <= target; // check if we've found the answer! if (targetAtOrAfter && target <= atOrAfter.blockTimestamp) break; if (!targetAtOrAfter) r = i - 1; else l = i + 1; } } function getSurroundingObservations( Observation[65535] storage self, uint32 target, uint96 lnImpliedRate, uint16 index, uint16 cardinality ) public view returns (Observation memory beforeOrAt, Observation memory atOrAfter) { // optimistically set before to the newest observation beforeOrAt = self[index]; // if the target is chronologically at or after the newest observation, we can early return if (beforeOrAt.blockTimestamp <= target) { if (beforeOrAt.blockTimestamp == target) { // if newest observation equals target, we're in the same block, so we can ignore atOrAfter return (beforeOrAt, atOrAfter); } else { // otherwise, we need to transform return (beforeOrAt, transform(beforeOrAt, target, lnImpliedRate)); } } // now, set beforeOrAt to the oldest observation beforeOrAt = self[(index + 1) % cardinality]; if (!beforeOrAt.initialized) beforeOrAt = self[0]; // ensure that the target is chronologically at or after the oldest observation if (target < beforeOrAt.blockTimestamp) revert Errors.OracleTargetTooOld(target, beforeOrAt.blockTimestamp); // if we've reached this point, we have to binary search return binarySearch(self, target, index, cardinality); } function observeSingle( Observation[65535] storage self, uint32 time, uint32 secondsAgo, uint96 lnImpliedRate, uint16 index, uint16 cardinality ) public view returns (uint216 lnImpliedRateCumulative) { if (secondsAgo == 0) { Observation memory last = self[index]; if (last.blockTimestamp != time) { return transform(last, time, lnImpliedRate).lnImpliedRateCumulative; } return last.lnImpliedRateCumulative; } uint32 target = time - secondsAgo; (Observation memory beforeOrAt, Observation memory atOrAfter) = getSurroundingObservations( self, target, lnImpliedRate, index, cardinality ); if (target == beforeOrAt.blockTimestamp) { // we're at the left boundary return beforeOrAt.lnImpliedRateCumulative; } else if (target == atOrAfter.blockTimestamp) { // we're at the right boundary return atOrAfter.lnImpliedRateCumulative; } else { // we're in the middle return (beforeOrAt.lnImpliedRateCumulative + uint216( (uint256(atOrAfter.lnImpliedRateCumulative - beforeOrAt.lnImpliedRateCumulative) * (target - beforeOrAt.blockTimestamp)) / (atOrAfter.blockTimestamp - beforeOrAt.blockTimestamp) )); } } function observe( Observation[65535] storage self, uint32 time, uint32[] memory secondsAgos, uint96 lnImpliedRate, uint16 index, uint16 cardinality ) public view returns (uint216[] memory lnImpliedRateCumulative) { if (cardinality == 0) revert Errors.OracleZeroCardinality(); lnImpliedRateCumulative = new uint216[](secondsAgos.length); for (uint256 i = 0; i < lnImpliedRateCumulative.length; ++i) { lnImpliedRateCumulative[i] = observeSingle(self, time, secondsAgos[i], lnImpliedRate, index, cardinality); } } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "./IPPrincipalToken.sol"; import "./IPYieldToken.sol"; import "./IStandardizedYield.sol"; import "./IPGauge.sol"; import "../core/Market/MarketMathCore.sol"; interface IPMarket is IERC20Metadata, IPGauge { event Mint(address indexed receiver, uint256 netLpMinted, uint256 netSyUsed, uint256 netPtUsed); event Burn( address indexed receiverSy, address indexed receiverPt, uint256 netLpBurned, uint256 netSyOut, uint256 netPtOut ); event Swap( address indexed caller, address indexed receiver, int256 netPtOut, int256 netSyOut, uint256 netSyFee, uint256 netSyToReserve ); event UpdateImpliedRate(uint256 indexed timestamp, uint256 lnLastImpliedRate); event IncreaseObservationCardinalityNext( uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew ); function mint( address receiver, uint256 netSyDesired, uint256 netPtDesired ) external returns (uint256 netLpOut, uint256 netSyUsed, uint256 netPtUsed); function burn( address receiverSy, address receiverPt, uint256 netLpToBurn ) external returns (uint256 netSyOut, uint256 netPtOut); function swapExactPtForSy( address receiver, uint256 exactPtIn, bytes calldata data ) external returns (uint256 netSyOut, uint256 netSyFee); function swapSyForExactPt( address receiver, uint256 exactPtOut, bytes calldata data ) external returns (uint256 netSyIn, uint256 netSyFee); function redeemRewards(address user) external returns (uint256[] memory); function readState(address router) external view returns (MarketState memory market); function observe(uint32[] memory secondsAgos) external view returns (uint216[] memory lnImpliedRateCumulative); function increaseObservationsCardinalityNext(uint16 cardinalityNext) external; function readTokens() external view returns (IStandardizedYield _SY, IPPrincipalToken _PT, IPYieldToken _YT); function getRewardTokens() external view returns (address[] memory); function isExpired() external view returns (bool); function expiry() external view returns (uint256); function observations( uint256 index ) external view returns (uint32 blockTimestamp, uint216 lnImpliedRateCumulative, bool initialized); function _storage() external view returns ( int128 totalPt, int128 totalSy, uint96 lastLnImpliedRate, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext ); }
// SPDX-License-Identifier: GPL-3.0-or-later // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "@openzeppelin/contracts/utils/Context.sol"; /** * @dev Pendle's ERC20 implementation, modified from @openzeppelin implementation * Changes are: * - comes with built-in reentrancy protection, storage-packed with totalSupply variable * - delete increaseAllowance / decreaseAllowance * - add nonReentrancy protection to transfer / transferFrom functions * - allow decimals to be passed in * - block self-transfer by default */ // solhint-disable contract PendleERC20 is Context, IERC20, IERC20Metadata { uint8 private constant _NOT_ENTERED = 1; uint8 private constant _ENTERED = 2; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint248 private _totalSupply; uint8 private _status; string private _name; string private _symbol; uint8 public immutable decimals; /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev Sets the values for {name}, {symbol} and {decimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_, uint8 decimals_) { _name = name_; _symbol = symbol_; decimals = decimals_; _status = _NOT_ENTERED; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) external virtual override nonReentrant returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) external virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) external virtual override nonReentrant returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Moves `amount` of tokens from `sender` to `recipient`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer(address from, address to, uint256 amount) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); require(from != to, "ERC20: transfer to self"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += toUint248(amount); _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= toUint248(amount); emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance(address owner, address spender, uint256 amount) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {} function toUint248(uint256 x) internal virtual returns (uint248) { require(x <= type(uint248).max); // signed, lim = bit-1 return uint248(x); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 amount) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts 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 v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/draft-ERC20Permit.sol) pragma solidity ^0.8.0; // EIP-2612 is Final as of 2022-11-01. This file is deprecated. import "./ERC20Permit.sol";
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/draft-EIP712.sol) pragma solidity ^0.8.0; // EIP-712 is Final as of 2022-08-11. This file is deprecated. import "./EIP712.sol";
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV // Deprecated in v4.8 } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) { // 32 is the length in bytes of hash, // enforced by the type signature above /// @solidity memory-safe-assembly assembly { mstore(0x00, "\x19Ethereum Signed Message:\n32") mstore(0x1c, hash) message := keccak256(0x00, 0x3c) } } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) { /// @solidity memory-safe-assembly assembly { let ptr := mload(0x40) mstore(ptr, "\x19\x01") mstore(add(ptr, 0x02), domainSeparator) mstore(add(ptr, 0x22), structHash) data := keccak256(ptr, 0x42) } } /** * @dev Returns an Ethereum Signed Data with intended validator, created from a * `validator` and `data` according to the version 0 of EIP-191. * * See {recover}. */ function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x00", validator, data)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Counters.sol) pragma solidity ^0.8.0; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids. * * Include with `using Counters for Counters.Counter;` */ library Counters { struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { unchecked { counter._value += 1; } } function decrement(Counter storage counter) internal { uint256 value = counter._value; require(value > 0, "Counter: decrement overflow"); unchecked { counter._value = value - 1; } } function reset(Counter storage counter) internal { counter._value = 0; } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; interface IPGauge { function totalActiveSupply() external view returns (uint256); function activeBalance(address user) external view returns (uint256); // only available for newer factories. please check the verified contracts event RedeemRewards(address indexed user, uint256[] rewardsOut); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; interface IPVeToken { // ============= USER INFO ============= function balanceOf(address user) external view returns (uint128); function positionData(address user) external view returns (uint128 amount, uint128 expiry); // ============= META DATA ============= function totalSupplyStored() external view returns (uint128); function totalSupplyCurrent() external returns (uint128); function totalSupplyAndBalanceCurrent(address user) external returns (uint128, uint128); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; interface IPGaugeController { event MarketClaimReward(address indexed market, uint256 amount); event ReceiveVotingResults(uint128 indexed wTime, address[] markets, uint256[] pendleAmounts); event UpdateMarketReward(address indexed market, uint256 pendlePerSec, uint256 incentiveEndsAt); function fundPendle(uint256 amount) external; function withdrawPendle(uint256 amount) external; function pendle() external returns (address); function redeemMarketReward() external; function rewardData(address pool) external view returns (uint128 pendlePerSec, uint128, uint128, uint128); }
// SPDX-License-Identifier: GPL-3.0-or-later /* * MIT License * =========== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; interface IStandardizedYield is IERC20Metadata { /// @dev Emitted when any base tokens is deposited to mint shares event Deposit( address indexed caller, address indexed receiver, address indexed tokenIn, uint256 amountDeposited, uint256 amountSyOut ); /// @dev Emitted when any shares are redeemed for base tokens event Redeem( address indexed caller, address indexed receiver, address indexed tokenOut, uint256 amountSyToRedeem, uint256 amountTokenOut ); /// @dev check `assetInfo()` for more information enum AssetType { TOKEN, LIQUIDITY } /// @dev Emitted when (`user`) claims their rewards event ClaimRewards(address indexed user, address[] rewardTokens, uint256[] rewardAmounts); /** * @notice mints an amount of shares by depositing a base token. * @param receiver shares recipient address * @param tokenIn address of the base tokens to mint shares * @param amountTokenToDeposit amount of base tokens to be transferred from (`msg.sender`) * @param minSharesOut reverts if amount of shares minted is lower than this * @return amountSharesOut amount of shares minted * @dev Emits a {Deposit} event * * Requirements: * - (`tokenIn`) must be a valid base token. */ function deposit( address receiver, address tokenIn, uint256 amountTokenToDeposit, uint256 minSharesOut ) external payable returns (uint256 amountSharesOut); /** * @notice redeems an amount of base tokens by burning some shares * @param receiver recipient address * @param amountSharesToRedeem amount of shares to be burned * @param tokenOut address of the base token to be redeemed * @param minTokenOut reverts if amount of base token redeemed is lower than this * @param burnFromInternalBalance if true, burns from balance of `address(this)`, otherwise burns from `msg.sender` * @return amountTokenOut amount of base tokens redeemed * @dev Emits a {Redeem} event * * Requirements: * - (`tokenOut`) must be a valid base token. */ function redeem( address receiver, uint256 amountSharesToRedeem, address tokenOut, uint256 minTokenOut, bool burnFromInternalBalance ) external returns (uint256 amountTokenOut); /** * @notice exchangeRate * syBalance / 1e18 must return the asset balance of the account * @notice vice-versa, if a user uses some amount of tokens equivalent to X asset, the amount of sy he can mint must be X * exchangeRate / 1e18 * @dev SYUtils's assetToSy & syToAsset should be used instead of raw multiplication & division */ function exchangeRate() external view returns (uint256 res); /** * @notice claims reward for (`user`) * @param user the user receiving their rewards * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens` * @dev * Emits a `ClaimRewards` event * See {getRewardTokens} for list of reward tokens */ function claimRewards(address user) external returns (uint256[] memory rewardAmounts); /** * @notice get the amount of unclaimed rewards for (`user`) * @param user the user to check for * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens` */ function accruedRewards(address user) external view returns (uint256[] memory rewardAmounts); function rewardIndexesCurrent() external returns (uint256[] memory indexes); function rewardIndexesStored() external view returns (uint256[] memory indexes); /** * @notice returns the list of reward token addresses */ function getRewardTokens() external view returns (address[] memory); /** * @notice returns the address of the underlying yield token */ function yieldToken() external view returns (address); /** * @notice returns all tokens that can mint this SY */ function getTokensIn() external view returns (address[] memory res); /** * @notice returns all tokens that can be redeemed by this SY */ function getTokensOut() external view returns (address[] memory res); function isValidTokenIn(address token) external view returns (bool); function isValidTokenOut(address token) external view returns (bool); function previewDeposit( address tokenIn, uint256 amountTokenToDeposit ) external view returns (uint256 amountSharesOut); function previewRedeem( address tokenOut, uint256 amountSharesToRedeem ) external view returns (uint256 amountTokenOut); /** * @notice This function contains information to interpret what the asset is * @return assetType the type of the asset (0 for ERC20 tokens, 1 for AMM liquidity tokens, 2 for bridged yield bearing tokens like wstETH, rETH on Arbi whose the underlying asset doesn't exist on the chain) * @return assetAddress the address of the asset * @return assetDecimals the decimals of the asset */ function assetInfo() external view returns (AssetType assetType, address assetAddress, uint8 assetDecimals); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "./RewardManagerAbstract.sol"; /// NOTE: This RewardManager is used with SY & YTv2 & PendleMarket. For YTv1, it will use RewardManagerAbstract /// NOTE: RewardManager must not have duplicated rewardTokens abstract contract RewardManager is RewardManagerAbstract { using PMath for uint256; using ArrayLib for uint256[]; uint256 public lastRewardBlock; mapping(address => RewardState) public rewardState; function _updateRewardIndex() internal virtual override returns (address[] memory tokens, uint256[] memory indexes) { tokens = _getRewardTokens(); indexes = new uint256[](tokens.length); if (tokens.length == 0) return (tokens, indexes); if (lastRewardBlock != block.number) { // if we have not yet update the index for this block lastRewardBlock = block.number; uint256 totalShares = _rewardSharesTotal(); _redeemExternalReward(); for (uint256 i = 0; i < tokens.length; ++i) { address token = tokens[i]; // the entire token balance of the contract must be the rewards of the contract RewardState memory _state = rewardState[token]; (uint256 lastBalance, uint256 index) = (_state.lastBalance, _state.index); uint256 accrued = _selfBalance(tokens[i]) - lastBalance; if (index == 0) index = INITIAL_REWARD_INDEX; if (totalShares != 0) index += accrued.divDown(totalShares); rewardState[token] = RewardState({ index: index.Uint128(), lastBalance: (lastBalance + accrued).Uint128() }); indexes[i] = index; } } else { for (uint256 i = 0; i < tokens.length; i++) { indexes[i] = rewardState[tokens[i]].index; } } } /// @dev this function doesn't need redeemExternal since redeemExternal is bundled in updateRewardIndex /// @dev this function also has to update rewardState.lastBalance function _doTransferOutRewards( address user, address receiver ) internal virtual override returns (uint256[] memory rewardAmounts) { address[] memory tokens = _getRewardTokens(); rewardAmounts = new uint256[](tokens.length); for (uint256 i = 0; i < tokens.length; i++) { rewardAmounts[i] = userReward[tokens[i]][user].accrued; if (rewardAmounts[i] != 0) { userReward[tokens[i]][user].accrued = 0; rewardState[tokens[i]].lastBalance -= rewardAmounts[i].Uint128(); _transferOut(tokens[i], receiver, rewardAmounts[i]); } } } function _getRewardTokens() internal view virtual returns (address[] memory); function _rewardSharesTotal() internal view virtual returns (uint256); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; library Errors { // BulkSeller error BulkInsufficientSyForTrade(uint256 currentAmount, uint256 requiredAmount); error BulkInsufficientTokenForTrade(uint256 currentAmount, uint256 requiredAmount); error BulkInSufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut); error BulkInSufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut); error BulkInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance); error BulkNotMaintainer(); error BulkNotAdmin(); error BulkSellerAlreadyExisted(address token, address SY, address bulk); error BulkSellerInvalidToken(address token, address SY); error BulkBadRateTokenToSy(uint256 actualRate, uint256 currentRate, uint256 eps); error BulkBadRateSyToToken(uint256 actualRate, uint256 currentRate, uint256 eps); // APPROX error ApproxFail(); error ApproxParamsInvalid(uint256 guessMin, uint256 guessMax, uint256 eps); error ApproxBinarySearchInputInvalid( uint256 approxGuessMin, uint256 approxGuessMax, uint256 minGuessMin, uint256 maxGuessMax ); // MARKET + MARKET MATH CORE error MarketExpired(); error MarketZeroAmountsInput(); error MarketZeroAmountsOutput(); error MarketZeroLnImpliedRate(); error MarketInsufficientPtForTrade(int256 currentAmount, int256 requiredAmount); error MarketInsufficientPtReceived(uint256 actualBalance, uint256 requiredBalance); error MarketInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance); error MarketZeroTotalPtOrTotalAsset(int256 totalPt, int256 totalAsset); error MarketExchangeRateBelowOne(int256 exchangeRate); error MarketProportionMustNotEqualOne(); error MarketRateScalarBelowZero(int256 rateScalar); error MarketScalarRootBelowZero(int256 scalarRoot); error MarketProportionTooHigh(int256 proportion, int256 maxProportion); error OracleUninitialized(); error OracleTargetTooOld(uint32 target, uint32 oldest); error OracleZeroCardinality(); error MarketFactoryExpiredPt(); error MarketFactoryInvalidPt(); error MarketFactoryMarketExists(); error MarketFactoryLnFeeRateRootTooHigh(uint80 lnFeeRateRoot, uint256 maxLnFeeRateRoot); error MarketFactoryOverriddenFeeTooHigh(uint80 overriddenFee, uint256 marketLnFeeRateRoot); error MarketFactoryReserveFeePercentTooHigh(uint8 reserveFeePercent, uint8 maxReserveFeePercent); error MarketFactoryZeroTreasury(); error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor); error MFNotPendleMarket(address addr); // ROUTER error RouterInsufficientLpOut(uint256 actualLpOut, uint256 requiredLpOut); error RouterInsufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut); error RouterInsufficientPtOut(uint256 actualPtOut, uint256 requiredPtOut); error RouterInsufficientYtOut(uint256 actualYtOut, uint256 requiredYtOut); error RouterInsufficientPYOut(uint256 actualPYOut, uint256 requiredPYOut); error RouterInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut); error RouterInsufficientSyRepay(uint256 actualSyRepay, uint256 requiredSyRepay); error RouterInsufficientPtRepay(uint256 actualPtRepay, uint256 requiredPtRepay); error RouterNotAllSyUsed(uint256 netSyDesired, uint256 netSyUsed); error RouterTimeRangeZero(); error RouterCallbackNotPendleMarket(address caller); error RouterInvalidAction(bytes4 selector); error RouterInvalidFacet(address facet); error RouterKyberSwapDataZero(); error SimulationResults(bool success, bytes res); // YIELD CONTRACT error YCExpired(); error YCNotExpired(); error YieldContractInsufficientSy(uint256 actualSy, uint256 requiredSy); error YCNothingToRedeem(); error YCPostExpiryDataNotSet(); error YCNoFloatingSy(); // YieldFactory error YCFactoryInvalidExpiry(); error YCFactoryYieldContractExisted(); error YCFactoryZeroExpiryDivisor(); error YCFactoryZeroTreasury(); error YCFactoryInterestFeeRateTooHigh(uint256 interestFeeRate, uint256 maxInterestFeeRate); error YCFactoryRewardFeeRateTooHigh(uint256 newRewardFeeRate, uint256 maxRewardFeeRate); // SY error SYInvalidTokenIn(address token); error SYInvalidTokenOut(address token); error SYZeroDeposit(); error SYZeroRedeem(); error SYInsufficientSharesOut(uint256 actualSharesOut, uint256 requiredSharesOut); error SYInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut); // SY-specific error SYQiTokenMintFailed(uint256 errCode); error SYQiTokenRedeemFailed(uint256 errCode); error SYQiTokenRedeemRewardsFailed(uint256 rewardAccruedType0, uint256 rewardAccruedType1); error SYQiTokenBorrowRateTooHigh(uint256 borrowRate, uint256 borrowRateMax); error SYCurveInvalidPid(); error SYCurve3crvPoolNotFound(); error SYApeDepositAmountTooSmall(uint256 amountDeposited); error SYBalancerInvalidPid(); error SYInvalidRewardToken(address token); error SYStargateRedeemCapExceeded(uint256 amountLpDesired, uint256 amountLpRedeemable); error SYBalancerReentrancy(); error NotFromTrustedRemote(uint16 srcChainId, bytes path); // Liquidity Mining error VCInactivePool(address pool); error VCPoolAlreadyActive(address pool); error VCZeroVePendle(address user); error VCExceededMaxWeight(uint256 totalWeight, uint256 maxWeight); error VCEpochNotFinalized(uint256 wTime); error VCPoolAlreadyAddAndRemoved(address pool); error VEInvalidNewExpiry(uint256 newExpiry); error VEExceededMaxLockTime(); error VEInsufficientLockTime(); error VENotAllowedReduceExpiry(); error VEZeroAmountLocked(); error VEPositionNotExpired(); error VEZeroPosition(); error VEZeroSlope(uint128 bias, uint128 slope); error VEReceiveOldSupply(uint256 msgTime); error GCNotPendleMarket(address caller); error GCNotVotingController(address caller); error InvalidWTime(uint256 wTime); error ExpiryInThePast(uint256 expiry); error ChainNotSupported(uint256 chainId); error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount); error FDEpochLengthMismatch(); error FDInvalidPool(address pool); error FDPoolAlreadyExists(address pool); error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch); error FDInvalidStartEpoch(uint256 startEpoch); error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime); error FDFutureFunding(uint256 lastFunded, uint256 currentWTime); error BDInvalidEpoch(uint256 epoch, uint256 startTime); // Cross-Chain error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path); error MsgNotFromReceiveEndpoint(address sender); error InsufficientFeeToSendMsg(uint256 currentFee, uint256 requiredFee); error ApproxDstExecutionGasNotSet(); error InvalidRetryData(); // GENERIC MSG error ArrayLengthMismatch(); error ArrayEmpty(); error ArrayOutOfBounds(); error ZeroAddress(); error FailedToSendEther(); error InvalidMerkleProof(); error OnlyLayerZeroEndpoint(); error OnlyYT(); error OnlyYCFactory(); error OnlyWhitelisted(); // Swap Aggregator error SAInsufficientTokenIn(address tokenIn, uint256 amountExpected, uint256 amountActual); error UnsupportedSelector(uint256 aggregatorType, bytes4 selector); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; interface IPPrincipalToken is IERC20Metadata { function burnByYT(address user, uint256 amount) external; function mintByYT(address user, uint256 amount) external; function initialize(address _YT) external; function SY() external view returns (address); function YT() external view returns (address); function factory() external view returns (address); function expiry() external view returns (uint256); function isExpired() external view returns (bool); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "./IRewardManager.sol"; import "./IPInterestManagerYT.sol"; interface IPYieldToken is IERC20Metadata, IRewardManager, IPInterestManagerYT { event NewInterestIndex(uint256 indexed newIndex); event Mint( address indexed caller, address indexed receiverPT, address indexed receiverYT, uint256 amountSyToMint, uint256 amountPYOut ); event Burn(address indexed caller, address indexed receiver, uint256 amountPYToRedeem, uint256 amountSyOut); event RedeemRewards(address indexed user, uint256[] amountRewardsOut); event RedeemInterest(address indexed user, uint256 interestOut); event CollectRewardFee(address indexed rewardToken, uint256 amountRewardFee); function mintPY(address receiverPT, address receiverYT) external returns (uint256 amountPYOut); function redeemPY(address receiver) external returns (uint256 amountSyOut); function redeemPYMulti( address[] calldata receivers, uint256[] calldata amountPYToRedeems ) external returns (uint256[] memory amountSyOuts); function redeemDueInterestAndRewards( address user, bool redeemInterest, bool redeemRewards ) external returns (uint256 interestOut, uint256[] memory rewardsOut); function rewardIndexesCurrent() external returns (uint256[] memory); function pyIndexCurrent() external returns (uint256); function pyIndexStored() external view returns (uint256); function getRewardTokens() external view returns (address[] memory); function SY() external view returns (address); function PT() external view returns (address); function factory() external view returns (address); function expiry() external view returns (uint256); function isExpired() external view returns (bool); function doCacheIndexSameBlock() external view returns (bool); function pyIndexLastUpdatedBlock() external view returns (uint128); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "../libraries/math/PMath.sol"; import "../libraries/math/LogExpMath.sol"; import "../StandardizedYield/PYIndex.sol"; import "../libraries/MiniHelpers.sol"; import "../libraries/Errors.sol"; struct MarketState { int256 totalPt; int256 totalSy; int256 totalLp; address treasury; /// immutable variables /// int256 scalarRoot; uint256 expiry; /// fee data /// uint256 lnFeeRateRoot; uint256 reserveFeePercent; // base 100 /// last trade data /// uint256 lastLnImpliedRate; } // params that are expensive to compute, therefore we pre-compute them struct MarketPreCompute { int256 rateScalar; int256 totalAsset; int256 rateAnchor; int256 feeRate; } // solhint-disable ordering library MarketMathCore { using PMath for uint256; using PMath for int256; using LogExpMath for int256; using PYIndexLib for PYIndex; int256 internal constant MINIMUM_LIQUIDITY = 10 ** 3; int256 internal constant PERCENTAGE_DECIMALS = 100; uint256 internal constant DAY = 86400; uint256 internal constant IMPLIED_RATE_TIME = 365 * DAY; int256 internal constant MAX_MARKET_PROPORTION = (1e18 * 96) / 100; using PMath for uint256; using PMath for int256; /*/////////////////////////////////////////////////////////////// UINT FUNCTIONS TO PROXY TO CORE FUNCTIONS //////////////////////////////////////////////////////////////*/ function addLiquidity( MarketState memory market, uint256 syDesired, uint256 ptDesired, uint256 blockTime ) internal pure returns (uint256 lpToReserve, uint256 lpToAccount, uint256 syUsed, uint256 ptUsed) { (int256 _lpToReserve, int256 _lpToAccount, int256 _syUsed, int256 _ptUsed) = addLiquidityCore( market, syDesired.Int(), ptDesired.Int(), blockTime ); lpToReserve = _lpToReserve.Uint(); lpToAccount = _lpToAccount.Uint(); syUsed = _syUsed.Uint(); ptUsed = _ptUsed.Uint(); } function removeLiquidity( MarketState memory market, uint256 lpToRemove ) internal pure returns (uint256 netSyToAccount, uint256 netPtToAccount) { (int256 _syToAccount, int256 _ptToAccount) = removeLiquidityCore(market, lpToRemove.Int()); netSyToAccount = _syToAccount.Uint(); netPtToAccount = _ptToAccount.Uint(); } function swapExactPtForSy( MarketState memory market, PYIndex index, uint256 exactPtToMarket, uint256 blockTime ) internal pure returns (uint256 netSyToAccount, uint256 netSyFee, uint256 netSyToReserve) { (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore( market, index, exactPtToMarket.neg(), blockTime ); netSyToAccount = _netSyToAccount.Uint(); netSyFee = _netSyFee.Uint(); netSyToReserve = _netSyToReserve.Uint(); } function swapSyForExactPt( MarketState memory market, PYIndex index, uint256 exactPtToAccount, uint256 blockTime ) internal pure returns (uint256 netSyToMarket, uint256 netSyFee, uint256 netSyToReserve) { (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore( market, index, exactPtToAccount.Int(), blockTime ); netSyToMarket = _netSyToAccount.neg().Uint(); netSyFee = _netSyFee.Uint(); netSyToReserve = _netSyToReserve.Uint(); } /*/////////////////////////////////////////////////////////////// CORE FUNCTIONS //////////////////////////////////////////////////////////////*/ function addLiquidityCore( MarketState memory market, int256 syDesired, int256 ptDesired, uint256 blockTime ) internal pure returns (int256 lpToReserve, int256 lpToAccount, int256 syUsed, int256 ptUsed) { /// ------------------------------------------------------------ /// CHECKS /// ------------------------------------------------------------ if (syDesired == 0 || ptDesired == 0) revert Errors.MarketZeroAmountsInput(); if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired(); /// ------------------------------------------------------------ /// MATH /// ------------------------------------------------------------ if (market.totalLp == 0) { lpToAccount = PMath.sqrt((syDesired * ptDesired).Uint()).Int() - MINIMUM_LIQUIDITY; lpToReserve = MINIMUM_LIQUIDITY; syUsed = syDesired; ptUsed = ptDesired; } else { int256 netLpByPt = (ptDesired * market.totalLp) / market.totalPt; int256 netLpBySy = (syDesired * market.totalLp) / market.totalSy; if (netLpByPt < netLpBySy) { lpToAccount = netLpByPt; ptUsed = ptDesired; syUsed = (market.totalSy * lpToAccount) / market.totalLp; } else { lpToAccount = netLpBySy; syUsed = syDesired; ptUsed = (market.totalPt * lpToAccount) / market.totalLp; } } if (lpToAccount <= 0) revert Errors.MarketZeroAmountsOutput(); /// ------------------------------------------------------------ /// WRITE /// ------------------------------------------------------------ market.totalSy += syUsed; market.totalPt += ptUsed; market.totalLp += lpToAccount + lpToReserve; } function removeLiquidityCore( MarketState memory market, int256 lpToRemove ) internal pure returns (int256 netSyToAccount, int256 netPtToAccount) { /// ------------------------------------------------------------ /// CHECKS /// ------------------------------------------------------------ if (lpToRemove == 0) revert Errors.MarketZeroAmountsInput(); /// ------------------------------------------------------------ /// MATH /// ------------------------------------------------------------ netSyToAccount = (lpToRemove * market.totalSy) / market.totalLp; netPtToAccount = (lpToRemove * market.totalPt) / market.totalLp; if (netSyToAccount == 0 && netPtToAccount == 0) revert Errors.MarketZeroAmountsOutput(); /// ------------------------------------------------------------ /// WRITE /// ------------------------------------------------------------ market.totalLp = market.totalLp.subNoNeg(lpToRemove); market.totalPt = market.totalPt.subNoNeg(netPtToAccount); market.totalSy = market.totalSy.subNoNeg(netSyToAccount); } function executeTradeCore( MarketState memory market, PYIndex index, int256 netPtToAccount, uint256 blockTime ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) { /// ------------------------------------------------------------ /// CHECKS /// ------------------------------------------------------------ if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired(); if (market.totalPt <= netPtToAccount) revert Errors.MarketInsufficientPtForTrade(market.totalPt, netPtToAccount); /// ------------------------------------------------------------ /// MATH /// ------------------------------------------------------------ MarketPreCompute memory comp = getMarketPreCompute(market, index, blockTime); (netSyToAccount, netSyFee, netSyToReserve) = calcTrade(market, comp, index, netPtToAccount); /// ------------------------------------------------------------ /// WRITE /// ------------------------------------------------------------ _setNewMarketStateTrade(market, comp, index, netPtToAccount, netSyToAccount, netSyToReserve, blockTime); } function getMarketPreCompute( MarketState memory market, PYIndex index, uint256 blockTime ) internal pure returns (MarketPreCompute memory res) { if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired(); uint256 timeToExpiry = market.expiry - blockTime; res.rateScalar = _getRateScalar(market, timeToExpiry); res.totalAsset = index.syToAsset(market.totalSy); if (market.totalPt == 0 || res.totalAsset == 0) revert Errors.MarketZeroTotalPtOrTotalAsset(market.totalPt, res.totalAsset); res.rateAnchor = _getRateAnchor( market.totalPt, market.lastLnImpliedRate, res.totalAsset, res.rateScalar, timeToExpiry ); res.feeRate = _getExchangeRateFromImpliedRate(market.lnFeeRateRoot, timeToExpiry); } function calcTrade( MarketState memory market, MarketPreCompute memory comp, PYIndex index, int256 netPtToAccount ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) { int256 preFeeExchangeRate = _getExchangeRate( market.totalPt, comp.totalAsset, comp.rateScalar, comp.rateAnchor, netPtToAccount ); int256 preFeeAssetToAccount = netPtToAccount.divDown(preFeeExchangeRate).neg(); int256 fee = comp.feeRate; if (netPtToAccount > 0) { int256 postFeeExchangeRate = preFeeExchangeRate.divDown(fee); if (postFeeExchangeRate < PMath.IONE) revert Errors.MarketExchangeRateBelowOne(postFeeExchangeRate); fee = preFeeAssetToAccount.mulDown(PMath.IONE - fee); } else { fee = ((preFeeAssetToAccount * (PMath.IONE - fee)) / fee).neg(); } int256 netAssetToReserve = (fee * market.reserveFeePercent.Int()) / PERCENTAGE_DECIMALS; int256 netAssetToAccount = preFeeAssetToAccount - fee; netSyToAccount = netAssetToAccount < 0 ? index.assetToSyUp(netAssetToAccount) : index.assetToSy(netAssetToAccount); netSyFee = index.assetToSy(fee); netSyToReserve = index.assetToSy(netAssetToReserve); } function _setNewMarketStateTrade( MarketState memory market, MarketPreCompute memory comp, PYIndex index, int256 netPtToAccount, int256 netSyToAccount, int256 netSyToReserve, uint256 blockTime ) internal pure { uint256 timeToExpiry = market.expiry - blockTime; market.totalPt = market.totalPt.subNoNeg(netPtToAccount); market.totalSy = market.totalSy.subNoNeg(netSyToAccount + netSyToReserve); market.lastLnImpliedRate = _getLnImpliedRate( market.totalPt, index.syToAsset(market.totalSy), comp.rateScalar, comp.rateAnchor, timeToExpiry ); if (market.lastLnImpliedRate == 0) revert Errors.MarketZeroLnImpliedRate(); } function _getRateAnchor( int256 totalPt, uint256 lastLnImpliedRate, int256 totalAsset, int256 rateScalar, uint256 timeToExpiry ) internal pure returns (int256 rateAnchor) { int256 newExchangeRate = _getExchangeRateFromImpliedRate(lastLnImpliedRate, timeToExpiry); if (newExchangeRate < PMath.IONE) revert Errors.MarketExchangeRateBelowOne(newExchangeRate); { int256 proportion = totalPt.divDown(totalPt + totalAsset); int256 lnProportion = _logProportion(proportion); rateAnchor = newExchangeRate - lnProportion.divDown(rateScalar); } } /// @notice Calculates the current market implied rate. /// @return lnImpliedRate the implied rate function _getLnImpliedRate( int256 totalPt, int256 totalAsset, int256 rateScalar, int256 rateAnchor, uint256 timeToExpiry ) internal pure returns (uint256 lnImpliedRate) { // This will check for exchange rates < PMath.IONE int256 exchangeRate = _getExchangeRate(totalPt, totalAsset, rateScalar, rateAnchor, 0); // exchangeRate >= 1 so its ln >= 0 uint256 lnRate = exchangeRate.ln().Uint(); lnImpliedRate = (lnRate * IMPLIED_RATE_TIME) / timeToExpiry; } /// @notice Converts an implied rate to an exchange rate given a time to expiry. The /// formula is E = e^rt function _getExchangeRateFromImpliedRate( uint256 lnImpliedRate, uint256 timeToExpiry ) internal pure returns (int256 exchangeRate) { uint256 rt = (lnImpliedRate * timeToExpiry) / IMPLIED_RATE_TIME; exchangeRate = LogExpMath.exp(rt.Int()); } function _getExchangeRate( int256 totalPt, int256 totalAsset, int256 rateScalar, int256 rateAnchor, int256 netPtToAccount ) internal pure returns (int256 exchangeRate) { int256 numerator = totalPt.subNoNeg(netPtToAccount); int256 proportion = (numerator.divDown(totalPt + totalAsset)); if (proportion > MAX_MARKET_PROPORTION) revert Errors.MarketProportionTooHigh(proportion, MAX_MARKET_PROPORTION); int256 lnProportion = _logProportion(proportion); exchangeRate = lnProportion.divDown(rateScalar) + rateAnchor; if (exchangeRate < PMath.IONE) revert Errors.MarketExchangeRateBelowOne(exchangeRate); } function _logProportion(int256 proportion) internal pure returns (int256 res) { if (proportion == PMath.IONE) revert Errors.MarketProportionMustNotEqualOne(); int256 logitP = proportion.divDown(PMath.IONE - proportion); res = logitP.ln(); } function _getRateScalar(MarketState memory market, uint256 timeToExpiry) internal pure returns (int256 rateScalar) { rateScalar = (market.scalarRoot * IMPLIED_RATE_TIME.Int()) / timeToExpiry.Int(); if (rateScalar <= 0) revert Errors.MarketRateScalarBelowZero(rateScalar); } function setInitialLnImpliedRate( MarketState memory market, PYIndex index, int256 initialAnchor, uint256 blockTime ) internal pure { /// ------------------------------------------------------------ /// CHECKS /// ------------------------------------------------------------ if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired(); /// ------------------------------------------------------------ /// MATH /// ------------------------------------------------------------ int256 totalAsset = index.syToAsset(market.totalSy); uint256 timeToExpiry = market.expiry - blockTime; int256 rateScalar = _getRateScalar(market, timeToExpiry); /// ------------------------------------------------------------ /// WRITE /// ------------------------------------------------------------ market.lastLnImpliedRate = _getLnImpliedRate( market.totalPt, totalAsset, rateScalar, initialAnchor, timeToExpiry ); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/ERC20Permit.sol) pragma solidity ^0.8.0; import "./IERC20Permit.sol"; import "../ERC20.sol"; import "../../../utils/cryptography/ECDSA.sol"; import "../../../utils/cryptography/EIP712.sol"; import "../../../utils/Counters.sol"; /** * @dev Implementation 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. * * _Available since v3.4._ */ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { using Counters for Counters.Counter; mapping(address => Counters.Counter) private _nonces; // solhint-disable-next-line var-name-mixedcase bytes32 private constant _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); /** * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`. * However, to ensure consistency with the upgradeable transpiler, we will continue * to reserve a slot. * @custom:oz-renamed-from _PERMIT_TYPEHASH */ // solhint-disable-next-line var-name-mixedcase bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT; /** * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. * * It's a good idea to use the same `name` that is defined as the ERC20 token name. */ constructor(string memory name) EIP712(name, "1") {} /** * @dev See {IERC20Permit-permit}. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual override { require(block.timestamp <= deadline, "ERC20Permit: expired deadline"); bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline)); bytes32 hash = _hashTypedDataV4(structHash); address signer = ECDSA.recover(hash, v, r, s); require(signer == owner, "ERC20Permit: invalid signature"); _approve(owner, spender, value); } /** * @dev See {IERC20Permit-nonces}. */ function nonces(address owner) public view virtual override returns (uint256) { return _nonces[owner].current(); } /** * @dev See {IERC20Permit-DOMAIN_SEPARATOR}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view override returns (bytes32) { return _domainSeparatorV4(); } /** * @dev "Consume a nonce": return the current value and increment. * * _Available since v4.1._ */ function _useNonce(address owner) internal virtual returns (uint256 current) { Counters.Counter storage nonce = _nonces[owner]; current = nonce.current(); nonce.increment(); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/EIP712.sol) pragma solidity ^0.8.8; import "./ECDSA.sol"; import "../ShortStrings.sol"; import "../../interfaces/IERC5267.sol"; /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. * * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible, * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding * they need in their contracts using a combination of `abi.encode` and `keccak256`. * * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA * ({_hashTypedDataV4}). * * The implementation of the domain separator was designed to be as efficient as possible while still properly updating * the chain id to protect against replay attacks on an eventual fork of the chain. * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. * * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain * separator of the implementation contract. This will cause the `_domainSeparatorV4` function to always rebuild the * separator from the immutable values, which is cheaper than accessing a cached version in cold storage. * * _Available since v3.4._ * * @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment */ abstract contract EIP712 is IERC5267 { using ShortStrings for *; bytes32 private constant _TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to // invalidate the cached domain separator if the chain id changes. bytes32 private immutable _cachedDomainSeparator; uint256 private immutable _cachedChainId; address private immutable _cachedThis; bytes32 private immutable _hashedName; bytes32 private immutable _hashedVersion; ShortString private immutable _name; ShortString private immutable _version; string private _nameFallback; string private _versionFallback; /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ constructor(string memory name, string memory version) { _name = name.toShortStringWithFallback(_nameFallback); _version = version.toShortStringWithFallback(_versionFallback); _hashedName = keccak256(bytes(name)); _hashedVersion = keccak256(bytes(version)); _cachedChainId = block.chainid; _cachedDomainSeparator = _buildDomainSeparator(); _cachedThis = address(this); } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view returns (bytes32) { if (address(this) == _cachedThis && block.chainid == _cachedChainId) { return _cachedDomainSeparator; } else { return _buildDomainSeparator(); } } function _buildDomainSeparator() private view returns (bytes32) { return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this))); } /** * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this * function returns the hash of the fully encoded EIP712 message for this domain. * * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: * * ```solidity * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( * keccak256("Mail(address to,string contents)"), * mailTo, * keccak256(bytes(mailContents)) * ))); * address signer = ECDSA.recover(digest, signature); * ``` */ function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) { return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash); } /** * @dev See {EIP-5267}. * * _Available since v4.9._ */ function eip712Domain() public view virtual override returns ( bytes1 fields, string memory name, string memory version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] memory extensions ) { return ( hex"0f", // 01111 _name.toStringWithFallback(_nameFallback), _version.toStringWithFallback(_versionFallback), block.chainid, address(this), bytes32(0), new uint256[](0) ); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; import "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value)))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "../../interfaces/IRewardManager.sol"; import "../libraries/ArrayLib.sol"; import "../libraries/TokenHelper.sol"; import "../libraries/math/PMath.sol"; import "./RewardManagerAbstract.sol"; /// NOTE: RewardManager must not have duplicated rewardTokens abstract contract RewardManagerAbstract is IRewardManager, TokenHelper { using PMath for uint256; uint256 internal constant INITIAL_REWARD_INDEX = 1; struct RewardState { uint128 index; uint128 lastBalance; } struct UserReward { uint128 index; uint128 accrued; } // [token] => [user] => (index,accrued) mapping(address => mapping(address => UserReward)) public userReward; function _updateAndDistributeRewards(address user) internal virtual { _updateAndDistributeRewardsForTwo(user, address(0)); } function _updateAndDistributeRewardsForTwo(address user1, address user2) internal virtual { (address[] memory tokens, uint256[] memory indexes) = _updateRewardIndex(); if (tokens.length == 0) return; if (user1 != address(0) && user1 != address(this)) _distributeRewardsPrivate(user1, tokens, indexes); if (user2 != address(0) && user2 != address(this)) _distributeRewardsPrivate(user2, tokens, indexes); } // should only be callable from `_updateAndDistributeRewardsForTwo` to guarantee user != address(0) && user != address(this) function _distributeRewardsPrivate(address user, address[] memory tokens, uint256[] memory indexes) private { assert(user != address(0) && user != address(this)); uint256 userShares = _rewardSharesUser(user); for (uint256 i = 0; i < tokens.length; ++i) { address token = tokens[i]; uint256 index = indexes[i]; uint256 userIndex = userReward[token][user].index; if (userIndex == 0) { userIndex = INITIAL_REWARD_INDEX.Uint128(); } if (userIndex == index) continue; uint256 deltaIndex = index - userIndex; uint256 rewardDelta = userShares.mulDown(deltaIndex); uint256 rewardAccrued = userReward[token][user].accrued + rewardDelta; userReward[token][user] = UserReward({index: index.Uint128(), accrued: rewardAccrued.Uint128()}); } } function _updateRewardIndex() internal virtual returns (address[] memory tokens, uint256[] memory indexes); function _redeemExternalReward() internal virtual; function _doTransferOutRewards( address user, address receiver ) internal virtual returns (uint256[] memory rewardAmounts); function _rewardSharesUser(address user) internal view virtual returns (uint256); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; interface IRewardManager { function userReward(address token, address user) external view returns (uint128 index, uint128 accrued); }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; interface IPInterestManagerYT { event CollectInterestFee(uint256 amountInterestFee); function userInterest(address user) external view returns (uint128 lastPYIndex, uint128 accruedInterest); }
// SPDX-License-Identifier: GPL-3.0-or-later // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. pragma solidity ^0.8.0; /* solhint-disable private-vars-leading-underscore, reason-string */ library PMath { uint256 internal constant ONE = 1e18; // 18 decimal places int256 internal constant IONE = 1e18; // 18 decimal places function subMax0(uint256 a, uint256 b) internal pure returns (uint256) { unchecked { return (a >= b ? a - b : 0); } } function subNoNeg(int256 a, int256 b) internal pure returns (int256) { require(a >= b, "negative"); return a - b; // no unchecked since if b is very negative, a - b might overflow } function mulDown(uint256 a, uint256 b) internal pure returns (uint256) { uint256 product = a * b; unchecked { return product / ONE; } } function mulDown(int256 a, int256 b) internal pure returns (int256) { int256 product = a * b; unchecked { return product / IONE; } } function divDown(uint256 a, uint256 b) internal pure returns (uint256) { uint256 aInflated = a * ONE; unchecked { return aInflated / b; } } function divDown(int256 a, int256 b) internal pure returns (int256) { int256 aInflated = a * IONE; unchecked { return aInflated / b; } } function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) { return (a + b - 1) / b; } // @author Uniswap function sqrt(uint256 y) internal pure returns (uint256 z) { if (y > 3) { z = y; uint256 x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } } else if (y != 0) { z = 1; } } function square(uint256 x) internal pure returns (uint256) { return x * x; } function squareDown(uint256 x) internal pure returns (uint256) { return mulDown(x, x); } function abs(int256 x) internal pure returns (uint256) { return uint256(x > 0 ? x : -x); } function neg(int256 x) internal pure returns (int256) { return x * (-1); } function neg(uint256 x) internal pure returns (int256) { return Int(x) * (-1); } function max(uint256 x, uint256 y) internal pure returns (uint256) { return (x > y ? x : y); } function max(int256 x, int256 y) internal pure returns (int256) { return (x > y ? x : y); } function min(uint256 x, uint256 y) internal pure returns (uint256) { return (x < y ? x : y); } function min(int256 x, int256 y) internal pure returns (int256) { return (x < y ? x : y); } /*/////////////////////////////////////////////////////////////// SIGNED CASTS //////////////////////////////////////////////////////////////*/ function Int(uint256 x) internal pure returns (int256) { require(x <= uint256(type(int256).max)); return int256(x); } function Int128(int256 x) internal pure returns (int128) { require(type(int128).min <= x && x <= type(int128).max); return int128(x); } function Int128(uint256 x) internal pure returns (int128) { return Int128(Int(x)); } /*/////////////////////////////////////////////////////////////// UNSIGNED CASTS //////////////////////////////////////////////////////////////*/ function Uint(int256 x) internal pure returns (uint256) { require(x >= 0); return uint256(x); } function Uint32(uint256 x) internal pure returns (uint32) { require(x <= type(uint32).max); return uint32(x); } function Uint64(uint256 x) internal pure returns (uint64) { require(x <= type(uint64).max); return uint64(x); } function Uint112(uint256 x) internal pure returns (uint112) { require(x <= type(uint112).max); return uint112(x); } function Uint96(uint256 x) internal pure returns (uint96) { require(x <= type(uint96).max); return uint96(x); } function Uint128(uint256 x) internal pure returns (uint128) { require(x <= type(uint128).max); return uint128(x); } function Uint192(uint256 x) internal pure returns (uint192) { require(x <= type(uint192).max); return uint192(x); } function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) { return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps); } function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) { return a >= b && a <= mulDown(b, ONE + eps); } function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) { return a <= b && a >= mulDown(b, ONE - eps); } }
// SPDX-License-Identifier: GPL-3.0-or-later // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated // documentation files (the “Software”), to deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the // Software. // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pragma solidity ^0.8.0; /* solhint-disable */ /** * @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument). * * Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural * exponentiation and logarithm (where the base is Euler's number). * * @author Fernando Martinelli - @fernandomartinelli * @author Sergio Yuhjtman - @sergioyuhjtman * @author Daniel Fernandez - @dmf7z */ library LogExpMath { // All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying // two numbers, and multiply by ONE when dividing them. // All arguments and return values are 18 decimal fixed point numbers. int256 constant ONE_18 = 1e18; // Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the // case of ln36, 36 decimals. int256 constant ONE_20 = 1e20; int256 constant ONE_36 = 1e36; // The domain of natural exponentiation is bound by the word size and number of decimals used. // // Because internally the result will be stored using 20 decimals, the largest possible result is // (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221. // The smallest possible result is 10^(-18), which makes largest negative argument // ln(10^(-18)) = -41.446531673892822312. // We use 130.0 and -41.0 to have some safety margin. int256 constant MAX_NATURAL_EXPONENT = 130e18; int256 constant MIN_NATURAL_EXPONENT = -41e18; // Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point // 256 bit integer. int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17; int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17; uint256 constant MILD_EXPONENT_BOUND = 2 ** 254 / uint256(ONE_20); // 18 decimal constants int256 constant x0 = 128000000000000000000; // 2ˆ7 int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals) int256 constant x1 = 64000000000000000000; // 2ˆ6 int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals) // 20 decimal constants int256 constant x2 = 3200000000000000000000; // 2ˆ5 int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2) int256 constant x3 = 1600000000000000000000; // 2ˆ4 int256 constant a3 = 888611052050787263676000000; // eˆ(x3) int256 constant x4 = 800000000000000000000; // 2ˆ3 int256 constant a4 = 298095798704172827474000; // eˆ(x4) int256 constant x5 = 400000000000000000000; // 2ˆ2 int256 constant a5 = 5459815003314423907810; // eˆ(x5) int256 constant x6 = 200000000000000000000; // 2ˆ1 int256 constant a6 = 738905609893065022723; // eˆ(x6) int256 constant x7 = 100000000000000000000; // 2ˆ0 int256 constant a7 = 271828182845904523536; // eˆ(x7) int256 constant x8 = 50000000000000000000; // 2ˆ-1 int256 constant a8 = 164872127070012814685; // eˆ(x8) int256 constant x9 = 25000000000000000000; // 2ˆ-2 int256 constant a9 = 128402541668774148407; // eˆ(x9) int256 constant x10 = 12500000000000000000; // 2ˆ-3 int256 constant a10 = 113314845306682631683; // eˆ(x10) int256 constant x11 = 6250000000000000000; // 2ˆ-4 int256 constant a11 = 106449445891785942956; // eˆ(x11) /** * @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent. * * Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`. */ function exp(int256 x) internal pure returns (int256) { unchecked { require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, "Invalid exponent"); if (x < 0) { // We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it // fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT). // Fixed point division requires multiplying by ONE_18. return ((ONE_18 * ONE_18) / exp(-x)); } // First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n, // where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7 // because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the // decomposition. // At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this // decomposition, which will be lower than the smallest x_n. // exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1. // We mutate x by subtracting x_n, making it the remainder of the decomposition. // The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause // intermediate overflows. Instead we store them as plain integers, with 0 decimals. // Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the // decomposition. // For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct // it and compute the accumulated product. int256 firstAN; if (x >= x0) { x -= x0; firstAN = a0; } else if (x >= x1) { x -= x1; firstAN = a1; } else { firstAN = 1; // One with no decimal places } // We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the // smaller terms. x *= 100; // `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point // one. Recall that fixed point multiplication requires dividing by ONE_20. int256 product = ONE_20; if (x >= x2) { x -= x2; product = (product * a2) / ONE_20; } if (x >= x3) { x -= x3; product = (product * a3) / ONE_20; } if (x >= x4) { x -= x4; product = (product * a4) / ONE_20; } if (x >= x5) { x -= x5; product = (product * a5) / ONE_20; } if (x >= x6) { x -= x6; product = (product * a6) / ONE_20; } if (x >= x7) { x -= x7; product = (product * a7) / ONE_20; } if (x >= x8) { x -= x8; product = (product * a8) / ONE_20; } if (x >= x9) { x -= x9; product = (product * a9) / ONE_20; } // x10 and x11 are unnecessary here since we have high enough precision already. // Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series // expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!). int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places. int256 term; // Each term in the sum, where the nth term is (x^n / n!). // The first term is simply x. term = x; seriesSum += term; // Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number, // multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not. term = ((term * x) / ONE_20) / 2; seriesSum += term; term = ((term * x) / ONE_20) / 3; seriesSum += term; term = ((term * x) / ONE_20) / 4; seriesSum += term; term = ((term * x) / ONE_20) / 5; seriesSum += term; term = ((term * x) / ONE_20) / 6; seriesSum += term; term = ((term * x) / ONE_20) / 7; seriesSum += term; term = ((term * x) / ONE_20) / 8; seriesSum += term; term = ((term * x) / ONE_20) / 9; seriesSum += term; term = ((term * x) / ONE_20) / 10; seriesSum += term; term = ((term * x) / ONE_20) / 11; seriesSum += term; term = ((term * x) / ONE_20) / 12; seriesSum += term; // 12 Taylor terms are sufficient for 18 decimal precision. // We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor // approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply // all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication), // and then drop two digits to return an 18 decimal value. return (((product * seriesSum) / ONE_20) * firstAN) / 100; } } /** * @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument. */ function ln(int256 a) internal pure returns (int256) { unchecked { // The real natural logarithm is not defined for negative numbers or zero. require(a > 0, "out of bounds"); if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) { return _ln_36(a) / ONE_18; } else { return _ln(a); } } } /** * @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent. * * Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`. */ function pow(uint256 x, uint256 y) internal pure returns (uint256) { unchecked { if (y == 0) { // We solve the 0^0 indetermination by making it equal one. return uint256(ONE_18); } if (x == 0) { return 0; } // Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to // arrive at that r`esult. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means // x^y = exp(y * ln(x)). // The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range. require(x < 2 ** 255, "x out of bounds"); int256 x_int256 = int256(x); // We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In // both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end. // This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range. require(y < MILD_EXPONENT_BOUND, "y out of bounds"); int256 y_int256 = int256(y); int256 logx_times_y; if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) { int256 ln_36_x = _ln_36(x_int256); // ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just // bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal // multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the // (downscaled) last 18 decimals. logx_times_y = ((ln_36_x / ONE_18) * y_int256 + ((ln_36_x % ONE_18) * y_int256) / ONE_18); } else { logx_times_y = _ln(x_int256) * y_int256; } logx_times_y /= ONE_18; // Finally, we compute exp(y * ln(x)) to arrive at x^y require( MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT, "product out of bounds" ); return uint256(exp(logx_times_y)); } } /** * @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument. */ function _ln(int256 a) private pure returns (int256) { unchecked { if (a < ONE_18) { // Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less // than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call. // Fixed point division requires multiplying by ONE_18. return (-_ln((ONE_18 * ONE_18) / a)); } // First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which // we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is, // ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot // be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a. // At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this // decomposition, which will be lower than the smallest a_n. // ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1. // We mutate a by subtracting a_n, making it the remainder of the decomposition. // For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point // numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by // ONE_18 to convert them to fixed point. // For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide // by it and compute the accumulated sum. int256 sum = 0; if (a >= a0 * ONE_18) { a /= a0; // Integer, not fixed point division sum += x0; } if (a >= a1 * ONE_18) { a /= a1; // Integer, not fixed point division sum += x1; } // All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format. sum *= 100; a *= 100; // Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them. if (a >= a2) { a = (a * ONE_20) / a2; sum += x2; } if (a >= a3) { a = (a * ONE_20) / a3; sum += x3; } if (a >= a4) { a = (a * ONE_20) / a4; sum += x4; } if (a >= a5) { a = (a * ONE_20) / a5; sum += x5; } if (a >= a6) { a = (a * ONE_20) / a6; sum += x6; } if (a >= a7) { a = (a * ONE_20) / a7; sum += x7; } if (a >= a8) { a = (a * ONE_20) / a8; sum += x8; } if (a >= a9) { a = (a * ONE_20) / a9; sum += x9; } if (a >= a10) { a = (a * ONE_20) / a10; sum += x10; } if (a >= a11) { a = (a * ONE_20) / a11; sum += x11; } // a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series // that converges rapidly for values of `a` close to one - the same one used in ln_36. // Let z = (a - 1) / (a + 1). // ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1)) // Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires // division by ONE_20. int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20); int256 z_squared = (z * z) / ONE_20; // num is the numerator of the series: the z^(2 * n + 1) term int256 num = z; // seriesSum holds the accumulated sum of each term in the series, starting with the initial z int256 seriesSum = num; // In each step, the numerator is multiplied by z^2 num = (num * z_squared) / ONE_20; seriesSum += num / 3; num = (num * z_squared) / ONE_20; seriesSum += num / 5; num = (num * z_squared) / ONE_20; seriesSum += num / 7; num = (num * z_squared) / ONE_20; seriesSum += num / 9; num = (num * z_squared) / ONE_20; seriesSum += num / 11; // 6 Taylor terms are sufficient for 36 decimal precision. // Finally, we multiply by 2 (non fixed point) to compute ln(remainder) seriesSum *= 2; // We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both // with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal // value. return (sum + seriesSum) / 100; } } /** * @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument, * for x close to one. * * Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND. */ function _ln_36(int256 x) private pure returns (int256) { unchecked { // Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits // worthwhile. // First, we transform x to a 36 digit fixed point value. x *= ONE_18; // We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1). // ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1)) // Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires // division by ONE_36. int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36); int256 z_squared = (z * z) / ONE_36; // num is the numerator of the series: the z^(2 * n + 1) term int256 num = z; // seriesSum holds the accumulated sum of each term in the series, starting with the initial z int256 seriesSum = num; // In each step, the numerator is multiplied by z^2 num = (num * z_squared) / ONE_36; seriesSum += num / 3; num = (num * z_squared) / ONE_36; seriesSum += num / 5; num = (num * z_squared) / ONE_36; seriesSum += num / 7; num = (num * z_squared) / ONE_36; seriesSum += num / 9; num = (num * z_squared) / ONE_36; seriesSum += num / 11; num = (num * z_squared) / ONE_36; seriesSum += num / 13; num = (num * z_squared) / ONE_36; seriesSum += num / 15; // 8 Taylor terms are sufficient for 36 decimal precision. // All that remains is multiplying by 2 (non fixed point). return seriesSum * 2; } } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "../../interfaces/IPYieldToken.sol"; import "../../interfaces/IPPrincipalToken.sol"; import "./SYUtils.sol"; import "../libraries/math/PMath.sol"; type PYIndex is uint256; library PYIndexLib { using PMath for uint256; using PMath for int256; function newIndex(IPYieldToken YT) internal returns (PYIndex) { return PYIndex.wrap(YT.pyIndexCurrent()); } function syToAsset(PYIndex index, uint256 syAmount) internal pure returns (uint256) { return SYUtils.syToAsset(PYIndex.unwrap(index), syAmount); } function assetToSy(PYIndex index, uint256 assetAmount) internal pure returns (uint256) { return SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount); } function assetToSyUp(PYIndex index, uint256 assetAmount) internal pure returns (uint256) { return SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount); } function syToAssetUp(PYIndex index, uint256 syAmount) internal pure returns (uint256) { uint256 _index = PYIndex.unwrap(index); return SYUtils.syToAssetUp(_index, syAmount); } function syToAsset(PYIndex index, int256 syAmount) internal pure returns (int256) { int256 sign = syAmount < 0 ? int256(-1) : int256(1); return sign * (SYUtils.syToAsset(PYIndex.unwrap(index), syAmount.abs())).Int(); } function assetToSy(PYIndex index, int256 assetAmount) internal pure returns (int256) { int256 sign = assetAmount < 0 ? int256(-1) : int256(1); return sign * (SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount.abs())).Int(); } function assetToSyUp(PYIndex index, int256 assetAmount) internal pure returns (int256) { int256 sign = assetAmount < 0 ? int256(-1) : int256(1); return sign * (SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount.abs())).Int(); } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; library MiniHelpers { function isCurrentlyExpired(uint256 expiry) internal view returns (bool) { return (expiry <= block.timestamp); } function isExpired(uint256 expiry, uint256 blockTime) internal pure returns (bool) { return (expiry <= blockTime); } function isTimeInThePast(uint256 timestamp) internal view returns (bool) { return (timestamp <= block.timestamp); // same definition as isCurrentlyExpired } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * The default value of {decimals} is 18. To change this, you should override * this function so it returns a different value. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the default value returned by this function, unless * it's overridden. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer(address from, address to, uint256 amount) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by // decrementing then incrementing. _balances[to] += amount; } emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; unchecked { // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above. _balances[account] += amount; } emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; // Overflow not possible: amount <= accountBalance <= totalSupply. _totalSupply -= amount; } emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance(address owner, address spender, uint256 amount) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/ShortStrings.sol) pragma solidity ^0.8.8; import "./StorageSlot.sol"; // | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | // | length | 0x BB | type ShortString is bytes32; /** * @dev This library provides functions to convert short memory strings * into a `ShortString` type that can be used as an immutable variable. * * Strings of arbitrary length can be optimized using this library if * they are short enough (up to 31 bytes) by packing them with their * length (1 byte) in a single EVM word (32 bytes). Additionally, a * fallback mechanism can be used for every other case. * * Usage example: * * ```solidity * contract Named { * using ShortStrings for *; * * ShortString private immutable _name; * string private _nameFallback; * * constructor(string memory contractName) { * _name = contractName.toShortStringWithFallback(_nameFallback); * } * * function name() external view returns (string memory) { * return _name.toStringWithFallback(_nameFallback); * } * } * ``` */ library ShortStrings { // Used as an identifier for strings longer than 31 bytes. bytes32 private constant _FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF; error StringTooLong(string str); error InvalidShortString(); /** * @dev Encode a string of at most 31 chars into a `ShortString`. * * This will trigger a `StringTooLong` error is the input string is too long. */ function toShortString(string memory str) internal pure returns (ShortString) { bytes memory bstr = bytes(str); if (bstr.length > 31) { revert StringTooLong(str); } return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length)); } /** * @dev Decode a `ShortString` back to a "normal" string. */ function toString(ShortString sstr) internal pure returns (string memory) { uint256 len = byteLength(sstr); // using `new string(len)` would work locally but is not memory safe. string memory str = new string(32); /// @solidity memory-safe-assembly assembly { mstore(str, len) mstore(add(str, 0x20), sstr) } return str; } /** * @dev Return the length of a `ShortString`. */ function byteLength(ShortString sstr) internal pure returns (uint256) { uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF; if (result > 31) { revert InvalidShortString(); } return result; } /** * @dev Encode a string into a `ShortString`, or write it to storage if it is too long. */ function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) { if (bytes(value).length < 32) { return toShortString(value); } else { StorageSlot.getStringSlot(store).value = value; return ShortString.wrap(_FALLBACK_SENTINEL); } } /** * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}. */ function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) { if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) { return toString(value); } else { return store; } } /** * @dev Return the length of a string that was encoded to `ShortString` or written to storage using {setWithFallback}. * * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of * actual characters as the UTF-8 encoding of a single character can span over multiple bytes. */ function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) { if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) { return byteLength(value); } else { return bytes(store).length; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol) pragma solidity ^0.8.0; interface IERC5267 { /** * @dev MAY be emitted to signal that the domain could have changed. */ event EIP712DomainChanged(); /** * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712 * signature. */ function eip712Domain() external view returns ( bytes1 fields, string memory name, string memory version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] memory extensions ); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.0; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; library ArrayLib { function sum(uint256[] memory input) internal pure returns (uint256) { uint256 value = 0; for (uint256 i = 0; i < input.length; ) { value += input[i]; unchecked { i++; } } return value; } /// @notice return index of the element if found, else return uint256.max function find(address[] memory array, address element) internal pure returns (uint256 index) { uint256 length = array.length; for (uint256 i = 0; i < length; ) { if (array[i] == element) return i; unchecked { i++; } } return type(uint256).max; } function append(address[] memory inp, address element) internal pure returns (address[] memory out) { uint256 length = inp.length; out = new address[](length + 1); for (uint256 i = 0; i < length; ) { out[i] = inp[i]; unchecked { i++; } } out[length] = element; } function appendHead(address[] memory inp, address element) internal pure returns (address[] memory out) { uint256 length = inp.length; out = new address[](length + 1); out[0] = element; for (uint256 i = 1; i <= length; ) { out[i] = inp[i - 1]; unchecked { i++; } } } /** * @dev This function assumes a and b each contains unidentical elements * @param a array of addresses a * @param b array of addresses b * @return out Concatenation of a and b containing unidentical elements */ function merge(address[] memory a, address[] memory b) internal pure returns (address[] memory out) { unchecked { uint256 countUnidenticalB = 0; bool[] memory isUnidentical = new bool[](b.length); for (uint256 i = 0; i < b.length; ++i) { if (!contains(a, b[i])) { countUnidenticalB++; isUnidentical[i] = true; } } out = new address[](a.length + countUnidenticalB); for (uint256 i = 0; i < a.length; ++i) { out[i] = a[i]; } uint256 id = a.length; for (uint256 i = 0; i < b.length; ++i) { if (isUnidentical[i]) { out[id++] = b[i]; } } } } // various version of contains function contains(address[] memory array, address element) internal pure returns (bool) { uint256 length = array.length; for (uint256 i = 0; i < length; ) { if (array[i] == element) return true; unchecked { i++; } } return false; } function contains(bytes4[] memory array, bytes4 element) internal pure returns (bool) { uint256 length = array.length; for (uint256 i = 0; i < length; ) { if (array[i] == element) return true; unchecked { i++; } } return false; } function create(address a) internal pure returns (address[] memory res) { res = new address[](1); res[0] = a; } function create(address a, address b) internal pure returns (address[] memory res) { res = new address[](2); res[0] = a; res[1] = b; } function create(address a, address b, address c) internal pure returns (address[] memory res) { res = new address[](3); res[0] = a; res[1] = b; res[2] = c; } function create(uint256 a) internal pure returns (uint256[] memory res) { res = new uint256[](1); res[0] = a; } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "../../interfaces/IWETH.sol"; abstract contract TokenHelper { using SafeERC20 for IERC20; address internal constant NATIVE = address(0); uint256 internal constant LOWER_BOUND_APPROVAL = type(uint96).max / 2; // some tokens use 96 bits for approval function _transferIn(address token, address from, uint256 amount) internal { if (token == NATIVE) require(msg.value == amount, "eth mismatch"); else if (amount != 0) IERC20(token).safeTransferFrom(from, address(this), amount); } function _transferFrom(IERC20 token, address from, address to, uint256 amount) internal { if (amount != 0) token.safeTransferFrom(from, to, amount); } function _transferOut(address token, address to, uint256 amount) internal { if (amount == 0) return; if (token == NATIVE) { (bool success, ) = to.call{value: amount}(""); require(success, "eth send failed"); } else { IERC20(token).safeTransfer(to, amount); } } function _transferOut(address[] memory tokens, address to, uint256[] memory amounts) internal { uint256 numTokens = tokens.length; require(numTokens == amounts.length, "length mismatch"); for (uint256 i = 0; i < numTokens; ) { _transferOut(tokens[i], to, amounts[i]); unchecked { i++; } } } function _selfBalance(address token) internal view returns (uint256) { return (token == NATIVE) ? address(this).balance : IERC20(token).balanceOf(address(this)); } function _selfBalance(IERC20 token) internal view returns (uint256) { return token.balanceOf(address(this)); } /// @notice Approves the stipulated contract to spend the given allowance in the given token /// @dev PLS PAY ATTENTION to tokens that requires the approval to be set to 0 before changing it function _safeApprove(address token, address to, uint256 value) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), "Safe Approve"); } function _safeApproveInf(address token, address to) internal { if (token == NATIVE) return; if (IERC20(token).allowance(address(this), to) < LOWER_BOUND_APPROVAL) { _safeApprove(token, to, 0); _safeApprove(token, to, type(uint256).max); } } function _wrap_unwrap_ETH(address tokenIn, address tokenOut, uint256 netTokenIn) internal { if (tokenIn == NATIVE) IWETH(tokenOut).deposit{value: netTokenIn}(); else IWETH(tokenIn).withdraw(netTokenIn); } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.0; library SYUtils { uint256 internal constant ONE = 1e18; function syToAsset(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) { return (syAmount * exchangeRate) / ONE; } function syToAssetUp(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) { return (syAmount * exchangeRate + ONE - 1) / ONE; } function assetToSy(uint256 exchangeRate, uint256 assetAmount) internal pure returns (uint256) { return (assetAmount * ONE) / exchangeRate; } function assetToSyUp(uint256 exchangeRate, uint256 assetAmount) internal pure returns (uint256) { return (assetAmount * ONE + exchangeRate - 1) / exchangeRate; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol) // This file was procedurally generated from scripts/generate/templates/StorageSlot.js. pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ```solidity * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._ * _Available since v4.9 for `string`, `bytes`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } struct StringSlot { string value; } struct BytesSlot { bytes value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` with member `value` located at `slot`. */ function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` representation of the string storage pointer `store`. */ function getStringSlot(string storage store) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } /** * @dev Returns an `BytesSlot` with member `value` located at `slot`. */ function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`. */ function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value)); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value)); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to * 0 before setting it to a non-zero value. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0)); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token)); } }
// SPDX-License-Identifier: GPL-3.0-or-later /* * MIT License * =========== * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IWETH is IERC20 { event Deposit(address indexed dst, uint256 wad); event Withdrawal(address indexed src, uint256 wad); function deposit() external payable; function withdraw(uint256 wad) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
{ "remappings": [ "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/", "ds-test/=lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "forge-std/=lib/forge-std/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "solmate/=lib/solmate/src/", "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/", "openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/", "openzeppelin/=lib/openzeppelin-contracts/contracts/", "solidity-stringutils/=lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "viaIR": true, "libraries": { "src/core/Market/OracleLib.sol": { "OracleLib": "0x2ff909a1fd086A055931FA6796588c214F13E274" } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_PT","type":"address"},{"internalType":"int256","name":"_scalarRoot","type":"int256"},{"internalType":"int256","name":"_initialAnchor","type":"int256"},{"internalType":"uint80","name":"_lnFeeRateRoot","type":"uint80"},{"internalType":"address","name":"_vePendle","type":"address"},{"internalType":"address","name":"_gaugeController","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[{"internalType":"int256","name":"exchangeRate","type":"int256"}],"name":"MarketExchangeRateBelowOne","type":"error"},{"inputs":[],"name":"MarketExpired","type":"error"},{"inputs":[{"internalType":"int256","name":"currentAmount","type":"int256"},{"internalType":"int256","name":"requiredAmount","type":"int256"}],"name":"MarketInsufficientPtForTrade","type":"error"},{"inputs":[{"internalType":"uint256","name":"actualBalance","type":"uint256"},{"internalType":"uint256","name":"requiredBalance","type":"uint256"}],"name":"MarketInsufficientPtReceived","type":"error"},{"inputs":[{"internalType":"uint256","name":"actualBalance","type":"uint256"},{"internalType":"uint256","name":"requiredBalance","type":"uint256"}],"name":"MarketInsufficientSyReceived","type":"error"},{"inputs":[],"name":"MarketProportionMustNotEqualOne","type":"error"},{"inputs":[{"internalType":"int256","name":"proportion","type":"int256"},{"internalType":"int256","name":"maxProportion","type":"int256"}],"name":"MarketProportionTooHigh","type":"error"},{"inputs":[{"internalType":"int256","name":"rateScalar","type":"int256"}],"name":"MarketRateScalarBelowZero","type":"error"},{"inputs":[{"internalType":"int256","name":"scalarRoot","type":"int256"}],"name":"MarketScalarRootBelowZero","type":"error"},{"inputs":[],"name":"MarketZeroAmountsInput","type":"error"},{"inputs":[],"name":"MarketZeroAmountsOutput","type":"error"},{"inputs":[],"name":"MarketZeroLnImpliedRate","type":"error"},{"inputs":[{"internalType":"int256","name":"totalPt","type":"int256"},{"internalType":"int256","name":"totalAsset","type":"int256"}],"name":"MarketZeroTotalPtOrTotalAsset","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiverSy","type":"address"},{"indexed":true,"internalType":"address","name":"receiverPt","type":"address"},{"indexed":false,"internalType":"uint256","name":"netLpBurned","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netSyOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netPtOut","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"observationCardinalityNextOld","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"observationCardinalityNextNew","type":"uint16"}],"name":"IncreaseObservationCardinalityNext","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"netLpMinted","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netSyUsed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netPtUsed","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"rewardsOut","type":"uint256[]"}],"name":"RedeemRewards","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"int256","name":"netPtOut","type":"int256"},{"indexed":false,"internalType":"int256","name":"netSyOut","type":"int256"},{"indexed":false,"internalType":"uint256","name":"netSyFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"netSyToReserve","type":"uint256"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"timestamp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lnLastImpliedRate","type":"uint256"}],"name":"UpdateImpliedRate","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_storage","outputs":[{"internalType":"int128","name":"totalPt","type":"int128"},{"internalType":"int128","name":"totalSy","type":"int128"},{"internalType":"uint96","name":"lastLnImpliedRate","type":"uint96"},{"internalType":"uint16","name":"observationIndex","type":"uint16"},{"internalType":"uint16","name":"observationCardinality","type":"uint16"},{"internalType":"uint16","name":"observationCardinalityNext","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"activeBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiverSy","type":"address"},{"internalType":"address","name":"receiverPt","type":"address"},{"internalType":"uint256","name":"netLpToBurn","type":"uint256"}],"name":"burn","outputs":[{"internalType":"uint256","name":"netSyOut","type":"uint256"},{"internalType":"uint256","name":"netPtOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"expiry","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNonOverrideLnFeeRateRoot","outputs":[{"internalType":"uint80","name":"","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRewardTokens","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"cardinalityNext","type":"uint16"}],"name":"increaseObservationsCardinalityNext","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isExpired","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastRewardBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"netSyDesired","type":"uint256"},{"internalType":"uint256","name":"netPtDesired","type":"uint256"}],"name":"mint","outputs":[{"internalType":"uint256","name":"netLpOut","type":"uint256"},{"internalType":"uint256","name":"netSyUsed","type":"uint256"},{"internalType":"uint256","name":"netPtUsed","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"observations","outputs":[{"internalType":"uint32","name":"blockTimestamp","type":"uint32"},{"internalType":"uint216","name":"lnImpliedRateCumulative","type":"uint216"},{"internalType":"bool","name":"initialized","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32[]","name":"secondsAgos","type":"uint32[]"}],"name":"observe","outputs":[{"internalType":"uint216[]","name":"lnImpliedRateCumulative","type":"uint216[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"router","type":"address"}],"name":"readState","outputs":[{"components":[{"internalType":"int256","name":"totalPt","type":"int256"},{"internalType":"int256","name":"totalSy","type":"int256"},{"internalType":"int256","name":"totalLp","type":"int256"},{"internalType":"address","name":"treasury","type":"address"},{"internalType":"int256","name":"scalarRoot","type":"int256"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"lnFeeRateRoot","type":"uint256"},{"internalType":"uint256","name":"reserveFeePercent","type":"uint256"},{"internalType":"uint256","name":"lastLnImpliedRate","type":"uint256"}],"internalType":"struct MarketState","name":"market","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"readTokens","outputs":[{"internalType":"contract IStandardizedYield","name":"_SY","type":"address"},{"internalType":"contract IPPrincipalToken","name":"_PT","type":"address"},{"internalType":"contract IPYieldToken","name":"_YT","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"redeemRewards","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardState","outputs":[{"internalType":"uint128","name":"index","type":"uint128"},{"internalType":"uint128","name":"lastBalance","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"skim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"exactPtIn","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"swapExactPtForSy","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":"uint256","name":"exactPtOut","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"swapSyForExactPt","outputs":[{"internalType":"uint256","name":"netSyIn","type":"uint256"},{"internalType":"uint256","name":"netSyFee","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalActiveSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"userReward","outputs":[{"internalType":"uint128","name":"index","type":"uint128"},{"internalType":"uint128","name":"accrued","type":"uint128"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
6103008060405234620005f85760c08162005c618038038091620000248285620009eb565b833981010312620005f8576200003a8162000a0f565b60208201516040830151606084015191936001600160501b0383168303620005f8576200007860a0620000706080840162000a0f565b920162000a0f565b60405163afd27bf560e01b8152906020826004816001600160a01b038a165afa91821562000606576000926200098b575b5060405190620000b982620009cf565b600c82526b121e5c195c8813585c9ad95d60a21b602083015260405191620000e183620009cf565b600983526812165411548b53141560ba1b6020840152604051926200010684620009cf565b60018452603160f81b602085015281516001600160401b0381116200074057600354600181811c9116801562000980575b60208210146200086357601f81116200091a575b50806020601f8211600114620008905760009162000884575b508160011b916000199060031b1c1916176003555b8051906001600160401b038211620007405760045490600182811c9216801562000879575b6020831014620008635781601f849311620007f1575b50602090601f8311600114620007625760009262000756575b50508160011b916000199060031b1c1916176004555b6012608052600280546001600160f81b0316600160f81b179055620002088162000a34565b61014052620002178362000bf8565b6101605260208151910120918261010052602081519101209384610120524660c0526040519460208601937f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8552604087015260608601524660808601523060a086015260a0855260c085019385851060018060401b0386111762000740576040859052855190932060a0523060e052610180929092526001600160a01b039182166101c0526101e0819052635162986d60e11b835260209183916004918391600091165af1918215620006065760009262000701575b50506101a0526001600160a01b03831661020081905260405163afd27bf560e01b815290602090829060049082905afa9081156200060657600091620006bf575b506001600160a01b03908116610220526102005160405163781c18db60e01b81529160209183916004918391165afa90811562000606576000916200067d575b506001600160a01b0316610240526040805163329f6acb60e21b8152600f60048201524263ffffffff1660248201529081604481732ff909a1fd086a055931fa6796588c214f13e2745af490811562000606576000906000926200062b575b50600e805463ffffffff60701b191660809390931b61ffff60801b169290921760709190911b61ffff60701b161790556000841315620006125790602092916004946102a0526102c0526102e052604051928380926370c264df60e11b825260018060a01b03165afa9081156200060657600091620005c9575b50610280523361026052604051614eb062000db18239608051816114d0015260a05181612eb0015260c05181612f7b015260e05181612e7a01526101005181612eff01526101205181612f2501526101405181610e5601526101605181610e80015261018051818181613184015261444a01526101a051816131b801526101c051818181611ff2015261493301526101e051816144820152610200518181816103780152818161131101528181611577015281816116ff015281816119ce0152611d890152610220518181816103ac0152818161119b01528181611552015281816116c70152818161183601528181611a0f0152611d420152610240518181816111100152818161159e015281816116350152611b3b01526102605181818161081e015261265d015261028051818181610573015281816110dc0152818161150d0152818161160101528181611b0701526126fa01526102a051816126d701526102c05181611ef201526102e05181818161053701526126b20152614eb090f35b90506020813d602011620005fd575b81620005e760209383620009eb565b81010312620005f857513862000448565b600080fd5b3d9150620005d8565b6040513d6000823e3d90fd5b60405163483512b160e11b815260048101859052602490fd5b9150506040813d60401162000674575b816200064a60409383620009eb565b81010312620005f8576200066c6020620006648362000a24565b920162000a24565b9038620003ce565b3d91506200063b565b90506020813d602011620006b6575b816200069b60209383620009eb565b81010312620005f857620006af9062000a0f565b386200036f565b3d91506200068c565b90506020813d602011620006f8575b81620006dd60209383620009eb565b81010312620005f857620006f19062000a0f565b386200032f565b3d9150620006ce565b6020809293503d831162000738575b6200071c8185620009eb565b81010312620005f857620007309062000a0f565b3880620002ee565b503d62000710565b634e487b7160e01b600052604160045260246000fd5b015190503880620001cd565b6004600090815293507f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b91905b601f1984168510620007d5576001945083601f19811610620007bb575b505050811b01600455620001e3565b015160001960f88460031b161c19169055388080620007ac565b818101518355602094850194600190930192909101906200078f565b60046000529091507f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b601f840160051c8101602085106200085b575b90849392915b601f830160051c820181106200084b575050620001b4565b6000815585945060010162000833565b50806200082d565b634e487b7160e01b600052602260045260246000fd5b91607f16916200019e565b90508301513862000164565b6003600090815292507fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b905b601f198316841062000901576001935082601f19811610620008e7575b5050811b0160035562000179565b85015160001960f88460031b161c191690553880620008d9565b85810151825560209384019360019092019101620008bc565b60036000527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b601f830160051c81016020841062000978575b601f830160051c820181106200096b5750506200014b565b6000815560010162000953565b508062000953565b90607f169062000137565b9091506020813d602011620009c6575b81620009aa60209383620009eb565b81010312620005f857620009be9062000a0f565b9038620000a9565b3d91506200099b565b604081019081106001600160401b038211176200074057604052565b601f909101601f19168101906001600160401b038211908210176200074057604052565b51906001600160a01b0382168203620005f857565b519061ffff82168203620005f857565b8051602091908281101562000ad3575090601f82511162000a72578082519201519080831062000a6357501790565b82600019910360031b1b161790565b90604051809263305a27a960e01b82528060048301528251908160248401526000935b82851062000ab9575050604492506000838284010152601f80199101168101030190fd5b848101820151868601604401529381019385935062000a95565b6001600160401b03811162000740576005928354926001938481811c9116801562000bed575b838210146200086357601f811162000bb6575b5081601f841160011462000b4c575092829391839260009462000b40575b50501b916000199060031b1c191617905560ff90565b01519250388062000b2a565b919083601f1981168760005284600020946000905b8883831062000b9b575050501062000b81575b505050811b01905560ff90565b015160001960f88460031b161c1916905538808062000b74565b85870151885590960195948501948793509081019062000b61565b8560005284601f846000209201871c820191601f8601881c015b82811062000be057505062000b0c565b6000815501859062000bd0565b90607f169062000af9565b80516020908181101562000c865750601f82511162000c25578082519201519080831062000a6357501790565b90604051809263305a27a960e01b82528060048301528251908160248401526000935b82851062000c6c575050604492506000838284010152601f80199101168101030190fd5b848101820151868601604401529381019385935062000c48565b906001600160401b0382116200074057600654926001938481811c9116801562000da5575b838210146200086357601f811162000d6b575b5081601f841160011462000cff575092829391839260009462000cf3575b50501b916000199060031b1c19161760065560ff90565b01519250388062000cdc565b919083601f198116600660005284600020946000905b8883831062000d50575050501062000d36575b505050811b0160065560ff90565b015160001960f88460031b161c1916905538808062000d28565b85870151885590960195948501948793509081019062000d15565b600660005284601f84600020920160051c820191601f860160051c015b82811062000d9857505062000cbe565b6000815501859062000d88565b90607f169062000cab56fe608080604052600436101561001357600080fd5b60e0600035811c91826306fdde031461227f575081630892cd8b14612245578163095ea7b314612214578163156e29f614611ac657816318160ddd14611a9d5781631dd19cb41461198357816323b872dd146118b1578163252c09d71461186257816329910b11146115c55781632c8ce6bc146115325781632f13b60c146114f4578163313ce567146114b65781633644e5151461149b57816337d45e3a1461134f5781635b709f171461109f5781635cbadbe41461103857816370a0823114610ff75781637206926414610fd9578163794052f314610f535781637ecebe0014610f1957816384b0196e14610e40578163883bdbfd14610c025781639262187b14610a1757816395d89b4114610934578163a9059cbb146108cd578163a9f8d181146108af578163c3fb90d61461084d578163c45a015514610808578163c4f59f9b146107a1578163d505accf146105e757508063dd62ed3e14610596578063e184c9be1461055b578063e4f8b2e914610514578063ea64a820146104be5763f6b911bc146101a257600080fd5b346103d8576101b036612396565b600292918354936101c6818660f81c1415612500565b6001600160f81b03948516600160f91b1781556101e2336125af565b94301561046f576101f230613e68565b306000526020926000845260406000205485811061041f5785903060005260008652036040600020558185116103d8578254828616838216038381116104095783169060ff60f81b161783556000604051868152600080516020614e5b833981519152863092a361026230613f11565b6001600160ff1b0385116103d85784156103f75783870195610285875187612e54565b9561029660408a0197885190613325565b976102ad6102a58b5184612e54565b895190613325565b978915806103ef575b6103dd576102c5838251613fea565b90526102d2888b51613fea565b8a526102df898251613fea565b9052600088126103d857600087126103d857877f4cf25bc1d991c17529c25213d3cc0cda295eeaad5f13f361969b12ea48015f909161034560409b60018060a01b0380871696853089036103a5575b50508b81891698308a03610372575b505050612956565b8a51908152602081019190915260408101889052606090a3815416600160f81b1790558351928352820152f35b61039d927f000000000000000000000000000000000000000000000000000000000000000016612b00565b388b8161033d565b6103d191837f000000000000000000000000000000000000000000000000000000000000000016612b00565b388561032e565b600080fd5b604051631997ea8d60e31b8152600490fd5b5088156102b6565b6040516325daaec360e01b8152600490fd5b634e487b7160e01b600052601160045260246000fd5b60405162461bcd60e51b815260048101869052602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608490fd5b60405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608490fd5b346103d85760203660031901126103d8576001600160a01b036104df61236a565b166000908152600a60209081526040918290205482516001600160801b038216815260809190911c91810191909152f35b0390f35b346103d85760003660031901126103d857602060405169ffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b346103d85760003660031901126103d85760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b346103d85760403660031901126103d8576105af61236a565b6105b7612380565b9060018060a01b038091166000526001602052604060002091166000526020526020604060002054604051908152f35b346103d857806003193601126103d8576105ff61236a565b90610608612380565b604435916084359060643560ff831683036103d85780421161075c5760018060a01b0391828716938460005260076020526040600020918254926001840190556040519360208501937f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98552876040870152868916606087015289608087015260a086015260c085015260c084528301918383106001600160401b03841117610746576106f0936106e8936040525190206106c1612e77565b906040519161190160f01b83526002830152602282015260c43591604260a4359220613a1b565b919091613aaa565b1603610701576106ff926127e0565b005b60405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606490fd5b634e487b7160e01b600052604160045260246000fd5b60405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606490fd5b346103d85760003660031901126103d8576107ba613165565b6040518091602080830160208452825180915260206040850193019160005b8281106107e857505050500390f35b83516001600160a01b0316855286955093810193928101926001016107d9565b346103d85760003660031901126103d8576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b346103d85760003660031901126103d85760c0600d54600e5461ffff906040519280600f0b845260801d600f0b60208401526001600160601b0381166040840152818160601c166060840152818160701c16608084015260801c1660a0820152f35b346103d85760003660031901126103d8576020600954604051908152f35b346103d85760403660031901126103d8576108e661236a565b61091b600254916108fd60028460f81c1415612500565b6001600160f81b03928316600160f91b176002556024359033612c37565b600160f81b906002541617600255602060405160018152f35b346103d85760003660031901126103d857604051600454600082610957836124c6565b91828252602093600190856001821691826000146109f757505060011461099a575b506109869250038361248e565b61051060405192828493845283019061232a565b84915060046000527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b906000915b8583106109df575050610986935082010185610979565b805483890185015287945086939092019181016109c8565b60ff19168582015261098695151560051b85010192508791506109799050565b346103d8576020806003193601126103d857610a3161236a565b9060025490610a4660028360f81c1415612500565b6001600160f81b03918216600160f91b17600255610a6383613e68565b610a6c83613f11565b610a74613165565b92610a7f84516127ae565b6001600160a01b03949091908582169060005b8151811015610ba55787610aa682846139ac565b5116600052600890818752604060002084600052875260406000205491608092831c610ad283896139ac565b52610add82886139ac565b51610aee575b506001915001610a92565b89610af983866139ac565b5116600052875260406000208460005287526040600020916001600160801b0392838154169055610b2a82886139ac565b51908382116103d8578a610b3e84876139ac565b5116600052600a89528360406000209216908254901c0392831161040957600192610b7d91906001600160801b0382549181199060801b169116179055565b610b9f89610b8b83866139ac565b511686610b98848a6139ac565b5191613f77565b89610ae3565b848688857f78d61a0c27b13f43911095f9f356f14daa3cd8b125eea1aa22421245e90e813d60405184815280610bdd8682018861242c565b0390a2600160f81b90600254161760025561051060405192828493845283019061242c565b346103d8576020806003193601126103d8576001600160401b036004358181116103d857366023820112156103d8578060040135610c3f816124af565b91610c4d604051938461248e565b8183528483016024819360051b830101913683116103d857602401905b828210610e245750505063ffffffff91600e5461ffff90604051948593630eea10e760e11b855260c4850190600f6004870152824216602487015260c060448701525180915260e4850195916000905b8a838310610e07578a88600081808d8c8c6001600160601b0381166064850152818160601c16608485015260701c1660a48301520381732ff909a1fd086a055931fa6796588c214f13e2745af4918215610dfb57600092610d64575b5050906040519181839283018184528251809152816040850193019160005b828110610d4457505050500390f35b83516001600160d81b031685528695509381019392810192600101610d35565b9091503d806000843e610d77818461248e565b82019183818403126103d85780519182116103d857019080601f830112156103d8578151610da4816124af565b92610db2604051948561248e565b818452848085019260051b8201019283116103d8578401905b828210610ddc575050508280610d16565b81516001600160d81b03811681036103d8578152908401908401610dcb565b6040513d6000823e3d90fd5b845182168952978801978997509093019260019190910190610cba565b813563ffffffff811681036103d8578152908601908601610c6a565b346103d85760003660031901126103d857610e7a7f0000000000000000000000000000000000000000000000000000000000000000612fa1565b90610ea47f00000000000000000000000000000000000000000000000000000000000000006130a5565b604051602081018181106001600160401b038211176107465761051092610ef89160405260008352610eea604051968796600f60f81b885280602089015287019061232a565b90858203604087015261232a565b90466060850152306080850152600060a085015283820360c085015261242c565b346103d85760203660031901126103d8576001600160a01b03610f3a61236a565b1660005260076020526020604060002054604051908152f35b346103d85760203660031901126103d85761012090610f78610f7361236a565b6125af565b6040519181518352602082015160208401526040820151604084015260018060a01b0360608301511660608401526080820151608084015260a082015160a084015260c082015160c084015280820151908301526101008091015190820152f35b346103d85760003660031901126103d8576020600b54604051908152f35b346103d85760203660031901126103d857602061103061101561236a565b6001600160a01b031660009081526020819052604090205490565b604051908152f35b346103d85760403660031901126103d85761105161236a565b611059612380565b6001600160a01b0391821660009081526008602090815260408083209390941682529182528290205482516001600160801b038216815260809190911c91810191909152f35b346103d8576110ad366123cb565b92600292919254906110c560028360f81c1415612500565b6001600160f81b03918216600160f91b17600255427f0000000000000000000000000000000000000000000000000000000000000000111561133d5761110a336125af565b926111347f00000000000000000000000000000000000000000000000000000000000000006128e2565b936001600160ff1b039081831190816103d85761115761116197854291846135b3565b9a91989098612e20565b9860008a126103d857600089126103d85760008b126103d8576001600160a01b038781169790929087308a0361130a575b50506111c88c847f0000000000000000000000000000000000000000000000000000000000000000169460608701511685612b00565b6111d184612956565b806112a5575b505060206111e482612ac5565b920191825190600082126103d857106112745750506103d85785116103d8577f829000a5bc6a12d46e30cdcecd7c56b1efd88f6d7d059da6734a04f3764557c48460409761125761123489612e20565b8a5195865260208601526040850192909252606084015233929081906080820190565b0390a3600160f81b90600254161760025582519182526020820152f35b61127d90612ac5565b905190600082126103d8576044916040519163f62951c760e01b835260048301526024820152fd5b6000945090858b116103d8576112ba8b612e20565b90333b156103d8576000916112e46040519485938493637d241f3960e11b85528c60048601612559565b038183335af18015610dfb576112fb575b806111d7565b61130490612460565b8a6112f5565b61133691857f000000000000000000000000000000000000000000000000000000000000000016612b00565b8c87611192565b60405163b2094b5960e01b8152600490fd5b346103d8576020806003193601126103d8576004359061ffff918281168091036103d8576002549261138760028560f81c1415612500565b6001600160f81b03938416600160f91b17600255600e54604051632c3e6e0360e11b8152600f600482015260809190911c821660248201819052604482019390935291908383606481732ff909a1fd086a055931fa6796588c214f13e2745af4928315610dfb57600093611464575b508216808203611411575b600280548616600160f81b179055005b7fac49e518f90a358f652e4400164f05a5d8f7e35e7747279bc3a93dbf584e125a93604093600e549061ffff60801b9060801b169061ffff60801b191617600e558351928352820152a181808080611401565b9092508381813d8311611494575b61147c818361248e565b810103126103d85761148d9061258c565b91856113f6565b503d611472565b346103d85760003660031901126103d8576020611030612e77565b346103d85760003660031901126103d857602060405160ff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b346103d85760003660031901126103d8576020604051427f000000000000000000000000000000000000000000000000000000000000000011158152f35b346103d85760003660031901126103d857606060405160018060a01b03807f0000000000000000000000000000000000000000000000000000000000000000168252807f00000000000000000000000000000000000000000000000000000000000000001660208301527f0000000000000000000000000000000000000000000000000000000000000000166040820152f35b346103d8576115d3366123cb565b909192600254906115ea60028360f81c1415612500565b6001600160f81b03918216600160f91b17600255427f0000000000000000000000000000000000000000000000000000000000000000111561133d5761162f336125af565b946116597f00000000000000000000000000000000000000000000000000000000000000006128e2565b6001600160ff1b03919082821190816103d85761168290429061167b85612e20565b908b6135b3565b999198909760008a126103d857600089126103d85760008b126103d8576001600160a01b03878116979092908b308a0361182f575b50506116ec8c84606087015116857f000000000000000000000000000000000000000000000000000000000000000016612b00565b6116f584612956565b816117c9575b50507f00000000000000000000000000000000000000000000000000000000000000001661172881612ac5565b825190600082126103d857106117985750506103d85761174790612e20565b9085116103d8576040805191825260208201869052818101859052606082019690965233907f829000a5bc6a12d46e30cdcecd7c56b1efd88f6d7d059da6734a04f3764557c4908060808101611257565b6117a190612ac5565b905190600082126103d85760449160405191632c49ea0f60e01b835260048301526024820152fd5b60009450906117d786612e20565b90878c116103d857333b156103d8576000916118098d926040519586948594637d241f3960e11b865260048601612559565b038183335af18015610dfb57611820575b806116fb565b61182990612460565b8a61181a565b61185b91857f000000000000000000000000000000000000000000000000000000000000000016612b00565b8c8b6116b7565b346103d85760203660031901126103d85760043561ffff8110156103d857606090600f01546040519063ffffffff8116825260018060d81b038160201c16602083015260f81c15156040820152f35b346103d8576118bf36612396565b600292919254926118d660028560f81c1415612500565b6001600160f81b03938416600160f91b176002556001600160a01b03831660009081526001602081815260408084203385529091529091205493908401611922575b61091b9350612c37565b82841061193e576119398361091b950333836127e0565b611918565b60405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606490fd5b346103d85760003660031901126103d8576002546119a760028260f81c1415612500565b6001600160f81b03908116600160f91b176002556119c4336125af565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081166119f881612ac5565b8351600081126103d857611a0b9161254c565b91807f00000000000000000000000000000000000000000000000000000000000000001691611a3983612ac5565b6020860151600081126103d857611a4f9161254c565b9380611a85575b505082611a6d57600280548616600160f81b179055005b6060611a7c9401511690612b00565b81808080611401565b611a96918360608801511690612b00565b8580611a56565b346103d85760003660031901126103d8576002546040516001600160f81b039091168152602090f35b346103d85760603660031901126103d857611adf61236a565b600254611af260028260f81c1415612500565b6001600160f81b0316600160f91b17600255427f0000000000000000000000000000000000000000000000000000000000000000111561133d57611b35336125af565b90611b5f7f00000000000000000000000000000000000000000000000000000000000000006128e2565b6001600160ff1b03602435116103d8576001600160ff1b03604435116103d857600060243515801561220a575b6103f7574260a0850151111561133d57604084015180612183575050611bb6604435602435612e54565b600081126103d857600060038211156121755750808060011c60018101811161040957600101905b82821061215b5750505b6001600160ff1b0381116103d8576103e719810190811360011661040957916103e89360243594604435935b60008613156103dd57611c2b876020850151613392565b6020840152611c3b858451613392565b8352611c54611c4a8388613392565b6040850151613392565b6040840152600082126103d857600086126103d857600087126103d857600085126103d85781611ec3575b50506001600160a01b03821615611e7e57611c9982613e68565b6001600160f81b0384116103d8576002546001600160f81b038082168682160111610409576001600160f81b031981166001600160f81b0391821686831601909116176002556001600160a01b03821660009081526020819052604090208054611d04908690612949565b90556040518481526001600160a01b03831690600090600080516020614e5b83398151915290602090a3611d3782613f11565b611d4081612956565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316611d7381612ac5565b602083015190600082126103d85710611e4a57507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316611dba81612ac5565b825190600082126103d85710611798575050604080518481526020810186905290810183905261051092916001600160a01b0316907fb4c03061fb5b7fed76389d5af8f2e0ddb09f8c70d1333abbb62582835e10accb90606090a2600280546001600160f81b0316600160f81b179055604080519384526020840194909452928201929092529081906060820190565b611e55602091612ac5565b91015190600082126103d8576044916040519163f62951c760e01b835260048301526024820152fd5b60405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606490fd5b4260a0840151111561133d57611ee1611f24916020850151906133ae565b611eef4260a086015161254c565b907f000000000000000000000000000000000000000000000000000000000000000090611f1c838761340d565b90865161346e565b610100830152611f32613d0d565b6001600160f81b0381116103d8576002546001600160f81b03808216818416019291908311610409576020600092600080516020614e5b83398151915292600195868060f81b03169060ff60f81b161760025584845283825260408420611f9a828254612949565b9055604051908152a3306001141580611fb4575b80611c7f565b611fbd906147a1565b6001600052600060205260406000205460405163389a2ce960e21b815260016004820152604081602481600060018060a01b037f0000000000000000000000000000000000000000000000000000000000000000165af18015610dfb57600091600091612114575b50826028810204602814831517156104095760646028840204916001600160801b0381166120be575b5050908082106000146120b757505b6120828161207d600b546001600052600c6020526040600020549061254c565b612949565b600b556001600052600c6020527fd421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5c5585611fae565b905061205d565b6002546120eb926001600160801b03928316926120e6929116906001600160f81b03166133fa565b613464565b9081603c810204603c1482151715610409576064603c61210d93020490612949565b878061204e565b9150506040813d604011612153575b816121306040938361248e565b810103126103d85761214d602061214683614e46565b9201614e46565b88612025565b3d9150612123565b90915061216c8261207d8184613464565b60011c90611bde565b9015611be857506001611be8565b61219761219f916044969593949635612e54565b845190613325565b926121b06040820151602435612e54565b926121c16020830194855190613325565b808612156121ec57506121e66121db866044359651612e54565b604084015190613325565b95611c14565b959350935084936122046121db602435978451612e54565b93611c14565b5060443515611b8c565b346103d85760403660031901126103d85761223a61223061236a565b60243590336127e0565b602060405160018152f35b346103d85760203660031901126103d8576001600160a01b0361226661236a565b16600052600c6020526020604060002054604051908152f35b346103d85760003660031901126103d85760035460008261229f836124c6565b91828252602093600190856001821691826000146109f75750506001146122cd57506109869250038361248e565b84915060036000527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b906000915b858310612312575050610986935082010185610979565b805483890185015287945086939092019181016122fb565b919082519283825260005b848110612356575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201612335565b600435906001600160a01b03821682036103d857565b602435906001600160a01b03821682036103d857565b60609060031901126103d8576001600160a01b039060043582811681036103d8579160243590811681036103d8579060443590565b9060606003198301126103d8576004356001600160a01b03811681036103d85791602435916044356001600160401b03928382116103d857806023830112156103d85781600401359384116103d857602484830101116103d8576024019190565b90815180825260208080930193019160005b82811061244c575050505090565b83518552938101939281019260010161243e565b6001600160401b03811161074657604052565b604081019081106001600160401b0382111761074657604052565b90601f801991011681019081106001600160401b0382111761074657604052565b6001600160401b0381116107465760051b60200190565b90600182811c921680156124f6575b60208310146124e057565b634e487b7160e01b600052602260045260246000fd5b91607f16916124d5565b1561250757565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b9190820391821161040957565b928492608095928552602085015260606040850152816060850152848401376000828201840152601f01601f1916010190565b519061ffff821682036103d857565b51906001600160a01b03821682036103d857565b90604080519261012084018481106001600160401b0382111761074657825260608401600090818152608086019180835260a087019381855260c088019282845260e089018381526101008a01978489528a600d5480600f0b825260801d600f0b602082015260018060f81b03600254169060018060ff1b038211612790578201528051635c098c1160e01b81523060048201526001600160a01b03948516602482015293916060856044817f000000000000000000000000000000000000000000000000000000000000000087165afa80156127a457869287968892612730575b505060ff16905216905269ffffffffffffffffffff915080821661272b57507f00000000000000000000000000000000000000000000000000000000000000005b1690527f000000000000000000000000000000000000000000000000000000000000000090527f000000000000000000000000000000000000000000000000000000000000000090526001600160601b03600e54169052565b6126d2565b93509550506060823d60601161279c575b8161274e6060938361248e565b810103126127985761275f8261259b565b9460208301519269ffffffffffffffffffff841684036127945701519460ff8616860361279057919460ff38612691565b8680fd5b8780fd5b8580fd5b3d9150612741565b82513d88823e3d90fd5b906127b8826124af565b6127c5604051918261248e565b82815280926127d6601f19916124af565b0190602036910137565b6001600160a01b0390811691821561289157169182156128415760207f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925918360005260018252604060002085600052825280604060002055604051908152a3565b60405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608490fd5b60405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b604051630754bb7160e21b815290602090829060049082906000906001600160a01b03165af1908115610dfb5760009161291a575090565b90506020813d602011612941575b816129356020938361248e565b810103126103d8575190565b3d9150612928565b9190820180921161040957565b610100810180516001600160601b03928382116103d857612984602061297c8351613585565b920151613585565b90600e549161ffff9560409687519463095ee96d60e31b8652600f6004870152818160601c16602487015263ffffffff421660448701528281166064870152818160701c16608487015260801c1660a4850152868460c481732ff909a1fd086a055931fa6796588c214f13e2745af4928315612aba57600094600094612a76575b506001600160801b0319809360801b16906001600160801b031617600d55600e549261ffff60701b9060701b1694169116179061ffff60601b9060601b161717600e555190519081527f5c0e21d57bb4cf91d8fe238d6f92e2685a695371b19209afcce6217b478f83e160204292a2565b945092508684813d8111612ab3575b612a8f818361248e565b810103126103d857612aac6020612aa58661258c565b950161258c565b9238612a05565b503d612a85565b87513d6000823e3d90fd5b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa908115610dfb5760009161291a575090565b90604051602081019363a9059cbb60e01b855260018060a01b03809316602483015260448201526044815260808101918183106001600160401b0384111761074657612b9993836040521690612b5583612473565b602083527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656460a0820152600080958192519082855af1612b93613f38565b91614a80565b908151918215928315612c09575b50505015612bb157565b60405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608490fd5b819293509060209181010312612c335760200151908115158203612c305750388080612ba7565b80fd5b5080fd5b9091906001600160a01b03808216908115612dcd578416928315612d7c57838214612d3757612c668584613eaf565b600090828252816020526040822054818110612ce3576020826040858795600080516020614e5b83398151915295878c9952828652038282205586815220612caf828254612949565b9055604051908152a33003612cd4575b503003612cc95750565b612cd2906148f0565b565b612cdd906148f0565b38612cbf565b60405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608490fd5b60405162461bcd60e51b815260206004820152601760248201527f45524332303a207472616e7366657220746f2073656c660000000000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608490fd5b60405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608490fd5b908160000391808305600019149015171561040957565b90670de0b6b3a76400009182810292818405149015171561040957565b818102929160008212600160ff1b82141661040957818405149015171561040957565b307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03161480612f78575b15612ed2577f000000000000000000000000000000000000000000000000000000000000000090565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527f000000000000000000000000000000000000000000000000000000000000000060408201527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260a0815260c081018181106001600160401b038211176107465760405251902090565b507f00000000000000000000000000000000000000000000000000000000000000004614612ea9565b60ff8114612fdf5760ff811690601f8211612fcd5760405191612fc383612473565b8252602082015290565b604051632cd44ac360e21b8152600490fd5b50604051600554816000612ff2836124c6565b808352926020906001908181169081156130815750600114613020575b505061301d9250038261248e565b90565b91509260056000527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0936000925b828410613069575061301d945050508101602001388061300f565b8554878501830152948501948694509281019261304e565b9150506020925061301d94915060ff191682840152151560051b820101388061300f565b60ff81146130c75760ff811690601f8211612fcd5760405191612fc383612473565b506040516006548160006130da836124c6565b80835292602090600190818116908115613081575060011461310457505061301d9250038261248e565b91509260066000527ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f936000925b82841061314d575061301d945050508101602001388061300f565b85548785018301529485019486945092810192613132565b60405163c4f59f9b60e01b81526000906001600160a01b0382826004817f000000000000000000000000000000000000000000000000000000000000000085165afa91821561331a57839261327c575b507f0000000000000000000000000000000000000000000000000000000000000000916131e283826139d6565b61327557805190600190600183019586841161326157613201876124af565b9661320f604051988961248e565b80885261321e601f19916124af565b013660208901375b8381106132415750505061323a90846139ac565b9116905290565b808561324e8593856139ac565b511661325a828a6139ac565b5201613226565b634e487b7160e01b81526011600452602490fd5b9250505090565b9091503d8084833e61328e818361248e565b8101906020908181840312613316578051906001600160401b03821161279857019180601f840112156133165782516132c6816124af565b936132d4604051958661248e565b818552838086019260051b820101928311612790578301905b8282106132ff575050505090386131b5565b83809161330b8461259b565b8152019101906132ed565b8480fd5b6040513d85823e3d90fd5b811561334057600160ff1b8114600019831416610409570590565b634e487b7160e01b600052601260045260246000fd5b90670de0b6b3a76400006000838203931281841281169184139015161761040957565b8181039291600013801582851316918412161761040957565b9190916000838201938412911290801582169115161761040957565b6133d7670de0b6b3a764000091600084126000146133ef576133d260001994613bc4565b6133fa565b046001600160ff1b0381116103d85761301d91612e54565b6133d2600194613bc4565b8181029291811591840414171561040957565b60800151906301e1338091828102928184051490151715610409576001600160ff1b0381116103d85761343f91613325565b90600082131561344b57565b604051630e520c3b60e11b815260048101839052602490fd5b8115613340570490565b94939291906000958681126135555761349361348d6134989383613392565b91612e37565b613bfb565b670d529ae9e860000080821361353757506134c792916134936134bd6134c293613ffb565b612e37565b613392565b670de0b6b3a7640000811261351f576134df90613c05565b83811261351b576301e13380908181029181830414901517156135075761301d929350613464565b634e487b7160e01b84526011600452602484fd5b8380fd5b6024906040519063329e322960e21b82526004820152fd5b6044925060405191637e34684f60e11b835260048301526024820152fd5b60405162461bcd60e51b81526020600482015260086024820152676e6567617469766560c01b6044820152606490fd5b8060016001607f1b03191315806135a2575b156103d857600f0b90565b5060016001607f1b03811315613597565b93909360a0810194848651111561133d5781518481131561398e5750604091825194608086018681106001600160401b0382111761074657845260009586815260208101938785528582019088825260608301948986528a8c51111561397d5761361e8b8d5161254c565b95613629878361340d565b8552602082019661363b8851856133ae565b808a5283519081158015613975575b61395857505082516101008401998a5192808251938a51956136726301e133809485926133fa565b6001600160ff1b03979190048781116139515761368e90614b5c565b91670de0b6b3a764000096878412613937576136ce926134936134bd6136c38561349361348d6136c8976136da9c9b99613392565b613ffb565b90613379565b8a5260c08801516133fa565b0483811161393357906136ed8a92614b5c565b8552613712865191519161349361348d8c519461370c8d519785613fea565b93613392565b670d529ae9e8600000808213613916575061373792916134936134bd6134c293613ffb565b8181126138ff578d90613755613750826134938d612e37565b612e20565b9451918a13156138da578161349361376c92612e37565b8281126138c357506137876137818392613356565b85612e54565b059c5b60e0850151838111612c33578e60646137a66137ad9383612e54565b0595613379565b9181831280156138ab57156138a0576137c860001993613bc4565b81810291818304149015171561388c57866137e291612949565b600019810190811161388c57866137f891613464565b928311612c3057506138159161380d91612e54565b9b5b8461436a565b90613820908461436a565b9a8b919c819e51906138319161254c565b9683519061383e91613fea565b835287519161384c91613392565b61385591613fea565b8096525194613863916133ae565b91519051916138719461346e565b8091521561387c5750565b51635534d70f60e11b8152600490fd5b634e487b7160e01b82526011600452602482fd5b6137c8600193613bc4565b50505061381591506138bd908561436a565b9b61380f565b6024908d519063329e322960e21b82526004820152fd5b50613750816138f46138ee6138f994613356565b87612e54565b613325565b9c61378a565b6024908c519063329e322960e21b82526004820152fd5b604492508e5191637e34684f60e11b835260048301526024820152fd5b8e80fd5b5050506024908f519063329e322960e21b82526004820152fd5b5050508f80fd5b604492508b519163b1c4aefb60e01b835260048301526024820152fd5b50801561364a565b875163b2094b5960e01b8152600490fd5b6044908560405191632185509b60e21b835260048301526024820152fd5b80518210156139c05760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b9081519160005b8381106139ed5750505050600090565b6001600160a01b0380613a0083856139ac565b511690841614613a12576001016139dd565b50505050600190565b9291907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311613a9e5791608094939160ff602094604051948552168484015260408301526060820152600093849182805260015afa15613a915781516001600160a01b03811615613a8b579190565b50600190565b50604051903d90823e3d90fd5b50505050600090600390565b6005811015613bae5780613abb5750565b60018103613b085760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606490fd5b60028103613b555760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606490fd5b600314613b5e57565b60405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608490fd5b634e487b7160e01b600052602160045260246000fd5b600080821315613bd2575090565b600160ff1b8214613261570390565b8015613340576ec097ce7bc90715b34b9f10000000000590565b8115613340570590565b6000811315613cd85780670c7d713b49da00001280613cc7575b15613cbe57670de0b6b3a7640000906ec097ce7bc90715b34b9f100000000090613c62908302828101906ec097ce7bc90715b34b9f0fffffffff19018302613bfb565b9080828002059181838202058284820205838582020591848684020593858786020595808888020597880205600f900596600d900595600b900594600990059360079005926005900591600390050101010101010160011b0590565b61301d90614034565b50670f43fc2c04ee00008112613c1f565b60405162461bcd60e51b815260206004820152600d60248201526c6f7574206f6620626f756e647360981b6044820152606490fd5b613d156143f7565b815115613e6457600190308214159081613d30575b50505050565b613d3d83959493926147a1565b6000828152602090600c8252604091828220549582985b613d65575b50505050839450613d2a565b8051891015613e5f576001600160a01b03613d808a836139ac565b511698613d8d81876139ac565b519980855260089081855286862089875285526001600160801b038088882054168015613e58575b8d8114613e485781613dfb8f92613ddf8f613dd9670de0b6b3a7640000938761254c565b906133fa565b04858b52868a528d8c8c20908c528a528b8b205460801c612949565b9111612794578181116127945792613e3f92828c9d9e9f93958d97968c5195613e2387612473565b16855216888401528852865287872084885286528787206143c5565b01989796613d54565b5050505086979899508690613e3f565b5089613db5565b613d59565b5050565b613e706143f7565b90805115613eaa576001600160a01b0383168015159081613e9f575b50613e9657505050565b612cd2926147be565b905030141538613e8c565b505050565b613eb76143f7565b91815115613d2a576001600160a01b039083838284168015159081613f06575b50613ef5575b50505083168015159081613e9f5750613e9657505050565b613efe926147be565b388383613edd565b905030141538613ed7565b6001600160a01b0381168015159081613f2d575b50612cc95750565b905030141538613f25565b3d15613f72573d906001600160401b0382116107465760405191613f66601f8201601f19166020018461248e565b82523d6000602084013e565b606090565b9190918115613eaa576001600160a01b03169182613fe1576000809350809281925af1613fa2613f38565b5015613faa57565b60405162461bcd60e51b815260206004820152600f60248201526e195d1a081cd95b990819985a5b1959608a1b6044820152606490fd5b612cd292612b00565b908082126135555761301d91613379565b670de0b6b3a764000081146140225761401d8161349361348d61301d94613356565b613c05565b60405163a9c8b14d60e01b8152600490fd5b670de0b6b3a764000081126143535760649060007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c0000000000000821215614328575b73011798004d755d3c8bc8e03204cf44619e000000821215614307575b820290808302906e01855144814a7ff805980ff008400090818312156142e4575b50506b02df0ab5a80a22c61ab5a700808212156142c4575b50693f1fce3da636ea5cf850808212156142a4575b50690127fa27722cc06cc5e280821215614284575b5068280e60114edb805d0380821215614264575b50680ebc5fb417461211108082121561424d575b506808f00f760a4b2db55d8082121561422d575b506806f5f17757889379378082121561420d575b506806248f33704b286603808212156141ee575b506805c548670b9510e7ac808212156141cf575b5061418e68056bc75e2d6310000091828082019168056bc75e2d630fffff190102613bfb565b9080828002059181838202058284820205916003600560076009600b888a89020598808b8b02059a8b0205059805960594059205010101010160011b010590565b68056bc75e2d631000006756bc75e2d631000092020591019038614168565b68056bc75e2d6310000067ad78ebc5ac62000092020591019038614154565b68056bc75e2d6310000068015af1d78b58c4000092020591019038614140565b68056bc75e2d631000006802b5e3af16b18800009202059101903861412c565b68056bc75e2d631000008092020591019038614118565b68056bc75e2d63100000680ad78ebc5ac620000092020591019038614104565b68056bc75e2d631000006815af1d78b58c400000920205910190386140f0565b68056bc75e2d63100000682b5e3af16b18800000920205910190386140db565b68056bc75e2d631000006856bc75e2d631000000920205910190386140c6565b68ad78ebc5ac62000000925069021e19e0c9bab2400000020591019038806140ae565b906b1425982cf597cd205cef73806803782dace9d90000009105910161408d565b50770195e54c5dd42177f53a27172fa9ec63026282700000000090056806f05b59d3b2000000614070565b61435f61436491613be1565b614034565b60000390565b60008212156143ba5761437f60001992613bc4565b90670de0b6b3a764000091828102928184041490151715610409576143a391613464565b6001600160ff1b0381116103d85761301d91612e54565b61437f600192613bc4565b815160209092015160801b6fffffffffffffffffffffffffffffffff19166001600160801b0392909216919091179055565b6143ff613165565b9061440a82516127ae565b918051926000931561479b57600954431461474c5743600955600b54604051633bd73ee360e21b81523060048083019190915295919291908181602481837f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af180156146b8576146c3575b507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316803b15612c33578180916004604051809481936358f3d16360e01b83525af180156146b8576146a9575b5090815b84518110156146a0576001600160a01b036144f382876139ac565b511690818452600a918260205260408520906040519161451283612473565b546001600160801b038116808452608082901c6020909401939093526001600160a01b03614540858b6139ac565b51168061462d5750614557475b8260801c9061254c565b6001600160801b03821615614624575b886145db575b6001600160801b0384116103d8576145879160801c612949565b6001600160801b0381116103d8576001946145ca926001600160801b03604051936145b185612473565b81871685521660208401528852602052604087206143c5565b6145d482856139ac565b52016144d8565b92670de0b6b3a764000080850290858204148515171561460f57906146038a61460993613464565b90612949565b9261456d565b60118d634e487b7160e01b6000525260246000fd5b60019350614567565b60208c6024604051809481936370a0823160e01b835230908301525afa8015614695578890614661575b614557915061454d565b506020813d60201161468d575b8161467b6020938361248e565b810103126103d8576145579051614657565b3d915061466e565b6040513d8a823e3d90fd5b50939294505050565b6146b290612460565b386144d4565b6040513d84823e3d90fd5b3d8083833e6146d2818361248e565b8101602091828183031261351b578051906001600160401b038211613316570181601f8201121561351b57805190838061470b846124af565b614718604051918261248e565b848152019260051b820101928311613316578301905b82821061473d5750505061447f565b8151815290830190830161472e565b9092805b8451811015614796576001906001600160a01b0361476e82886139ac565b51168352600a6020526001600160801b0360408420541661478f82866139ac565b5201614750565b505090565b92509190565b156147a857565b634e487b7160e01b600052600160045260246000fd5b909291906001600160a01b03908116801515806148e6575b6147df906147a1565b600094818652602090600c82526040938488205491885b81518110156148da578261480a82846139ac565b5116908a614818828b6139ac565b5183825260088089528a83208a845289526001600160801b0394858c8520541680156148d2575b8381146148c457670de0b6b3a764000061486561485f614880938761254c565b8c6133fa565b04828652838c528d86208d87528c528d86205460801c612949565b93868411612c3057868511612c3057866148be956001988f51966148a388612473565b168652168b850152528852898d20898e528852898d206143c5565b016147f6565b5050505050600191506148be565b50600161483f565b50505050505050509050565b50308114156147d6565b6001600160a01b03818116916149129083151580614a76575b611015906147a1565b90604091825163389a2ce960e21b81528460048201528381602481600080977f0000000000000000000000000000000000000000000000000000000000000000165af1908115614a6c5783908492614a2b575b506001600160801b03809116906028840284810460281485151715614a17576064900492826149d2575b505050908082106000146149ca5750925b6149bc8461207d600b54848652600c602052868620549061254c565b600b558152600c6020522055565b9050926149a0565b6002546149ee93926120e69216906001600160f81b03166133fa565b603c810290808204603c149015171561350757906064614a0f920490612949565b38808061498f565b634e487b7160e01b86526011600452602486fd5b809250858092503d8311614a65575b614a44818361248e565b81010312614a6157614a5a602061214683614e46565b9038614965565b8280fd5b503d614a3a565b84513d85823e3d90fd5b5030841415614909565b91929015614ae25750815115614a94575090565b3b15614a9d5790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b825190915015614af55750805190602001fd5b60405162461bcd60e51b815260206004820152908190614b1990602483019061232a565b0390fd5b15614b2457565b60405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a5908195e1c1bdb995b9d60821b6044820152606490fd5b680238fd42c5cf03ffff1981121580614e33575b614b7990614b1d565b60008112614e1e576064906806f05b59d3b20000008112614dd1576806f05b59d3b1ffffff190168056bc75e2d6310000082770195e54c5dd42177f53a27172fa9ec630262827000000000925b02819068ad78ebc5ac62000000811215614dae575b6856bc75e2d631000000811215614d8a575b682b5e3af16b18800000811215614d68575b6815af1d78b58c400000811215614d46575b680ad78ebc5ac6200000811215614d25575b82811215614d04575b6802b5e3af16b1880000811215614ce3575b68015af1d78b58c40000811215614cc2575b60028382800205058360038184840205056004828583020505600583868302050560068487830205056007858883020505906008868984020505926009878a8602050594600a888b8802050596600b898c8a02050599600c8a8d8d0205059b0101010101010101010101010205020590565b6806f5f1775788937937839168015af1d78b58c3ffff190192020590614c50565b6808f00f760a4b2db55d83916802b5e3af16b187ffff190192020590614c3e565b680ebc5fb41746121110839168056bc75e2d630fffff190192020590614c2c565b68280e60114edb805d038391680ad78ebc5ac61fffff190192020590614c23565b690127fa27722cc06cc5e283916815af1d78b58c3fffff190192020590614c11565b693f1fce3da636ea5cf8508391682b5e3af16b187fffff190192020590614bff565b6b02df0ab5a80a22c61ab5a70083916856bc75e2d630ffffff190192020590614bed565b6e01855144814a7ff805980ff0084000915068ad78ebc5ac61ffffff1901614bdb565b6803782dace9d90000008112614e0b576803782dace9d8ffffff190168056bc75e2d63100000826b1425982cf597cd205cef738092614bc6565b68056bc75e2d6310000082600192614bc6565b614e2a90600003614b5c565b61301d90613be1565b5068070c1cc73b00c80000811315614b70565b51906001600160801b03821682036103d85756feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220385eee72d78a9a48b16b43034becf97da5e6792d13a3cc687ce44c2354ac3d0464736f6c634300081600330000000000000000000000001cde6a099a1cb14f3093d2b7cb5b7cbb2145cb64000000000000000000000000000000000000000000000001180d3169d90e98000000000000000000000000000000000000000000000000000eac898fbed23600000000000000000000000000000000000000000000000000000aa466489d62c000000000000000000000000049fe8c5ced2d50303b0899cef3d56f69d604f0880000000000000000000000003c0763930a3cfd3c7e9b9b33aeabdc1fa1a60d4c
Deployed Bytecode
0x608080604052600436101561001357600080fd5b60e0600035811c91826306fdde031461227f575081630892cd8b14612245578163095ea7b314612214578163156e29f614611ac657816318160ddd14611a9d5781631dd19cb41461198357816323b872dd146118b1578163252c09d71461186257816329910b11146115c55781632c8ce6bc146115325781632f13b60c146114f4578163313ce567146114b65781633644e5151461149b57816337d45e3a1461134f5781635b709f171461109f5781635cbadbe41461103857816370a0823114610ff75781637206926414610fd9578163794052f314610f535781637ecebe0014610f1957816384b0196e14610e40578163883bdbfd14610c025781639262187b14610a1757816395d89b4114610934578163a9059cbb146108cd578163a9f8d181146108af578163c3fb90d61461084d578163c45a015514610808578163c4f59f9b146107a1578163d505accf146105e757508063dd62ed3e14610596578063e184c9be1461055b578063e4f8b2e914610514578063ea64a820146104be5763f6b911bc146101a257600080fd5b346103d8576101b036612396565b600292918354936101c6818660f81c1415612500565b6001600160f81b03948516600160f91b1781556101e2336125af565b94301561046f576101f230613e68565b306000526020926000845260406000205485811061041f5785903060005260008652036040600020558185116103d8578254828616838216038381116104095783169060ff60f81b161783556000604051868152600080516020614e5b833981519152863092a361026230613f11565b6001600160ff1b0385116103d85784156103f75783870195610285875187612e54565b9561029660408a0197885190613325565b976102ad6102a58b5184612e54565b895190613325565b978915806103ef575b6103dd576102c5838251613fea565b90526102d2888b51613fea565b8a526102df898251613fea565b9052600088126103d857600087126103d857877f4cf25bc1d991c17529c25213d3cc0cda295eeaad5f13f361969b12ea48015f909161034560409b60018060a01b0380871696853089036103a5575b50508b81891698308a03610372575b505050612956565b8a51908152602081019190915260408101889052606090a3815416600160f81b1790558351928352820152f35b61039d927f0000000000000000000000001cde6a099a1cb14f3093d2b7cb5b7cbb2145cb6416612b00565b388b8161033d565b6103d191837f00000000000000000000000013293dacab830d8fa2e0e961fb997b3f37186f4616612b00565b388561032e565b600080fd5b604051631997ea8d60e31b8152600490fd5b5088156102b6565b6040516325daaec360e01b8152600490fd5b634e487b7160e01b600052601160045260246000fd5b60405162461bcd60e51b815260048101869052602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608490fd5b60405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608490fd5b346103d85760203660031901126103d8576001600160a01b036104df61236a565b166000908152600a60209081526040918290205482516001600160801b038216815260809190911c91810191909152f35b0390f35b346103d85760003660031901126103d857602060405169ffffffffffffffffffff7f000000000000000000000000000000000000000000000000000aa466489d62c0168152f35b346103d85760003660031901126103d85760206040517f00000000000000000000000000000000000000000000000000000000667cab808152f35b346103d85760403660031901126103d8576105af61236a565b6105b7612380565b9060018060a01b038091166000526001602052604060002091166000526020526020604060002054604051908152f35b346103d857806003193601126103d8576105ff61236a565b90610608612380565b604435916084359060643560ff831683036103d85780421161075c5760018060a01b0391828716938460005260076020526040600020918254926001840190556040519360208501937f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98552876040870152868916606087015289608087015260a086015260c085015260c084528301918383106001600160401b03841117610746576106f0936106e8936040525190206106c1612e77565b906040519161190160f01b83526002830152602282015260c43591604260a4359220613a1b565b919091613aaa565b1603610701576106ff926127e0565b005b60405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606490fd5b634e487b7160e01b600052604160045260246000fd5b60405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606490fd5b346103d85760003660031901126103d8576107ba613165565b6040518091602080830160208452825180915260206040850193019160005b8281106107e857505050500390f35b83516001600160a01b0316855286955093810193928101926001016107d9565b346103d85760003660031901126103d8576040517f00000000000000000000000096a6c433078059577f0ceb707d596a5f81d643756001600160a01b03168152602090f35b346103d85760003660031901126103d85760c0600d54600e5461ffff906040519280600f0b845260801d600f0b60208401526001600160601b0381166040840152818160601c166060840152818160701c16608084015260801c1660a0820152f35b346103d85760003660031901126103d8576020600954604051908152f35b346103d85760403660031901126103d8576108e661236a565b61091b600254916108fd60028460f81c1415612500565b6001600160f81b03928316600160f91b176002556024359033612c37565b600160f81b906002541617600255602060405160018152f35b346103d85760003660031901126103d857604051600454600082610957836124c6565b91828252602093600190856001821691826000146109f757505060011461099a575b506109869250038361248e565b61051060405192828493845283019061232a565b84915060046000527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b906000915b8583106109df575050610986935082010185610979565b805483890185015287945086939092019181016109c8565b60ff19168582015261098695151560051b85010192508791506109799050565b346103d8576020806003193601126103d857610a3161236a565b9060025490610a4660028360f81c1415612500565b6001600160f81b03918216600160f91b17600255610a6383613e68565b610a6c83613f11565b610a74613165565b92610a7f84516127ae565b6001600160a01b03949091908582169060005b8151811015610ba55787610aa682846139ac565b5116600052600890818752604060002084600052875260406000205491608092831c610ad283896139ac565b52610add82886139ac565b51610aee575b506001915001610a92565b89610af983866139ac565b5116600052875260406000208460005287526040600020916001600160801b0392838154169055610b2a82886139ac565b51908382116103d8578a610b3e84876139ac565b5116600052600a89528360406000209216908254901c0392831161040957600192610b7d91906001600160801b0382549181199060801b169116179055565b610b9f89610b8b83866139ac565b511686610b98848a6139ac565b5191613f77565b89610ae3565b848688857f78d61a0c27b13f43911095f9f356f14daa3cd8b125eea1aa22421245e90e813d60405184815280610bdd8682018861242c565b0390a2600160f81b90600254161760025561051060405192828493845283019061242c565b346103d8576020806003193601126103d8576001600160401b036004358181116103d857366023820112156103d8578060040135610c3f816124af565b91610c4d604051938461248e565b8183528483016024819360051b830101913683116103d857602401905b828210610e245750505063ffffffff91600e5461ffff90604051948593630eea10e760e11b855260c4850190600f6004870152824216602487015260c060448701525180915260e4850195916000905b8a838310610e07578a88600081808d8c8c6001600160601b0381166064850152818160601c16608485015260701c1660a48301520381732ff909a1fd086a055931fa6796588c214f13e2745af4918215610dfb57600092610d64575b5050906040519181839283018184528251809152816040850193019160005b828110610d4457505050500390f35b83516001600160d81b031685528695509381019392810192600101610d35565b9091503d806000843e610d77818461248e565b82019183818403126103d85780519182116103d857019080601f830112156103d8578151610da4816124af565b92610db2604051948561248e565b818452848085019260051b8201019283116103d8578401905b828210610ddc575050508280610d16565b81516001600160d81b03811681036103d8578152908401908401610dcb565b6040513d6000823e3d90fd5b845182168952978801978997509093019260019190910190610cba565b813563ffffffff811681036103d8578152908601908601610c6a565b346103d85760003660031901126103d857610e7a7f4879706572204d61726b6574000000000000000000000000000000000000000c612fa1565b90610ea47f31000000000000000000000000000000000000000000000000000000000000016130a5565b604051602081018181106001600160401b038211176107465761051092610ef89160405260008352610eea604051968796600f60f81b885280602089015287019061232a565b90858203604087015261232a565b90466060850152306080850152600060a085015283820360c085015261242c565b346103d85760203660031901126103d8576001600160a01b03610f3a61236a565b1660005260076020526020604060002054604051908152f35b346103d85760203660031901126103d85761012090610f78610f7361236a565b6125af565b6040519181518352602082015160208401526040820151604084015260018060a01b0360608301511660608401526080820151608084015260a082015160a084015260c082015160c084015280820151908301526101008091015190820152f35b346103d85760003660031901126103d8576020600b54604051908152f35b346103d85760203660031901126103d857602061103061101561236a565b6001600160a01b031660009081526020819052604090205490565b604051908152f35b346103d85760403660031901126103d85761105161236a565b611059612380565b6001600160a01b0391821660009081526008602090815260408083209390941682529182528290205482516001600160801b038216815260809190911c91810191909152f35b346103d8576110ad366123cb565b92600292919254906110c560028360f81c1415612500565b6001600160f81b03918216600160f91b17600255427f00000000000000000000000000000000000000000000000000000000667cab80111561133d5761110a336125af565b926111347f000000000000000000000000c878aeb90e6c35d81a8ceaa8dbb89b35aee81c876128e2565b936001600160ff1b039081831190816103d85761115761116197854291846135b3565b9a91989098612e20565b9860008a126103d857600089126103d85760008b126103d8576001600160a01b038781169790929087308a0361130a575b50506111c88c847f00000000000000000000000013293dacab830d8fa2e0e961fb997b3f37186f46169460608701511685612b00565b6111d184612956565b806112a5575b505060206111e482612ac5565b920191825190600082126103d857106112745750506103d85785116103d8577f829000a5bc6a12d46e30cdcecd7c56b1efd88f6d7d059da6734a04f3764557c48460409761125761123489612e20565b8a5195865260208601526040850192909252606084015233929081906080820190565b0390a3600160f81b90600254161760025582519182526020820152f35b61127d90612ac5565b905190600082126103d8576044916040519163f62951c760e01b835260048301526024820152fd5b6000945090858b116103d8576112ba8b612e20565b90333b156103d8576000916112e46040519485938493637d241f3960e11b85528c60048601612559565b038183335af18015610dfb576112fb575b806111d7565b61130490612460565b8a6112f5565b61133691857f0000000000000000000000001cde6a099a1cb14f3093d2b7cb5b7cbb2145cb6416612b00565b8c87611192565b60405163b2094b5960e01b8152600490fd5b346103d8576020806003193601126103d8576004359061ffff918281168091036103d8576002549261138760028560f81c1415612500565b6001600160f81b03938416600160f91b17600255600e54604051632c3e6e0360e11b8152600f600482015260809190911c821660248201819052604482019390935291908383606481732ff909a1fd086a055931fa6796588c214f13e2745af4928315610dfb57600093611464575b508216808203611411575b600280548616600160f81b179055005b7fac49e518f90a358f652e4400164f05a5d8f7e35e7747279bc3a93dbf584e125a93604093600e549061ffff60801b9060801b169061ffff60801b191617600e558351928352820152a181808080611401565b9092508381813d8311611494575b61147c818361248e565b810103126103d85761148d9061258c565b91856113f6565b503d611472565b346103d85760003660031901126103d8576020611030612e77565b346103d85760003660031901126103d857602060405160ff7f0000000000000000000000000000000000000000000000000000000000000012168152f35b346103d85760003660031901126103d8576020604051427f00000000000000000000000000000000000000000000000000000000667cab8011158152f35b346103d85760003660031901126103d857606060405160018060a01b03807f00000000000000000000000013293dacab830d8fa2e0e961fb997b3f37186f46168252807f0000000000000000000000001cde6a099a1cb14f3093d2b7cb5b7cbb2145cb641660208301527f000000000000000000000000c878aeb90e6c35d81a8ceaa8dbb89b35aee81c87166040820152f35b346103d8576115d3366123cb565b909192600254906115ea60028360f81c1415612500565b6001600160f81b03918216600160f91b17600255427f00000000000000000000000000000000000000000000000000000000667cab80111561133d5761162f336125af565b946116597f000000000000000000000000c878aeb90e6c35d81a8ceaa8dbb89b35aee81c876128e2565b6001600160ff1b03919082821190816103d85761168290429061167b85612e20565b908b6135b3565b999198909760008a126103d857600089126103d85760008b126103d8576001600160a01b03878116979092908b308a0361182f575b50506116ec8c84606087015116857f00000000000000000000000013293dacab830d8fa2e0e961fb997b3f37186f4616612b00565b6116f584612956565b816117c9575b50507f0000000000000000000000001cde6a099a1cb14f3093d2b7cb5b7cbb2145cb641661172881612ac5565b825190600082126103d857106117985750506103d85761174790612e20565b9085116103d8576040805191825260208201869052818101859052606082019690965233907f829000a5bc6a12d46e30cdcecd7c56b1efd88f6d7d059da6734a04f3764557c4908060808101611257565b6117a190612ac5565b905190600082126103d85760449160405191632c49ea0f60e01b835260048301526024820152fd5b60009450906117d786612e20565b90878c116103d857333b156103d8576000916118098d926040519586948594637d241f3960e11b865260048601612559565b038183335af18015610dfb57611820575b806116fb565b61182990612460565b8a61181a565b61185b91857f00000000000000000000000013293dacab830d8fa2e0e961fb997b3f37186f4616612b00565b8c8b6116b7565b346103d85760203660031901126103d85760043561ffff8110156103d857606090600f01546040519063ffffffff8116825260018060d81b038160201c16602083015260f81c15156040820152f35b346103d8576118bf36612396565b600292919254926118d660028560f81c1415612500565b6001600160f81b03938416600160f91b176002556001600160a01b03831660009081526001602081815260408084203385529091529091205493908401611922575b61091b9350612c37565b82841061193e576119398361091b950333836127e0565b611918565b60405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606490fd5b346103d85760003660031901126103d8576002546119a760028260f81c1415612500565b6001600160f81b03908116600160f91b176002556119c4336125af565b6001600160a01b037f0000000000000000000000001cde6a099a1cb14f3093d2b7cb5b7cbb2145cb6481166119f881612ac5565b8351600081126103d857611a0b9161254c565b91807f00000000000000000000000013293dacab830d8fa2e0e961fb997b3f37186f461691611a3983612ac5565b6020860151600081126103d857611a4f9161254c565b9380611a85575b505082611a6d57600280548616600160f81b179055005b6060611a7c9401511690612b00565b81808080611401565b611a96918360608801511690612b00565b8580611a56565b346103d85760003660031901126103d8576002546040516001600160f81b039091168152602090f35b346103d85760603660031901126103d857611adf61236a565b600254611af260028260f81c1415612500565b6001600160f81b0316600160f91b17600255427f00000000000000000000000000000000000000000000000000000000667cab80111561133d57611b35336125af565b90611b5f7f000000000000000000000000c878aeb90e6c35d81a8ceaa8dbb89b35aee81c876128e2565b6001600160ff1b03602435116103d8576001600160ff1b03604435116103d857600060243515801561220a575b6103f7574260a0850151111561133d57604084015180612183575050611bb6604435602435612e54565b600081126103d857600060038211156121755750808060011c60018101811161040957600101905b82821061215b5750505b6001600160ff1b0381116103d8576103e719810190811360011661040957916103e89360243594604435935b60008613156103dd57611c2b876020850151613392565b6020840152611c3b858451613392565b8352611c54611c4a8388613392565b6040850151613392565b6040840152600082126103d857600086126103d857600087126103d857600085126103d85781611ec3575b50506001600160a01b03821615611e7e57611c9982613e68565b6001600160f81b0384116103d8576002546001600160f81b038082168682160111610409576001600160f81b031981166001600160f81b0391821686831601909116176002556001600160a01b03821660009081526020819052604090208054611d04908690612949565b90556040518481526001600160a01b03831690600090600080516020614e5b83398151915290602090a3611d3782613f11565b611d4081612956565b7f00000000000000000000000013293dacab830d8fa2e0e961fb997b3f37186f466001600160a01b0316611d7381612ac5565b602083015190600082126103d85710611e4a57507f0000000000000000000000001cde6a099a1cb14f3093d2b7cb5b7cbb2145cb646001600160a01b0316611dba81612ac5565b825190600082126103d85710611798575050604080518481526020810186905290810183905261051092916001600160a01b0316907fb4c03061fb5b7fed76389d5af8f2e0ddb09f8c70d1333abbb62582835e10accb90606090a2600280546001600160f81b0316600160f81b179055604080519384526020840194909452928201929092529081906060820190565b611e55602091612ac5565b91015190600082126103d8576044916040519163f62951c760e01b835260048301526024820152fd5b60405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606490fd5b4260a0840151111561133d57611ee1611f24916020850151906133ae565b611eef4260a086015161254c565b907f0000000000000000000000000000000000000000000000000eac898fbed2360090611f1c838761340d565b90865161346e565b610100830152611f32613d0d565b6001600160f81b0381116103d8576002546001600160f81b03808216818416019291908311610409576020600092600080516020614e5b83398151915292600195868060f81b03169060ff60f81b161760025584845283825260408420611f9a828254612949565b9055604051908152a3306001141580611fb4575b80611c7f565b611fbd906147a1565b6001600052600060205260406000205460405163389a2ce960e21b815260016004820152604081602481600060018060a01b037f00000000000000000000000049fe8c5ced2d50303b0899cef3d56f69d604f088165af18015610dfb57600091600091612114575b50826028810204602814831517156104095760646028840204916001600160801b0381166120be575b5050908082106000146120b757505b6120828161207d600b546001600052600c6020526040600020549061254c565b612949565b600b556001600052600c6020527fd421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5c5585611fae565b905061205d565b6002546120eb926001600160801b03928316926120e6929116906001600160f81b03166133fa565b613464565b9081603c810204603c1482151715610409576064603c61210d93020490612949565b878061204e565b9150506040813d604011612153575b816121306040938361248e565b810103126103d85761214d602061214683614e46565b9201614e46565b88612025565b3d9150612123565b90915061216c8261207d8184613464565b60011c90611bde565b9015611be857506001611be8565b61219761219f916044969593949635612e54565b845190613325565b926121b06040820151602435612e54565b926121c16020830194855190613325565b808612156121ec57506121e66121db866044359651612e54565b604084015190613325565b95611c14565b959350935084936122046121db602435978451612e54565b93611c14565b5060443515611b8c565b346103d85760403660031901126103d85761223a61223061236a565b60243590336127e0565b602060405160018152f35b346103d85760203660031901126103d8576001600160a01b0361226661236a565b16600052600c6020526020604060002054604051908152f35b346103d85760003660031901126103d85760035460008261229f836124c6565b91828252602093600190856001821691826000146109f75750506001146122cd57506109869250038361248e565b84915060036000527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b906000915b858310612312575050610986935082010185610979565b805483890185015287945086939092019181016122fb565b919082519283825260005b848110612356575050826000602080949584010152601f8019910116010190565b602081830181015184830182015201612335565b600435906001600160a01b03821682036103d857565b602435906001600160a01b03821682036103d857565b60609060031901126103d8576001600160a01b039060043582811681036103d8579160243590811681036103d8579060443590565b9060606003198301126103d8576004356001600160a01b03811681036103d85791602435916044356001600160401b03928382116103d857806023830112156103d85781600401359384116103d857602484830101116103d8576024019190565b90815180825260208080930193019160005b82811061244c575050505090565b83518552938101939281019260010161243e565b6001600160401b03811161074657604052565b604081019081106001600160401b0382111761074657604052565b90601f801991011681019081106001600160401b0382111761074657604052565b6001600160401b0381116107465760051b60200190565b90600182811c921680156124f6575b60208310146124e057565b634e487b7160e01b600052602260045260246000fd5b91607f16916124d5565b1561250757565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b9190820391821161040957565b928492608095928552602085015260606040850152816060850152848401376000828201840152601f01601f1916010190565b519061ffff821682036103d857565b51906001600160a01b03821682036103d857565b90604080519261012084018481106001600160401b0382111761074657825260608401600090818152608086019180835260a087019381855260c088019282845260e089018381526101008a01978489528a600d5480600f0b825260801d600f0b602082015260018060f81b03600254169060018060ff1b038211612790578201528051635c098c1160e01b81523060048201526001600160a01b03948516602482015293916060856044817f00000000000000000000000096a6c433078059577f0ceb707d596a5f81d6437587165afa80156127a457869287968892612730575b505060ff16905216905269ffffffffffffffffffff915080821661272b57507f000000000000000000000000000000000000000000000000000aa466489d62c05b1690527f000000000000000000000000000000000000000000000001180d3169d90e980090527f00000000000000000000000000000000000000000000000000000000667cab8090526001600160601b03600e54169052565b6126d2565b93509550506060823d60601161279c575b8161274e6060938361248e565b810103126127985761275f8261259b565b9460208301519269ffffffffffffffffffff841684036127945701519460ff8616860361279057919460ff38612691565b8680fd5b8780fd5b8580fd5b3d9150612741565b82513d88823e3d90fd5b906127b8826124af565b6127c5604051918261248e565b82815280926127d6601f19916124af565b0190602036910137565b6001600160a01b0390811691821561289157169182156128415760207f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925918360005260018252604060002085600052825280604060002055604051908152a3565b60405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608490fd5b60405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608490fd5b604051630754bb7160e21b815290602090829060049082906000906001600160a01b03165af1908115610dfb5760009161291a575090565b90506020813d602011612941575b816129356020938361248e565b810103126103d8575190565b3d9150612928565b9190820180921161040957565b610100810180516001600160601b03928382116103d857612984602061297c8351613585565b920151613585565b90600e549161ffff9560409687519463095ee96d60e31b8652600f6004870152818160601c16602487015263ffffffff421660448701528281166064870152818160701c16608487015260801c1660a4850152868460c481732ff909a1fd086a055931fa6796588c214f13e2745af4928315612aba57600094600094612a76575b506001600160801b0319809360801b16906001600160801b031617600d55600e549261ffff60701b9060701b1694169116179061ffff60601b9060601b161717600e555190519081527f5c0e21d57bb4cf91d8fe238d6f92e2685a695371b19209afcce6217b478f83e160204292a2565b945092508684813d8111612ab3575b612a8f818361248e565b810103126103d857612aac6020612aa58661258c565b950161258c565b9238612a05565b503d612a85565b87513d6000823e3d90fd5b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa908115610dfb5760009161291a575090565b90604051602081019363a9059cbb60e01b855260018060a01b03809316602483015260448201526044815260808101918183106001600160401b0384111761074657612b9993836040521690612b5583612473565b602083527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656460a0820152600080958192519082855af1612b93613f38565b91614a80565b908151918215928315612c09575b50505015612bb157565b60405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608490fd5b819293509060209181010312612c335760200151908115158203612c305750388080612ba7565b80fd5b5080fd5b9091906001600160a01b03808216908115612dcd578416928315612d7c57838214612d3757612c668584613eaf565b600090828252816020526040822054818110612ce3576020826040858795600080516020614e5b83398151915295878c9952828652038282205586815220612caf828254612949565b9055604051908152a33003612cd4575b503003612cc95750565b612cd2906148f0565b565b612cdd906148f0565b38612cbf565b60405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608490fd5b60405162461bcd60e51b815260206004820152601760248201527f45524332303a207472616e7366657220746f2073656c660000000000000000006044820152606490fd5b60405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608490fd5b60405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608490fd5b908160000391808305600019149015171561040957565b90670de0b6b3a76400009182810292818405149015171561040957565b818102929160008212600160ff1b82141661040957818405149015171561040957565b307f0000000000000000000000006b61cfce05aaf44eba5da45def48c0fbd26390a16001600160a01b03161480612f78575b15612ed2577fe105bb20bcd78e37c25c71c807cab4560179ff861258839aea609058836bc4c190565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527f5e06d78dcce90a459971b996197e4a5adc575456efb81bba67e58bbf2d2c8e5360408201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260a0815260c081018181106001600160401b038211176107465760405251902090565b507f0000000000000000000000000000000000000000000000000000000000013e314614612ea9565b60ff8114612fdf5760ff811690601f8211612fcd5760405191612fc383612473565b8252602082015290565b604051632cd44ac360e21b8152600490fd5b50604051600554816000612ff2836124c6565b808352926020906001908181169081156130815750600114613020575b505061301d9250038261248e565b90565b91509260056000527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0936000925b828410613069575061301d945050508101602001388061300f565b8554878501830152948501948694509281019261304e565b9150506020925061301d94915060ff191682840152151560051b820101388061300f565b60ff81146130c75760ff811690601f8211612fcd5760405191612fc383612473565b506040516006548160006130da836124c6565b80835292602090600190818116908115613081575060011461310457505061301d9250038261248e565b91509260066000527ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f936000925b82841061314d575061301d945050508101602001388061300f565b85548785018301529485019486945092810192613132565b60405163c4f59f9b60e01b81526000906001600160a01b0382826004817f00000000000000000000000013293dacab830d8fa2e0e961fb997b3f37186f4685165afa91821561331a57839261327c575b507f000000000000000000000000fbbb158bb0ac602e2165480f1bf11c640ad80c58916131e283826139d6565b61327557805190600190600183019586841161326157613201876124af565b9661320f604051988961248e565b80885261321e601f19916124af565b013660208901375b8381106132415750505061323a90846139ac565b9116905290565b808561324e8593856139ac565b511661325a828a6139ac565b5201613226565b634e487b7160e01b81526011600452602490fd5b9250505090565b9091503d8084833e61328e818361248e565b8101906020908181840312613316578051906001600160401b03821161279857019180601f840112156133165782516132c6816124af565b936132d4604051958661248e565b818552838086019260051b820101928311612790578301905b8282106132ff575050505090386131b5565b83809161330b8461259b565b8152019101906132ed565b8480fd5b6040513d85823e3d90fd5b811561334057600160ff1b8114600019831416610409570590565b634e487b7160e01b600052601260045260246000fd5b90670de0b6b3a76400006000838203931281841281169184139015161761040957565b8181039291600013801582851316918412161761040957565b9190916000838201938412911290801582169115161761040957565b6133d7670de0b6b3a764000091600084126000146133ef576133d260001994613bc4565b6133fa565b046001600160ff1b0381116103d85761301d91612e54565b6133d2600194613bc4565b8181029291811591840414171561040957565b60800151906301e1338091828102928184051490151715610409576001600160ff1b0381116103d85761343f91613325565b90600082131561344b57565b604051630e520c3b60e11b815260048101839052602490fd5b8115613340570490565b94939291906000958681126135555761349361348d6134989383613392565b91612e37565b613bfb565b670d529ae9e860000080821361353757506134c792916134936134bd6134c293613ffb565b612e37565b613392565b670de0b6b3a7640000811261351f576134df90613c05565b83811261351b576301e13380908181029181830414901517156135075761301d929350613464565b634e487b7160e01b84526011600452602484fd5b8380fd5b6024906040519063329e322960e21b82526004820152fd5b6044925060405191637e34684f60e11b835260048301526024820152fd5b60405162461bcd60e51b81526020600482015260086024820152676e6567617469766560c01b6044820152606490fd5b8060016001607f1b03191315806135a2575b156103d857600f0b90565b5060016001607f1b03811315613597565b93909360a0810194848651111561133d5781518481131561398e5750604091825194608086018681106001600160401b0382111761074657845260009586815260208101938785528582019088825260608301948986528a8c51111561397d5761361e8b8d5161254c565b95613629878361340d565b8552602082019661363b8851856133ae565b808a5283519081158015613975575b61395857505082516101008401998a5192808251938a51956136726301e133809485926133fa565b6001600160ff1b03979190048781116139515761368e90614b5c565b91670de0b6b3a764000096878412613937576136ce926134936134bd6136c38561349361348d6136c8976136da9c9b99613392565b613ffb565b90613379565b8a5260c08801516133fa565b0483811161393357906136ed8a92614b5c565b8552613712865191519161349361348d8c519461370c8d519785613fea565b93613392565b670d529ae9e8600000808213613916575061373792916134936134bd6134c293613ffb565b8181126138ff578d90613755613750826134938d612e37565b612e20565b9451918a13156138da578161349361376c92612e37565b8281126138c357506137876137818392613356565b85612e54565b059c5b60e0850151838111612c33578e60646137a66137ad9383612e54565b0595613379565b9181831280156138ab57156138a0576137c860001993613bc4565b81810291818304149015171561388c57866137e291612949565b600019810190811161388c57866137f891613464565b928311612c3057506138159161380d91612e54565b9b5b8461436a565b90613820908461436a565b9a8b919c819e51906138319161254c565b9683519061383e91613fea565b835287519161384c91613392565b61385591613fea565b8096525194613863916133ae565b91519051916138719461346e565b8091521561387c5750565b51635534d70f60e11b8152600490fd5b634e487b7160e01b82526011600452602482fd5b6137c8600193613bc4565b50505061381591506138bd908561436a565b9b61380f565b6024908d519063329e322960e21b82526004820152fd5b50613750816138f46138ee6138f994613356565b87612e54565b613325565b9c61378a565b6024908c519063329e322960e21b82526004820152fd5b604492508e5191637e34684f60e11b835260048301526024820152fd5b8e80fd5b5050506024908f519063329e322960e21b82526004820152fd5b5050508f80fd5b604492508b519163b1c4aefb60e01b835260048301526024820152fd5b50801561364a565b875163b2094b5960e01b8152600490fd5b6044908560405191632185509b60e21b835260048301526024820152fd5b80518210156139c05760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b9081519160005b8381106139ed5750505050600090565b6001600160a01b0380613a0083856139ac565b511690841614613a12576001016139dd565b50505050600190565b9291907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311613a9e5791608094939160ff602094604051948552168484015260408301526060820152600093849182805260015afa15613a915781516001600160a01b03811615613a8b579190565b50600190565b50604051903d90823e3d90fd5b50505050600090600390565b6005811015613bae5780613abb5750565b60018103613b085760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606490fd5b60028103613b555760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606490fd5b600314613b5e57565b60405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608490fd5b634e487b7160e01b600052602160045260246000fd5b600080821315613bd2575090565b600160ff1b8214613261570390565b8015613340576ec097ce7bc90715b34b9f10000000000590565b8115613340570590565b6000811315613cd85780670c7d713b49da00001280613cc7575b15613cbe57670de0b6b3a7640000906ec097ce7bc90715b34b9f100000000090613c62908302828101906ec097ce7bc90715b34b9f0fffffffff19018302613bfb565b9080828002059181838202058284820205838582020591848684020593858786020595808888020597880205600f900596600d900595600b900594600990059360079005926005900591600390050101010101010160011b0590565b61301d90614034565b50670f43fc2c04ee00008112613c1f565b60405162461bcd60e51b815260206004820152600d60248201526c6f7574206f6620626f756e647360981b6044820152606490fd5b613d156143f7565b815115613e6457600190308214159081613d30575b50505050565b613d3d83959493926147a1565b6000828152602090600c8252604091828220549582985b613d65575b50505050839450613d2a565b8051891015613e5f576001600160a01b03613d808a836139ac565b511698613d8d81876139ac565b519980855260089081855286862089875285526001600160801b038088882054168015613e58575b8d8114613e485781613dfb8f92613ddf8f613dd9670de0b6b3a7640000938761254c565b906133fa565b04858b52868a528d8c8c20908c528a528b8b205460801c612949565b9111612794578181116127945792613e3f92828c9d9e9f93958d97968c5195613e2387612473565b16855216888401528852865287872084885286528787206143c5565b01989796613d54565b5050505086979899508690613e3f565b5089613db5565b613d59565b5050565b613e706143f7565b90805115613eaa576001600160a01b0383168015159081613e9f575b50613e9657505050565b612cd2926147be565b905030141538613e8c565b505050565b613eb76143f7565b91815115613d2a576001600160a01b039083838284168015159081613f06575b50613ef5575b50505083168015159081613e9f5750613e9657505050565b613efe926147be565b388383613edd565b905030141538613ed7565b6001600160a01b0381168015159081613f2d575b50612cc95750565b905030141538613f25565b3d15613f72573d906001600160401b0382116107465760405191613f66601f8201601f19166020018461248e565b82523d6000602084013e565b606090565b9190918115613eaa576001600160a01b03169182613fe1576000809350809281925af1613fa2613f38565b5015613faa57565b60405162461bcd60e51b815260206004820152600f60248201526e195d1a081cd95b990819985a5b1959608a1b6044820152606490fd5b612cd292612b00565b908082126135555761301d91613379565b670de0b6b3a764000081146140225761401d8161349361348d61301d94613356565b613c05565b60405163a9c8b14d60e01b8152600490fd5b670de0b6b3a764000081126143535760649060007e1600ef3172e58d2e933ec884fde10064c63b5372d805e203c0000000000000821215614328575b73011798004d755d3c8bc8e03204cf44619e000000821215614307575b820290808302906e01855144814a7ff805980ff008400090818312156142e4575b50506b02df0ab5a80a22c61ab5a700808212156142c4575b50693f1fce3da636ea5cf850808212156142a4575b50690127fa27722cc06cc5e280821215614284575b5068280e60114edb805d0380821215614264575b50680ebc5fb417461211108082121561424d575b506808f00f760a4b2db55d8082121561422d575b506806f5f17757889379378082121561420d575b506806248f33704b286603808212156141ee575b506805c548670b9510e7ac808212156141cf575b5061418e68056bc75e2d6310000091828082019168056bc75e2d630fffff190102613bfb565b9080828002059181838202058284820205916003600560076009600b888a89020598808b8b02059a8b0205059805960594059205010101010160011b010590565b68056bc75e2d631000006756bc75e2d631000092020591019038614168565b68056bc75e2d6310000067ad78ebc5ac62000092020591019038614154565b68056bc75e2d6310000068015af1d78b58c4000092020591019038614140565b68056bc75e2d631000006802b5e3af16b18800009202059101903861412c565b68056bc75e2d631000008092020591019038614118565b68056bc75e2d63100000680ad78ebc5ac620000092020591019038614104565b68056bc75e2d631000006815af1d78b58c400000920205910190386140f0565b68056bc75e2d63100000682b5e3af16b18800000920205910190386140db565b68056bc75e2d631000006856bc75e2d631000000920205910190386140c6565b68ad78ebc5ac62000000925069021e19e0c9bab2400000020591019038806140ae565b906b1425982cf597cd205cef73806803782dace9d90000009105910161408d565b50770195e54c5dd42177f53a27172fa9ec63026282700000000090056806f05b59d3b2000000614070565b61435f61436491613be1565b614034565b60000390565b60008212156143ba5761437f60001992613bc4565b90670de0b6b3a764000091828102928184041490151715610409576143a391613464565b6001600160ff1b0381116103d85761301d91612e54565b61437f600192613bc4565b815160209092015160801b6fffffffffffffffffffffffffffffffff19166001600160801b0392909216919091179055565b6143ff613165565b9061440a82516127ae565b918051926000931561479b57600954431461474c5743600955600b54604051633bd73ee360e21b81523060048083019190915295919291908181602481837f00000000000000000000000013293dacab830d8fa2e0e961fb997b3f37186f466001600160a01b03165af180156146b8576146c3575b507f0000000000000000000000003c0763930a3cfd3c7e9b9b33aeabdc1fa1a60d4c6001600160a01b0316803b15612c33578180916004604051809481936358f3d16360e01b83525af180156146b8576146a9575b5090815b84518110156146a0576001600160a01b036144f382876139ac565b511690818452600a918260205260408520906040519161451283612473565b546001600160801b038116808452608082901c6020909401939093526001600160a01b03614540858b6139ac565b51168061462d5750614557475b8260801c9061254c565b6001600160801b03821615614624575b886145db575b6001600160801b0384116103d8576145879160801c612949565b6001600160801b0381116103d8576001946145ca926001600160801b03604051936145b185612473565b81871685521660208401528852602052604087206143c5565b6145d482856139ac565b52016144d8565b92670de0b6b3a764000080850290858204148515171561460f57906146038a61460993613464565b90612949565b9261456d565b60118d634e487b7160e01b6000525260246000fd5b60019350614567565b60208c6024604051809481936370a0823160e01b835230908301525afa8015614695578890614661575b614557915061454d565b506020813d60201161468d575b8161467b6020938361248e565b810103126103d8576145579051614657565b3d915061466e565b6040513d8a823e3d90fd5b50939294505050565b6146b290612460565b386144d4565b6040513d84823e3d90fd5b3d8083833e6146d2818361248e565b8101602091828183031261351b578051906001600160401b038211613316570181601f8201121561351b57805190838061470b846124af565b614718604051918261248e565b848152019260051b820101928311613316578301905b82821061473d5750505061447f565b8151815290830190830161472e565b9092805b8451811015614796576001906001600160a01b0361476e82886139ac565b51168352600a6020526001600160801b0360408420541661478f82866139ac565b5201614750565b505090565b92509190565b156147a857565b634e487b7160e01b600052600160045260246000fd5b909291906001600160a01b03908116801515806148e6575b6147df906147a1565b600094818652602090600c82526040938488205491885b81518110156148da578261480a82846139ac565b5116908a614818828b6139ac565b5183825260088089528a83208a845289526001600160801b0394858c8520541680156148d2575b8381146148c457670de0b6b3a764000061486561485f614880938761254c565b8c6133fa565b04828652838c528d86208d87528c528d86205460801c612949565b93868411612c3057868511612c3057866148be956001988f51966148a388612473565b168652168b850152528852898d20898e528852898d206143c5565b016147f6565b5050505050600191506148be565b50600161483f565b50505050505050509050565b50308114156147d6565b6001600160a01b03818116916149129083151580614a76575b611015906147a1565b90604091825163389a2ce960e21b81528460048201528381602481600080977f00000000000000000000000049fe8c5ced2d50303b0899cef3d56f69d604f088165af1908115614a6c5783908492614a2b575b506001600160801b03809116906028840284810460281485151715614a17576064900492826149d2575b505050908082106000146149ca5750925b6149bc8461207d600b54848652600c602052868620549061254c565b600b558152600c6020522055565b9050926149a0565b6002546149ee93926120e69216906001600160f81b03166133fa565b603c810290808204603c149015171561350757906064614a0f920490612949565b38808061498f565b634e487b7160e01b86526011600452602486fd5b809250858092503d8311614a65575b614a44818361248e565b81010312614a6157614a5a602061214683614e46565b9038614965565b8280fd5b503d614a3a565b84513d85823e3d90fd5b5030841415614909565b91929015614ae25750815115614a94575090565b3b15614a9d5790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b825190915015614af55750805190602001fd5b60405162461bcd60e51b815260206004820152908190614b1990602483019061232a565b0390fd5b15614b2457565b60405162461bcd60e51b815260206004820152601060248201526f125b9d985b1a5908195e1c1bdb995b9d60821b6044820152606490fd5b680238fd42c5cf03ffff1981121580614e33575b614b7990614b1d565b60008112614e1e576064906806f05b59d3b20000008112614dd1576806f05b59d3b1ffffff190168056bc75e2d6310000082770195e54c5dd42177f53a27172fa9ec630262827000000000925b02819068ad78ebc5ac62000000811215614dae575b6856bc75e2d631000000811215614d8a575b682b5e3af16b18800000811215614d68575b6815af1d78b58c400000811215614d46575b680ad78ebc5ac6200000811215614d25575b82811215614d04575b6802b5e3af16b1880000811215614ce3575b68015af1d78b58c40000811215614cc2575b60028382800205058360038184840205056004828583020505600583868302050560068487830205056007858883020505906008868984020505926009878a8602050594600a888b8802050596600b898c8a02050599600c8a8d8d0205059b0101010101010101010101010205020590565b6806f5f1775788937937839168015af1d78b58c3ffff190192020590614c50565b6808f00f760a4b2db55d83916802b5e3af16b187ffff190192020590614c3e565b680ebc5fb41746121110839168056bc75e2d630fffff190192020590614c2c565b68280e60114edb805d038391680ad78ebc5ac61fffff190192020590614c23565b690127fa27722cc06cc5e283916815af1d78b58c3fffff190192020590614c11565b693f1fce3da636ea5cf8508391682b5e3af16b187fffff190192020590614bff565b6b02df0ab5a80a22c61ab5a70083916856bc75e2d630ffffff190192020590614bed565b6e01855144814a7ff805980ff0084000915068ad78ebc5ac61ffffff1901614bdb565b6803782dace9d90000008112614e0b576803782dace9d8ffffff190168056bc75e2d63100000826b1425982cf597cd205cef738092614bc6565b68056bc75e2d6310000082600192614bc6565b614e2a90600003614b5c565b61301d90613be1565b5068070c1cc73b00c80000811315614b70565b51906001600160801b03821682036103d85756feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220385eee72d78a9a48b16b43034becf97da5e6792d13a3cc687ce44c2354ac3d0464736f6c63430008160033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000001cde6a099a1cb14f3093d2b7cb5b7cbb2145cb64000000000000000000000000000000000000000000000001180d3169d90e98000000000000000000000000000000000000000000000000000eac898fbed23600000000000000000000000000000000000000000000000000000aa466489d62c000000000000000000000000049fe8c5ced2d50303b0899cef3d56f69d604f0880000000000000000000000003c0763930a3cfd3c7e9b9b33aeabdc1fa1a60d4c
-----Decoded View---------------
Arg [0] : _PT (address): 0x1CDE6a099A1Cb14f3093d2B7cB5B7cBb2145cB64
Arg [1] : _scalarRoot (int256): 20179839836000000000
Arg [2] : _initialAnchor (int256): 1057371263000000000
Arg [3] : _lnFeeRateRoot (uint80): 2995508979000000
Arg [4] : _vePendle (address): 0x49fe8C5CEd2D50303b0899CEF3D56F69d604F088
Arg [5] : _gaugeController (address): 0x3c0763930A3CfD3c7e9b9B33AeAbdC1FA1a60D4c
-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 0000000000000000000000001cde6a099a1cb14f3093d2b7cb5b7cbb2145cb64
Arg [1] : 000000000000000000000000000000000000000000000001180d3169d90e9800
Arg [2] : 0000000000000000000000000000000000000000000000000eac898fbed23600
Arg [3] : 000000000000000000000000000000000000000000000000000aa466489d62c0
Arg [4] : 00000000000000000000000049fe8c5ced2d50303b0899cef3d56f69d604f088
Arg [5] : 0000000000000000000000003c0763930a3cfd3c7e9b9b33aeabdc1fa1a60d4c
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ 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.