Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 142 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Write Oracle Ent... | 17393799 | 463 days ago | IN | 0 ETH | 0.00560071 | ||||
Write Oracle Ent... | 17386714 | 464 days ago | IN | 0 ETH | 0.0050456 | ||||
Write Oracle Ent... | 17379608 | 465 days ago | IN | 0 ETH | 0.00860288 | ||||
Write Oracle Ent... | 17372491 | 466 days ago | IN | 0 ETH | 0.01020879 | ||||
Write Oracle Ent... | 17351146 | 469 days ago | IN | 0 ETH | 0.00341571 | ||||
Write Oracle Ent... | 17344021 | 470 days ago | IN | 0 ETH | 0.00495479 | ||||
Write Oracle Ent... | 17336910 | 471 days ago | IN | 0 ETH | 0.00523804 | ||||
Write Oracle Ent... | 17329798 | 472 days ago | IN | 0 ETH | 0.00811077 | ||||
Write Oracle Ent... | 17322679 | 473 days ago | IN | 0 ETH | 0.0076953 | ||||
Write Oracle Ent... | 17308492 | 475 days ago | IN | 0 ETH | 0.00401988 | ||||
Write Oracle Ent... | 17301389 | 476 days ago | IN | 0 ETH | 0.00607078 | ||||
Write Oracle Ent... | 17294288 | 477 days ago | IN | 0 ETH | 0.00928464 | ||||
Write Oracle Ent... | 17287188 | 478 days ago | IN | 0 ETH | 0.00909161 | ||||
Write Oracle Ent... | 17283632 | 478 days ago | IN | 0 ETH | 0.00591729 | ||||
Write Oracle Ent... | 17273011 | 480 days ago | IN | 0 ETH | 0.01078907 | ||||
Write Oracle Ent... | 17216525 | 488 days ago | IN | 0 ETH | 0.01928018 | ||||
Write Oracle Ent... | 17209412 | 489 days ago | IN | 0 ETH | 0.01656767 | ||||
Write Oracle Ent... | 17195188 | 491 days ago | IN | 0 ETH | 0.02685154 | ||||
Write Oracle Ent... | 17188054 | 492 days ago | IN | 0 ETH | 0.01109078 | ||||
Write Oracle Ent... | 17180940 | 493 days ago | IN | 0 ETH | 0.01387699 | ||||
Write Oracle Ent... | 17173842 | 494 days ago | IN | 0 ETH | 0.01093918 | ||||
Write Oracle Ent... | 17170295 | 494 days ago | IN | 0 ETH | 0.00875002 | ||||
Variable Factor | 17159426 | 496 days ago | IN | 0 ETH | 0.01241287 | ||||
Write Oracle Ent... | 17159425 | 496 days ago | IN | 0 ETH | 0.00631514 | ||||
Write Oracle Ent... | 16983328 | 521 days ago | IN | 0 ETH | 0.00534406 |
Advanced mode: Intended for advanced users or developers and will display all Internal Transactions including zero value transfers. Name tag integration is not available in advanced view.
Latest 25 internal transactions (View All)
Advanced mode:
Parent Transaction Hash | Block | From | To | ||||
---|---|---|---|---|---|---|---|
20700084 | 6 hrs ago | 0 ETH | |||||
20663694 | 5 days ago | 0 ETH | |||||
20656288 | 6 days ago | 0 ETH | |||||
20651273 | 7 days ago | 0 ETH | |||||
20615136 | 12 days ago | 0 ETH | |||||
20615136 | 12 days ago | 0 ETH | |||||
20615136 | 12 days ago | 0 ETH | |||||
20615136 | 12 days ago | 0 ETH | |||||
20615136 | 12 days ago | 0 ETH | |||||
20615136 | 12 days ago | 0 ETH | |||||
20613058 | 12 days ago | 0 ETH | |||||
20613052 | 12 days ago | 0 ETH | |||||
20583195 | 16 days ago | 0 ETH | |||||
20564133 | 19 days ago | 0 ETH | |||||
20564118 | 19 days ago | 0 ETH | |||||
20564108 | 19 days ago | 0 ETH | |||||
20564103 | 19 days ago | 0 ETH | |||||
20558486 | 20 days ago | 0 ETH | |||||
20558484 | 20 days ago | 0 ETH | |||||
20553672 | 20 days ago | 0 ETH | |||||
20553669 | 20 days ago | 0 ETH | |||||
20550773 | 21 days ago | 0 ETH | |||||
20550758 | 21 days ago | 0 ETH | |||||
20538511 | 22 days ago | 0 ETH | |||||
20538454 | 22 days ago | 0 ETH |
Loading...
Loading
Contract Name:
LidoRateOracle
Compiler Version
v0.8.9+commit.e5eed63a
Optimization Enabled:
Yes with 10 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; import "../interfaces/rate_oracles/ILidoRateOracle.sol"; import "../interfaces/lido/IStETH.sol"; import "../interfaces/lido/ILidoOracle.sol"; import "../rate_oracles/BaseRateOracle.sol"; import "../utils/WadRayMath.sol"; import "./OracleBuffer.sol"; import "../core_libraries/Time.sol"; contract LidoRateOracle is BaseRateOracle, ILidoRateOracle { IStETH public override stEth; // Lido info ILidoOracle public override lidoOracle; uint64 genesisTime; // From Beacon chain spec; changes rarely. `refreshBeaconSpec()` to update. uint64 secondsPerEpoch; // From Beacon chain spec; changes rarely. `refreshBeaconSpec()` to update. uint8 public constant override UNDERLYING_YIELD_BEARING_PROTOCOL_ID = 3; // id of Lido is 3 using OracleBuffer for OracleBuffer.Observation[65535]; constructor( IStETH _stEth, ILidoOracle _lidoOracle, IWETH _weth, uint32[] memory _times, uint256[] memory _results ) BaseRateOracle(IERC20Minimal(address(_weth))) { // Underlying is ETH, so no address needed require(address(_stEth) != address(0), "stETH must exist"); require(address(_lidoOracle) != address(0), "lidoOracle must exist"); stEth = _stEth; lidoOracle = _lidoOracle; refreshBeaconSpec(); _populateInitialObservations(_times, _results); } /// Refresh the beacon spec from Lido's oracle. Permissionless. function refreshBeaconSpec() public { ( , uint64 slotsPerEpoch, uint64 secondsPerSlot, uint64 _genesisTime ) = lidoOracle.getBeaconSpec(); genesisTime = _genesisTime; secondsPerEpoch = slotsPerEpoch * secondsPerSlot; } /// @inheritdoc BaseRateOracle function getLastUpdatedRate() public view override returns (uint32 timestamp, uint256 resultRay) { // We are taking advantage of the fact that Lido's implementation does not care about us passing in a // number of shares that is higher than the number of shared in existence. // The calculation that Lido does here would risk phantom overflow if Lido had > 10^50 ETH WEI staked // But that amount of ETH will never exist, so this is safe uint256 lastUpdatedRate = stEth.getPooledEthByShares(WadRayMath.RAY); if (lastUpdatedRate == 0) { revert CustomErrors.LidoGetPooledEthBySharesReturnedZero(); } uint256 epoch = lidoOracle.getLastCompletedEpochId(); uint32 lastCompletedTime = Time.timestampAsUint32( genesisTime + (epoch * secondsPerEpoch) ); return (lastCompletedTime, lastUpdatedRate); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; import "../lido/IStETH.sol"; import "../rate_oracles/IRateOracle.sol"; import "../lido/ILidoOracle.sol"; interface ILidoRateOracle is IRateOracle { /// @notice Gets the address of the Lido stETH token /// @return Address of the Lido stETH token function stEth() external view returns (IStETH); /// @notice Gets the address of the Lido Oracle /// @return Address of the Lido Oracle function lidoOracle() external view returns (ILidoOracle); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; interface IStETH { function getPooledEthByShares(uint256 _sharesAmount) external view returns (uint256); /** * @notice Returns staking rewards fee rate */ function getFee() external view returns (uint16 feeBasisPoints); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; interface ILidoOracle { function getLastCompletedReportDelta() external view returns ( uint256 postTotalPooledEther, uint256 preTotalPooledEther, uint256 timeElapsed ); function getCurrentFrame() external view returns ( uint256 frameEpochId, uint256 frameStartTime, uint256 frameEndTime ); function getLastCompletedEpochId() external view returns (uint256); function getBeaconSpec() external view returns ( uint64 epochsPerFrame, uint64 slotsPerEpoch, uint64 secondsPerSlot, uint64 genesisTime ); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; import "./OracleBuffer.sol"; import "../interfaces/rate_oracles/IRateOracle.sol"; import "../core_libraries/FixedAndVariableMath.sol"; import "prb-math/contracts/PRBMathUD60x18.sol"; import "../interfaces/IFactory.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "../core_libraries/Time.sol"; import "../utils/WadRayMath.sol"; import "hardhat/console.sol"; /// @notice Common contract base for a Rate Oracle implementation. /// This contract is abstract. To make the contract deployable override the /// `getCurrentRateInRay` and `getLastUpdatedRate` functions and the `UNDERLYING_YIELD_BEARING_PROTOCOL_ID` constant. /// @dev Each specific rate oracle implementation will need to implement the virtual functions abstract contract BaseRateOracle is IRateOracle, Ownable { uint256 public constant ONE_IN_WAD = 1e18; using OracleBuffer for OracleBuffer.Observation[65535]; /// @notice a cache of settlement rates for interest rate swaps associated with this rate oracle, indexed by start time and then end time mapping(uint32 => mapping(uint32 => uint256)) public settlementRateCache; struct OracleVars { /// @dev the most-recently updated index of the rates array uint16 rateIndex; /// @dev the current maximum number of rates that are being stored uint16 rateCardinality; /// @dev the next maximum number of rates to store, triggered in rates.write uint16 rateCardinalityNext; } struct BlockInfo { uint32 timestamp; uint256 number; } struct BlockSlopeInfo { uint32 timeChange; uint256 blockChange; } /// @inheritdoc IRateOracle IERC20Minimal public immutable override underlying; /// @inheritdoc IRateOracle uint256 public override minSecondsSinceLastUpdate; OracleVars public oracleVars; /// @notice the observations tracked over time by this oracle OracleBuffer.Observation[65535] public observations; BlockInfo public lastUpdatedBlock; BlockSlopeInfo public currentBlockSlope; /// @inheritdoc IRateOracle function setMinSecondsSinceLastUpdate(uint256 _minSecondsSinceLastUpdate) external override onlyOwner { if (minSecondsSinceLastUpdate != _minSecondsSinceLastUpdate) { minSecondsSinceLastUpdate = _minSecondsSinceLastUpdate; emit MinSecondsSinceLastUpdate(_minSecondsSinceLastUpdate); } } constructor(IERC20Minimal _underlying) { underlying = _underlying; lastUpdatedBlock.number = block.number; lastUpdatedBlock.timestamp = Time.blockTimestampTruncated(); currentBlockSlope.timeChange = 135; currentBlockSlope.blockChange = 10; } /// @dev this must be called at the *end* of the constructor, after the contract member variables have been set, because it needs to read rates. function _populateInitialObservations( uint32[] memory _times, uint256[] memory _results ) internal { // If we're using even half the max buffer size, something has gone wrong require(_times.length < OracleBuffer.MAX_BUFFER_LENGTH / 2, "MAXT"); uint16 length = uint16(_times.length); require(length == _results.length, "Lengths must match"); // We must pass equal-sized dynamic arrays containing initial timestamps and observed values uint32[] memory times = new uint32[](length + 1); uint256[] memory results = new uint256[](length + 1); for (uint256 i = 0; i < length; i++) { times[i] = _times[i]; results[i] = _results[i]; } ( uint32 lastUpdatedTimestamp, uint256 lastUpdatedRate ) = getLastUpdatedRate(); // `observations.initialize` will check that all times are correctly sorted so no need to check here times[length] = lastUpdatedTimestamp; results[length] = lastUpdatedRate; ( oracleVars.rateCardinality, oracleVars.rateCardinalityNext, oracleVars.rateIndex ) = observations.initialize(times, results); } /// @notice Calculates the interpolated (counterfactual) rate value /// @param beforeOrAtRateValueRay Rate Value (in ray) before the timestamp for which we want to calculate the counterfactual rate value /// @param apyFromBeforeOrAtToAtOrAfterWad Apy in the period between the timestamp of the beforeOrAt Rate and the atOrAfter Rate /// @param timeDeltaBeforeOrAtToQueriedTimeWad Time Delta (in wei seconds) between the timestamp of the beforeOrAt Rate and the atOrAfter Rate /// @return rateValueRay Counterfactual (interpolated) rate value in ray /// @dev Given [beforeOrAt, atOrAfter] where the timestamp for which the counterfactual is calculated is within that range (but does not touch any of the bounds) /// @dev We can calculate the apy for [beforeOrAt, atOrAfter] --> refer to this value as apyFromBeforeOrAtToAtOrAfter /// @dev Then we want a counterfactual rate value which results in apy_before_after if the apy is calculated between [beforeOrAt, timestampForCounterfactual] /// @dev Hence (1+rateValueWei/beforeOrAtRateValueWei)^(1/timeInYears) = apyFromBeforeOrAtToAtOrAfter /// @dev Hence rateValueWei = beforeOrAtRateValueWei * (1+apyFromBeforeOrAtToAtOrAfter)^timeInYears - 1) function interpolateRateValue( uint256 beforeOrAtRateValueRay, uint256 apyFromBeforeOrAtToAtOrAfterWad, uint256 timeDeltaBeforeOrAtToQueriedTimeWad ) public pure virtual returns (uint256 rateValueRay) { uint256 timeInYearsWad = FixedAndVariableMath.accrualFact( timeDeltaBeforeOrAtToQueriedTimeWad ); uint256 apyPlusOne = apyFromBeforeOrAtToAtOrAfterWad + ONE_IN_WAD; uint256 factorInWad = PRBMathUD60x18.pow(apyPlusOne, timeInYearsWad); uint256 factorInRay = WadRayMath.wadToRay(factorInWad); rateValueRay = WadRayMath.rayMul(beforeOrAtRateValueRay, factorInRay); } /// @inheritdoc IRateOracle function increaseObservationCardinalityNext(uint16 rateCardinalityNext) external override { uint16 rateCardinalityNextOld = oracleVars.rateCardinalityNext; // for the event uint16 rateCardinalityNextNew = observations.grow( rateCardinalityNextOld, rateCardinalityNext ); oracleVars.rateCardinalityNext = rateCardinalityNextNew; if (rateCardinalityNextOld != rateCardinalityNextNew) { emit RateCardinalityNext(rateCardinalityNextNew); } } /// @notice Get the last updated rate in Ray with the accompanying truncated timestamp /// This data point must be a known data point from the source of the data, and not extrapolated or interpolated by us. /// The source and expected values of "rate" may differ by rate oracle type. All that /// matters is that we can divide one "rate" by another "rate" to get the factor of growth between the two timestamps. /// For example if we have rates of { (t=0, rate=5), (t=100, rate=5.5) }, we can divide 5.5 by 5 to get a growth factor /// of 1.1, suggesting that 10% growth in capital was experienced between timesamp 0 and timestamp 100. /// @dev FOr convenience, the rate is normalised to Ray for storage, so that we can perform consistent math across all rates. /// @dev This function should revert if a valid rate cannot be discerned /// @return timestamp the timestamp corresponding to the known rate (could be the current time, or a time in the past) /// @return rate the rate in Ray (decimal scaled up by 10^27 for storage in a uint256) function getLastUpdatedRate() public view virtual returns (uint32 timestamp, uint256 rate); /// @inheritdoc IRateOracle function getRateFromTo(uint256 _from, uint256 _to) public view override(IRateOracle) returns (uint256) { require(_from <= _to, "from > to"); if (_from == _to) { return 0; } // note that we have to convert the rate multiple into a "floating rate" for // swap calculations, e.g. an index multiple of 1.04*10**27 corresponds to // 0.04*10**27 = 4*10*25 uint32 currentTime = Time.blockTimestampTruncated(); uint32 from = Time.timestampAsUint32(_from); uint32 to = Time.timestampAsUint32(_to); uint256 rateFromRay = observeSingle( currentTime, from, oracleVars.rateIndex, oracleVars.rateCardinality ); uint256 rateToRay = observeSingle( currentTime, to, oracleVars.rateIndex, oracleVars.rateCardinality ); if (rateToRay > rateFromRay) { uint256 result = WadRayMath.rayToWad( WadRayMath.rayDiv(rateToRay, rateFromRay) - WadRayMath.RAY ); return result; } else { return 0; } } /// @inheritdoc IRateOracle function getRateFrom(uint256 _from) public view override(IRateOracle) returns (uint256) { return getRateFromTo(_from, block.timestamp); } function observeSingle( uint32 currentTime, uint32 queriedTime, uint16 index, uint16 cardinality ) internal view returns (uint256 rateValueRay) { if (currentTime < queriedTime) revert CustomErrors.OOO(); if (currentTime == queriedTime) { OracleBuffer.Observation memory rate; rate = observations[index]; if (rate.blockTimestamp != currentTime) { rateValueRay = getCurrentRateInRay(); } else { rateValueRay = rate.observedValue; } return rateValueRay; } uint256 currentValueRay = getCurrentRateInRay(); ( OracleBuffer.Observation memory beforeOrAt, OracleBuffer.Observation memory atOrAfter ) = observations.getSurroundingObservations( queriedTime, currentTime, currentValueRay, index, cardinality ); if (queriedTime == beforeOrAt.blockTimestamp) { // we are at the left boundary rateValueRay = beforeOrAt.observedValue; } else if (queriedTime == atOrAfter.blockTimestamp) { // we are at the right boundary rateValueRay = atOrAfter.observedValue; } else { // we are in the middle // find apy between beforeOrAt and atOrAfter uint256 rateFromBeforeOrAtToAtOrAfterWad; // more generally, what should our terminology be to distinguish cases where we represetn a 5% APY as = 1.05 vs. 0.05? We should pick a clear terminology and be use it throughout our descriptions / Hungarian notation / user defined types. if (atOrAfter.observedValue > beforeOrAt.observedValue) { uint256 rateFromBeforeOrAtToAtOrAfterRay = WadRayMath.rayDiv( atOrAfter.observedValue, beforeOrAt.observedValue ) - WadRayMath.RAY; rateFromBeforeOrAtToAtOrAfterWad = WadRayMath.rayToWad( rateFromBeforeOrAtToAtOrAfterRay ); } uint256 timeInYearsWad = FixedAndVariableMath.accrualFact( (atOrAfter.blockTimestamp - beforeOrAt.blockTimestamp) * WadRayMath.WAD ); uint256 apyFromBeforeOrAtToAtOrAfterWad = computeApyFromRate( rateFromBeforeOrAtToAtOrAfterWad, timeInYearsWad ); // interpolate rateValue for queriedTime rateValueRay = interpolateRateValue( beforeOrAt.observedValue, apyFromBeforeOrAtToAtOrAfterWad, (queriedTime - beforeOrAt.blockTimestamp) * WadRayMath.WAD ); } } /// @notice Computes the APY based on the un-annualised rateFromTo value and timeInYears (in wei) /// @param rateFromToWad Un-annualised rate (in wei) /// @param timeInYearsWad Time in years for the period for which we want to calculate the apy (in wei) /// @return apyWad APY for a given rateFromTo and timeInYears function computeApyFromRate(uint256 rateFromToWad, uint256 timeInYearsWad) internal pure returns (uint256 apyWad) { if (rateFromToWad == 0) { return 0; } uint256 exponentWad = PRBMathUD60x18.div( PRBMathUD60x18.fromUint(1), timeInYearsWad ); uint256 apyPlusOneWad = PRBMathUD60x18.pow( (PRBMathUD60x18.fromUint(1) + rateFromToWad), exponentWad ); apyWad = apyPlusOneWad - PRBMathUD60x18.fromUint(1); } /// @inheritdoc IRateOracle function getApyFromTo(uint256 from, uint256 to) public view override returns (uint256 apyFromToWad) { require(from <= to, "Misordered dates"); uint256 rateFromToWad = getRateFromTo(from, to); uint256 timeInSeconds = to - from; uint256 timeInSecondsWad = PRBMathUD60x18.fromUint(timeInSeconds); uint256 timeInYearsWad = FixedAndVariableMath.accrualFact( timeInSecondsWad ); apyFromToWad = computeApyFromRate(rateFromToWad, timeInYearsWad); } /// @inheritdoc IRateOracle function getApyFrom(uint256 from) public view override returns (uint256 apyFromToWad) { return getApyFromTo(from, block.timestamp); } /// @inheritdoc IRateOracle function variableFactor( uint256 termStartTimestampInWeiSeconds, uint256 termEndTimestampInWeiSeconds ) public override(IRateOracle) returns (uint256 resultWad) { bool cacheable; (resultWad, cacheable) = _variableFactor( termStartTimestampInWeiSeconds, termEndTimestampInWeiSeconds ); if (cacheable) { uint32 termStartTimestamp = Time.timestampAsUint32( PRBMathUD60x18.toUint(termStartTimestampInWeiSeconds) ); uint32 termEndTimestamp = Time.timestampAsUint32( PRBMathUD60x18.toUint(termEndTimestampInWeiSeconds) ); settlementRateCache[termStartTimestamp][ termEndTimestamp ] = resultWad; } return resultWad; } /// @inheritdoc IRateOracle function variableFactorNoCache( uint256 termStartTimestampInWeiSeconds, uint256 termEndTimestampInWeiSeconds ) public view override(IRateOracle) returns (uint256 resultWad) { (resultWad, ) = _variableFactor( termStartTimestampInWeiSeconds, termEndTimestampInWeiSeconds ); } function _variableFactor( uint256 termStartTimestampInWeiSeconds, uint256 termEndTimestampInWeiSeconds ) private view returns (uint256 resultWad, bool cacheable) { uint32 termStartTimestamp = Time.timestampAsUint32( PRBMathUD60x18.toUint(termStartTimestampInWeiSeconds) ); uint32 termEndTimestamp = Time.timestampAsUint32( PRBMathUD60x18.toUint(termEndTimestampInWeiSeconds) ); require(termStartTimestamp > 0 && termEndTimestamp > 0, "UNITS"); if (settlementRateCache[termStartTimestamp][termEndTimestamp] != 0) { resultWad = settlementRateCache[termStartTimestamp][ termEndTimestamp ]; cacheable = false; } else if (Time.blockTimestampTruncated() >= termEndTimestamp) { resultWad = getRateFromTo(termStartTimestamp, termEndTimestamp); cacheable = true; } else { resultWad = getRateFromTo( termStartTimestamp, Time.blockTimestampTruncated() ); cacheable = false; } } /// @notice Store the last updated rate (returned by getLastUpdatedRate) into our buffer, unless a rate was written less than minSecondsSinceLastUpdate ago /// @param index The index of the Observation that was most recently written to the observations buffer. (Note that at least one Observation is written at contract construction time, so this is always defined.) /// @param cardinality The number of populated elements in the observations buffer /// @param cardinalityNext The new length of the observations buffer, independent of population /// @return indexUpdated The new index of the most recently written element in the oracle array /// @return cardinalityUpdated The new cardinality of the oracle array function writeRate( uint16 index, uint16 cardinality, uint16 cardinalityNext ) internal returns (uint16 indexUpdated, uint16 cardinalityUpdated) { OracleBuffer.Observation memory last = observations[index]; ( uint32 lastUpdatedTimestamp, uint256 lastUpdatedRate ) = getLastUpdatedRate(); // early return (to increase ttl of data in the observations buffer) if we've already written an observation recently if ( lastUpdatedTimestamp < last.blockTimestamp + minSecondsSinceLastUpdate ) return (index, cardinality); emit OracleBufferUpdate( Time.blockTimestampScaled(), address(this), index, lastUpdatedTimestamp, lastUpdatedRate, cardinality, cardinalityNext ); currentBlockSlope.blockChange = block.number - lastUpdatedBlock.number; currentBlockSlope.timeChange = Time.blockTimestampTruncated() - lastUpdatedBlock.timestamp; lastUpdatedBlock.number = block.number; lastUpdatedBlock.timestamp = Time.blockTimestampTruncated(); return observations.write( index, lastUpdatedTimestamp, lastUpdatedRate, cardinality, cardinalityNext ); } /// @inheritdoc IRateOracle function writeOracleEntry() external override(IRateOracle) { (oracleVars.rateIndex, oracleVars.rateCardinality) = writeRate( oracleVars.rateIndex, oracleVars.rateCardinality, oracleVars.rateCardinalityNext ); } /// @inheritdoc IRateOracle function getLastRateSlope() public view override returns (uint256 rateChange, uint32 timeChange) { uint16 last = oracleVars.rateIndex; uint16 lastButOne = (oracleVars.rateIndex >= 1) ? oracleVars.rateIndex - 1 : oracleVars.rateCardinality - 1; // check if there are at least two points in the rate oracle // otherwise, revert with "Not Enough Points" require( oracleVars.rateCardinality >= 2 && observations[lastButOne].initialized && observations[lastButOne].observedValue <= observations[last].observedValue, "NEP" ); rateChange = observations[last].observedValue - observations[lastButOne].observedValue; timeChange = observations[last].blockTimestamp - observations[lastButOne].blockTimestamp; } /// @inheritdoc IRateOracle function getCurrentRateInRay() public view override returns (uint256 currentRate) { ( uint32 lastUpdatedTimestamp, uint256 lastUpdatedRate ) = getLastUpdatedRate(); if (lastUpdatedTimestamp >= Time.blockTimestampTruncated()) { return lastUpdatedRate; } // We can't get the current rate from the underlying platform, perhaps because it only pushes // rates to chain periodically. So we extrapolate the likely current rate from recent rates. (uint256 rateChange, uint32 timeChange) = getLastRateSlope(); currentRate = lastUpdatedRate + ((Time.blockTimestampTruncated() - lastUpdatedTimestamp) * rateChange) / timeChange; } /// @inheritdoc IRateOracle function getBlockSlope() public view override returns (uint256 blockChange, uint32 timeChange) { if (lastUpdatedBlock.number >= block.number) { return ( currentBlockSlope.blockChange, currentBlockSlope.timeChange ); } return ( block.number - lastUpdatedBlock.number, Time.blockTimestampTruncated() - lastUpdatedBlock.timestamp ); } }
// SPDX-License-Identifier: Apache-2.0 // solhint-disable const-name-snakecase pragma solidity =0.8.9; /** * @title WadRayMath library * @author Voltz, matching an interface and terminology used by Aave for consistency * @dev Provides mul and div function for wads (decimal numbers with 18 digits precision) and rays (decimals with 27 digits) **/ library WadRayMath { enum Mode { WAD_MODE, RAY_MODE } uint256 public constant WAD = 1e18; uint256 public constant RAY = 1e27; uint256 public constant HALF_WAD = WAD / 2; uint256 public constant HALF_RAY = RAY / 2; uint256 public constant WAD_RAY_RATIO = RAY / WAD; uint256 internal constant HALF_RATIO = WAD_RAY_RATIO / 2; // Multiplies two values in WAD_MODE or RAY_MODE, rounding up function _mul( uint256 a, uint256 b, Mode m ) private pure returns (uint256) { if (a == 0 || b == 0) { return 0; } return (a * b + (m == Mode.RAY_MODE ? HALF_RAY : HALF_WAD)) / (m == Mode.RAY_MODE ? RAY : WAD); } /** * @dev Multiplies two wad, rounding half up to the nearest wad * @param a Wad * @param b Wad * @return The result of a*b, in wad **/ function wadMul(uint256 a, uint256 b) internal pure returns (uint256) { return _mul(a, b, Mode.WAD_MODE); } /** * @dev Multiplies two ray, rounding half up to the nearest ray * @param a Ray * @param b Ray * @return The result of a*b, in ray **/ function rayMul(uint256 a, uint256 b) internal pure returns (uint256) { return _mul(a, b, Mode.RAY_MODE); } // Divides two values in WAD_MODE or RAY_MODE, rounding up function _div( uint256 a, uint256 b, Mode m ) private pure returns (uint256) { require(b != 0, "DIV0"); uint256 halfB = b / 2; return (a * (m == Mode.RAY_MODE ? RAY : WAD) + halfB) / b; } /** * @dev Divides two wad, rounding half up to the nearest wad * @param a Wad * @param b Wad * @return The result of a/b, in wad **/ function wadDiv(uint256 a, uint256 b) internal pure returns (uint256) { return _div(a, b, Mode.WAD_MODE); } /** * @dev Divides two ray, rounding half up to the nearest ray * @param a Ray * @param b Ray * @return The result of a/b, in ray **/ function rayDiv(uint256 a, uint256 b) internal pure returns (uint256) { return _div(a, b, Mode.RAY_MODE); } /** * @dev Scales a value in WAD up to a value in RAY * @param a WAD value * @return a, scaled up to a value in RAY **/ function wadToRay(uint256 a) internal pure returns (uint256) { uint256 result = a * WAD_RAY_RATIO; return result; } /** * @dev Scales a value in RAY down to a value in WAD * @param a RAY value * @return a, scaled down to a value in WAD (rounded up to the nearest WAD) **/ function rayToWad(uint256 a) internal pure returns (uint256) { uint256 result = a / WAD_RAY_RATIO; if (a % WAD_RAY_RATIO >= HALF_RATIO) { result += 1; } return result; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.9; /// @title OracleBuffer /// @notice Provides the value history needed by multiple oracle contracts /// @dev Instances of stored oracle data, "observations", are collected in the oracle array /// Every pool is initialized with an oracle array length of 1. Anyone can pay the SSTOREs to increase the /// maximum length of the oracle array. New slots will be added when the array is fully populated. /// Observations are overwritten when the full length of the oracle array is populated. /// The most recent observation is available, independent of the length of the oracle array, by passing 0 to observe() library OracleBuffer { uint256 public constant MAX_BUFFER_LENGTH = 65535; /// @dev An Observation fits in one storage slot, keeping gas costs down and allowing `grow()` to pre-pay for gas struct Observation { // The timesamp in seconds. uint32 allows tiemstamps up to the year 2105. Future versions may wish to use uint40. uint32 blockTimestamp; /// @dev Even if observedVale is a decimal with 27 decimal places, this still allows decimal values up to 1.053122916685572e+38 uint216 observedValue; bool initialized; } /// @notice Creates an observation struct from the current timestamp and observed value /// @dev blockTimestamp _must_ be chronologically equal to or greater than last.blockTimestamp, safe for 0 or 1 overflows /// @param blockTimestamp The timestamp of the new observation /// @param observedValue The observed value (semantics may differ for different types of rate oracle) /// @return Observation The newly populated observation function observation(uint32 blockTimestamp, uint256 observedValue) private pure returns (Observation memory) { require(observedValue <= type(uint216).max, ">216"); return Observation({ blockTimestamp: blockTimestamp, observedValue: uint216(observedValue), initialized: true }); } /// @notice Initialize the oracle array by writing the first slot(s). Called once for the lifecycle of the observations array /// @param self The stored oracle array /// @param times The times to populate in the Oracle buffe (block.timestamps truncated to uint32) /// @param observedValues The observed values to populate in the oracle buffer (semantics may differ for different types of rate oracle) /// @return cardinality The number of populated elements in the oracle array /// @return cardinalityNext The new length of the oracle array, independent of population /// @return rateIndex The index of the most recently populated element of the array function initialize( Observation[MAX_BUFFER_LENGTH] storage self, uint32[] memory times, uint256[] memory observedValues ) internal returns ( uint16 cardinality, uint16 cardinalityNext, uint16 rateIndex ) { require(times.length < MAX_BUFFER_LENGTH, "MAXT"); uint16 length = uint16(times.length); require(length == observedValues.length, "Lengths must match"); require(length > 0, "0T"); uint32 prevTime = 0; for (uint16 i = 0; i < length; i++) { require(prevTime < times[i], "input unordered"); self[i] = observation(times[i], observedValues[i]); prevTime = times[i]; } return (length, length, length - 1); } /// @notice Writes an oracle observation to the array /// @dev Writable at most once per block. Index represents the most recently written element. cardinality and index must be tracked externally. /// If the index is at the end of the allowable array length (according to cardinality), and the next cardinality /// is greater than the current one, cardinality may be increased. This restriction is created to preserve ordering. /// @param self The stored oracle array /// @param index The index of the observation that was most recently written to the observations array /// @param blockTimestamp The timestamp of the new observation /// @param observedValue The observed value (semantics may differ for different types of rate oracle) /// @param cardinality The number of populated elements in the oracle array /// @param cardinalityNext The new length of the oracle array, independent of population /// @return indexUpdated The new index of the most recently written element in the oracle array /// @return cardinalityUpdated The new cardinality of the oracle array function write( Observation[MAX_BUFFER_LENGTH] storage self, uint16 index, uint32 blockTimestamp, uint256 observedValue, uint16 cardinality, uint16 cardinalityNext ) internal 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] = observation(blockTimestamp, observedValue); } /// @notice Prepares the oracle array to store up to `next` observations /// @param self The stored oracle array /// @param current The current next cardinality of the oracle array /// @param next The proposed next cardinality which will be populated in the oracle array /// @return next The next cardinality which will be populated in the oracle array function grow( Observation[MAX_BUFFER_LENGTH] storage self, uint16 current, uint16 next ) internal returns (uint16) { require(current > 0, "I"); require(next < MAX_BUFFER_LENGTH, "buffer limit"); // 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; i++) self[i].blockTimestamp = 1; return next; } /// @notice Fetches the observations beforeOrAt and atOrAfter a target, i.e. where [beforeOrAt, atOrAfter] is satisfied. /// The result may be the same observation, or adjacent observations. /// @dev The answer must be contained in the array, used when the target is located within the stored observation /// boundaries: older than the most recent observation and younger, or the same age as, the oldest observation /// @param self The stored oracle array /// @param target The timestamp at which the reserved observation should be for /// @param index The index of the observation that was most recently written to the observations array /// @param cardinality The number of populated elements in the oracle array /// @return beforeOrAt The observation recorded before, or at, the target /// @return atOrAfter The observation recorded at, or after, the target function binarySearch( Observation[MAX_BUFFER_LENGTH] storage self, uint32 target, uint16 index, uint16 cardinality ) internal 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; i = (l + r) >> 1; beforeOrAt = self[i % cardinality]; // we've landed on an uninitialized tick, 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; } } /// @notice Fetches the observations beforeOrAt and atOrAfter a given target, i.e. where [beforeOrAt, atOrAfter] is satisfied /// @dev Assumes there is at least 1 initialized observation. /// Used by observeSingle() to compute the counterfactual accumulator values as of a given block timestamp. /// @param self The stored oracle array /// @param target The timestamp at which the reserved observation should be for. Must be chronologically before currentTime. /// @param currentTime The current timestamp, at which currentValue applies. /// @param currentValue The current observed value if we were writing a new observation now (semantics may differ for different types of rate oracle) /// @param index The index of the observation that was most recently written to the observations array /// @param cardinality The number of populated elements in the oracle array /// @return beforeOrAt The observation which occurred at, or before, the given timestamp /// @return atOrAfter The observation which occurred at, or after, the given timestamp function getSurroundingObservations( Observation[MAX_BUFFER_LENGTH] storage self, uint32 target, uint32 currentTime, uint256 currentValue, uint16 index, uint16 cardinality ) internal 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, observation(currentTime, currentValue)); } } // now, set before 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 require(beforeOrAt.blockTimestamp <= target, "OLD"); // if we've reached this point, we have to binary search return binarySearch(self, target, index, cardinality); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; import "prb-math/contracts/PRBMathUD60x18.sol"; library Time { uint256 public constant SECONDS_IN_DAY_WAD = 86400e18; /// @notice Calculate block.timestamp to wei precision /// @return Current timestamp in wei-seconds (1/1e18) function blockTimestampScaled() internal view returns (uint256) { // solhint-disable-next-line not-rely-on-time return PRBMathUD60x18.fromUint(block.timestamp); } /// @dev Returns the block timestamp truncated to 32 bits, checking for overflow. function blockTimestampTruncated() internal view returns (uint32) { return timestampAsUint32(block.timestamp); } function timestampAsUint32(uint256 _timestamp) internal pure returns (uint32 timestamp) { require((timestamp = uint32(_timestamp)) == _timestamp, "TSOFLOW"); } function isCloseToMaturityOrBeyondMaturity(uint256 termEndTimestampWad) internal view returns (bool vammInactive) { return Time.blockTimestampScaled() + SECONDS_IN_DAY_WAD >= termEndTimestampWad; } }
// SPDX-License-Identifier: Apache-2.0 import "contracts/utils/CustomErrors.sol"; pragma solidity =0.8.9; import "contracts/utils/CustomErrors.sol"; import "../IERC20Minimal.sol"; /// @dev The RateOracle is used for two purposes on the Voltz Protocol /// @dev Settlement: in order to be able to settle IRS positions after the termEndTimestamp of a given AMM /// @dev Margin Engine Computations: getApyFromTo is used by the MarginCalculator and MarginEngine /// @dev It is necessary to produce margin requirements for Trader and Liquidity Providers interface IRateOracle is CustomErrors { // events event MinSecondsSinceLastUpdate(uint256 _minSecondsSinceLastUpdate); event OracleBufferUpdate( uint256 blockTimestampScaled, address source, uint16 index, uint32 blockTimestamp, uint256 observedValue, uint16 cardinality, uint16 cardinalityNext ); /// @notice Emitted by the rate oracle for increases to the number of observations that can be stored /// @param observationCardinalityNextNew The updated value of the next observation cardinality event RateCardinalityNext( uint16 observationCardinalityNextNew ); // view functions /// @notice Gets minimum number of seconds that need to pass since the last update to the rates array /// @dev This is a throttling mechanic that needs to ensure we don't run out of space in the rates array /// @dev The maximum size of the rates array is 65535 entries // AB: as long as this doesn't affect the termEndTimestamp rateValue too much // AB: can have a different minSecondsSinceLastUpdate close to termEndTimestamp to have more granularity for settlement purposes /// @return minSecondsSinceLastUpdate in seconds function minSecondsSinceLastUpdate() external view returns (uint256); /// @notice Gets the address of the underlying token of the RateOracle /// @dev may be unset (`address(0)`) if the underlying is ETH /// @return underlying The address of the underlying token function underlying() external view returns (IERC20Minimal); /// @notice Gets the variable factor between termStartTimestamp and termEndTimestamp /// @return result The variable factor /// @dev If the current block timestamp is beyond the maturity of the AMM, then the variableFactor is getRateFromTo(termStartTimestamp, termEndTimestamp). Term end timestamps are cached for quick retrieval later. /// @dev If the current block timestamp is before the maturity of the AMM, then the variableFactor is getRateFromTo(termStartTimestamp,Time.blockTimestampScaled()); /// @dev if queried before maturity then returns the rate of return between pool initiation and current timestamp (in wad) /// @dev if queried after maturity then returns the rate of return between pool initiation and maturity timestamp (in wad) function variableFactor(uint256 termStartTimestamp, uint256 termEndTimestamp) external returns(uint256 result); /// @notice Gets the variable factor between termStartTimestamp and termEndTimestamp /// @return result The variable factor /// @dev If the current block timestamp is beyond the maturity of the AMM, then the variableFactor is getRateFromTo(termStartTimestamp, termEndTimestamp). No caching takes place. /// @dev If the current block timestamp is before the maturity of the AMM, then the variableFactor is getRateFromTo(termStartTimestamp,Time.blockTimestampScaled()); function variableFactorNoCache(uint256 termStartTimestamp, uint256 termEndTimestamp) external view returns(uint256 result); /// @notice Calculates the observed interest returned by the underlying in a given period /// @dev Reverts if we have no data point for `_from` /// @param _from The timestamp of the start of the period, in seconds /// @return The "floating rate" expressed in Wad, e.g. 4% is encoded as 0.04*10**18 = 4*10**16 function getRateFrom(uint256 _from) external view returns (uint256); /// @notice Calculates the observed interest returned by the underlying in a given period /// @dev Reverts if we have no data point for either timestamp /// @param _from The timestamp of the start of the period, in seconds /// @param _to The timestamp of the end of the period, in seconds /// @return The "floating rate" expressed in Wad, e.g. 4% is encoded as 0.04*10**18 = 4*10**16 function getRateFromTo(uint256 _from, uint256 _to) external view returns (uint256); /// @notice Calculates the observed APY returned by the rate oracle between the given timestamp and the current time /// @param from The timestamp of the start of the period, in seconds /// @dev Reverts if we have no data point for `from` /// @return apyFromTo The "floating rate" expressed in Wad, e.g. 4% is encoded as 0.04*10**18 = 4*10**16 function getApyFrom(uint256 from) external view returns (uint256 apyFromTo); /// @notice Calculates the observed APY returned by the rate oracle in a given period /// @param from The timestamp of the start of the period, in seconds /// @param to The timestamp of the end of the period, in seconds /// @dev Reverts if we have no data point for either timestamp /// @return apyFromTo The "floating rate" expressed in Wad, e.g. 4% is encoded as 0.04*10**18 = 4*10**16 function getApyFromTo(uint256 from, uint256 to) external view returns (uint256 apyFromTo); // non-view functions /// @notice Sets minSecondsSinceLastUpdate: The minimum number of seconds that need to pass since the last update to the rates array /// @dev Can only be set by the Factory Owner function setMinSecondsSinceLastUpdate(uint256 _minSecondsSinceLastUpdate) external; /// @notice Increase the maximum number of rates observations that this RateOracle will store /// @dev This method is no-op if the RateOracle already has an observationCardinalityNext greater than or equal to /// the input observationCardinalityNext. /// @param rateCardinalityNext The desired minimum number of observations for the pool to store function increaseObservationCardinalityNext(uint16 rateCardinalityNext) external; /// @notice Writes a rate observation to the rates array given the current rate cardinality, rate index and rate cardinality next /// Write oracle entry is called whenever a new position is minted via the vamm or when a swap is initiated via the vamm /// That way the gas costs of Rate Oracle updates can be distributed across organic interactions with the protocol function writeOracleEntry() external; /// @notice unique ID of the underlying yield bearing protocol (e.g. Aave v2 has id 1) /// @return yieldBearingProtocolID unique id of the underlying yield bearing protocol function UNDERLYING_YIELD_BEARING_PROTOCOL_ID() external view returns(uint8 yieldBearingProtocolID); /// @notice returns the last change in rate and time /// Gets the last two observations and returns the change in rate and time. /// This can help us to extrapolate an estiamte of the current rate from recent known rates. function getLastRateSlope() external view returns (uint256 rateChange, uint32 timeChange); /// @notice Get the current "rate" in Ray at the current timestamp. /// This might be a direct reading if real-time readings are available, or it might be an extrapolation from recent known rates. /// The source and expected values of "rate" may differ by rate oracle type. All that /// matters is that we can divide one "rate" by another "rate" to get the factor of growth between the two timestamps. /// For example if we have rates of { (t=0, rate=5), (t=100, rate=5.5) }, we can divide 5.5 by 5 to get a growth factor /// of 1.1, suggesting that 10% growth in capital was experienced between timesamp 0 and timestamp 100. /// @dev For convenience, the rate is normalised to Ray for storage, so that we can perform consistent math across all rates. /// @dev This function should revert if a valid rate cannot be discerned /// @return currentRate the rate in Ray (decimal scaled up by 10^27 for storage in a uint256) function getCurrentRateInRay() external view returns (uint256 currentRate); /// @notice returns the last change in block number and timestamp /// Some implementations may use this data to estimate timestamps for recent rate readings, if we only know the block number function getBlockSlope() external view returns (uint256 blockChange, uint32 timeChange); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; interface CustomErrors { /// @dev No need to unwind a net zero position error PositionNetZero(); error DebugError(uint256 x, uint256 y); /// @dev Cannot have less margin than the minimum requirement error MarginLessThanMinimum(int256 marginRequirement); /// @dev We can't withdraw more margin than we have error WithdrawalExceedsCurrentMargin(); /// @dev Position must be settled after AMM has reached maturity error PositionNotSettled(); /// The resulting margin does not meet minimum requirements error MarginRequirementNotMet( int256 marginRequirement, int24 tick, int256 fixedTokenDelta, int256 variableTokenDelta, uint256 cumulativeFeeIncurred, int256 fixedTokenDeltaUnbalanced ); /// The position/trader needs to be below the liquidation threshold to be liquidated error CannotLiquidate(); /// Only the position/trade owner can update the LP/Trader margin error OnlyOwnerCanUpdatePosition(); error OnlyVAMM(); error OnlyFCM(); /// Margin delta must not equal zero error InvalidMarginDelta(); /// Positions and Traders cannot be settled before the applicable interest rate swap has matured error CannotSettleBeforeMaturity(); error closeToOrBeyondMaturity(); /// @dev There are not enough funds available for the requested operation error NotEnoughFunds(uint256 requested, uint256 available); /// @dev The two values were expected to have oppostite sigs, but do not error ExpectedOppositeSigns(int256 amount0, int256 amount1); /// @dev Error which is reverted if the sqrt price of the vamm is non-zero before a vamm is initialized error ExpectedSqrtPriceZeroBeforeInit(uint160 sqrtPriceX96); /// @dev Error which ensures the liquidity delta is positive if a given LP wishes to mint further liquidity in the vamm error LiquidityDeltaMustBePositiveInMint(uint128 amount); /// @dev Error which ensures the liquidity delta is positive if a given LP wishes to burn liquidity in the vamm error LiquidityDeltaMustBePositiveInBurn(uint128 amount); /// @dev Error which ensures the amount of notional specified when initiating an IRS contract (via the swap function in the vamm) is non-zero error IRSNotionalAmountSpecifiedMustBeNonZero(); /// @dev Error which ensures the VAMM is unlocked error CanOnlyTradeIfUnlocked(bool unlocked); /// @dev only the margin engine can run a certain function error OnlyMarginEngine(); /// The resulting margin does not meet minimum requirements error MarginRequirementNotMetFCM(int256 marginRequirement); /// @dev getReserveNormalizedIncome() returned zero for underlying asset. Oracle only supports active Aave-V2 assets. error AavePoolGetReserveNormalizedIncomeReturnedZero(); /// @dev getPooledEthByShares() returned zero for Lido's stETH. error LidoGetPooledEthBySharesReturnedZero(); /// @dev getEthValue() returned zero for RocketPool's RETH. error RocketPoolGetEthValueReturnedZero(); /// @dev ctoken.exchangeRateStored() returned zero for a given Compound ctoken. Oracle only supports active Compound assets. error CTokenExchangeRateReturnedZero(); /// @dev currentTime < queriedTime error OOO(); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.9; /// @title Minimal ERC20 interface for Voltz /// @notice Contains a subset of the full ERC20 interface that is used in Voltz interface IERC20Minimal { /// @notice Returns the balance of a token /// @param account The account for which to look up the number of tokens it has, i.e. its balance /// @return The number of tokens held by the account function balanceOf(address account) external view returns (uint256); /// @notice Transfers the amount of token from the `msg.sender` to the recipient /// @param recipient The account that will receive the amount transferred /// @param amount The number of tokens to send from the sender to the recipient /// @return Returns true for a successful transfer, false for an unsuccessful transfer function transfer(address recipient, uint256 amount) external returns (bool); /// @notice Returns the current allowance given to a spender by an owner /// @param owner The account of the token owner /// @param spender The account of the token spender /// @return The current allowance granted by `owner` to `spender` function allowance(address owner, address spender) external view returns (uint256); /// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount` /// @param spender The account which will be allowed to spend a given amount of the owners tokens /// @param amount The amount of tokens allowed to be used by `spender` /// @return Returns true for a successful approval, false for unsuccessful function approve(address spender, uint256 amount) external returns (bool); /// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender` /// @param sender The account from which the transfer will be initiated /// @param recipient The recipient of the transfer /// @param amount The amount of the transfer /// @return Returns true for a successful transfer, false for unsuccessful function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /// @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. function decimals() external view returns (uint8); /// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`. /// @param from The account from which the tokens were sent, i.e. the balance decreased /// @param to The account to which the tokens were sent, i.e. the balance increased /// @param value The amount of tokens that were transferred event Transfer(address indexed from, address indexed to, uint256 value); /// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes. /// @param owner The account that approved spending of its tokens /// @param spender The account for which the spending allowance was modified /// @param value The new allowance from the owner to the spender event Approval( address indexed owner, address indexed spender, uint256 value ); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; import "prb-math/contracts/PRBMathSD59x18.sol"; import "prb-math/contracts/PRBMathUD60x18.sol"; import "./Time.sol"; /// @title A utility library for mathematics of fixed and variable token amounts. library FixedAndVariableMath { using PRBMathSD59x18 for int256; using PRBMathUD60x18 for uint256; /// @notice Number of wei-seconds in a year /// @dev Ignoring leap years since we're only using it to calculate the eventual APY rate uint256 public constant SECONDS_IN_YEAR_IN_WAD = 31536000e18; uint256 public constant ONE_HUNDRED_IN_WAD = 100e18; /// @notice Caclulate the remaining cashflow to settle a position /// @param fixedTokenBalance The current balance of the fixed side of the position /// @param variableTokenBalance The current balance of the variable side of the position /// @param termStartTimestampWad When did the position begin, in seconds /// @param termEndTimestampWad When does the position reach maturity, in seconds /// @param variableFactorToMaturityWad What factor expresses the current remaining variable rate, up to position maturity? (in wad) /// @return cashflow The remaining cashflow of the position function calculateSettlementCashflow( int256 fixedTokenBalance, int256 variableTokenBalance, uint256 termStartTimestampWad, uint256 termEndTimestampWad, uint256 variableFactorToMaturityWad ) internal view returns (int256 cashflow) { /// @dev convert fixed and variable token balances to their respective fixed token representations int256 fixedTokenBalanceWad = fixedTokenBalance.fromInt(); int256 variableTokenBalanceWad = variableTokenBalance.fromInt(); int256 fixedCashflowWad = fixedTokenBalanceWad.mul( int256( fixedFactor(true, termStartTimestampWad, termEndTimestampWad) ) ); int256 variableCashflowWad = variableTokenBalanceWad.mul( int256(variableFactorToMaturityWad) ); int256 cashflowWad = fixedCashflowWad + variableCashflowWad; /// @dev convert back to non-fixed point representation cashflow = cashflowWad.toInt(); } /// @notice Divide a given time in seconds by the number of seconds in a year /// @param timeInSecondsAsWad A time in seconds in Wad (i.e. scaled up by 10^18) /// @return timeInYearsWad An annualised factor of timeInSeconds, also in Wad function accrualFact(uint256 timeInSecondsAsWad) internal pure returns (uint256 timeInYearsWad) { timeInYearsWad = timeInSecondsAsWad.div(SECONDS_IN_YEAR_IN_WAD); } /// @notice Calculate the fixed factor for a position - that is, the percentage earned over /// the specified period of time, assuming 1% per year /// @param atMaturity Whether to calculate the factor at maturity (true), or now (false) /// @param termStartTimestampWad When does the period of time begin, in wei-seconds /// @param termEndTimestampWad When does the period of time end, in wei-seconds /// @return fixedFactorValueWad The fixed factor for the position (in Wad) function fixedFactor( bool atMaturity, uint256 termStartTimestampWad, uint256 termEndTimestampWad ) internal view returns (uint256 fixedFactorValueWad) { require(termEndTimestampWad > termStartTimestampWad, "E<=S"); uint256 currentTimestampWad = Time.blockTimestampScaled(); require(currentTimestampWad >= termStartTimestampWad, "B.T<S"); uint256 timeInSecondsWad; if (atMaturity || (currentTimestampWad >= termEndTimestampWad)) { timeInSecondsWad = termEndTimestampWad - termStartTimestampWad; } else { timeInSecondsWad = currentTimestampWad - termStartTimestampWad; } fixedFactorValueWad = accrualFact(timeInSecondsWad).div( ONE_HUNDRED_IN_WAD ); } /// @notice Calculate the fixed token balance for a position over a timespan /// @param amountFixedWad A fixed amount /// @param excessBalanceWad Cashflows accrued to the fixed and variable token amounts since the inception of the IRS AMM /// @param termStartTimestampWad When does the period of time begin, in wei-seconds /// @param termEndTimestampWad When does the period of time end, in wei-seconds /// @return fixedTokenBalanceWad The fixed token balance for that time period function calculateFixedTokenBalance( int256 amountFixedWad, int256 excessBalanceWad, uint256 termStartTimestampWad, uint256 termEndTimestampWad ) internal view returns (int256 fixedTokenBalanceWad) { require(termEndTimestampWad > termStartTimestampWad, "E<=S"); return amountFixedWad - excessBalanceWad.div( int256( fixedFactor( true, termStartTimestampWad, termEndTimestampWad ) ) ); } /// @notice Calculate the excess balance of both sides of a position in Wad /// @param amountFixedWad A fixed balance /// @param amountVariableWad A variable balance /// @param accruedVariableFactorWad An annualised factor in wei-years /// @param termStartTimestampWad When does the period of time begin, in wei-seconds /// @param termEndTimestampWad When does the period of time end, in wei-seconds /// @return excessBalanceWad The excess balance in wad function getExcessBalance( int256 amountFixedWad, int256 amountVariableWad, uint256 accruedVariableFactorWad, uint256 termStartTimestampWad, uint256 termEndTimestampWad ) internal view returns (int256) { /// @dev cashflows accrued since the inception of the IRS AMM return amountFixedWad.mul( int256( fixedFactor( false, termStartTimestampWad, termEndTimestampWad ) ) ) + amountVariableWad.mul(int256(accruedVariableFactorWad)); } /// @notice Calculate the fixed token balance given both fixed and variable balances /// @param amountFixed A fixed balance /// @param amountVariable A variable balance /// @param accruedVariableFactorWad An annualised factor in wei-years /// @param termStartTimestampWad When does the period of time begin, in wei-seconds /// @param termEndTimestampWad When does the period of time end, in wei-seconds /// @return fixedTokenBalance The fixed token balance for that time period function getFixedTokenBalance( int256 amountFixed, int256 amountVariable, uint256 accruedVariableFactorWad, uint256 termStartTimestampWad, uint256 termEndTimestampWad ) internal view returns (int256 fixedTokenBalance) { require(termEndTimestampWad > termStartTimestampWad, "E<=S"); if (amountFixed == 0 && amountVariable == 0) return 0; int256 amountFixedWad = amountFixed.fromInt(); int256 amountVariableWad = amountVariable.fromInt(); int256 excessBalanceWad = getExcessBalance( amountFixedWad, amountVariableWad, accruedVariableFactorWad, termStartTimestampWad, termEndTimestampWad ); int256 fixedTokenBalanceWad = calculateFixedTokenBalance( amountFixedWad, excessBalanceWad, termStartTimestampWad, termEndTimestampWad ); fixedTokenBalance = fixedTokenBalanceWad.toInt(); } }
// SPDX-License-Identifier: Unlicense pragma solidity >=0.8.4; import "./PRBMath.sol"; /// @title PRBMathUD60x18 /// @author Paul Razvan Berg /// @notice Smart contract library for advanced fixed-point math that works with uint256 numbers considered to have 18 /// trailing decimals. We call this number representation unsigned 60.18-decimal fixed-point, since there can be up to 60 /// digits in the integer part and up to 18 decimals in the fractional part. The numbers are bound by the minimum and the /// maximum values permitted by the Solidity type uint256. library PRBMathUD60x18 { /// @dev Half the SCALE number. uint256 internal constant HALF_SCALE = 5e17; /// @dev log2(e) as an unsigned 60.18-decimal fixed-point number. uint256 internal constant LOG2_E = 1_442695040888963407; /// @dev The maximum value an unsigned 60.18-decimal fixed-point number can have. uint256 internal constant MAX_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_584007913129639935; /// @dev The maximum whole value an unsigned 60.18-decimal fixed-point number can have. uint256 internal constant MAX_WHOLE_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_000000000000000000; /// @dev How many trailing decimals can be represented. uint256 internal constant SCALE = 1e18; /// @notice Calculates the arithmetic average of x and y, rounding down. /// @param x The first operand as an unsigned 60.18-decimal fixed-point number. /// @param y The second operand as an unsigned 60.18-decimal fixed-point number. /// @return result The arithmetic average as an unsigned 60.18-decimal fixed-point number. function avg(uint256 x, uint256 y) internal pure returns (uint256 result) { // The operations can never overflow. unchecked { // The last operand checks if both x and y are odd and if that is the case, we add 1 to the result. We need // to do this because if both numbers are odd, the 0.5 remainder gets truncated twice. result = (x >> 1) + (y >> 1) + (x & y & 1); } } /// @notice Yields the least unsigned 60.18 decimal fixed-point number greater than or equal to x. /// /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts. /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions. /// /// Requirements: /// - x must be less than or equal to MAX_WHOLE_UD60x18. /// /// @param x The unsigned 60.18-decimal fixed-point number to ceil. /// @param result The least integer greater than or equal to x, as an unsigned 60.18-decimal fixed-point number. function ceil(uint256 x) internal pure returns (uint256 result) { if (x > MAX_WHOLE_UD60x18) { revert PRBMathUD60x18__CeilOverflow(x); } assembly { // Equivalent to "x % SCALE" but faster. let remainder := mod(x, SCALE) // Equivalent to "SCALE - remainder" but faster. let delta := sub(SCALE, remainder) // Equivalent to "x + delta * (remainder > 0 ? 1 : 0)" but faster. result := add(x, mul(delta, gt(remainder, 0))) } } /// @notice Divides two unsigned 60.18-decimal fixed-point numbers, returning a new unsigned 60.18-decimal fixed-point number. /// /// @dev Uses mulDiv to enable overflow-safe multiplication and division. /// /// Requirements: /// - The denominator cannot be zero. /// /// @param x The numerator as an unsigned 60.18-decimal fixed-point number. /// @param y The denominator as an unsigned 60.18-decimal fixed-point number. /// @param result The quotient as an unsigned 60.18-decimal fixed-point number. function div(uint256 x, uint256 y) internal pure returns (uint256 result) { result = PRBMath.mulDiv(x, SCALE, y); } /// @notice Returns Euler's number as an unsigned 60.18-decimal fixed-point number. /// @dev See https://en.wikipedia.org/wiki/E_(mathematical_constant). function e() internal pure returns (uint256 result) { result = 2_718281828459045235; } /// @notice Calculates the natural exponent of x. /// /// @dev Based on the insight that e^x = 2^(x * log2(e)). /// /// Requirements: /// - All from "log2". /// - x must be less than 133.084258667509499441. /// /// @param x The exponent as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function exp(uint256 x) internal pure returns (uint256 result) { // Without this check, the value passed to "exp2" would be greater than 192. if (x >= 133_084258667509499441) { revert PRBMathUD60x18__ExpInputTooBig(x); } // Do the fixed-point multiplication inline to save gas. unchecked { uint256 doubleScaleProduct = x * LOG2_E; result = exp2((doubleScaleProduct + HALF_SCALE) / SCALE); } } /// @notice Calculates the binary exponent of x using the binary fraction method. /// /// @dev See https://ethereum.stackexchange.com/q/79903/24693. /// /// Requirements: /// - x must be 192 or less. /// - The result must fit within MAX_UD60x18. /// /// @param x The exponent as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function exp2(uint256 x) internal pure returns (uint256 result) { // 2^192 doesn't fit within the 192.64-bit format used internally in this function. if (x >= 192e18) { revert PRBMathUD60x18__Exp2InputTooBig(x); } unchecked { // Convert x to the 192.64-bit fixed-point format. uint256 x192x64 = (x << 64) / SCALE; // Pass x to the PRBMath.exp2 function, which uses the 192.64-bit fixed-point number representation. result = PRBMath.exp2(x192x64); } } /// @notice Yields the greatest unsigned 60.18 decimal fixed-point number less than or equal to x. /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts. /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions. /// @param x The unsigned 60.18-decimal fixed-point number to floor. /// @param result The greatest integer less than or equal to x, as an unsigned 60.18-decimal fixed-point number. function floor(uint256 x) internal pure returns (uint256 result) { assembly { // Equivalent to "x % SCALE" but faster. let remainder := mod(x, SCALE) // Equivalent to "x - remainder * (remainder > 0 ? 1 : 0)" but faster. result := sub(x, mul(remainder, gt(remainder, 0))) } } /// @notice Yields the excess beyond the floor of x. /// @dev Based on the odd function definition https://en.wikipedia.org/wiki/Fractional_part. /// @param x The unsigned 60.18-decimal fixed-point number to get the fractional part of. /// @param result The fractional part of x as an unsigned 60.18-decimal fixed-point number. function frac(uint256 x) internal pure returns (uint256 result) { assembly { result := mod(x, SCALE) } } /// @notice Converts a number from basic integer form to unsigned 60.18-decimal fixed-point representation. /// /// @dev Requirements: /// - x must be less than or equal to MAX_UD60x18 divided by SCALE. /// /// @param x The basic integer to convert. /// @param result The same number in unsigned 60.18-decimal fixed-point representation. function fromUint(uint256 x) internal pure returns (uint256 result) { unchecked { if (x > MAX_UD60x18 / SCALE) { revert PRBMathUD60x18__FromUintOverflow(x); } result = x * SCALE; } } /// @notice Calculates geometric mean of x and y, i.e. sqrt(x * y), rounding down. /// /// @dev Requirements: /// - x * y must fit within MAX_UD60x18, lest it overflows. /// /// @param x The first operand as an unsigned 60.18-decimal fixed-point number. /// @param y The second operand as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function gm(uint256 x, uint256 y) internal pure returns (uint256 result) { if (x == 0) { return 0; } unchecked { // Checking for overflow this way is faster than letting Solidity do it. uint256 xy = x * y; if (xy / x != y) { revert PRBMathUD60x18__GmOverflow(x, y); } // We don't need to multiply by the SCALE here because the x*y product had already picked up a factor of SCALE // during multiplication. See the comments within the "sqrt" function. result = PRBMath.sqrt(xy); } } /// @notice Calculates 1 / x, rounding toward zero. /// /// @dev Requirements: /// - x cannot be zero. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the inverse. /// @return result The inverse as an unsigned 60.18-decimal fixed-point number. function inv(uint256 x) internal pure returns (uint256 result) { unchecked { // 1e36 is SCALE * SCALE. result = 1e36 / x; } } /// @notice Calculates the natural logarithm of x. /// /// @dev Based on the insight that ln(x) = log2(x) / log2(e). /// /// Requirements: /// - All from "log2". /// /// Caveats: /// - All from "log2". /// - This doesn't return exactly 1 for 2.718281828459045235, for that we would need more fine-grained precision. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the natural logarithm. /// @return result The natural logarithm as an unsigned 60.18-decimal fixed-point number. function ln(uint256 x) internal pure returns (uint256 result) { // Do the fixed-point multiplication inline to save gas. This is overflow-safe because the maximum value that log2(x) // can return is 196205294292027477728. unchecked { result = (log2(x) * SCALE) / LOG2_E; } } /// @notice Calculates the common logarithm of x. /// /// @dev First checks if x is an exact power of ten and it stops if yes. If it's not, calculates the common /// logarithm based on the insight that log10(x) = log2(x) / log2(10). /// /// Requirements: /// - All from "log2". /// /// Caveats: /// - All from "log2". /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the common logarithm. /// @return result The common logarithm as an unsigned 60.18-decimal fixed-point number. function log10(uint256 x) internal pure returns (uint256 result) { if (x < SCALE) { revert PRBMathUD60x18__LogInputTooSmall(x); } // Note that the "mul" in this block is the assembly multiplication operation, not the "mul" function defined // in this contract. // prettier-ignore assembly { switch x case 1 { result := mul(SCALE, sub(0, 18)) } case 10 { result := mul(SCALE, sub(1, 18)) } case 100 { result := mul(SCALE, sub(2, 18)) } case 1000 { result := mul(SCALE, sub(3, 18)) } case 10000 { result := mul(SCALE, sub(4, 18)) } case 100000 { result := mul(SCALE, sub(5, 18)) } case 1000000 { result := mul(SCALE, sub(6, 18)) } case 10000000 { result := mul(SCALE, sub(7, 18)) } case 100000000 { result := mul(SCALE, sub(8, 18)) } case 1000000000 { result := mul(SCALE, sub(9, 18)) } case 10000000000 { result := mul(SCALE, sub(10, 18)) } case 100000000000 { result := mul(SCALE, sub(11, 18)) } case 1000000000000 { result := mul(SCALE, sub(12, 18)) } case 10000000000000 { result := mul(SCALE, sub(13, 18)) } case 100000000000000 { result := mul(SCALE, sub(14, 18)) } case 1000000000000000 { result := mul(SCALE, sub(15, 18)) } case 10000000000000000 { result := mul(SCALE, sub(16, 18)) } case 100000000000000000 { result := mul(SCALE, sub(17, 18)) } case 1000000000000000000 { result := 0 } case 10000000000000000000 { result := SCALE } case 100000000000000000000 { result := mul(SCALE, 2) } case 1000000000000000000000 { result := mul(SCALE, 3) } case 10000000000000000000000 { result := mul(SCALE, 4) } case 100000000000000000000000 { result := mul(SCALE, 5) } case 1000000000000000000000000 { result := mul(SCALE, 6) } case 10000000000000000000000000 { result := mul(SCALE, 7) } case 100000000000000000000000000 { result := mul(SCALE, 8) } case 1000000000000000000000000000 { result := mul(SCALE, 9) } case 10000000000000000000000000000 { result := mul(SCALE, 10) } case 100000000000000000000000000000 { result := mul(SCALE, 11) } case 1000000000000000000000000000000 { result := mul(SCALE, 12) } case 10000000000000000000000000000000 { result := mul(SCALE, 13) } case 100000000000000000000000000000000 { result := mul(SCALE, 14) } case 1000000000000000000000000000000000 { result := mul(SCALE, 15) } case 10000000000000000000000000000000000 { result := mul(SCALE, 16) } case 100000000000000000000000000000000000 { result := mul(SCALE, 17) } case 1000000000000000000000000000000000000 { result := mul(SCALE, 18) } case 10000000000000000000000000000000000000 { result := mul(SCALE, 19) } case 100000000000000000000000000000000000000 { result := mul(SCALE, 20) } case 1000000000000000000000000000000000000000 { result := mul(SCALE, 21) } case 10000000000000000000000000000000000000000 { result := mul(SCALE, 22) } case 100000000000000000000000000000000000000000 { result := mul(SCALE, 23) } case 1000000000000000000000000000000000000000000 { result := mul(SCALE, 24) } case 10000000000000000000000000000000000000000000 { result := mul(SCALE, 25) } case 100000000000000000000000000000000000000000000 { result := mul(SCALE, 26) } case 1000000000000000000000000000000000000000000000 { result := mul(SCALE, 27) } case 10000000000000000000000000000000000000000000000 { result := mul(SCALE, 28) } case 100000000000000000000000000000000000000000000000 { result := mul(SCALE, 29) } case 1000000000000000000000000000000000000000000000000 { result := mul(SCALE, 30) } case 10000000000000000000000000000000000000000000000000 { result := mul(SCALE, 31) } case 100000000000000000000000000000000000000000000000000 { result := mul(SCALE, 32) } case 1000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 33) } case 10000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 34) } case 100000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 35) } case 1000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 36) } case 10000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 37) } case 100000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 38) } case 1000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 39) } case 10000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 40) } case 100000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 41) } case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 42) } case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 43) } case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 44) } case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 45) } case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 46) } case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 47) } case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 48) } case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 49) } case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 50) } case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 51) } case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 52) } case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 53) } case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 54) } case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 55) } case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 56) } case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 57) } case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 58) } case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 59) } default { result := MAX_UD60x18 } } if (result == MAX_UD60x18) { // Do the fixed-point division inline to save gas. The denominator is log2(10). unchecked { result = (log2(x) * SCALE) / 3_321928094887362347; } } } /// @notice Calculates the binary logarithm of x. /// /// @dev Based on the iterative approximation algorithm. /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation /// /// Requirements: /// - x must be greater than or equal to SCALE, otherwise the result would be negative. /// /// Caveats: /// - The results are nor perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the binary logarithm. /// @return result The binary logarithm as an unsigned 60.18-decimal fixed-point number. function log2(uint256 x) internal pure returns (uint256 result) { if (x < SCALE) { revert PRBMathUD60x18__LogInputTooSmall(x); } unchecked { // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n). uint256 n = PRBMath.mostSignificantBit(x / SCALE); // The integer part of the logarithm as an unsigned 60.18-decimal fixed-point number. The operation can't overflow // because n is maximum 255 and SCALE is 1e18. result = n * SCALE; // This is y = x * 2^(-n). uint256 y = x >> n; // If y = 1, the fractional part is zero. if (y == SCALE) { return result; } // Calculate the fractional part via the iterative approximation. // The "delta >>= 1" part is equivalent to "delta /= 2", but shifting bits is faster. for (uint256 delta = HALF_SCALE; delta > 0; delta >>= 1) { y = (y * y) / SCALE; // Is y^2 > 2 and so in the range [2,4)? if (y >= 2 * SCALE) { // Add the 2^(-m) factor to the logarithm. result += delta; // Corresponds to z/2 on Wikipedia. y >>= 1; } } } } /// @notice Multiplies two unsigned 60.18-decimal fixed-point numbers together, returning a new unsigned 60.18-decimal /// fixed-point number. /// @dev See the documentation for the "PRBMath.mulDivFixedPoint" function. /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number. /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number. /// @return result The product as an unsigned 60.18-decimal fixed-point number. function mul(uint256 x, uint256 y) internal pure returns (uint256 result) { result = PRBMath.mulDivFixedPoint(x, y); } /// @notice Returns PI as an unsigned 60.18-decimal fixed-point number. function pi() internal pure returns (uint256 result) { result = 3_141592653589793238; } /// @notice Raises x to the power of y. /// /// @dev Based on the insight that x^y = 2^(log2(x) * y). /// /// Requirements: /// - All from "exp2", "log2" and "mul". /// /// Caveats: /// - All from "exp2", "log2" and "mul". /// - Assumes 0^0 is 1. /// /// @param x Number to raise to given power y, as an unsigned 60.18-decimal fixed-point number. /// @param y Exponent to raise x to, as an unsigned 60.18-decimal fixed-point number. /// @return result x raised to power y, as an unsigned 60.18-decimal fixed-point number. function pow(uint256 x, uint256 y) internal pure returns (uint256 result) { if (x == 0) { result = y == 0 ? SCALE : uint256(0); } else { result = exp2(mul(log2(x), y)); } } /// @notice Raises x (unsigned 60.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the /// famous algorithm "exponentiation by squaring". /// /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring /// /// Requirements: /// - The result must fit within MAX_UD60x18. /// /// Caveats: /// - All from "mul". /// - Assumes 0^0 is 1. /// /// @param x The base as an unsigned 60.18-decimal fixed-point number. /// @param y The exponent as an uint256. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function powu(uint256 x, uint256 y) internal pure returns (uint256 result) { // Calculate the first iteration of the loop in advance. result = y & 1 > 0 ? x : SCALE; // Equivalent to "for(y /= 2; y > 0; y /= 2)" but faster. for (y >>= 1; y > 0; y >>= 1) { x = PRBMath.mulDivFixedPoint(x, x); // Equivalent to "y % 2 == 1" but faster. if (y & 1 > 0) { result = PRBMath.mulDivFixedPoint(result, x); } } } /// @notice Returns 1 as an unsigned 60.18-decimal fixed-point number. function scale() internal pure returns (uint256 result) { result = SCALE; } /// @notice Calculates the square root of x, rounding down. /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method. /// /// Requirements: /// - x must be less than MAX_UD60x18 / SCALE. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the square root. /// @return result The result as an unsigned 60.18-decimal fixed-point . function sqrt(uint256 x) internal pure returns (uint256 result) { unchecked { if (x > MAX_UD60x18 / SCALE) { revert PRBMathUD60x18__SqrtOverflow(x); } // Multiply x by the SCALE to account for the factor of SCALE that is picked up when multiplying two unsigned // 60.18-decimal fixed-point numbers together (in this case, those two numbers are both the square root). result = PRBMath.sqrt(x * SCALE); } } /// @notice Converts a unsigned 60.18-decimal fixed-point number to basic integer form, rounding down in the process. /// @param x The unsigned 60.18-decimal fixed-point number to convert. /// @return result The same number in basic integer form. function toUint(uint256 x) internal pure returns (uint256 result) { unchecked { result = x / SCALE; } } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; import "contracts/utils/CustomErrors.sol"; import "./rate_oracles/IRateOracle.sol"; import "./IMarginEngine.sol"; import "./IVAMM.sol"; import "./fcms/IFCM.sol"; import "./IERC20Minimal.sol"; import "./IPeriphery.sol"; /// @title The interface for the Voltz AMM Factory /// @notice The AMM Factory facilitates creation of Voltz AMMs interface IFactory is CustomErrors { event IrsInstance( IERC20Minimal indexed underlyingToken, IRateOracle indexed rateOracle, uint256 termStartTimestampWad, uint256 termEndTimestampWad, int24 tickSpacing, IMarginEngine marginEngine, IVAMM vamm, IFCM fcm, uint8 yieldBearingProtocolID, uint8 underlyingTokenDecimals ); event MasterFCM(IFCM masterFCMAddress, uint8 yieldBearingProtocolID); event Approval( address indexed owner, address indexed intAddress, bool indexed isApproved ); event PeripheryUpdate(IPeriphery periphery); // view functions function isApproved(address _owner, address intAddress) external view returns (bool); function masterVAMM() external view returns (IVAMM); function masterMarginEngine() external view returns (IMarginEngine); function periphery() external view returns (IPeriphery); // settters function setApproval(address intAddress, bool allowIntegration) external; function setMasterFCM(IFCM masterFCM, uint8 yieldBearingProtocolID) external; function setMasterVAMM(IVAMM _masterVAMM) external; function setMasterMarginEngine(IMarginEngine _masterMarginEngine) external; function setPeriphery(IPeriphery _periphery) external; /// @notice Deploys the contracts required for a new Interest Rate Swap instance function deployIrsInstance( IERC20Minimal _underlyingToken, IRateOracle _rateOracle, uint256 _termStartTimestampWad, uint256 _termEndTimestampWad, int24 _tickSpacing ) external returns ( IMarginEngine marginEngineProxy, IVAMM vammProxy, IFCM fcmProxy ); function masterFCMs(uint8 yieldBearingProtocolID) external view returns (IFCM masterFCM); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT pragma solidity >= 0.4.22 <0.9.0; library console { address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67); function _sendLogPayload(bytes memory payload) private view { uint256 payloadLength = payload.length; address consoleAddress = CONSOLE_ADDRESS; assembly { let payloadStart := add(payload, 32) let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0) } } function log() internal view { _sendLogPayload(abi.encodeWithSignature("log()")); } function logInt(int p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(int)", p0)); } function logUint(uint p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint)", p0)); } function logString(string memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(string)", p0)); } function logBool(bool p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool)", p0)); } function logAddress(address p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(address)", p0)); } function logBytes(bytes memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes)", p0)); } function logBytes1(bytes1 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0)); } function logBytes2(bytes2 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0)); } function logBytes3(bytes3 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0)); } function logBytes4(bytes4 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0)); } function logBytes5(bytes5 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0)); } function logBytes6(bytes6 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0)); } function logBytes7(bytes7 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0)); } function logBytes8(bytes8 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0)); } function logBytes9(bytes9 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0)); } function logBytes10(bytes10 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0)); } function logBytes11(bytes11 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0)); } function logBytes12(bytes12 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0)); } function logBytes13(bytes13 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0)); } function logBytes14(bytes14 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0)); } function logBytes15(bytes15 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0)); } function logBytes16(bytes16 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0)); } function logBytes17(bytes17 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0)); } function logBytes18(bytes18 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0)); } function logBytes19(bytes19 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0)); } function logBytes20(bytes20 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0)); } function logBytes21(bytes21 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0)); } function logBytes22(bytes22 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0)); } function logBytes23(bytes23 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0)); } function logBytes24(bytes24 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0)); } function logBytes25(bytes25 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0)); } function logBytes26(bytes26 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0)); } function logBytes27(bytes27 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0)); } function logBytes28(bytes28 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0)); } function logBytes29(bytes29 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0)); } function logBytes30(bytes30 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0)); } function logBytes31(bytes31 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0)); } function logBytes32(bytes32 p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0)); } function log(uint p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint)", p0)); } function log(string memory p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(string)", p0)); } function log(bool p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool)", p0)); } function log(address p0) internal view { _sendLogPayload(abi.encodeWithSignature("log(address)", p0)); } function log(uint p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint)", p0, p1)); } function log(uint p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string)", p0, p1)); } function log(uint p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool)", p0, p1)); } function log(uint p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address)", p0, p1)); } function log(string memory p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint)", p0, p1)); } function log(string memory p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1)); } function log(string memory p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1)); } function log(string memory p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1)); } function log(bool p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint)", p0, p1)); } function log(bool p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1)); } function log(bool p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1)); } function log(bool p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1)); } function log(address p0, uint p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint)", p0, p1)); } function log(address p0, string memory p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1)); } function log(address p0, bool p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1)); } function log(address p0, address p1) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1)); } function log(uint p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint)", p0, p1, p2)); } function log(uint p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string)", p0, p1, p2)); } function log(uint p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool)", p0, p1, p2)); } function log(uint p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address)", p0, p1, p2)); } function log(uint p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint)", p0, p1, p2)); } function log(uint p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string)", p0, p1, p2)); } function log(uint p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool)", p0, p1, p2)); } function log(uint p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address)", p0, p1, p2)); } function log(uint p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint)", p0, p1, p2)); } function log(uint p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string)", p0, p1, p2)); } function log(uint p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool)", p0, p1, p2)); } function log(uint p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address)", p0, p1, p2)); } function log(uint p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint)", p0, p1, p2)); } function log(uint p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string)", p0, p1, p2)); } function log(uint p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool)", p0, p1, p2)); } function log(uint p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address)", p0, p1, p2)); } function log(string memory p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint)", p0, p1, p2)); } function log(string memory p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string)", p0, p1, p2)); } function log(string memory p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool)", p0, p1, p2)); } function log(string memory p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address)", p0, p1, p2)); } function log(string memory p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint)", p0, p1, p2)); } function log(string memory p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2)); } function log(string memory p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2)); } function log(string memory p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2)); } function log(string memory p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint)", p0, p1, p2)); } function log(string memory p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2)); } function log(string memory p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2)); } function log(string memory p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2)); } function log(string memory p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint)", p0, p1, p2)); } function log(string memory p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2)); } function log(string memory p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2)); } function log(string memory p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2)); } function log(bool p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint)", p0, p1, p2)); } function log(bool p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string)", p0, p1, p2)); } function log(bool p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool)", p0, p1, p2)); } function log(bool p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address)", p0, p1, p2)); } function log(bool p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint)", p0, p1, p2)); } function log(bool p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2)); } function log(bool p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2)); } function log(bool p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2)); } function log(bool p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint)", p0, p1, p2)); } function log(bool p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2)); } function log(bool p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2)); } function log(bool p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2)); } function log(bool p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint)", p0, p1, p2)); } function log(bool p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2)); } function log(bool p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2)); } function log(bool p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2)); } function log(address p0, uint p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint)", p0, p1, p2)); } function log(address p0, uint p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string)", p0, p1, p2)); } function log(address p0, uint p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool)", p0, p1, p2)); } function log(address p0, uint p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address)", p0, p1, p2)); } function log(address p0, string memory p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint)", p0, p1, p2)); } function log(address p0, string memory p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2)); } function log(address p0, string memory p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2)); } function log(address p0, string memory p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2)); } function log(address p0, bool p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint)", p0, p1, p2)); } function log(address p0, bool p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2)); } function log(address p0, bool p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2)); } function log(address p0, bool p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2)); } function log(address p0, address p1, uint p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint)", p0, p1, p2)); } function log(address p0, address p1, string memory p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2)); } function log(address p0, address p1, bool p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2)); } function log(address p0, address p1, address p2) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2)); } function log(uint p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,address)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,uint)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,string)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,bool)", p0, p1, p2, p3)); } function log(uint p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,string,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,address)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,uint)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,string)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,bool)", p0, p1, p2, p3)); } function log(uint p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,string,address,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,address)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,uint)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,string)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,bool)", p0, p1, p2, p3)); } function log(uint p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,string,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,address)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,uint)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,string)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,bool)", p0, p1, p2, p3)); } function log(uint p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,string,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,string)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,uint,address,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,uint,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3)); } function log(string memory p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,address)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,uint)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,string)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,bool)", p0, p1, p2, p3)); } function log(bool p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3)); } function log(bool p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3)); } function log(bool p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3)); } function log(bool p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,string,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,address)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,uint)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,string)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,bool)", p0, p1, p2, p3)); } function log(address p0, uint p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,uint,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3)); } function log(address p0, string memory p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3)); } function log(address p0, bool p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,string)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, uint p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,address)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, string memory p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, bool p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, uint p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, string memory p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, bool p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3)); } function log(address p0, address p1, address p2, address p3) internal view { _sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3)); } }
// SPDX-License-Identifier: Unlicense pragma solidity >=0.8.4; import "./PRBMath.sol"; /// @title PRBMathSD59x18 /// @author Paul Razvan Berg /// @notice Smart contract library for advanced fixed-point math that works with int256 numbers considered to have 18 /// trailing decimals. We call this number representation signed 59.18-decimal fixed-point, since the numbers can have /// a sign and there can be up to 59 digits in the integer part and up to 18 decimals in the fractional part. The numbers /// are bound by the minimum and the maximum values permitted by the Solidity type int256. library PRBMathSD59x18 { /// @dev log2(e) as a signed 59.18-decimal fixed-point number. int256 internal constant LOG2_E = 1_442695040888963407; /// @dev Half the SCALE number. int256 internal constant HALF_SCALE = 5e17; /// @dev The maximum value a signed 59.18-decimal fixed-point number can have. int256 internal constant MAX_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_792003956564819967; /// @dev The maximum whole value a signed 59.18-decimal fixed-point number can have. int256 internal constant MAX_WHOLE_SD59x18 = 57896044618658097711785492504343953926634992332820282019728_000000000000000000; /// @dev The minimum value a signed 59.18-decimal fixed-point number can have. int256 internal constant MIN_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_792003956564819968; /// @dev The minimum whole value a signed 59.18-decimal fixed-point number can have. int256 internal constant MIN_WHOLE_SD59x18 = -57896044618658097711785492504343953926634992332820282019728_000000000000000000; /// @dev How many trailing decimals can be represented. int256 internal constant SCALE = 1e18; /// INTERNAL FUNCTIONS /// /// @notice Calculate the absolute value of x. /// /// @dev Requirements: /// - x must be greater than MIN_SD59x18. /// /// @param x The number to calculate the absolute value for. /// @param result The absolute value of x. function abs(int256 x) internal pure returns (int256 result) { unchecked { if (x == MIN_SD59x18) { revert PRBMathSD59x18__AbsInputTooSmall(); } result = x < 0 ? -x : x; } } /// @notice Calculates the arithmetic average of x and y, rounding down. /// @param x The first operand as a signed 59.18-decimal fixed-point number. /// @param y The second operand as a signed 59.18-decimal fixed-point number. /// @return result The arithmetic average as a signed 59.18-decimal fixed-point number. function avg(int256 x, int256 y) internal pure returns (int256 result) { // The operations can never overflow. unchecked { int256 sum = (x >> 1) + (y >> 1); if (sum < 0) { // If at least one of x and y is odd, we add 1 to the result. This is because shifting negative numbers to the // right rounds down to infinity. assembly { result := add(sum, and(or(x, y), 1)) } } else { // If both x and y are odd, we add 1 to the result. This is because if both numbers are odd, the 0.5 // remainder gets truncated twice. result = sum + (x & y & 1); } } } /// @notice Yields the least greatest signed 59.18 decimal fixed-point number greater than or equal to x. /// /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts. /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions. /// /// Requirements: /// - x must be less than or equal to MAX_WHOLE_SD59x18. /// /// @param x The signed 59.18-decimal fixed-point number to ceil. /// @param result The least integer greater than or equal to x, as a signed 58.18-decimal fixed-point number. function ceil(int256 x) internal pure returns (int256 result) { if (x > MAX_WHOLE_SD59x18) { revert PRBMathSD59x18__CeilOverflow(x); } unchecked { int256 remainder = x % SCALE; if (remainder == 0) { result = x; } else { // Solidity uses C fmod style, which returns a modulus with the same sign as x. result = x - remainder; if (x > 0) { result += SCALE; } } } } /// @notice Divides two signed 59.18-decimal fixed-point numbers, returning a new signed 59.18-decimal fixed-point number. /// /// @dev Variant of "mulDiv" that works with signed numbers. Works by computing the signs and the absolute values separately. /// /// Requirements: /// - All from "PRBMath.mulDiv". /// - None of the inputs can be MIN_SD59x18. /// - The denominator cannot be zero. /// - The result must fit within int256. /// /// Caveats: /// - All from "PRBMath.mulDiv". /// /// @param x The numerator as a signed 59.18-decimal fixed-point number. /// @param y The denominator as a signed 59.18-decimal fixed-point number. /// @param result The quotient as a signed 59.18-decimal fixed-point number. function div(int256 x, int256 y) internal pure returns (int256 result) { if (x == MIN_SD59x18 || y == MIN_SD59x18) { revert PRBMathSD59x18__DivInputTooSmall(); } // Get hold of the absolute values of x and y. uint256 ax; uint256 ay; unchecked { ax = x < 0 ? uint256(-x) : uint256(x); ay = y < 0 ? uint256(-y) : uint256(y); } // Compute the absolute value of (x*SCALE)÷y. The result must fit within int256. uint256 rAbs = PRBMath.mulDiv(ax, uint256(SCALE), ay); if (rAbs > uint256(MAX_SD59x18)) { revert PRBMathSD59x18__DivOverflow(rAbs); } // Get the signs of x and y. uint256 sx; uint256 sy; assembly { sx := sgt(x, sub(0, 1)) sy := sgt(y, sub(0, 1)) } // XOR over sx and sy. This is basically checking whether the inputs have the same sign. If yes, the result // should be positive. Otherwise, it should be negative. result = sx ^ sy == 1 ? -int256(rAbs) : int256(rAbs); } /// @notice Returns Euler's number as a signed 59.18-decimal fixed-point number. /// @dev See https://en.wikipedia.org/wiki/E_(mathematical_constant). function e() internal pure returns (int256 result) { result = 2_718281828459045235; } /// @notice Calculates the natural exponent of x. /// /// @dev Based on the insight that e^x = 2^(x * log2(e)). /// /// Requirements: /// - All from "log2". /// - x must be less than 133.084258667509499441. /// /// Caveats: /// - All from "exp2". /// - For any x less than -41.446531673892822322, the result is zero. /// /// @param x The exponent as a signed 59.18-decimal fixed-point number. /// @return result The result as a signed 59.18-decimal fixed-point number. function exp(int256 x) internal pure returns (int256 result) { // Without this check, the value passed to "exp2" would be less than -59.794705707972522261. if (x < -41_446531673892822322) { return 0; } // Without this check, the value passed to "exp2" would be greater than 192. if (x >= 133_084258667509499441) { revert PRBMathSD59x18__ExpInputTooBig(x); } // Do the fixed-point multiplication inline to save gas. unchecked { int256 doubleScaleProduct = x * LOG2_E; result = exp2((doubleScaleProduct + HALF_SCALE) / SCALE); } } /// @notice Calculates the binary exponent of x using the binary fraction method. /// /// @dev See https://ethereum.stackexchange.com/q/79903/24693. /// /// Requirements: /// - x must be 192 or less. /// - The result must fit within MAX_SD59x18. /// /// Caveats: /// - For any x less than -59.794705707972522261, the result is zero. /// /// @param x The exponent as a signed 59.18-decimal fixed-point number. /// @return result The result as a signed 59.18-decimal fixed-point number. function exp2(int256 x) internal pure returns (int256 result) { // This works because 2^(-x) = 1/2^x. if (x < 0) { // 2^59.794705707972522262 is the maximum number whose inverse does not truncate down to zero. if (x < -59_794705707972522261) { return 0; } // Do the fixed-point inversion inline to save gas. The numerator is SCALE * SCALE. unchecked { result = 1e36 / exp2(-x); } } else { // 2^192 doesn't fit within the 192.64-bit format used internally in this function. if (x >= 192e18) { revert PRBMathSD59x18__Exp2InputTooBig(x); } unchecked { // Convert x to the 192.64-bit fixed-point format. uint256 x192x64 = (uint256(x) << 64) / uint256(SCALE); // Safe to convert the result to int256 directly because the maximum input allowed is 192. result = int256(PRBMath.exp2(x192x64)); } } } /// @notice Yields the greatest signed 59.18 decimal fixed-point number less than or equal to x. /// /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts. /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions. /// /// Requirements: /// - x must be greater than or equal to MIN_WHOLE_SD59x18. /// /// @param x The signed 59.18-decimal fixed-point number to floor. /// @param result The greatest integer less than or equal to x, as a signed 58.18-decimal fixed-point number. function floor(int256 x) internal pure returns (int256 result) { if (x < MIN_WHOLE_SD59x18) { revert PRBMathSD59x18__FloorUnderflow(x); } unchecked { int256 remainder = x % SCALE; if (remainder == 0) { result = x; } else { // Solidity uses C fmod style, which returns a modulus with the same sign as x. result = x - remainder; if (x < 0) { result -= SCALE; } } } } /// @notice Yields the excess beyond the floor of x for positive numbers and the part of the number to the right /// of the radix point for negative numbers. /// @dev Based on the odd function definition. https://en.wikipedia.org/wiki/Fractional_part /// @param x The signed 59.18-decimal fixed-point number to get the fractional part of. /// @param result The fractional part of x as a signed 59.18-decimal fixed-point number. function frac(int256 x) internal pure returns (int256 result) { unchecked { result = x % SCALE; } } /// @notice Converts a number from basic integer form to signed 59.18-decimal fixed-point representation. /// /// @dev Requirements: /// - x must be greater than or equal to MIN_SD59x18 divided by SCALE. /// - x must be less than or equal to MAX_SD59x18 divided by SCALE. /// /// @param x The basic integer to convert. /// @param result The same number in signed 59.18-decimal fixed-point representation. function fromInt(int256 x) internal pure returns (int256 result) { unchecked { if (x < MIN_SD59x18 / SCALE) { revert PRBMathSD59x18__FromIntUnderflow(x); } if (x > MAX_SD59x18 / SCALE) { revert PRBMathSD59x18__FromIntOverflow(x); } result = x * SCALE; } } /// @notice Calculates geometric mean of x and y, i.e. sqrt(x * y), rounding down. /// /// @dev Requirements: /// - x * y must fit within MAX_SD59x18, lest it overflows. /// - x * y cannot be negative. /// /// @param x The first operand as a signed 59.18-decimal fixed-point number. /// @param y The second operand as a signed 59.18-decimal fixed-point number. /// @return result The result as a signed 59.18-decimal fixed-point number. function gm(int256 x, int256 y) internal pure returns (int256 result) { if (x == 0) { return 0; } unchecked { // Checking for overflow this way is faster than letting Solidity do it. int256 xy = x * y; if (xy / x != y) { revert PRBMathSD59x18__GmOverflow(x, y); } // The product cannot be negative. if (xy < 0) { revert PRBMathSD59x18__GmNegativeProduct(x, y); } // We don't need to multiply by the SCALE here because the x*y product had already picked up a factor of SCALE // during multiplication. See the comments within the "sqrt" function. result = int256(PRBMath.sqrt(uint256(xy))); } } /// @notice Calculates 1 / x, rounding toward zero. /// /// @dev Requirements: /// - x cannot be zero. /// /// @param x The signed 59.18-decimal fixed-point number for which to calculate the inverse. /// @return result The inverse as a signed 59.18-decimal fixed-point number. function inv(int256 x) internal pure returns (int256 result) { unchecked { // 1e36 is SCALE * SCALE. result = 1e36 / x; } } /// @notice Calculates the natural logarithm of x. /// /// @dev Based on the insight that ln(x) = log2(x) / log2(e). /// /// Requirements: /// - All from "log2". /// /// Caveats: /// - All from "log2". /// - This doesn't return exactly 1 for 2718281828459045235, for that we would need more fine-grained precision. /// /// @param x The signed 59.18-decimal fixed-point number for which to calculate the natural logarithm. /// @return result The natural logarithm as a signed 59.18-decimal fixed-point number. function ln(int256 x) internal pure returns (int256 result) { // Do the fixed-point multiplication inline to save gas. This is overflow-safe because the maximum value that log2(x) // can return is 195205294292027477728. unchecked { result = (log2(x) * SCALE) / LOG2_E; } } /// @notice Calculates the common logarithm of x. /// /// @dev First checks if x is an exact power of ten and it stops if yes. If it's not, calculates the common /// logarithm based on the insight that log10(x) = log2(x) / log2(10). /// /// Requirements: /// - All from "log2". /// /// Caveats: /// - All from "log2". /// /// @param x The signed 59.18-decimal fixed-point number for which to calculate the common logarithm. /// @return result The common logarithm as a signed 59.18-decimal fixed-point number. function log10(int256 x) internal pure returns (int256 result) { if (x <= 0) { revert PRBMathSD59x18__LogInputTooSmall(x); } // Note that the "mul" in this block is the assembly mul operation, not the "mul" function defined in this contract. // prettier-ignore assembly { switch x case 1 { result := mul(SCALE, sub(0, 18)) } case 10 { result := mul(SCALE, sub(1, 18)) } case 100 { result := mul(SCALE, sub(2, 18)) } case 1000 { result := mul(SCALE, sub(3, 18)) } case 10000 { result := mul(SCALE, sub(4, 18)) } case 100000 { result := mul(SCALE, sub(5, 18)) } case 1000000 { result := mul(SCALE, sub(6, 18)) } case 10000000 { result := mul(SCALE, sub(7, 18)) } case 100000000 { result := mul(SCALE, sub(8, 18)) } case 1000000000 { result := mul(SCALE, sub(9, 18)) } case 10000000000 { result := mul(SCALE, sub(10, 18)) } case 100000000000 { result := mul(SCALE, sub(11, 18)) } case 1000000000000 { result := mul(SCALE, sub(12, 18)) } case 10000000000000 { result := mul(SCALE, sub(13, 18)) } case 100000000000000 { result := mul(SCALE, sub(14, 18)) } case 1000000000000000 { result := mul(SCALE, sub(15, 18)) } case 10000000000000000 { result := mul(SCALE, sub(16, 18)) } case 100000000000000000 { result := mul(SCALE, sub(17, 18)) } case 1000000000000000000 { result := 0 } case 10000000000000000000 { result := SCALE } case 100000000000000000000 { result := mul(SCALE, 2) } case 1000000000000000000000 { result := mul(SCALE, 3) } case 10000000000000000000000 { result := mul(SCALE, 4) } case 100000000000000000000000 { result := mul(SCALE, 5) } case 1000000000000000000000000 { result := mul(SCALE, 6) } case 10000000000000000000000000 { result := mul(SCALE, 7) } case 100000000000000000000000000 { result := mul(SCALE, 8) } case 1000000000000000000000000000 { result := mul(SCALE, 9) } case 10000000000000000000000000000 { result := mul(SCALE, 10) } case 100000000000000000000000000000 { result := mul(SCALE, 11) } case 1000000000000000000000000000000 { result := mul(SCALE, 12) } case 10000000000000000000000000000000 { result := mul(SCALE, 13) } case 100000000000000000000000000000000 { result := mul(SCALE, 14) } case 1000000000000000000000000000000000 { result := mul(SCALE, 15) } case 10000000000000000000000000000000000 { result := mul(SCALE, 16) } case 100000000000000000000000000000000000 { result := mul(SCALE, 17) } case 1000000000000000000000000000000000000 { result := mul(SCALE, 18) } case 10000000000000000000000000000000000000 { result := mul(SCALE, 19) } case 100000000000000000000000000000000000000 { result := mul(SCALE, 20) } case 1000000000000000000000000000000000000000 { result := mul(SCALE, 21) } case 10000000000000000000000000000000000000000 { result := mul(SCALE, 22) } case 100000000000000000000000000000000000000000 { result := mul(SCALE, 23) } case 1000000000000000000000000000000000000000000 { result := mul(SCALE, 24) } case 10000000000000000000000000000000000000000000 { result := mul(SCALE, 25) } case 100000000000000000000000000000000000000000000 { result := mul(SCALE, 26) } case 1000000000000000000000000000000000000000000000 { result := mul(SCALE, 27) } case 10000000000000000000000000000000000000000000000 { result := mul(SCALE, 28) } case 100000000000000000000000000000000000000000000000 { result := mul(SCALE, 29) } case 1000000000000000000000000000000000000000000000000 { result := mul(SCALE, 30) } case 10000000000000000000000000000000000000000000000000 { result := mul(SCALE, 31) } case 100000000000000000000000000000000000000000000000000 { result := mul(SCALE, 32) } case 1000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 33) } case 10000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 34) } case 100000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 35) } case 1000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 36) } case 10000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 37) } case 100000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 38) } case 1000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 39) } case 10000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 40) } case 100000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 41) } case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 42) } case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 43) } case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 44) } case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 45) } case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 46) } case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 47) } case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 48) } case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 49) } case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 50) } case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 51) } case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 52) } case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 53) } case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 54) } case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 55) } case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 56) } case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 57) } case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 58) } default { result := MAX_SD59x18 } } if (result == MAX_SD59x18) { // Do the fixed-point division inline to save gas. The denominator is log2(10). unchecked { result = (log2(x) * SCALE) / 3_321928094887362347; } } } /// @notice Calculates the binary logarithm of x. /// /// @dev Based on the iterative approximation algorithm. /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation /// /// Requirements: /// - x must be greater than zero. /// /// Caveats: /// - The results are not perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation. /// /// @param x The signed 59.18-decimal fixed-point number for which to calculate the binary logarithm. /// @return result The binary logarithm as a signed 59.18-decimal fixed-point number. function log2(int256 x) internal pure returns (int256 result) { if (x <= 0) { revert PRBMathSD59x18__LogInputTooSmall(x); } unchecked { // This works because log2(x) = -log2(1/x). int256 sign; if (x >= SCALE) { sign = 1; } else { sign = -1; // Do the fixed-point inversion inline to save gas. The numerator is SCALE * SCALE. assembly { x := div(1000000000000000000000000000000000000, x) } } // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n). uint256 n = PRBMath.mostSignificantBit(uint256(x / SCALE)); // The integer part of the logarithm as a signed 59.18-decimal fixed-point number. The operation can't overflow // because n is maximum 255, SCALE is 1e18 and sign is either 1 or -1. result = int256(n) * SCALE; // This is y = x * 2^(-n). int256 y = x >> n; // If y = 1, the fractional part is zero. if (y == SCALE) { return result * sign; } // Calculate the fractional part via the iterative approximation. // The "delta >>= 1" part is equivalent to "delta /= 2", but shifting bits is faster. for (int256 delta = int256(HALF_SCALE); delta > 0; delta >>= 1) { y = (y * y) / SCALE; // Is y^2 > 2 and so in the range [2,4)? if (y >= 2 * SCALE) { // Add the 2^(-m) factor to the logarithm. result += delta; // Corresponds to z/2 on Wikipedia. y >>= 1; } } result *= sign; } } /// @notice Multiplies two signed 59.18-decimal fixed-point numbers together, returning a new signed 59.18-decimal /// fixed-point number. /// /// @dev Variant of "mulDiv" that works with signed numbers and employs constant folding, i.e. the denominator is /// always 1e18. /// /// Requirements: /// - All from "PRBMath.mulDivFixedPoint". /// - None of the inputs can be MIN_SD59x18 /// - The result must fit within MAX_SD59x18. /// /// Caveats: /// - The body is purposely left uncommented; see the NatSpec comments in "PRBMath.mulDiv" to understand how this works. /// /// @param x The multiplicand as a signed 59.18-decimal fixed-point number. /// @param y The multiplier as a signed 59.18-decimal fixed-point number. /// @return result The product as a signed 59.18-decimal fixed-point number. function mul(int256 x, int256 y) internal pure returns (int256 result) { if (x == MIN_SD59x18 || y == MIN_SD59x18) { revert PRBMathSD59x18__MulInputTooSmall(); } unchecked { uint256 ax; uint256 ay; ax = x < 0 ? uint256(-x) : uint256(x); ay = y < 0 ? uint256(-y) : uint256(y); uint256 rAbs = PRBMath.mulDivFixedPoint(ax, ay); if (rAbs > uint256(MAX_SD59x18)) { revert PRBMathSD59x18__MulOverflow(rAbs); } uint256 sx; uint256 sy; assembly { sx := sgt(x, sub(0, 1)) sy := sgt(y, sub(0, 1)) } result = sx ^ sy == 1 ? -int256(rAbs) : int256(rAbs); } } /// @notice Returns PI as a signed 59.18-decimal fixed-point number. function pi() internal pure returns (int256 result) { result = 3_141592653589793238; } /// @notice Raises x to the power of y. /// /// @dev Based on the insight that x^y = 2^(log2(x) * y). /// /// Requirements: /// - All from "exp2", "log2" and "mul". /// - z cannot be zero. /// /// Caveats: /// - All from "exp2", "log2" and "mul". /// - Assumes 0^0 is 1. /// /// @param x Number to raise to given power y, as a signed 59.18-decimal fixed-point number. /// @param y Exponent to raise x to, as a signed 59.18-decimal fixed-point number. /// @return result x raised to power y, as a signed 59.18-decimal fixed-point number. function pow(int256 x, int256 y) internal pure returns (int256 result) { if (x == 0) { result = y == 0 ? SCALE : int256(0); } else { result = exp2(mul(log2(x), y)); } } /// @notice Raises x (signed 59.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the /// famous algorithm "exponentiation by squaring". /// /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring /// /// Requirements: /// - All from "abs" and "PRBMath.mulDivFixedPoint". /// - The result must fit within MAX_SD59x18. /// /// Caveats: /// - All from "PRBMath.mulDivFixedPoint". /// - Assumes 0^0 is 1. /// /// @param x The base as a signed 59.18-decimal fixed-point number. /// @param y The exponent as an uint256. /// @return result The result as a signed 59.18-decimal fixed-point number. function powu(int256 x, uint256 y) internal pure returns (int256 result) { uint256 xAbs = uint256(abs(x)); // Calculate the first iteration of the loop in advance. uint256 rAbs = y & 1 > 0 ? xAbs : uint256(SCALE); // Equivalent to "for(y /= 2; y > 0; y /= 2)" but faster. uint256 yAux = y; for (yAux >>= 1; yAux > 0; yAux >>= 1) { xAbs = PRBMath.mulDivFixedPoint(xAbs, xAbs); // Equivalent to "y % 2 == 1" but faster. if (yAux & 1 > 0) { rAbs = PRBMath.mulDivFixedPoint(rAbs, xAbs); } } // The result must fit within the 59.18-decimal fixed-point representation. if (rAbs > uint256(MAX_SD59x18)) { revert PRBMathSD59x18__PowuOverflow(rAbs); } // Is the base negative and the exponent an odd number? bool isNegative = x < 0 && y & 1 == 1; result = isNegative ? -int256(rAbs) : int256(rAbs); } /// @notice Returns 1 as a signed 59.18-decimal fixed-point number. function scale() internal pure returns (int256 result) { result = SCALE; } /// @notice Calculates the square root of x, rounding down. /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method. /// /// Requirements: /// - x cannot be negative. /// - x must be less than MAX_SD59x18 / SCALE. /// /// @param x The signed 59.18-decimal fixed-point number for which to calculate the square root. /// @return result The result as a signed 59.18-decimal fixed-point . function sqrt(int256 x) internal pure returns (int256 result) { unchecked { if (x < 0) { revert PRBMathSD59x18__SqrtNegativeInput(x); } if (x > MAX_SD59x18 / SCALE) { revert PRBMathSD59x18__SqrtOverflow(x); } // Multiply x by the SCALE to account for the factor of SCALE that is picked up when multiplying two signed // 59.18-decimal fixed-point numbers together (in this case, those two numbers are both the square root). result = int256(PRBMath.sqrt(uint256(x * SCALE))); } } /// @notice Converts a signed 59.18-decimal fixed-point number to basic integer form, rounding down in the process. /// @param x The signed 59.18-decimal fixed-point number to convert. /// @return result The same number in basic integer form. function toInt(int256 x) internal pure returns (int256 result) { unchecked { result = x / SCALE; } } }
// SPDX-License-Identifier: Unlicense pragma solidity >=0.8.4; /// @notice Emitted when the result overflows uint256. error PRBMath__MulDivFixedPointOverflow(uint256 prod1); /// @notice Emitted when the result overflows uint256. error PRBMath__MulDivOverflow(uint256 prod1, uint256 denominator); /// @notice Emitted when one of the inputs is type(int256).min. error PRBMath__MulDivSignedInputTooSmall(); /// @notice Emitted when the intermediary absolute result overflows int256. error PRBMath__MulDivSignedOverflow(uint256 rAbs); /// @notice Emitted when the input is MIN_SD59x18. error PRBMathSD59x18__AbsInputTooSmall(); /// @notice Emitted when ceiling a number overflows SD59x18. error PRBMathSD59x18__CeilOverflow(int256 x); /// @notice Emitted when one of the inputs is MIN_SD59x18. error PRBMathSD59x18__DivInputTooSmall(); /// @notice Emitted when one of the intermediary unsigned results overflows SD59x18. error PRBMathSD59x18__DivOverflow(uint256 rAbs); /// @notice Emitted when the input is greater than 133.084258667509499441. error PRBMathSD59x18__ExpInputTooBig(int256 x); /// @notice Emitted when the input is greater than 192. error PRBMathSD59x18__Exp2InputTooBig(int256 x); /// @notice Emitted when flooring a number underflows SD59x18. error PRBMathSD59x18__FloorUnderflow(int256 x); /// @notice Emitted when converting a basic integer to the fixed-point format overflows SD59x18. error PRBMathSD59x18__FromIntOverflow(int256 x); /// @notice Emitted when converting a basic integer to the fixed-point format underflows SD59x18. error PRBMathSD59x18__FromIntUnderflow(int256 x); /// @notice Emitted when the product of the inputs is negative. error PRBMathSD59x18__GmNegativeProduct(int256 x, int256 y); /// @notice Emitted when multiplying the inputs overflows SD59x18. error PRBMathSD59x18__GmOverflow(int256 x, int256 y); /// @notice Emitted when the input is less than or equal to zero. error PRBMathSD59x18__LogInputTooSmall(int256 x); /// @notice Emitted when one of the inputs is MIN_SD59x18. error PRBMathSD59x18__MulInputTooSmall(); /// @notice Emitted when the intermediary absolute result overflows SD59x18. error PRBMathSD59x18__MulOverflow(uint256 rAbs); /// @notice Emitted when the intermediary absolute result overflows SD59x18. error PRBMathSD59x18__PowuOverflow(uint256 rAbs); /// @notice Emitted when the input is negative. error PRBMathSD59x18__SqrtNegativeInput(int256 x); /// @notice Emitted when the calculating the square root overflows SD59x18. error PRBMathSD59x18__SqrtOverflow(int256 x); /// @notice Emitted when addition overflows UD60x18. error PRBMathUD60x18__AddOverflow(uint256 x, uint256 y); /// @notice Emitted when ceiling a number overflows UD60x18. error PRBMathUD60x18__CeilOverflow(uint256 x); /// @notice Emitted when the input is greater than 133.084258667509499441. error PRBMathUD60x18__ExpInputTooBig(uint256 x); /// @notice Emitted when the input is greater than 192. error PRBMathUD60x18__Exp2InputTooBig(uint256 x); /// @notice Emitted when converting a basic integer to the fixed-point format format overflows UD60x18. error PRBMathUD60x18__FromUintOverflow(uint256 x); /// @notice Emitted when multiplying the inputs overflows UD60x18. error PRBMathUD60x18__GmOverflow(uint256 x, uint256 y); /// @notice Emitted when the input is less than 1. error PRBMathUD60x18__LogInputTooSmall(uint256 x); /// @notice Emitted when the calculating the square root overflows UD60x18. error PRBMathUD60x18__SqrtOverflow(uint256 x); /// @notice Emitted when subtraction underflows UD60x18. error PRBMathUD60x18__SubUnderflow(uint256 x, uint256 y); /// @dev Common mathematical functions used in both PRBMathSD59x18 and PRBMathUD60x18. Note that this shared library /// does not always assume the signed 59.18-decimal fixed-point or the unsigned 60.18-decimal fixed-point /// representation. When it does not, it is explicitly mentioned in the NatSpec documentation. library PRBMath { /// STRUCTS /// struct SD59x18 { int256 value; } struct UD60x18 { uint256 value; } /// STORAGE /// /// @dev How many trailing decimals can be represented. uint256 internal constant SCALE = 1e18; /// @dev Largest power of two divisor of SCALE. uint256 internal constant SCALE_LPOTD = 262144; /// @dev SCALE inverted mod 2^256. uint256 internal constant SCALE_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281; /// FUNCTIONS /// /// @notice Calculates the binary exponent of x using the binary fraction method. /// @dev Has to use 192.64-bit fixed-point numbers. /// See https://ethereum.stackexchange.com/a/96594/24693. /// @param x The exponent as an unsigned 192.64-bit fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function exp2(uint256 x) internal pure returns (uint256 result) { unchecked { // Start from 0.5 in the 192.64-bit fixed-point format. result = 0x800000000000000000000000000000000000000000000000; // Multiply the result by root(2, 2^-i) when the bit at position i is 1. None of the intermediary results overflows // because the initial result is 2^191 and all magic factors are less than 2^65. if (x & 0x8000000000000000 > 0) { result = (result * 0x16A09E667F3BCC909) >> 64; } if (x & 0x4000000000000000 > 0) { result = (result * 0x1306FE0A31B7152DF) >> 64; } if (x & 0x2000000000000000 > 0) { result = (result * 0x1172B83C7D517ADCE) >> 64; } if (x & 0x1000000000000000 > 0) { result = (result * 0x10B5586CF9890F62A) >> 64; } if (x & 0x800000000000000 > 0) { result = (result * 0x1059B0D31585743AE) >> 64; } if (x & 0x400000000000000 > 0) { result = (result * 0x102C9A3E778060EE7) >> 64; } if (x & 0x200000000000000 > 0) { result = (result * 0x10163DA9FB33356D8) >> 64; } if (x & 0x100000000000000 > 0) { result = (result * 0x100B1AFA5ABCBED61) >> 64; } if (x & 0x80000000000000 > 0) { result = (result * 0x10058C86DA1C09EA2) >> 64; } if (x & 0x40000000000000 > 0) { result = (result * 0x1002C605E2E8CEC50) >> 64; } if (x & 0x20000000000000 > 0) { result = (result * 0x100162F3904051FA1) >> 64; } if (x & 0x10000000000000 > 0) { result = (result * 0x1000B175EFFDC76BA) >> 64; } if (x & 0x8000000000000 > 0) { result = (result * 0x100058BA01FB9F96D) >> 64; } if (x & 0x4000000000000 > 0) { result = (result * 0x10002C5CC37DA9492) >> 64; } if (x & 0x2000000000000 > 0) { result = (result * 0x1000162E525EE0547) >> 64; } if (x & 0x1000000000000 > 0) { result = (result * 0x10000B17255775C04) >> 64; } if (x & 0x800000000000 > 0) { result = (result * 0x1000058B91B5BC9AE) >> 64; } if (x & 0x400000000000 > 0) { result = (result * 0x100002C5C89D5EC6D) >> 64; } if (x & 0x200000000000 > 0) { result = (result * 0x10000162E43F4F831) >> 64; } if (x & 0x100000000000 > 0) { result = (result * 0x100000B1721BCFC9A) >> 64; } if (x & 0x80000000000 > 0) { result = (result * 0x10000058B90CF1E6E) >> 64; } if (x & 0x40000000000 > 0) { result = (result * 0x1000002C5C863B73F) >> 64; } if (x & 0x20000000000 > 0) { result = (result * 0x100000162E430E5A2) >> 64; } if (x & 0x10000000000 > 0) { result = (result * 0x1000000B172183551) >> 64; } if (x & 0x8000000000 > 0) { result = (result * 0x100000058B90C0B49) >> 64; } if (x & 0x4000000000 > 0) { result = (result * 0x10000002C5C8601CC) >> 64; } if (x & 0x2000000000 > 0) { result = (result * 0x1000000162E42FFF0) >> 64; } if (x & 0x1000000000 > 0) { result = (result * 0x10000000B17217FBB) >> 64; } if (x & 0x800000000 > 0) { result = (result * 0x1000000058B90BFCE) >> 64; } if (x & 0x400000000 > 0) { result = (result * 0x100000002C5C85FE3) >> 64; } if (x & 0x200000000 > 0) { result = (result * 0x10000000162E42FF1) >> 64; } if (x & 0x100000000 > 0) { result = (result * 0x100000000B17217F8) >> 64; } if (x & 0x80000000 > 0) { result = (result * 0x10000000058B90BFC) >> 64; } if (x & 0x40000000 > 0) { result = (result * 0x1000000002C5C85FE) >> 64; } if (x & 0x20000000 > 0) { result = (result * 0x100000000162E42FF) >> 64; } if (x & 0x10000000 > 0) { result = (result * 0x1000000000B17217F) >> 64; } if (x & 0x8000000 > 0) { result = (result * 0x100000000058B90C0) >> 64; } if (x & 0x4000000 > 0) { result = (result * 0x10000000002C5C860) >> 64; } if (x & 0x2000000 > 0) { result = (result * 0x1000000000162E430) >> 64; } if (x & 0x1000000 > 0) { result = (result * 0x10000000000B17218) >> 64; } if (x & 0x800000 > 0) { result = (result * 0x1000000000058B90C) >> 64; } if (x & 0x400000 > 0) { result = (result * 0x100000000002C5C86) >> 64; } if (x & 0x200000 > 0) { result = (result * 0x10000000000162E43) >> 64; } if (x & 0x100000 > 0) { result = (result * 0x100000000000B1721) >> 64; } if (x & 0x80000 > 0) { result = (result * 0x10000000000058B91) >> 64; } if (x & 0x40000 > 0) { result = (result * 0x1000000000002C5C8) >> 64; } if (x & 0x20000 > 0) { result = (result * 0x100000000000162E4) >> 64; } if (x & 0x10000 > 0) { result = (result * 0x1000000000000B172) >> 64; } if (x & 0x8000 > 0) { result = (result * 0x100000000000058B9) >> 64; } if (x & 0x4000 > 0) { result = (result * 0x10000000000002C5D) >> 64; } if (x & 0x2000 > 0) { result = (result * 0x1000000000000162E) >> 64; } if (x & 0x1000 > 0) { result = (result * 0x10000000000000B17) >> 64; } if (x & 0x800 > 0) { result = (result * 0x1000000000000058C) >> 64; } if (x & 0x400 > 0) { result = (result * 0x100000000000002C6) >> 64; } if (x & 0x200 > 0) { result = (result * 0x10000000000000163) >> 64; } if (x & 0x100 > 0) { result = (result * 0x100000000000000B1) >> 64; } if (x & 0x80 > 0) { result = (result * 0x10000000000000059) >> 64; } if (x & 0x40 > 0) { result = (result * 0x1000000000000002C) >> 64; } if (x & 0x20 > 0) { result = (result * 0x10000000000000016) >> 64; } if (x & 0x10 > 0) { result = (result * 0x1000000000000000B) >> 64; } if (x & 0x8 > 0) { result = (result * 0x10000000000000006) >> 64; } if (x & 0x4 > 0) { result = (result * 0x10000000000000003) >> 64; } if (x & 0x2 > 0) { result = (result * 0x10000000000000001) >> 64; } if (x & 0x1 > 0) { result = (result * 0x10000000000000001) >> 64; } // We're doing two things at the same time: // // 1. Multiply the result by 2^n + 1, where "2^n" is the integer part and the one is added to account for // the fact that we initially set the result to 0.5. This is accomplished by subtracting from 191 // rather than 192. // 2. Convert the result to the unsigned 60.18-decimal fixed-point format. // // This works because 2^(191-ip) = 2^ip / 2^191, where "ip" is the integer part "2^n". result *= SCALE; result >>= (191 - (x >> 64)); } } /// @notice Finds the zero-based index of the first one in the binary representation of x. /// @dev See the note on msb in the "Find First Set" Wikipedia article https://en.wikipedia.org/wiki/Find_first_set /// @param x The uint256 number for which to find the index of the most significant bit. /// @return msb The index of the most significant bit as an uint256. function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) { if (x >= 2**128) { x >>= 128; msb += 128; } if (x >= 2**64) { x >>= 64; msb += 64; } if (x >= 2**32) { x >>= 32; msb += 32; } if (x >= 2**16) { x >>= 16; msb += 16; } if (x >= 2**8) { x >>= 8; msb += 8; } if (x >= 2**4) { x >>= 4; msb += 4; } if (x >= 2**2) { x >>= 2; msb += 2; } if (x >= 2**1) { // No need to shift x any more. msb += 1; } } /// @notice Calculates floor(x*y÷denominator) with full precision. /// /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv. /// /// Requirements: /// - The denominator cannot be zero. /// - The result must fit within uint256. /// /// Caveats: /// - This function does not work with fixed-point numbers. /// /// @param x The multiplicand as an uint256. /// @param y The multiplier as an uint256. /// @param denominator The divisor as an uint256. /// @return result The result as an uint256. function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { // 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) { unchecked { result = prod0 / denominator; } return result; } // Make sure the result is less than 2^256. Also prevents denominator == 0. if (prod1 >= denominator) { revert PRBMath__MulDivOverflow(prod1, denominator); } /////////////////////////////////////////////// // 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. unchecked { // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 lpotdod = denominator & (~denominator + 1); assembly { // Divide denominator by lpotdod. denominator := div(denominator, lpotdod) // Divide [prod1 prod0] by lpotdod. prod0 := div(prod0, lpotdod) // Flip lpotdod such that it is 2^256 / lpotdod. If lpotdod is zero, then it becomes one. lpotdod := add(div(sub(0, lpotdod), lpotdod), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * lpotdod; // 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 floor(x*y÷1e18) with full precision. /// /// @dev Variant of "mulDiv" with constant folding, i.e. in which the denominator is always 1e18. Before returning the /// final result, we add 1 if (x * y) % SCALE >= HALF_SCALE. Without this, 6.6e-19 would be truncated to 0 instead of /// being rounded to 1e-18. See "Listing 6" and text above it at https://accu.org/index.php/journals/1717. /// /// Requirements: /// - The result must fit within uint256. /// /// Caveats: /// - The body is purposely left uncommented; see the NatSpec comments in "PRBMath.mulDiv" to understand how this works. /// - It is assumed that the result can never be type(uint256).max when x and y solve the following two equations: /// 1. x * y = type(uint256).max * SCALE /// 2. (x * y) % SCALE >= SCALE / 2 /// /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number. /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function mulDivFixedPoint(uint256 x, uint256 y) internal pure returns (uint256 result) { uint256 prod0; uint256 prod1; assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } if (prod1 >= SCALE) { revert PRBMath__MulDivFixedPointOverflow(prod1); } uint256 remainder; uint256 roundUpUnit; assembly { remainder := mulmod(x, y, SCALE) roundUpUnit := gt(remainder, 499999999999999999) } if (prod1 == 0) { unchecked { result = (prod0 / SCALE) + roundUpUnit; return result; } } assembly { result := add( mul( or( div(sub(prod0, remainder), SCALE_LPOTD), mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, SCALE_LPOTD), SCALE_LPOTD), 1)) ), SCALE_INVERSE ), roundUpUnit ) } } /// @notice Calculates floor(x*y÷denominator) with full precision. /// /// @dev An extension of "mulDiv" for signed numbers. Works by computing the signs and the absolute values separately. /// /// Requirements: /// - None of the inputs can be type(int256).min. /// - The result must fit within int256. /// /// @param x The multiplicand as an int256. /// @param y The multiplier as an int256. /// @param denominator The divisor as an int256. /// @return result The result as an int256. function mulDivSigned( int256 x, int256 y, int256 denominator ) internal pure returns (int256 result) { if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) { revert PRBMath__MulDivSignedInputTooSmall(); } // Get hold of the absolute values of x, y and the denominator. uint256 ax; uint256 ay; uint256 ad; unchecked { ax = x < 0 ? uint256(-x) : uint256(x); ay = y < 0 ? uint256(-y) : uint256(y); ad = denominator < 0 ? uint256(-denominator) : uint256(denominator); } // Compute the absolute value of (x*y)÷denominator. The result must fit within int256. uint256 rAbs = mulDiv(ax, ay, ad); if (rAbs > uint256(type(int256).max)) { revert PRBMath__MulDivSignedOverflow(rAbs); } // Get the signs of x, y and the denominator. uint256 sx; uint256 sy; uint256 sd; assembly { sx := sgt(x, sub(0, 1)) sy := sgt(y, sub(0, 1)) sd := sgt(denominator, sub(0, 1)) } // XOR over sx, sy and sd. This is checking whether there are one or three negative signs in the inputs. // If yes, the result should be negative. result = sx ^ sy ^ sd == 0 ? -int256(rAbs) : int256(rAbs); } /// @notice Calculates the square root of x, rounding down. /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method. /// /// Caveats: /// - This function does not work with fixed-point numbers. /// /// @param x The uint256 number for which to calculate the square root. /// @return result The result as an uint256. function sqrt(uint256 x) internal pure returns (uint256 result) { if (x == 0) { return 0; } // Set the initial guess to the least power of two that is greater than or equal to sqrt(x). uint256 xAux = uint256(x); result = 1; if (xAux >= 0x100000000000000000000000000000000) { xAux >>= 128; result <<= 64; } if (xAux >= 0x10000000000000000) { xAux >>= 64; result <<= 32; } if (xAux >= 0x100000000) { xAux >>= 32; result <<= 16; } if (xAux >= 0x10000) { xAux >>= 16; result <<= 8; } if (xAux >= 0x100) { xAux >>= 8; result <<= 4; } if (xAux >= 0x10) { xAux >>= 4; result <<= 2; } if (xAux >= 0x8) { result <<= 1; } // The operations can never overflow because the result is max 2^127 when it enters this block. unchecked { result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; // Seven iterations should be enough uint256 roundedDownResult = x / result; return result >= roundedDownResult ? roundedDownResult : result; } } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; import "./IVAMM.sol"; import "./IPositionStructs.sol"; import "../core_libraries/Position.sol"; import "./rate_oracles/IRateOracle.sol"; import "./fcms/IFCM.sol"; import "./IFactory.sol"; import "./IERC20Minimal.sol"; import "contracts/utils/CustomErrors.sol"; interface IMarginEngine is IPositionStructs, CustomErrors { // structs function setPausability(bool state) external; struct MarginCalculatorParameters { /// @dev Upper bound of the underlying pool (e.g. Aave v2 USDC lending pool) APY from the initiation of the IRS AMM and until its maturity (18 decimals fixed point number) uint256 apyUpperMultiplierWad; /// @dev Lower bound of the underlying pool (e.g. Aave v2 USDC lending pool) APY from the initiation of the IRS AMM and until its maturity (18 decimals) uint256 apyLowerMultiplierWad; /// @dev The volatility of the underlying pool APY (settable by the owner of the Margin Engine) (18 decimals) int256 sigmaSquaredWad; /// @dev Margin Engine Parameter estimated via CIR model calibration (for details refer to litepaper) (18 decimals) int256 alphaWad; /// @dev Margin Engine Parameter estimated via CIR model calibration (for details refer to litepaper) (18 decimals) int256 betaWad; /// @dev Standard normal critical value used in the computation of the Upper APY Bound of the underlying pool int256 xiUpperWad; /// @dev Standard normal critical value used in the computation of the Lower APY Bound of the underlying pool int256 xiLowerWad; /// @dev Max term possible for a Voltz IRS AMM in seconds (18 decimals) int256 tMaxWad; /// @dev multiplier of the starting fixed rate (refer to the litepaper) if simulating a counterfactual fixed taker unwind (moving to the left along the VAMM) for purposes of calculating liquidation margin requirement uint256 devMulLeftUnwindLMWad; /// @dev multiplier of the starting fixed rate (refer to the litepaper) if simulating a counterfactual variable taker unwind (moving to the right along the VAMM) for purposes of calculating liquidation margin requirement uint256 devMulRightUnwindLMWad; /// @dev same as devMulLeftUnwindLMWad but for purposes of calculating the initial margin requirement uint256 devMulLeftUnwindIMWad; /// @dev same as devMulRightUnwindLMWad but for purposes of calculating the initial margin requirement uint256 devMulRightUnwindIMWad; /// @dev r_min from the litepaper eq. 11 for a scenario where counterfactual is a simulated fixed taker unwind (left unwind along the VAMM), used for liquidation margin calculation uint256 fixedRateDeviationMinLeftUnwindLMWad; /// @dev r_min from the litepaper eq. 11 for a scenario where counterfactual is a simulated variable taker unwind (right unwind along the VAMM), used for liquidation margin calculation uint256 fixedRateDeviationMinRightUnwindLMWad; /// @dev same as fixedRateDeviationMinLeftUnwindLMWad but for Initial Margin Requirement uint256 fixedRateDeviationMinLeftUnwindIMWad; /// @dev same as fixedRateDeviationMinRightUnwindLMWad but for Initial Margin Requirement uint256 fixedRateDeviationMinRightUnwindIMWad; /// @dev gamma from eqn. 12 [append this logic to the litepaper] from the litepaper, gamma is an adjustable parameter necessary to calculate scaled deviations to the fixed rate in counterfactual unwinds for minimum margin requirement calculations uint256 gammaWad; /// @dev settable parameter that ensures that minimumMarginRequirement is always above or equal to the minMarginToIncentiviseLiquidators which ensures there is always sufficient incentive for liquidators to liquidate positions given the fact their income is a proportion of position margin uint256 minMarginToIncentiviseLiquidators; } // Events event HistoricalApyWindowSetting(uint256 secondsAgo); event CacheMaxAgeSetting(uint256 cacheMaxAgeInSeconds); event RateOracle(uint256 cacheMaxAgeInSeconds); event ProtocolCollection( address sender, address indexed recipient, uint256 amount ); event LiquidatorRewardSetting(uint256 liquidatorRewardWad); event VAMMSetting(IVAMM indexed vamm); event RateOracleSetting(IRateOracle indexed rateOracle); event FCMSetting(IFCM indexed fcm); event MarginCalculatorParametersSetting( MarginCalculatorParameters marginCalculatorParameters ); event PositionMarginUpdate( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, int256 marginDelta ); event HistoricalApy(uint256 value); event PositionSettlement( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, int256 settlementCashflow ); event PositionLiquidation( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, address liquidator, int256 notionalUnwound, uint256 liquidatorReward ); event PositionUpdate( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 _liquidity, int256 margin, int256 fixedTokenBalance, int256 variableTokenBalance, uint256 accumulatedFees ); /// @dev emitted after the _isAlpha boolean is updated by the owner of the Margin Engine /// @dev _isAlpha boolean dictates whether the Margin Engine is in the Alpha State, i.e. margin updates can only be done via the periphery /// @dev additionally, the periphery has the logic to take care of lp margin caps in the Alpha State phase of the Margin Engine /// @dev __isAlpha is the newly set value for the _isAlpha boolean event IsAlpha(bool __isAlpha); // immutables /// @notice The Full Collateralisation Module (FCM) /// @dev The FCM is a smart contract that acts as an intermediary Position between the Voltz Core and traders who wish to take fully collateralised fixed taker positions /// @dev An example FCM is the AaveFCM.sol module which inherits from the IFCM interface, it lets fixed takers deposit underlying yield bearing tokens (e.g.) aUSDC as margin to enter into a fixed taker swap without the need to worry about liquidations /// @dev since the MarginEngine is confident the FCM is always fully collateralised, it does not let liquidators liquidate the FCM Position /// @return The Full Collateralisation Module linked to the MarginEngine function fcm() external view returns (IFCM); /// @notice The Factory /// @dev the factory that deployed the master Margin Engine function factory() external view returns (IFactory); /// @notice The address of the underlying (non-yield bearing) token - e.g. USDC /// @return The underlying ERC20 token (e.g. USDC) function underlyingToken() external view returns (IERC20Minimal); /// @notice The rateOracle contract which lets the protocol access historical apys in the yield bearing pools it is built on top of /// @return The underlying ERC20 token (e.g. USDC) function rateOracle() external view returns (IRateOracle); /// @notice The unix termStartTimestamp of the MarginEngine in Wad /// @return Term Start Timestamp in Wad function termStartTimestampWad() external view returns (uint256); /// @notice The unix termEndTimestamp of the MarginEngine in Wad /// @return Term End Timestamp in Wad function termEndTimestampWad() external view returns (uint256); /// @dev "constructor" for proxy instances function initialize( IERC20Minimal __underlyingToken, IRateOracle __rateOracle, uint256 __termStartTimestampWad, uint256 __termEndTimestampWad ) external; // view functions /// @notice The liquidator Reward Percentage (in Wad) /// @dev liquidatorReward (in wad) is the percentage of the margin (of a liquidated position) that is sent to the liquidator /// @dev following a successful liquidation that results in a trader/position unwind; example value: 2 * 10**16 => 2% of position margin is used to cover liquidator reward /// @return Liquidator Reward in Wad function liquidatorRewardWad() external view returns (uint256); /// @notice VAMM (Virtual Automated Market Maker) linked to the MarginEngine /// @dev The VAMM is responsible for pricing only (determining the effective fixed rate at which a given Interest Rate Swap notional will be executed) /// @return The VAMM function vamm() external view returns (IVAMM); /// @return If true, the Margin Engine Proxy is currently in alpha state, hence margin updates of LPs can only be done via the periphery. If false, lps can directly update their margin via Margin Engine. function isAlpha() external view returns (bool); /// @notice Returns the information about a position by the position's key /// @param _owner The address of the position owner /// @param _tickLower The lower tick boundary of the position /// @param _tickUpper The upper tick boundary of the position /// Returns position The Position.Info corresponding to the requested position function getPosition( address _owner, int24 _tickLower, int24 _tickUpper ) external returns (Position.Info memory position); /// @notice Gets the look-back window size that's used to request the historical APY from the rate Oracle /// @dev The historical APY of the Rate Oracle is necessary for MarginEngine computations /// @dev The look-back window is seconds from the current timestamp /// @dev This value is only settable by the the Factory owner and may be unique for each MarginEngine /// @dev When setting secondAgo, the setter needs to take into consideration the underlying volatility of the APYs in the reference yield-bearing pool (e.g. Aave v2 USDC) function lookbackWindowInSeconds() external view returns (uint256); // non-view functions /// @notice Sets secondsAgo: The look-back window size used to calculate the historical APY for margin purposes /// @param _secondsAgo the duration of the lookback window in seconds /// @dev Can only be set by the Factory Owner function setLookbackWindowInSeconds(uint256 _secondsAgo) external; /// @notice Set the MarginCalculatorParameters (each margin engine can have its own custom set of margin calculator parameters) /// @param _marginCalculatorParameters the MarginCalculatorParameters to set /// @dev marginCalculatorParameteres is of type MarginCalculatorParameters (refer to the definition of the struct for elaboration on what each parameter means) function setMarginCalculatorParameters( MarginCalculatorParameters memory _marginCalculatorParameters ) external; /// @notice Sets the liquidator reward: proportion of liquidated position's margin paid as a reward to the liquidator function setLiquidatorReward(uint256 _liquidatorRewardWad) external; /// @notice Function that sets the _isAlpha state variable, if it is set to true the protocol is in the Alpha State /// @dev if the Margin Engine is at the alpha state, lp margin updates can only be done via the periphery which in turn takes care of margin caps for the LPs /// @dev this function can only be called by the owner of the VAMM function setIsAlpha(bool __isAlpha) external; /// @notice updates the margin account of a position which can be uniquily identified with its _owner, tickLower, tickUpper /// @dev if the position has positive liquidity then before the margin update, we call the updatePositionTokenBalancesAndAccountForFees functon that calculates up to date /// @dev margin, fixed and variable token balances by taking into account the fee income from their tick range and fixed and variable deltas settled along their tick range /// @dev marginDelta is the delta applied to the current margin of a position, if the marginDelta is negative, the position is withdrawing margin, if the marginDelta is positive, the position is depositing funds in terms of the underlying tokens /// @dev if marginDelta is negative, we need to check if the msg.sender is either the _owner of the position or the msg.sender is apporved by the _owner to act on their behalf in Voltz Protocol /// @dev the approval logic is implemented in the Factory.sol /// @dev if marginDelta is negative, we additionally need to check if post the initial margin requirement is still satisfied post withdrawal /// @dev if marginDelta is positive, the depositor of the margin is either the msg.sender or the owner who interacted through an approved peripheral contract function updatePositionMargin( address _owner, int24 _tickLower, int24 _tickUpper, int256 marginDelta ) external; /// @notice Settles a Position /// @dev Can be called by anyone /// @dev A position cannot be settled before maturity /// @dev Steps to settle a position: /// @dev 1. Retrieve the current fixed and variable token growth inside the tick range of a position /// @dev 2. Calculate accumulated fixed and variable balances of the position since the last mint/poke/burn /// @dev 3. Update the postion's fixed and variable token balances /// @dev 4. Update the postion's fixed and varaible token growth inside last to enable future updates /// @dev 5. Calculates the settlement cashflow from all of the IRS contracts the position has entered since entering the AMM /// @dev 6. Updates the fixed and variable token balances of the position to be zero, adds the settlement cashflow to the position's current margin function settlePosition( address _owner, int24 _tickLower, int24 _tickUpper ) external; /// @notice Liquidate a Position /// @dev Steps to liquidate: update position's fixed and variable token balances to account for balances accumulated throughout the trades made since the last mint/burn/poke, /// @dev Check if the position is liquidatable by calling the isLiquidatablePosition function of the calculator, revert if that is not the case, /// @dev Calculate the liquidation reward = current margin of the position * liquidatorReward, subtract the liquidator reward from the position margin, /// @dev Burn the position's liquidity, unwind unnetted fixed and variable balances of a position, transfer the reward to the liquidator function liquidatePosition( address _owner, int24 _tickLower, int24 _tickUpper ) external returns (uint256); /// @notice Update a Position post VAMM induced mint or burn /// @dev Steps taken: /// @dev 1. Update position liquidity based on params.liquidityDelta /// @dev 2. Update fixed and variable token balances of the position based on how much has been accumulated since the last mint/burn/poke /// @dev 3. Update position's margin by taking into account the position accumulated fees since the last mint/burn/poke /// @dev 4. Update fixed and variable token growth + fee growth in the position info struct for future interactions with the position /// @param _params necessary for the purposes of referencing the position being updated (owner, tickLower, tickUpper, _) and the liquidity delta that needs to be applied to position._liquidity function updatePositionPostVAMMInducedMintBurn( IPositionStructs.ModifyPositionParams memory _params ) external returns (int256 _positionMarginRequirement); // @notive Update a position post VAMM induced swap /// @dev Since every position can also engage in swaps with the VAMM, this function needs to be invoked after non-external calls are made to the VAMM's swap function /// @dev This purpose of this function is to: /// @dev 1. updatePositionTokenBalancesAndAccountForFees /// @dev 2. update position margin to account for fees paid to execute the swap /// @dev 3. calculate the position margin requrement given the swap, check if the position marigin satisfies the most up to date requirement /// @dev 4. if all the requirements are satisfied then position gets updated to take into account the swap that it just entered, if the minimum margin requirement is not satisfied then the transaction will revert function updatePositionPostVAMMInducedSwap( address _owner, int24 _tickLower, int24 _tickUpper, int256 _fixedTokenDelta, int256 _variableTokenDelta, uint256 _cumulativeFeeIncurred, int256 _fixedTokenDeltaUnbalanced ) external returns (int256 _positionMarginRequirement); /// @notice function that can only be called by the owner enables collection of protocol generated fees from any give margin engine /// @param _recipient the address which collects the protocol generated fees /// @param _amount the amount in terms of underlying tokens collected from the protocol's earnings function collectProtocol(address _recipient, uint256 _amount) external; /// @notice sets the Virtual Automated Market Maker (VAMM) attached to the MarginEngine /// @dev the VAMM is responsible for price discovery, whereas the management of the underlying collateral and liquidations are handled by the Margin Engine function setVAMM(IVAMM _vAMM) external; /// @notice sets the Virtual Automated Market Maker (VAMM) attached to the MarginEngine /// @dev the VAMM is responsible for price discovery, whereas the management of the underlying collateral and liquidations are handled by the Margin Engine function setRateOracle(IRateOracle __rateOracle) external; /// @notice sets the Full Collateralisation Module function setFCM(IFCM _newFCM) external; /// @notice transfers margin in terms of underlying tokens to a trader from the Full Collateralisation Module /// @dev post maturity date of the MarginEngine, the traders from the Full Collateralisation module will be able to settle with the MarginEngine /// @dev to ensure their fixed yield is guaranteed, in order to collect the funds from the MarginEngine, the FCM needs to invoke the transferMarginToFCMTrader function whcih is only callable by the FCM attached to a particular Margin Engine function transferMarginToFCMTrader(address _account, uint256 _marginDelta) external; /// @notice Gets the maximum age of the cached historical APY value can be without being refreshed function cacheMaxAgeInSeconds() external view returns (uint256); /// @notice Sets the maximum age that the cached historical APY value /// @param _cacheMaxAgeInSeconds The new maximum age that the historical APY cache can be before being considered stale function setCacheMaxAgeInSeconds(uint256 _cacheMaxAgeInSeconds) external; /// @notice Get Historical APY /// @dev The lookback window used by this function is determined by `lookbackWindowInSeconds` /// @dev refresh the historical apy cache if necessary /// @return historicalAPY (Wad) function getHistoricalApy() external returns (uint256); /// @notice Computes the historical APY value of the RateOracle, without updating the cached value /// @dev The lookback window used by this function is determined by `lookbackWindowInSeconds` function getHistoricalApyReadOnly() external view returns (uint256); function getPositionMarginRequirement( address _recipient, int24 _tickLower, int24 _tickUpper, bool _isLM ) external returns (uint256); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.9; import "./IMarginEngine.sol"; import "./rate_oracles/IRateOracle.sol"; import "./IFactory.sol"; import "./IPositionStructs.sol"; import "../core_libraries/Tick.sol"; import "contracts/utils/CustomErrors.sol"; interface IVAMM is IPositionStructs, CustomErrors { function setPausability(bool state) external; // events event Swap( address sender, address indexed recipient, int24 indexed tickLower, int24 indexed tickUpper, int256 desiredNotional, uint160 sqrtPriceLimitX96, uint256 cumulativeFeeIncurred, int256 fixedTokenDelta, int256 variableTokenDelta, int256 fixedTokenDeltaUnbalanced ); /// @dev emitted after a given vamm is successfully initialized event VAMMInitialization(uint160 sqrtPriceX96, int24 tick); /// @dev emitted after a successful minting of a given LP position event Mint( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount ); /// @dev emitted after a successful burning of a given LP position event Burn( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount ); /// @dev emitted after setting feeProtocol event FeeProtocol(uint8 feeProtocol); /// @dev emitted after fee is set event Fee(uint256 feeWad); /// @dev emitted after the _isAlpha boolean is updated by the owner of the VAMM /// @dev _isAlpha boolean dictates whether the VAMM is in the Alpha State, i.e. mints can only be done via the periphery /// @dev additionally, the periphery has the logic to take care of lp notional caps in the Alpha State phase of VAMM /// @dev __isAlpha is the newly set value for the _isAlpha boolean event IsAlpha(bool __isAlpha); event VAMMPriceChange(int24 tick); // structs struct VAMMVars { /// @dev The current price of the pool as a sqrt(variableToken/fixedToken) Q64.96 value uint160 sqrtPriceX96; /// @dev The current tick of the vamm, i.e. according to the last tick transition that was run. int24 tick; // the current protocol fee as a percentage of the swap fee taken on withdrawal // represented as an integer denominator (1/x) uint8 feeProtocol; } struct SwapParams { /// @dev Address of the trader initiating the swap address recipient; /// @dev The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) int256 amountSpecified; /// @dev The Q64.96 sqrt price limit. If !isFT, the price cannot be less than this uint160 sqrtPriceLimitX96; /// @dev lower tick of the position int24 tickLower; /// @dev upper tick of the position int24 tickUpper; } struct SwapCache { /// @dev liquidity at the beginning of the swap uint128 liquidityStart; // the current protocol fee as a percentage of the swap fee taken on withdrawal // represented as an integer denominator (1/x)% uint8 feeProtocol; } /// @dev the top level state of the swap, the results of which are recorded in storage at the end struct SwapState { /// @dev the amount remaining to be swapped in/out of the input/output asset int256 amountSpecifiedRemaining; /// @dev the amount already swapped out/in of the output/input asset int256 amountCalculated; /// @dev current sqrt(price) uint160 sqrtPriceX96; /// @dev the tick associated with the current price int24 tick; /// @dev the global fixed token growth int256 fixedTokenGrowthGlobalX128; /// @dev the global variable token growth int256 variableTokenGrowthGlobalX128; /// @dev the current liquidity in range uint128 liquidity; /// @dev the global fee growth of the underlying token uint256 feeGrowthGlobalX128; /// @dev amount of underlying token paid as protocol fee uint256 protocolFee; /// @dev cumulative fee incurred while initiating a swap uint256 cumulativeFeeIncurred; /// @dev fixedTokenDelta that will be applied to the fixed token balance of the position executing the swap (recipient) int256 fixedTokenDeltaCumulative; /// @dev variableTokenDelta that will be applied to the variable token balance of the position executing the swap (recipient) int256 variableTokenDeltaCumulative; /// @dev fixed token delta cumulative but without rebalancings applied int256 fixedTokenDeltaUnbalancedCumulative; } struct StepComputations { /// @dev the price at the beginning of the step uint160 sqrtPriceStartX96; /// @dev the next tick to swap to from the current tick in the swap direction int24 tickNext; /// @dev whether tickNext is initialized or not bool initialized; /// @dev sqrt(price) for the next tick (1/0) uint160 sqrtPriceNextX96; /// @dev how much is being swapped in in this step uint256 amountIn; /// @dev how much is being swapped out uint256 amountOut; /// @dev how much fee is being paid in (underlying token) uint256 feeAmount; /// @dev ... uint256 feeProtocolDelta; /// @dev ... int256 fixedTokenDeltaUnbalanced; // for LP /// @dev ... int256 fixedTokenDelta; // for LP /// @dev ... int256 variableTokenDelta; // for LP } /// @dev "constructor" for proxy instances function initialize(IMarginEngine __marginEngine, int24 __tickSpacing) external; // immutables /// @notice The vamm's fee (proportion) in wad /// @return The fee in wad function feeWad() external view returns (uint256); /// @notice The vamm tick spacing /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... /// This value is an int24 to avoid casting even though it is always positive. /// @return The tick spacing function tickSpacing() external view returns (int24); /// @notice The maximum amount of position liquidity that can use any tick in the range /// @dev This parameter should be enforced per tick (when setting) to prevent liquidity from overflowing a uint128 at any point, and /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to the vamm /// @return The max amount of liquidity per tick function maxLiquidityPerTick() external view returns (uint128); // state variables /// @return The current VAMM Vars (see struct definition for semantics) function vammVars() external view returns (VAMMVars memory); /// @return If true, the VAMM Proxy is currently in alpha state, hence minting can only be done via the periphery. If false, minting can be done directly via VAMM. function isAlpha() external view returns (bool); /// @notice The fixed token growth accumulated per unit of liquidity for the entire life of the vamm /// @dev This value can overflow the uint256 function fixedTokenGrowthGlobalX128() external view returns (int256); /// @notice The variable token growth accumulated per unit of liquidity for the entire life of the vamm /// @dev This value can overflow the uint256 function variableTokenGrowthGlobalX128() external view returns (int256); /// @notice The fee growth collected per unit of liquidity for the entire life of the vamm /// @dev This value can overflow the uint256 function feeGrowthGlobalX128() external view returns (uint256); /// @notice The currently in range liquidity available to the vamm function liquidity() external view returns (uint128); /// @notice The amount underlying token that are owed to the protocol /// @dev Protocol fees will never exceed uint256 function protocolFees() external view returns (uint256); function marginEngine() external view returns (IMarginEngine); function factory() external view returns (IFactory); /// @notice Function that sets the feeProtocol of the vamm /// @dev the current protocol fee as a percentage of the swap fee taken on withdrawal // represented as an integer denominator (1/x) function setFeeProtocol(uint8 feeProtocol) external; /// @notice Function that sets the _isAlpha state variable, if it is set to true the protocol is in the Alpha State /// @dev if the VAMM is at the alpha state, mints can only be done via the periphery which in turn takes care of notional caps for the LPs /// @dev this function can only be called by the owner of the VAMM function setIsAlpha(bool __isAlpha) external; /// @notice Function that sets fee of the vamm /// @dev The vamm's fee (proportion) in wad function setFee(uint256 _fee) external; /// @notice Updates internal accounting to reflect a collection of protocol fees. The actual transfer of fees must happen separately in the AMM /// @dev can only be done via the collectProtocol function of the parent AMM of the vamm function updateProtocolFees(uint256 protocolFeesCollected) external; /// @notice Sets the initial price for the vamm /// @dev Price is represented as a sqrt(amountVariableToken/amountFixedToken) Q64.96 value /// @param sqrtPriceX96 the initial sqrt price of the vamm as a Q64.96 function initializeVAMM(uint160 sqrtPriceX96) external; /// @notice removes liquidity given recipient/tickLower/tickUpper of the position /// @param recipient The address for which the liquidity will be removed /// @param tickLower The lower tick of the position in which to remove liquidity /// @param tickUpper The upper tick of the position in which to remove liqudiity /// @param amount The amount of liquidity to burn function burn( address recipient, int24 tickLower, int24 tickUpper, uint128 amount ) external returns (int256 positionMarginRequirement); /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position /// @param recipient The address for which the liquidity will be created /// @param tickLower The lower tick of the position in which to add liquidity /// @param tickUpper The upper tick of the position in which to add liquidity /// @param amount The amount of liquidity to mint function mint( address recipient, int24 tickLower, int24 tickUpper, uint128 amount ) external returns (int256 positionMarginRequirement); /// @notice Initiate an Interest Rate Swap /// @param params SwapParams necessary to initiate an Interest Rate Swap /// @return fixedTokenDelta Fixed Token Delta /// @return variableTokenDelta Variable Token Delta /// @return cumulativeFeeIncurred Cumulative Fee Incurred function swap(SwapParams memory params) external returns ( int256 fixedTokenDelta, int256 variableTokenDelta, uint256 cumulativeFeeIncurred, int256 fixedTokenDeltaUnbalanced, int256 marginRequirement ); /// @notice Look up information about a specific tick in the amm /// @param tick The tick to look up /// @return liquidityGross: the total amount of position liquidity that uses the vamm either as tick lower or tick upper, /// liquidityNet: how much liquidity changes when the vamm price crosses the tick, /// feeGrowthOutsideX128: the fee growth on the other side of the tick from the current tick in underlying token. i.e. if liquidityGross is greater than 0. In addition, these values are only relative. function ticks(int24 tick) external view returns (Tick.Info memory); /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information function tickBitmap(int16 wordPosition) external view returns (uint256); /// @notice Computes the current fixed and variable token growth inside a given tick range given the current tick in the vamm /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @return fixedTokenGrowthInsideX128 Fixed Token Growth inside the given tick range /// @return variableTokenGrowthInsideX128 Variable Token Growth inside the given tick range /// @return feeGrowthInsideX128 Fee Growth Inside given tick range function computeGrowthInside(int24 tickLower, int24 tickUpper) external view returns ( int256 fixedTokenGrowthInsideX128, int256 variableTokenGrowthInsideX128, uint256 feeGrowthInsideX128 ); /// @notice refreshes the Rate Oracle attached to the Margin Engine function refreshRateOracle() external; /// @notice The rateOracle contract which lets the protocol access historical apys in the yield bearing pools it is built on top of /// @return The underlying ERC20 token (e.g. USDC) function getRateOracle() external view returns (IRateOracle); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; import "../IMarginEngine.sol"; import "../../utils/CustomErrors.sol"; import "../IERC20Minimal.sol"; import "../../core_libraries/TraderWithYieldBearingAssets.sol"; import "../IVAMM.sol"; import "../rate_oracles/IRateOracle.sol"; interface IFCM is CustomErrors { function setPausability(bool state) external; function getTraderWithYieldBearingAssets(address trader) external view returns (TraderWithYieldBearingAssets.Info memory traderInfo); /// @notice Initiate a Fully Collateralised Fixed Taker Swap /// @param notional amount of notional (in terms of the underlying token) to trade /// @param sqrtPriceLimitX96 the sqrtPriceLimit (in binary fixed point math notation) beyond which swaps won't be executed /// @dev An example of an initiated fully collateralised fixed taker swap is a scenario where a trader with 100 aTokens wishes to get a fixed return on them /// @dev they can choose to deposit their 100aTokens into the FCM (enter into a fixed taker position with a notional of 100) to swap variable cashflows from the aTokens /// @dev with the fixed cashflows from the variable takers function initiateFullyCollateralisedFixedTakerSwap( uint256 notional, uint160 sqrtPriceLimitX96 ) external returns (int256 fixedTokenDelta, int256 variableTokenDelta, uint256 cumulativeFeeIncurred, int256 fixedTokenDeltaUnbalanced); /// @notice Unwind a Fully Collateralised Fixed Taker Swap /// @param notionalToUnwind The amount of notional of the original Fully Collateralised Fixed Taker swap to be unwound at the current VAMM fixed rates /// @param sqrtPriceLimitX96 the sqrtPriceLimit (in binary fixed point math notation) beyond which the unwind swaps won't be executed /// @dev The purpose of this function is to let fully collateralised fixed takers to exist their swaps by entering into variable taker positions against the VAMM /// @dev thus effectively releasing the margin in yield bearing tokens from the fixed swap contract function unwindFullyCollateralisedFixedTakerSwap( uint256 notionalToUnwind, uint160 sqrtPriceLimitX96 ) external returns (int256 fixedTokenDelta, int256 variableTokenDelta, uint256 cumulativeFeeIncurred, int256 fixedTokenDeltaUnbalanced); /// @notice Settle Trader /// @dev this function in the fcm let's traders settle with the MarginEngine based on their settlement cashflows which is a functon of their fixed and variable token balances function settleTrader() external returns (int256); /// @notice /// @param account address of the position owner from the MarginEngine who wishes to settle with the FCM in underlying tokens /// @param marginDeltaInUnderlyingTokens amount in terms of underlying tokens that needs to be settled with the trader from the MarginEngine function transferMarginToMarginEngineTrader( address account, uint256 marginDeltaInUnderlyingTokens ) external; /// @notice initialize is the constructor for the proxy instances of the FCM /// @dev "constructor" for proxy instances /// @dev in the initialize function we set the vamm and the margiEngine associated with the fcm /// @dev different FCM implementations are free to have different implementations for the initialisation logic function initialize(IVAMM __vamm, IMarginEngine __marginEngine) external; /// @notice Margine Engine linked to the Full Collateralisation Module /// @return marginEngine Margine Engine linked to the Full Collateralisation Module function marginEngine() external view returns (IMarginEngine); /// @notice VAMM linked to the Full Collateralisation Module /// @return VAMM linked to the Full Collateralisation Module function vamm() external view returns (IVAMM); /// @notice Rate Oracle linked to the Full Collateralisation Module /// @return Rate Oracle linked to the Full Collateralisation Module function rateOracle() external view returns (IRateOracle); event FullyCollateralisedSwap( address indexed trader, uint256 desiredNotional, uint160 sqrtPriceLimitX96, uint256 cumulativeFeeIncurred, int256 fixedTokenDelta, int256 variableTokenDelta, int256 fixedTokenDeltaUnbalanced ); event FullyCollateralisedUnwind( address indexed trader, uint256 desiredNotional, uint160 sqrtPriceLimitX96, uint256 cumulativeFeeIncurred, int256 fixedTokenDelta, int256 variableTokenDelta, int256 fixedTokenDeltaUnbalanced ); event fcmPositionSettlement( address indexed trader, int256 settlementCashflow ); event FCMTraderUpdate( address indexed trader, uint256 marginInScaledYieldBearingTokens, int256 fixedTokenBalance, int256 variableTokenBalance ); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; import "../interfaces/IMarginEngine.sol"; import "../interfaces/IVAMM.sol"; import "contracts/utils/CustomErrors.sol"; import "contracts/interfaces/IWETH.sol"; interface IPeriphery is CustomErrors { // events /// @dev emitted after new lp margin cap is set event MarginCap(IVAMM vamm, int256 lpMarginCapNew); // structs struct MintOrBurnParams { IMarginEngine marginEngine; int24 tickLower; int24 tickUpper; uint256 notional; bool isMint; int256 marginDelta; } struct SwapPeripheryParams { IMarginEngine marginEngine; bool isFT; uint256 notional; uint160 sqrtPriceLimitX96; int24 tickLower; int24 tickUpper; uint256 marginDelta; } // view functions function getCurrentTick(IMarginEngine marginEngine) external view returns (int24 currentTick); /// @param vamm VAMM for which to get the lp cap in underlying tokens /// @return Notional Cap for liquidity providers that mint or burn via periphery (enforced in the core if isAlpha is set to true) function lpMarginCaps(IVAMM vamm) external view returns (int256); /// @param vamm VAMM for which to get the lp notional cumulative in underlying tokens /// @return Total amount of notional supplied by the LPs to a given VAMM via the periphery function lpMarginCumulatives(IVAMM vamm) external view returns (int256); // non-view functions function mintOrBurn(MintOrBurnParams memory params) external payable returns (int256 positionMarginRequirement); function swap(SwapPeripheryParams memory params) external payable returns ( int256 _fixedTokenDelta, int256 _variableTokenDelta, uint256 _cumulativeFeeIncurred, int256 _fixedTokenDeltaUnbalanced, int256 _marginRequirement, int24 _tickAfter ); function updatePositionMargin( IMarginEngine marginEngine, int24 tickLower, int24 tickUpper, int256 marginDelta, bool fullyWithdraw ) external payable; function setLPMarginCap(IVAMM vamm, int256 lpMarginCapNew) external; function setLPMarginCumulative(IVAMM vamm, int256 lpMarginCumulative) external; function settlePositionAndWithdrawMargin( IMarginEngine marginEngine, address owner, int24 tickLower, int24 tickUpper ) external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.9; interface IPositionStructs { struct ModifyPositionParams { // the address that owns the position address owner; // the lower and upper tick of the position int24 tickLower; int24 tickUpper; // any change in liquidity int128 liquidityDelta; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.9; import "../utils/LiquidityMath.sol"; import "../utils/FixedPoint128.sol"; import "../core_libraries/Tick.sol"; import "../utils/FullMath.sol"; import "prb-math/contracts/PRBMathSD59x18.sol"; import "prb-math/contracts/PRBMathUD60x18.sol"; import "@openzeppelin/contracts/utils/math/SafeCast.sol"; /// @title Position /// @notice Positions represent an owner address' liquidity between a lower and upper tick boundary /// @dev Positions store additional state for tracking fees owed to the position as well as their fixed and variable token balances library Position { using Position for Info; // info stored for each user's position struct Info { // has the position been already burned // a burned position can no longer support new IRS contracts but still needs to cover settlement cash-flows of on-going IRS contracts it entered // bool isBurned;, equivalent to having zero liquidity // is position settled bool isSettled; // the amount of liquidity owned by this position uint128 _liquidity; // current margin of the position in terms of the underlyingToken int256 margin; // fixed token growth per unit of liquidity as of the last update to liquidity or fixed/variable token balance int256 fixedTokenGrowthInsideLastX128; // variable token growth per unit of liquidity as of the last update to liquidity or fixed/variable token balance int256 variableTokenGrowthInsideLastX128; // current Fixed Token balance of the position, 1 fixed token can be redeemed for 1% APY * (annualised amm term) at the maturity of the amm // assuming 1 token worth of notional "deposited" in the underlying pool at the inception of the amm // can be negative/positive/zero int256 fixedTokenBalance; // current Variable Token Balance of the position, 1 variable token can be redeemed for underlyingPoolAPY*(annualised amm term) at the maturity of the amm // assuming 1 token worth of notional "deposited" in the underlying pool at the inception of the amm // can be negative/positive/zero int256 variableTokenBalance; // fee growth per unit of liquidity as of the last update to liquidity or fees owed (via the margin) uint256 feeGrowthInsideLastX128; // amount of variable tokens at the initiation of liquidity uint256 rewardPerAmount; // amount of fees accumulated uint256 accumulatedFees; } /// @notice Returns the Info struct of a position, given an owner and position boundaries /// @param self The mapping containing all user positions /// @param owner The address of the position owner /// @param tickLower The lower tick boundary of the position /// @param tickUpper The upper tick boundary of the position /// @return position The position info struct of the given owners' position function get( mapping(bytes32 => Info) storage self, address owner, int24 tickLower, int24 tickUpper ) internal view returns (Position.Info storage position) { Tick.checkTicks(tickLower, tickUpper); position = self[ keccak256(abi.encodePacked(owner, tickLower, tickUpper)) ]; } function settlePosition(Info storage self) internal { require(!self.isSettled, "already settled"); self.isSettled = true; } /// @notice Updates the Info struct of a position by changing the amount of margin according to marginDelta /// @param self Position Info Struct of the Liquidity Provider /// @param marginDelta Change in the margin account of the position (in wei) function updateMarginViaDelta(Info storage self, int256 marginDelta) internal { self.margin += marginDelta; } /// @notice Updates the Info struct of a position by changing the fixed and variable token balances of the position /// @param self Position Info struct of the liquidity provider /// @param fixedTokenBalanceDelta Change in the number of fixed tokens in the position's fixed token balance /// @param variableTokenBalanceDelta Change in the number of variable tokens in the position's variable token balance function updateBalancesViaDeltas( Info storage self, int256 fixedTokenBalanceDelta, int256 variableTokenBalanceDelta ) internal { if (fixedTokenBalanceDelta | variableTokenBalanceDelta != 0) { self.fixedTokenBalance += fixedTokenBalanceDelta; self.variableTokenBalance += variableTokenBalanceDelta; } } /// @notice Returns Fee Delta = (feeGrowthInside-feeGrowthInsideLast) * liquidity of the position /// @param self position info struct represeting a liquidity provider /// @param feeGrowthInsideX128 fee growth per unit of liquidity as of now /// @return _feeDelta Fee Delta function calculateFeeDelta(Info storage self, uint256 feeGrowthInsideX128) internal pure returns (uint256 _feeDelta) { Info memory _self = self; /// @dev 0xZenus: The multiplication overflows, need to wrap the below expression in an unchecked block. unchecked { _feeDelta = FullMath.mulDiv( feeGrowthInsideX128 - _self.feeGrowthInsideLastX128, _self._liquidity, FixedPoint128.Q128 ); } } /// @notice Returns Fixed and Variable Token Deltas /// @param self position info struct represeting a liquidity provider /// @param fixedTokenGrowthInsideX128 fixed token growth per unit of liquidity as of now (in wei) /// @param variableTokenGrowthInsideX128 variable token growth per unit of liquidity as of now (in wei) /// @return _fixedTokenDelta = (fixedTokenGrowthInside-fixedTokenGrowthInsideLast) * liquidity of a position /// @return _variableTokenDelta = (variableTokenGrowthInside-variableTokenGrowthInsideLast) * liquidity of a position function calculateFixedAndVariableDelta( Info storage self, int256 fixedTokenGrowthInsideX128, int256 variableTokenGrowthInsideX128 ) internal pure returns (int256 _fixedTokenDelta, int256 _variableTokenDelta) { Info memory _self = self; int256 fixedTokenGrowthInsideDeltaX128 = fixedTokenGrowthInsideX128 - _self.fixedTokenGrowthInsideLastX128; _fixedTokenDelta = FullMath.mulDivSigned( fixedTokenGrowthInsideDeltaX128, _self._liquidity, FixedPoint128.Q128 ); int256 variableTokenGrowthInsideDeltaX128 = variableTokenGrowthInsideX128 - _self.variableTokenGrowthInsideLastX128; _variableTokenDelta = FullMath.mulDivSigned( variableTokenGrowthInsideDeltaX128, _self._liquidity, FixedPoint128.Q128 ); } /// @notice Updates fixedTokenGrowthInsideLast and variableTokenGrowthInsideLast to the current values /// @param self position info struct represeting a liquidity provider /// @param fixedTokenGrowthInsideX128 fixed token growth per unit of liquidity as of now /// @param variableTokenGrowthInsideX128 variable token growth per unit of liquidity as of now function updateFixedAndVariableTokenGrowthInside( Info storage self, int256 fixedTokenGrowthInsideX128, int256 variableTokenGrowthInsideX128 ) internal { self.fixedTokenGrowthInsideLastX128 = fixedTokenGrowthInsideX128; self.variableTokenGrowthInsideLastX128 = variableTokenGrowthInsideX128; } /// @notice Updates feeGrowthInsideLast to the current value /// @param self position info struct represeting a liquidity provider /// @param feeGrowthInsideX128 fee growth per unit of liquidity as of now function updateFeeGrowthInside( Info storage self, uint256 feeGrowthInsideX128 ) internal { self.feeGrowthInsideLastX128 = feeGrowthInsideX128; } /// @notice Updates position's liqudity following either mint or a burn /// @param self The individual position to update /// @param liquidityDelta The change in pool liquidity as a result of the position update function updateLiquidity(Info storage self, int128 liquidityDelta) internal { Info memory _self = self; if (liquidityDelta == 0) { require(_self._liquidity > 0, "NP"); // disallow pokes for 0 liquidity positions } else { self._liquidity = LiquidityMath.addDelta( _self._liquidity, liquidityDelta ); } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.9; import "../utils/LiquidityMath.sol"; import "../utils/TickMath.sol"; import "../utils/SafeCastUni.sol"; /// @title Tick /// @notice Contains functions for managing tick processes and relevant calculations library Tick { using SafeCastUni for int256; using SafeCastUni for uint256; int24 public constant MAXIMUM_TICK_SPACING = 16384; // info stored for each initialized individual tick struct Info { /// @dev the total position liquidity that references this tick (either as tick lower or tick upper) uint128 liquidityGross; /// @dev amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left), int128 liquidityNet; /// @dev fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick) /// @dev only has relative meaning, not absolute — the value depends on when the tick is initialized int256 fixedTokenGrowthOutsideX128; int256 variableTokenGrowthOutsideX128; uint256 feeGrowthOutsideX128; /// @dev true iff the tick is initialized, i.e. the value is exactly equivalent to the expression liquidityGross != 0 /// @dev these 8 bits are set to prevent fresh sstores when crossing newly initialized ticks bool initialized; } /// @notice Derives max liquidity per tick from given tick spacing /// @dev Executed within the pool constructor /// @param tickSpacing The amount of required tick separation, realized in multiples of `tickSpacing` /// e.g., a tickSpacing of 3 requires ticks to be initialized every 3rd tick i.e., ..., -6, -3, 0, 3, 6, ... /// @return The max liquidity per tick function tickSpacingToMaxLiquidityPerTick(int24 tickSpacing) internal pure returns (uint128) { int24 minTick = TickMath.MIN_TICK - (TickMath.MIN_TICK % tickSpacing); int24 maxTick = -minTick; uint24 numTicks = uint24((maxTick - minTick) / tickSpacing) + 1; return type(uint128).max / numTicks; } /// @dev Common checks for valid tick inputs. function checkTicks(int24 tickLower, int24 tickUpper) internal pure { require(tickLower < tickUpper, "TLU"); require(tickLower >= TickMath.MIN_TICK, "TLM"); require(tickUpper <= TickMath.MAX_TICK, "TUM"); } struct FeeGrowthInsideParams { int24 tickLower; int24 tickUpper; int24 tickCurrent; uint256 feeGrowthGlobalX128; } function _getGrowthInside( int24 _tickLower, int24 _tickUpper, int24 _tickCurrent, int256 _growthGlobalX128, int256 _lowerGrowthOutsideX128, int256 _upperGrowthOutsideX128 ) private pure returns (int256) { // calculate the growth below int256 _growthBelowX128; if (_tickCurrent >= _tickLower) { _growthBelowX128 = _lowerGrowthOutsideX128; } else { _growthBelowX128 = _growthGlobalX128 - _lowerGrowthOutsideX128; } // calculate the growth above int256 _growthAboveX128; if (_tickCurrent < _tickUpper) { _growthAboveX128 = _upperGrowthOutsideX128; } else { _growthAboveX128 = _growthGlobalX128 - _upperGrowthOutsideX128; } int256 _growthInsideX128; _growthInsideX128 = _growthGlobalX128 - (_growthBelowX128 + _growthAboveX128); return _growthInsideX128; } function getFeeGrowthInside( mapping(int24 => Tick.Info) storage self, FeeGrowthInsideParams memory params ) internal view returns (uint256 feeGrowthInsideX128) { unchecked { Info storage lower = self[params.tickLower]; Info storage upper = self[params.tickUpper]; feeGrowthInsideX128 = uint256( _getGrowthInside( params.tickLower, params.tickUpper, params.tickCurrent, params.feeGrowthGlobalX128.toInt256(), lower.feeGrowthOutsideX128.toInt256(), upper.feeGrowthOutsideX128.toInt256() ) ); } } struct VariableTokenGrowthInsideParams { int24 tickLower; int24 tickUpper; int24 tickCurrent; int256 variableTokenGrowthGlobalX128; } function getVariableTokenGrowthInside( mapping(int24 => Tick.Info) storage self, VariableTokenGrowthInsideParams memory params ) internal view returns (int256 variableTokenGrowthInsideX128) { Info storage lower = self[params.tickLower]; Info storage upper = self[params.tickUpper]; variableTokenGrowthInsideX128 = _getGrowthInside( params.tickLower, params.tickUpper, params.tickCurrent, params.variableTokenGrowthGlobalX128, lower.variableTokenGrowthOutsideX128, upper.variableTokenGrowthOutsideX128 ); } struct FixedTokenGrowthInsideParams { int24 tickLower; int24 tickUpper; int24 tickCurrent; int256 fixedTokenGrowthGlobalX128; } function getFixedTokenGrowthInside( mapping(int24 => Tick.Info) storage self, FixedTokenGrowthInsideParams memory params ) internal view returns (int256 fixedTokenGrowthInsideX128) { Info storage lower = self[params.tickLower]; Info storage upper = self[params.tickUpper]; // do we need an unchecked block in here (given we are dealing with an int256)? fixedTokenGrowthInsideX128 = _getGrowthInside( params.tickLower, params.tickUpper, params.tickCurrent, params.fixedTokenGrowthGlobalX128, lower.fixedTokenGrowthOutsideX128, upper.fixedTokenGrowthOutsideX128 ); } /// @notice Updates a tick and returns true if the tick was flipped from initialized to uninitialized, or vice versa /// @param self The mapping containing all tick information for initialized ticks /// @param tick The tick that will be updated /// @param tickCurrent The current tick /// @param liquidityDelta A new amount of liquidity to be added (subtracted) when tick is crossed from left to right (right to left) /// @param fixedTokenGrowthGlobalX128 The fixed token growth accumulated per unit of liquidity for the entire life of the vamm /// @param variableTokenGrowthGlobalX128 The variable token growth accumulated per unit of liquidity for the entire life of the vamm /// @param upper true for updating a position's upper tick, or false for updating a position's lower tick /// @param maxLiquidity The maximum liquidity allocation for a single tick /// @return flipped Whether the tick was flipped from initialized to uninitialized, or vice versa function update( mapping(int24 => Tick.Info) storage self, int24 tick, int24 tickCurrent, int128 liquidityDelta, int256 fixedTokenGrowthGlobalX128, int256 variableTokenGrowthGlobalX128, uint256 feeGrowthGlobalX128, bool upper, uint128 maxLiquidity ) internal returns (bool flipped) { Tick.Info storage info = self[tick]; uint128 liquidityGrossBefore = info.liquidityGross; require( int128(info.liquidityGross) + liquidityDelta >= 0, "not enough liquidity to burn" ); uint128 liquidityGrossAfter = LiquidityMath.addDelta( liquidityGrossBefore, liquidityDelta ); require(liquidityGrossAfter <= maxLiquidity, "LO"); flipped = (liquidityGrossAfter == 0) != (liquidityGrossBefore == 0); if (liquidityGrossBefore == 0) { // by convention, we assume that all growth before a tick was initialized happened _below_ the tick if (tick <= tickCurrent) { info.feeGrowthOutsideX128 = feeGrowthGlobalX128; info.fixedTokenGrowthOutsideX128 = fixedTokenGrowthGlobalX128; info .variableTokenGrowthOutsideX128 = variableTokenGrowthGlobalX128; } info.initialized = true; } /// check shouldn't we unintialize the tick if liquidityGrossAfter = 0? info.liquidityGross = liquidityGrossAfter; /// add comments // when the lower (upper) tick is crossed left to right (right to left), liquidity must be added (removed) info.liquidityNet = upper ? info.liquidityNet - liquidityDelta : info.liquidityNet + liquidityDelta; } /// @notice Clears tick data /// @param self The mapping containing all initialized tick information for initialized ticks /// @param tick The tick that will be cleared function clear(mapping(int24 => Tick.Info) storage self, int24 tick) internal { delete self[tick]; } /// @notice Transitions to next tick as needed by price movement /// @param self The mapping containing all tick information for initialized ticks /// @param tick The destination tick of the transition /// @param fixedTokenGrowthGlobalX128 The fixed token growth accumulated per unit of liquidity for the entire life of the vamm /// @param variableTokenGrowthGlobalX128 The variable token growth accumulated per unit of liquidity for the entire life of the vamm /// @param feeGrowthGlobalX128 The fee growth collected per unit of liquidity for the entire life of the vamm /// @return liquidityNet The amount of liquidity added (subtracted) when tick is crossed from left to right (right to left) function cross( mapping(int24 => Tick.Info) storage self, int24 tick, int256 fixedTokenGrowthGlobalX128, int256 variableTokenGrowthGlobalX128, uint256 feeGrowthGlobalX128 ) internal returns (int128 liquidityNet) { Tick.Info storage info = self[tick]; info.feeGrowthOutsideX128 = feeGrowthGlobalX128 - info.feeGrowthOutsideX128; info.fixedTokenGrowthOutsideX128 = fixedTokenGrowthGlobalX128 - info.fixedTokenGrowthOutsideX128; info.variableTokenGrowthOutsideX128 = variableTokenGrowthGlobalX128 - info.variableTokenGrowthOutsideX128; liquidityNet = info.liquidityNet; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.9; /// @title Math library for liquidity library LiquidityMath { /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows /// @param x The liquidity before change /// @param y The delta by which liquidity should be changed /// @return z The liquidity delta function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { if (y < 0) { uint128 yAbsolute; unchecked { yAbsolute = uint128(-y); } z = x - yAbsolute; } else { z = x + uint128(y); } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.9; /// @title FixedPoint128 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) library FixedPoint128 { uint256 internal constant Q128 = 0x100000000000000000000000000000000; }
// SPDX-License-Identifier: MIT // solhint-disable no-inline-assembly pragma solidity =0.8.9; /// @title Contains 512-bit math functions /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits library FullMath { /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv function mulDivSigned( int256 a, uint256 b, uint256 denominator ) internal pure returns (int256 result) { if (a < 0) return -int256(mulDiv(uint256(-a), b, denominator)); return int256(mulDiv(uint256(a), b, denominator)); } function mulDiv( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { // 512-bit multiply [prod1 prod0] = a * b // Compute the product mod 2**256 and mod 2**256 - 1 // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2**256 + prod0 uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product unchecked { assembly { let mm := mulmod(a, b, not(0)) prod0 := mul(a, b) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { require(denominator > 0, "Division by zero"); assembly { result := div(prod0, denominator) } return result; } // Make sure the result is less than 2**256. // Also prevents denominator == 0 require(denominator > prod1, "overflow"); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0] // Compute remainder using mulmod uint256 remainder; assembly { remainder := mulmod(a, b, denominator) } // Subtract 256 bit number from 512 bit number assembly { prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator // Compute largest power of two divisor of denominator. // Always >= 1. // uint256 twos = -denominator & denominator; // https://ethereum.stackexchange.com/questions/96642/unary-operator-cannot-be-applied-to-type-uint256 uint256 twos = (type(uint256).max - denominator + 1) & denominator; // Divide denominator by power of two assembly { denominator := div(denominator, twos) } // Divide [prod1 prod0] by the factors of two assembly { prod0 := div(prod0, twos) } // Shift in bits from prod1 into prod0. For this we need // to flip `twos` such that it is 2**256 / twos. // If twos is zero, then it becomes one assembly { twos := add(div(sub(0, twos), twos), 1) } 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 // correct for four bits. That is, denominator * inv = 1 mod 2**4 uint256 inv = (3 * denominator) ^ 2; // Now use Newton-Raphson iteration to improve the precision. // Thanks to Hensel's lifting lemma, this also works in modular // arithmetic, doubling the correct bits in each step. inv *= 2 - denominator * inv; // inverse mod 2**8 inv *= 2 - denominator * inv; // inverse mod 2**16 inv *= 2 - denominator * inv; // inverse mod 2**32 inv *= 2 - denominator * inv; // inverse mod 2**64 inv *= 2 - denominator * inv; // inverse mod 2**128 inv *= 2 - denominator * inv; // 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 precoditions 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 * inv; return result; } } /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result function mulDivRoundingUp( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) > 0) { require(result < type(uint256).max, "overflow"); result++; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol) pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits. */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128) { require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits"); return int128(value); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64) { require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits"); return int64(value); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32) { require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits"); return int32(value); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16) { require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits"); return int16(value); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits. * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8) { require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits"); return int8(value); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// SPDX-License-Identifier: BUSL-1.1 // solhint-disable no-inline-assembly pragma solidity =0.8.9; /// @title Math library for computing sqrt prices from ticks and vice versa /// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports /// prices between 2**-128 and 2**128 library TickMath { /// @dev MIN_TICK corresponds to an annualized fixed rate of 1000% /// @dev MAX_TICK corresponds to an annualized fixed rate of 0.001% /// @dev MIN and MAX TICKs can't be safely changed without reinstating getSqrtRatioAtTick removed lines of code from original /// TickMath.sol implementation in uniswap v3 /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128 int24 internal constant MIN_TICK = -69100; /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 int24 internal constant MAX_TICK = -MIN_TICK; /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) uint160 internal constant MIN_SQRT_RATIO = 2503036416286949174936592462; /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) uint160 internal constant MAX_SQRT_RATIO = 2507794810551837817144115957740; /// @notice Calculates sqrt(1.0001^tick) * 2^96 /// @dev Throws if |tick| > max tick /// @param tick The input tick for the above formula /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0) /// at the given tick function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) { uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); require(absTick <= uint256(int256(MAX_TICK)), "T"); uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000; if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128; if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128; if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128; if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128; if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128; if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128; if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128; if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128; if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128; if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128; if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128; if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128; if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128; if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128; if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128; if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128; if (tick > 0) ratio = type(uint256).max / ratio; // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96. // we then downcast because we know the result always fits within 160 bits due to our tick input constraint // we round up in the division so getTickAtSqrtRatio of the output price is always consistent sqrtPriceX96 = uint160( (ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1) ); } /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may /// ever return. /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96 /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) { // second inequality must be < because the price can never reach the price at the max tick require( sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, "R" ); uint256 ratio = uint256(sqrtPriceX96) << 32; uint256 r = ratio; uint256 msb = 0; assembly { let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(5, gt(r, 0xFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(4, gt(r, 0xFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(3, gt(r, 0xFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(2, gt(r, 0xF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(1, gt(r, 0x3)) msb := or(msb, f) r := shr(f, r) } assembly { let f := gt(r, 0x1) msb := or(msb, f) } if (msb >= 128) r = ratio >> (msb - 127); else r = ratio << (127 - msb); // solhint-disable-next-line var-name-mixedcase int256 log_2 = (int256(msb) - 128) << 64; assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(63, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(62, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(61, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(60, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(59, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(58, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(57, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(56, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(55, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(54, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(53, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(52, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(51, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(50, f)) } // solhint-disable-next-line var-name-mixedcase int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number int24 tickLow = int24( (log_sqrt10001 - 3402992956809132418596140100660247210) >> 128 ); int24 tickHi = int24( (log_sqrt10001 + 291339464771989622907027621153398088495) >> 128 ); tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow; } }
// SPDX-License-Identifier: BUSL-1.1 // With contributions from OpenZeppelin Contracts v4.4.0 (utils/math/SafeCast.sol) pragma solidity =0.8.9; /// @title Safe casting methods /// @notice Contains methods for safely casting between types library SafeCastUni { /// @notice Cast a uint256 to a uint160, revert on overflow /// @param y The uint256 to be downcasted /// @return z The downcasted integer, now type uint160 function toUint160(uint256 y) internal pure returns (uint160 z) { require((z = uint160(y)) == y, "toUint160 oflo"); } /// @notice Cast a int256 to a int128, revert on overflow or underflow /// @param y The int256 to be downcasted /// @return z The downcasted integer, now type int128 function toInt128(int256 y) internal pure returns (int128 z) { require((z = int128(y)) == y, "toInt128 oflo"); } /// @notice Cast a uint256 to a int256, revert on overflow /// @param y The uint256 to be casted /// @return z The casted integer, now type int256 function toInt256(uint256 y) internal pure returns (int256 z) { require(y < 2**255, "toInt256 oflo"); z = int256(y); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "toUint256 < 0"); return uint256(value); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; import "./FixedAndVariableMath.sol"; /// @title Trader library TraderWithYieldBearingAssets { // info stored for each user's position struct Info { // For Aave v2 The scaled balance is the sum of all the updated stored balances in the // underlying token, divided by the reserve's liquidity index at the moment of the update // // For componund, the scaled balance is the sum of all the updated stored balances in the // underlying token, divided by the cToken exchange rate at the moment of the update. // This is simply the number of cTokens! uint256 marginInScaledYieldBearingTokens; int256 fixedTokenBalance; int256 variableTokenBalance; bool isSettled; } function updateMarginInScaledYieldBearingTokens( Info storage self, uint256 _marginInScaledYieldBearingTokens ) internal { self .marginInScaledYieldBearingTokens = _marginInScaledYieldBearingTokens; } function settleTrader(Info storage self) internal { require(!self.isSettled, "already settled"); self.isSettled = true; } function updateBalancesViaDeltas( Info storage self, int256 fixedTokenBalanceDelta, int256 variableTokenBalanceDelta ) internal returns (int256 _fixedTokenBalance, int256 _variableTokenBalance) { _fixedTokenBalance = self.fixedTokenBalance + fixedTokenBalanceDelta; _variableTokenBalance = self.variableTokenBalance + variableTokenBalanceDelta; self.fixedTokenBalance = _fixedTokenBalance; self.variableTokenBalance = _variableTokenBalance; } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity =0.8.9; import "../interfaces/IERC20Minimal.sol"; interface IWETH { function deposit() external payable; function withdraw(uint256 amount) external; }
// 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; } }
{ "optimizer": { "enabled": true, "runs": 10 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract IStETH","name":"_stEth","type":"address"},{"internalType":"contract ILidoOracle","name":"_lidoOracle","type":"address"},{"internalType":"contract IWETH","name":"_weth","type":"address"},{"internalType":"uint32[]","name":"_times","type":"uint32[]"},{"internalType":"uint256[]","name":"_results","type":"uint256[]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AavePoolGetReserveNormalizedIncomeReturnedZero","type":"error"},{"inputs":[],"name":"CTokenExchangeRateReturnedZero","type":"error"},{"inputs":[{"internalType":"bool","name":"unlocked","type":"bool"}],"name":"CanOnlyTradeIfUnlocked","type":"error"},{"inputs":[],"name":"CannotLiquidate","type":"error"},{"inputs":[],"name":"CannotSettleBeforeMaturity","type":"error"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"name":"DebugError","type":"error"},{"inputs":[{"internalType":"int256","name":"amount0","type":"int256"},{"internalType":"int256","name":"amount1","type":"int256"}],"name":"ExpectedOppositeSigns","type":"error"},{"inputs":[{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"name":"ExpectedSqrtPriceZeroBeforeInit","type":"error"},{"inputs":[],"name":"IRSNotionalAmountSpecifiedMustBeNonZero","type":"error"},{"inputs":[],"name":"InvalidMarginDelta","type":"error"},{"inputs":[],"name":"LidoGetPooledEthBySharesReturnedZero","type":"error"},{"inputs":[{"internalType":"uint128","name":"amount","type":"uint128"}],"name":"LiquidityDeltaMustBePositiveInBurn","type":"error"},{"inputs":[{"internalType":"uint128","name":"amount","type":"uint128"}],"name":"LiquidityDeltaMustBePositiveInMint","type":"error"},{"inputs":[{"internalType":"int256","name":"marginRequirement","type":"int256"}],"name":"MarginLessThanMinimum","type":"error"},{"inputs":[{"internalType":"int256","name":"marginRequirement","type":"int256"},{"internalType":"int24","name":"tick","type":"int24"},{"internalType":"int256","name":"fixedTokenDelta","type":"int256"},{"internalType":"int256","name":"variableTokenDelta","type":"int256"},{"internalType":"uint256","name":"cumulativeFeeIncurred","type":"uint256"},{"internalType":"int256","name":"fixedTokenDeltaUnbalanced","type":"int256"}],"name":"MarginRequirementNotMet","type":"error"},{"inputs":[{"internalType":"int256","name":"marginRequirement","type":"int256"}],"name":"MarginRequirementNotMetFCM","type":"error"},{"inputs":[{"internalType":"uint256","name":"requested","type":"uint256"},{"internalType":"uint256","name":"available","type":"uint256"}],"name":"NotEnoughFunds","type":"error"},{"inputs":[],"name":"OOO","type":"error"},{"inputs":[],"name":"OnlyFCM","type":"error"},{"inputs":[],"name":"OnlyMarginEngine","type":"error"},{"inputs":[],"name":"OnlyOwnerCanUpdatePosition","type":"error"},{"inputs":[],"name":"OnlyVAMM","type":"error"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"PRBMathUD60x18__Exp2InputTooBig","type":"error"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"PRBMathUD60x18__FromUintOverflow","type":"error"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"PRBMathUD60x18__LogInputTooSmall","type":"error"},{"inputs":[{"internalType":"uint256","name":"prod1","type":"uint256"}],"name":"PRBMath__MulDivFixedPointOverflow","type":"error"},{"inputs":[{"internalType":"uint256","name":"prod1","type":"uint256"},{"internalType":"uint256","name":"denominator","type":"uint256"}],"name":"PRBMath__MulDivOverflow","type":"error"},{"inputs":[],"name":"PositionNetZero","type":"error"},{"inputs":[],"name":"PositionNotSettled","type":"error"},{"inputs":[],"name":"RocketPoolGetEthValueReturnedZero","type":"error"},{"inputs":[],"name":"WithdrawalExceedsCurrentMargin","type":"error"},{"inputs":[],"name":"closeToOrBeyondMaturity","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_minSecondsSinceLastUpdate","type":"uint256"}],"name":"MinSecondsSinceLastUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"blockTimestampScaled","type":"uint256"},{"indexed":false,"internalType":"address","name":"source","type":"address"},{"indexed":false,"internalType":"uint16","name":"index","type":"uint16"},{"indexed":false,"internalType":"uint32","name":"blockTimestamp","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"observedValue","type":"uint256"},{"indexed":false,"internalType":"uint16","name":"cardinality","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"cardinalityNext","type":"uint16"}],"name":"OracleBufferUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"observationCardinalityNextNew","type":"uint16"}],"name":"RateCardinalityNext","type":"event"},{"inputs":[],"name":"ONE_IN_WAD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNDERLYING_YIELD_BEARING_PROTOCOL_ID","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentBlockSlope","outputs":[{"internalType":"uint32","name":"timeChange","type":"uint32"},{"internalType":"uint256","name":"blockChange","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"from","type":"uint256"}],"name":"getApyFrom","outputs":[{"internalType":"uint256","name":"apyFromToWad","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"from","type":"uint256"},{"internalType":"uint256","name":"to","type":"uint256"}],"name":"getApyFromTo","outputs":[{"internalType":"uint256","name":"apyFromToWad","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBlockSlope","outputs":[{"internalType":"uint256","name":"blockChange","type":"uint256"},{"internalType":"uint32","name":"timeChange","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentRateInRay","outputs":[{"internalType":"uint256","name":"currentRate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLastRateSlope","outputs":[{"internalType":"uint256","name":"rateChange","type":"uint256"},{"internalType":"uint32","name":"timeChange","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLastUpdatedRate","outputs":[{"internalType":"uint32","name":"timestamp","type":"uint32"},{"internalType":"uint256","name":"resultRay","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_from","type":"uint256"}],"name":"getRateFrom","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_from","type":"uint256"},{"internalType":"uint256","name":"_to","type":"uint256"}],"name":"getRateFromTo","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"rateCardinalityNext","type":"uint16"}],"name":"increaseObservationCardinalityNext","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"beforeOrAtRateValueRay","type":"uint256"},{"internalType":"uint256","name":"apyFromBeforeOrAtToAtOrAfterWad","type":"uint256"},{"internalType":"uint256","name":"timeDeltaBeforeOrAtToQueriedTimeWad","type":"uint256"}],"name":"interpolateRateValue","outputs":[{"internalType":"uint256","name":"rateValueRay","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"lastUpdatedBlock","outputs":[{"internalType":"uint32","name":"timestamp","type":"uint32"},{"internalType":"uint256","name":"number","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lidoOracle","outputs":[{"internalType":"contract ILidoOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minSecondsSinceLastUpdate","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":"observedValue","type":"uint216"},{"internalType":"bool","name":"initialized","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracleVars","outputs":[{"internalType":"uint16","name":"rateIndex","type":"uint16"},{"internalType":"uint16","name":"rateCardinality","type":"uint16"},{"internalType":"uint16","name":"rateCardinalityNext","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"refreshBeaconSpec","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minSecondsSinceLastUpdate","type":"uint256"}],"name":"setMinSecondsSinceLastUpdate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"uint32","name":"","type":"uint32"}],"name":"settlementRateCache","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stEth","outputs":[{"internalType":"contract IStETH","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"underlying","outputs":[{"internalType":"contract IERC20Minimal","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"termStartTimestampInWeiSeconds","type":"uint256"},{"internalType":"uint256","name":"termEndTimestampInWeiSeconds","type":"uint256"}],"name":"variableFactor","outputs":[{"internalType":"uint256","name":"resultWad","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"termStartTimestampInWeiSeconds","type":"uint256"},{"internalType":"uint256","name":"termEndTimestampInWeiSeconds","type":"uint256"}],"name":"variableFactorNoCache","outputs":[{"internalType":"uint256","name":"resultWad","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"writeOracleEntry","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60a06040523480156200001157600080fd5b5060405162003c2538038062003c25833981016040819052620000349162000b27565b82620000403362000196565b6001600160a01b03811660805243620100045562000069620001e6602090811b62000e5417901c565b62010003805463ffffffff9290921663ffffffff19928316179055620100058054909116608717905550600a62010006556001600160a01b038516620000e95760405162461bcd60e51b815260206004820152601060248201526f1cdd115512081b5d5cdd08195e1a5cdd60821b60448201526064015b60405180910390fd5b6001600160a01b038416620001415760405162461bcd60e51b815260206004820152601560248201527f6c69646f4f7261636c65206d75737420657869737400000000000000000000006044820152606401620000e0565b6201000780546001600160a01b038088166001600160a01b031992831617909255620100088054928716929091169190911790556200017f620001f8565b6200018b8282620002eb565b505050505062000e6d565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000620001f34262000576565b905090565b60008060006201000860009054906101000a90046001600160a01b03166001600160a01b031663e547c77c6040518163ffffffff1660e01b815260040160806040518083038186803b1580156200024e57600080fd5b505afa15801562000263573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000289919062000c5c565b620100088054600160a01b600160e01b031916600160a01b6001600160401b0384160217905591955093509150620002c49050828462000ccf565b6201000980546001600160401b0319166001600160401b0392909216919091179055505050565b620002fa600261ffff62000d01565b8251106200031c5760405162461bcd60e51b8152600401620000e09062000d24565b8151815161ffff821614620003455760405162461bcd60e51b8152600401620000e09062000d42565b60006200035482600162000d6e565b61ffff166001600160401b0381111562000372576200037262000a45565b6040519080825280602002602001820160405280156200039c578160200160208202803683370190505b5090506000620003ae83600162000d6e565b61ffff166001600160401b03811115620003cc57620003cc62000a45565b604051908082528060200260200182016040528015620003f6578160200160208202803683370190505b50905060005b8361ffff16811015620004a7578581815181106200041e576200041e62000d97565b60200260200101518382815181106200043b576200043b62000d97565b602002602001019063ffffffff16908163ffffffff16815250508481815181106200046a576200046a62000d97565b602002602001015182828151811062000487576200048762000d97565b6020908102919091010152806200049e8162000dad565b915050620003fc565b50600080620004b5620005bd565b9150915081848661ffff1681518110620004d357620004d362000d97565b602002602001019063ffffffff16908163ffffffff168152505080838661ffff168151811062000507576200050762000d97565b60200260200101818152505062000530848460046200075860201b62000e64179092919060201c565b6003805461ffff948516620100000263ffff0000199486166401000000000265ffff0000ffff199092169590931694909417939093179190911617905550505050505050565b8063ffffffff81168114620005b85760405162461bcd60e51b815260206004820152600760248201526654534f464c4f5760c81b6044820152606401620000e0565b919050565b6201000754604051630f451f7160e31b81526b033b2e3c9fd0803ce80000006004820152600091829182916001600160a01b031690637a28fb889060240160206040518083038186803b1580156200061457600080fd5b505afa15801562000629573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200064f919062000dcb565b90508062000673576040516001620723a560e01b0319815260040160405180910390fd5b6201000854604080516389896aef60e01b815290516000926001600160a01b0316916389896aef916004808301926020929190829003018186803b158015620006bb57600080fd5b505afa158015620006d0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620006f6919062000dcb565b62010009549091506000906200074d906200071b906001600160401b03168462000de5565b62010008546200073c9190600160a01b90046001600160401b031662000e07565b6200057660201b620010a71760201c565b959294509192505050565b600080600061ffff855110620007825760405162461bcd60e51b8152600401620000e09062000d24565b8451845161ffff821614620007ab5760405162461bcd60e51b8152600401620000e09062000d42565b60008161ffff1611620007e65760405162461bcd60e51b81526020600482015260026024820152610c1560f21b6044820152606401620000e0565b6000805b8261ffff168161ffff1610156200097c57878161ffff168151811062000814576200081462000d97565b602002602001015163ffffffff168263ffffffff16106200086a5760405162461bcd60e51b815260206004820152600f60248201526e1a5b9c1d5d081d5b9bdc99195c9959608a1b6044820152606401620000e0565b620008bc888261ffff168151811062000887576200088762000d97565b6020026020010151888361ffff1681518110620008a857620008a862000d97565b60200260200101516200099d60201b60201c565b898261ffff1661ffff8110620008d657620008d662000d97565b82519101805460208401516040909401511515600160f81b026001600160f81b036001600160d81b03909516640100000000027fff0000000000000000000000000000000000000000000000000000000000000090921663ffffffff9094169390931717929092161790558751889061ffff83169081106200095c576200095c62000d97565b602002602001015191508080620009739062000e22565b915050620007ea565b5081806200098c60018262000e47565b945094509450505093509350939050565b60408051606081018252600080825260208201819052918101919091526001600160d81b03821115620009fc5760405162461bcd60e51b8152600401620000e0906020808252600490820152631f19189b60e11b604082015260600190565b506040805160608101825263ffffffff9390931683526001600160d81b0391909116602083015260019082015290565b6001600160a01b038116811462000a4257600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171562000a865762000a8662000a45565b604052919050565b60006001600160401b0382111562000aaa5762000aaa62000a45565b5060051b60200190565b600082601f83011262000ac657600080fd5b8151602062000adf62000ad98362000a8e565b62000a5b565b82815260059290921b8401810191818101908684111562000aff57600080fd5b8286015b8481101562000b1c578051835291830191830162000b03565b509695505050505050565b600080600080600060a0868803121562000b4057600080fd5b855162000b4d8162000a2c565b8095505060208087015162000b628162000a2c565b604088015190955062000b758162000a2c565b60608801519094506001600160401b038082111562000b9357600080fd5b818901915089601f83011262000ba857600080fd5b815162000bb962000ad98262000a8e565b81815260059190911b8301840190848101908c83111562000bd957600080fd5b938501935b8285101562000c0d57845163ffffffff8116811462000bfd5760008081fd5b8252938501939085019062000bde565b60808c0151909750945050508083111562000c2757600080fd5b505062000c378882890162000ab4565b9150509295509295909350565b80516001600160401b0381168114620005b857600080fd5b6000806000806080858703121562000c7357600080fd5b62000c7e8562000c44565b935062000c8e6020860162000c44565b925062000c9e6040860162000c44565b915062000cae6060860162000c44565b905092959194509250565b634e487b7160e01b600052601160045260246000fd5b60006001600160401b038281168482168115158284048211161562000cf85762000cf862000cb9565b02949350505050565b60008262000d1f57634e487b7160e01b600052601260045260246000fd5b500490565b6020808252600490820152631350561560e21b604082015260600190565b602080825260129082015271098cadccee8d0e640daeae6e840dac2e8c6d60731b604082015260600190565b600061ffff80831681851680830382111562000d8e5762000d8e62000cb9565b01949350505050565b634e487b7160e01b600052603260045260246000fd5b600060001982141562000dc45762000dc462000cb9565b5060010190565b60006020828403121562000dde57600080fd5b5051919050565b600081600019048311821515161562000e025762000e0262000cb9565b500290565b6000821982111562000e1d5762000e1d62000cb9565b500190565b600061ffff8083168181141562000e3d5762000e3d62000cb9565b6001019392505050565b600061ffff8381169083168181101562000e655762000e6562000cb9565b039392505050565b608051612d9c62000e8960003960006102d50152612d9c6000f3fe608060405234801561001057600080fd5b506004361061015f5760003560e01c80631195082e14610164578063163e9c4f146101a257806317221ef1146101b557806322ff6568146101c857806324b18b17146101e2578063252c09d71461021657806325f258dd1461025557806332148f6714610268578063357d7b5c1461027d57806341453528146102aa57806354124c64146102bd5780636f307dc3146102d0578063715018a6146102f75780637aa4db13146102ff5780637cf2cc9f146103075780638a6b8c5d146103105780638da5cb5b1461031857806391aa375d1461032057806393556dbd1461034257806399940ece14610355578063bdb050921461036a578063c330c98d1461037d578063c7db359b1461038c578063ddc7a5aa146103d4578063efdf5d8b146103dc578063f2fde38b146103e4578063f739670c146103f7578063f90ce5ba1461040a578063fe115fbe14610422575b600080fd5b61018f610172366004612a00565b600160209081526000928352604080842090915290825290205481565b6040519081526020015b60405180910390f35b61018f6101b0366004612a33565b61042a565b61018f6101c3366004612a33565b61043c565b6101d0600381565b60405160ff9091168152602001610199565b620100055462010006546101fa9163ffffffff169082565b6040805163ffffffff9093168352602083019190915201610199565b610229610224366004612a33565b610448565b6040805163ffffffff90941684526001600160d81b039092166020840152151590820152606001610199565b61018f610263366004612a4c565b610482565b61027b610276366004612a6e565b6104fd565b005b6201000854610292906001600160a01b031681565b6040516001600160a01b039091168152602001610199565b61018f6102b8366004612a4c565b610582565b61018f6102cb366004612a92565b610596565b6102927f000000000000000000000000000000000000000000000000000000000000000081565b61027b6105eb565b61027b61062f565b61018f60025481565b6101fa61067c565b6102926107f7565b610328610806565b6040805192835263ffffffff909116602083015201610199565b61018f610350366004612a4c565b610864565b6201000754610292906001600160a01b031681565b61027b610378366004612a33565b6108f4565b61018f670de0b6b3a764000081565b6003546103af9061ffff80821691620100008104821691600160201b9091041683565b6040805161ffff94851681529284166020840152921691810191909152606001610199565b61027b610968565b61018f610a55565b61027b6103f2366004612abe565b610add565b61018f610405366004612a4c565b610b7a565b620100035462010004546101fa9163ffffffff169082565b610328610c84565b60006104368242610b7a565b92915050565b60006104368242610864565b60048161ffff811061045957600080fd5b015463ffffffff81169150600160201b81046001600160d81b031690600160f81b900460ff1683565b60008061048f84846110ec565b909250905080156104f65760006104b4670de0b6b3a764000086046110a7565b6110a7565b905060006104cb670de0b6b3a764000086046110a7565b63ffffffff928316600090815260016020908152604080832095909316825293909352909120839055505b5092915050565b600354600160201b900461ffff1660006105196004838561122a565b6003805461ffff808416600160201b810261ffff60201b199093169290921790925591925083161461057d5760405161ffff821681527f8a96a9c4bca0fb28be0fc5c84e95aff121a64e2533021e9d638bdc1f03b14ece9060200160405180910390a15b505050565b600061058e83836110ec565b509392505050565b6000806105a28361131f565b905060006105b8670de0b6b3a764000086612afd565b905060006105c68284611336565b905060006105d382611375565b90506105df888261139f565b98975050505050505050565b336105f46107f7565b6001600160a01b0316146106235760405162461bcd60e51b815260040161061a90612b15565b60405180910390fd5b61062d60006113ad565b565b6003546106549061ffff80821691620100008104821691600160201b909104166113fd565b6003805463ffffffff19166201000061ffff9384160261ffff19161792909116919091179055565b6201000754604051630f451f7160e31b8152676765c793fa10079d601b1b6004820152600091829182916001600160a01b031690637a28fb889060240160206040518083038186803b1580156106d157600080fd5b505afa1580156106e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107099190612b4a565b90508061072c576040516001620723a560e01b0319815260040160405180910390fd5b6201000854604080516389896aef60e01b815290516000926001600160a01b0316916389896aef916004808301926020929190829003018186803b15801561077357600080fd5b505afa158015610787573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107ab9190612b4a565b62010009549091506000906107ec906107cd906001600160401b031684612b63565b62010008546104af9190600160a01b90046001600160401b0316612afd565b959294509192505050565b6000546001600160a01b031690565b6000804362010003600101541061083057505062010006546201000554909163ffffffff90911690565b620100045461083f9043612b82565b620100035463ffffffff16610852610e54565b61085c9190612b99565b915091509091565b6000818311156108a95760405162461bcd60e51b815260206004820152601060248201526f4d69736f72646572656420646174657360801b604482015260640161061a565b60006108b58484610b7a565b905060006108c38585612b82565b905060006108d0826115a0565b905060006108dd8261131f565b90506108e984826115ed565b979650505050505050565b336108fd6107f7565b6001600160a01b0316146109235760405162461bcd60e51b815260040161061a90612b15565b80600254146109655760028190556040518181527f88bd1242a1ad7dbba4967e0120324f17c382e4e3006e01dc3ffc0bf43e4b2a399060200160405180910390a15b50565b60008060006201000860009054906101000a90046001600160a01b03166001600160a01b031663e547c77c6040518163ffffffff1660e01b815260040160806040518083038186803b1580156109bd57600080fd5b505afa1580156109d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109f59190612bd5565b620100088054600160a01b600160e01b031916600160a01b6001600160401b0384160217905591955093509150610a2e90508284612c29565b6201000980546001600160401b0319166001600160401b0392909216919091179055505050565b6000806000610a6261067c565b91509150610a6e610e54565b63ffffffff168263ffffffff1610610a865792915050565b600080610a91610c84565b915091508063ffffffff168285610aa6610e54565b610ab09190612b99565b63ffffffff16610ac09190612b63565b610aca9190612c6e565b610ad49084612afd565b94505050505090565b33610ae66107f7565b6001600160a01b031614610b0c5760405162461bcd60e51b815260040161061a90612b15565b6001600160a01b038116610b715760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161061a565b610965816113ad565b600081831115610bb85760405162461bcd60e51b815260206004820152600960248201526866726f6d203e20746f60b81b604482015260640161061a565b81831415610bc857506000610436565b6000610bd2610e54565b90506000610bdf856110a7565b90506000610bec856110a7565b600354909150600090610c10908590859061ffff8082169162010000900416611652565b600354909150600090610c34908690859061ffff8082169162010000900416611652565b905081811115610c76576000610c68676765c793fa10079d601b1b610c59848661189e565b610c639190612b82565b6118ac565b965061043695505050505050565b600095505050505050610436565b600354600090819061ffff16816001821015610cb857600354610cb39060019062010000900461ffff16612c82565b610ccb565b600354610ccb9060019061ffff16612c82565b60035490915060026201000090910461ffff1610801590610d0c575060048161ffff1661ffff8110610cff57610cff612c9d565b0154600160f81b900460ff165b8015610d69575060048261ffff1661ffff8110610d2b57610d2b612c9d565b0154600160201b90046001600160d81b0316600461ffff838116908110610d5457610d54612c9d565b0154600160201b90046001600160d81b031611155b610d9b5760405162461bcd60e51b815260206004820152600360248201526204e45560ec1b604482015260640161061a565b60048161ffff1661ffff8110610db357610db3612c9d565b0154600160201b90046001600160d81b0316600461ffff848116908110610ddc57610ddc612c9d565b0154610df89190600160201b90046001600160d81b0316612cb3565b6001600160d81b0316935060048161ffff1661ffff8110610e1b57610e1b612c9d565b015463ffffffff16600461ffff808516908110610e3a57610e3a612c9d565b0154610e4c919063ffffffff16612b99565b925050509091565b6000610e5f426110a7565b905090565b600080600061ffff855110610ea45760405162461bcd60e51b815260040161061a906020808252600490820152631350561560e21b604082015260600190565b8451845161ffff821614610eef5760405162461bcd60e51b8152602060048201526012602482015271098cadccee8d0e640daeae6e840dac2e8c6d60731b604482015260640161061a565b60008161ffff1611610f285760405162461bcd60e51b81526020600482015260026024820152610c1560f21b604482015260640161061a565b6000805b8261ffff168161ffff16101561108857878161ffff1681518110610f5257610f52612c9d565b602002602001015163ffffffff168263ffffffff1610610fa65760405162461bcd60e51b815260206004820152600f60248201526e1a5b9c1d5d081d5b9bdc99195c9959608a1b604482015260640161061a565b610fea888261ffff1681518110610fbf57610fbf612c9d565b6020026020010151888361ffff1681518110610fdd57610fdd612c9d565b6020026020010151611938565b898261ffff1661ffff811061100157611001612c9d565b82519101805460208401516040909401511515600160f81b026001600160f81b036001600160d81b03909516600160201b026001600160f81b031990921663ffffffff9094169390931717929092161790558751889061ffff831690811061106b5761106b612c9d565b60200260200101519150808061108090612cd3565b915050610f2c565b508180611096600182612c82565b945094509450505093509350939050565b8063ffffffff811681146110e75760405162461bcd60e51b815260206004820152600760248201526654534f464c4f5760c81b604482015260640161061a565b919050565b60008080611103670de0b6b3a764000086046110a7565b9050600061111a670de0b6b3a764000086046110a7565b905060008263ffffffff16118015611138575060008163ffffffff16115b61116c5760405162461bcd60e51b8152602060048201526005602482015264554e49545360d81b604482015260640161061a565b63ffffffff808316600090815260016020908152604080832093851683529290522054156111c25763ffffffff808316600090815260016020908152604080832093851683529290529081205494509250611221565b8063ffffffff166111d1610e54565b63ffffffff16106111fd576111f28263ffffffff168263ffffffff16610b7a565b935060019250611221565b61121a8263ffffffff1661120f610e54565b63ffffffff16610b7a565b9350600092505b50509250929050565b6000808361ffff16116112635760405162461bcd60e51b81526020600482015260016024820152604960f81b604482015260640161061a565b61ffff8261ffff16106112a75760405162461bcd60e51b815260206004820152600c60248201526b189d5999995c881b1a5b5a5d60a21b604482015260640161061a565b8261ffff168261ffff16116112bd575081611318565b825b8261ffff168161ffff161015611313576001858261ffff1661ffff81106112e8576112e8612c9d565b01805463ffffffff191663ffffffff929092169190911790558061130b81612cd3565b9150506112bf565b508190505b9392505050565b6000610436826a1a1601fc4ea7109e0000006119b0565b60008261135b57811561134a576000611354565b670de0b6b3a76400005b9050610436565b61131861137061136a856119c5565b84611a75565b611a81565b600080611395670de0b6b3a7640000676765c793fa10079d601b1b612c6e565b6113189084612b63565b600061131883836001611ac7565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080600060048661ffff1661ffff811061141a5761141a612c9d565b60408051606081018252929091015463ffffffff811683526001600160d81b03600160201b820416602084015260ff600160f81b90910416151590820152905060008061146561067c565b600254855192945090925061147f9163ffffffff16612afd565b8263ffffffff16101561149a57878794509450505050611598565b7f5aec68e6980e788266f2f59f6fddb85f3e256ce6da46fdfab920b9b06aaa73756114c3611b7a565b6040805191825230602083015261ffff8b81168383015263ffffffff86166060840152608083018590528a811660a0840152891660c0830152519081900360e00190a162010004546115159043612b82565b6201000655620100035463ffffffff1661152d610e54565b6115379190612b99565b62010005805463ffffffff191663ffffffff92909216919091179055436201000455611561610e54565b62010003805463ffffffff191663ffffffff928316179055611590906004908a90859085908c908c90611b8516565b945094505050505b935093915050565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218211156115df57604051633492ffd960e01b81526004810183905260240161061a565b50670de0b6b3a76400000290565b6000826115fc57506000610436565b600061161161160b60016115a0565b846119b0565b905060006116338561162360016115a0565b61162d9190612afd565b83611336565b905061163f60016115a0565b6116499082612b82565b95945050505050565b60008363ffffffff168563ffffffff16101561168157604051632ff198e560e21b815260040160405180910390fd5b8363ffffffff168563ffffffff1614156117295761169d6129cc565b60048461ffff1661ffff81106116b5576116b5612c9d565b60408051606081018252919092015463ffffffff808216808452600160201b83046001600160d81b03166020850152600160f81b90920460ff16151593830193909352909250908716146117125761170b610a55565b9150611723565b80602001516001600160d81b031691505b50611896565b6000611733610a55565b90506000806117476004888a868a8a611ccd565b91509150816000015163ffffffff168763ffffffff1614156117785781602001516001600160d81b03169350611892565b805163ffffffff8881169116141561179f5780602001516001600160d81b03169350611892565b600082602001516001600160d81b031682602001516001600160d81b0316111561180e576000676765c793fa10079d601b1b6117f584602001516001600160d81b031686602001516001600160d81b031661189e565b6117ff9190612b82565b905061180a816118ac565b9150505b8251825160009161184191670de0b6b3a76400009161182c91612b99565b63ffffffff1661183c9190612b63565b61131f565b9050600061184f83836115ed565b905061188c85602001516001600160d81b031682670de0b6b3a764000088600001518e61187c9190612b99565b63ffffffff166102cb9190612b63565b96505050505b5050505b949350505050565b600061131883836001611e7f565b6000806118cc670de0b6b3a7640000676765c793fa10079d601b1b612c6e565b6118d69084612c6e565b905060026118f7670de0b6b3a7640000676765c793fa10079d601b1b612c6e565b6119019190612c6e565b61191e670de0b6b3a7640000676765c793fa10079d601b1b612c6e565b6119289085612cf5565b1061043657611318600182612afd565b6119406129cc565b6001600160d81b038211156119805760405162461bcd60e51b815260040161061a906020808252600490820152631f19189b60e11b604082015260600190565b506040805160608101825263ffffffff9390931683526001600160d81b0391909116602083015260019082015290565b600061131883670de0b6b3a764000084611f1a565b6000670de0b6b3a76400008210156119f357604051633621413760e21b81526004810183905260240161061a565b6000611a08670de0b6b3a76400008404611fe8565b670de0b6b3a7640000808202935090915083821c90811415611a2b575050919050565b6706f05b59d3b200005b8015611a6d57670de0b6b3a7640000828002049150671bc16d674ec800008210611a65579283019260019190911c905b60011c611a35565b505050919050565b600061131883836120c6565b6000680a688906bd8b0000008210611aaf57604051634a4f26f160e01b81526004810183905260240161061a565b670de0b6b3a7640000604083901b0461131881612188565b6000831580611ad4575082155b15611ae157506000611318565b6001826001811115611af557611af5612d09565b14611b0857670de0b6b3a7640000611b15565b676765c793fa10079d601b1b5b6001836001811115611b2957611b29612d09565b14611b4657611b416002670de0b6b3a7640000612c6e565b611b5c565b611b5c6002676765c793fa10079d601b1b612c6e565b611b668587612b63565b611b709190612afd565b6118969190612c6e565b6000610e5f426115a0565b6000806000888861ffff1661ffff8110611ba157611ba1612c9d565b60408051606081018252919092015463ffffffff808216808452600160201b83046001600160d81b03166020850152600160f81b90920460ff161515938301939093529092509088161415611bfc5787859250925050611cc2565b8461ffff168461ffff16118015611c245750611c19600186612c82565b61ffff168861ffff16145b15611c3157839150611c35565b8491505b81611c41896001612d1f565b611c4b9190612d45565b9250611c578787611938565b898461ffff1661ffff8110611c6e57611c6e612c9d565b82519101805460208401516040909401511515600160f81b026001600160f81b036001600160d81b03909516600160201b026001600160f81b031990921663ffffffff909416939093171792909216179055505b965096945050505050565b611cd56129cc565b611cdd6129cc565b878461ffff1661ffff8110611cf457611cf4612c9d565b60408051606081018252919092015463ffffffff808216808452600160201b83046001600160d81b03166020850152600160f81b90920460ff1615159383019390935290935090881610611d73578663ffffffff16826000015163ffffffff161415611d5f57611cc2565b81611d6a8787611938565b91509150611cc2565b8783611d80866001612d1f565b611d8a9190612d45565b61ffff1661ffff8110611d9f57611d9f612c9d565b60408051606081018252919092015463ffffffff81168252600160201b81046001600160d81b03166020830152600160f81b900460ff1615159181018290529250611e245760408051606081018252895463ffffffff81168252600160201b81046001600160d81b03166020830152600160f81b900460ff1615159181019190915291505b815163ffffffff80891691161115611e645760405162461bcd60e51b815260206004820152600360248201526213d31160ea1b604482015260640161061a565b611e708888868661281a565b91509150965096945050505050565b600082611eb75760405162461bcd60e51b815260040161061a906020808252600490820152630444956360e41b604082015260600190565b6000611ec4600285612c6e565b905083816001856001811115611edc57611edc612d09565b14611eef57670de0b6b3a7640000611efc565b676765c793fa10079d601b1b5b611f069088612b63565b611f109190612afd565b6116499190612c6e565b600080806000198587098587029250828110838203039150508060001415611f5557838281611f4b57611f4b612c58565b0492505050611318565b838110611f7f57604051631dcf306360e21b8152600481018290526024810185905260440161061a565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6000600160801b821061200857608091821c916120059082612afd565b90505b600160401b821061202657604091821c916120239082612afd565b90505b600160201b821061204457602091821c916120419082612afd565b90505b62010000821061206157601091821c9161205e9082612afd565b90505b610100821061207d57600891821c9161207a9082612afd565b90505b6010821061209857600491821c916120959082612afd565b90505b600482106120b357600291821c916120b09082612afd565b90505b600282106110e757610436600182612afd565b60008080600019848609848602925082811083820303915050670de0b6b3a7640000811061210a5760405163698d9a0160e11b81526004810182905260240161061a565b600080670de0b6b3a76400008688099150506706f05b59d3b1ffff8111826121445780670de0b6b3a7640000850401945050505050610436565b620400008285030493909111909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690201905092915050565b600160bf1b6001603f1b8216156121a85768016a09e667f3bcc9090260401c5b6001603e1b8216156121c3576801306fe0a31b7152df0260401c5b6001603d1b8216156121de576801172b83c7d517adce0260401c5b6001603c1b8216156121f95768010b5586cf9890f62a0260401c5b6001603b1b821615612214576801059b0d31585743ae0260401c5b6001603a1b82161561222f57680102c9a3e778060ee70260401c5b600160391b82161561224a5768010163da9fb33356d80260401c5b600160381b82161561226557680100b1afa5abcbed610260401c5b600160371b8216156122805768010058c86da1c09ea20260401c5b600160361b82161561229b576801002c605e2e8cec500260401c5b600160351b8216156122b657680100162f3904051fa10260401c5b600160341b8216156122d1576801000b175effdc76ba0260401c5b600160331b8216156122ec57680100058ba01fb9f96d0260401c5b600160321b8216156123075768010002c5cc37da94920260401c5b600160311b821615612322576801000162e525ee05470260401c5b600160301b82161561233d5768010000b17255775c040260401c5b6001602f1b821615612358576801000058b91b5bc9ae0260401c5b6001602e1b82161561237357680100002c5c89d5ec6d0260401c5b6001602d1b82161561238e5768010000162e43f4f8310260401c5b6001602c1b8216156123a957680100000b1721bcfc9a0260401c5b6001602b1b8216156123c45768010000058b90cf1e6e0260401c5b6001602a1b8216156123df576801000002c5c863b73f0260401c5b600160291b8216156123fa57680100000162e430e5a20260401c5b600160281b821615612415576801000000b1721835510260401c5b600160271b82161561243057680100000058b90c0b490260401c5b600160261b82161561244b5768010000002c5c8601cc0260401c5b600160251b821615612466576801000000162e42fff00260401c5b600160241b8216156124815768010000000b17217fbb0260401c5b600160231b82161561249c576801000000058b90bfce0260401c5b600160221b8216156124b757680100000002c5c85fe30260401c5b600160211b8216156124d25768010000000162e42ff10260401c5b600160201b8216156124ed57680100000000b17217f80260401c5b63800000008216156125085768010000000058b90bfc0260401c5b6340000000821615612523576801000000002c5c85fe0260401c5b632000000082161561253e57680100000000162e42ff0260401c5b6310000000821615612559576801000000000b17217f0260401c5b630800000082161561257457680100000000058b90c00260401c5b630400000082161561258f5768010000000002c5c8600260401c5b63020000008216156125aa576801000000000162e4300260401c5b63010000008216156125c55768010000000000b172180260401c5b628000008216156125df576801000000000058b90c0260401c5b624000008216156125f957680100000000002c5c860260401c5b622000008216156126135768010000000000162e430260401c5b6210000082161561262d57680100000000000b17210260401c5b620800008216156126475768010000000000058b910260401c5b62040000821615612661576801000000000002c5c80260401c5b6202000082161561267b57680100000000000162e40260401c5b620100008216156126945761b172600160401b010260401c5b6180008216156126ac576158b9600160401b010260401c5b6140008216156126c457612c5d600160401b010260401c5b6120008216156126dc5761162e600160401b010260401c5b6110008216156126f457610b17600160401b010260401c5b61080082161561270c5761058c600160401b010260401c5b610400821615612724576102c6600160401b010260401c5b61020082161561273c57610163600160401b010260401c5b6101008216156127535760b1600160401b010260401c5b6080821615612769576059600160401b010260401c5b604082161561277f57602c600160401b010260401c5b6020821615612795576016600160401b010260401c5b60108216156127ab57600b600160401b010260401c5b60088216156127c1576006600160401b010260401c5b60048216156127d7576003600160401b010260401c5b60028216156127ed576001600160401b010260401c5b6001821615612803576001600160401b010260401c5b670de0b6b3a76400000260409190911c60bf031c90565b6128226129cc565b61282a6129cc565b600083612838866001612d1f565b6128429190612d45565b61ffff169050600060018561ffff168361285c9190612afd565b6128669190612b82565b905060005b60016128778385612afd565b901c90508861288a61ffff881683612cf5565b61ffff811061289b5761289b612c9d565b60408051606081018252919092015463ffffffff81168252600160201b81046001600160d81b03166020830152600160f81b900460ff16151591810182905295506128f2576128eb816001612afd565b925061286b565b8861ffff8716612903836001612afd565b61290d9190612cf5565b61ffff811061291e5761291e612c9d565b60408051606081018252919092015463ffffffff8082168352600160201b82046001600160d81b03166020840152600160f81b90910460ff161515928201929092528651909550898216911611801590819061298a5750846000015163ffffffff168963ffffffff1611155b1561299557506129c0565b806129ac576129a5600183612b82565b92506129ba565b6129b7826001612afd565b93505b5061286b565b50505094509492505050565b604080516060810182526000808252602082018190529181019190915290565b803563ffffffff811681146110e757600080fd5b60008060408385031215612a1357600080fd5b612a1c836129ec565b9150612a2a602084016129ec565b90509250929050565b600060208284031215612a4557600080fd5b5035919050565b60008060408385031215612a5f57600080fd5b50508035926020909101359150565b600060208284031215612a8057600080fd5b813561ffff8116811461131857600080fd5b600080600060608486031215612aa757600080fd5b505081359360208301359350604090920135919050565b600060208284031215612ad057600080fd5b81356001600160a01b038116811461131857600080fd5b634e487b7160e01b600052601160045260246000fd5b60008219821115612b1057612b10612ae7565b500190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600060208284031215612b5c57600080fd5b5051919050565b6000816000190483118215151615612b7d57612b7d612ae7565b500290565b600082821015612b9457612b94612ae7565b500390565b600063ffffffff83811690831681811015612bb657612bb6612ae7565b039392505050565b80516001600160401b03811681146110e757600080fd5b60008060008060808587031215612beb57600080fd5b612bf485612bbe565b9350612c0260208601612bbe565b9250612c1060408601612bbe565b9150612c1e60608601612bbe565b905092959194509250565b60006001600160401b0382811684821681151582840482111615612c4f57612c4f612ae7565b02949350505050565b634e487b7160e01b600052601260045260246000fd5b600082612c7d57612c7d612c58565b500490565b600061ffff83811690831681811015612bb657612bb6612ae7565b634e487b7160e01b600052603260045260246000fd5b60006001600160d81b0383811690831681811015612bb657612bb6612ae7565b600061ffff80831681811415612ceb57612ceb612ae7565b6001019392505050565b600082612d0457612d04612c58565b500690565b634e487b7160e01b600052602160045260246000fd5b600061ffff808316818516808303821115612d3c57612d3c612ae7565b01949350505050565b600061ffff80841680612d5a57612d5a612c58565b9216919091069291505056fea264697066735822122053ab365b0ad5f734fbf8bfc6cbb382acddecb97ed90761871f8aa5b2f080946e64736f6c63430008090033000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe84000000000000000000000000442af784a788a5bd6f42a01ebe9f287a871243fb000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000062bd90570000000000000000000000000000000000000000000000000000000062bee1d70000000000000000000000000000000000000000000000000000000062c033570000000000000000000000000000000000000000000000000000000062c184d70000000000000000000000000000000000000000000000000000000062c2d6570000000000000000000000000000000000000000000000000000000062c427d70000000000000000000000000000000000000000000000000000000062c579570000000000000000000000000000000000000000000000000000000062c6cad70000000000000000000000000000000000000000000000000000000062c81c570000000000000000000000000000000000000000000000000000000062c96dd7000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000037ab68221831882d92651230000000000000000000000000000000000000000037acf279350c7b21a1b3e0e0000000000000000000000000000000000000000037ae8000ae89417b47980cc0000000000000000000000000000000000000000037b00988ca655ec9c80324b0000000000000000000000000000000000000000037b1944621ee56622d530c80000000000000000000000000000000000000000037b32049eabab23ad74345d0000000000000000000000000000000000000000037b4aac553db56f59f782030000000000000000000000000000000000000000037b638d9222018783a9a72d0000000000000000000000000000000000000000037b7c54274ab06c05d3de430000000000000000000000000000000000000000037b95195b9426c36f9ee382
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061015f5760003560e01c80631195082e14610164578063163e9c4f146101a257806317221ef1146101b557806322ff6568146101c857806324b18b17146101e2578063252c09d71461021657806325f258dd1461025557806332148f6714610268578063357d7b5c1461027d57806341453528146102aa57806354124c64146102bd5780636f307dc3146102d0578063715018a6146102f75780637aa4db13146102ff5780637cf2cc9f146103075780638a6b8c5d146103105780638da5cb5b1461031857806391aa375d1461032057806393556dbd1461034257806399940ece14610355578063bdb050921461036a578063c330c98d1461037d578063c7db359b1461038c578063ddc7a5aa146103d4578063efdf5d8b146103dc578063f2fde38b146103e4578063f739670c146103f7578063f90ce5ba1461040a578063fe115fbe14610422575b600080fd5b61018f610172366004612a00565b600160209081526000928352604080842090915290825290205481565b6040519081526020015b60405180910390f35b61018f6101b0366004612a33565b61042a565b61018f6101c3366004612a33565b61043c565b6101d0600381565b60405160ff9091168152602001610199565b620100055462010006546101fa9163ffffffff169082565b6040805163ffffffff9093168352602083019190915201610199565b610229610224366004612a33565b610448565b6040805163ffffffff90941684526001600160d81b039092166020840152151590820152606001610199565b61018f610263366004612a4c565b610482565b61027b610276366004612a6e565b6104fd565b005b6201000854610292906001600160a01b031681565b6040516001600160a01b039091168152602001610199565b61018f6102b8366004612a4c565b610582565b61018f6102cb366004612a92565b610596565b6102927f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b61027b6105eb565b61027b61062f565b61018f60025481565b6101fa61067c565b6102926107f7565b610328610806565b6040805192835263ffffffff909116602083015201610199565b61018f610350366004612a4c565b610864565b6201000754610292906001600160a01b031681565b61027b610378366004612a33565b6108f4565b61018f670de0b6b3a764000081565b6003546103af9061ffff80821691620100008104821691600160201b9091041683565b6040805161ffff94851681529284166020840152921691810191909152606001610199565b61027b610968565b61018f610a55565b61027b6103f2366004612abe565b610add565b61018f610405366004612a4c565b610b7a565b620100035462010004546101fa9163ffffffff169082565b610328610c84565b60006104368242610b7a565b92915050565b60006104368242610864565b60048161ffff811061045957600080fd5b015463ffffffff81169150600160201b81046001600160d81b031690600160f81b900460ff1683565b60008061048f84846110ec565b909250905080156104f65760006104b4670de0b6b3a764000086046110a7565b6110a7565b905060006104cb670de0b6b3a764000086046110a7565b63ffffffff928316600090815260016020908152604080832095909316825293909352909120839055505b5092915050565b600354600160201b900461ffff1660006105196004838561122a565b6003805461ffff808416600160201b810261ffff60201b199093169290921790925591925083161461057d5760405161ffff821681527f8a96a9c4bca0fb28be0fc5c84e95aff121a64e2533021e9d638bdc1f03b14ece9060200160405180910390a15b505050565b600061058e83836110ec565b509392505050565b6000806105a28361131f565b905060006105b8670de0b6b3a764000086612afd565b905060006105c68284611336565b905060006105d382611375565b90506105df888261139f565b98975050505050505050565b336105f46107f7565b6001600160a01b0316146106235760405162461bcd60e51b815260040161061a90612b15565b60405180910390fd5b61062d60006113ad565b565b6003546106549061ffff80821691620100008104821691600160201b909104166113fd565b6003805463ffffffff19166201000061ffff9384160261ffff19161792909116919091179055565b6201000754604051630f451f7160e31b8152676765c793fa10079d601b1b6004820152600091829182916001600160a01b031690637a28fb889060240160206040518083038186803b1580156106d157600080fd5b505afa1580156106e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107099190612b4a565b90508061072c576040516001620723a560e01b0319815260040160405180910390fd5b6201000854604080516389896aef60e01b815290516000926001600160a01b0316916389896aef916004808301926020929190829003018186803b15801561077357600080fd5b505afa158015610787573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107ab9190612b4a565b62010009549091506000906107ec906107cd906001600160401b031684612b63565b62010008546104af9190600160a01b90046001600160401b0316612afd565b959294509192505050565b6000546001600160a01b031690565b6000804362010003600101541061083057505062010006546201000554909163ffffffff90911690565b620100045461083f9043612b82565b620100035463ffffffff16610852610e54565b61085c9190612b99565b915091509091565b6000818311156108a95760405162461bcd60e51b815260206004820152601060248201526f4d69736f72646572656420646174657360801b604482015260640161061a565b60006108b58484610b7a565b905060006108c38585612b82565b905060006108d0826115a0565b905060006108dd8261131f565b90506108e984826115ed565b979650505050505050565b336108fd6107f7565b6001600160a01b0316146109235760405162461bcd60e51b815260040161061a90612b15565b80600254146109655760028190556040518181527f88bd1242a1ad7dbba4967e0120324f17c382e4e3006e01dc3ffc0bf43e4b2a399060200160405180910390a15b50565b60008060006201000860009054906101000a90046001600160a01b03166001600160a01b031663e547c77c6040518163ffffffff1660e01b815260040160806040518083038186803b1580156109bd57600080fd5b505afa1580156109d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109f59190612bd5565b620100088054600160a01b600160e01b031916600160a01b6001600160401b0384160217905591955093509150610a2e90508284612c29565b6201000980546001600160401b0319166001600160401b0392909216919091179055505050565b6000806000610a6261067c565b91509150610a6e610e54565b63ffffffff168263ffffffff1610610a865792915050565b600080610a91610c84565b915091508063ffffffff168285610aa6610e54565b610ab09190612b99565b63ffffffff16610ac09190612b63565b610aca9190612c6e565b610ad49084612afd565b94505050505090565b33610ae66107f7565b6001600160a01b031614610b0c5760405162461bcd60e51b815260040161061a90612b15565b6001600160a01b038116610b715760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840161061a565b610965816113ad565b600081831115610bb85760405162461bcd60e51b815260206004820152600960248201526866726f6d203e20746f60b81b604482015260640161061a565b81831415610bc857506000610436565b6000610bd2610e54565b90506000610bdf856110a7565b90506000610bec856110a7565b600354909150600090610c10908590859061ffff8082169162010000900416611652565b600354909150600090610c34908690859061ffff8082169162010000900416611652565b905081811115610c76576000610c68676765c793fa10079d601b1b610c59848661189e565b610c639190612b82565b6118ac565b965061043695505050505050565b600095505050505050610436565b600354600090819061ffff16816001821015610cb857600354610cb39060019062010000900461ffff16612c82565b610ccb565b600354610ccb9060019061ffff16612c82565b60035490915060026201000090910461ffff1610801590610d0c575060048161ffff1661ffff8110610cff57610cff612c9d565b0154600160f81b900460ff165b8015610d69575060048261ffff1661ffff8110610d2b57610d2b612c9d565b0154600160201b90046001600160d81b0316600461ffff838116908110610d5457610d54612c9d565b0154600160201b90046001600160d81b031611155b610d9b5760405162461bcd60e51b815260206004820152600360248201526204e45560ec1b604482015260640161061a565b60048161ffff1661ffff8110610db357610db3612c9d565b0154600160201b90046001600160d81b0316600461ffff848116908110610ddc57610ddc612c9d565b0154610df89190600160201b90046001600160d81b0316612cb3565b6001600160d81b0316935060048161ffff1661ffff8110610e1b57610e1b612c9d565b015463ffffffff16600461ffff808516908110610e3a57610e3a612c9d565b0154610e4c919063ffffffff16612b99565b925050509091565b6000610e5f426110a7565b905090565b600080600061ffff855110610ea45760405162461bcd60e51b815260040161061a906020808252600490820152631350561560e21b604082015260600190565b8451845161ffff821614610eef5760405162461bcd60e51b8152602060048201526012602482015271098cadccee8d0e640daeae6e840dac2e8c6d60731b604482015260640161061a565b60008161ffff1611610f285760405162461bcd60e51b81526020600482015260026024820152610c1560f21b604482015260640161061a565b6000805b8261ffff168161ffff16101561108857878161ffff1681518110610f5257610f52612c9d565b602002602001015163ffffffff168263ffffffff1610610fa65760405162461bcd60e51b815260206004820152600f60248201526e1a5b9c1d5d081d5b9bdc99195c9959608a1b604482015260640161061a565b610fea888261ffff1681518110610fbf57610fbf612c9d565b6020026020010151888361ffff1681518110610fdd57610fdd612c9d565b6020026020010151611938565b898261ffff1661ffff811061100157611001612c9d565b82519101805460208401516040909401511515600160f81b026001600160f81b036001600160d81b03909516600160201b026001600160f81b031990921663ffffffff9094169390931717929092161790558751889061ffff831690811061106b5761106b612c9d565b60200260200101519150808061108090612cd3565b915050610f2c565b508180611096600182612c82565b945094509450505093509350939050565b8063ffffffff811681146110e75760405162461bcd60e51b815260206004820152600760248201526654534f464c4f5760c81b604482015260640161061a565b919050565b60008080611103670de0b6b3a764000086046110a7565b9050600061111a670de0b6b3a764000086046110a7565b905060008263ffffffff16118015611138575060008163ffffffff16115b61116c5760405162461bcd60e51b8152602060048201526005602482015264554e49545360d81b604482015260640161061a565b63ffffffff808316600090815260016020908152604080832093851683529290522054156111c25763ffffffff808316600090815260016020908152604080832093851683529290529081205494509250611221565b8063ffffffff166111d1610e54565b63ffffffff16106111fd576111f28263ffffffff168263ffffffff16610b7a565b935060019250611221565b61121a8263ffffffff1661120f610e54565b63ffffffff16610b7a565b9350600092505b50509250929050565b6000808361ffff16116112635760405162461bcd60e51b81526020600482015260016024820152604960f81b604482015260640161061a565b61ffff8261ffff16106112a75760405162461bcd60e51b815260206004820152600c60248201526b189d5999995c881b1a5b5a5d60a21b604482015260640161061a565b8261ffff168261ffff16116112bd575081611318565b825b8261ffff168161ffff161015611313576001858261ffff1661ffff81106112e8576112e8612c9d565b01805463ffffffff191663ffffffff929092169190911790558061130b81612cd3565b9150506112bf565b508190505b9392505050565b6000610436826a1a1601fc4ea7109e0000006119b0565b60008261135b57811561134a576000611354565b670de0b6b3a76400005b9050610436565b61131861137061136a856119c5565b84611a75565b611a81565b600080611395670de0b6b3a7640000676765c793fa10079d601b1b612c6e565b6113189084612b63565b600061131883836001611ac7565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080600060048661ffff1661ffff811061141a5761141a612c9d565b60408051606081018252929091015463ffffffff811683526001600160d81b03600160201b820416602084015260ff600160f81b90910416151590820152905060008061146561067c565b600254855192945090925061147f9163ffffffff16612afd565b8263ffffffff16101561149a57878794509450505050611598565b7f5aec68e6980e788266f2f59f6fddb85f3e256ce6da46fdfab920b9b06aaa73756114c3611b7a565b6040805191825230602083015261ffff8b81168383015263ffffffff86166060840152608083018590528a811660a0840152891660c0830152519081900360e00190a162010004546115159043612b82565b6201000655620100035463ffffffff1661152d610e54565b6115379190612b99565b62010005805463ffffffff191663ffffffff92909216919091179055436201000455611561610e54565b62010003805463ffffffff191663ffffffff928316179055611590906004908a90859085908c908c90611b8516565b945094505050505b935093915050565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218211156115df57604051633492ffd960e01b81526004810183905260240161061a565b50670de0b6b3a76400000290565b6000826115fc57506000610436565b600061161161160b60016115a0565b846119b0565b905060006116338561162360016115a0565b61162d9190612afd565b83611336565b905061163f60016115a0565b6116499082612b82565b95945050505050565b60008363ffffffff168563ffffffff16101561168157604051632ff198e560e21b815260040160405180910390fd5b8363ffffffff168563ffffffff1614156117295761169d6129cc565b60048461ffff1661ffff81106116b5576116b5612c9d565b60408051606081018252919092015463ffffffff808216808452600160201b83046001600160d81b03166020850152600160f81b90920460ff16151593830193909352909250908716146117125761170b610a55565b9150611723565b80602001516001600160d81b031691505b50611896565b6000611733610a55565b90506000806117476004888a868a8a611ccd565b91509150816000015163ffffffff168763ffffffff1614156117785781602001516001600160d81b03169350611892565b805163ffffffff8881169116141561179f5780602001516001600160d81b03169350611892565b600082602001516001600160d81b031682602001516001600160d81b0316111561180e576000676765c793fa10079d601b1b6117f584602001516001600160d81b031686602001516001600160d81b031661189e565b6117ff9190612b82565b905061180a816118ac565b9150505b8251825160009161184191670de0b6b3a76400009161182c91612b99565b63ffffffff1661183c9190612b63565b61131f565b9050600061184f83836115ed565b905061188c85602001516001600160d81b031682670de0b6b3a764000088600001518e61187c9190612b99565b63ffffffff166102cb9190612b63565b96505050505b5050505b949350505050565b600061131883836001611e7f565b6000806118cc670de0b6b3a7640000676765c793fa10079d601b1b612c6e565b6118d69084612c6e565b905060026118f7670de0b6b3a7640000676765c793fa10079d601b1b612c6e565b6119019190612c6e565b61191e670de0b6b3a7640000676765c793fa10079d601b1b612c6e565b6119289085612cf5565b1061043657611318600182612afd565b6119406129cc565b6001600160d81b038211156119805760405162461bcd60e51b815260040161061a906020808252600490820152631f19189b60e11b604082015260600190565b506040805160608101825263ffffffff9390931683526001600160d81b0391909116602083015260019082015290565b600061131883670de0b6b3a764000084611f1a565b6000670de0b6b3a76400008210156119f357604051633621413760e21b81526004810183905260240161061a565b6000611a08670de0b6b3a76400008404611fe8565b670de0b6b3a7640000808202935090915083821c90811415611a2b575050919050565b6706f05b59d3b200005b8015611a6d57670de0b6b3a7640000828002049150671bc16d674ec800008210611a65579283019260019190911c905b60011c611a35565b505050919050565b600061131883836120c6565b6000680a688906bd8b0000008210611aaf57604051634a4f26f160e01b81526004810183905260240161061a565b670de0b6b3a7640000604083901b0461131881612188565b6000831580611ad4575082155b15611ae157506000611318565b6001826001811115611af557611af5612d09565b14611b0857670de0b6b3a7640000611b15565b676765c793fa10079d601b1b5b6001836001811115611b2957611b29612d09565b14611b4657611b416002670de0b6b3a7640000612c6e565b611b5c565b611b5c6002676765c793fa10079d601b1b612c6e565b611b668587612b63565b611b709190612afd565b6118969190612c6e565b6000610e5f426115a0565b6000806000888861ffff1661ffff8110611ba157611ba1612c9d565b60408051606081018252919092015463ffffffff808216808452600160201b83046001600160d81b03166020850152600160f81b90920460ff161515938301939093529092509088161415611bfc5787859250925050611cc2565b8461ffff168461ffff16118015611c245750611c19600186612c82565b61ffff168861ffff16145b15611c3157839150611c35565b8491505b81611c41896001612d1f565b611c4b9190612d45565b9250611c578787611938565b898461ffff1661ffff8110611c6e57611c6e612c9d565b82519101805460208401516040909401511515600160f81b026001600160f81b036001600160d81b03909516600160201b026001600160f81b031990921663ffffffff909416939093171792909216179055505b965096945050505050565b611cd56129cc565b611cdd6129cc565b878461ffff1661ffff8110611cf457611cf4612c9d565b60408051606081018252919092015463ffffffff808216808452600160201b83046001600160d81b03166020850152600160f81b90920460ff1615159383019390935290935090881610611d73578663ffffffff16826000015163ffffffff161415611d5f57611cc2565b81611d6a8787611938565b91509150611cc2565b8783611d80866001612d1f565b611d8a9190612d45565b61ffff1661ffff8110611d9f57611d9f612c9d565b60408051606081018252919092015463ffffffff81168252600160201b81046001600160d81b03166020830152600160f81b900460ff1615159181018290529250611e245760408051606081018252895463ffffffff81168252600160201b81046001600160d81b03166020830152600160f81b900460ff1615159181019190915291505b815163ffffffff80891691161115611e645760405162461bcd60e51b815260206004820152600360248201526213d31160ea1b604482015260640161061a565b611e708888868661281a565b91509150965096945050505050565b600082611eb75760405162461bcd60e51b815260040161061a906020808252600490820152630444956360e41b604082015260600190565b6000611ec4600285612c6e565b905083816001856001811115611edc57611edc612d09565b14611eef57670de0b6b3a7640000611efc565b676765c793fa10079d601b1b5b611f069088612b63565b611f109190612afd565b6116499190612c6e565b600080806000198587098587029250828110838203039150508060001415611f5557838281611f4b57611f4b612c58565b0492505050611318565b838110611f7f57604051631dcf306360e21b8152600481018290526024810185905260440161061a565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6000600160801b821061200857608091821c916120059082612afd565b90505b600160401b821061202657604091821c916120239082612afd565b90505b600160201b821061204457602091821c916120419082612afd565b90505b62010000821061206157601091821c9161205e9082612afd565b90505b610100821061207d57600891821c9161207a9082612afd565b90505b6010821061209857600491821c916120959082612afd565b90505b600482106120b357600291821c916120b09082612afd565b90505b600282106110e757610436600182612afd565b60008080600019848609848602925082811083820303915050670de0b6b3a7640000811061210a5760405163698d9a0160e11b81526004810182905260240161061a565b600080670de0b6b3a76400008688099150506706f05b59d3b1ffff8111826121445780670de0b6b3a7640000850401945050505050610436565b620400008285030493909111909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690201905092915050565b600160bf1b6001603f1b8216156121a85768016a09e667f3bcc9090260401c5b6001603e1b8216156121c3576801306fe0a31b7152df0260401c5b6001603d1b8216156121de576801172b83c7d517adce0260401c5b6001603c1b8216156121f95768010b5586cf9890f62a0260401c5b6001603b1b821615612214576801059b0d31585743ae0260401c5b6001603a1b82161561222f57680102c9a3e778060ee70260401c5b600160391b82161561224a5768010163da9fb33356d80260401c5b600160381b82161561226557680100b1afa5abcbed610260401c5b600160371b8216156122805768010058c86da1c09ea20260401c5b600160361b82161561229b576801002c605e2e8cec500260401c5b600160351b8216156122b657680100162f3904051fa10260401c5b600160341b8216156122d1576801000b175effdc76ba0260401c5b600160331b8216156122ec57680100058ba01fb9f96d0260401c5b600160321b8216156123075768010002c5cc37da94920260401c5b600160311b821615612322576801000162e525ee05470260401c5b600160301b82161561233d5768010000b17255775c040260401c5b6001602f1b821615612358576801000058b91b5bc9ae0260401c5b6001602e1b82161561237357680100002c5c89d5ec6d0260401c5b6001602d1b82161561238e5768010000162e43f4f8310260401c5b6001602c1b8216156123a957680100000b1721bcfc9a0260401c5b6001602b1b8216156123c45768010000058b90cf1e6e0260401c5b6001602a1b8216156123df576801000002c5c863b73f0260401c5b600160291b8216156123fa57680100000162e430e5a20260401c5b600160281b821615612415576801000000b1721835510260401c5b600160271b82161561243057680100000058b90c0b490260401c5b600160261b82161561244b5768010000002c5c8601cc0260401c5b600160251b821615612466576801000000162e42fff00260401c5b600160241b8216156124815768010000000b17217fbb0260401c5b600160231b82161561249c576801000000058b90bfce0260401c5b600160221b8216156124b757680100000002c5c85fe30260401c5b600160211b8216156124d25768010000000162e42ff10260401c5b600160201b8216156124ed57680100000000b17217f80260401c5b63800000008216156125085768010000000058b90bfc0260401c5b6340000000821615612523576801000000002c5c85fe0260401c5b632000000082161561253e57680100000000162e42ff0260401c5b6310000000821615612559576801000000000b17217f0260401c5b630800000082161561257457680100000000058b90c00260401c5b630400000082161561258f5768010000000002c5c8600260401c5b63020000008216156125aa576801000000000162e4300260401c5b63010000008216156125c55768010000000000b172180260401c5b628000008216156125df576801000000000058b90c0260401c5b624000008216156125f957680100000000002c5c860260401c5b622000008216156126135768010000000000162e430260401c5b6210000082161561262d57680100000000000b17210260401c5b620800008216156126475768010000000000058b910260401c5b62040000821615612661576801000000000002c5c80260401c5b6202000082161561267b57680100000000000162e40260401c5b620100008216156126945761b172600160401b010260401c5b6180008216156126ac576158b9600160401b010260401c5b6140008216156126c457612c5d600160401b010260401c5b6120008216156126dc5761162e600160401b010260401c5b6110008216156126f457610b17600160401b010260401c5b61080082161561270c5761058c600160401b010260401c5b610400821615612724576102c6600160401b010260401c5b61020082161561273c57610163600160401b010260401c5b6101008216156127535760b1600160401b010260401c5b6080821615612769576059600160401b010260401c5b604082161561277f57602c600160401b010260401c5b6020821615612795576016600160401b010260401c5b60108216156127ab57600b600160401b010260401c5b60088216156127c1576006600160401b010260401c5b60048216156127d7576003600160401b010260401c5b60028216156127ed576001600160401b010260401c5b6001821615612803576001600160401b010260401c5b670de0b6b3a76400000260409190911c60bf031c90565b6128226129cc565b61282a6129cc565b600083612838866001612d1f565b6128429190612d45565b61ffff169050600060018561ffff168361285c9190612afd565b6128669190612b82565b905060005b60016128778385612afd565b901c90508861288a61ffff881683612cf5565b61ffff811061289b5761289b612c9d565b60408051606081018252919092015463ffffffff81168252600160201b81046001600160d81b03166020830152600160f81b900460ff16151591810182905295506128f2576128eb816001612afd565b925061286b565b8861ffff8716612903836001612afd565b61290d9190612cf5565b61ffff811061291e5761291e612c9d565b60408051606081018252919092015463ffffffff8082168352600160201b82046001600160d81b03166020840152600160f81b90910460ff161515928201929092528651909550898216911611801590819061298a5750846000015163ffffffff168963ffffffff1611155b1561299557506129c0565b806129ac576129a5600183612b82565b92506129ba565b6129b7826001612afd565b93505b5061286b565b50505094509492505050565b604080516060810182526000808252602082018190529181019190915290565b803563ffffffff811681146110e757600080fd5b60008060408385031215612a1357600080fd5b612a1c836129ec565b9150612a2a602084016129ec565b90509250929050565b600060208284031215612a4557600080fd5b5035919050565b60008060408385031215612a5f57600080fd5b50508035926020909101359150565b600060208284031215612a8057600080fd5b813561ffff8116811461131857600080fd5b600080600060608486031215612aa757600080fd5b505081359360208301359350604090920135919050565b600060208284031215612ad057600080fd5b81356001600160a01b038116811461131857600080fd5b634e487b7160e01b600052601160045260246000fd5b60008219821115612b1057612b10612ae7565b500190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600060208284031215612b5c57600080fd5b5051919050565b6000816000190483118215151615612b7d57612b7d612ae7565b500290565b600082821015612b9457612b94612ae7565b500390565b600063ffffffff83811690831681811015612bb657612bb6612ae7565b039392505050565b80516001600160401b03811681146110e757600080fd5b60008060008060808587031215612beb57600080fd5b612bf485612bbe565b9350612c0260208601612bbe565b9250612c1060408601612bbe565b9150612c1e60608601612bbe565b905092959194509250565b60006001600160401b0382811684821681151582840482111615612c4f57612c4f612ae7565b02949350505050565b634e487b7160e01b600052601260045260246000fd5b600082612c7d57612c7d612c58565b500490565b600061ffff83811690831681811015612bb657612bb6612ae7565b634e487b7160e01b600052603260045260246000fd5b60006001600160d81b0383811690831681811015612bb657612bb6612ae7565b600061ffff80831681811415612ceb57612ceb612ae7565b6001019392505050565b600082612d0457612d04612c58565b500690565b634e487b7160e01b600052602160045260246000fd5b600061ffff808316818516808303821115612d3c57612d3c612ae7565b01949350505050565b600061ffff80841680612d5a57612d5a612c58565b9216919091069291505056fea264697066735822122053ab365b0ad5f734fbf8bfc6cbb382acddecb97ed90761871f8aa5b2f080946e64736f6c63430008090033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe84000000000000000000000000442af784a788a5bd6f42a01ebe9f287a871243fb000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000062bd90570000000000000000000000000000000000000000000000000000000062bee1d70000000000000000000000000000000000000000000000000000000062c033570000000000000000000000000000000000000000000000000000000062c184d70000000000000000000000000000000000000000000000000000000062c2d6570000000000000000000000000000000000000000000000000000000062c427d70000000000000000000000000000000000000000000000000000000062c579570000000000000000000000000000000000000000000000000000000062c6cad70000000000000000000000000000000000000000000000000000000062c81c570000000000000000000000000000000000000000000000000000000062c96dd7000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000037ab68221831882d92651230000000000000000000000000000000000000000037acf279350c7b21a1b3e0e0000000000000000000000000000000000000000037ae8000ae89417b47980cc0000000000000000000000000000000000000000037b00988ca655ec9c80324b0000000000000000000000000000000000000000037b1944621ee56622d530c80000000000000000000000000000000000000000037b32049eabab23ad74345d0000000000000000000000000000000000000000037b4aac553db56f59f782030000000000000000000000000000000000000000037b638d9222018783a9a72d0000000000000000000000000000000000000000037b7c54274ab06c05d3de430000000000000000000000000000000000000000037b95195b9426c36f9ee382
-----Decoded View---------------
Arg [0] : _stEth (address): 0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84
Arg [1] : _lidoOracle (address): 0x442af784A788A5bd6F42A01Ebe9F287a871243fb
Arg [2] : _weth (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [3] : _times (uint32[]): 1656590423,1656676823,1656763223,1656849623,1656936023,1657022423,1657108823,1657195223,1657281623,1657368023
Arg [4] : _results (uint256[]): 1076805850648432598627799331,1076922239357196746188602894,1077039569267086687687246028,1077155719316616284685218379,1077272225887644039895134408,1077389108821174620494509149,1077505539378612583110509059,1077623031079333642872923949,1077740031078281916028542531,1077857005650125989376615298
-----Encoded View---------------
27 Constructor Arguments found :
Arg [0] : 000000000000000000000000ae7ab96520de3a18e5e111b5eaab095312d7fe84
Arg [1] : 000000000000000000000000442af784a788a5bd6f42a01ebe9f287a871243fb
Arg [2] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [3] : 00000000000000000000000000000000000000000000000000000000000000a0
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000200
Arg [5] : 000000000000000000000000000000000000000000000000000000000000000a
Arg [6] : 0000000000000000000000000000000000000000000000000000000062bd9057
Arg [7] : 0000000000000000000000000000000000000000000000000000000062bee1d7
Arg [8] : 0000000000000000000000000000000000000000000000000000000062c03357
Arg [9] : 0000000000000000000000000000000000000000000000000000000062c184d7
Arg [10] : 0000000000000000000000000000000000000000000000000000000062c2d657
Arg [11] : 0000000000000000000000000000000000000000000000000000000062c427d7
Arg [12] : 0000000000000000000000000000000000000000000000000000000062c57957
Arg [13] : 0000000000000000000000000000000000000000000000000000000062c6cad7
Arg [14] : 0000000000000000000000000000000000000000000000000000000062c81c57
Arg [15] : 0000000000000000000000000000000000000000000000000000000062c96dd7
Arg [16] : 000000000000000000000000000000000000000000000000000000000000000a
Arg [17] : 0000000000000000000000000000000000000000037ab68221831882d9265123
Arg [18] : 0000000000000000000000000000000000000000037acf279350c7b21a1b3e0e
Arg [19] : 0000000000000000000000000000000000000000037ae8000ae89417b47980cc
Arg [20] : 0000000000000000000000000000000000000000037b00988ca655ec9c80324b
Arg [21] : 0000000000000000000000000000000000000000037b1944621ee56622d530c8
Arg [22] : 0000000000000000000000000000000000000000037b32049eabab23ad74345d
Arg [23] : 0000000000000000000000000000000000000000037b4aac553db56f59f78203
Arg [24] : 0000000000000000000000000000000000000000037b638d9222018783a9a72d
Arg [25] : 0000000000000000000000000000000000000000037b7c54274ab06c05d3de43
Arg [26] : 0000000000000000000000000000000000000000037b95195b9426c36f9ee382
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 26 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.