Feature Tip: Add private address tag to any address under My Name Tag !
Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Source Code Verified (Exact Match)
Contract Name:
AutopoolETHStrategy
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 200 runs
Other Settings:
london EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { Roles } from "src/libs/Roles.sol"; import { ISystemRegistry } from "src/interfaces/ISystemRegistry.sol"; import { Initializable } from "openzeppelin-contracts/proxy/utils/Initializable.sol"; import { IDestinationVault } from "src/interfaces/vault/IDestinationVault.sol"; import { Errors } from "src/utils/Errors.sol"; import { IStrategy } from "src/interfaces/strategy/IStrategy.sol"; import { IAutopoolStrategy } from "src/interfaces/strategy/IAutopoolStrategy.sol"; import { IAutopool } from "src/interfaces/vault/IAutopool.sol"; import { SecurityBase } from "src/security/SecurityBase.sol"; import { IDexLSTStats } from "src/interfaces/stats/IDexLSTStats.sol"; import { ViolationTracking } from "src/strategy/ViolationTracking.sol"; import { NavTracking } from "src/strategy/NavTracking.sol"; import { IRootPriceOracle } from "src/interfaces/oracles/IRootPriceOracle.sol"; import { ILSTStats } from "src/interfaces/stats/ILSTStats.sol"; import { AutopoolETHStrategyConfig } from "src/strategy/AutopoolETHStrategyConfig.sol"; import { IERC20Metadata } from "openzeppelin-contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { Math } from "openzeppelin-contracts/utils/math/Math.sol"; import { AutopoolDebt } from "src/vault/libs/AutopoolDebt.sol"; import { ISystemComponent } from "src/interfaces/ISystemComponent.sol"; import { Initializable } from "openzeppelin-contracts/proxy/utils/Initializable.sol"; import { StrategyUtils } from "src/strategy/libs/StrategyUtils.sol"; import { SubSaturateMath } from "src/strategy/libs/SubSaturateMath.sol"; import { SummaryStats } from "src/strategy/libs/SummaryStats.sol"; import { SystemComponent } from "src/SystemComponent.sol"; import { Incentives } from "src/strategy/libs/Incentives.sol"; contract AutopoolETHStrategy is SystemComponent, Initializable, IAutopoolStrategy, SecurityBase { using ViolationTracking for ViolationTracking.State; using NavTracking for NavTracking.State; using SubSaturateMath for uint256; using SubSaturateMath for int256; using Math for uint256; /* ******************************** */ /* Immutable Config */ /* ******************************** */ /// @notice the number of days to pause rebalancing due to NAV decay uint16 public immutable pauseRebalancePeriodInDays; /// @notice the number of seconds gap between consecutive rebalances uint256 public immutable rebalanceTimeGapInSeconds; /// @notice destinations trading a premium above maxPremium will be blocked from new capital deployments int256 public immutable maxPremium; // 100% = 1e18 /// @notice destinations trading a discount above maxDiscount will be blocked from new capital deployments int256 public immutable maxDiscount; // 100% = 1e18 /// @notice the allowed staleness of stats data before a revert occurs uint40 public immutable staleDataToleranceInSeconds; /// @notice the swap cost offset period to initialize the strategy with uint16 public immutable swapCostOffsetInitInDays; /// @notice the number of violations required to trigger a tightening of the swap cost offset period (1 to 10) uint16 public immutable swapCostOffsetTightenThresholdInViolations; /// @notice the number of days to decrease the swap offset period for each tightening step uint16 public immutable swapCostOffsetTightenStepInDays; /// @notice the number of days since a rebalance required to trigger a relaxing of the swap cost offset period uint16 public immutable swapCostOffsetRelaxThresholdInDays; /// @notice the number of days to increase the swap offset period for each relaxing step uint16 public immutable swapCostOffsetRelaxStepInDays; // slither-disable-start similar-names /// @notice the maximum the swap cost offset period can reach. This is the loosest the strategy will be uint16 public immutable swapCostOffsetMaxInDays; /// @notice the minimum the swap cost offset period can reach. This is the most conservative the strategy will be uint16 public immutable swapCostOffsetMinInDays; /// @notice the number of days for the first NAV decay comparison (e.g., 30 days) uint8 public immutable navLookback1InDays; /// @notice the number of days for the second NAV decay comparison (e.g., 60 days) uint8 public immutable navLookback2InDays; /// @notice the number of days for the third NAV decay comparison (e.g., 90 days) uint8 public immutable navLookback3InDays; // slither-disable-end similar-names /// @notice the maximum slippage that is allowed for a normal rebalance uint256 public immutable maxNormalOperationSlippage; // 100% = 1e18 /// @notice the maximum amount of slippage to allow when a destination is trimmed due to constraint violations /// recommend setting this higher than maxNormalOperationSlippage uint256 public immutable maxTrimOperationSlippage; // 100% = 1e18 /// @notice the maximum amount of slippage to allow when a destinationVault has been shutdown /// shutdown for a vault is abnormal and means there is an issue at that destination /// recommend setting this higher than maxNormalOperationSlippage uint256 public immutable maxEmergencyOperationSlippage; // 100% = 1e18 /// @notice the maximum amount of slippage to allow when the AutopoolETH has been shutdown uint256 public immutable maxShutdownOperationSlippage; // 100% = 1e18 /// @notice the maximum discount used for price return int256 public immutable maxAllowedDiscount; // 18 precision /// @notice model weight used for LSTs base yield, 1e6 is the highest uint256 public immutable weightBase; /// @notice model weight used for DEX fee yield, 1e6 is the highest uint256 public immutable weightFee; /// @notice model weight used for incentive yield uint256 public immutable weightIncentive; /// @notice model weight used slashing costs uint256 public immutable weightSlashing; /// @notice model weight applied to an LST discount when exiting the position int256 public immutable weightPriceDiscountExit; /// @notice model weight applied to an LST discount when entering the position int256 public immutable weightPriceDiscountEnter; /// @notice model weight applied to an LST premium when entering or exiting the position int256 public immutable weightPricePremium; /// @notice initial value of the swap cost offset to use uint16 public immutable swapCostOffsetInit; uint256 public immutable defaultLstPriceGapTolerance; /* ******************************** */ /* State Variables */ /* ******************************** */ /// @notice model weight applied to an LST premium when entering or exiting the position uint256 public lstPriceGapTolerance; /// @notice Dust position portions /// @dev Value is determined as 1/f then truncated to a integer value, where f is a fractional value < 1.0. /// For ex. f = 0.02 means a position < 0.02 will be treated as a dust position uint256 public dustPositionPortions; /// @notice Idle Threshold Low /// @dev Fractional value < 1.0 represented in 18 decimals /// For ex. a value = 4e16 means 4% of total assets in the vault uint256 public idleLowThreshold; /// @notice Idle Threshold High /// @dev Fractional value < 1.0 represented in 18 decimals /// For ex. a value = 7e16 means 7% of total assets in the vault /// Low & high idle thresholds trigger different behaviors. When idle is less than low threshold, idle level must be /// brought up to high threshold. Any amount > high threshold is free to be deployed to destinations. When idle lies /// between low & high threshold, it does not trigger new idle to be added. uint256 public idleHighThreshold; /// @notice The AutopoolETH that this strategy is associated with IAutopool public autoPool; /// @notice The timestamp for when rebalancing was last paused uint40 public lastPausedTimestamp; /// @notice The last timestamp that a destination was added to mapping(address => uint40) public lastAddTimestampByDestination; /// @notice The last timestamp a rebalance was completed uint40 public lastRebalanceTimestamp; /// @notice Rebalance violation tracking state ViolationTracking.State public violationTrackingState; /// @notice NAV tracking state NavTracking.State public navTrackingState; uint16 private _swapCostOffsetPeriod; /* ******************************** */ /* Events */ /* ******************************** */ enum RebalanceToIdleReasonEnum { DestinationIsShutdown, AutopoolETHIsShutdown, TrimDustPosition, DestinationIsQueuedForRemoval, DestinationViolatedConstraint, ReplenishIdlePosition, UnknownReason } event RebalanceToIdleReason(RebalanceToIdleReasonEnum reason, uint256 maxSlippage, uint256 slippage); event DestTrimRebalanceDetails( uint256 assetIndex, uint256 numViolationsOne, uint256 numViolationsTwo, int256 discount ); event DestViolationMaxTrimAmount(uint256 trimAmount); event RebalanceToIdle( RebalanceValueStats valueStats, IStrategy.SummaryStats outSummary, IStrategy.RebalanceParams params ); event RebalanceBetweenDestinations( RebalanceValueStats valueStats, IStrategy.RebalanceParams params, IStrategy.SummaryStats outSummaryStats, IStrategy.SummaryStats inSummaryStats, uint256 swapOffsetPeriod, int256 predictedAnnualizedGain ); event SuccessfulRebalanceBetweenDestinations( address destinationOut, uint40 lastRebalanceTimestamp, uint40 lastTimestampAddedToDestination, uint40 swapCostOffsetPeriod ); event PauseStart(uint256 navPerShare, uint256 nav1, uint256 nav2, uint256 nav3); event PauseStop(); event LstPriceGapSet(uint256 newPriceGap); event DustPositionPortionSet(uint256 newValue); event IdleThresholdsSet(uint256 newLowValue, uint256 newHighValue); /* ******************************** */ /* Errors */ /* ******************************** */ error NotAutopoolETH(); error StrategyPaused(); error RebalanceTimeGapNotMet(); error RebalanceDestinationsMatch(); error RebalanceDestinationUnderlyerMismatch(address destination, address trueUnderlyer, address providedUnderlyer); error StaleData(string name); error SwapCostExceeded(); error MaxSlippageExceeded(); error MaxDiscountExceeded(); error MaxPremiumExceeded(); error OnlyRebalanceToIdleAvailable(); error InvalidRebalanceToIdle(); error CannotConvertUintToInt(); error InsufficientAssets(address asset); error SystemRegistryMismatch(); error UnregisteredDestination(address dest); error LSTPriceGapToleranceExceeded(); error InconsistentIdleThresholds(); error IdleHighThresholdViolated(); struct RebalanceValueStats { uint256 inPrice; uint256 outPrice; uint256 inEthValue; uint256 outEthValue; uint256 swapCost; uint256 slippage; } modifier onlyAutopool() { if (msg.sender != address(autoPool)) revert NotAutopoolETH(); _; } constructor( ISystemRegistry _systemRegistry, AutopoolETHStrategyConfig.StrategyConfig memory conf ) SystemComponent(_systemRegistry) SecurityBase(address(_systemRegistry.accessController())) { AutopoolETHStrategyConfig.validate(conf); rebalanceTimeGapInSeconds = conf.rebalanceTimeGapInSeconds; pauseRebalancePeriodInDays = conf.pauseRebalancePeriodInDays; maxPremium = conf.maxPremium; maxDiscount = conf.maxDiscount; staleDataToleranceInSeconds = conf.staleDataToleranceInSeconds; swapCostOffsetInitInDays = conf.swapCostOffset.initInDays; swapCostOffsetTightenThresholdInViolations = conf.swapCostOffset.tightenThresholdInViolations; swapCostOffsetTightenStepInDays = conf.swapCostOffset.tightenStepInDays; swapCostOffsetRelaxThresholdInDays = conf.swapCostOffset.relaxThresholdInDays; swapCostOffsetRelaxStepInDays = conf.swapCostOffset.relaxStepInDays; swapCostOffsetMaxInDays = conf.swapCostOffset.maxInDays; swapCostOffsetMinInDays = conf.swapCostOffset.minInDays; navLookback1InDays = conf.navLookback.lookback1InDays; navLookback2InDays = conf.navLookback.lookback2InDays; navLookback3InDays = conf.navLookback.lookback3InDays; maxNormalOperationSlippage = conf.slippage.maxNormalOperationSlippage; maxTrimOperationSlippage = conf.slippage.maxTrimOperationSlippage; maxEmergencyOperationSlippage = conf.slippage.maxEmergencyOperationSlippage; maxShutdownOperationSlippage = conf.slippage.maxShutdownOperationSlippage; maxAllowedDiscount = conf.maxAllowedDiscount; weightBase = conf.modelWeights.baseYield; weightFee = conf.modelWeights.feeYield; weightIncentive = conf.modelWeights.incentiveYield; weightSlashing = conf.modelWeights.slashing; weightPriceDiscountExit = conf.modelWeights.priceDiscountExit; weightPriceDiscountEnter = conf.modelWeights.priceDiscountEnter; weightPricePremium = conf.modelWeights.pricePremium; defaultLstPriceGapTolerance = conf.lstPriceGapTolerance; swapCostOffsetInit = conf.swapCostOffset.initInDays; _disableInitializers(); } function initialize(address _autoPool) external virtual initializer { _initialize(_autoPool); } function _initialize(address _autoPool) internal virtual { Errors.verifyNotZero(_autoPool, "_autoPool"); if (ISystemComponent(_autoPool).getSystemRegistry() != address(systemRegistry)) { revert SystemRegistryMismatch(); } autoPool = IAutopool(_autoPool); lastRebalanceTimestamp = uint40(block.timestamp) - uint40(rebalanceTimeGapInSeconds); _swapCostOffsetPeriod = swapCostOffsetInit; lstPriceGapTolerance = defaultLstPriceGapTolerance; dustPositionPortions = 50; idleLowThreshold = 0; idleHighThreshold = 0; } /// @notice Sets the LST price gap tolerance to the provided value function setLstPriceGapTolerance(uint256 priceGapTolerance) external hasRole(Roles.AUTO_POOL_MANAGER) { lstPriceGapTolerance = priceGapTolerance; emit LstPriceGapSet(priceGapTolerance); } /// @notice Sets the dust position portions to the provided value function setDustPositionPortions(uint256 newValue) external hasRole(Roles.AUTO_POOL_MANAGER) { dustPositionPortions = newValue; emit DustPositionPortionSet(newValue); } /// @notice Sets the Idle low/high threshold function setIdleThresholds(uint256 newLowValue, uint256 newHighValue) external hasRole(Roles.AUTO_POOL_MANAGER) { idleLowThreshold = newLowValue; idleHighThreshold = newHighValue; // Check for consistency in values i.e. low threshold should be strictly < high threshold if (((idleLowThreshold > 0 && idleHighThreshold > 0)) && (idleLowThreshold >= idleHighThreshold)) { revert InconsistentIdleThresholds(); } // Setting both thresholds to 0 allows no minimum requirement for idle if ((idleLowThreshold == 0 && idleHighThreshold != 0) || (idleLowThreshold != 0 && idleHighThreshold == 0)) { revert InconsistentIdleThresholds(); } emit IdleThresholdsSet(newLowValue, newHighValue); } /// @inheritdoc IAutopoolStrategy function verifyRebalance( IStrategy.RebalanceParams memory params, IStrategy.SummaryStats memory outSummary ) external returns (bool success, string memory message) { RebalanceValueStats memory valueStats = getRebalanceValueStats(params); // moves from a destination back to eth only happen under specific scenarios // if the move is valid, the constraints are different than if assets are moving to a normal destination if (params.destinationIn == address(autoPool)) { verifyRebalanceToIdle(params, valueStats.slippage); // slither-disable-next-line reentrancy-events emit RebalanceToIdle(valueStats, outSummary, params); // exit early b/c the remaining constraints only apply when moving to a normal destination return (true, ""); } // rebalances back to idle are allowed even when a strategy is paused // all other rebalances should be blocked in a paused state ensureNotPaused(); // Ensure enough time has passed between rebalances if ((uint40(block.timestamp) - lastRebalanceTimestamp) < rebalanceTimeGapInSeconds) { revert RebalanceTimeGapNotMet(); } // ensure that we're not exceeding top-level max slippage if (valueStats.slippage > maxNormalOperationSlippage) { revert MaxSlippageExceeded(); } // ensure that idle is not depleted below the high threshold if we are pulling from Idle assets // totalAssets will be reduced by swap cost amount. if (params.destinationOut == address(autoPool)) { uint256 totalAssets = autoPool.totalAssets().subSaturate(valueStats.swapCost); if (autoPool.getAssetBreakdown().totalIdle < valueStats.outEthValue) { revert IdleHighThresholdViolated(); } else if ( (autoPool.getAssetBreakdown().totalIdle - valueStats.outEthValue) < ((totalAssets * idleHighThreshold) / 1e18) ) { revert IdleHighThresholdViolated(); } } IStrategy.SummaryStats memory inSummary = getRebalanceInSummaryStats(params); // ensure that the destination that is being added to doesn't exceed top-level premium/discount constraints if (inSummary.maxDiscount > maxDiscount) revert MaxDiscountExceeded(); if (-inSummary.maxPremium > maxPremium) revert MaxPremiumExceeded(); uint256 swapOffsetPeriod = swapCostOffsetPeriodInDays(); // if the swap is only moving lp tokens from one destination to another // make the swap offset period more conservative b/c the gas costs/complexity is lower // Discard the fractional part resulting from div by 2 to be conservative if (params.tokenIn == params.tokenOut) { swapOffsetPeriod = swapOffsetPeriod / 2; } // slither-disable-start divide-before-multiply // equation is `compositeReturn * ethValue` / 1e18, which is multiply before divide // compositeReturn and ethValue are both 1e18 precision int256 predictedAnnualizedGain = ( inSummary.compositeReturn * StrategyUtils.convertUintToInt(valueStats.inEthValue) ).subSaturate(outSummary.compositeReturn * StrategyUtils.convertUintToInt(valueStats.outEthValue)) / 1e18; // slither-disable-end divide-before-multiply int256 predictedGainAtOffsetEnd = (predictedAnnualizedGain * StrategyUtils.convertUintToInt(swapOffsetPeriod) / 365); // if the predicted gain in Eth by the end of the swap offset period is less than // the swap cost then revert b/c the vault will not offset slippage in sufficient time // slither-disable-next-line timestamp if (predictedGainAtOffsetEnd <= StrategyUtils.convertUintToInt(valueStats.swapCost)) revert SwapCostExceeded(); // slither-disable-next-line reentrancy-events emit RebalanceBetweenDestinations( valueStats, params, outSummary, inSummary, swapOffsetPeriod, predictedAnnualizedGain ); return (true, ""); } function expiredRewardTolerance() external pure returns (uint256) { return Incentives.EXPIRED_REWARD_TOLERANCE; } /// @notice Returns stats for a given destination /// @dev Used to evaluate the current state of the destinations and decide best action /// @param destAddress Destination address. Can be a DestinationVault or the AutoPool /// @param direction Direction to evaluate the stats at /// @param amount Amount to evaluate the stats at function getDestinationSummaryStats( address destAddress, IAutopoolStrategy.RebalanceDirection direction, uint256 amount ) external returns (IStrategy.SummaryStats memory) { address token = destAddress == address(autoPool) ? autoPool.asset() : IDestinationVault(destAddress).underlying(); uint256 outPrice = _getInOutTokenPriceInEth(token, destAddress); return SummaryStats.getDestinationSummaryStats( autoPool, systemRegistry.incentivePricing(), destAddress, outPrice, direction, amount ); } function validateRebalanceParams(IStrategy.RebalanceParams memory params) internal view { Errors.verifyNotZero(params.destinationIn, "destinationIn"); Errors.verifyNotZero(params.destinationOut, "destinationOut"); Errors.verifyNotZero(params.tokenIn, "tokenIn"); Errors.verifyNotZero(params.tokenOut, "tokenOut"); Errors.verifyNotZero(params.amountIn, "amountIn"); Errors.verifyNotZero(params.amountOut, "amountOut"); ensureDestinationRegistered(params.destinationIn); ensureDestinationRegistered(params.destinationOut); // when a vault is shutdown, rebalancing can only pull assets from destinations back to the vault if (autoPool.isShutdown() && params.destinationIn != address(autoPool)) revert OnlyRebalanceToIdleAvailable(); if (params.destinationIn == params.destinationOut) revert RebalanceDestinationsMatch(); address baseAsset = autoPool.asset(); // if the in/out destination is the AutopoolETH then the in/out token must be the baseAsset // if the in/out is not the AutopoolETH then the in/out token must match the destinations underlying token if (params.destinationIn == address(autoPool)) { if (params.tokenIn != baseAsset) { revert RebalanceDestinationUnderlyerMismatch(params.destinationIn, params.tokenIn, baseAsset); } } else { IDestinationVault inDest = IDestinationVault(params.destinationIn); if (params.tokenIn != inDest.underlying()) { revert RebalanceDestinationUnderlyerMismatch(params.destinationIn, inDest.underlying(), params.tokenIn); } } if (params.destinationOut == address(autoPool)) { if (params.tokenOut != baseAsset) { revert RebalanceDestinationUnderlyerMismatch(params.destinationOut, params.tokenOut, baseAsset); } if (params.amountOut > autoPool.getAssetBreakdown().totalIdle) { revert InsufficientAssets(params.tokenOut); } } else { IDestinationVault outDest = IDestinationVault(params.destinationOut); if (params.tokenOut != outDest.underlying()) { revert RebalanceDestinationUnderlyerMismatch( params.destinationOut, outDest.underlying(), params.tokenOut ); } if (params.amountOut > outDest.balanceOf(address(autoPool))) { revert InsufficientAssets(params.tokenOut); } } } function ensureDestinationRegistered(address dest) private view { if (dest == address(autoPool)) return; if (!(autoPool.isDestinationRegistered(dest) || autoPool.isDestinationQueuedForRemoval(dest))) { revert UnregisteredDestination(dest); } } function getRebalanceValueStats(IStrategy.RebalanceParams memory params) internal returns (RebalanceValueStats memory) { uint8 tokenOutDecimals = IERC20Metadata(params.tokenOut).decimals(); uint8 tokenInDecimals = IERC20Metadata(params.tokenIn).decimals(); address autoPoolAddress = address(autoPool); // Prices are all in terms of the base asset, so when its a rebalance back to the vault // or out of the vault, We can just take things as 1:1 // Get the price of one unit of the underlying lp token, the params.tokenOut/tokenIn // Prices are calculated using the spot of price of the constituent tokens // validated to be within a tolerance of the safe price of those tokens uint256 outPrice = params.destinationOut != autoPoolAddress ? IDestinationVault(params.destinationOut).getValidatedSpotPrice() : 10 ** tokenOutDecimals; uint256 inPrice = params.destinationIn != autoPoolAddress ? IDestinationVault(params.destinationIn).getValidatedSpotPrice() : 10 ** tokenInDecimals; // prices are 1e18 and we want values in 1e18, so divide by token decimals uint256 outEthValue = params.destinationOut != autoPoolAddress ? outPrice * params.amountOut / 10 ** tokenOutDecimals : params.amountOut; // amountIn is a minimum to receive, but it is OK if we receive more uint256 inEthValue = params.destinationIn != autoPoolAddress ? inPrice * params.amountIn / 10 ** tokenInDecimals : params.amountIn; uint256 swapCost = outEthValue.subSaturate(inEthValue); uint256 slippage = outEthValue == 0 ? 0 : swapCost * 1e18 / outEthValue; return RebalanceValueStats({ inPrice: inPrice, outPrice: outPrice, inEthValue: inEthValue, outEthValue: outEthValue, swapCost: swapCost, slippage: slippage }); } function verifyRebalanceToIdle(IStrategy.RebalanceParams memory params, uint256 slippage) internal { IDestinationVault outDest = IDestinationVault(params.destinationOut); // multiple scenarios can be active at a given time. We want to use the highest // slippage among the active scenarios. uint256 maxSlippage = 0; RebalanceToIdleReasonEnum reason = RebalanceToIdleReasonEnum.UnknownReason; // Scenario 1: the destination has been shutdown -- done when a fast exit is required if (outDest.isShutdown()) { reason = RebalanceToIdleReasonEnum.DestinationIsShutdown; maxSlippage = maxEmergencyOperationSlippage; } // Scenario 2: the AutopoolETH has been shutdown if (autoPool.isShutdown() && maxShutdownOperationSlippage > maxSlippage) { reason = RebalanceToIdleReasonEnum.AutopoolETHIsShutdown; maxSlippage = maxShutdownOperationSlippage; } // Scenario 3: Replenishing Idle requires trimming destination if (verifyIdleUpOperation(params) && maxNormalOperationSlippage > maxSlippage) { reason = RebalanceToIdleReasonEnum.ReplenishIdlePosition; maxSlippage = maxNormalOperationSlippage; } // Scenario 4: position is a dust position and should be trimmed if (verifyCleanUpOperation(params) && maxNormalOperationSlippage > maxSlippage) { reason = RebalanceToIdleReasonEnum.TrimDustPosition; maxSlippage = maxNormalOperationSlippage; } // Scenario 5: the destination has been moved out of the Autopools active destinations if (autoPool.isDestinationQueuedForRemoval(params.destinationOut) && maxNormalOperationSlippage > maxSlippage) { reason = RebalanceToIdleReasonEnum.DestinationIsQueuedForRemoval; maxSlippage = maxNormalOperationSlippage; } // Scenario 6: the destination needs to be trimmed because it violated a constraint if (maxTrimOperationSlippage > maxSlippage) { reason = RebalanceToIdleReasonEnum.DestinationViolatedConstraint; uint256 trimAmount = getDestinationTrimAmount(outDest); // this is expensive, can it be refactored? if (trimAmount < 1e18 && verifyTrimOperation(params, trimAmount)) { maxSlippage = maxTrimOperationSlippage; } // slither-disable-next-line reentrancy-events emit DestViolationMaxTrimAmount(trimAmount); } // slither-disable-next-line reentrancy-events emit RebalanceToIdleReason(reason, maxSlippage, slippage); // if none of the scenarios are active then this rebalance is invalid if (maxSlippage == 0) revert InvalidRebalanceToIdle(); if (slippage > maxSlippage) revert MaxSlippageExceeded(); } function verifyCleanUpOperation(IStrategy.RebalanceParams memory params) internal view returns (bool) { IDestinationVault outDest = IDestinationVault(params.destinationOut); AutopoolDebt.DestinationInfo memory destInfo = autoPool.getDestinationInfo(params.destinationOut); // revert if information is too old ensureNotStaleData("DestInfo", destInfo.lastReport); // shares of the destination currently held by the AutopoolETH uint256 currentShares = outDest.balanceOf(address(autoPool)); // withdrawals reduce totalAssets, but do not update the destinationInfo // adjust the current debt based on the currently owned shares uint256 currentDebt = destInfo.ownedShares == 0 ? 0 : destInfo.cachedDebtValue * currentShares / destInfo.ownedShares; // If the current position is the minimum portion, trim to idle is allowed // slither-disable-next-line divide-before-multiply if ((currentDebt * 1e18) < ((autoPool.totalAssets() * 1e18) / dustPositionPortions)) { return true; } return false; } function verifyIdleUpOperation(IStrategy.RebalanceParams memory params) internal view returns (bool) { AutopoolDebt.DestinationInfo memory destInfo = autoPool.getDestinationInfo(params.destinationOut); // revert if information is too old ensureNotStaleData("DestInfo", destInfo.lastReport); uint256 currentIdle = autoPool.getAssetBreakdown().totalIdle; uint256 newIdle = currentIdle + params.amountIn; uint256 totalAssets = autoPool.totalAssets(); // If idle is below low threshold, then allow replinishing Idle. New idle after rebalance should be above high // threshold. While totalAssets after this rebalance will be lower by swap loss, the ratio idle / total assets // as used is conservative. // Idle thresholds (both low & high) use 18 decimals // slither-disable-next-line divide-before-multiply if ((currentIdle * 1e18) / totalAssets < idleLowThreshold) { // Allow small margin to exceed high threshold to avoid precision issues & pricing differences if ((newIdle * 1e18) / totalAssets < idleHighThreshold + 1e16) { return true; } } return false; } function verifyTrimOperation(IStrategy.RebalanceParams memory params, uint256 trimAmount) internal returns (bool) { // if the position can be trimmed to zero, then no checks are necessary if (trimAmount == 0) { return true; } IDestinationVault outDest = IDestinationVault(params.destinationOut); AutopoolDebt.DestinationInfo memory destInfo = autoPool.getDestinationInfo(params.destinationOut); // revert if information is too old ensureNotStaleData("DestInfo", destInfo.lastReport); // shares of the destination currently held by the AutopoolETH uint256 currentShares = outDest.balanceOf(address(autoPool)); // withdrawals reduce totalAssets, but do not update the destinationInfo // adjust the current debt based on the currently owned shares uint256 currentDebt = destInfo.ownedShares == 0 ? 0 : destInfo.cachedDebtValue * currentShares / destInfo.ownedShares; // prior validation ensures that currentShares >= amountOut uint256 sharesAfterRebalance = currentShares - params.amountOut; // current value of the destination shares, not cached from debt reporting uint256 destValueAfterRebalance = outDest.debtValue(sharesAfterRebalance); // calculate the total value of the autoPool after the rebalance is made // note that only the out destination value is adjusted to current // amountIn is a minimum to receive, but it is OK if we receive more uint256 autoPoolAssetsAfterRebalance = (autoPool.totalAssets() + params.amountIn + destValueAfterRebalance - currentDebt); // trimming may occur over multiple rebalances, so we only want to ensure we aren't removing too much if (autoPoolAssetsAfterRebalance > 0) { return destValueAfterRebalance * 1e18 / autoPoolAssetsAfterRebalance >= trimAmount; } else { // Autopool assets after rebalance are 0 return true; } } function getDestinationTrimAmount(IDestinationVault dest) internal returns (uint256) { uint256 discountThresholdOne = 3e5; // 3% 1e7 precision, discount required to consider trimming uint256 discountDaysThreshold = 7; // number of last 10 days that it was >= discountThreshold uint256 discountThresholdTwo = 5e5; // 5% 1e7 precision, discount required to completely exit // this is always the out destination and guaranteed not to be the AutopoolETH idle asset IDexLSTStats.DexLSTStatsData memory stats = dest.getStats().current(); ILSTStats.LSTStatsData[] memory lstStats = stats.lstStatsData; uint256 numLsts = lstStats.length; uint256 minTrim = 1e18; // 100% -- no trim required for (uint256 i = 0; i < numLsts; ++i) { ILSTStats.LSTStatsData memory targetLst = lstStats[i]; (uint256 numViolationsOne, uint256 numViolationsTwo) = getDiscountAboveThreshold(targetLst.discountHistory, discountThresholdOne, discountThresholdTwo); // slither-disable-next-line reentrancy-events emit DestTrimRebalanceDetails(i, numViolationsOne, numViolationsTwo, targetLst.discount); if (targetLst.discount >= int256(discountThresholdTwo * 1e11) && numViolationsTwo >= discountDaysThreshold) { // this is the worst possible trim, so we can exit without checking other LSTs return 0; } // discountThreshold is 1e7 precision for the discount history, but here it is compared to a 1e18, so pad it if (targetLst.discount >= int256(discountThresholdOne * 1e11) && numViolationsOne >= discountDaysThreshold) { minTrim = minTrim.min(1e17); // 10% } } return minTrim; } function getDiscountAboveThreshold( uint24[10] memory discountHistory, uint256 threshold1, uint256 threshold2 ) internal pure returns (uint256 count1, uint256 count2) { count1 = 0; count2 = 0; uint256 len = discountHistory.length; for (uint256 i = 0; i < len; ++i) { if (discountHistory[i] >= threshold1) { count1 += 1; } if (discountHistory[i] >= threshold2) { count2 += 1; } } } /// @inheritdoc IAutopoolStrategy function getRebalanceOutSummaryStats(IStrategy.RebalanceParams memory rebalanceParams) external returns (IStrategy.SummaryStats memory outSummary) { validateRebalanceParams(rebalanceParams); // Verify spot & safe price for the individual tokens in the pool are not far apart. // Call to verify before remove/add liquidity to the dest in the rebalance txn // if the in dest is not the Autopool i.e. this is not a rebalance to idle txn, verify price tolerance if (rebalanceParams.destinationIn != address(autoPool)) { if (!SummaryStats.verifyLSTPriceGap(autoPool, rebalanceParams, lstPriceGapTolerance)) { revert LSTPriceGapToleranceExceeded(); } } outSummary = _getRebalanceOutSummaryStats(rebalanceParams); } function _getRebalanceOutSummaryStats(IStrategy.RebalanceParams memory rebalanceParams) internal virtual returns (IStrategy.SummaryStats memory outSummary) { // Use safe price uint256 outPrice = _getInOutTokenPriceInEth(rebalanceParams.tokenOut, rebalanceParams.destinationOut); outSummary = ( SummaryStats.getDestinationSummaryStats( autoPool, systemRegistry.incentivePricing(), rebalanceParams.destinationOut, outPrice, RebalanceDirection.Out, rebalanceParams.amountOut ) ); } /// @dev Price the tokens from rebalance params with the appropriate method function _getInOutTokenPriceInEth(address token, address destination) private returns (uint256) { IRootPriceOracle pricer = systemRegistry.rootPriceOracle(); if (destination == address(autoPool)) { // When the destination is the autoPool then the token is the underlying asset // which means its not an LP token so we use this pricing fn return pricer.getPriceInEth(token); } else { // Otherwise we know its a real destination and so we can get the price directly from there return IDestinationVault(destination).getValidatedSafePrice(); } } // Summary stats for destination In function getRebalanceInSummaryStats(IStrategy.RebalanceParams memory rebalanceParams) internal virtual returns (IStrategy.SummaryStats memory inSummary) { // Use safe price uint256 inPrice = _getInOutTokenPriceInEth(rebalanceParams.tokenIn, rebalanceParams.destinationIn); inSummary = ( SummaryStats.getDestinationSummaryStats( autoPool, systemRegistry.incentivePricing(), rebalanceParams.destinationIn, inPrice, RebalanceDirection.In, rebalanceParams.amountIn ) ); } /// @inheritdoc IAutopoolStrategy function navUpdate(uint256 navPerShare) external onlyAutopool { uint40 blockTime = uint40(block.timestamp); navTrackingState.insert(navPerShare, blockTime); clearExpiredPause(); // check if the strategy needs to be paused due to NAV decay // the check only happens after there are enough data points // skip the check if the strategy is already paused // slither-disable-next-line timestamp if (navTrackingState.len > navLookback3InDays && !paused()) { uint256 nav1 = navTrackingState.getDaysAgo(navLookback1InDays); uint256 nav2 = navTrackingState.getDaysAgo(navLookback2InDays); uint256 nav3 = navTrackingState.getDaysAgo(navLookback3InDays); if (navPerShare < nav1 && navPerShare < nav2 && navPerShare < nav3) { lastPausedTimestamp = blockTime; emit PauseStart(navPerShare, nav1, nav2, nav3); } } } /// @inheritdoc IAutopoolStrategy function rebalanceSuccessfullyExecuted(IStrategy.RebalanceParams memory params) external onlyAutopool { // clearExpirePause sets _swapCostOffsetPeriod, so skip when possible to avoid double write if (!clearExpiredPause()) _swapCostOffsetPeriod = swapCostOffsetPeriodInDays(); address autoPoolAddress = address(autoPool); // update the destination that had assets added // moves into idle are not tracked for violations if (params.destinationIn != autoPoolAddress) { // Update to lastRebalanceTimestamp excludes rebalances to idle as those skip swapCostOffset logic lastRebalanceTimestamp = uint40(block.timestamp); lastAddTimestampByDestination[params.destinationIn] = lastRebalanceTimestamp; } // violations are only tracked when moving between non-idle assets if (params.destinationOut != autoPoolAddress && params.destinationIn != autoPoolAddress) { uint40 lastAddForRemoveDestination = lastAddTimestampByDestination[params.destinationOut]; uint40 swapCostOffsetPeriod = uint40(swapCostOffsetPeriodInDays()); if ( // slither-disable-start timestamp lastRebalanceTimestamp - lastAddForRemoveDestination < swapCostOffsetPeriod * 1 days ) { // slither-disable-end timestamp violationTrackingState.insert(true); } else { violationTrackingState.insert(false); } emit SuccessfulRebalanceBetweenDestinations( params.destinationOut, lastRebalanceTimestamp, lastAddForRemoveDestination, swapCostOffsetPeriod ); } // tighten if X of the last 10 rebalances were violations if ( violationTrackingState.len == 10 && violationTrackingState.violationCount >= swapCostOffsetTightenThresholdInViolations ) { tightenSwapCostOffset(); violationTrackingState.reset(); } } function swapCostOffsetPeriodInDays() public view returns (uint16) { // if the system is in an expired pause state then ensure that swap cost offset // is set to the most conservative value (shortest number of days) if (expiredPauseState()) { return swapCostOffsetMinInDays; } // truncation is desirable because we only want the number of times it has exceeded the threshold // slither-disable-next-line divide-before-multiply uint40 numRelaxPeriods = swapCostOffsetRelaxThresholdInDays == 0 ? 0 : (uint40(block.timestamp) - lastRebalanceTimestamp) / 1 days / uint40(swapCostOffsetRelaxThresholdInDays); uint40 relaxDays = numRelaxPeriods * uint40(swapCostOffsetRelaxStepInDays); uint40 newSwapCostOffset = uint40(_swapCostOffsetPeriod) + relaxDays; // slither-disable-next-line timestamp if (newSwapCostOffset > swapCostOffsetMaxInDays) { return swapCostOffsetMaxInDays; } return uint16(newSwapCostOffset); } function tightenSwapCostOffset() internal { uint16 currentSwapOffset = swapCostOffsetPeriodInDays(); uint16 newSwapCostOffset = 0; if (currentSwapOffset > swapCostOffsetTightenStepInDays) { newSwapCostOffset = currentSwapOffset - swapCostOffsetTightenStepInDays; } // slither-disable-next-line timestamp if (newSwapCostOffset < swapCostOffsetMinInDays) { _swapCostOffsetPeriod = swapCostOffsetMinInDays; } else { _swapCostOffsetPeriod = newSwapCostOffset; } } function paused() public view returns (bool) { // slither-disable-next-line incorrect-equality,timestamp if (lastPausedTimestamp == 0) return false; uint40 pauseRebalanceInSeconds = uint40(pauseRebalancePeriodInDays) * 1 days; // slither-disable-next-line timestamp return uint40(block.timestamp) - lastPausedTimestamp <= pauseRebalanceInSeconds; } function ensureNotPaused() internal view { if (paused()) revert StrategyPaused(); } function expiredPauseState() internal view returns (bool) { // slither-disable-next-line timestamp return lastPausedTimestamp > 0 && !paused(); } function clearExpiredPause() internal returns (bool) { if (!expiredPauseState()) return false; lastPausedTimestamp = 0; emit PauseStop(); _swapCostOffsetPeriod = swapCostOffsetMinInDays; return true; } function ensureNotStaleData(string memory name, uint256 dataTimestamp) internal view { // slither-disable-next-line timestamp if (block.timestamp - dataTimestamp > staleDataToleranceInSeconds) revert StaleData(name); } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; library Roles { // -------------------------------------------------------------------- // Central roles list used by all contracts that call AccessController // -------------------------------------------------------------------- // TODO: Update the hash values to match the variable names for new deployments. // Naming Conventions: // - Use MANAGER, CREATOR, UPDATER, ..., for roles primarily managing on-chain activities. // - Use EXECUTOR for roles that trigger off-chain initiated actions. // - Group roles by functional area for clarity. // -------------------------------------------------------------------- // Destination Vault Management bytes32 public constant DESTINATION_VAULT_FACTORY_MANAGER = keccak256("CREATE_DESTINATION_VAULT_ROLE"); bytes32 public constant DESTINATION_VAULT_REGISTRY_MANAGER = keccak256("DESTINATION_VAULT_REGISTRY_MANAGER"); bytes32 public constant DESTINATION_VAULT_MANAGER = keccak256("DESTINATION_VAULT_MANAGER"); // Auto Pool Factory and Registry Management bytes32 public constant AUTO_POOL_REGISTRY_UPDATER = keccak256("REGISTRY_UPDATER"); bytes32 public constant AUTO_POOL_FACTORY_MANAGER = 0x00; // keccak256("LMP_VAULT_FACTORY_MANAGER"); bytes32 public constant AUTO_POOL_FACTORY_VAULT_CREATOR = keccak256("CREATE_POOL_ROLE"); // Auto Pool Management bytes32 public constant AUTO_POOL_DESTINATION_UPDATER = keccak256("DESTINATION_VAULTS_UPDATER"); bytes32 public constant AUTO_POOL_FEE_UPDATER = keccak256("AUTO_POOL_FEE_SETTER_ROLE"); bytes32 public constant AUTO_POOL_PERIODIC_FEE_UPDATER = keccak256("AUTO_POOL_PERIODIC_FEE_SETTER_ROLE"); bytes32 public constant AUTO_POOL_REWARD_MANAGER = keccak256("AUTO_POOL_REWARD_MANAGER_ROLE"); bytes32 public constant AUTO_POOL_MANAGER = keccak256("AUTO_POOL_ADMIN"); bytes32 public constant REBALANCER = keccak256("REBALANCER_ROLE"); // Reward Management bytes32 public constant LIQUIDATOR_MANAGER = keccak256("LIQUIDATOR_ROLE"); bytes32 public constant DV_REWARD_MANAGER = keccak256("DV_REWARD_MANAGER_ROLE"); bytes32 public constant REWARD_LIQUIDATION_MANAGER = keccak256("REWARD_LIQUIDATION_MANAGER"); bytes32 public constant EXTRA_REWARD_MANAGER = keccak256("EXTRA_REWARD_MANAGER_ROLE"); bytes32 public constant REWARD_LIQUIDATION_EXECUTOR = keccak256("REWARD_LIQUIDATION_EXECUTOR"); // Statistics and Reporting bytes32 public constant STATS_CALC_REGISTRY_MANAGER = 0x00; // keccak256("STATS_CALC_REGISTRY_MANAGER"); bytes32 public constant STATS_CALC_FACTORY_MANAGER = keccak256("CREATE_STATS_CALC_ROLE"); bytes32 public constant STATS_CALC_FACTORY_TEMPLATE_MANAGER = keccak256("STATS_CALC_TEMPLATE_MGMT_ROLE"); bytes32 public constant STATS_SNAPSHOT_EXECUTOR = keccak256("STATS_SNAPSHOT_ROLE"); bytes32 public constant STATS_INCENTIVE_TOKEN_UPDATER = keccak256("STATS_INCENTIVE_TOKEN_UPDATER"); bytes32 public constant STATS_GENERAL_MANAGER = keccak256("STATS_GENERAL_MANAGER"); // Emergency Management bytes32 public constant EMERGENCY_PAUSER = keccak256("EMERGENCY_PAUSER"); // Miscellaneous Roles bytes32 public constant SOLVER = keccak256("SOLVER_ROLE"); bytes32 public constant AUTO_POOL_REPORTING_EXECUTOR = keccak256("AUTO_POOL_UPDATE_DEBT_REPORTING_ROLE"); // Swapper Roles bytes32 public constant SWAP_ROUTER_MANAGER = 0x00; // keccak256("SWAP_ROUTER_MANAGER"); // Price Oracles Roles bytes32 public constant ORACLE_MANAGER = keccak256("ORACLE_MANAGER_ROLE"); bytes32 public constant CUSTOM_ORACLE_EXECUTOR = keccak256("CUSTOM_ORACLE_EXECUTOR"); bytes32 public constant MAVERICK_FEE_ORACLE_EXECUTOR = keccak256("MAVERICK_FEE_ORACLE_MANAGER"); // AccToke Roles bytes32 public constant ACC_TOKE_MANAGER = keccak256("ACC_TOKE_MANAGER"); // Admin Roles bytes32 public constant TOKEN_RECOVERY_MANAGER = keccak256("TOKEN_RECOVERY_ROLE"); // Cross chain communications roles bytes32 public constant MESSAGE_PROXY_MANAGER = keccak256("MESSAGE_PROXY_MANAGER"); bytes32 public constant MESSAGE_PROXY_EXECUTOR = keccak256("MESSAGE_PROXY_EXECUTOR"); bytes32 public constant RECEIVING_ROUTER_MANAGER = keccak256("RECEIVING_ROUTER_MANAGER"); bytes32 public constant RECEIVING_ROUTER_EXECUTOR = keccak256("RECEIVING_ROUTER_EXECUTOR"); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IWETH9 } from "src/interfaces/utils/IWETH9.sol"; import { IAccToke } from "src/interfaces/staking/IAccToke.sol"; import { IAutopoolRegistry } from "src/interfaces/vault/IAutopoolRegistry.sol"; import { IAccessController } from "src/interfaces/security/IAccessController.sol"; import { ISwapRouter } from "src/interfaces/swapper/ISwapRouter.sol"; import { ICurveResolver } from "src/interfaces/utils/ICurveResolver.sol"; import { IAutopilotRouter } from "src/interfaces/vault/IAutopilotRouter.sol"; import { IAutopoolFactory } from "src/interfaces/vault/IAutopoolFactory.sol"; import { ISystemSecurity } from "src/interfaces/security/ISystemSecurity.sol"; import { IDestinationRegistry } from "src/interfaces/destinations/IDestinationRegistry.sol"; import { IRootPriceOracle } from "src/interfaces/oracles/IRootPriceOracle.sol"; import { IDestinationVaultRegistry } from "src/interfaces/vault/IDestinationVaultRegistry.sol"; import { IAccessController } from "src/interfaces/security/IAccessController.sol"; import { IStatsCalculatorRegistry } from "src/interfaces/stats/IStatsCalculatorRegistry.sol"; import { IAsyncSwapperRegistry } from "src/interfaces/liquidation/IAsyncSwapperRegistry.sol"; import { IERC20Metadata } from "openzeppelin-contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { IIncentivesPricingStats } from "src/interfaces/stats/IIncentivesPricingStats.sol"; import { IMessageProxy } from "src/interfaces/messageProxy/IMessageProxy.sol"; /// @notice Root most registry contract for the system interface ISystemRegistry { /// @notice Get the TOKE contract for the system /// @return toke instance of TOKE used in the system function toke() external view returns (IERC20Metadata); /// @notice Get the referenced WETH contract for the system /// @return weth contract pointer function weth() external view returns (IWETH9); /// @notice Get the AccToke staking contract /// @return accToke instance of the accToke contract for the system function accToke() external view returns (IAccToke); /// @notice Get the AutopoolRegistry for this system /// @return registry instance of the registry for this system function autoPoolRegistry() external view returns (IAutopoolRegistry registry); /// @notice Get the destination Vault registry for this system /// @return registry instance of the registry for this system function destinationVaultRegistry() external view returns (IDestinationVaultRegistry registry); /// @notice Get the access Controller for this system /// @return controller instance of the access controller for this system function accessController() external view returns (IAccessController controller); /// @notice Get the destination template registry for this system /// @return registry instance of the registry for this system function destinationTemplateRegistry() external view returns (IDestinationRegistry registry); /// @notice Auto Pilot Router /// @return router instance of the system function autoPoolRouter() external view returns (IAutopilotRouter router); /// @notice Vault factory lookup by type /// @return vaultFactory instance of the vault factory for this vault type function getAutopoolFactoryByType(bytes32 vaultType) external view returns (IAutopoolFactory vaultFactory); /// @notice Get the stats calculator registry for this system /// @return registry instance of the registry for this system function statsCalculatorRegistry() external view returns (IStatsCalculatorRegistry registry); /// @notice Get the root price oracle for this system /// @return oracle instance of the root price oracle for this system function rootPriceOracle() external view returns (IRootPriceOracle oracle); /// @notice Get the async swapper registry for this system /// @return registry instance of the registry for this system function asyncSwapperRegistry() external view returns (IAsyncSwapperRegistry registry); /// @notice Get the swap router for this system /// @return router instance of the swap router for this system function swapRouter() external view returns (ISwapRouter router); /// @notice Get the curve resolver for this system /// @return resolver instance of the curve resolver for this system function curveResolver() external view returns (ICurveResolver resolver); /// @notice Verify if given address is registered as Reward Token /// @param rewardToken token address to verify /// @return bool that indicates true if token is registered and false if not function isRewardToken(address rewardToken) external view returns (bool); /// @notice Get the system security instance for this system /// @return security instance of system security for this system function systemSecurity() external view returns (ISystemSecurity security); /// @notice Get the Incentive Pricing Stats /// @return incentivePricing the incentive pricing contract function incentivePricing() external view returns (IIncentivesPricingStats); /// @notice Get the Messagy Proxy /// @return Message proxy contract function messageProxy() external view returns (IMessageProxy); /// @notice Get the receiving router contract. /// @return Receiving router contract function receivingRouter() external view returns (address); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.1) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/Address.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ``` * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized < type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IERC20Metadata as IERC20 } from "openzeppelin-contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { IBaseAssetVault } from "src/interfaces/vault/IBaseAssetVault.sol"; import { IMainRewarder } from "src/interfaces/rewarders/IMainRewarder.sol"; import { IDexLSTStats } from "src/interfaces/stats/IDexLSTStats.sol"; interface IDestinationVault is IBaseAssetVault, IERC20 { enum VaultShutdownStatus { Active, Deprecated, Exploit } error LogicDefect(); error BaseAmountReceived(uint256 amount); /* ******************************** */ /* View */ /* ******************************** */ /// @notice A full unit of this vault // solhint-disable-next-line func-name-mixedcase function ONE() external view returns (uint256); /// @notice The asset that is deposited into the vault function underlying() external view returns (address); /// @notice The asset that rewards and withdrawals to the Autopool are denominated in /// @inheritdoc IBaseAssetVault function baseAsset() external view override returns (address); /// @notice Debt balance of underlying asset that is in contract. This /// value includes only assets that are known as debt by the rest of the /// system (i.e. transferred in on rebalance), and does not include /// extraneous amounts of underlyer that may have ended up in this contract. function internalDebtBalance() external view returns (uint256); /// @notice Debt balance of underlyering asset staked externally. This value only /// includes assets known as debt to the rest of the system, and does not include /// any assets staked on behalf of the DV in external contracts. function externalDebtBalance() external view returns (uint256); /// @notice Returns true value of _underlyer in DV. Debt + tokens that may have /// been transferred into the contract outside of rebalance. function internalQueriedBalance() external view returns (uint256); /// @notice Returns true value of staked _underlyer in external contract. This /// will include any _underlyer that has been staked on behalf of the DV. function externalQueriedBalance() external view returns (uint256); /// @notice Balance of underlying debt, sum of `externalDebtBalance()` and `internalDebtBalance()`. function balanceOfUnderlyingDebt() external view returns (uint256); /// @notice Rewarder for this vault function rewarder() external view returns (address); /// @notice Exchange this destination vault points to function exchangeName() external view returns (string memory); /// @notice The type of pool associated with this vault function poolType() external view returns (string memory); /// @notice If the pool only deals in ETH when adding or removing liquidity function poolDealInEth() external view returns (bool); /// @notice Tokens that base asset can be swapped into function underlyingTokens() external view returns (address[] memory); /* ******************************** */ /* Events */ /* ******************************** */ event Donated(address sender, uint256 amount); event Withdraw( uint256 target, uint256 actual, uint256 debtLoss, uint256 claimLoss, uint256 fromIdle, uint256 fromDebt ); event UpdateSignedMessage(bytes32 hash, bool flag); /* ******************************** */ /* Errors */ /* ******************************** */ error ZeroAddress(string paramName); error InvalidShutdownStatus(VaultShutdownStatus status); /* ******************************** */ /* Functions */ /* ******************************** */ /// @notice Setup the contract. These will be cloned so no constructor /// @param baseAsset_ Base asset of the system. WETH/USDC/etc /// @param underlyer_ Underlying asset the vault will wrap /// @param rewarder_ Reward tracker for this vault /// @param incentiveCalculator_ Incentive calculator for this vault /// @param additionalTrackedTokens_ Additional tokens that should be considered 'tracked' /// @param params_ Any extra parameters needed to setup the contract function initialize( IERC20 baseAsset_, IERC20 underlyer_, IMainRewarder rewarder_, address incentiveCalculator_, address[] memory additionalTrackedTokens_, bytes memory params_ ) external; function getRangePricesLP() external returns (uint256 spotPrice, uint256 safePrice, bool isSpotSafe); /// @notice Calculates the current value of a portion of the debt based on shares /// @dev Queries the current value of all tokens we have deployed, whether its a single place, multiple, staked, etc /// @param shares The number of shares to value /// @return value The current value of our debt in terms of the baseAsset function debtValue(uint256 shares) external returns (uint256 value); /// @notice Collects any earned rewards from staking, incentives, etc. Transfers to sender /// @dev Should be limited to LIQUIDATOR_MANAGER. Rewards must be collected before claimed /// @return amounts amount of rewards claimed for each token /// @return tokens tokens claimed function collectRewards() external returns (uint256[] memory amounts, address[] memory tokens); /// @notice Pull any non-tracked token to the specified destination /// @dev Should be limited to TOKEN_RECOVERY_MANAGER function recover(address[] calldata tokens, uint256[] calldata amounts, address[] calldata destinations) external; /// @notice Recovers any extra underlying both in DV and staked externally not tracked as debt. /// @dev Should be limited to TOKEN_SAVER_ROLE. /// @param destination The address to send excess underlyer to. function recoverUnderlying(address destination) external; /// @notice Deposit underlying to receive destination vault shares /// @param amount amount of base lp asset to deposit function depositUnderlying(uint256 amount) external returns (uint256 shares); /// @notice Withdraw underlying by burning destination vault shares /// @param shares amount of destination vault shares to burn /// @param to destination of the underlying asset /// @return amount underlyer amount 'to' received function withdrawUnderlying(uint256 shares, address to) external returns (uint256 amount); /// @notice Burn specified shares for underlyer swapped to base asset /// @param shares amount of vault shares to burn /// @param to destination of the base asset /// @return amount base asset amount 'to' received function withdrawBaseAsset(uint256 shares, address to) external returns (uint256 amount); /// @notice Mark this vault as shutdown so that autoPools can react function shutdown(VaultShutdownStatus reason) external; /// @notice True if the vault has been shutdown function isShutdown() external view returns (bool); /// @notice Returns the reason for shutdown (or `Active` if not shutdown) function shutdownStatus() external view returns (VaultShutdownStatus); /// @notice Stats contract for this vault function getStats() external view returns (IDexLSTStats); /// @notice get the marketplace rewards /// @return rewardTokens list of reward token addresses /// @return rewardRates list of reward rates function getMarketplaceRewards() external returns (uint256[] memory rewardTokens, uint256[] memory rewardRates); /// @notice Get the address of the underlying pool the vault points to /// @return poolAddress address of the underlying pool function getPool() external view returns (address poolAddress); /// @notice Gets the spot price of the underlying LP token /// @dev Price validated to be inside our tolerance against safe price. Will revert if outside. /// @return price Value of 1 unit of the underlying LP token in terms of the base asset function getValidatedSpotPrice() external returns (uint256 price); /// @notice Gets the safe price of the underlying LP token /// @dev Price validated to be inside our tolerance against spot price. Will revert if outside. /// @return price Value of 1 unit of the underlying LP token in terms of the base asset function getValidatedSafePrice() external returns (uint256 price); /// @notice Get the lowest price we can get for the LP token /// @dev This price can be attacked is not validate to be in any range /// @return price Value of 1 unit of the underlying LP token in terms of the base asset function getUnderlyerFloorPrice() external returns (uint256 price); /// @notice Get the highest price we can get for the LP token /// @dev This price can be attacked is not validate to be in any range /// @return price Value of 1 unit of the underlying LP token in terms of the base asset function getUnderlyerCeilingPrice() external returns (uint256 price); /// @notice Set or unset a hash as a signed message /// @dev Should be limited to DESTINATION_VAULTS_UPDATER. The set hash is used to vaildate a signature. /// This signature can be potentially used to claim offchain rewards earned by Destination Vaults. /// @param hash bytes32 hash of a payload /// @param flag boolean flag to indicate a validity of hash function setMessage(bytes32 hash, bool flag) external; }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { Address } from "openzeppelin-contracts/utils/Address.sol"; library Errors { using Address for address; /////////////////////////////////////////////////////////////////// // Set errors /////////////////////////////////////////////////////////////////// error AccessDenied(); error ZeroAddress(string paramName); error ZeroAmount(); error InsufficientBalance(address token); error AssetNotAllowed(address token); error NotImplemented(); error InvalidAddress(address addr); error InvalidParam(string paramName); error InvalidParams(); error UnsafePrice(address token, uint256 spotPrice, uint256 safePrice); error AlreadySet(string param); error AlreadyRegistered(address param); error SlippageExceeded(uint256 expected, uint256 actual); error ArrayLengthMismatch(uint256 length1, uint256 length2, string details); error ItemNotFound(); error ItemExists(); error MissingRole(bytes32 role, address user); error RegistryItemMissing(string item); error NotRegistered(); // Used to check storage slot is empty before setting. error MustBeZero(); // Used to check storage slot set before deleting. error MustBeSet(); error ApprovalFailed(address token); error FlashLoanFailed(address token, uint256 amount); error SystemMismatch(address source1, address source2); error InvalidToken(address token); error UnreachableError(); error InvalidSigner(address signer); error InvalidChainId(uint256 chainId); error SenderMismatch(address recipient, address sender); function verifyNotZero(address addr, string memory paramName) internal pure { if (addr == address(0)) { revert ZeroAddress(paramName); } } function verifyNotZero(bytes32 key, string memory paramName) internal pure { if (key == bytes32(0)) { revert InvalidParam(paramName); } } function verifyNotEmpty(string memory val, string memory paramName) internal pure { if (bytes(val).length == 0) { revert InvalidParam(paramName); } } function verifyNotZero(uint256 num, string memory paramName) internal pure { if (num == 0) { revert InvalidParam(paramName); } } function verifySystemsMatch(address component1, address component2) internal view { bytes memory call = abi.encodeWithSignature("getSystemRegistry()"); address registry1 = abi.decode(component1.functionStaticCall(call), (address)); address registry2 = abi.decode(component2.functionStaticCall(call), (address)); if (registry1 != registry2) { revert SystemMismatch(component1, component2); } } function verifyArrayLengths(uint256 length1, uint256 length2, string memory details) internal pure { if (length1 != length2) { revert ArrayLengthMismatch(length1, length2, details); } } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IERC3156FlashBorrower } from "openzeppelin-contracts/interfaces/IERC3156FlashBorrower.sol"; interface IStrategy { /* ******************************** */ /* Events */ /* ******************************** */ event DestinationVaultAdded(address destination); event DestinationVaultRemoved(address destination); event WithdrawalQueueSet(address[] destinations); event AddedToRemovalQueue(address destination); event RemovedFromRemovalQueue(address destination); error InvalidDestinationVault(); error RebalanceFailed(string message); /// @notice gets the list of supported destination vaults for the Autopool/Strategy /// @return _destinations List of supported destination vaults function getDestinations() external view returns (address[] memory _destinations); /// @notice add supported destination vaults for the Autopool/Strategy /// @param _destinations The list of destination vaults to add function addDestinations(address[] calldata _destinations) external; /// @notice remove supported destination vaults for the Autopool/Strategy /// @param _destinations The list of destination vaults to remove function removeDestinations(address[] calldata _destinations) external; /// @param destinationIn The address / lp token of the destination vault that will increase /// @param tokenIn The address of the underlyer token that will be provided by the swapper /// @param amountIn The amount of the underlying LP tokens that will be received /// @param destinationOut The address of the destination vault that will decrease /// @param tokenOut The address of the underlyer token that will be received by the swapper /// @param amountOut The amount of the tokenOut that will be received by the swapper struct RebalanceParams { address destinationIn; address tokenIn; uint256 amountIn; address destinationOut; address tokenOut; uint256 amountOut; } /// @param destination The address / lp token of the destination vault /// @param baseApr Base Apr is the yield generated by staking rewards /// @param feeApr Yield for pool trading fees /// @param incentiveApr Incentives for LP /// @param safeTotalSupply Safe supply for LP tokens /// @param priceReturn Return from price movement to & away from peg /// @param maxDiscount Max discount to peg /// @param maxPremium Max premium to peg /// @param ownedShares Shares owned for this destination /// @param compositeReturn Total return combined from the individual yield components /// @param pricePerShare Price per share /// @param slashingCost The loss due to slashing of the backing struct SummaryStats { address destination; uint256 baseApr; uint256 feeApr; uint256 incentiveApr; uint256 safeTotalSupply; int256 priceReturn; int256 maxDiscount; int256 maxPremium; uint256 ownedShares; int256 compositeReturn; uint256 pricePerShare; uint256 slashingCost; } /// @notice rebalance the Autopool from the tokenOut (decrease) to the tokenIn (increase) /// This uses a flash loan to receive the tokenOut to reduce the working capital requirements of the swapper /// @param receiver The contract receiving the tokens, needs to implement the /// `onFlashLoan(address user, address token, uint256 amount, uint256 fee, bytes calldata)` interface /// @param params Parameters by which to perform the rebalance /// @param data A data parameter to be passed on to the `receiver` for any custom use function flashRebalance( IERC3156FlashBorrower receiver, RebalanceParams calldata params, bytes calldata data ) external; }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IStrategy } from "src/interfaces/strategy/IStrategy.sol"; interface IAutopoolStrategy { enum RebalanceDirection { In, Out } /// @notice verify that a rebalance (swap between destinations) meets all the strategy constraints /// @dev Signature identical to IStrategy.verifyRebalance function verifyRebalance( IStrategy.RebalanceParams memory, IStrategy.SummaryStats memory ) external returns (bool, string memory message); /// @notice called by the Autopool when NAV is updated /// @dev can only be called by the strategy's registered Autopool /// @param navPerShare The navPerShare to record function navUpdate(uint256 navPerShare) external; /// @notice called by the Autopool when a rebalance is completed /// @dev can only be called by the strategy's registered Autopool /// @param rebalanceParams The parameters for the rebalance that was executed function rebalanceSuccessfullyExecuted(IStrategy.RebalanceParams memory rebalanceParams) external; /// @notice called by the Autopool during rebalance process /// @param rebalanceParams The parameters for the rebalance that was executed function getRebalanceOutSummaryStats(IStrategy.RebalanceParams memory rebalanceParams) external returns (IStrategy.SummaryStats memory outSummary); /// @notice the number of days to pause rebalancing due to NAV decay function pauseRebalancePeriodInDays() external view returns (uint16); /// @notice the number of seconds gap between consecutive rebalances function rebalanceTimeGapInSeconds() external view returns (uint256); /// @notice destinations trading a premium above maxPremium will be blocked from new capital deployments function maxPremium() external view returns (int256); // 100% = 1e18 /// @notice destinations trading a discount above maxDiscount will be blocked from new capital deployments function maxDiscount() external view returns (int256); // 100% = 1e18 /// @notice the allowed staleness of stats data before a revert occurs function staleDataToleranceInSeconds() external view returns (uint40); /// @notice the swap cost offset period to initialize the strategy with function swapCostOffsetInitInDays() external view returns (uint16); /// @notice the number of violations required to trigger a tightening of the swap cost offset period (1 to 10) function swapCostOffsetTightenThresholdInViolations() external view returns (uint16); /// @notice the number of days to decrease the swap offset period for each tightening step function swapCostOffsetTightenStepInDays() external view returns (uint16); /// @notice the number of days since a rebalance required to trigger a relaxing of the swap cost offset period function swapCostOffsetRelaxThresholdInDays() external view returns (uint16); /// @notice the number of days to increase the swap offset period for each relaxing step function swapCostOffsetRelaxStepInDays() external view returns (uint16); // slither-disable-start similar-names /// @notice the maximum the swap cost offset period can reach. This is the loosest the strategy will be function swapCostOffsetMaxInDays() external view returns (uint16); /// @notice the minimum the swap cost offset period can reach. This is the most conservative the strategy will be function swapCostOffsetMinInDays() external view returns (uint16); /// @notice the number of days for the first NAV decay comparison (e.g., 30 days) function navLookback1InDays() external view returns (uint8); /// @notice the number of days for the second NAV decay comparison (e.g., 60 days) function navLookback2InDays() external view returns (uint8); /// @notice the number of days for the third NAV decay comparison (e.g., 90 days) function navLookback3InDays() external view returns (uint8); // slither-disable-end similar-names /// @notice the maximum slippage that is allowed for a normal rebalance function maxNormalOperationSlippage() external view returns (uint256); // 100% = 1e18 /// @notice the maximum amount of slippage to allow when a destination is trimmed due to constraint violations /// recommend setting this higher than maxNormalOperationSlippage function maxTrimOperationSlippage() external view returns (uint256); // 100% = 1e18 /// @notice the maximum amount of slippage to allow when a destinationVault has been shutdown /// shutdown for a vault is abnormal and means there is an issue at that destination /// recommend setting this higher than maxNormalOperationSlippage function maxEmergencyOperationSlippage() external view returns (uint256); // 100% = 1e18 /// @notice the maximum amount of slippage to allow when the Autopool has been shutdown function maxShutdownOperationSlippage() external view returns (uint256); // 100% = 1e18 /// @notice the maximum discount used for price return function maxAllowedDiscount() external view returns (int256); // 18 precision /// @notice model weight used for LSTs base yield, 1e6 is the highest function weightBase() external view returns (uint256); /// @notice model weight used for DEX fee yield, 1e6 is the highest function weightFee() external view returns (uint256); /// @notice model weight used for incentive yield function weightIncentive() external view returns (uint256); /// @notice model weight used slashing costs function weightSlashing() external view returns (uint256); /// @notice model weight applied to an LST discount when exiting the position function weightPriceDiscountExit() external view returns (int256); /// @notice model weight applied to an LST discount when entering the position function weightPriceDiscountEnter() external view returns (int256); /// @notice model weight applied to an LST premium when entering or exiting the position function weightPricePremium() external view returns (int256); /// @notice initial value of the swap cost offset to use function swapCostOffsetInit() external view returns (uint16); /// @notice initial lst price gap tolerance function defaultLstPriceGapTolerance() external view returns (uint256); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { AutopoolDebt } from "src/vault/libs/AutopoolDebt.sol"; import { IERC4626 } from "src/interfaces/vault/IERC4626.sol"; import { Math } from "openzeppelin-contracts/utils/math/Math.sol"; import { IAutopoolStrategy } from "src/interfaces/strategy/IAutopoolStrategy.sol"; import { IMainRewarder } from "src/interfaces/rewarders/IMainRewarder.sol"; import { IERC20Permit } from "openzeppelin-contracts/token/ERC20/extensions/draft-IERC20Permit.sol"; interface IAutopool is IERC4626, IERC20Permit { enum VaultShutdownStatus { Active, Deprecated, Exploit } /// @param unlockPeriodInSeconds Time it takes for profit to unlock in seconds /// @param fullProfitUnlockTime Time at which all profit will have been unlocked /// @param lastProfitUnlockTime Last time profits were unlocked /// @param profitUnlockRate Per second rate at which profit shares unlocks. Rate when calculated is denominated in /// MAX_BPS_PROFIT. TODO: Get into uint112 struct ProfitUnlockSettings { uint48 unlockPeriodInSeconds; uint48 fullProfitUnlockTime; uint48 lastProfitUnlockTime; uint256 profitUnlockRate; } /// @param feeSink Where claimed fees are sent /// @param totalAssetsHighMark The last totalAssets amount we took fees at /// @param totalAssetsHighMarkTimestamp The last timestamp we updated the high water mark /// @param lastPeriodicFeeTake Timestamp of when the last periodic fee was taken. /// @param periodicFeeSink Address that receives periodic fee. /// @param periodicFeeBps Current periodic fee. 100% == 10000. /// @param streamingFeeBps Current streaming fee taken on profit. 100% == 10000 /// @param navPerShareLastFeeMark The last nav/share height we took fees at /// @param navPerShareLastFeeMarkTimestamp The last timestamp we took fees at /// @param rebalanceFeeHighWaterMarkEnabled Returns whether the nav/share high water mark is enabled for the /// rebalance fee struct AutopoolFeeSettings { address feeSink; uint256 totalAssetsHighMark; uint256 totalAssetsHighMarkTimestamp; uint256 lastPeriodicFeeTake; address periodicFeeSink; uint256 periodicFeeBps; uint256 streamingFeeBps; uint256 navPerShareLastFeeMark; uint256 navPerShareLastFeeMarkTimestamp; bool rebalanceFeeHighWaterMarkEnabled; } /// @param totalIdle The amount of baseAsset deposited into the contract pending deployment /// @param totalDebt The current (though cached) value of assets we've deployed /// @param totalDebtMin The current (though cached) value of assets we use for valuing during deposits /// @param totalDebtMax The current (though cached) value of assets we use for valuing during withdrawals struct AssetBreakdown { uint256 totalIdle; uint256 totalDebt; uint256 totalDebtMin; uint256 totalDebtMax; } enum TotalAssetPurpose { Global, Deposit, Withdraw } /* ******************************** */ /* Events */ /* ******************************** */ event TokensPulled(address[] tokens, uint256[] amounts, address[] destinations); event TokensRecovered(address[] tokens, uint256[] amounts, address[] destinations); event Nav(uint256 idle, uint256 debt, uint256 totalSupply); event RewarderSet(address newRewarder, address oldRewarder); event DestinationDebtReporting(address destination, uint256 debtValue, uint256 claimed, uint256 claimGasUsed); event FeeCollected(uint256 fees, address feeSink, uint256 mintedShares, uint256 profit, uint256 idle, uint256 debt); event PeriodicFeeCollected(uint256 fees, address feeSink, uint256 mintedShares); event Shutdown(VaultShutdownStatus reason); /* ******************************** */ /* Errors */ /* ******************************** */ error ERC4626MintExceedsMax(uint256 shares, uint256 maxMint); error ERC4626DepositExceedsMax(uint256 assets, uint256 maxDeposit); error ERC4626ExceededMaxWithdraw(address owner, uint256 assets, uint256 max); error ERC4626ExceededMaxRedeem(address owner, uint256 shares, uint256 max); error InvalidShutdownStatus(VaultShutdownStatus status); error WithdrawalFailed(); error DepositFailed(); error InsufficientFundsInDestinations(uint256 deficit); error WithdrawalIncomplete(); error ValueSharesMismatch(uint256 value, uint256 shares); /// @notice A full unit of this pool // solhint-disable-next-line func-name-mixedcase function ONE() external view returns (uint256); /// @notice Query the type of vault function vaultType() external view returns (bytes32); /// @notice Strategy governing the pools rebalances function autoPoolStrategy() external view returns (IAutopoolStrategy); /// @notice Allow token recoverer to collect dust / unintended transfers (non-tracked assets only) function recover(address[] calldata tokens, uint256[] calldata amounts, address[] calldata destinations) external; /// @notice Set the order of destination vaults used for withdrawals // NOTE: will be done going directly to strategy (IStrategy) vault points to. // How it'll delegate is still being decided // function setWithdrawalQueue(address[] calldata destinations) external; /// @notice Get a list of destination vaults with pending assets to clear out function getRemovalQueue() external view returns (address[] memory); function getFeeSettings() external view returns (AutopoolFeeSettings memory); /// @notice Initiate the shutdown procedures for this vault function shutdown(VaultShutdownStatus reason) external; /// @notice True if the vault has been shutdown function isShutdown() external view returns (bool); /// @notice Returns the reason for shutdown (or `Active` if not shutdown) function shutdownStatus() external view returns (VaultShutdownStatus); /// @notice gets the list of supported destination vaults for the Autopool/Strategy /// @return _destinations List of supported destination vaults function getDestinations() external view returns (address[] memory _destinations); function convertToShares( uint256 assets, uint256 totalAssetsForPurpose, uint256 supply, Math.Rounding rounding ) external view returns (uint256 shares); function convertToAssets( uint256 shares, uint256 totalAssetsForPurpose, uint256 supply, Math.Rounding rounding ) external view returns (uint256 assets); function totalAssets(TotalAssetPurpose purpose) external view returns (uint256); function getAssetBreakdown() external view returns (AssetBreakdown memory); /// @notice get a destinations last reported debt value /// @param destVault the address of the target destination /// @return destinations last reported debt value function getDestinationInfo(address destVault) external view returns (AutopoolDebt.DestinationInfo memory); /// @notice check if a destination is registered with the vault function isDestinationRegistered(address destination) external view returns (bool); /// @notice get if a destinationVault is queued for removal by the AutopoolETH function isDestinationQueuedForRemoval(address destination) external view returns (bool); /// @notice Returns instance of vault rewarder. function rewarder() external view returns (IMainRewarder); /// @notice Returns all past rewarders. function getPastRewarders() external view returns (address[] memory _pastRewarders); /// @notice Returns boolean telling whether address passed in is past rewarder. function isPastRewarder(address _pastRewarder) external view returns (bool); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IAccessController } from "src/interfaces/security/IAccessController.sol"; import { Errors } from "src/utils/Errors.sol"; contract SecurityBase { IAccessController public immutable accessController; error UndefinedAddress(); constructor(address _accessController) { if (_accessController == address(0)) revert UndefinedAddress(); accessController = IAccessController(_accessController); } modifier onlyOwner() { accessController.verifyOwner(msg.sender); _; } modifier hasRole(bytes32 role) { if (!accessController.hasRole(role, msg.sender)) revert Errors.AccessDenied(); _; } /////////////////////////////////////////////////////////////////// // // Forward all the regular methods to central security module // /////////////////////////////////////////////////////////////////// function _hasRole(bytes32 role, address account) internal view returns (bool) { return accessController.hasRole(role, account); } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { ILSTStats } from "src/interfaces/stats/ILSTStats.sol"; /// @title Return stats DEXs with LSTs interface IDexLSTStats { event DexSnapshotTaken(uint256 snapshotTimestamp, uint256 priorFeeApr, uint256 newFeeApr, uint256 unfilteredFeeApr); struct StakingIncentiveStats { // time-weighted average total supply to prevent spikes/attacks from impacting rebalancing uint256 safeTotalSupply; // rewardTokens, annualizedRewardAmounts, and periodFinishForRewards will match indexes // they are split to workaround an issue with forge having nested structs // address of the reward tokens address[] rewardTokens; // the annualized reward rate for the reward token uint256[] annualizedRewardAmounts; // the timestamp for when the rewards are set to terminate uint40[] periodFinishForRewards; // incentive rewards score. max 48, min 0 uint8 incentiveCredits; } struct DexLSTStatsData { uint256 lastSnapshotTimestamp; uint256 feeApr; uint256[] reservesInEth; StakingIncentiveStats stakingIncentiveStats; ILSTStats.LSTStatsData[] lstStatsData; } /// @notice Get the current stats for the DEX with underlying LST tokens /// @dev Returned data is a combination of current data and filtered snapshots /// @return dexLSTStatsData current data on the DEX function current() external returns (DexLSTStatsData memory dexLSTStatsData); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; library ViolationTracking { uint16 internal constant TAIL_MASK = 1 << 9; uint16 internal constant HEAD_MASK = 1; struct State { uint8 violationCount; uint8 len; uint16 violations; } function insert(State storage self, bool isViolation) internal { bool tailValue = (self.violations & TAIL_MASK) > 0; // push new spot into the queue (default false) self.violations <<= 1; // flip the bit to true and increment counter if it is a violation if (isViolation) { self.violations |= HEAD_MASK; self.violationCount += 1; } // if we're dropping a violation then decrement the counter if (tailValue) { self.violationCount -= 1; } if (self.len < 10) { self.len += 1; } } function reset(State storage self) internal { self.violationCount = 0; self.violations = 0; self.len = 0; } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; library NavTracking { uint8 internal constant MAX_NAV_TRACKING = 91; error NavHistoryInsufficient(); error InvalidNavTimestamp(uint40 current, uint40 provided); event NavHistoryInsert(uint256 navPerShare, uint40 timestamp); struct State { uint8 len; uint8 currentIndex; uint40 lastFinalizedTimestamp; uint256[MAX_NAV_TRACKING] history; } function insert(State storage self, uint256 navPerShare, uint40 timestamp) internal { if (timestamp < self.lastFinalizedTimestamp) revert InvalidNavTimestamp(self.lastFinalizedTimestamp, timestamp); // if it's been a day since the last finalized value, then finalize the current value // otherwise continue to overwrite the currentIndex if (timestamp - self.lastFinalizedTimestamp >= 1 days) { if (self.lastFinalizedTimestamp > 0) { self.currentIndex = (self.currentIndex + 1) % MAX_NAV_TRACKING; } self.lastFinalizedTimestamp = timestamp; } self.history[self.currentIndex] = navPerShare; if (self.len < MAX_NAV_TRACKING) { self.len += 1; } emit NavHistoryInsert(navPerShare, timestamp); } // the way this information is used, it is ok for it to not perfectly be daily // gaps of a few days are acceptable and do not materially degrade the NAV decay checks function getDaysAgo(State memory self, uint8 daysAgo) internal pure returns (uint256) { if (daysAgo >= self.len) revert NavHistoryInsufficient(); uint8 targetIndex = (MAX_NAV_TRACKING + self.currentIndex - daysAgo) % MAX_NAV_TRACKING; return self.history[targetIndex]; } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; /// @notice Retrieve a price for any token used in the system interface IRootPriceOracle { /// @notice Returns a fair price for the provided token in ETH /// @param token token to get the price of /// @return price the price of the token in ETH function getPriceInEth(address token) external returns (uint256 price); /// @notice Returns a spot price for the provided token in ETH, utilizing specified liquidity pool /// @param token token to get the spot price of /// @param pool liquidity pool to be used for price determination /// @return price the spot price of the token in ETH based on the provided pool function getSpotPriceInEth(address token, address pool) external returns (uint256); /// @notice Returns a price for base token in quote token. /// @dev Requires both tokens to be registered. /// @param base Address of base token. /// @param quote Address of quote token. /// @return price Price of the base token in quote token. function getPriceInQuote(address base, address quote) external returns (uint256 price); /// @notice Retrieve the price of LP token based on the reserves /// @param lpToken LP token to get the price of /// @param pool liquidity pool to be used for price determination /// @param quoteToken token to quote the price in function getRangePricesLP( address lpToken, address pool, address quoteToken ) external returns (uint256 spotPriceInQuote, uint256 safePriceInQuote, bool isSpotSafe); /// @notice Returns floor or ceiling price of the supplied lp token in terms of requested quote. /// @dev Floor price: the minimum price among all the spot prices and safe prices of the tokens in the pool. /// Ceiling price: the maximum price among all the spot prices and safe prices of the tokens in the pool. /// @param pool Address of pool to get spot pricing from. /// @param lpToken Address of the lp token to price. /// @param inQuote Address of desired quote token. /// @param ceiling Bool indicating whether to get floor or ceiling price. /// @return floorOrCeilingPerLpToken Floor or ceiling price of the lp token. function getFloorCeilingPrice( address pool, address lpToken, address inQuote, bool ceiling ) external returns (uint256 floorOrCeilingPerLpToken); function getFloorPrice(address, address, address) external returns (uint256 price); function getCeilingPrice(address, address, address) external returns (uint256 price); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; /// @title Return stats on base LSTs interface ILSTStats { struct LSTStatsData { uint256 lastSnapshotTimestamp; uint256 baseApr; int256 discount; // positive number is a discount, negative is a premium uint24[10] discountHistory; // 7 decimal precision uint40[5] discountTimestampByPercent; // each index is the timestamp that the token reached that discount uint256[] slashingCosts; uint256[] slashingTimestamps; } /// @notice Used to transfer LST snapshot data to other chain. struct LSTDestinationInfo { uint256 snapshotTimestamp; uint256 newBaseApr; uint256 currentEthPerToken; } /// @notice Get the current stats for the LST /// @dev Returned data is a combination of current data and filtered snapshots /// @return lstStatsData current data on the LST function current() external returns (LSTStatsData memory lstStatsData); /// @notice Get the EthPerToken (or Share) for the LST /// @return ethPerShare the backing eth for the LST function calculateEthPerToken() external view returns (uint256 ethPerShare); /// @notice Get if the underlying LST token is rebasing /// @return rebasing is true if the lst is a rebasing token function isRebasing() external view returns (bool rebasing); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { NavTracking } from "src/strategy/NavTracking.sol"; library AutopoolETHStrategyConfig { uint256 private constant WEIGHT_MAX = 1e6; int256 private constant WEIGHT_MAX_I = 1e6; error InvalidConfig(string paramName); // TODO: switch swapCostOffset from days to seconds; possibly pauseRebalance too struct StrategyConfig { SwapCostOffsetConfig swapCostOffset; NavLookbackConfig navLookback; SlippageConfig slippage; ModelWeights modelWeights; // number of days to pause rebalancing if a long-term nav decay is detected uint16 pauseRebalancePeriodInDays; // number of seconds before next rebalance can occur uint256 rebalanceTimeGapInSeconds; // destinations trading a premium above maxPremium will be blocked from new capital deployments int256 maxPremium; // 100% = 1e18 // destinations trading a discount above maxDiscount will be blocked from new capital deployments int256 maxDiscount; // 100% = 1e18 // if any stats data is older than this, rebalancing will revert uint40 staleDataToleranceInSeconds; // the maximum discount incorporated in price return int256 maxAllowedDiscount; // the maximum deviation between spot & safe price for individual LSTs uint256 lstPriceGapTolerance; } struct SwapCostOffsetConfig { // the swap cost offset period to initialize the strategy with uint16 initInDays; // the number of violations required to trigger a tightening of the swap cost offset period (1 to 10) uint16 tightenThresholdInViolations; // the number of days to decrease the swap offset period for each tightening step uint16 tightenStepInDays; // the number of days since a rebalance required to trigger a relaxing of the swap cost offset period uint16 relaxThresholdInDays; // the number of days to increase the swap offset period for each relaxing step uint16 relaxStepInDays; // the maximum the swap cost offset period can reach. This is the loosest the strategy will be uint16 maxInDays; // the minimum the swap cost offset period can reach. This is the most conservative the strategy will be uint16 minInDays; } struct NavLookbackConfig { // the number of days for the first NAV decay comparison (e.g., 30 days) uint8 lookback1InDays; // the number of days for the second NAV decay comparison (e.g., 60 days) uint8 lookback2InDays; // the number of days for the third NAV decay comparison (e.g., 90 days) uint8 lookback3InDays; } struct SlippageConfig { // the maximum slippage that is allowed for a normal rebalance // under normal circumstances this will not be triggered because the swap offset logic is the primary gate // but this ensures a sensible slippage level will never be exceeded uint256 maxNormalOperationSlippage; // 100% = 1e18 // the maximum amount of slippage to allow when a destination is trimmed due to constraint violations // recommend setting this higher than maxNormalOperationSlippage uint256 maxTrimOperationSlippage; // 100% = 1e18 // the maximum amount of slippage to allow when a destinationVault has been shutdown // shutdown for a vault is abnormal and means there is an issue at that destination // recommend setting this higher than maxNormalOperationSlippage uint256 maxEmergencyOperationSlippage; // 100% = 1e18 // the maximum amount of slippage to allow when the Autopool has been shutdown uint256 maxShutdownOperationSlippage; // 100% = 1e18 } struct ModelWeights { uint256 baseYield; uint256 feeYield; uint256 incentiveYield; uint256 slashing; int256 priceDiscountExit; int256 priceDiscountEnter; int256 pricePremium; } // slither-disable-start cyclomatic-complexity function validate(StrategyConfig memory config) internal pure { // Swap Cost Offset Config if ( config.swapCostOffset.initInDays < config.swapCostOffset.minInDays || config.swapCostOffset.initInDays > config.swapCostOffset.maxInDays || config.swapCostOffset.initInDays < 7 || config.swapCostOffset.initInDays > 90 ) { revert InvalidConfig("swapCostOffset_initInDays"); } if ( config.swapCostOffset.tightenThresholdInViolations < 1 || config.swapCostOffset.tightenThresholdInViolations > 10 ) { revert InvalidConfig("swapCostOffset_tightenThresholdInViolations"); } if (config.swapCostOffset.tightenStepInDays < 1 || config.swapCostOffset.tightenStepInDays > 7) { revert InvalidConfig("swapCostOffset_tightenStepInDays"); } if (config.swapCostOffset.relaxThresholdInDays < 14 || config.swapCostOffset.relaxThresholdInDays > 90) { revert InvalidConfig("swapCostOffset_relaxThresholdInDays"); } if (config.swapCostOffset.relaxStepInDays < 1 || config.swapCostOffset.relaxStepInDays > 7) { revert InvalidConfig("swapCostOffset_relaxStepInDays"); } if ( config.swapCostOffset.maxInDays <= config.swapCostOffset.minInDays || config.swapCostOffset.maxInDays < 8 || config.swapCostOffset.maxInDays > 90 ) { revert InvalidConfig("swapCostOffset_maxInDays"); } if (config.swapCostOffset.minInDays < 7 || config.swapCostOffset.minInDays > 90) { revert InvalidConfig("swapCostOffset_minInDays"); } // NavLookback _validateNotZero(config.navLookback.lookback1InDays, "navLookback_lookback1InDays"); // the 91st spot holds current (0 days ago), so the farthest back that can be retrieved is 90 days ago if ( config.navLookback.lookback1InDays >= NavTracking.MAX_NAV_TRACKING || config.navLookback.lookback2InDays >= NavTracking.MAX_NAV_TRACKING || config.navLookback.lookback3InDays > NavTracking.MAX_NAV_TRACKING ) { revert InvalidConfig("navLookback_max"); } // lookback should be configured smallest to largest and should not be equal if ( config.navLookback.lookback1InDays >= config.navLookback.lookback2InDays || config.navLookback.lookback2InDays >= config.navLookback.lookback3InDays ) { revert InvalidConfig("navLookback_steps"); } // Slippage _ensureNotGt25PctE18(config.slippage.maxShutdownOperationSlippage, "slippage_maxShutdownOperationSlippage"); _ensureNotGt25PctE18(config.slippage.maxEmergencyOperationSlippage, "slippage_maxEmergencyOperationSlippage"); _ensureNotGt25PctE18(config.slippage.maxTrimOperationSlippage, "slippage_maxTrimOperationSlippage"); _ensureNotGt25PctE18(config.slippage.maxNormalOperationSlippage, "slippage_maxNormalOperationSlippage"); // Model Weights if (config.modelWeights.baseYield > WEIGHT_MAX) { revert InvalidConfig("modelWeights_baseYield"); } if (config.modelWeights.feeYield > WEIGHT_MAX) { revert InvalidConfig("modelWeights_feeYield"); } if (config.modelWeights.incentiveYield > WEIGHT_MAX) { revert InvalidConfig("modelWeights_incentiveYield"); } if (config.modelWeights.slashing > WEIGHT_MAX) { revert InvalidConfig("modelWeights_slashing"); } if (config.modelWeights.priceDiscountExit > WEIGHT_MAX_I) { revert InvalidConfig("modelWeights_priceDiscountExit"); } if (config.modelWeights.priceDiscountEnter > WEIGHT_MAX_I) { revert InvalidConfig("modelWeights_priceDiscountEnter"); } if (config.modelWeights.pricePremium > WEIGHT_MAX_I) { revert InvalidConfig("modelWeights_pricePremium"); } // Top Level Config if (config.pauseRebalancePeriodInDays < 7 || config.pauseRebalancePeriodInDays > 90) { revert InvalidConfig("pauseRebalancePeriodInDays"); } if (config.rebalanceTimeGapInSeconds < 1 hours || config.rebalanceTimeGapInSeconds > 30 days) { revert InvalidConfig("rebalanceTimeGapInSeconds"); } _ensureNotGt25PctE18OrLtZero(config.maxPremium, "maxPremium"); _ensureNotGt25PctE18OrLtZero(config.maxDiscount, "maxPremium"); if (config.staleDataToleranceInSeconds < 1 hours || config.staleDataToleranceInSeconds > 7 days) { revert InvalidConfig("staleDataToleranceInSeconds"); } if (config.maxAllowedDiscount < 0 || config.maxAllowedDiscount > 0.5e18) { revert InvalidConfig("maxAllowedDiscount"); } if (config.lstPriceGapTolerance > 500) { revert InvalidConfig("lstPriceGapTolerance"); } } // slither-disable-end cyclomatic-complexity function _validateNotZero(uint256 val, string memory err) private pure { if (val == 0) { revert InvalidConfig(err); } } function _ensureNotGt25PctE18(uint256 value, string memory err) private pure { if (value > 0.25e18) { revert InvalidConfig(err); } } function _ensureNotGt25PctE18OrLtZero(int256 value, string memory err) private pure { if (value > 0.25e18 || value < 0) { revert InvalidConfig(err); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10**64) { value /= 10**64; result += 64; } if (value >= 10**32) { value /= 10**32; result += 32; } if (value >= 10**16) { value /= 10**16; result += 16; } if (value >= 10**8) { value /= 10**8; result += 8; } if (value >= 10**4) { value /= 10**4; result += 4; } if (value >= 10**2) { value /= 10**2; result += 2; } if (value >= 10**1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { Errors } from "src/utils/Errors.sol"; import { LibAdapter } from "src/libs/LibAdapter.sol"; import { IDestinationVault } from "src/interfaces/vault/IDestinationVault.sol"; import { Math } from "openzeppelin-contracts/utils/math/Math.sol"; import { EnumerableSet } from "openzeppelin-contracts/utils/structs/EnumerableSet.sol"; import { IStrategy } from "src/interfaces/strategy/IStrategy.sol"; import { SafeERC20 } from "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol"; import { IERC20Metadata as IERC20 } from "openzeppelin-contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { IERC3156FlashBorrower } from "openzeppelin-contracts/interfaces/IERC3156FlashBorrower.sol"; import { IAutopoolStrategy } from "src/interfaces/strategy/IAutopoolStrategy.sol"; import { StructuredLinkedList } from "src/strategy/StructuredLinkedList.sol"; import { WithdrawalQueue } from "src/strategy/WithdrawalQueue.sol"; import { IAutopool } from "src/interfaces/vault/IAutopool.sol"; import { IMainRewarder } from "src/interfaces/rewarders/IMainRewarder.sol"; import { AutopoolToken } from "src/vault/libs/AutopoolToken.sol"; library AutopoolDebt { using Math for uint256; using SafeERC20 for IERC20; using WithdrawalQueue for StructuredLinkedList.List; using EnumerableSet for EnumerableSet.AddressSet; using AutopoolToken for AutopoolToken.TokenData; /// @notice Max time a cached debt report can be used uint256 public constant MAX_DEBT_REPORT_AGE_SECONDS = 1 days; error VaultShutdown(); error WithdrawShareCalcInvalid(uint256 currentShares, uint256 cachedShares); error RebalanceDestinationsMatch(address destinationVault); error RebalanceFailed(string message); error InvalidPrices(); error InvalidTotalAssetPurpose(); error InvalidDestination(address destination); error TooFewAssets(uint256 requested, uint256 actual); error SharesAndAssetsReceived(uint256 assets, uint256 shares); error AmountExceedsAllowance(uint256 shares, uint256 allowed); event DestinationDebtReporting( address destination, AutopoolDebt.IdleDebtUpdates debtInfo, uint256 claimed, uint256 claimGasUsed ); event NewNavShareFeeMark(uint256 navPerShare, uint256 timestamp); event Nav(uint256 idle, uint256 debt, uint256 totalSupply); event Withdraw( address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares ); struct DestinationInfo { /// @notice Current underlying value at the destination vault /// @dev Used for calculating totalDebt, mid point of min and max uint256 cachedDebtValue; /// @notice Current minimum underlying value at the destination vault /// @dev Used for calculating totalDebt during withdrawal uint256 cachedMinDebtValue; /// @notice Current maximum underlying value at the destination vault /// @dev Used for calculating totalDebt of the deposit uint256 cachedMaxDebtValue; /// @notice Last block timestamp this info was updated uint256 lastReport; /// @notice How many shares of the destination vault we owned at last report uint256 ownedShares; } struct IdleDebtUpdates { bool pricesWereSafe; uint256 totalIdleDecrease; uint256 totalIdleIncrease; uint256 totalDebtIncrease; uint256 totalDebtDecrease; uint256 totalMinDebtIncrease; uint256 totalMinDebtDecrease; uint256 totalMaxDebtIncrease; uint256 totalMaxDebtDecrease; } struct RebalanceOutParams { /// Address that will received the withdrawn underlyer address receiver; /// The "out" destination vault address destinationOut; /// The amount of tokenOut that will be withdrawn uint256 amountOut; /// The underlyer for destinationOut address tokenOut; IERC20 _baseAsset; bool _shutdown; } /// @dev In memory struct only for managing vars in _withdraw struct WithdrawInfo { uint256 currentIdle; uint256 assetsFromIdle; uint256 totalAssetsToPull; uint256 assetsToPull; uint256 assetsPulled; uint256 idleIncrease; uint256 debtDecrease; uint256 debtMinDecrease; uint256 debtMaxDecrease; uint256 totalMinDebt; uint256 destinationRound; uint256 lastRoundSlippage; uint256 expectedAssets; } struct FlashRebalanceParams { uint256 totalIdle; uint256 totalDebt; IERC20 baseAsset; bool shutdown; } struct FlashResultInfo { uint256 tokenInBalanceBefore; uint256 tokenInBalanceAfter; bytes32 flashResult; } function flashRebalance( DestinationInfo storage destInfoOut, DestinationInfo storage destInfoIn, IERC3156FlashBorrower receiver, IStrategy.RebalanceParams memory params, IStrategy.SummaryStats memory destSummaryOut, IAutopoolStrategy autoPoolStrategy, FlashRebalanceParams memory flashParams, bytes calldata data ) external returns (IdleDebtUpdates memory result) { // Handle decrease (shares going "Out", cashing in shares and sending underlying back to swapper) // If the tokenOut is _asset we assume they are taking idle // which is already in the contract result = _handleRebalanceOut( AutopoolDebt.RebalanceOutParams({ receiver: address(receiver), destinationOut: params.destinationOut, amountOut: params.amountOut, tokenOut: params.tokenOut, _baseAsset: flashParams.baseAsset, _shutdown: flashParams.shutdown }), destInfoOut ); if (!result.pricesWereSafe) { revert InvalidPrices(); } // Handle increase (shares coming "In", getting underlying from the swapper and trading for new shares) if (params.amountIn > 0) { FlashResultInfo memory flashResultInfo; // get "before" counts flashResultInfo.tokenInBalanceBefore = IERC20(params.tokenIn).balanceOf(address(this)); // Give control back to the solver so they can make use of the "out" assets // and get our "in" asset flashResultInfo.flashResult = receiver.onFlashLoan(msg.sender, params.tokenIn, params.amountIn, 0, data); // We assume the solver will send us the assets flashResultInfo.tokenInBalanceAfter = IERC20(params.tokenIn).balanceOf(address(this)); // Make sure the call was successful and verify we have at least the assets we think // we were getting if ( flashResultInfo.flashResult != keccak256("ERC3156FlashBorrower.onFlashLoan") || flashResultInfo.tokenInBalanceAfter < flashResultInfo.tokenInBalanceBefore + params.amountIn ) { revert Errors.FlashLoanFailed(params.tokenIn, params.amountIn); } { // make sure we have a valid path (bool success, string memory message) = autoPoolStrategy.verifyRebalance(params, destSummaryOut); if (!success) { revert RebalanceFailed(message); } } if (params.tokenIn != address(flashParams.baseAsset)) { IdleDebtUpdates memory inDebtResult = _handleRebalanceIn( destInfoIn, IDestinationVault(params.destinationIn), params.tokenIn, flashResultInfo.tokenInBalanceAfter ); if (!inDebtResult.pricesWereSafe) { revert InvalidPrices(); } result.totalDebtDecrease += inDebtResult.totalDebtDecrease; result.totalDebtIncrease += inDebtResult.totalDebtIncrease; result.totalMinDebtDecrease += inDebtResult.totalMinDebtDecrease; result.totalMinDebtIncrease += inDebtResult.totalMinDebtIncrease; result.totalMaxDebtDecrease += inDebtResult.totalMaxDebtDecrease; result.totalMaxDebtIncrease += inDebtResult.totalMaxDebtIncrease; } else { result.totalIdleIncrease += flashResultInfo.tokenInBalanceAfter - flashResultInfo.tokenInBalanceBefore; } } } /// @notice Perform deposit and debt info update for the "in" destination during a rebalance /// @dev This "in" function performs less validations than its "out" version /// @param dvIn The "in" destination vault /// @param tokenIn The underlyer for dvIn /// @param depositAmount The amount of tokenIn that will be deposited /// @return result Changes in debt values function _handleRebalanceIn( DestinationInfo storage destInfo, IDestinationVault dvIn, address tokenIn, uint256 depositAmount ) private returns (IdleDebtUpdates memory result) { LibAdapter._approve(IERC20(tokenIn), address(dvIn), depositAmount); // Snapshot our current shares so we know how much to back out uint256 originalShareBal = dvIn.balanceOf(address(this)); // deposit to dv uint256 newShares = dvIn.depositUnderlying(depositAmount); // Update the debt info snapshot result = _recalculateDestInfo(destInfo, dvIn, originalShareBal, originalShareBal + newShares); } /** * @notice Perform withdraw and debt info update for the "out" destination during a rebalance * @dev This "out" function performs more validations and handles idle as opposed to "in" which does not * debtDecrease The previous amount of debt destinationOut accounted for in totalDebt * debtIncrease The current amount of debt destinationOut should account for in totalDebt * idleDecrease Amount of baseAsset that was sent from the vault. > 0 only when tokenOut == baseAsset * idleIncrease Amount of baseAsset that was claimed from Destination Vault * @param params Rebalance out params * @param destOutInfo The "out" destination vault info * @return assetChange debt and idle change data */ function _handleRebalanceOut( RebalanceOutParams memory params, DestinationInfo storage destOutInfo ) private returns (IdleDebtUpdates memory assetChange) { // Handle decrease (shares going "Out", cashing in shares and sending underlying back to swapper) // If the tokenOut is _asset we assume they are taking idle // which is already in the contract if (params.amountOut > 0) { if (params.tokenOut != address(params._baseAsset)) { IDestinationVault dvOut = IDestinationVault(params.destinationOut); // Snapshot our current shares so we know how much to back out uint256 originalShareBal = dvOut.balanceOf(address(this)); // Burning our shares will claim any pending baseAsset // rewards and send them to us. // Get our starting balance uint256 beforeBaseAssetBal = params._baseAsset.balanceOf(address(this)); // Withdraw underlying from the destination vault // Shares are sent directly to the flashRebalance receiver // slither-disable-next-line unused-return dvOut.withdrawUnderlying(params.amountOut, params.receiver); // Update the debt info snapshot assetChange = _recalculateDestInfo(destOutInfo, dvOut, originalShareBal, originalShareBal - params.amountOut); // Capture any rewards we may have claimed as part of withdrawing assetChange.totalIdleIncrease = params._baseAsset.balanceOf(address(this)) - beforeBaseAssetBal; } else { // If we are shutdown then the only operations we should be performing are those that get // the base asset back to the vault. We shouldn't be sending out more if (params._shutdown) { revert VaultShutdown(); } // Working with idle baseAsset which should be in the vault already // Just send it out IERC20(params.tokenOut).safeTransfer(params.receiver, params.amountOut); assetChange.totalIdleDecrease = params.amountOut; // We weren't dealing with any debt or pricing, just idle, so we can just mark // it as safe assetChange.pricesWereSafe = true; } } } function recalculateDestInfo( DestinationInfo storage destInfo, IDestinationVault destVault, uint256 originalShares, uint256 currentShares ) external returns (IdleDebtUpdates memory result) { result = _recalculateDestInfo(destInfo, destVault, originalShares, currentShares); } /// @dev Will not revert on unsafe prices. Up to the caller. function _recalculateDestInfo( DestinationInfo storage destInfo, IDestinationVault destVault, uint256 originalShares, uint256 currentShares ) private returns (IdleDebtUpdates memory result) { // TODO: Trace the use of this fn and ensure that every is handling is pricesWereSafe // Figure out what to back out of our totalDebt number. // We could have had withdraws since the last snapshot which means our // cached currentDebt number should be decreased based on the remaining shares // totalDebt is decreased using the same proportion of shares method during withdrawals // so this should represent whatever is remaining. // Prices are per LP token and whether or not the prices are safe to use // If they aren't safe then just continue and we'll get it on the next go around (uint256 spotPrice, uint256 safePrice, bool isSpotSafe) = destVault.getRangePricesLP(); // Calculate what we're backing out based on the original shares uint256 minPrice = spotPrice > safePrice ? safePrice : spotPrice; uint256 maxPrice = spotPrice > safePrice ? spotPrice : safePrice; // If we previously had shares, calculate how much of our cached numbers // still remain as this will be deducted from the overall debt numbers // TODO: Evaluate whether to round these up so we don't accumulate small amounts // over time uint256 prevOwnedShares = destInfo.ownedShares; if (prevOwnedShares > 0) { result.totalDebtDecrease = (destInfo.cachedDebtValue * originalShares) / prevOwnedShares; result.totalMinDebtDecrease = (destInfo.cachedMinDebtValue * originalShares) / prevOwnedShares; result.totalMaxDebtDecrease = (destInfo.cachedMaxDebtValue * originalShares) / prevOwnedShares; } // The overall debt value is the mid point of min and max uint256 div = 10 ** destVault.decimals(); uint256 newDebtValue = (minPrice * currentShares + maxPrice * currentShares) / (div * 2); result.pricesWereSafe = isSpotSafe; result.totalDebtIncrease = newDebtValue; result.totalMinDebtIncrease = minPrice * currentShares / div; result.totalMaxDebtIncrease = maxPrice * currentShares / div; // Save our current new values destInfo.cachedDebtValue = newDebtValue; destInfo.cachedMinDebtValue = result.totalMinDebtIncrease; destInfo.cachedMaxDebtValue = result.totalMaxDebtIncrease; destInfo.lastReport = block.timestamp; destInfo.ownedShares = currentShares; } function totalAssetsTimeChecked( StructuredLinkedList.List storage debtReportQueue, mapping(address => AutopoolDebt.DestinationInfo) storage destinationInfo, IAutopool.TotalAssetPurpose purpose ) external returns (uint256) { IDestinationVault destVault = IDestinationVault(debtReportQueue.peekHead()); uint256 recalculatedTotalAssets = IAutopool(address(this)).totalAssets(purpose); while (address(destVault) != address(0)) { uint256 lastReport = destinationInfo[address(destVault)].lastReport; if (lastReport + MAX_DEBT_REPORT_AGE_SECONDS > block.timestamp) { // Its not stale // This report is OK, we don't need to recalculate anything break; } else { // It is stale, recalculate //slither-disable-next-line unused-return uint256 currentShares = destVault.balanceOf(address(this)); uint256 staleDebt; uint256 extremePrice; // Figure out exactly which price to use based on its purpose if (purpose == IAutopool.TotalAssetPurpose.Deposit) { // We use max value so that anything deposited is worth less extremePrice = destVault.getUnderlyerCeilingPrice(); // Round down. We are subtracting this value out of the total so some left // behind just increases the value which is what we want staleDebt = destinationInfo[address(destVault)].cachedMaxDebtValue.mulDiv( currentShares, destinationInfo[address(destVault)].ownedShares, Math.Rounding.Down ); } else if (purpose == IAutopool.TotalAssetPurpose.Withdraw) { // We use min value so that we value the shares as worth less extremePrice = destVault.getUnderlyerFloorPrice(); // Round up. We are subtracting this value out of the total so if we take a little // extra it just decreases the value which is what we want staleDebt = destinationInfo[address(destVault)].cachedMinDebtValue.mulDiv( currentShares, destinationInfo[address(destVault)].ownedShares, Math.Rounding.Up ); } else { revert InvalidTotalAssetPurpose(); } // Back out our stale debt, add in its new value // Our goal is to find the most conservative value in each situation. If the current // value we have represents that, then use it. Otherwise, use the new one. uint256 newValue = (currentShares * extremePrice) / destVault.ONE(); if (purpose == IAutopool.TotalAssetPurpose.Deposit && staleDebt > newValue) { newValue = staleDebt; } else if (purpose == IAutopool.TotalAssetPurpose.Withdraw && staleDebt < newValue) { newValue = staleDebt; } recalculatedTotalAssets = recalculatedTotalAssets + newValue - staleDebt; } destVault = IDestinationVault(debtReportQueue.getAdjacent(address(destVault), true)); } return recalculatedTotalAssets; } function _updateDebtReporting( StructuredLinkedList.List storage debtReportQueue, mapping(address => AutopoolDebt.DestinationInfo) storage destinationInfo, uint256 numToProcess ) external returns (IdleDebtUpdates memory result) { numToProcess = Math.min(numToProcess, debtReportQueue.sizeOf()); for (uint256 i = 0; i < numToProcess; ++i) { IDestinationVault destVault = IDestinationVault(debtReportQueue.popHead()); // Get the reward value we've earned. DV rewards are always in terms of base asset // We track the gas used purely for off-chain stats purposes // Main rewarder on DV's store the earned and liquidated rewards // Extra rewarders are disabled at the DV level uint256 claimGasUsed = gasleft(); uint256 beforeBaseAsset = IERC20(IAutopool(address(this)).asset()).balanceOf(address(this)); IMainRewarder(destVault.rewarder()).getReward(address(this), false); uint256 claimedRewardValue = IERC20(IAutopool(address(this)).asset()).balanceOf(address(this)) - beforeBaseAsset; result.totalIdleIncrease += claimedRewardValue; // Recalculate the debt info figuring out the change in // total debt value we can roll up later uint256 currentShareBalance = destVault.balanceOf(address(this)); AutopoolDebt.IdleDebtUpdates memory debtResult = _recalculateDestInfo( destinationInfo[address(destVault)], destVault, currentShareBalance, currentShareBalance ); result.totalDebtDecrease += debtResult.totalDebtDecrease; result.totalDebtIncrease += debtResult.totalDebtIncrease; result.totalMinDebtDecrease += debtResult.totalMinDebtDecrease; result.totalMinDebtIncrease += debtResult.totalMinDebtIncrease; result.totalMaxDebtDecrease += debtResult.totalMaxDebtDecrease; result.totalMaxDebtIncrease += debtResult.totalMaxDebtIncrease; // If we no longer have shares, then there's no reason to continue reporting on the destination. // The strategy will only call for the info if its moving "out" of the destination // and that will only happen if we have shares. // A rebalance where we move "in" to the position will refresh the data at that time if (currentShareBalance > 0) { debtReportQueue.addToTail(address(destVault)); } claimGasUsed -= gasleft(); emit DestinationDebtReporting(address(destVault), debtResult, claimedRewardValue, claimGasUsed); } } function _initiateWithdrawInfo( uint256 assets, IAutopool.AssetBreakdown storage assetBreakdown ) private view returns (WithdrawInfo memory) { uint256 idle = assetBreakdown.totalIdle; WithdrawInfo memory info = WithdrawInfo({ currentIdle: idle, // If idle can cover the full amount, then we want to pull all assets from there // Otherwise, we want to pull from the market and only get idle if we exhaust the market assetsFromIdle: assets > idle ? 0 : assets, totalAssetsToPull: 0, assetsToPull: 0, assetsPulled: 0, idleIncrease: 0, debtDecrease: 0, debtMinDecrease: 0, debtMaxDecrease: 0, totalMinDebt: assetBreakdown.totalDebtMin, destinationRound: 0, lastRoundSlippage: 0, expectedAssets: 0 }); info.totalAssetsToPull = assets - info.assetsFromIdle; // This var we use to track our progress later info.assetsToPull = assets - info.assetsFromIdle; // Idle + minDebt is the maximum amount of assets/debt we could burn during a withdraw. // If the user is request more than that (like during a withdraw) we can just revert // early without trying if (info.totalAssetsToPull > info.currentIdle + info.totalMinDebt) { revert TooFewAssets(assets, info.currentIdle + info.totalMinDebt); } return info; } function withdraw( uint256 assets, uint256 applicableTotalAssets, IAutopool.AssetBreakdown storage assetBreakdown, StructuredLinkedList.List storage withdrawalQueue, mapping(address => AutopoolDebt.DestinationInfo) storage destinationInfo ) public returns (uint256 actualAssets, uint256 actualShares, uint256 debtBurned) { WithdrawInfo memory info = _initiateWithdrawInfo(assets, assetBreakdown); // Pull the market if there aren't enough funds in idle to cover the entire amount // This flow is not bounded by a set number of shares. The user has requested X assets // and a variable number of shares to burn so we don't have easy break out points like we do // during redeem (like using debt burned). When we get slippage here and don't meet the requested assets // we need to keep going if we can. This is tricky if we consider that (most of) our destinations are // LP positions and we'll be swapping assets, so we can expect some slippage. Even // if our minDebtValue numbers are up to date and perfectly accurate slippage could ensure we // are always receiving less than we expect/calculate and we never hit the requested assets // even though the owner would have shares to cover it. Under normal/expected conditions, our // minDebtValue is lower than actual and we expect overall value to be going up, so we burn a tad // more than we should and receive a tad more than we expect. This should cover us. However, // in other conditions we have to be sure we aren't endlessly trying to approach 0 so we are tracking // the slippage we received on the last pull, repricing, and applying an increasing multiplier until we either // pull enough to cover or pull them all and/or move to the next destination. uint256 dvSharesToBurn; while (info.assetsToPull > 0) { IDestinationVault destVault = IDestinationVault(withdrawalQueue.peekHead()); if (address(destVault) == address(0)) { // TODO: This may be some NULL value too, check the underlying library break; } uint256 dvShares = destVault.balanceOf(address(this)); { uint256 dvSharesValue; if (info.destinationRound == 0) { // First time pulling // We use the min debt value here because its a withdrawal and we're trying to cover an amount // of assets. Undervaluing the shares may mean we pull more but given that we expect slippage // that is desirable. dvSharesValue = destinationInfo[address(destVault)].cachedMinDebtValue * dvShares / destinationInfo[address(destVault)].ownedShares; } else { // When we've pulled from this destination before, i.e. destinationRound > 0, then we // know a more accurate exchange rate and its worse than we were expecting. // We even will pad it a bit as we want to account for any additional slippage we // may receive by say being farther down an AMM curve. // dvSharesToBurn is the last value we used when pulling from this destination // info.expectedAssets is how much we expected to get on that last pull // info.expectedAssets - info.lastRoundSlippage is how much we actually received uint256 paddedSlippage = info.lastRoundSlippage * (info.destinationRound + 10_000) / 10_000; if (paddedSlippage < info.expectedAssets) { dvSharesValue = (info.expectedAssets - paddedSlippage) * dvShares / dvSharesToBurn; } else { // This will just mean we pull all shares dvSharesValue = 0; } } if (dvSharesValue > info.assetsToPull) { dvSharesToBurn = (dvShares * info.assetsToPull) / dvSharesValue; // Only need to set it here because the only time we'll use it is if // we don't exhaust all shares and have to try the destination again info.expectedAssets = info.assetsToPull; } else { dvSharesToBurn = dvShares; } } // Destination Vaults always burn the exact amount we instruct them to uint256 pulledAssets = destVault.withdrawBaseAsset(dvSharesToBurn, address(this)); info.assetsPulled += pulledAssets; // Calculate the totalDebt we'll need to remove based on the shares we're burning // We're rounding up here so take care when actually applying to totalDebt // The assets we calculated to pull are from the minDebt number we track so // we'll use that one to ensure we properly account for slippage (the `pulled` var below) // The other two debt numbers we just need to keep up to date. uint256 debtMinDecrease = destinationInfo[address(destVault)].cachedMinDebtValue.mulDiv( dvSharesToBurn, destinationInfo[address(destVault)].ownedShares, Math.Rounding.Up ); info.debtMinDecrease += debtMinDecrease; info.debtDecrease += destinationInfo[address(destVault)].cachedDebtValue.mulDiv( dvSharesToBurn, destinationInfo[address(destVault)].ownedShares, Math.Rounding.Up ); info.debtMaxDecrease += destinationInfo[address(destVault)].cachedMaxDebtValue.mulDiv( dvSharesToBurn, destinationInfo[address(destVault)].ownedShares, Math.Rounding.Up ); // If we've exhausted all shares we can remove the withdrawal from the queue // We need to leave it in the debt report queue though so that our destination specific // debt tracking values can be updated if (dvShares == dvSharesToBurn) { withdrawalQueue.popAddress(address(destVault)); info.destinationRound = 0; info.lastRoundSlippage = 0; } else { // If we didn't burn all the shares and we received enough to cover our // expected that means we'll break out below as we've hit our target unchecked { if (pulledAssets < info.expectedAssets) { info.lastRoundSlippage = info.expectedAssets - pulledAssets; if (info.destinationRound == 0) { info.destinationRound = 100; } else { info.destinationRound *= 2; } } } } // It's possible we'll get back more assets than we anticipate from a swap // so if we do, throw it in idle and stop processing. You don't get more than we've calculated if (info.assetsPulled >= info.totalAssetsToPull) { info.idleIncrease += info.assetsPulled - info.totalAssetsToPull; info.assetsPulled = info.totalAssetsToPull; break; } info.assetsToPull -= pulledAssets; } // info.assetsToPull isn't safe to use past this point. // It may or may not be accurate from the previous loop // We didn't get enough assets from the debt pull // See if we can get the rest from idle if (info.assetsPulled < assets && info.currentIdle > 0) { uint256 remaining = assets - info.assetsPulled; if (remaining <= info.currentIdle) { info.assetsFromIdle = remaining; } // We don't worry about the else case because if currentIdle can't // cover remaining then we'll fail the `actualAssets < assets` // check below and revert } debtBurned = info.assetsFromIdle + info.debtMinDecrease; actualAssets = info.assetsFromIdle + info.assetsPulled; if (actualAssets < assets) { revert TooFewAssets(assets, actualAssets); } actualShares = IAutopool(address(this)).convertToShares( Math.max(actualAssets, debtBurned), applicableTotalAssets, IAutopool(address(this)).totalSupply(), Math.Rounding.Up ); // Subtract what's taken out of idle from totalIdle // We may also have some increase to account for it we over pulled // or received better execution than we were anticipating // slither-disable-next-line events-maths assetBreakdown.totalIdle = info.currentIdle + info.idleIncrease - info.assetsFromIdle; // Save off our various debt numbers if (info.debtDecrease > assetBreakdown.totalDebt) { assetBreakdown.totalDebt = 0; } else { assetBreakdown.totalDebt -= info.debtDecrease; } if (info.debtMinDecrease > info.totalMinDebt) { assetBreakdown.totalDebtMin = 0; } else { assetBreakdown.totalDebtMin -= info.debtMinDecrease; } if (info.debtMaxDecrease > assetBreakdown.totalDebtMax) { assetBreakdown.totalDebtMax = 0; } else { assetBreakdown.totalDebtMax -= info.debtMaxDecrease; } } /// @notice Perform a removal of assets via the redeem path where the shares are the limiting factor. /// This means we break out whenever we reach either `assets` retrieved or debt value equivalent to `assets` burned function redeem( uint256 assets, uint256 applicableTotalAssets, IAutopool.AssetBreakdown storage assetBreakdown, StructuredLinkedList.List storage withdrawalQueue, mapping(address => AutopoolDebt.DestinationInfo) storage destinationInfo ) public returns (uint256 actualAssets, uint256 actualShares, uint256 debtBurned) { WithdrawInfo memory info = _initiateWithdrawInfo(assets, assetBreakdown); // If not enough funds in idle, then pull what we need from destinations bool exhaustedDestinations = false; while (info.assetsToPull > 0) { IDestinationVault destVault = IDestinationVault(withdrawalQueue.peekHead()); if (address(destVault) == address(0)) { exhaustedDestinations = true; break; } uint256 dvShares = destVault.balanceOf(address(this)); uint256 dvSharesToBurn = dvShares; { // Valuing these shares higher, rounding up, will result in us burning less of them // in the event we don't burn all of them. Good thing. uint256 dvSharesValue = destinationInfo[address(destVault)].cachedMinDebtValue.mulDiv( dvSharesToBurn, destinationInfo[address(destVault)].ownedShares, Math.Rounding.Up ); // If the dv shares we own are worth more than we need, limit the shares to burn // Any extra we get will be dropped into idle if (dvSharesValue > info.assetsToPull) { uint256 limitedShares = (dvSharesToBurn * info.assetsToPull) / dvSharesValue; // Final set for the actual shares we'll burn later dvSharesToBurn = limitedShares; } } // Destination Vaults always burn the exact amount we instruct them to uint256 pulledAssets = destVault.withdrawBaseAsset(dvSharesToBurn, address(this)); info.assetsPulled += pulledAssets; // Calculate the totalDebt we'll need to remove based on the shares we're burning // We're rounding up here so take care when actually applying to totalDebt // The assets we calculated to pull are from the minDebt number we track so // we'll use that one to ensure we properly account for slippage (the `pulled` var below) // The other two debt numbers we just need to keep up to date. uint256 debtMinDecrease = destinationInfo[address(destVault)].cachedMinDebtValue.mulDiv( dvSharesToBurn, destinationInfo[address(destVault)].ownedShares, Math.Rounding.Up ); info.debtMinDecrease += debtMinDecrease; info.debtDecrease += destinationInfo[address(destVault)].cachedDebtValue.mulDiv( dvSharesToBurn, destinationInfo[address(destVault)].ownedShares, Math.Rounding.Up ); info.debtMaxDecrease += destinationInfo[address(destVault)].cachedMaxDebtValue.mulDiv( dvSharesToBurn, destinationInfo[address(destVault)].ownedShares, Math.Rounding.Up ); // If we've exhausted all shares we can remove the withdrawal from the queue // We need to leave it in the debt report queue though so that our destination specific // debt tracking values can be updated if (dvShares == dvSharesToBurn) { withdrawalQueue.popAddress(address(destVault)); } // It's possible we'll get back more assets than we anticipate from a swap // so if we do, throw it in idle and stop processing. You don't get more than we've calculated if (info.assetsPulled >= info.totalAssetsToPull) { info.idleIncrease += info.assetsPulled - info.totalAssetsToPull; info.assetsPulled = info.totalAssetsToPull; break; } // Any deficiency in the amount we received is slippage. debtDecrease is what we expected // to receive. If we received any extra, that's great we'll roll it forward so we burn // less on the next loop. uint256 pulled = Math.max(debtMinDecrease, pulledAssets); if (pulled >= info.assetsToPull) { // We either have enough assets, or we've burned the max debt we're allowed break; } else { info.assetsToPull -= pulled; } // If we didn't exhaust all of the shares from the destination it means we // assume we will get everything we need from there and everything else is slippage if (dvShares != dvSharesToBurn) { break; } } // info.assetsToPull isn't safe to use past this point. // It may or may not be accurate from the previous loop // We didn't get enough assets from the debt pull // See if we can get the rest from idle // Check the debt burned though to ensure that we don't try to make up // slippage incurred out of idle if ( info.assetsPulled < assets && info.debtMinDecrease < assets && info.currentIdle > 0 && exhaustedDestinations ) { uint256 remaining = assets - Math.max(info.assetsPulled, info.debtMinDecrease); if (remaining < info.currentIdle) { info.assetsFromIdle = remaining; } else { info.assetsFromIdle = info.currentIdle; } } debtBurned = info.assetsFromIdle + info.debtMinDecrease; actualAssets = info.assetsFromIdle + info.assetsPulled; actualShares = IAutopool(address(this)).convertToShares( debtBurned, applicableTotalAssets, IAutopool(address(this)).totalSupply(), Math.Rounding.Up ); // Subtract what's taken out of idle from totalIdle // We may also have some increase to account for it we over pulled // or received better execution than we were anticipating // slither-disable-next-line events-maths assetBreakdown.totalIdle = info.currentIdle + info.idleIncrease - info.assetsFromIdle; // Save off our various debt numbers if (info.debtDecrease > assetBreakdown.totalDebt) { assetBreakdown.totalDebt = 0; } else { assetBreakdown.totalDebt -= info.debtDecrease; } if (info.debtMinDecrease > info.totalMinDebt) { assetBreakdown.totalDebtMin = 0; } else { assetBreakdown.totalDebtMin -= info.debtMinDecrease; } if (info.debtMaxDecrease > assetBreakdown.totalDebtMax) { assetBreakdown.totalDebtMax = 0; } else { assetBreakdown.totalDebtMax -= info.debtMaxDecrease; } } /** * @notice Function to complete a withdrawal or redeem. This runs after shares to be burned and assets to be * transferred are calculated. * @param assets Amount of assets to be transferred to receiver. * @param shares Amount of shares to be burned from owner. * @param owner Owner of shares, user to burn shares from. * @param receiver The receiver of the baseAsset. * @param baseAsset Base asset of the Autopool. * @param assetBreakdown Asset breakdown for the Autopool. * @param tokenData Token data for the Autopool. */ function completeWithdrawal( uint256 assets, uint256 shares, address owner, address receiver, IERC20 baseAsset, IAutopool.AssetBreakdown storage assetBreakdown, AutopoolToken.TokenData storage tokenData ) external { if (msg.sender != owner) { uint256 allowed = IAutopool(address(this)).allowance(owner, msg.sender); if (allowed != type(uint256).max) { if (shares > allowed) revert AmountExceedsAllowance(shares, allowed); unchecked { tokenData.approve(owner, msg.sender, allowed - shares); } } } tokenData.burn(owner, shares); uint256 ts = IAutopool(address(this)).totalSupply(); emit Withdraw(msg.sender, receiver, owner, assets, shares); emit Nav(assetBreakdown.totalIdle, assetBreakdown.totalDebt, ts); baseAsset.safeTransfer(receiver, assets); } /** * @notice A helper function to get estimates of what would happen on a withdraw or redeem. * @dev Reverts all changing state. * @param previewWithdraw Bool denoting whether to preview a redeem or withdrawal. * @param assets Assets to be withdrawn or redeemed. * @param applicableTotalAssets Operation dependent assets in the Autopool. * @param functionCallEncoded Abi encoded function signature for recursive call. * @param assetBreakdown Breakdown of vault assets from Autopool storage. * @param withdrawalQueue Destination vault withdrawal queue from Autopool storage. * @param destinationInfo Mapping of information for destinations. * @return assetsAmount Preview of amount of assets to send to receiver. * @return sharesAmount Preview of amount of assets to burn from owner. */ function preview( bool previewWithdraw, uint256 assets, uint256 applicableTotalAssets, bytes memory functionCallEncoded, IAutopool.AssetBreakdown storage assetBreakdown, StructuredLinkedList.List storage withdrawalQueue, mapping(address => AutopoolDebt.DestinationInfo) storage destinationInfo ) external returns (uint256 assetsAmount, uint256 sharesAmount) { if (msg.sender != address(this)) { // Perform a recursive call the function in `funcCallEncoded`. This will result in a call back to // the Autopool, and then this function. The intention is to reach the "else" block in this function. // solhint-disable avoid-low-level-calls // slither-disable-next-line missing-zero-check,low-level-calls (bool success, bytes memory returnData) = address(this).call(functionCallEncoded); // solhint-enable avoid-low-level-calls // If the recursive call is successful, it means an unintended code path was taken. if (success) { revert Errors.UnreachableError(); } bytes4 sharesAmountSig = bytes4(keccak256("SharesAndAssetsReceived(uint256,uint256)")); // Extract the error signature (first 4 bytes) from the revert reason. bytes4 errorSignature; // solhint-disable no-inline-assembly assembly { errorSignature := mload(add(returnData, 0x20)) } // If the error matches the expected signature, extract the amount from the revert reason and return. if (errorSignature == sharesAmountSig) { // Extract subsequent bytes for uint256. assembly { assetsAmount := mload(add(returnData, 0x24)) sharesAmount := mload(add(returnData, 0x44)) } } else { // If the error is not the expected one, forward the original revert reason. assembly { revert(add(32, returnData), mload(returnData)) } } // solhint-enable no-inline-assembly } // This branch is taken during the recursive call. else { // Perform the actual withdrawal or redeem logic to compute the amount. This will be reverted to // simulate the action. uint256 previewAssets; uint256 previewShares; if (previewWithdraw) { (previewAssets, previewShares,) = withdraw(assets, applicableTotalAssets, assetBreakdown, withdrawalQueue, destinationInfo); } else { (previewAssets, previewShares,) = redeem(assets, applicableTotalAssets, assetBreakdown, withdrawalQueue, destinationInfo); } // Revert with the computed amount as an error. revert SharesAndAssetsReceived(previewAssets, previewShares); } } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; /// @notice Stores a reference to the registry for this system interface ISystemComponent { /// @notice The system instance this contract is tied to function getSystemRegistry() external view returns (address registry); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; library StrategyUtils { error CannotConvertUintToInt(); function convertUintToInt(uint256 value) internal pure returns (int256) { // slither-disable-next-line timestamp if (value > uint256(type(int256).max)) revert CannotConvertUintToInt(); return int256(value); } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; library SubSaturateMath { function subSaturate(uint256 self, uint256 other) internal pure returns (uint256) { if (other >= self) return 0; return self - other; } function subSaturate(int256 self, int256 other) internal pure returns (int256) { if (other >= self) return 0; return self - other; } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IDexLSTStats } from "src/interfaces/stats/IDexLSTStats.sol"; import { IAutopoolStrategy } from "src/interfaces/strategy/IAutopoolStrategy.sol"; import { IIncentivesPricingStats } from "src/interfaces/stats/IIncentivesPricingStats.sol"; import { IDestinationVault } from "src/interfaces/vault/IDestinationVault.sol"; import { IStrategy } from "src/interfaces/strategy/IStrategy.sol"; import { IAutopoolStrategy } from "src/interfaces/strategy/IAutopoolStrategy.sol"; import { StrategyUtils } from "src/strategy/libs/StrategyUtils.sol"; import { IDexLSTStats } from "src/interfaces/stats/IDexLSTStats.sol"; import { Incentives } from "src/strategy/libs/Incentives.sol"; import { PriceReturn } from "src/strategy/libs/PriceReturn.sol"; import { IAutopool } from "src/interfaces/vault/IAutopool.sol"; import { ISystemComponent } from "src/interfaces/ISystemComponent.sol"; import { IRootPriceOracle } from "src/interfaces/oracles/IRootPriceOracle.sol"; import { ISystemRegistry } from "src/interfaces/ISystemRegistry.sol"; library SummaryStats { error StaleData(string name); error LstStatsReservesMismatch(); event InLSTPriceGap(address token, uint256 priceSafe, uint256 priceSpot); event OutLSTPriceGap(address token, uint256 priceSafe, uint256 priceSpot); struct InterimStats { uint256 baseApr; int256 priceReturn; int256 maxDiscount; int256 maxPremium; uint256 reservesTotal; int256[] priceReturns; uint256 numLstStats; } function getDestinationSummaryStats( IAutopool autoPool, IIncentivesPricingStats incentivePricing, address destAddress, uint256 price, IAutopoolStrategy.RebalanceDirection direction, uint256 amount ) external returns (IStrategy.SummaryStats memory) { // NOTE: creating this as empty to save on variables later // has the distinct downside that if you forget to update a value, you get the zero value // slither-disable-next-line uninitialized-local IStrategy.SummaryStats memory result; if (destAddress == address(autoPool)) { result.destination = destAddress; result.ownedShares = autoPool.getAssetBreakdown().totalIdle; result.pricePerShare = price; return result; } IDestinationVault dest = IDestinationVault(destAddress); IDexLSTStats.DexLSTStatsData memory stats = dest.getStats().current(); ensureNotStaleData("DexStats", stats.lastSnapshotTimestamp); // temporary holder to reduce variables InterimStats memory interimStats; interimStats.numLstStats = stats.lstStatsData.length; if (interimStats.numLstStats != stats.reservesInEth.length) revert LstStatsReservesMismatch(); interimStats.priceReturns = PriceReturn.calculatePriceReturns(stats); for (uint256 i = 0; i < interimStats.numLstStats; ++i) { uint256 reserveValue = stats.reservesInEth[i]; interimStats.reservesTotal += reserveValue; if (interimStats.priceReturns[i] != 0) { interimStats.priceReturn += PriceReturn.calculateWeightedPriceReturn(interimStats.priceReturns[i], reserveValue, direction); } // For tokens like WETH/ETH who have no data, tokens we've configured as NO_OP's in the // destinations/calculators, we can just skip the rest of these calcs as they have no stats if (stats.lstStatsData[i].baseApr == 0 && stats.lstStatsData[i].lastSnapshotTimestamp == 0) { continue; } ensureNotStaleData("lstData", stats.lstStatsData[i].lastSnapshotTimestamp); interimStats.baseApr += stats.lstStatsData[i].baseApr * reserveValue; int256 discount = stats.lstStatsData[i].discount; // slither-disable-next-line timestamp if (discount < interimStats.maxPremium) { interimStats.maxPremium = discount; } // slither-disable-next-line timestamp if (discount > interimStats.maxDiscount) { interimStats.maxDiscount = discount; } } // if reserves are 0, then leave baseApr + priceReturn as 0 if (interimStats.reservesTotal > 0) { result.baseApr = interimStats.baseApr / interimStats.reservesTotal; result.priceReturn = interimStats.priceReturn / StrategyUtils.convertUintToInt(interimStats.reservesTotal); } result.destination = destAddress; result.feeApr = stats.feeApr; result.incentiveApr = Incentives.calculateIncentiveApr( incentivePricing, stats.stakingIncentiveStats, direction, destAddress, amount, price ); result.safeTotalSupply = stats.stakingIncentiveStats.safeTotalSupply; result.ownedShares = dest.balanceOf(address(autoPool)); result.pricePerShare = price; result.maxPremium = interimStats.maxPremium; result.maxDiscount = interimStats.maxDiscount; uint256 returnExPrice = ( result.baseApr * IAutopoolStrategy(address(this)).weightBase() / 1e6 + result.feeApr * IAutopoolStrategy(address(this)).weightFee() / 1e6 + result.incentiveApr * IAutopoolStrategy(address(this)).weightIncentive() / 1e6 ); // price already weighted result.compositeReturn = StrategyUtils.convertUintToInt(returnExPrice) + result.priceReturn; return result; } // Calculate the largest difference between spot & safe price for the underlying LST tokens. // This does not support Curve meta pools function verifyLSTPriceGap( IAutopool autoPool, IStrategy.RebalanceParams memory params, uint256 tolerance ) external returns (bool) { // Pricer ISystemRegistry registry = ISystemRegistry(ISystemComponent(address(this)).getSystemRegistry()); IRootPriceOracle pricer = registry.rootPriceOracle(); IDestinationVault dest; address[] memory lstTokens; uint256 numLsts; address dvPoolAddress; // Out Destination if (params.destinationOut != address(autoPool)) { dest = IDestinationVault(params.destinationOut); lstTokens = dest.underlyingTokens(); numLsts = lstTokens.length; dvPoolAddress = dest.getPool(); for (uint256 i = 0; i < numLsts; ++i) { uint256 priceSafe = pricer.getPriceInEth(lstTokens[i]); uint256 priceSpot = pricer.getSpotPriceInEth(lstTokens[i], dvPoolAddress); // slither-disable-next-line reentrancy-events emit OutLSTPriceGap(lstTokens[i], priceSafe, priceSpot); // For out destination, the pool tokens should not be lower than safe price by tolerance if ((priceSafe == 0) || (priceSpot == 0)) { return false; } else if (priceSafe > priceSpot) { if (((priceSafe * 1.0e18 / priceSpot - 1.0e18) * 10_000) / 1.0e18 > tolerance) { return false; } } } } // In Destination dest = IDestinationVault(params.destinationIn); lstTokens = dest.underlyingTokens(); numLsts = lstTokens.length; dvPoolAddress = dest.getPool(); for (uint256 i = 0; i < numLsts; ++i) { uint256 priceSafe = pricer.getPriceInEth(lstTokens[i]); uint256 priceSpot = pricer.getSpotPriceInEth(lstTokens[i], dvPoolAddress); // slither-disable-next-line reentrancy-events emit InLSTPriceGap(lstTokens[i], priceSafe, priceSpot); // For in destination, the pool tokens should not be higher than safe price by tolerance if ((priceSafe == 0) || (priceSpot == 0)) { return false; } else if (priceSpot > priceSafe) { if (((priceSpot * 1.0e18 / priceSafe - 1.0e18) * 10_000) / 1.0e18 > tolerance) { return false; } } } return true; } function ensureNotStaleData(string memory name, uint256 dataTimestamp) internal view { // slither-disable-next-line timestamp if (block.timestamp - dataTimestamp > IAutopoolStrategy(address(this)).staleDataToleranceInSeconds()) { revert StaleData(name); } } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { ISystemComponent } from "src/interfaces/ISystemComponent.sol"; import { ISystemRegistry } from "src/interfaces/ISystemRegistry.sol"; import { Errors } from "src/utils/Errors.sol"; contract SystemComponent is ISystemComponent { ISystemRegistry internal immutable systemRegistry; constructor(ISystemRegistry _systemRegistry) { Errors.verifyNotZero(address(_systemRegistry), "_systemRegistry"); systemRegistry = _systemRegistry; } /// @inheritdoc ISystemComponent function getSystemRegistry() external view returns (address) { return address(systemRegistry); } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IDexLSTStats } from "src/interfaces/stats/IDexLSTStats.sol"; import { IAutopoolStrategy } from "src/interfaces/strategy/IAutopoolStrategy.sol"; import { IIncentivesPricingStats } from "src/interfaces/stats/IIncentivesPricingStats.sol"; import { IDestinationVault } from "src/interfaces/vault/IDestinationVault.sol"; import { IERC20Metadata } from "openzeppelin-contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { Math } from "openzeppelin-contracts/utils/math/Math.sol"; library Incentives { using Math for uint256; // when removing liquidity, rewards can be expired by this amount if the pool as incentive credits uint256 public constant EXPIRED_REWARD_TOLERANCE = 7 days; function calculateIncentiveApr( IIncentivesPricingStats pricing, IDexLSTStats.StakingIncentiveStats memory stats, IAutopoolStrategy.RebalanceDirection direction, address destAddress, uint256 lpAmountToAddOrRemove, uint256 lpPrice ) external view returns (uint256) { uint40 staleDataToleranceInSeconds = IAutopoolStrategy(address(this)).staleDataToleranceInSeconds(); bool hasCredits = stats.incentiveCredits > 0; uint256 totalRewards = 0; uint256 numRewards = stats.annualizedRewardAmounts.length; for (uint256 i = 0; i < numRewards; ++i) { address rewardToken = stats.rewardTokens[i]; // Move ahead only if the rewardToken is not 0 if (rewardToken != address(0)) { uint256 tokenPrice = getIncentivePrice(staleDataToleranceInSeconds, pricing, rewardToken); // skip processing if the token is worthless or unregistered if (tokenPrice == 0) continue; uint256 periodFinish = stats.periodFinishForRewards[i]; uint256 rewardRate = stats.annualizedRewardAmounts[i]; uint256 rewardDivisor = 10 ** IERC20Metadata(rewardToken).decimals(); if (direction == IAutopoolStrategy.RebalanceDirection.Out) { // if the destination has credits then extend the periodFinish by the expiredTolerance // this allows destinations that consistently had rewards some leniency if (hasCredits) { periodFinish += EXPIRED_REWARD_TOLERANCE; } // slither-disable-next-line timestamp if (periodFinish > block.timestamp) { // tokenPrice is 1e18 and we want 1e18 out, so divide by the token decimals totalRewards += rewardRate * tokenPrice / rewardDivisor; } } else { // when adding to a destination, count incentives only when either of the following conditions are // met: // 1) the incentive lasts at least 7 days // 2) the incentive lasts >3 days and the destination has a positive incentive credit balance if ( // slither-disable-next-line timestamp periodFinish >= block.timestamp + 7 days || (hasCredits && periodFinish > block.timestamp + 3 days) ) { // tokenPrice is 1e18 and we want 1e18 out, so divide by the token decimals totalRewards += rewardRate * tokenPrice / rewardDivisor; } } } } if (totalRewards == 0) { return 0; } uint256 lpTokenDivisor = 10 ** IDestinationVault(destAddress).decimals(); uint256 totalSupplyInEth = 0; // When comparing in & out destinations, we want to consider the supply with our allocation // included to estimate the resulting incentive rate if (direction == IAutopoolStrategy.RebalanceDirection.Out) { totalSupplyInEth = stats.safeTotalSupply * lpPrice / lpTokenDivisor; } else { totalSupplyInEth = (stats.safeTotalSupply + lpAmountToAddOrRemove) * lpPrice / lpTokenDivisor; } // Adjust for totalSupplyInEth is 0 if (totalSupplyInEth != 0) { return (totalRewards * 1e18) / totalSupplyInEth; } else { return (totalRewards); } } function getIncentivePrice( uint40 staleDataToleranceInSeconds, IIncentivesPricingStats pricing, address token ) public view returns (uint256) { (uint256 fastPrice, uint256 slowPrice) = pricing.getPriceOrZero(token, staleDataToleranceInSeconds); return fastPrice.min(slowPrice); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.7; import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol"; interface IWETH9 is IERC20 { function symbol() external view returns (string memory); function deposit() external payable; function withdraw(uint256 amount) external; }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IERC20Metadata } from "openzeppelin-contracts/token/ERC20/extensions/IERC20Metadata.sol"; interface IAccToke { /////////////////////////////////////////////////////////////////// // Variables /////////////////////////////////////////////////////////////////// function startEpoch() external view returns (uint256); function minStakeDuration() external view returns (uint256); struct Lockup { uint128 amount; uint128 end; uint256 points; } function getLockups(address user) external view returns (Lockup[] memory); function toke() external view returns (IERC20Metadata); /////////////////////////////////////////////////////////////////// // Errors /////////////////////////////////////////////////////////////////// error ZeroAddress(); error StakingDurationTooShort(); error StakingDurationTooLong(); error StakingPointsExceeded(); error IncorrectStakingAmount(); error InsufficientFunds(); error LockupDoesNotExist(); error NotUnlockableYet(); error AlreadyUnlocked(); error ExtendDurationTooShort(); error TransfersDisabled(); error TransferFailed(); error NoRewardsToClaim(); error InsufficientAmount(); error InvalidLockupIds(); error InvalidDurationLength(); /////////////////////////////////////////////////////////////////// // Events /////////////////////////////////////////////////////////////////// event SetMaxStakeDuration(uint256 oldDuration, uint256 newDuration); event Stake(address indexed user, uint256 lockupId, uint256 amount, uint256 end, uint256 points); event Unstake(address indexed user, uint256 lockupId, uint256 amount, uint256 end, uint256 points); event Extend( address indexed user, uint256 lockupId, uint256 amount, uint256 oldEnd, uint256 newEnd, uint256 oldPoints, uint256 newPoints ); event RewardsAdded(uint256 amount, uint256 accRewardPerShare); event RewardsCollected(address indexed user, uint256 amount); event RewardsClaimed(address indexed user, uint256 amount); /////////////////////////////////////////////////////////////////// // // Staking Methods // /////////////////////////////////////////////////////////////////// /** * @notice Stake TOKE to an address that may not be the same as the sender of the funds. This can be used to give * staked funds to someone else. * * If staking before the start of staking (epoch), then the lockup start and end dates are shifted forward so that * the lockup starts at the epoch. * * @param amount TOKE to lockup in the stake * @param duration in seconds for the stake * @param to address to receive ownership of the stake */ function stake(uint256 amount, uint256 duration, address to) external; /** * @notice Stake TOKE * * If staking before the start of staking (epoch), then the lockup start and end dates are shifted forward so that * the lockup starts at the epoch. * * @notice Stake TOKE for myself. * @param amount TOKE to lockup in the stake * @param duration in seconds for the stake */ function stake(uint256 amount, uint256 duration) external; /** * @notice Collect staked TOKE for a lockup and any earned rewards. * @param lockupIds the id of the lockup to unstake */ function unstake(uint256[] memory lockupIds) external; /** * @notice Extend a stake lockup for additional points. * * The stake end time is computed from the current time + duration, just like it is for new stakes. So a new stake * for seven days duration and an old stake extended with a seven days duration would have the same end. * * If an extend is made before the start of staking, the start time for the new stake is shifted forwards to the * start of staking, which also shifts forward the end date. * * @param lockupIds the id of the old lockup to extend * @param durations number of seconds from now to stake for */ function extend(uint256[] memory lockupIds, uint256[] memory durations) external; /////////////////////////////////////////////////////////////////// // // Rewards // /////////////////////////////////////////////////////////////////// /// @notice The total amount of rewards earned for all stakes function totalRewardsEarned() external returns (uint256); /// @notice Total rewards claimed by all stakers function totalRewardsClaimed() external returns (uint256); /// @notice Rewards claimed by a specific wallet /// @param user Address of the wallet to check function rewardsClaimed(address user) external returns (uint256); /** * @notice Preview the number of points that would be returned for the * given amount and duration. * * @param amount TOKE to be staked * @param duration number of seconds to stake for * @return points staking points that would be returned * @return end staking period end date */ function previewPoints(uint256 amount, uint256 duration) external view returns (uint256, uint256); /// @notice Preview the reward amount a caller can claim function previewRewards() external view returns (uint256); /// @notice Preview the reward amount a specified wallet can claim function previewRewards(address user) external view returns (uint256); /// @notice Claim rewards for the caller function collectRewards() external returns (uint256); /// @notice Check if amount can be staked function isStakeableAmount(uint256 amount) external pure returns (bool); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; /// @title Keep track of Vaults created through the Vault Factory interface IAutopoolRegistry { /////////////////////////////////////////////////////////////////// // Errors /////////////////////////////////////////////////////////////////// error VaultNotFound(address vaultAddress); error VaultAlreadyExists(address vaultAddress); /////////////////////////////////////////////////////////////////// // Events /////////////////////////////////////////////////////////////////// event VaultAdded(address indexed asset, address indexed vault); event VaultRemoved(address indexed asset, address indexed vault); /////////////////////////////////////////////////////////////////// // Functions /////////////////////////////////////////////////////////////////// /// @notice Checks if an address is a valid vault /// @param vaultAddress Vault address to be added function isVault(address vaultAddress) external view returns (bool); /// @notice Registers a vault /// @param vaultAddress Vault address to be added function addVault(address vaultAddress) external; /// @notice Removes vault registration /// @param vaultAddress Vault address to be removed function removeVault(address vaultAddress) external; /// @notice Returns a list of all registered vaults function listVaults() external view returns (address[] memory); /// @notice Returns a list of all registered vaults for a given asset /// @param asset Asset address function listVaultsForAsset(address asset) external view returns (address[] memory); /// @notice Returns a list of all registered vaults for a given type /// @param _vaultType Vault type function listVaultsForType(bytes32 _vaultType) external view returns (address[] memory); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IAccessControlEnumerable } from "openzeppelin-contracts/access/IAccessControlEnumerable.sol"; interface IAccessController is IAccessControlEnumerable { error AccessDenied(); /** * @notice Setup a role for an account * @param role The role to setup * @param account The account to setup the role for */ function setupRole(bytes32 role, address account) external; /** * @notice Verify if an account is an owner. Reverts if not * @param account The account to verify */ function verifyOwner(address account) external view; }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { ISyncSwapper } from "src/interfaces/swapper/ISyncSwapper.sol"; interface ISwapRouter { struct SwapData { address token; address pool; ISyncSwapper swapper; bytes data; } error MaxSlippageExceeded(); error SwapRouteLookupFailed(address from, address to); error SwapFailed(); event SwapRouteSet(address indexed token, SwapData[] routes); event SwapForQuoteSuccessful( address indexed assetToken, uint256 sellAmount, address indexed quoteToken, uint256 minBuyAmount, uint256 buyAmount ); /** * @notice Sets a new swap route for a given asset token. * @param assetToken The asset token for which the swap route is being set. * @param _swapRoute The new swap route as an array of SwapData. The last element represents the quoteToken. * @dev Each 'hop' in the swap route is validated using the respective swapper's validate function. The validate * function ensures that the encoded data contains the correct 'fromAddress' and 'toAddress' (swapData.token), and * verifies that these tokens are in the pool. */ function setSwapRoute(address assetToken, SwapData[] calldata _swapRoute) external; /** * @notice Swaps the asset token for the quote token. * @dev We're adopting an "exact in, variable out" model for all our swaps. This ensures that the entire sellAmount * is used, eliminating the need for additional balance checks and refunds. This model is expected to be followed by * all swapper implementations to maintain consistency and to optimize for gas efficiency. * @param assetToken The address of the asset token to swap. * @param sellAmount The exact amount of the asset token to swap. * @param quoteToken The address of the quote token. * @param minBuyAmount The minimum amount of the quote token expected to be received from the swap. * @return The amount received from the swap. */ function swapForQuote( address assetToken, uint256 sellAmount, address quoteToken, uint256 minBuyAmount ) external returns (uint256); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; interface ICurveResolver { /// @notice Resolve details of a Curve pool regardless of type or version /// @dev This resolves tokens without unwrapping to underlying in the case of meta pools. /// @param poolAddress pool address to lookup /// @return tokens tokens that make up the pool /// @return numTokens the number of tokens. tokens are not unwrapped. /// @return isStableSwap is this a StableSwap pool. false = CryptoSwap function resolve(address poolAddress) external view returns (address[8] memory tokens, uint256 numTokens, bool isStableSwap); /// @notice Resolve details of a Curve pool regardless of type or version /// @dev This resolves tokens without unwrapping to underlying in the case of meta pools. /// @dev Use the isStableSwap value to differentiate between StableSwap (V1) and CryptoSwap (V2) pools. /// @param poolAddress pool address to lookup /// @return tokens tokens that make up the pool /// @return numTokens the number of tokens. tokens are not unwrapped /// @return lpToken lp token of the pool /// @return isStableSwap is this a StableSwap pool. false = CryptoSwap function resolveWithLpToken(address poolAddress) external view returns (address[8] memory tokens, uint256 numTokens, address lpToken, bool isStableSwap); /// @notice Get the lp token of a Curve pool /// @param poolAddress pool address to lookup function getLpToken(address poolAddress) external view returns (address); /// @notice Get the reserves of a Curve pools' tokens /// @dev Actual balances length might differ from 8 and should be verified by the caller /// @param poolAddress pool address to lookup /// @return balances reserves of the pool tokens function getReservesInfo(address poolAddress) external view returns (uint256[8] memory balances); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IAutopool } from "src/interfaces/vault/IAutopool.sol"; import { IAutopilotRouterBase } from "src/interfaces/vault/IAutopilotRouterBase.sol"; import { IRewards } from "src/interfaces/rewarders/IRewards.sol"; import { SwapParams } from "src/interfaces/liquidation/IAsyncSwapper.sol"; /** * @title IAutopilotRouter Interface * @notice Extends the IAutopilotRouterBase with specific flows to save gas */ interface IAutopilotRouter is IAutopilotRouterBase { /** * *************************** Deposit ******************************** */ /** * @notice deposit available asset balance to a AutopoolETH. * @param vault The AutopoolETH to deposit assets to. * @param to The destination of ownership shares. * @param minSharesOut The min amount of `vault` shares received by `to`. * @return sharesOut the amount of shares received by `to`. * @dev throws MinSharesError */ function depositBalance(IAutopool vault, address to, uint256 minSharesOut) external returns (uint256 sharesOut); /** * @notice deposit max assets to a AutopoolETH. * @param vault The AutopoolETH to deposit assets to. * @param to The destination of ownership shares. * @param minSharesOut The min amount of `vault` shares received by `to`. * @return sharesOut the amount of shares received by `to`. * @dev throws MinSharesError */ function depositMax(IAutopool vault, address to, uint256 minSharesOut) external returns (uint256 sharesOut); /** * ************************* Withdraw ********************************** */ /** * @notice withdraw `amount` to a AutopoolETH. * @param fromVault The AutopoolETH to withdraw assets from. * @param toVault The AutopoolETH to deposit assets to. * @param to The destination of ownership shares. * @param amount The amount of assets to withdraw from fromVault. * @param maxSharesIn The max amount of fromVault shares withdrawn by caller. * @param minSharesOut The min amount of toVault shares received by `to`. * @return sharesOut the amount of shares received by `to`. * @dev throws MaxSharesError, MinSharesError */ function withdrawToDeposit( IAutopool fromVault, IAutopool toVault, address to, uint256 amount, uint256 maxSharesIn, uint256 minSharesOut ) external returns (uint256 sharesOut); /** * ************************* Redeem ******************************** */ /** * @notice redeem `shares` to a AutopoolETH. * @param fromVault The AutopoolETH to redeem shares from. * @param toVault The AutopoolETH to deposit assets to. * @param to The destination of ownership shares. * @param shares The amount of shares to redeem from fromVault. * @param minSharesOut The min amount of toVault shares received by `to`. * @return sharesOut the amount of shares received by `to`. * @dev throws MinAmountError, MinSharesError */ function redeemToDeposit( IAutopool fromVault, IAutopool toVault, address to, uint256 shares, uint256 minSharesOut ) external returns (uint256 sharesOut); /** * @notice redeem max shares to a AutopoolETH. * @param vault The AutopoolETH to redeem shares from. * @param to The destination of assets. * @param minAmountOut The min amount of assets received by `to`. * @return amountOut the amount of assets received by `to`. * @dev throws MinAmountError */ function redeemMax(IAutopool vault, address to, uint256 minAmountOut) external returns (uint256 amountOut); /** * @notice swaps token * @param swapper Address of the swapper to use * @param swapParams Parameters for the swap * @return amountReceived Swap output amount */ function swapToken(address swapper, SwapParams memory swapParams) external returns (uint256 amountReceived); /** * @notice claims vault token rewards * @param rewarder Address of the rewarder to claim from * @param recipient Struct containing recipient details * @return amountReceived Swap output amount */ function claimRewards( IRewards rewarder, IRewards.Recipient calldata recipient, uint8 v, bytes32 r, bytes32 s ) external returns (uint256); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; interface IAutopoolFactory { /////////////////////////////////////////////////////////////////// // Vault Creation /////////////////////////////////////////////////////////////////// /** * @notice Spin up a new AutopoolETH * @param strategy Strategy template address * @param symbolSuffix Symbol suffix of the new token * @param descPrefix Description prefix of the new token * @param salt Vault creation salt * @param extraParams Any extra data needed for the vault */ function createVault( address strategy, string memory symbolSuffix, string memory descPrefix, bytes32 salt, bytes calldata extraParams ) external payable returns (address newVaultAddress); function addStrategyTemplate(address strategyTemplate) external; function removeStrategyTemplate(address strategyTemplate) external; }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; interface ISystemSecurity { /// @notice Get the number of NAV/share operations currently in progress /// @return Number of operations function navOpsInProgress() external view returns (uint256); /// @notice Called at the start of any NAV/share changing operation function enterNavOperation() external; /// @notice Called at the end of any NAV/share changing operation function exitNavOperation() external; /// @notice Whether or not the system as a whole is paused function isSystemPaused() external view returns (bool); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IDestinationAdapter } from "src/interfaces/destinations/IDestinationAdapter.sol"; interface IDestinationRegistry { event Register(bytes32[] indexed destinationTypes, address[] indexed targets); event Replace(bytes32[] indexed destinationTypes, address[] indexed targets); event Unregister(bytes32[] indexed destinationTypes); event Whitelist(bytes32[] indexed destinationTypes); event RemoveFromWhitelist(bytes32[] indexed destinationTypes); error InvalidAddress(address addr); error NotAllowedDestination(); error DestinationAlreadySet(); /** * @notice Adds a new addresses of the given destination types * @dev Fails if trying to overwrite previous value of the same destination type * @param destinationTypes Ones from the destination type whitelist * @param targets addresses of the deployed DestinationAdapters, cannot be 0 */ function register(bytes32[] calldata destinationTypes, address[] calldata targets) external; /** * @notice Replaces an addresses of the given destination types * @dev Fails if given destination type was not set previously * @param destinationTypes Ones from the destination type whitelist * @param targets addresses of the deployed DestinationAdapters, cannot be 0 */ function replace(bytes32[] calldata destinationTypes, address[] calldata targets) external; /** * @notice Removes an addresses of the given pre-registered destination types * @param destinationTypes Ones from the destination types whitelist */ function unregister(bytes32[] calldata destinationTypes) external; /** * @notice Gives an address of the given destination type * @dev Should revert on missing destination * @param destination One from the destination type whitelist */ function getAdapter(bytes32 destination) external returns (IDestinationAdapter); /** * @notice Adds given destination types to the whitelist * @param destinationTypes Types to whitelist */ function addToWhitelist(bytes32[] calldata destinationTypes) external; /** * @notice Removes given pre-whitelisted destination types * @param destinationTypes Ones from the destination type whitelist */ function removeFromWhitelist(bytes32[] calldata destinationTypes) external; /** * @notice Checks if the given destination type is whitelisted * @param destinationType Type to verify */ function isWhitelistedDestination(bytes32 destinationType) external view returns (bool); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IDestinationVaultFactory } from "src/interfaces/vault/IDestinationVaultFactory.sol"; /// @notice Tracks valid Destination Vaults for the system interface IDestinationVaultRegistry { /// @notice Determines if a given address is a valid Destination Vault in the system /// @param destinationVault address to check /// @return True if vault is registered function isRegistered(address destinationVault) external view returns (bool); /// @notice Registers a new Destination Vault /// @dev Should be locked down to only a factory /// @param newDestinationVault Address of the new vault function register(address newDestinationVault) external; /// @notice Checks if an address is a valid Destination Vault and reverts if not /// @param destinationVault Destination Vault address to checked function verifyIsRegistered(address destinationVault) external view; /// @notice Returns a list of all registered vaults function listVaults() external view returns (address[] memory); /// @notice Factory that is allowed to create and registry Destination Vaults function factory() external view returns (IDestinationVaultFactory); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IStatsCalculator } from "src/interfaces/stats/IStatsCalculator.sol"; /// @notice Track stat calculators for this instance of the system interface IStatsCalculatorRegistry { /// @notice Get a registered calculator /// @dev Should revert if missing /// @param aprId key of the calculator to get /// @return calculator instance of the calculator function getCalculator(bytes32 aprId) external view returns (IStatsCalculator calculator); /// @notice Register a new stats calculator /// @param calculator address of the calculator function register(address calculator) external; /// @notice Set the factory that can register calculators /// @param factory address of the factory function setCalculatorFactory(address factory) external; }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; interface IAsyncSwapperRegistry { event SwapperAdded(address indexed item); event SwapperRemoved(address indexed item); /// @notice Registers an item /// @param item Item address to be added function register(address item) external; /// @notice Removes item registration /// @param item Item address to be removed function unregister(address item) external; /// @notice Returns a list of all registered items function list() external view returns (address[] memory); /// @notice Checks if an address is a valid item /// @param item Item address to be checked function isRegistered(address item) external view returns (bool); /// @notice Checks if an address is a valid swapper and reverts if not /// @param item Swapper address to be checked function verifyIsRegistered(address item) external view; }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; /// @title EWMA pricing for incentive tokens interface IIncentivesPricingStats { event TokenAdded(address indexed token); event TokenRemoved(address indexed token); event TokenSnapshot( address indexed token, uint40 lastSnapshot, uint256 fastFilterPrice, uint256 slowFilterPrice, uint256 initCount, bool initComplete ); error TokenAlreadyRegistered(address token); error TokenNotFound(address token); error IncentiveTokenPriceStale(address token); error TokenSnapshotNotReady(address token); struct TokenSnapshotInfo { uint40 lastSnapshot; bool _initComplete; uint8 _initCount; uint256 _initAcc; uint256 fastFilterPrice; uint256 slowFilterPrice; } /// @notice add a token to snapshot /// @dev the token must be configured in the RootPriceOracle before adding here /// @param token the address of the token to add function setRegisteredToken(address token) external; /// @notice remove a token from being snapshot /// @param token the address of the token to remove function removeRegisteredToken(address token) external; /// @notice get the addresses for all currently registered tokens /// @return tokens all of the registered token addresses function getRegisteredTokens() external view returns (address[] memory tokens); /// @notice get all of the registered tokens with the latest snapshot info /// @return tokenAddresses token addresses in the same order as info /// @return info a list of snapshot info for the tokens function getTokenPricingInfo() external view returns (address[] memory tokenAddresses, TokenSnapshotInfo[] memory info); /// @notice update the snapshot for the specified tokens /// @dev if a token is not ready to be snapshot the entire call will fail function snapshot(address[] calldata tokensToSnapshot) external; /// @notice get the latest prices for an incentive token. Reverts if token is not registered /// @return fastPrice the price based on the faster filter (weighted toward current prices) /// @return slowPrice the price based on the slower filter (weighted toward older prices, relative to fast) function getPrice(address token, uint40 staleCheck) external view returns (uint256 fastPrice, uint256 slowPrice); /// @notice get the latest prices for an incentive token or zero if the token is not registered /// @return fastPrice the price based on the faster filter (weighted toward current prices) /// @return slowPrice the price based on the slower filter (weighted toward older prices, relative to fast) function getPriceOrZero( address token, uint40 staleCheck ) external view returns (uint256 fastPrice, uint256 slowPrice); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; /// @title Send messages to our systems on other chains interface IMessageProxy { function sendMessage(bytes32 messageType, bytes memory message) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; interface IBaseAssetVault { /// @notice Asset that this Vault primarily manages /// @dev Vault decimals should be the same as the baseAsset function baseAsset() external view returns (address); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IBaseRewarder } from "src/interfaces/rewarders/IBaseRewarder.sol"; import { IExtraRewarder } from "src/interfaces/rewarders/IExtraRewarder.sol"; interface IMainRewarder is IBaseRewarder { error ExtraRewardsNotAllowed(); event ExtraRewardAdded(address reward); event ExtraRewardsCleared(); event ExtraRewardRemoved(address reward); /** * @notice Adds an ExtraRewarder contract address to the extraRewards array. * @param reward The address of the ExtraRewarder contract. */ function addExtraReward(address reward) external; /** * @notice Removes a list of ExtraRewarder contract addresses from the extraRewards array. */ function removeExtraRewards(address[] calldata _rewards) external; /** * @notice Withdraws the specified amount of tokens from the vault for the specified account, and transfers all * rewards for the account from this contract and any linked extra reward contracts. * @param account The address of the account to withdraw tokens and claim rewards for. * @param amount The amount of tokens to withdraw. * @param claim If true, claims all rewards for the account from this contract and any linked extra reward * contracts. */ function withdraw(address account, uint256 amount, bool claim) external; /** * @notice Clears the extraRewards array. */ function clearExtraRewards() external; /** * @notice Claims and transfers all rewards for the specified account from this contract and any linked extra reward * contracts. * @dev If claimExtras is true, also claims all rewards from linked extra reward contracts. * @param account The address of the account to claim rewards for. * @param claimExtras If true, claims rewards from linked extra reward contracts. */ function getReward(address account, bool claimExtras) external; /** * @notice Number of extra rewards currently registered */ function extraRewardsLength() external view returns (uint256); /** * @notice Get the extra rewards array values */ function extraRewards() external view returns (address[] memory); /** * @notice Get the rewarder at the specified index */ function getExtraRewarder(uint256 index) external view returns (IExtraRewarder); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (interfaces/IERC3156FlashBorrower.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC3156 FlashBorrower, as defined in * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156]. * * _Available since v4.1._ */ interface IERC3156FlashBorrower { /** * @dev Receive a flash loan. * @param initiator The initiator of the loan. * @param token The loan currency. * @param amount The amount of tokens lent. * @param fee The additional amount of tokens to repay. * @param data Arbitrary data structure, intended to contain user-defined parameters. * @return The keccak256 hash of "IERC3156FlashBorrower.onFlashLoan" */ function onFlashLoan( address initiator, address token, uint256 amount, uint256 fee, bytes calldata data ) external returns (bytes32); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; import { IERC20Metadata } from "openzeppelin-contracts/token/ERC20/extensions/IERC20Metadata.sol"; /// @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in https://eips.ethereum.org/EIPS/eip-4626 /// @dev Due to the nature of obtaining estimates for previewing withdraws and redeems, a few functions are not /// view and therefore do not conform to eip 4626. These functions use state changing operations /// to get accurate estimates, reverting after the preview amounts have been obtained. interface IERC4626 is IERC20Metadata { event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares); event Withdraw( address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares ); /// @notice Returns the address of the underlying token used for the Vault for accounting, depositing, and /// withdrawing. /// @dev /// - MUST be an ERC-20 token contract. /// - MUST NOT revert. function asset() external view returns (address assetTokenAddress); /// @notice Returns the total amount of the underlying asset that is “managed” by Vault. /// @dev /// - SHOULD include any compounding that occurs from yield. /// - MUST be inclusive of any fees that are charged against assets in the Vault. /// - MUST NOT revert. function totalAssets() external view returns (uint256 totalManagedAssets); /// @notice Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an /// ideal /// scenario where all the conditions are met. /// @dev /// - MUST NOT be inclusive of any fees that are charged against assets in the Vault. /// - MUST NOT show any variations depending on the caller. /// - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange. /// - MUST NOT revert. /// /// NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the /// “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and /// from. function convertToShares(uint256 assets) external view returns (uint256 shares); /// @notice Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an /// ideal /// scenario where all the conditions are met. /// @dev /// - MUST NOT be inclusive of any fees that are charged against assets in the Vault. /// - MUST NOT show any variations depending on the caller. /// - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange. /// - MUST NOT revert. /// /// NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the /// “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and /// from. function convertToAssets(uint256 shares) external view returns (uint256 assets); /// @notice Returns the maximum amount of the underlying asset that can be deposited into the Vault for the /// receiver, /// through a deposit call. /// @dev /// - MUST return a limited value if receiver is subject to some deposit limit. /// - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited. /// - MUST NOT revert. function maxDeposit(address receiver) external returns (uint256 maxAssets); /// @notice Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, /// given /// current on-chain conditions. /// @dev /// - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit /// call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called /// in the same transaction. /// - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the /// deposit would be accepted, regardless if the user has enough tokens approved, etc. /// - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees. /// - MUST NOT revert. /// /// NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in /// share price or some other type of condition, meaning the depositor will lose assets by depositing. function previewDeposit(uint256 assets) external returns (uint256 shares); /// @notice Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens. /// @dev /// - MUST emit the Deposit event. /// - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the /// deposit execution, and are accounted for during deposit. /// - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not /// approving enough underlying tokens to the Vault contract, etc). /// /// NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token. function deposit(uint256 assets, address receiver) external returns (uint256 shares); /// @notice Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call. /// @dev /// - MUST return a limited value if receiver is subject to some mint limit. /// - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted. /// - MUST NOT revert. function maxMint(address receiver) external returns (uint256 maxShares); /// @notice Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given /// current on-chain conditions. /// @dev /// - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call /// in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the /// same transaction. /// - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint /// would be accepted, regardless if the user has enough tokens approved, etc. /// - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees. /// - MUST NOT revert. /// /// NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in /// share price or some other type of condition, meaning the depositor will lose assets by minting. function previewMint(uint256 shares) external returns (uint256 assets); /// @notice Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens. /// @dev /// - MUST emit the Deposit event. /// - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint /// execution, and are accounted for during mint. /// - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not /// approving enough underlying tokens to the Vault contract, etc). /// /// NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token. function mint(uint256 shares, address receiver) external returns (uint256 assets); /// @notice Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the /// Vault, through a withdraw call. /// @dev /// - MUST return a limited value if owner is subject to some withdrawal limit or timelock. /// - MUST NOT revert. function maxWithdraw(address owner) external returns (uint256 maxAssets); /// @notice Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block, /// given current on-chain conditions. /// @dev /// - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw /// call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if /// called /// in the same transaction. /// - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though /// the withdrawal would be accepted, regardless if the user has enough shares, etc. /// - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees. /// - MUST NOT revert. /// /// NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in /// share price or some other type of condition, meaning the depositor will lose assets by depositing. function previewWithdraw(uint256 assets) external returns (uint256 shares); /// @notice Burns shares from owner and sends exactly assets of underlying tokens to receiver. /// @dev /// - MUST emit the Withdraw event. /// - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the /// withdraw execution, and are accounted for during withdraw. /// - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner /// not having enough shares, etc). /// /// Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed. /// Those methods should be performed separately. function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares); /// @notice Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault, /// through a redeem call. /// @dev /// - MUST return a limited value if owner is subject to some withdrawal limit or timelock. /// - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock. /// - MUST NOT revert. function maxRedeem(address owner) external returns (uint256 maxShares); /// @notice Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block, /// given current on-chain conditions. /// @dev /// - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call /// in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the /// same transaction. /// - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the /// redemption would be accepted, regardless if the user has enough shares, etc. /// - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees. /// - MUST NOT revert. /// /// NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in /// share price or some other type of condition, meaning the depositor will lose assets by redeeming. function previewRedeem(uint256 shares) external returns (uint256 assets); /// @notice Burns exactly shares from owner and sends assets of underlying tokens to receiver. /// @dev /// - MUST emit the Withdraw event. /// - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the /// redeem execution, and are accounted for during redeem. /// - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner /// not having enough shares, etc). /// /// NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed. /// Those methods should be performed separately. function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol"; import { SafeERC20 } from "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol"; library LibAdapter { using SafeERC20 for IERC20; address public constant CURVE_REGISTRY_ETH_ADDRESS_POINTER = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; error MinLpAmountNotReached(); error LpTokenAmountMismatch(); error NoNonZeroAmountProvided(); error InvalidBalanceChange(); // Utils function _approve(IERC20 token, address spender, uint256 amount) internal { uint256 currentAllowance = token.allowance(address(this), spender); if (currentAllowance > 0) { token.safeDecreaseAllowance(spender, currentAllowance); } token.safeIncreaseAllowance(spender, amount); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT pragma solidity =0.8.17; /** * @title StructuredLinkedList * @author Vittorio Minacori (https://github.com/vittominacori) * @dev An utility library for using sorted linked list data structures in your Solidity project. * @notice Adapted from * https://github.com/Layr-Labs/eigenlayer-contracts/blob/master/src/contracts/libraries/StructuredLinkedList.sol */ library StructuredLinkedList { uint256 private constant _NULL = 0; uint256 private constant _HEAD = 0; bool private constant _PREV = false; bool private constant _NEXT = true; struct List { uint256 size; mapping(uint256 => mapping(bool => uint256)) list; } /** * @dev Checks if the list exists * @param self stored linked list from contract * @return bool true if list exists, false otherwise */ function listExists(List storage self) public view returns (bool) { // if the head nodes previous or next pointers both point to itself, then there are no items in the list if (self.list[_HEAD][_PREV] != _HEAD || self.list[_HEAD][_NEXT] != _HEAD) { return true; } else { return false; } } /** * @dev Checks if the node exists * @param self stored linked list from contract * @param _node a node to search for * @return bool true if node exists, false otherwise */ function nodeExists(List storage self, uint256 _node) public view returns (bool) { if (self.list[_node][_PREV] == _HEAD && self.list[_node][_NEXT] == _HEAD) { if (self.list[_HEAD][_NEXT] == _node) { return true; } else { return false; } } else { return true; } } /** * @dev Returns the number of elements in the list * @param self stored linked list from contract * @return uint256 */ // slither-disable-next-line dead-code function sizeOf(List storage self) public view returns (uint256) { return self.size; } /** * @dev Gets the head of the list * @param self stored linked list from contract * @return uint256 the head of the list */ function getHead(List storage self) public view returns (uint256) { return self.list[_HEAD][_NEXT]; } /** * @dev Gets the head of the list * @param self stored linked list from contract * @return uint256 the head of the list */ function getTail(List storage self) public view returns (uint256) { return self.list[_HEAD][_PREV]; } /** * @dev Returns the links of a node as a tuple * @param self stored linked list from contract * @param _node id of the node to get * @return bool, uint256, uint256 true if node exists or false otherwise, previous node, next node */ // slither-disable-next-line dead-code function getNode(List storage self, uint256 _node) public view returns (bool, uint256, uint256) { if (!nodeExists(self, _node)) { return (false, 0, 0); } else { return (true, self.list[_node][_PREV], self.list[_node][_NEXT]); } } /** * @dev Returns the link of a node `_node` in direction `_direction`. * @param self stored linked list from contract * @param _node id of the node to step from * @param _direction direction to step in * @return bool, uint256 true if node exists or false otherwise, node in _direction */ // slither-disable-next-line dead-code function getAdjacent(List storage self, uint256 _node, bool _direction) public view returns (bool, uint256) { if (!nodeExists(self, _node)) { return (false, 0); } else { uint256 adjacent = self.list[_node][_direction]; return (adjacent != _HEAD, adjacent); } } /** * @dev Returns the link of a node `_node` in direction `_NEXT`. * @param self stored linked list from contract * @param _node id of the node to step from * @return bool, uint256 true if node exists or false otherwise, next node */ // slither-disable-next-line dead-code function getNextNode(List storage self, uint256 _node) public view returns (bool, uint256) { return getAdjacent(self, _node, _NEXT); } /** * @dev Returns the link of a node `_node` in direction `_PREV`. * @param self stored linked list from contract * @param _node id of the node to step from * @return bool, uint256 true if node exists or false otherwise, previous node */ // slither-disable-next-line dead-code function getPreviousNode(List storage self, uint256 _node) public view returns (bool, uint256) { return getAdjacent(self, _node, _PREV); } /** * @dev Insert node `_new` beside existing node `_node` in direction `_NEXT`. * @param self stored linked list from contract * @param _node existing node * @param _new new node to insert * @return bool true if success, false otherwise */ // slither-disable-next-line dead-code function insertAfter(List storage self, uint256 _node, uint256 _new) public returns (bool) { return _insert(self, _node, _new, _NEXT); } /** * @dev Insert node `_new` beside existing node `_node` in direction `_PREV`. * @param self stored linked list from contract * @param _node existing node * @param _new new node to insert * @return bool true if success, false otherwise */ // slither-disable-next-line dead-code function insertBefore(List storage self, uint256 _node, uint256 _new) public returns (bool) { return _insert(self, _node, _new, _PREV); } /** * @dev Removes an entry from the linked list * @param self stored linked list from contract * @param _node node to remove from the list * @return uint256 the removed node */ function remove(List storage self, uint256 _node) public returns (uint256) { if ((_node == _NULL) || (!nodeExists(self, _node))) { return 0; } _createLink(self, self.list[_node][_PREV], self.list[_node][_NEXT], _NEXT); delete self.list[_node][_PREV]; delete self.list[_node][_NEXT]; self.size -= 1; return _node; } /** * @dev Pushes an entry to the head of the linked list * @param self stored linked list from contract * @param _node new entry to push to the head * @return bool true if success, false otherwise */ function pushFront(List storage self, uint256 _node) public returns (bool) { return _push(self, _node, _NEXT); } /** * @dev Pushes an entry to the tail of the linked list * @param self stored linked list from contract * @param _node new entry to push to the tail * @return bool true if success, false otherwise */ function pushBack(List storage self, uint256 _node) public returns (bool) { return _push(self, _node, _PREV); } /** * @dev Pops the first entry from the head of the linked list * @param self stored linked list from contract * @return uint256 the removed node */ // slither-disable-next-line dead-code function popFront(List storage self) public returns (uint256) { return _pop(self, _NEXT); } /** * @dev Pops the first entry from the tail of the linked list * @param self stored linked list from contract * @return uint256 the removed node */ // slither-disable-next-line dead-code function popBack(List storage self) public returns (uint256) { return _pop(self, _PREV); } /** * @dev Pushes an entry to the head of the linked list * @param self stored linked list from contract * @param _node new entry to push to the head * @param _direction push to the head (_NEXT) or tail (_PREV) * @return bool true if success, false otherwise */ function _push(List storage self, uint256 _node, bool _direction) private returns (bool) { return _insert(self, _HEAD, _node, _direction); } /** * @dev Pops the first entry from the linked list * @param self stored linked list from contract * @param _direction pop from the head (_NEXT) or the tail (_PREV) * @return uint256 the removed node */ // slither-disable-next-line dead-code function _pop(List storage self, bool _direction) private returns (uint256) { uint256 adj; (, adj) = getAdjacent(self, _HEAD, _direction); return remove(self, adj); } /** * @dev Insert node `_new` beside existing node `_node` in direction `_direction`. * @param self stored linked list from contract * @param _node existing node * @param _new new node to insert * @param _direction direction to insert node in * @return bool true if success, false otherwise */ function _insert(List storage self, uint256 _node, uint256 _new, bool _direction) private returns (bool) { if (!nodeExists(self, _new) && nodeExists(self, _node)) { uint256 c = self.list[_node][_direction]; _createLink(self, _node, _new, _direction); _createLink(self, _new, c, _direction); self.size += 1; return true; } return false; } /** * @dev Creates a bidirectional link between two nodes on direction `_direction` * @param self stored linked list from contract * @param _node existing node * @param _link node to link to in the _direction * @param _direction direction to insert node in */ function _createLink(List storage self, uint256 _node, uint256 _link, bool _direction) private { self.list[_link][!_direction] = _node; self.list[_node][_direction] = _link; } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; // their version was using 8.12? import { StructuredLinkedList } from "src/strategy/StructuredLinkedList.sol"; // https://github.com/Layr-Labs/eigenlayer-contracts/blob/master/src/contracts/libraries/StructuredLinkedList.sol library WithdrawalQueue { using StructuredLinkedList for StructuredLinkedList.List; error CannotInsertZeroAddress(); error UnexpectedNodeRemoved(); error AddToHeadFailed(); error AddToTailFailed(); error NodeDoesNotExist(); /// @notice Returns true if the address is in the queue. function addressExists(StructuredLinkedList.List storage queue, address addr) public view returns (bool) { return StructuredLinkedList.nodeExists(queue, _addressToUint(addr)); } /// @notice Returns the current head. function peekHead(StructuredLinkedList.List storage queue) public view returns (address) { return _uintToAddress(StructuredLinkedList.getHead(queue)); } /// @notice Returns the current tail. function peekTail(StructuredLinkedList.List storage queue) public view returns (address) { return _uintToAddress(StructuredLinkedList.getTail(queue)); } /// @notice Returns the number of items in the queue function sizeOf(StructuredLinkedList.List storage queue) public view returns (uint256) { return StructuredLinkedList.sizeOf(queue); } /// @notice Return all items in the queue /// @dev Enumerates from head to tail function getList(StructuredLinkedList.List storage self) public view returns (address[] memory list) { uint256 size = self.sizeOf(); list = new address[](size); if (size > 0) { uint256 lastNode = self.getHead(); list[0] = _uintToAddress(lastNode); for (uint256 i = 1; i < size; ++i) { (bool exists, uint256 node) = self.getAdjacent(lastNode, true); if (!exists) { revert NodeDoesNotExist(); } list[i] = _uintToAddress(node); lastNode = node; } } } /// @notice Returns the current tail. function popHead(StructuredLinkedList.List storage queue) public returns (address) { return _uintToAddress(StructuredLinkedList.popFront(queue)); } /// @notice remove address toRemove from queue if it exists. function popAddress(StructuredLinkedList.List storage queue, address toRemove) public { uint256 addrAsUint = _addressToUint(toRemove); uint256 _removedNode = StructuredLinkedList.remove(queue, addrAsUint); if (!((_removedNode == addrAsUint) || (_removedNode == 0))) { revert UnexpectedNodeRemoved(); } } /// @notice returns true if there are no addresses in queue. function isEmpty(StructuredLinkedList.List storage queue) public view returns (bool) { return !StructuredLinkedList.listExists(queue); } /// @notice if addr in queue, move it to the top // if addr not in queue, add it to the top of the queue. // if queue is empty, make a new queue with addr as the only node function addToHead(StructuredLinkedList.List storage queue, address addr) public { if (addr == address(0)) { revert CannotInsertZeroAddress(); } popAddress(queue, addr); bool success = StructuredLinkedList.pushFront(queue, _addressToUint(addr)); if (!success) { revert AddToHeadFailed(); } } function getAdjacent( StructuredLinkedList.List storage queue, address addr, bool direction ) public view returns (address) { (bool exists, uint256 addrNum) = queue.getAdjacent(_addressToUint(addr), direction); if (!exists) { return address(0); } return _uintToAddress(addrNum); } /// @notice if addr in queue, move it to the end // if addr not in queue, add it to the end of the queue. // if queue is empty, make a new queue with addr as the only node function addToTail(StructuredLinkedList.List storage queue, address addr) public { if (addr == address(0)) { revert CannotInsertZeroAddress(); } popAddress(queue, addr); bool success = StructuredLinkedList.pushBack(queue, _addressToUint(addr)); if (!success) { revert AddToTailFailed(); } } function _addressToUint(address addr) private pure returns (uint256) { return uint256(uint160(addr)); } function _uintToAddress(uint256 x) private pure returns (address) { return address(uint160(x)); } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { ECDSA } from "openzeppelin-contracts/utils/cryptography/ECDSA.sol"; import { IERC20Permit } from "openzeppelin-contracts/token/ERC20/extensions/draft-IERC20Permit.sol"; /// @notice ERC20 token functionality converted into a library. Based on OZ's v5 /// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.1/contracts/token/ERC20/ERC20.sol library AutopoolToken { struct TokenData { /// @notice Token balances /// @dev account => balance mapping(address => uint256) balances; /// @notice Account spender allowances /// @dev account => spender => allowance mapping(address => mapping(address => uint256)) allowances; /// @notice Total supply of the pool. Be careful when using this directly from the struct. The pool itself /// modifies this number based on unlocked profited shares uint256 totalSupply; /// @notice ERC20 Permit nonces /// @dev account -> nonce. Exposed via `nonces(owner)` mapping(address => uint256) nonces; } /// @notice EIP2612 permit type hash bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); /// @notice EIP712 domain type hash bytes32 public constant TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); /// @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. /// @param sender Address whose tokens are being transferred. /// @param balance Current balance for the interacting account. /// @param needed Minimum amount required to perform a transfer. error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed); /// @dev Indicates a failure with the token `sender`. Used in transfers. /// @param sender Address whose tokens are being transferred. error ERC20InvalidSender(address sender); /// @dev Indicates a failure with the token `receiver`. Used in transfers. /// @param receiver Address to which tokens are being transferred. error ERC20InvalidReceiver(address receiver); /// @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers. ///@param spender Address that may be allowed to operate on tokens without being their owner. /// @param allowance Amount of tokens a `spender` is allowed to operate with. ///@param needed Minimum amount required to perform a transfer. error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed); /// @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. /// @param approver Address initiating an approval operation. error ERC20InvalidApprover(address approver); /// @dev Indicates a failure with the `spender` to be approved. Used in approvals. /// @param spender Address that may be allowed to operate on tokens without being their owner. error ERC20InvalidSpender(address spender); /// @dev Permit deadline has expired. error ERC2612ExpiredSignature(uint256 deadline); /// @dev Mismatched signature. error ERC2612InvalidSigner(address signer, address owner); /// @dev The nonce used for an `account` is not the expected current nonce. error InvalidAccountNonce(address account, uint256 currentNonce); /// @dev Emitted when `value` tokens are moved from one account `from` to another `to`. event Transfer(address indexed from, address indexed to, uint256 value); /// @dev Emitted when the allowance of a `spender` for an `owner` is set by a call to {approve}. /// `value` is the new allowance. event Approval(address indexed owner, address indexed spender, uint256 value); /// @dev Sets a `value` amount of tokens as the allowance of `spender` over the caller's tokens. function approve(TokenData storage data, address spender, uint256 value) external returns (bool) { address owner = msg.sender; approve(data, owner, spender, value); return true; } /// @dev Sets `value` as the allowance of `spender` over the `owner` s tokens. function approve(TokenData storage data, address owner, address spender, uint256 value) public { _approve(data, owner, spender, value, true); } function transfer(TokenData storage data, address to, uint256 value) external returns (bool) { address owner = msg.sender; _transfer(data, owner, to, value); return true; } /// @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism. /// value` is then deducted from the caller's allowance. function transferFrom(TokenData storage data, address from, address to, uint256 value) external returns (bool) { address spender = msg.sender; _spendAllowance(data, from, spender, value); _transfer(data, from, to, value); return true; } /// @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0). function mint(TokenData storage data, address account, uint256 value) external { if (account == address(0)) { revert ERC20InvalidReceiver(address(0)); } _update(data, address(0), account, value); } /// @dev Destroys a `value` amount of tokens from `account`, lowering the total supply. function burn(TokenData storage data, address account, uint256 value) external { if (account == address(0)) { revert ERC20InvalidSender(address(0)); } _update(data, account, address(0), value); } function permit( TokenData storage data, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external { if (block.timestamp > deadline) { revert ERC2612ExpiredSignature(deadline); } uint256 nonce; // For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be // decremented or reset. This guarantees that the nonce never overflows. unchecked { // It is important to do x++ and not ++x here. Nonces starts at 0 nonce = data.nonces[owner]++; } bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonce, deadline)); bytes32 hash = ECDSA.toTypedDataHash(IERC20Permit(address(this)).DOMAIN_SEPARATOR(), structHash); address signer = ECDSA.recover(hash, v, r, s); if (signer != owner) { revert ERC2612InvalidSigner(signer, owner); } approve(data, owner, spender, value); } /// @dev Moves a `value` amount of tokens from `from` to `to`. function _transfer(TokenData storage data, address from, address to, uint256 value) private { if (from == address(0)) { revert ERC20InvalidSender(address(0)); } if (to == address(0)) { revert ERC20InvalidReceiver(address(0)); } _update(data, from, to, value); } /// @dev Updates `owner` s allowance for `spender` based on spent `value`. function _spendAllowance(TokenData storage data, address owner, address spender, uint256 value) private { uint256 currentAllowance = data.allowances[owner][spender]; if (currentAllowance != type(uint256).max) { if (currentAllowance < value) { revert ERC20InsufficientAllowance(spender, currentAllowance, value); } unchecked { _approve(data, owner, spender, currentAllowance - value, false); } } } /// @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from` /// (or `to`) is the zero address. function _update(TokenData storage data, address from, address to, uint256 value) private { if (from == address(0)) { // Overflow check required: The rest of the code assumes that totalSupply never overflows data.totalSupply += value; } else { uint256 fromBalance = data.balances[from]; if (fromBalance < value) { revert ERC20InsufficientBalance(from, fromBalance, value); } unchecked { // Overflow not possible: value <= fromBalance <= totalSupply. data.balances[from] = fromBalance - value; } } if (to == address(0)) { unchecked { // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply. data.totalSupply -= value; } } else { unchecked { // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256. data.balances[to] += value; } } emit Transfer(from, to, value); } /// @dev Variant of `_approve` with an optional flag to enable or disable the Approval event. function _approve(TokenData storage data, address owner, address spender, uint256 value, bool emitEvent) private { if (owner == address(0)) { revert ERC20InvalidApprover(address(0)); } if (spender == address(0)) { revert ERC20InvalidSpender(address(0)); } data.allowances[owner][spender] = value; if (emitEvent) { emit Approval(owner, spender, value); } } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IAutopoolStrategy } from "src/interfaces/strategy/IAutopoolStrategy.sol"; import { StrategyUtils } from "src/strategy/libs/StrategyUtils.sol"; import { IDexLSTStats } from "src/interfaces/stats/IDexLSTStats.sol"; import { ILSTStats } from "src/interfaces/stats/ILSTStats.sol"; library PriceReturn { function calculateWeightedPriceReturn( int256 priceReturn, uint256 reserveValue, IAutopoolStrategy.RebalanceDirection direction ) external view returns (int256) { IAutopoolStrategy strategy = IAutopoolStrategy(address(this)); // slither-disable-next-line timestamp if (priceReturn > 0) { // LST trading at a discount if (direction == IAutopoolStrategy.RebalanceDirection.Out) { return priceReturn * StrategyUtils.convertUintToInt(reserveValue) * strategy.weightPriceDiscountExit() / 1e6; } else { return priceReturn * StrategyUtils.convertUintToInt(reserveValue) * strategy.weightPriceDiscountEnter() / 1e6; } } else { // LST trading at 0 or a premium return priceReturn * StrategyUtils.convertUintToInt(reserveValue) * strategy.weightPricePremium() / 1e6; } } function calculatePriceReturns(IDexLSTStats.DexLSTStatsData memory stats) external view returns (int256[] memory) { IAutopoolStrategy strategy = IAutopoolStrategy(address(this)); ILSTStats.LSTStatsData[] memory lstStatsData = stats.lstStatsData; uint256 numLsts = lstStatsData.length; int256[] memory priceReturns = new int256[](numLsts); for (uint256 i = 0; i < numLsts; ++i) { ILSTStats.LSTStatsData memory data = lstStatsData[i]; uint256 scalingFactor = 1e18; // default scalingFactor is 1 int256 discount = data.discount; if (discount > strategy.maxAllowedDiscount()) { discount = strategy.maxAllowedDiscount(); } // discount value that is negative indicates LST price premium // scalingFactor = 1e18 for premiums and discounts that are small // discountTimestampByPercent array holds the timestamp in position i for discount = (i+1)% uint40[5] memory discountTimestampByPercent = data.discountTimestampByPercent; // 1e16 means a 1% LST discount where full scale is 1e18. if (discount > 1e16) { // linear approximation for exponential function with approx. half life of 30 days uint256 halfLifeSec = 30 * 24 * 60 * 60; uint256 len = data.discountTimestampByPercent.length; for (uint256 j = 1; j < len; ++j) { // slither-disable-next-line timestamp if (discount <= StrategyUtils.convertUintToInt((j + 1) * 1e16)) { // current timestamp should be strictly >= timestamp in discountTimestampByPercent uint256 timeSinceDiscountSec = uint256(uint40(block.timestamp) - discountTimestampByPercent[j - 1]); scalingFactor >>= (timeSinceDiscountSec / halfLifeSec); // slither-disable-next-line weak-prng timeSinceDiscountSec %= halfLifeSec; scalingFactor -= scalingFactor * timeSinceDiscountSec / halfLifeSec / 2; break; } } } priceReturns[i] = discount * StrategyUtils.convertUintToInt(scalingFactor) / 1e18; } return priceReturns; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; /** * @dev External interface of AccessControlEnumerable declared to support ERC165 detection. */ interface IAccessControlEnumerable is IAccessControl { /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) external view returns (address); /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) external view returns (uint256); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { ISwapRouter } from "src/interfaces/swapper/ISwapRouter.sol"; interface ISyncSwapper { error DataMismatch(string element); error InvalidIndex(); /** * @notice Swaps sellToken for buyToken * @param pool The address of the pool for the swapper * @param sellTokenAddress The address of the token to sell * @param sellAmount The amount of sellToken to sell * @param buyTokenAddress The address of the token to buy * @param minBuyAmount The minimum amount of buyToken expected * @param data Additional data used differently by the different swappers * @return actualBuyAmount The actual amount received from the swap */ function swap( address pool, address sellTokenAddress, uint256 sellAmount, address buyTokenAddress, uint256 minBuyAmount, bytes memory data ) external returns (uint256 actualBuyAmount); /** * @notice Validates that the swapData contains the correct information, ensuring that the encoded data contains the * correct 'fromAddress' and 'toAddress' (swapData.token), and verifies that these tokens are in the pool * @dev This function should revert with a DataMismatch error if the swapData is invalid * @param fromAddress The address from which the swap originates * @param swapData The data associated with the swap that needs to be validated */ function validate(address fromAddress, ISwapRouter.SwapData memory swapData) external view; }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity >=0.8.7; import { IAutopool } from "src/interfaces/vault/IAutopool.sol"; import { IMainRewarder } from "src/interfaces/rewarders/IMainRewarder.sol"; import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol"; /** * @title AutopoolETH Router Base Interface * @notice A canonical router between AutopoolETHs * * The base router is a multicall style router inspired by Uniswap v3 with built-in features for permit, * WETH9 wrap/unwrap, and ERC20 token pulling/sweeping/approving. It includes methods for the four mutable * ERC4626 functions deposit/mint/withdraw/redeem as well. * * These can all be arbitrarily composed using the multicall functionality of the router. * * NOTE the router is capable of pulling any approved token from your wallet. This is only possible when * your address is msg.sender, but regardless be careful when interacting with the router or ERC4626 Vaults. * The router makes no special considerations for unique ERC20 implementations such as fee on transfer. * There are no built in protections for unexpected behavior beyond enforcing the minSharesOut is received. */ interface IAutopilotRouterBase { /// @notice thrown when amount of assets received is below the min set by caller error MinAmountError(); /// @notice thrown when amount of shares received is below the min set by caller error MinSharesError(); /// @notice thrown when amount of assets received is above the max set by caller error MaxAmountError(); /// @notice thrown when amount of shares received is above the max set by caller error MaxSharesError(); /** * @notice mint `shares` from an ERC4626 vault. * @param vault The AutopoolETH to mint shares from. * @param to The destination of ownership shares. * @param shares The amount of shares to mint from `vault`. * @param maxAmountIn The max amount of assets used to mint. * @return amountIn the amount of assets used to mint by `to`. * @dev throws MaxAmountError */ function mint( IAutopool vault, address to, uint256 shares, uint256 maxAmountIn ) external payable returns (uint256 amountIn); /** * @notice deposit `amount` to an ERC4626 vault. * @param vault The AutopoolETH to deposit assets to. * @param to The destination of ownership shares. * @param amount The amount of assets to deposit to `vault`. * @param minSharesOut The min amount of `vault` shares received by `to`. * @return sharesOut the amount of shares received by `to`. * @dev throws MinSharesError */ function deposit( IAutopool vault, address to, uint256 amount, uint256 minSharesOut ) external payable returns (uint256 sharesOut); /** * @notice withdraw `amount` from an ERC4626 vault. * @param vault The AutopoolETH to withdraw assets from. * @param to The destination of assets. * @param amount The amount of assets to withdraw from vault. * @param maxSharesOut The max amount of shares burned for assets requested. * @return sharesOut the amount of shares received by `to`. * @dev throws MaxSharesError */ function withdraw( IAutopool vault, address to, uint256 amount, uint256 maxSharesOut ) external payable returns (uint256 sharesOut); /** * @notice redeem `shares` shares from a AutopoolETH * @param vault The AutopoolETH to redeem shares from. * @param to The destination of assets. * @param shares The amount of shares to redeem from vault. * @param minAmountOut The min amount of assets received by `to`. * @return amountOut the amount of assets received by `to`. * @dev throws MinAmountError */ function redeem( IAutopool vault, address to, uint256 shares, uint256 minAmountOut ) external payable returns (uint256 amountOut); /// @notice Stakes vault token to corresponding rewarder. /// @param vault IERC20 instance of an Autopool to stake to. /// @param maxAmount Maximum amount for user to stake. Amount > balanceOf(user) will stake all present tokens. /// @return staked Returns total amount staked. function stakeVaultToken(IERC20 vault, uint256 maxAmount) external returns (uint256 staked); /// @notice Unstakes vault token from corresponding rewarder. /// @param vault IAutopool instance of the vault token to withdraw. /// @param rewarder Rewarder to withdraw from. /// @param maxAmount Amount of vault token to withdraw Amount > balanceOf(user) will withdraw all owned tokens. /// @param claim Claiming rewards or not on unstaking. /// @return withdrawn Amount of vault token withdrawn. function withdrawVaultToken( IAutopool vault, IMainRewarder rewarder, uint256 maxAmount, bool claim ) external returns (uint256 withdrawn); /// @notice Claims rewards on user stake of vault token. /// @param vault IAutopool instance of vault token to claim rewards for. /// @param rewarder Rewarder to claim rewards from. function claimAutopoolRewards(IAutopool vault, IMainRewarder rewarder) external; }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2024 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol"; /** * @title Validates and distributes Vault token rewards based on the * the signed and submitted payloads */ interface IRewards { struct Recipient { uint256 chainId; uint256 cycle; address wallet; uint256 amount; } event SignerSet(address newSigner); event Claimed(uint256 cycle, address recipient, uint256 amount); /// @notice Get the underlying token rewards are paid in /// @return Token address function vaultToken() external view returns (IERC20); /// @notice Get the current payload signer; /// @return Signer address function rewardsSigner() external view returns (address); /// @notice Check the amount an account has already claimed /// @param account Account to check /// @return Amount already claimed function claimedAmounts(address account) external view returns (uint256); /// @notice Get the amount that is claimable based on the provided payload /// @param recipient Published rewards payload /// @return Amount claimable if the payload is signed function getClaimableAmount(Recipient calldata recipient) external view returns (uint256); /// @notice Change the signer used to validate payloads /// @param newSigner The new address that will be signing rewards payloads function setSigner(address newSigner) external; /// @notice Claim your rewards /// @param recipient Published rewards payload /// @param v v component of the payload signature /// @param r r component of the payload signature /// @param s s component of the payload signature function claim(Recipient calldata recipient, uint8 v, bytes32 r, bytes32 s) external returns (uint256); /// @notice Claim rewards on behalf of another account , invoked primarily by the router /// @param recipient Published rewards payload /// @param v v component of the payload signature /// @param r r component of the payload signature /// @param s s component of the payload signature function claimFor(Recipient calldata recipient, uint8 v, bytes32 r, bytes32 s) external returns (uint256); /// @notice Generate the hash of the payload /// @param recipient Published rewards payload /// @return Hash of the payload function genHash(Recipient memory recipient) external view returns (bytes32); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; struct SwapParams { /// @dev The address of the token to be sold. address sellTokenAddress; /// @dev The amount of tokens to be sold. uint256 sellAmount; /// @dev The address of the token to be bought. address buyTokenAddress; /// @dev The expected minimum amount of tokens to be bought. uint256 buyAmount; /// @dev Data payload to be used for complex swap operations. bytes data; /// @dev Extra data payload reserved for future development. This field allows for additional information /// or functionality to be added without changing the struct and interface. bytes extraData; } interface IAsyncSwapper { error TokenAddressZero(); error SwapFailed(); error InsufficientBuyAmountReceived(uint256 buyTokenAmountReceived, uint256 buyAmount); error InsufficientSellAmount(); error InsufficientBuyAmount(); error InsufficientBalance(uint256 balanceNeeded, uint256 balanceAvailable); event Swapped( address indexed sellTokenAddress, address indexed buyTokenAddress, uint256 sellAmount, uint256 buyAmount, uint256 buyTokenAmountReceived ); /** * @notice Swaps sellToken for buyToken * @param swapParams Encoded swap data * @return buyTokenAmountReceived The amount of buyToken received from the swap */ function swap(SwapParams memory swapParams) external returns (uint256 buyTokenAmountReceived); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.17; /** * @title IDestinationAdapter * @dev This is a super-interface to unify different types of adapters to be registered in Destination Registry. * Specific interface type is defined by extending from this interface. */ interface IDestinationAdapter { error MustBeMoreThanZero(); error ArraysLengthMismatch(); error BalanceMustIncrease(); error MinLpAmountNotReached(); error LpTokenAmountMismatch(); error NoNonZeroAmountProvided(); error InvalidBalanceChange(); error InvalidAddress(address); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { ISystemComponent } from "src/interfaces/ISystemComponent.sol"; /// @notice Creates and registers Destination Vaults for the system interface IDestinationVaultFactory is ISystemComponent { /// @notice Creates a vault of the specified type /// @dev vaultType will be bytes32 encoded and checked that a template is registered /// @param vaultType human readable key of the vault template /// @param baseAsset Base asset of the system. WETH/USDC/etc /// @param underlyer Underlying asset the vault will wrap /// @param incentiveCalculator Incentive calculator of the vault /// @param additionalTrackedTokens Any tokens in addition to base and underlyer that should be tracked /// @param salt Contracts are created via CREATE2 with this value /// @param params params to be passed to vaults initialize function /// @return vault address of the newly created destination vault function create( string memory vaultType, address baseAsset, address underlyer, address incentiveCalculator, address[] memory additionalTrackedTokens, bytes32 salt, bytes memory params ) external returns (address vault); /// @notice Sets the default reward ratio /// @param rewardRatio new default reward ratio function setDefaultRewardRatio(uint256 rewardRatio) external; /// @notice Sets the default reward block duration /// @param blockDuration new default reward block duration function setDefaultRewardBlockDuration(uint256 blockDuration) external; }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; /// @title Capture information about a pool or destination interface IStatsCalculator { /// @notice thrown when no snapshot is taken error NoSnapshotTaken(); /// @notice The id for this instance of a calculator function getAprId() external view returns (bytes32); /// @notice The id of the underlying asset/pool/destination this calculator represents /// @dev This may be a generated address function getAddressId() external view returns (address); /// @notice Setup the calculator after it has been copied /// @dev Should only be executed one time /// @param dependentAprIds apr ids that cover the dependencies of this calculator /// @param initData setup data specific to this type of calculator function initialize(bytes32[] calldata dependentAprIds, bytes calldata initData) external; /// @notice Capture stat data about this setup function snapshot() external; /// @notice Indicates if a snapshot should be taken /// @return takeSnapshot if true then a snapshot should be taken. If false, calling snapshot will do nothing function shouldSnapshot() external view returns (bool takeSnapshot); /// @dev Enum representing the snapshot status for a given rewarder (Convex and Aura) or reward token (Maverick) enum SnapshotStatus { noSnapshot, // Indicates that no snapshot has been taken yet for the rewarder. tooSoon, // Indicates that it's too soon to take another snapshot since the last one. shouldFinalize, // Indicates that the conditions are met for finalizing a snapshot. shouldRestart // Indicates that the conditions are met for restarting a snapshot. } }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; interface IBaseRewarder { event RewardAdded( uint256 reward, uint256 rewardRate, uint256 lastUpdateBlock, uint256 periodInBlockFinish, uint256 historicalRewards ); event UserRewardUpdated( address indexed user, uint256 amount, uint256 rewardPerTokenStored, uint256 lastUpdateBlock ); event Staked(address indexed user, uint256 amount); event Withdrawn(address indexed user, uint256 amount); event RewardPaid(address indexed user, uint256 reward); event QueuedRewardsUpdated(uint256 startingQueuedRewards, uint256 startingNewRewards, uint256 queuedRewards); event AddedToWhitelist(address indexed wallet); event RemovedFromWhitelist(address indexed wallet); event TokeLockDurationUpdated(uint256 newDuration); /** * @notice Claims and transfers all rewards for the specified account */ function getReward() external; /** * @notice Stakes the specified amount of tokens for the specified account. * @param account The address of the account to stake tokens for. * @param amount The amount of tokens to stake. */ function stake(address account, uint256 amount) external; /** * @notice Calculate the earned rewards for an account. * @param account Address of the account. * @return The earned rewards for the given account. */ function earned(address account) external view returns (uint256); /** * @notice Calculates the rewards per token for the current block. * @dev The total amount of rewards available in the system is fixed, and it needs to be distributed among the users * based on their token balances and staking duration. * Rewards per token represent the amount of rewards that each token is entitled to receive at the current block. * The calculation takes into account the reward rate, the time duration since the last update, * and the total supply of tokens in the staking pool. * @return The updated rewards per token value for the current block. */ function rewardPerToken() external view returns (uint256); /** * @notice Get the current reward rate per block. * @return The current reward rate per block. */ function rewardRate() external view returns (uint256); /** * @notice Get the current TOKE lock duration. * @return The current TOKE lock duration. */ function tokeLockDuration() external view returns (uint256); /** * @notice Get the last block where rewards are applicable. * @return The last block number where rewards are applicable. */ function lastBlockRewardApplicable() external view returns (uint256); /** * @notice The total amount of tokens staked */ function totalSupply() external view returns (uint256); /** * @notice The amount of tokens staked for the specified account * @param account The address of the account to get the balance of */ function balanceOf(address account) external view returns (uint256); /** * @notice Queue new rewards to be distributed. * @param newRewards The amount of new rewards to be queued. */ function queueNewRewards(uint256 newRewards) external; /** * @notice Token distributed as rewards * @return reward token address */ function rewardToken() external view returns (address); /** * @notice Add an address to the whitelist. * @param wallet The address to be added to the whitelist. */ function addToWhitelist(address wallet) external; /** * @notice Remove an address from the whitelist. * @param wallet The address to be removed from the whitelist. */ function removeFromWhitelist(address wallet) external; /** * @notice Check if an address is whitelisted. * @param wallet The address to be checked. * @return bool indicating if the address is whitelisted. */ function isWhitelisted(address wallet) external view returns (bool); }
// SPDX-License-Identifier: UNLICENSED // Copyright (c) 2023 Tokemak Foundation. All rights reserved. pragma solidity 0.8.17; import { IBaseRewarder } from "src/interfaces/rewarders/IBaseRewarder.sol"; interface IExtraRewarder is IBaseRewarder { /** * @notice Withdraws the specified amount of tokens from the vault for the specified account. * @param account The address of the account to withdraw tokens for. * @param amount The amount of tokens to withdraw. */ function withdraw(address account, uint256 amount) external; /** * @notice Claims and transfers all rewards for the specified account from this contract. * @param account The address of the account to claim rewards for. */ function getReward(address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV // Deprecated in v4.8 } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { // 32 is the length in bytes of hash, // enforced by the type signature above return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
{ "remappings": [ "forge-std/=lib/forge-std/src/", "ds-test/=lib/forge-std/lib/ds-test/src/", "src/=src/", "test/=test/", "openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/", "erc4626-tests/=lib/erc4626-tests/", "prb-math/=lib/prb-math/", "crytic/properties/=lib/properties/", "ERC4626/=lib/properties/lib/ERC4626/contracts/", "properties/=lib/properties/contracts/", "solmate/=lib/properties/lib/solmate/src/", "usingtellor/=lib/usingtellor/contracts/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "viaIR": false, "libraries": { "src/destinations/adapters/BalancerBeethovenAdapter.sol": { "BalancerBeethovenAdapter": "0xeE9d4bDA0a124157D05756e48e12C67289833191" }, "src/destinations/adapters/CurveV2FactoryCryptoAdapter.sol": { "CurveV2FactoryCryptoAdapter": "0xe46E7634d6e0BC954407078818fF62eDfF414184" }, "src/destinations/adapters/rewards/AuraRewardsAdapter.sol": { "AuraRewards": "0x27401aca0EA294195187F6aE0673451AB01e5471" }, "src/destinations/adapters/rewards/ConvexRewardsAdapter.sol": { "ConvexRewards": "0x08F295fD04B52Ab6a7f8A86bC9A0A1c0EA8aDE01" }, "src/destinations/adapters/rewards/MaverickRewardsAdapter.sol": { "MaverickRewardsAdapter": "0x487F4bdf1201Ac0eD5D8c9A9b706A3b62De5249e" }, "src/destinations/adapters/rewards/MaverickStakingAdapter.sol": { "MaverickStakingAdapter": "0x123d88094FEfB727Bef3906123485C2AF49810bC" }, "src/destinations/adapters/staking/AuraAdapter.sol": { "AuraStaking": "0x9f121874565cC071Fd2E830DF2021987210DD853" }, "src/destinations/adapters/staking/ConvexAdapter.sol": { "ConvexStaking": "0x6c2f91978004B0A769c622dfe352EdF331044d49" }, "src/libs/BalancerUtilities.sol": { "BalancerUtilities": "0xa986Cc1bc9C8987E7b679F4edF8e065079BA461B" }, "src/strategy/StructuredLinkedList.sol": { "StructuredLinkedList": "0x6C566a67b34CFed9821FC7433750A1391fa97989" }, "src/strategy/WithdrawalQueue.sol": { "WithdrawalQueue": "0xC754773B0e8CaFbD17e978be3c31ef34869ba733" }, "src/strategy/libs/Incentives.sol": { "Incentives": "0x5259d941fccCDCc0a3FC9FFf5Dffa89c0bBAADDc" }, "src/strategy/libs/PriceReturn.sol": { "PriceReturn": "0xF8e01E7120C0C4cF8Ba90d12DDdF0E3bE9e3DBaD" }, "src/strategy/libs/SummaryStats.sol": { "SummaryStats": "0x70EFfB18025d5718B975A453cb50CB6C3f00543d" }, "src/vault/libs/Autopool4626.sol": { "Autopool4626": "0x87B8e8956A240E05A8Bd6C42642268C7e4D83172" }, "src/vault/libs/AutopoolDebt.sol": { "AutopoolDebt": "0xc2d3450E1b80136aE8fa3bC6EE8E4b702C7D4942" }, "src/vault/libs/AutopoolDestinations.sol": { "AutopoolDestinations": "0x93B5d679C4FC5b5705cba9D8e505Ff66b962C7aD" }, "src/vault/libs/AutopoolFees.sol": { "AutopoolFees": "0x35400b052d96ce4d9943AEeE9f36beB63eCB6b2b" }, "src/vault/libs/AutopoolToken.sol": { "AutopoolToken": "0xb916038B047C637bD2be297A7480708Ba74E1A82" } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract ISystemRegistry","name":"_systemRegistry","type":"address"},{"components":[{"components":[{"internalType":"uint16","name":"initInDays","type":"uint16"},{"internalType":"uint16","name":"tightenThresholdInViolations","type":"uint16"},{"internalType":"uint16","name":"tightenStepInDays","type":"uint16"},{"internalType":"uint16","name":"relaxThresholdInDays","type":"uint16"},{"internalType":"uint16","name":"relaxStepInDays","type":"uint16"},{"internalType":"uint16","name":"maxInDays","type":"uint16"},{"internalType":"uint16","name":"minInDays","type":"uint16"}],"internalType":"struct AutopoolETHStrategyConfig.SwapCostOffsetConfig","name":"swapCostOffset","type":"tuple"},{"components":[{"internalType":"uint8","name":"lookback1InDays","type":"uint8"},{"internalType":"uint8","name":"lookback2InDays","type":"uint8"},{"internalType":"uint8","name":"lookback3InDays","type":"uint8"}],"internalType":"struct AutopoolETHStrategyConfig.NavLookbackConfig","name":"navLookback","type":"tuple"},{"components":[{"internalType":"uint256","name":"maxNormalOperationSlippage","type":"uint256"},{"internalType":"uint256","name":"maxTrimOperationSlippage","type":"uint256"},{"internalType":"uint256","name":"maxEmergencyOperationSlippage","type":"uint256"},{"internalType":"uint256","name":"maxShutdownOperationSlippage","type":"uint256"}],"internalType":"struct AutopoolETHStrategyConfig.SlippageConfig","name":"slippage","type":"tuple"},{"components":[{"internalType":"uint256","name":"baseYield","type":"uint256"},{"internalType":"uint256","name":"feeYield","type":"uint256"},{"internalType":"uint256","name":"incentiveYield","type":"uint256"},{"internalType":"uint256","name":"slashing","type":"uint256"},{"internalType":"int256","name":"priceDiscountExit","type":"int256"},{"internalType":"int256","name":"priceDiscountEnter","type":"int256"},{"internalType":"int256","name":"pricePremium","type":"int256"}],"internalType":"struct AutopoolETHStrategyConfig.ModelWeights","name":"modelWeights","type":"tuple"},{"internalType":"uint16","name":"pauseRebalancePeriodInDays","type":"uint16"},{"internalType":"uint256","name":"rebalanceTimeGapInSeconds","type":"uint256"},{"internalType":"int256","name":"maxPremium","type":"int256"},{"internalType":"int256","name":"maxDiscount","type":"int256"},{"internalType":"uint40","name":"staleDataToleranceInSeconds","type":"uint40"},{"internalType":"int256","name":"maxAllowedDiscount","type":"int256"},{"internalType":"uint256","name":"lstPriceGapTolerance","type":"uint256"}],"internalType":"struct AutopoolETHStrategyConfig.StrategyConfig","name":"conf","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessDenied","type":"error"},{"inputs":[],"name":"CannotConvertUintToInt","type":"error"},{"inputs":[],"name":"CannotConvertUintToInt","type":"error"},{"inputs":[],"name":"IdleHighThresholdViolated","type":"error"},{"inputs":[],"name":"InconsistentIdleThresholds","type":"error"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"InsufficientAssets","type":"error"},{"inputs":[{"internalType":"string","name":"paramName","type":"string"}],"name":"InvalidConfig","type":"error"},{"inputs":[{"internalType":"uint40","name":"current","type":"uint40"},{"internalType":"uint40","name":"provided","type":"uint40"}],"name":"InvalidNavTimestamp","type":"error"},{"inputs":[{"internalType":"string","name":"paramName","type":"string"}],"name":"InvalidParam","type":"error"},{"inputs":[],"name":"InvalidRebalanceToIdle","type":"error"},{"inputs":[],"name":"LSTPriceGapToleranceExceeded","type":"error"},{"inputs":[],"name":"MaxDiscountExceeded","type":"error"},{"inputs":[],"name":"MaxPremiumExceeded","type":"error"},{"inputs":[],"name":"MaxSlippageExceeded","type":"error"},{"inputs":[],"name":"NavHistoryInsufficient","type":"error"},{"inputs":[],"name":"NotAutopoolETH","type":"error"},{"inputs":[],"name":"OnlyRebalanceToIdleAvailable","type":"error"},{"inputs":[{"internalType":"address","name":"destination","type":"address"},{"internalType":"address","name":"trueUnderlyer","type":"address"},{"internalType":"address","name":"providedUnderlyer","type":"address"}],"name":"RebalanceDestinationUnderlyerMismatch","type":"error"},{"inputs":[],"name":"RebalanceDestinationsMatch","type":"error"},{"inputs":[],"name":"RebalanceTimeGapNotMet","type":"error"},{"inputs":[{"internalType":"string","name":"name","type":"string"}],"name":"StaleData","type":"error"},{"inputs":[],"name":"StrategyPaused","type":"error"},{"inputs":[],"name":"SwapCostExceeded","type":"error"},{"inputs":[],"name":"SystemRegistryMismatch","type":"error"},{"inputs":[],"name":"UndefinedAddress","type":"error"},{"inputs":[{"internalType":"address","name":"dest","type":"address"}],"name":"UnregisteredDestination","type":"error"},{"inputs":[{"internalType":"string","name":"paramName","type":"string"}],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"assetIndex","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"numViolationsOne","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"numViolationsTwo","type":"uint256"},{"indexed":false,"internalType":"int256","name":"discount","type":"int256"}],"name":"DestTrimRebalanceDetails","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"trimAmount","type":"uint256"}],"name":"DestViolationMaxTrimAmount","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"DustPositionPortionSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newLowValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newHighValue","type":"uint256"}],"name":"IdleThresholdsSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newPriceGap","type":"uint256"}],"name":"LstPriceGapSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"navPerShare","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nav1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nav2","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nav3","type":"uint256"}],"name":"PauseStart","type":"event"},{"anonymous":false,"inputs":[],"name":"PauseStop","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint256","name":"inPrice","type":"uint256"},{"internalType":"uint256","name":"outPrice","type":"uint256"},{"internalType":"uint256","name":"inEthValue","type":"uint256"},{"internalType":"uint256","name":"outEthValue","type":"uint256"},{"internalType":"uint256","name":"swapCost","type":"uint256"},{"internalType":"uint256","name":"slippage","type":"uint256"}],"indexed":false,"internalType":"struct AutopoolETHStrategy.RebalanceValueStats","name":"valueStats","type":"tuple"},{"components":[{"internalType":"address","name":"destinationIn","type":"address"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"destinationOut","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountOut","type":"uint256"}],"indexed":false,"internalType":"struct IStrategy.RebalanceParams","name":"params","type":"tuple"},{"components":[{"internalType":"address","name":"destination","type":"address"},{"internalType":"uint256","name":"baseApr","type":"uint256"},{"internalType":"uint256","name":"feeApr","type":"uint256"},{"internalType":"uint256","name":"incentiveApr","type":"uint256"},{"internalType":"uint256","name":"safeTotalSupply","type":"uint256"},{"internalType":"int256","name":"priceReturn","type":"int256"},{"internalType":"int256","name":"maxDiscount","type":"int256"},{"internalType":"int256","name":"maxPremium","type":"int256"},{"internalType":"uint256","name":"ownedShares","type":"uint256"},{"internalType":"int256","name":"compositeReturn","type":"int256"},{"internalType":"uint256","name":"pricePerShare","type":"uint256"},{"internalType":"uint256","name":"slashingCost","type":"uint256"}],"indexed":false,"internalType":"struct IStrategy.SummaryStats","name":"outSummaryStats","type":"tuple"},{"components":[{"internalType":"address","name":"destination","type":"address"},{"internalType":"uint256","name":"baseApr","type":"uint256"},{"internalType":"uint256","name":"feeApr","type":"uint256"},{"internalType":"uint256","name":"incentiveApr","type":"uint256"},{"internalType":"uint256","name":"safeTotalSupply","type":"uint256"},{"internalType":"int256","name":"priceReturn","type":"int256"},{"internalType":"int256","name":"maxDiscount","type":"int256"},{"internalType":"int256","name":"maxPremium","type":"int256"},{"internalType":"uint256","name":"ownedShares","type":"uint256"},{"internalType":"int256","name":"compositeReturn","type":"int256"},{"internalType":"uint256","name":"pricePerShare","type":"uint256"},{"internalType":"uint256","name":"slashingCost","type":"uint256"}],"indexed":false,"internalType":"struct IStrategy.SummaryStats","name":"inSummaryStats","type":"tuple"},{"indexed":false,"internalType":"uint256","name":"swapOffsetPeriod","type":"uint256"},{"indexed":false,"internalType":"int256","name":"predictedAnnualizedGain","type":"int256"}],"name":"RebalanceBetweenDestinations","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint256","name":"inPrice","type":"uint256"},{"internalType":"uint256","name":"outPrice","type":"uint256"},{"internalType":"uint256","name":"inEthValue","type":"uint256"},{"internalType":"uint256","name":"outEthValue","type":"uint256"},{"internalType":"uint256","name":"swapCost","type":"uint256"},{"internalType":"uint256","name":"slippage","type":"uint256"}],"indexed":false,"internalType":"struct AutopoolETHStrategy.RebalanceValueStats","name":"valueStats","type":"tuple"},{"components":[{"internalType":"address","name":"destination","type":"address"},{"internalType":"uint256","name":"baseApr","type":"uint256"},{"internalType":"uint256","name":"feeApr","type":"uint256"},{"internalType":"uint256","name":"incentiveApr","type":"uint256"},{"internalType":"uint256","name":"safeTotalSupply","type":"uint256"},{"internalType":"int256","name":"priceReturn","type":"int256"},{"internalType":"int256","name":"maxDiscount","type":"int256"},{"internalType":"int256","name":"maxPremium","type":"int256"},{"internalType":"uint256","name":"ownedShares","type":"uint256"},{"internalType":"int256","name":"compositeReturn","type":"int256"},{"internalType":"uint256","name":"pricePerShare","type":"uint256"},{"internalType":"uint256","name":"slashingCost","type":"uint256"}],"indexed":false,"internalType":"struct IStrategy.SummaryStats","name":"outSummary","type":"tuple"},{"components":[{"internalType":"address","name":"destinationIn","type":"address"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"destinationOut","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountOut","type":"uint256"}],"indexed":false,"internalType":"struct IStrategy.RebalanceParams","name":"params","type":"tuple"}],"name":"RebalanceToIdle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum AutopoolETHStrategy.RebalanceToIdleReasonEnum","name":"reason","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"maxSlippage","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"slippage","type":"uint256"}],"name":"RebalanceToIdleReason","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"destinationOut","type":"address"},{"indexed":false,"internalType":"uint40","name":"lastRebalanceTimestamp","type":"uint40"},{"indexed":false,"internalType":"uint40","name":"lastTimestampAddedToDestination","type":"uint40"},{"indexed":false,"internalType":"uint40","name":"swapCostOffsetPeriod","type":"uint40"}],"name":"SuccessfulRebalanceBetweenDestinations","type":"event"},{"inputs":[],"name":"accessController","outputs":[{"internalType":"contract IAccessController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"autoPool","outputs":[{"internalType":"contract IAutopool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultLstPriceGapTolerance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dustPositionPortions","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"expiredRewardTolerance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"destAddress","type":"address"},{"internalType":"enum IAutopoolStrategy.RebalanceDirection","name":"direction","type":"uint8"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getDestinationSummaryStats","outputs":[{"components":[{"internalType":"address","name":"destination","type":"address"},{"internalType":"uint256","name":"baseApr","type":"uint256"},{"internalType":"uint256","name":"feeApr","type":"uint256"},{"internalType":"uint256","name":"incentiveApr","type":"uint256"},{"internalType":"uint256","name":"safeTotalSupply","type":"uint256"},{"internalType":"int256","name":"priceReturn","type":"int256"},{"internalType":"int256","name":"maxDiscount","type":"int256"},{"internalType":"int256","name":"maxPremium","type":"int256"},{"internalType":"uint256","name":"ownedShares","type":"uint256"},{"internalType":"int256","name":"compositeReturn","type":"int256"},{"internalType":"uint256","name":"pricePerShare","type":"uint256"},{"internalType":"uint256","name":"slashingCost","type":"uint256"}],"internalType":"struct IStrategy.SummaryStats","name":"","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"destinationIn","type":"address"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"destinationOut","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountOut","type":"uint256"}],"internalType":"struct IStrategy.RebalanceParams","name":"rebalanceParams","type":"tuple"}],"name":"getRebalanceOutSummaryStats","outputs":[{"components":[{"internalType":"address","name":"destination","type":"address"},{"internalType":"uint256","name":"baseApr","type":"uint256"},{"internalType":"uint256","name":"feeApr","type":"uint256"},{"internalType":"uint256","name":"incentiveApr","type":"uint256"},{"internalType":"uint256","name":"safeTotalSupply","type":"uint256"},{"internalType":"int256","name":"priceReturn","type":"int256"},{"internalType":"int256","name":"maxDiscount","type":"int256"},{"internalType":"int256","name":"maxPremium","type":"int256"},{"internalType":"uint256","name":"ownedShares","type":"uint256"},{"internalType":"int256","name":"compositeReturn","type":"int256"},{"internalType":"uint256","name":"pricePerShare","type":"uint256"},{"internalType":"uint256","name":"slashingCost","type":"uint256"}],"internalType":"struct IStrategy.SummaryStats","name":"outSummary","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getSystemRegistry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"idleHighThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"idleLowThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_autoPool","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastAddTimestampByDestination","outputs":[{"internalType":"uint40","name":"","type":"uint40"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastPausedTimestamp","outputs":[{"internalType":"uint40","name":"","type":"uint40"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastRebalanceTimestamp","outputs":[{"internalType":"uint40","name":"","type":"uint40"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lstPriceGapTolerance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxAllowedDiscount","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxDiscount","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxEmergencyOperationSlippage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxNormalOperationSlippage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxPremium","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxShutdownOperationSlippage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxTrimOperationSlippage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"navLookback1InDays","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"navLookback2InDays","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"navLookback3InDays","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"navTrackingState","outputs":[{"internalType":"uint8","name":"len","type":"uint8"},{"internalType":"uint8","name":"currentIndex","type":"uint8"},{"internalType":"uint40","name":"lastFinalizedTimestamp","type":"uint40"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"navPerShare","type":"uint256"}],"name":"navUpdate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pauseRebalancePeriodInDays","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"destinationIn","type":"address"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"destinationOut","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountOut","type":"uint256"}],"internalType":"struct IStrategy.RebalanceParams","name":"params","type":"tuple"}],"name":"rebalanceSuccessfullyExecuted","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rebalanceTimeGapInSeconds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"setDustPositionPortions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLowValue","type":"uint256"},{"internalType":"uint256","name":"newHighValue","type":"uint256"}],"name":"setIdleThresholds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"priceGapTolerance","type":"uint256"}],"name":"setLstPriceGapTolerance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"staleDataToleranceInSeconds","outputs":[{"internalType":"uint40","name":"","type":"uint40"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapCostOffsetInit","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapCostOffsetInitInDays","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapCostOffsetMaxInDays","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapCostOffsetMinInDays","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapCostOffsetPeriodInDays","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapCostOffsetRelaxStepInDays","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapCostOffsetRelaxThresholdInDays","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapCostOffsetTightenStepInDays","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapCostOffsetTightenThresholdInViolations","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"destinationIn","type":"address"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"destinationOut","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountOut","type":"uint256"}],"internalType":"struct IStrategy.RebalanceParams","name":"params","type":"tuple"},{"components":[{"internalType":"address","name":"destination","type":"address"},{"internalType":"uint256","name":"baseApr","type":"uint256"},{"internalType":"uint256","name":"feeApr","type":"uint256"},{"internalType":"uint256","name":"incentiveApr","type":"uint256"},{"internalType":"uint256","name":"safeTotalSupply","type":"uint256"},{"internalType":"int256","name":"priceReturn","type":"int256"},{"internalType":"int256","name":"maxDiscount","type":"int256"},{"internalType":"int256","name":"maxPremium","type":"int256"},{"internalType":"uint256","name":"ownedShares","type":"uint256"},{"internalType":"int256","name":"compositeReturn","type":"int256"},{"internalType":"uint256","name":"pricePerShare","type":"uint256"},{"internalType":"uint256","name":"slashingCost","type":"uint256"}],"internalType":"struct IStrategy.SummaryStats","name":"outSummary","type":"tuple"}],"name":"verifyRebalance","outputs":[{"internalType":"bool","name":"success","type":"bool"},{"internalType":"string","name":"message","type":"string"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"violationTrackingState","outputs":[{"internalType":"uint8","name":"violationCount","type":"uint8"},{"internalType":"uint8","name":"len","type":"uint8"},{"internalType":"uint16","name":"violations","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weightBase","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weightFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weightIncentive","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weightPriceDiscountEnter","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weightPriceDiscountExit","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weightPricePremium","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weightSlashing","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
6104606040523480156200001257600080fd5b50604051620074c0380380620074c083398101604081905262000035916200118e565b816001600160a01b031663bc43cbaf6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000074573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200009a91906200128a565b82620000d9816040518060400160405280600f81526020016e5f73797374656d526567697374727960881b8152506200027560201b62001e6e1760201c565b6001600160a01b0390811660805281166200010757604051630cbe126f60e11b815260040160405180910390fd5b6001600160a01b031660a0526200012a81620002ae602090811b62001e9717901c565b60a08082015160e090815260808084015161ffff90811660c090815280860151610100908152938601516101209081529386015164ffffffffff166101409081528651518316610160528651602090810151841661018052875160409081015185166101a052885160609081015186166101c052895187015186166101e05289518901518616610200528951850151861661022052828a0180515160ff90811661024052815185015181166102605290518301511661028052818a018051516102a05280518401516102c05280518301516102e05251810151610300529689015161032052868901805151610340528051909201516103605281510151610380528051909501516103a0528451909301516103c0528351909401516103e05291519092015161040052908201516104405281515116610420526200026d62000d80565b505062001301565b6001600160a01b038216620002aa578060405163eac0d38960e01b8152600401620002a19190620012b1565b60405180910390fd5b5050565b805160c0810151905161ffff91821691161080620002da5750805160a0810151905161ffff9182169116115b80620002ee5750805151600761ffff909116105b80620003025750805151605a61ffff909116115b1562000352576040516389a6198960e01b815260206004820152601960248201527f73776170436f73744f66667365745f696e6974496e44617973000000000000006044820152606401620002a1565b600181600001516020015161ffff1610806200037a5750600a81600001516020015161ffff16115b15620003de576040516389a6198960e01b815260206004820152602b60248201527f73776170436f73744f66667365745f7469676874656e5468726573686f6c644960448201526a6e56696f6c6174696f6e7360a81b6064820152608401620002a1565b600181600001516040015161ffff161080620004065750600781600001516040015161ffff16115b1562000456576040516389a6198960e01b815260206004820181905260248201527f73776170436f73744f66667365745f7469676874656e53746570496e446179736044820152606401620002a1565b600e81600001516060015161ffff1610806200047e5750605a81600001516060015161ffff16115b15620004da576040516389a6198960e01b815260206004820152602360248201527f73776170436f73744f66667365745f72656c61785468726573686f6c64496e4460448201526261797360e81b6064820152608401620002a1565b600181600001516080015161ffff161080620005025750600781600001516080015161ffff16115b1562000552576040516389a6198960e01b815260206004820152601e60248201527f73776170436f73744f66667365745f72656c617853746570496e4461797300006044820152606401620002a1565b805160c081015160a09091015161ffff91821691161115806200058157506008816000015160a0015161ffff16105b80620005995750605a816000015160a0015161ffff16115b15620005e9576040516389a6198960e01b815260206004820152601860248201527f73776170436f73744f66667365745f6d6178496e4461797300000000000000006044820152606401620002a1565b6007816000015160c0015161ffff161080620006115750605a816000015160c0015161ffff16115b1562000661576040516389a6198960e01b815260206004820152601860248201527f73776170436f73744f66667365745f6d696e496e4461797300000000000000006044820152606401620002a1565b620006b381602001516000015160ff166040518060400160405280601b81526020017f6e61764c6f6f6b6261636b5f6c6f6f6b6261636b31496e44617973000000000081525062000e3f60201b60201c565b602081015151605b60ff909116101580620006dd5750605b60ff1681602001516020015160ff1610155b80620006f75750605b60ff1681602001516040015160ff16115b1562000739576040516389a6198960e01b815260206004820152600f60248201526e0dcc2ec98deded6c4c2c6d6bedac2f608b1b6044820152606401620002a1565b60208082015190810151905160ff918216911610158062000770575080602001516040015160ff1681602001516020015160ff1610155b15620007b4576040516389a6198960e01b81526020600482015260116024820152706e61764c6f6f6b6261636b5f737465707360781b6044820152606401620002a1565b620007e18160400151606001516040518060600160405280602581526020016200749b6025913962000e65565b6200080e816040015160400151604051806060016040528060268152602001620074546026913962000e65565b6200083b8160400151602001516040518060600160405280602181526020016200747a6021913962000e65565b62000868816040015160000151604051806060016040528060238152602001620074316023913962000e65565b606081015151620f42401015620008c3576040516389a6198960e01b815260206004820152601660248201527f6d6f64656c576569676874735f626173655969656c64000000000000000000006044820152606401620002a1565b620f4240816060015160200151111562000921576040516389a6198960e01b815260206004820152601560248201527f6d6f64656c576569676874735f6665655969656c6400000000000000000000006044820152606401620002a1565b620f424081606001516040015111156200097f576040516389a6198960e01b815260206004820152601b60248201527f6d6f64656c576569676874735f696e63656e746976655969656c6400000000006044820152606401620002a1565b620f42408160600151606001511115620009dd576040516389a6198960e01b815260206004820152601560248201527f6d6f64656c576569676874735f736c617368696e6700000000000000000000006044820152606401620002a1565b620f4240816060015160800151131562000a3b576040516389a6198960e01b815260206004820152601e60248201527f6d6f64656c576569676874735f7072696365446973636f756e744578697400006044820152606401620002a1565b620f4240816060015160a00151131562000a99576040516389a6198960e01b815260206004820152601f60248201527f6d6f64656c576569676874735f7072696365446973636f756e74456e746572006044820152606401620002a1565b620f4240816060015160c00151131562000af7576040516389a6198960e01b815260206004820152601960248201527f6d6f64656c576569676874735f70726963655072656d69756d000000000000006044820152606401620002a1565b6007816080015161ffff16108062000b175750605a816080015161ffff16115b1562000b67576040516389a6198960e01b815260206004820152601a60248201527f7061757365526562616c616e6365506572696f64496e446179730000000000006044820152606401620002a1565b610e108160a00151108062000b82575062278d008160a00151115b1562000bd2576040516389a6198960e01b815260206004820152601960248201527f726562616c616e636554696d65476170496e5365636f6e6473000000000000006044820152606401620002a1565b62000c0a8160c001516040518060400160405280600a8152602001696d61785072656d69756d60b01b81525062000e9360201b60201c565b62000c428160e001516040518060400160405280600a8152602001696d61785072656d69756d60b01b81525062000e9360201b60201c565b610e1081610100015164ffffffffff16108062000c6d575062093a8081610100015164ffffffffff16115b1562000cbd576040516389a6198960e01b815260206004820152601b60248201527f7374616c6544617461546f6c6572616e6365496e5365636f6e647300000000006044820152606401620002a1565b6000816101200151128062000cde57506706f05b59d3b20000816101200151135b1562000d23576040516389a6198960e01b81526020600482015260126024820152711b585e105b1b1bddd959111a5cd8dbdd5b9d60721b6044820152606401620002a1565b6101f4816101400151111562000d7d576040516389a6198960e01b815260206004820152601460248201527f6c73745072696365476170546f6c6572616e63650000000000000000000000006044820152606401620002a1565b50565b600054610100900460ff161562000dea5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b6064820152608401620002a1565b60005460ff908116101562000e3d576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b81600003620002aa57806040516389a6198960e01b8152600401620002a19190620012b1565b6703782dace9d90000821115620002aa57806040516389a6198960e01b8152600401620002a19190620012b1565b6703782dace9d9000082138062000eaa5750600082125b15620002aa57806040516389a6198960e01b8152600401620002a19190620012b1565b6001600160a01b038116811462000d7d57600080fd5b60405160e081016001600160401b038111828210171562000f1457634e487b7160e01b600052604160045260246000fd5b60405290565b60405161016081016001600160401b038111828210171562000f1457634e487b7160e01b600052604160045260246000fd5b805161ffff8116811462000f5f57600080fd5b919050565b600060e0828403121562000f7757600080fd5b62000f8162000ee3565b905062000f8e8262000f4c565b815262000f9e6020830162000f4c565b602082015262000fb16040830162000f4c565b604082015262000fc46060830162000f4c565b606082015262000fd76080830162000f4c565b608082015262000fea60a0830162000f4c565b60a082015262000ffd60c0830162000f4c565b60c082015292915050565b805160ff8116811462000f5f57600080fd5b6000606082840312156200102d57600080fd5b604051606081016001600160401b03811182821017156200105e57634e487b7160e01b600052604160045260246000fd5b6040529050806200106f8362001008565b81526200107f6020840162001008565b6020820152620010926040840162001008565b60408201525092915050565b600060808284031215620010b157600080fd5b604051608081016001600160401b0381118282101715620010e257634e487b7160e01b600052604160045260246000fd5b8060405250809150825181526020830151602082015260408301516040820152606083015160608201525092915050565b600060e082840312156200112657600080fd5b6200113062000ee3565b9050815181526020820151602082015260408201516040820152606082015160608201526080820151608082015260a082015160a082015260c082015160c082015292915050565b805164ffffffffff8116811462000f5f57600080fd5b6000808284036103a0811215620011a457600080fd5b8351620011b18162000ecd565b9250610380601f198201811315620011c857600080fd5b620011d262000f1a565b9150620011e3866020870162000f64565b8252610100620011f6878288016200101a565b60208401526200120b8761016088016200109e565b604084015262001220876101e0880162001113565b6060840152620012346102c0870162000f4c565b60808401526102e086015160a084015261030086015160c084015261032086015160e084015262001269610340870162001178565b90830152610360850151610120830152909301516101408401525092909150565b6000602082840312156200129d57600080fd5b8151620012aa8162000ecd565b9392505050565b600060208083528351808285015260005b81811015620012e057858101830151858201604001528201620012c2565b506000604082860101526040601f19601f8301168501019250505092915050565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c0516101e05161020051610220516102405161026051610280516102a0516102c0516102e05161030051610320516103405161036051610380516103a0516103c0516103e051610400516104205161044051615e9962001598600039600081816107b10152613ff90152600081816105090152613fd101526000610373015260006104e20152600061040f0152600061057d015260006108d20152600061084a01526000610a1c015260006108f90152600081816107170152818161358c01526135b501526000818161073e01526134e70152600081816108ab0152818161376501526137bd0152600081816109ce01528181610e9b015281816135ec015281816136150152818161364c0152818161367501528181613715015261373e015260008181610933015281816114b7015261168801526000818161069001526115e60152600081816105f2015261153601526000818161087101528181610b4701528181613bf501528181613e0c0152613e470152600081816105cb01528181610c3e0152610c710152600081816106b70152610bfc0152600081816109a701528181610b700152610b9d01526000818161095a01528181613daf0152613de20152600081816105430152611ae6015260006107650152600081816103310152614c460152600081816107e901526110f50152600081816105a4015261113a01526000818161043601528181610e430152613f840152600081816109f5015261179201526000818161081001528181610cdd01528181611311015261182b01526000818161097e01528181611d7d01528181612ffd0152818161392401528181613eb301526140310152615e996000f3fe608060405234801561001057600080fd5b50600436106103275760003560e01c80639c205b9f116101b8578063c28e888a11610104578063e84aa981116100a2578063f5073f6f1161007c578063f5073f6f146109c9578063f5a67e21146109f0578063f5b28fee14610a17578063fa46197414610a3e57600080fd5b8063e84aa98114610955578063f12baf5c1461097c578063f37d9f14146109a257600080fd5b8063cc3aa353116100de578063cc3aa353146108cd578063d98646ce146108f4578063dddf00951461091b578063e47d4e391461092e57600080fd5b8063c28e888a1461086c578063c4d66de814610893578063c721500d146108a657600080fd5b8063ac5062a411610171578063b8b89e1b1161014b578063b8b89e1b146107e4578063bc43cbaf1461080b578063c0f09d9614610832578063c183673a1461084557600080fd5b8063ac5062a4146107a3578063b2680b89146107ac578063b83d8157146107d357600080fd5b80639c205b9f146107095780639f42ba9d14610712578063a2a2d95914610739578063a839601f14610760578063a98550c914610787578063aa5ed0981461079a57600080fd5b80633ef947571161027757806355eb949011610230578063756f72701161020a578063756f72701461068b5780637a39cf63146106b25780637df1ba6c146106d95780639ae111d41461070057600080fd5b806355eb9490146105ed5780635c975abb146106265780636b286faa1461063e57600080fd5b80633ef947571461052b57806341b5380a1461053e5780634244cc901461056557806348e0d4e21461057857806351b79d551461059f57806353aa3f8d146105c657600080fd5b80632265d3d8116102e457806332866e08116102be57806332866e081461049157806335c68d13146104bc5780633740ea21146104dd578063377a1a061461050457600080fd5b80632265d3d8146104585780632c68799814610473578063324fb0401461048857600080fd5b806305d3e5a21461032c57806309d46bd51461036e5780630b9da51c146103a357806314c2e12f146103c357806319f3d0a71461040a5780631b5e0a7314610431575b600080fd5b6103537f000000000000000000000000000000000000000000000000000000000000000081565b60405164ffffffffff90911681526020015b60405180910390f35b6103957f000000000000000000000000000000000000000000000000000000000000000081565b604051908152602001610365565b6103b66103b1366004614f0d565b610a56565b6040516103659190614fb0565b6008546103e69060ff8082169161010081049091169062010000900461ffff1683565b6040805160ff948516815293909216602084015261ffff1690820152606001610365565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b610460610b35565b60405161ffff9091168152602001610365565b610486610481366004614fbf565b610c9f565b005b62093a80610395565b6005546104a4906001600160a01b031681565b6040516001600160a01b039091168152602001610365565b6104cf6104ca366004614fd8565b610daa565b6040516103659291906150f1565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6104607f000000000000000000000000000000000000000000000000000000000000000081565b610486610539366004615114565b6112d3565b6104607f000000000000000000000000000000000000000000000000000000000000000081565b610486610573366004614fbf565b61146f565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6104607f000000000000000000000000000000000000000000000000000000000000000081565b6106147f000000000000000000000000000000000000000000000000000000000000000081565b60405160ff9091168152602001610365565b61062e611768565b6040519015158152602001610365565b6009546106649060ff8082169161010081049091169062010000900464ffffffffff1683565b6040805160ff948516815293909216602084015264ffffffffff1690820152606001610365565b6106147f000000000000000000000000000000000000000000000000000000000000000081565b6104607f000000000000000000000000000000000000000000000000000000000000000081565b6103536106e7366004615136565b60066020526000908152604090205464ffffffffff1681565b61039560045481565b61039560015481565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6104607f000000000000000000000000000000000000000000000000000000000000000081565b610486610795366004614fbf565b6117ed565b61039560035481565b61039560025481565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6007546103539064ffffffffff1681565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6104a47f000000000000000000000000000000000000000000000000000000000000000081565b610486610840366004614f0d565b6118f0565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6104607f000000000000000000000000000000000000000000000000000000000000000081565b6104866108a1366004615136565b611b2d565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6103b6610929366004615153565b611c3d565b6106147f000000000000000000000000000000000000000000000000000000000000000081565b6104607f000000000000000000000000000000000000000000000000000000000000000081565b7f00000000000000000000000000000000000000000000000000000000000000006104a4565b6104607f000000000000000000000000000000000000000000000000000000000000000081565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6104607f000000000000000000000000000000000000000000000000000000000000000081565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b60055461035390600160a01b900464ffffffffff1681565b610a5e614d30565b610a67826128ea565b60055482516001600160a01b03908116911614610b2657600554600154604051631b27682360e21b81527370effb18025d5718b975a453cb50cb6c3f00543d92636c9da08c92610ac8926001600160a01b03909216918791906004016151e1565b602060405180830381865af4158015610ae5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b09919061520d565b610b265760405163be6d74d960e01b815260040160405180910390fd5b610b2f82612fad565b92915050565b6000610b3f6130ed565b15610b6957507f000000000000000000000000000000000000000000000000000000000000000090565b600061ffff7f00000000000000000000000000000000000000000000000000000000000000001615610bed5760075461ffff7f000000000000000000000000000000000000000000000000000000000000000016906201518090610bd49064ffffffffff1642615245565b610bde9190615279565b610be89190615279565b610bf0565b60005b90506000610c2261ffff7f0000000000000000000000000000000000000000000000000000000000000000168361529d565b606554909150600090610c3a90839061ffff166152c6565b90507f000000000000000000000000000000000000000000000000000000000000000061ffff168164ffffffffff161115610c98577f0000000000000000000000000000000000000000000000000000000000000000935050505090565b9392505050565b604051632474521560e21b81527f29f066ba98b1de62c9c969c781ec5d316c4e96752461c65aa1a1f8b71b81895560048201819052336024830152907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906391d1485490604401602060405180830381865afa158015610d2c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d50919061520d565b610d6d57604051634ca8886760e01b815260040160405180910390fd5b60018290556040518281527f7fb536150735f6239dc94ea9260169d08c02e5442b3046e6b9f4f4dc46d8406c906020015b60405180910390a15050565b600060606000610db985613119565b60055486519192506001600160a01b03908116911603610e3657610de1858260a0015161346d565b7f6dc83a6200630225027dad34801b66484afdecbfff6ed4e071c2d930e25f46d9818587604051610e14939291906152e4565b60405180910390a15050604080516020810190915260008152600191506112cc565b610e3e613891565b6007547f000000000000000000000000000000000000000000000000000000000000000090610e749064ffffffffff1642615245565b64ffffffffff161015610e99576040516275f7b160e31b815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000008160a001511115610ede57604051637546bf8160e11b815260040160405180910390fd5b60055460608601516001600160a01b039182169116036110e6576000610f7f8260800151600560009054906101000a90046001600160a01b03166001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f799190615343565b906138b9565b90508160600151600560009054906101000a90046001600160a01b03166001600160a01b0316636fcb5f3d6040518163ffffffff1660e01b8152600401608060405180830381865afa158015610fd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ffd919061535c565b51101561101d5760405163d1f1451d60e01b815260040160405180910390fd5b670de0b6b3a76400006004548261103491906153c1565b61103e91906153d8565b8260600151600560009054906101000a90046001600160a01b03166001600160a01b0316636fcb5f3d6040518163ffffffff1660e01b8152600401608060405180830381865afa158015611096573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ba919061535c565b516110c591906153ec565b10156110e45760405163d1f1451d60e01b815260040160405180910390fd5b505b60006110f1866138d4565b90507f00000000000000000000000000000000000000000000000000000000000000008160c00151131561113857604051638e8e87d960e01b815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000008160e00151611167906153ff565b131561118657604051635fbb969b60e01b815260040160405180910390fd5b6000611190610b35565b61ffff16905086608001516001600160a01b031687602001516001600160a01b0316036111c5576111c26002826153d8565b90505b6000670de0b6b3a76400006112136111e086606001516139d2565b8961012001516111f0919061541b565b6111fd87604001516139d2565b86610120015161120d919061541b565b90613a00565b61121d919061544b565b9050600061016d61122d846139d2565b611237908461541b565b611241919061544b565b905061125085608001516139d2565b811361126f576040516316f55c9960e11b815260040160405180910390fd5b7f890916ed0fa0e4f234201e8e043e312221cbf025f6673980eca923556b3a877b858a8a8787876040516112a896959493929190615479565b60405180910390a16001604051806020016040528060008152509650965050505050505b9250929050565b604051632474521560e21b81527f29f066ba98b1de62c9c969c781ec5d316c4e96752461c65aa1a1f8b71b81895560048201819052336024830152907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906391d1485490604401602060405180830381865afa158015611360573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611384919061520d565b6113a157604051634ca8886760e01b815260040160405180910390fd5b6003839055600482905582158015906113bc57506000600454115b80156113cc575060045460035410155b156113ea576040516317d1aa3960e31b815260040160405180910390fd5b6003541580156113fb575060045415155b806114125750600354158015906114125750600454155b15611430576040516317d1aa3960e31b815260040160405180910390fd5b60408051848152602081018490527f2522c552407bc03820bf5d7eaae11ff1d451b3a408500f5db2ced251a024db7f91015b60405180910390a1505050565b6005546001600160a01b0316331461149a5760405163ba6819f760e01b815260040160405180910390fd5b426114a760098383613a1b565b6114af613b9b565b5060095460ff7f0000000000000000000000000000000000000000000000000000000000000000811691161180156114ec57506114ea611768565b155b1561176457604080516080810182526009805460ff8082168452610100820416602084015262010000900464ffffffffff16828401528251610b60810193849052600093611593937f00000000000000000000000000000000000000000000000000000000000000009390929091606084019190600a90605b9082845b81548152602001906001019080831161156957505050505081525050613c2090919063ffffffff16565b604080516080810182526009805460ff80821684526101008204166020808501919091526201000090910464ffffffffff16838501528351610b60810194859052600a80548252959650600095611635957f000000000000000000000000000000000000000000000000000000000000000095949360608601939291605b91600b90850180831161156957505050505081525050613c2090919063ffffffff16565b604080516080810182526009805460ff80821684526101008204166020808501919091526201000090910464ffffffffff16838501528351610b60810194859052600a805482529596506000956116d7957f000000000000000000000000000000000000000000000000000000000000000095949360608601939291605b91600b90850180831161156957505050505081525050613c2090919063ffffffff16565b905082851080156116e757508185105b80156116f257508085105b15611760576005805464ffffffffff60a01b1916600160a01b64ffffffffff8716021790556040805186815260208101859052908101839052606081018290527fb21f4046ce7ada58e6b837de39b02f7e71e34c526b4a88ebeff19feb47df20d39060800160405180910390a15b5050505b5050565b600554600090600160a01b900464ffffffffff1681036117885750600090565b60006117bb61ffff7f0000000000000000000000000000000000000000000000000000000000000000166201518061529d565b60055490915064ffffffffff808316916117de91600160a01b9091041642615245565b64ffffffffff16111591505090565b604051632474521560e21b81527f29f066ba98b1de62c9c969c781ec5d316c4e96752461c65aa1a1f8b71b81895560048201819052336024830152907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906391d1485490604401602060405180830381865afa15801561187a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189e919061520d565b6118bb57604051634ca8886760e01b815260040160405180910390fd5b60028290556040518281527f86f1132636137ed5c3d54a7e920be1bc10378caf3f600eb15e67df2423fb182f90602001610d9e565b6005546001600160a01b0316331461191b5760405163ba6819f760e01b815260040160405180910390fd5b611923613b9b565b6119465761192f610b35565b6065805461ffff191661ffff929092169190911790555b60055481516001600160a01b039182169116811461199d576007805464ffffffffff421664ffffffffff19918216811790925583516001600160a01b03166000908152600660205260409020805490911690911790555b806001600160a01b031682606001516001600160a01b0316141580156119d95750806001600160a01b031682600001516001600160a01b031614155b15611ac95760608201516001600160a01b031660009081526006602052604081205464ffffffffff1690611a0b610b35565b61ffff169050611a1e816201518061529d565b60075464ffffffffff91821691611a3791859116615245565b64ffffffffff161015611a5557611a5060086001613c9e565b611a61565b611a6160086000613c9e565b606084810151600754604080516001600160a01b03909316835264ffffffffff9182166020840152858216908301528316918101919091527fec5778e96082e7b6d7c8cd6c03242aa325a9460fb2ca79ef07af28fdf69323409060800160405180910390a150505b600854610100900460ff16600a148015611b0e575060085461ffff7f00000000000000000000000000000000000000000000000000000000000000001660ff90911610155b1561176457611b1b613d9f565b6117646008805463ffffffff19169055565b600054610100900460ff1615808015611b4d5750600054600160ff909116105b80611b675750303b158015611b67575060005460ff166001145b611bcf5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015611bf2576000805461ff0019166101001790555b611bfb82613e86565b8015611764576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610d9e565b611c45614d30565b6005546000906001600160a01b03868116911614611cc457846001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c9b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cbf9190615507565b611d3b565b600560009054906101000a90046001600160a01b03166001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3b9190615507565b90506000611d49828761402c565b90507370effb18025d5718b975a453cb50cb6c3f00543d63216db07f600560009054906101000a90046001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a13f67616040518163ffffffff1660e01b8152600401602060405180830381865afa158015611dd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dfd9190615507565b89858a8a6040518763ffffffff1660e01b8152600401611e229695949392919061553a565b61018060405180830381865af4158015611e40573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e649190615585565b9695505050505050565b6001600160a01b038216611764578060405163eac0d38960e01b8152600401611bc6919061562b565b805160c0810151905161ffff91821691161080611ec25750805160a0810151905161ffff9182169116115b80611ed55750805151600761ffff909116105b80611ee85750805151605a61ffff909116115b15611f36576040516389a6198960e01b815260206004820152601960248201527f73776170436f73744f66667365745f696e6974496e44617973000000000000006044820152606401611bc6565b600181600001516020015161ffff161080611f5d5750600a81600001516020015161ffff16115b15611fbf576040516389a6198960e01b815260206004820152602b60248201527f73776170436f73744f66667365745f7469676874656e5468726573686f6c644960448201526a6e56696f6c6174696f6e7360a81b6064820152608401611bc6565b600181600001516040015161ffff161080611fe65750600781600001516040015161ffff16115b15612034576040516389a6198960e01b815260206004820181905260248201527f73776170436f73744f66667365745f7469676874656e53746570496e446179736044820152606401611bc6565b600e81600001516060015161ffff16108061205b5750605a81600001516060015161ffff16115b156120b5576040516389a6198960e01b815260206004820152602360248201527f73776170436f73744f66667365745f72656c61785468726573686f6c64496e4460448201526261797360e81b6064820152608401611bc6565b600181600001516080015161ffff1610806120dc5750600781600001516080015161ffff16115b1561212a576040516389a6198960e01b815260206004820152601e60248201527f73776170436f73744f66667365745f72656c617853746570496e4461797300006044820152606401611bc6565b805160c081015160a09091015161ffff918216911611158061215857506008816000015160a0015161ffff16105b8061216f5750605a816000015160a0015161ffff16115b156121bd576040516389a6198960e01b815260206004820152601860248201527f73776170436f73744f66667365745f6d6178496e4461797300000000000000006044820152606401611bc6565b6007816000015160c0015161ffff1610806121e45750605a816000015160c0015161ffff16115b15612232576040516389a6198960e01b815260206004820152601860248201527f73776170436f73744f66667365745f6d696e496e4461797300000000000000006044820152606401611bc6565b61227c81602001516000015160ff166040518060400160405280601b81526020017f6e61764c6f6f6b6261636b5f6c6f6f6b6261636b31496e446179730000000000815250614185565b602081015151605b60ff9091161015806122a55750605b60ff1681602001516020015160ff1610155b806122be5750605b60ff1681602001516040015160ff16115b156122fe576040516389a6198960e01b815260206004820152600f60248201526e0dcc2ec98deded6c4c2c6d6bedac2f608b1b6044820152606401611bc6565b60208082015190810151905160ff9182169116101580612334575080602001516040015160ff1681602001516020015160ff1610155b15612376576040516389a6198960e01b81526020600482015260116024820152706e61764c6f6f6b6261636b5f737465707360781b6044820152606401611bc6565b6123a0816040015160600151604051806060016040528060258152602001615e3f602591396141a8565b6123ca816040015160400151604051806060016040528060268152602001615df8602691396141a8565b6123f4816040015160200151604051806060016040528060218152602001615e1e602191396141a8565b61241e816040015160000151604051806060016040528060238152602001615dd5602391396141a8565b606081015151620f42401015612470576040516389a6198960e01b81526020600482015260166024820152751b5bd9195b15d95a59da1d1cd7d8985cd9565a595b1960521b6044820152606401611bc6565b620f424081606001516020015111156124c4576040516389a6198960e01b81526020600482015260156024820152741b5bd9195b15d95a59da1d1cd7d99959565a595b19605a1b6044820152606401611bc6565b620f42408160600151604001511115612520576040516389a6198960e01b815260206004820152601b60248201527f6d6f64656c576569676874735f696e63656e746976655969656c6400000000006044820152606401611bc6565b620f42408160600151606001511115612574576040516389a6198960e01b81526020600482015260156024820152746d6f64656c576569676874735f736c617368696e6760581b6044820152606401611bc6565b620f424081606001516080015113156125d0576040516389a6198960e01b815260206004820152601e60248201527f6d6f64656c576569676874735f7072696365446973636f756e744578697400006044820152606401611bc6565b620f4240816060015160a00151131561262c576040516389a6198960e01b815260206004820152601f60248201527f6d6f64656c576569676874735f7072696365446973636f756e74456e746572006044820152606401611bc6565b620f4240816060015160c001511315612688576040516389a6198960e01b815260206004820152601960248201527f6d6f64656c576569676874735f70726963655072656d69756d000000000000006044820152606401611bc6565b6007816080015161ffff1610806126a75750605a816080015161ffff16115b156126f5576040516389a6198960e01b815260206004820152601a60248201527f7061757365526562616c616e6365506572696f64496e446179730000000000006044820152606401611bc6565b610e108160a00151108061270f575062278d008160a00151115b1561275d576040516389a6198960e01b815260206004820152601960248201527f726562616c616e636554696d65476170496e5365636f6e6473000000000000006044820152606401611bc6565b61278d8160c001516040518060400160405280600a8152602001696d61785072656d69756d60b01b8152506141d3565b6127bd8160e001516040518060400160405280600a8152602001696d61785072656d69756d60b01b8152506141d3565b610e1081610100015164ffffffffff1610806127e7575062093a8081610100015164ffffffffff16115b15612835576040516389a6198960e01b815260206004820152601b60248201527f7374616c6544617461546f6c6572616e6365496e5365636f6e647300000000006044820152606401611bc6565b6000816101200151128061285557506706f05b59d3b20000816101200151135b15612898576040516389a6198960e01b81526020600482015260126024820152711b585e105b1b1bddd959111a5cd8dbdd5b9d60721b6044820152606401611bc6565b6101f481610140015111156128e7576040516389a6198960e01b81526020600482015260146024820152736c73745072696365476170546f6c6572616e636560601b6044820152606401611bc6565b50565b61291d81600001516040518060400160405280600d81526020016c3232b9ba34b730ba34b7b724b760991b815250611e6e565b61295181606001516040518060400160405280600e81526020016d19195cdd1a5b985d1a5bdb93dd5d60921b815250611e6e565b61297e8160200151604051806040016040528060078152602001663a37b5b2b724b760c91b815250611e6e565b6129ac8160800151604051806040016040528060088152602001671d1bdad95b93dd5d60c21b815250611e6e565b6129da81604001516040518060400160405280600881526020016730b6b7bab73a24b760c11b815250614209565b612a098160a0015160405180604001604052806009815260200168185b5bdd5b9d13dd5d60ba1b815250614209565b8051612a149061422c565b612a21816060015161422c565b600560009054906101000a90046001600160a01b03166001600160a01b031663bf86d6906040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a98919061520d565b8015612ab4575060055481516001600160a01b03908116911614155b15612ad2576040516306c7e2e560e11b815260040160405180910390fd5b80606001516001600160a01b031681600001516001600160a01b031603612b0c576040516307737b6160e41b815260040160405180910390fd5b600554604080516338d52e0f60e01b815290516000926001600160a01b0316916338d52e0f9160048083019260209291908290030181865afa158015612b56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b7a9190615507565b60055483519192506001600160a01b03908116911603612bda57806001600160a01b031682602001516001600160a01b031614612bd557815160208301516040516349223f2f60e11b8152611bc6929190849060040161563e565b612ceb565b600082600001519050806001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c459190615507565b6001600160a01b031683602001516001600160a01b031614612ce9578260000151816001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ca4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cc89190615507565b84602001516040516349223f2f60e11b8152600401611bc69392919061563e565b505b60055460608301516001600160a01b03918216911603612df657806001600160a01b031682608001516001600160a01b031614612d495781606001518260800151826040516349223f2f60e11b8152600401611bc69392919061563e565b600560009054906101000a90046001600160a01b03166001600160a01b0316636fcb5f3d6040518163ffffffff1660e01b8152600401608060405180830381865afa158015612d9c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dc0919061535c565b5160a0830151111561176457608082015160405163477da5bf60e01b81526001600160a01b039091166004820152602401611bc6565b600082606001519050806001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015612e3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e619190615507565b6001600160a01b031683608001516001600160a01b031614612f05578260600151816001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ec0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ee49190615507565b84608001516040516349223f2f60e11b8152600401611bc69392919061563e565b6005546040516370a0823160e01b81526001600160a01b039182166004820152908216906370a0823190602401602060405180830381865afa158015612f4f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f739190615343565b8360a001511115612fa857608083015160405163477da5bf60e01b81526001600160a01b039091166004820152602401611bc6565b505050565b612fb5614d30565b6000612fc98360800151846060015161402c565b90507370effb18025d5718b975a453cb50cb6c3f00543d63216db07f600560009054906101000a90046001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a13f67616040518163ffffffff1660e01b8152600401602060405180830381865afa158015613059573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061307d9190615507565b86606001518560018960a001516040518763ffffffff1660e01b81526004016130ab9695949392919061553a565b61018060405180830381865af41580156130c9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c989190615585565b600554600090600160a01b900464ffffffffff16158015906131145750613112611768565b155b905090565b6131526040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b600082608001516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613196573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131ba9190615672565b9050600083602001516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613200573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132249190615672565b60055460608601519192506001600160a01b0390811691600091168290036132565761325184600a615771565b6132be565b85606001516001600160a01b031663708b0b5b6040518163ffffffff1660e01b81526004016020604051808303816000875af115801561329a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132be9190615343565b90506000826001600160a01b031687600001516001600160a01b0316036132ef576132ea84600a615771565b613357565b86600001516001600160a01b031663708b0b5b6040518163ffffffff1660e01b81526004016020604051808303816000875af1158015613333573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133579190615343565b90506000836001600160a01b031688606001516001600160a01b031603613382578760a001516133a6565b61338d86600a615771565b60a089015161339c90856153c1565b6133a691906153d8565b90506000846001600160a01b031689600001516001600160a01b0316036133d15788604001516133f5565b6133dc86600a615771565b60408a01516133eb90856153c1565b6133f591906153d8565b9050600061340383836138b9565b90506000831561342f578361342083670de0b6b3a76400006153c1565b61342a91906153d8565b613432565b60005b6040805160c081018252968752602087019790975295850192909252606084019290925250608082015260a081019190915295945050505050565b60008260600151905060008060069050826001600160a01b031663bf86d6906040518163ffffffff1660e01b8152600401602060405180830381865afa1580156134bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134df919061520d565b1561350b57507f0000000000000000000000000000000000000000000000000000000000000000905060005b600560009054906101000a90046001600160a01b03166001600160a01b031663bf86d6906040518163ffffffff1660e01b8152600401602060405180830381865afa15801561355e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613582919061520d565b80156135ad5750817f0000000000000000000000000000000000000000000000000000000000000000115b156135d957507f0000000000000000000000000000000000000000000000000000000000000000905060015b6135e28561434f565b801561360d5750817f0000000000000000000000000000000000000000000000000000000000000000115b1561363957507f0000000000000000000000000000000000000000000000000000000000000000905060055b6136428561456c565b801561366d5750817f0000000000000000000000000000000000000000000000000000000000000000115b1561369957507f0000000000000000000000000000000000000000000000000000000000000000905060025b600554606086015160405163e225df1b60e01b81526001600160a01b03918216600482015291169063e225df1b90602401602060405180830381865afa1580156136e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061370b919061520d565b80156137365750817f0000000000000000000000000000000000000000000000000000000000000000115b1561376257507f0000000000000000000000000000000000000000000000000000000000000000905060035b817f0000000000000000000000000000000000000000000000000000000000000000111561381457506004600061379884614762565b9050670de0b6b3a7640000811080156137b657506137b68682614979565b156137df577f000000000000000000000000000000000000000000000000000000000000000092505b6040518181527f63995d2aabf0fe9ae27a7d7f6bf4acae34f0b1700fb28086a13352b1ab7daad89060200160405180910390a1505b7ff5cd2d774b43b300136086f0759cc02fd561c8e82fe3e9ae3786561ae9bf5b5381838660405161384793929190615780565b60405180910390a181600003613870576040516379c30bc160e01b815260040160405180910390fd5b8184111561176057604051637546bf8160e11b815260040160405180910390fd5b613899611768565b156138b75760405163e628b94960e01b815260040160405180910390fd5b565b60008282106138ca57506000610b2f565b610c9882846153ec565b6138dc614d30565b60006138f08360200151846000015161402c565b90507370effb18025d5718b975a453cb50cb6c3f00543d63216db07f600560009054906101000a90046001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a13f67616040518163ffffffff1660e01b8152600401602060405180830381865afa158015613980573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139a49190615507565b866000015185600089604001516040518763ffffffff1660e01b81526004016130ab9695949392919061553a565b60006001600160ff1b038211156139fc5760405163d255e99f60e01b815260040160405180910390fd5b5090565b6000828212613a1157506000610b2f565b610c9882846157a8565b825464ffffffffff6201000090910481169082161015613a685782546040516328d7624d60e01b81526201000090910464ffffffffff908116600483015282166024820152604401611bc6565b82546201518090613a869062010000900464ffffffffff1683615245565b64ffffffffff1610613afc57825462010000900464ffffffffff1615613adf578254605b90613abe90610100900460ff1660016157c8565b613ac891906157e1565b835460ff919091166101000261ff00199091161783555b825466ffffffffff000019166201000064ffffffffff8316021783555b825482906001850190610100900460ff16605b8110613b1d57613b1d615803565b01558254605b60ff9091161015613b5f5782546001908490600090613b4690849060ff166157c8565b92506101000a81548160ff021916908360ff1602179055505b6040805183815264ffffffffff831660208201527fd18f60bba314274d4b3c7fc79e0a27db22275670859a4aa96cefe588a80cab1f9101611462565b6000613ba56130ed565b613baf5750600090565b6005805464ffffffffff60a01b191690556040517f325597e0208ab761674ac3e02ee5ddc7b06819d649638bb5182b05f15b05fa9890600090a1506065805461ffff19167f000000000000000000000000000000000000000000000000000000000000000061ffff16179055600190565b6000826000015160ff168260ff1610613c4c57604051632bdc4a3b60e01b815260040160405180910390fd5b6000605b838560200151605b613c6291906157c8565b613c6c9190615819565b613c7691906157e1565b905083606001518160ff16605b8110613c9157613c91615803565b6020020151949350505050565b815463ffff00001981166201000091829004600181901b61fffe169092021783556102001615158115613d1c57825463ffff000019811660016201000080840461ffff168217029182178655918591600091613d0391859160ff9081169116176157c8565b92506101000a81548160ff021916908360ff1602179055505b8015613d535782546001908490600090613d3a90849060ff16615819565b92506101000a81548160ff021916908360ff1602179055505b8254600a61010090910460ff161015612fa857825460019084908290613d82908290610100900460ff166157c8565b92506101000a81548160ff021916908360ff160217905550505050565b6000613da9610b35565b905060007f000000000000000000000000000000000000000000000000000000000000000061ffff168261ffff161115613e0a57613e077f000000000000000000000000000000000000000000000000000000000000000083615832565b90505b7f000000000000000000000000000000000000000000000000000000000000000061ffff168161ffff161015613e6f5750506065805461ffff19167f000000000000000000000000000000000000000000000000000000000000000061ffff16179055565b6065805461ffff831661ffff199091161790555050565b613eb1816040518060400160405280600981526020016817d85d5d1bd41bdbdb60ba1b815250611e6e565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b031663f12baf5c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613f19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f3d9190615507565b6001600160a01b031614613f645760405163da4304b560e01b815260040160405180910390fd5b600580546001600160a01b0319166001600160a01b038316179055613fa97f000000000000000000000000000000000000000000000000000000000000000042615245565b6007805464ffffffffff191664ffffffffff92909216919091179055506065805461ffff19167f000000000000000000000000000000000000000000000000000000000000000061ffff161790557f0000000000000000000000000000000000000000000000000000000000000000600155603260025560006003819055600455565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f3c274f76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561408d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140b19190615507565b6005549091506001600160a01b039081169084160361413e576040516334ff2eeb60e01b81526001600160a01b0385811660048301528216906334ff2eeb906024016020604051808303816000875af1158015614112573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141369190615343565b915050610b2f565b826001600160a01b031663ae41ee4d6040518163ffffffff1660e01b81526004016020604051808303816000875af1158015614112573d6000803e3d6000fd5b5092915050565b8160000361176457806040516389a6198960e01b8152600401611bc6919061562b565b6703782dace9d9000082111561176457806040516389a6198960e01b8152600401611bc6919061562b565b6703782dace9d900008213806141e95750600082125b1561176457806040516389a6198960e01b8152600401611bc6919061562b565b816000036117645780604051634389d5ab60e01b8152600401611bc6919061562b565b6005546001600160a01b03908116908216036142455750565b600554604051635d344d0960e11b81526001600160a01b0383811660048301529091169063ba689a1290602401602060405180830381865afa15801561428f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142b3919061520d565b80614327575060055460405163e225df1b60e01b81526001600160a01b0383811660048301529091169063e225df1b90602401602060405180830381865afa158015614303573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614327919061520d565b6128e75760405163faef606760e01b81526001600160a01b0382166004820152602401611bc6565b6005546060820151604051630c8020a160e11b81526001600160a01b0391821660048201526000928392169063190041429060240160a060405180830381865afa1580156143a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143c5919061584d565b90506143f56040518060400160405280600881526020016744657374496e666f60c01b8152508260600151614c3e565b60055460408051636fcb5f3d60e01b815290516000926001600160a01b031691636fcb5f3d9160048083019260809291908290030181865afa15801561443f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614463919061535c565b51604085015190915060009061447990836158bc565b90506000600560009054906101000a90046001600160a01b03166001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa1580156144d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144f49190615343565b6003549091508161450d85670de0b6b3a76400006153c1565b61451791906153d8565b10156145605760045461453190662386f26fc100006158bc565b8161454484670de0b6b3a76400006153c1565b61454e91906153d8565b10156145605750600195945050505050565b50600095945050505050565b6060810151600554604051630c8020a160e11b81526001600160a01b03808416600483015260009392849291169063190041429060240160a060405180830381865afa1580156145c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145e4919061584d565b90506146146040518060400160405280600881526020016744657374496e666f60c01b8152508260600151614c3e565b6005546040516370a0823160e01b81526001600160a01b0391821660048201526000918416906370a0823190602401602060405180830381865afa158015614660573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146849190615343565b9050600082608001516000146146b557608083015183516146a69084906153c1565b6146b091906153d8565b6146b8565b60005b9050600254600560009054906101000a90046001600160a01b03166001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa158015614710573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147349190615343565b61474690670de0b6b3a76400006153c1565b61475091906153d8565b61454e82670de0b6b3a76400006153c1565b600080620493e0905060006007905060006207a12090506000856001600160a01b031663c59d48476040518163ffffffff1660e01b8152600401602060405180830381865afa1580156147b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147dd9190615507565b6001600160a01b0316639fa6a6e36040518163ffffffff1660e01b81526004016000604051808303816000875af115801561481c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526148449190810190615cf3565b6080810151805191925090670de0b6b3a764000060005b8281101561496c57600084828151811061487757614877615803565b6020026020010151905060008061489383606001518c8b614c91565b604080860151815188815260208101859052918201839052606082015291935091507f02472faa99f17c3831b25bc1545db4d576d7f076957e433664f9fc028c46713e9060800160405180910390a16148f18964174876e8006153c1565b8360400151121580156149045750898110155b1561491c575060009c9b505050505050505050505050565b61492b8b64174876e8006153c1565b83604001511215801561493e5750898210155b15614958576149558567016345785d8a0000614d1a565b94505b5050508061496590615dbb565b905061485b565b5098975050505050505050565b60008160000361498b57506001610b2f565b6060830151600554604051630c8020a160e11b81526001600160a01b038084166004830152600092169063190041429060240160a060405180830381865afa1580156149db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906149ff919061584d565b9050614a2f6040518060400160405280600881526020016744657374496e666f60c01b8152508260600151614c3e565b6005546040516370a0823160e01b81526001600160a01b0391821660048201526000918416906370a0823190602401602060405180830381865afa158015614a7b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614a9f9190615343565b905060008260800151600014614ad05760808301518351614ac19084906153c1565b614acb91906153d8565b614ad3565b60005b905060008760a0015183614ae791906153ec565b604051631061be6560e01b8152600481018290529091506000906001600160a01b03871690631061be65906024016020604051808303816000875af1158015614b34573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614b589190615343565b9050600083828b60400151600560009054906101000a90046001600160a01b03166001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa158015614bb6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614bda9190615343565b614be491906158bc565b614bee91906158bc565b614bf891906153ec565b90508015614c2e578881614c1484670de0b6b3a76400006153c1565b614c1e91906153d8565b1015975050505050505050610b2f565b6001975050505050505050610b2f565b64ffffffffff7f000000000000000000000000000000000000000000000000000000000000000016614c7082426153ec565b11156117645781604051633766569560e21b8152600401611bc6919061562b565b600080600a815b81811015614d1057858782600a8110614cb357614cb3615803565b602002015162ffffff1610614cd057614ccd6001856158bc565b93505b848782600a8110614ce357614ce3615803565b602002015162ffffff1610614d0057614cfd6001846158bc565b92505b614d0981615dbb565b9050614c98565b5050935093915050565b6000818310614d295781610c98565b5090919050565b60405180610180016040528060006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b634e487b7160e01b600052604160045260246000fd5b60405161018081016001600160401b0381118282101715614dd357614dd3614d9a565b60405290565b60405160a081016001600160401b0381118282101715614dd357614dd3614d9a565b60405160e081016001600160401b0381118282101715614dd357614dd3614d9a565b604051601f8201601f191681016001600160401b0381118282101715614e4557614e45614d9a565b604052919050565b6001600160a01b03811681146128e757600080fd5b8035614e6d81614e4d565b919050565b600060c08284031215614e8457600080fd5b60405160c081018181106001600160401b0382111715614ea657614ea6614d9a565b6040529050808235614eb781614e4d565b81526020830135614ec781614e4d565b6020820152604083810135908201526060830135614ee481614e4d565b60608201526080830135614ef781614e4d565b608082015260a092830135920191909152919050565b600060c08284031215614f1f57600080fd5b610c988383614e72565b80516001600160a01b031682526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e08301526101008082015181840152506101208082015181840152506101408082015181840152506101608082015181840152505050565b6101808101610b2f8284614f29565b600060208284031215614fd157600080fd5b5035919050565b600080828403610240811215614fed57600080fd5b614ff78585614e72565b92506101808060bf198301121561500d57600080fd5b615015614db0565b915061502360c08601614e62565b825260e085013560208301526101008086013560408401526101208087013560608501526101408088013560808601526101608089013560a08701528489013560c08701526101a089013560e08701526101c0890135848701526101e08901358387015261020089013582870152610220890135818701525050505050809150509250929050565b6000815180845260005b818110156150d1576020818501810151868301820152016150b5565b506000602082860101526020601f19601f83011685010191505092915050565b821515815260406020820152600061510c60408301846150ab565b949350505050565b6000806040838503121561512757600080fd5b50508035926020909101359150565b60006020828403121561514857600080fd5b8135610c9881614e4d565b60008060006060848603121561516857600080fd5b833561517381614e4d565b925060208401356002811061518757600080fd5b929592945050506040919091013590565b80516001600160a01b039081168352602080830151821690840152604080830151908401526060808301518216908401526080808301519091169083015260a090810151910152565b6001600160a01b038416815261010081016151ff6020830185615198565b8260e0830152949350505050565b60006020828403121561521f57600080fd5b81518015158114610c9857600080fd5b634e487b7160e01b600052601160045260246000fd5b64ffffffffff82811682821603908082111561417e5761417e61522f565b634e487b7160e01b600052601260045260246000fd5b600064ffffffffff8084168061529157615291615263565b92169190910492915050565b64ffffffffff8181168382160280821691908281146152be576152be61522f565b505092915050565b64ffffffffff81811683821601908082111561417e5761417e61522f565b61030081016153288286805182526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a08301525050565b61533560c0830185614f29565b61510c610240830184615198565b60006020828403121561535557600080fd5b5051919050565b60006080828403121561536e57600080fd5b604051608081018181106001600160401b038211171561539057615390614d9a565b8060405250825181526020830151602082015260408301516040820152606083015160608201528091505092915050565b8082028115828204841417610b2f57610b2f61522f565b6000826153e7576153e7615263565b500490565b81810381811115610b2f57610b2f61522f565b6000600160ff1b82016154145761541461522f565b5060000390565b80820260008212600160ff1b841416156154375761543761522f565b8181058314821517610b2f57610b2f61522f565b60008261545a5761545a615263565b600160ff1b8214600019841416156154745761547461522f565b500590565b6104c081016154bd8289805182526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a08301525050565b6154ca60c0830188615198565b6154d8610180830187614f29565b6154e6610300830186614f29565b6104808201939093526104a00152949350505050565b8051614e6d81614e4d565b60006020828403121561551957600080fd5b8151610c9881614e4d565b634e487b7160e01b600052602160045260246000fd5b6001600160a01b0387811682528681166020830152851660408201526060810184905260c081016002841061557157615571615524565b608082019390935260a00152949350505050565b6000610180828403121561559857600080fd5b6155a0614db0565b6155a9836154fc565b81526020830151602082015260408301516040820152606083015160608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e08201526101008084015181830152506101208084015181830152506101408084015181830152506101608084015181830152508091505092915050565b602081526000610c9860208301846150ab565b6001600160a01b0393841681529183166020830152909116604082015260600190565b805160ff81168114614e6d57600080fd5b60006020828403121561568457600080fd5b610c9882615661565b600181815b808511156156c85781600019048211156156ae576156ae61522f565b808516156156bb57918102915b93841c9390800290615692565b509250929050565b6000826156df57506001610b2f565b816156ec57506000610b2f565b8160018114615702576002811461570c57615728565b6001915050610b2f565b60ff84111561571d5761571d61522f565b50506001821b610b2f565b5060208310610133831016604e8410600b841016171561574b575081810a610b2f565b615755838361568d565b80600019048211156157695761576961522f565b029392505050565b6000610c9860ff8416836156d0565b606081016007851061579457615794615524565b938152602081019290925260409091015290565b818103600083128015838313168383128216171561417e5761417e61522f565b60ff8181168382160190811115610b2f57610b2f61522f565b600060ff8316806157f4576157f4615263565b8060ff84160691505092915050565b634e487b7160e01b600052603260045260246000fd5b60ff8281168282160390811115610b2f57610b2f61522f565b61ffff82811682821603908082111561417e5761417e61522f565b600060a0828403121561585f57600080fd5b60405160a081018181106001600160401b038211171561588157615881614d9a565b806040525082518152602083015160208201526040830151604082015260608301516060820152608083015160808201528091505092915050565b80820180821115610b2f57610b2f61522f565b60006001600160401b038211156158e8576158e8614d9a565b5060051b60200190565b600082601f83011261590357600080fd5b81516020615918615913836158cf565b614e1d565b82815260059290921b8401810191818101908684111561593757600080fd5b8286015b84811015615952578051835291830191830161593b565b509695505050505050565b600082601f83011261596e57600080fd5b8151602061597e615913836158cf565b82815260059290921b8401810191818101908684111561599d57600080fd5b8286015b848110156159525780516159b481614e4d565b83529183019183016159a1565b805164ffffffffff81168114614e6d57600080fd5b600082601f8301126159e757600080fd5b815160206159f7615913836158cf565b82815260059290921b84018101918181019086841115615a1657600080fd5b8286015b8481101561595257615a2b816159c1565b8352918301918301615a1a565b600060a08284031215615a4a57600080fd5b615a52614dd9565b90508151815260208201516001600160401b0380821115615a7257600080fd5b615a7e8583860161595d565b60208401526040840151915080821115615a9757600080fd5b615aa3858386016158f2565b60408401526060840151915080821115615abc57600080fd5b50615ac9848285016159d6565b606083015250615adb60808301615661565b608082015292915050565b600082601f830112615af757600080fd5b6040516101408082018281106001600160401b0382111715615b1b57615b1b614d9a565b60405283018185821115615b2e57600080fd5b845b82811015615b5a57805162ffffff81168114615b4c5760008081fd5b825260209182019101615b30565b509195945050505050565b600082601f830112615b7657600080fd5b60405160a081018181106001600160401b0382111715615b9857615b98614d9a565b6040528060a0840185811115615bad57600080fd5b845b81811015615b5a57615bc0816159c1565b835260209283019201615baf565b600082601f830112615bdf57600080fd5b81516020615bef615913836158cf565b82815260059290921b84018101918181019086841115615c0e57600080fd5b8286015b848110156159525780516001600160401b0380821115615c325760008081fd5b90880190610280828b03601f1901811315615c4d5760008081fd5b615c55614dfb565b878401518152604080850151898301526060808601518284015260809150615c7f8e838801615ae6565b90830152615c918d6101c08701615b65565b9082015261026084015183811115615ca95760008081fd5b615cb78d8a838801016158f2565b60a083015250908301519082821115615cd05760008081fd5b615cde8c89848701016158f2565b60c08201528652505050918301918301615c12565b600060208284031215615d0557600080fd5b81516001600160401b0380821115615d1c57600080fd5b9083019060a08286031215615d3057600080fd5b615d38614dd9565b8251815260208301516020820152604083015182811115615d5857600080fd5b615d64878286016158f2565b604083015250606083015182811115615d7c57600080fd5b615d8887828601615a38565b606083015250608083015182811115615da057600080fd5b615dac87828601615bce565b60808301525095945050505050565b600060018201615dcd57615dcd61522f565b506001019056fe736c6970706167655f6d61784e6f726d616c4f7065726174696f6e536c697070616765736c6970706167655f6d6178456d657267656e63794f7065726174696f6e536c697070616765736c6970706167655f6d61785472696d4f7065726174696f6e536c697070616765736c6970706167655f6d617853687574646f776e4f7065726174696f6e536c697070616765a2646970667358221220ab2bdee6410846224b2d9cf0d4e87b83f7bb7c8ad64bfe253e759aa3da27e91f64736f6c63430008110033736c6970706167655f6d61784e6f726d616c4f7065726174696f6e536c697070616765736c6970706167655f6d6178456d657267656e63794f7065726174696f6e536c697070616765736c6970706167655f6d61785472696d4f7065726174696f6e536c697070616765736c6970706167655f6d617853687574646f776e4f7065726174696f6e536c697070616765000000000000000000000000b20193f43c9a7184f3cbed9bad59154da01488b4000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000003c0000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000005a0000000000000000000000000000000000000000000000000011c37937e0800000000000000000000000000000000000000000000000000000470de4df820000000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000000000000000000000000000000354a6ba7a1800000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000dbba000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000b71b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f4240000000000000000000000000000000000000000000000000000000000000005a0000000000000000000000000000000000000000000000000000000000007080000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000470de4df820000000000000000000000000000000000000000000000000000000000000002a30000000000000000000000000000000000000000000000000000b1a2bc2ec50000000000000000000000000000000000000000000000000000000000000000000a
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106103275760003560e01c80639c205b9f116101b8578063c28e888a11610104578063e84aa981116100a2578063f5073f6f1161007c578063f5073f6f146109c9578063f5a67e21146109f0578063f5b28fee14610a17578063fa46197414610a3e57600080fd5b8063e84aa98114610955578063f12baf5c1461097c578063f37d9f14146109a257600080fd5b8063cc3aa353116100de578063cc3aa353146108cd578063d98646ce146108f4578063dddf00951461091b578063e47d4e391461092e57600080fd5b8063c28e888a1461086c578063c4d66de814610893578063c721500d146108a657600080fd5b8063ac5062a411610171578063b8b89e1b1161014b578063b8b89e1b146107e4578063bc43cbaf1461080b578063c0f09d9614610832578063c183673a1461084557600080fd5b8063ac5062a4146107a3578063b2680b89146107ac578063b83d8157146107d357600080fd5b80639c205b9f146107095780639f42ba9d14610712578063a2a2d95914610739578063a839601f14610760578063a98550c914610787578063aa5ed0981461079a57600080fd5b80633ef947571161027757806355eb949011610230578063756f72701161020a578063756f72701461068b5780637a39cf63146106b25780637df1ba6c146106d95780639ae111d41461070057600080fd5b806355eb9490146105ed5780635c975abb146106265780636b286faa1461063e57600080fd5b80633ef947571461052b57806341b5380a1461053e5780634244cc901461056557806348e0d4e21461057857806351b79d551461059f57806353aa3f8d146105c657600080fd5b80632265d3d8116102e457806332866e08116102be57806332866e081461049157806335c68d13146104bc5780633740ea21146104dd578063377a1a061461050457600080fd5b80632265d3d8146104585780632c68799814610473578063324fb0401461048857600080fd5b806305d3e5a21461032c57806309d46bd51461036e5780630b9da51c146103a357806314c2e12f146103c357806319f3d0a71461040a5780631b5e0a7314610431575b600080fd5b6103537f000000000000000000000000000000000000000000000000000000000002a30081565b60405164ffffffffff90911681526020015b60405180910390f35b6103957f00000000000000000000000000000000000000000000000000000000000f424081565b604051908152602001610365565b6103b66103b1366004614f0d565b610a56565b6040516103659190614fb0565b6008546103e69060ff8082169161010081049091169062010000900461ffff1683565b6040805160ff948516815293909216602084015261ffff1690820152606001610365565b6103957f00000000000000000000000000000000000000000000000000000000000b71b081565b6103957f000000000000000000000000000000000000000000000000000000000000708081565b610460610b35565b60405161ffff9091168152602001610365565b610486610481366004614fbf565b610c9f565b005b62093a80610395565b6005546104a4906001600160a01b031681565b6040516001600160a01b039091168152602001610365565b6104cf6104ca366004614fd8565b610daa565b6040516103659291906150f1565b6103957f000000000000000000000000000000000000000000000000000000000000000081565b6104607f000000000000000000000000000000000000000000000000000000000000003c81565b610486610539366004615114565b6112d3565b6104607f000000000000000000000000000000000000000000000000000000000000000581565b610486610573366004614fbf565b61146f565b6103957f00000000000000000000000000000000000000000000000000000000000f424081565b6103957f000000000000000000000000000000000000000000000000002386f26fc1000081565b6104607f000000000000000000000000000000000000000000000000000000000000003c81565b6106147f000000000000000000000000000000000000000000000000000000000000001e81565b60405160ff9091168152602001610365565b61062e611768565b6040519015158152602001610365565b6009546106649060ff8082169161010081049091169062010000900464ffffffffff1683565b6040805160ff948516815293909216602084015264ffffffffff1690820152606001610365565b6106147f000000000000000000000000000000000000000000000000000000000000003c81565b6104607f000000000000000000000000000000000000000000000000000000000000000181565b6103536106e7366004615136565b60066020526000908152604090205464ffffffffff1681565b61039560045481565b61039560015481565b6103957f00000000000000000000000000000000000000000000000000354a6ba7a1800081565b6103957f000000000000000000000000000000000000000000000000016345785d8a000081565b6104607f000000000000000000000000000000000000000000000000000000000000003c81565b610486610795366004614fbf565b6117ed565b61039560035481565b61039560025481565b6103957f000000000000000000000000000000000000000000000000000000000000000a81565b6007546103539064ffffffffff1681565b6103957f00000000000000000000000000000000000000000000000000470de4df82000081565b6104a47f0000000000000000000000006d7c75d36931535c8cdbd2e5dbdc4644a61e1ee681565b610486610840366004614f0d565b6118f0565b6103957f00000000000000000000000000000000000000000000000000000000000f424081565b6104607f000000000000000000000000000000000000000000000000000000000000000781565b6104866108a1366004615136565b611b2d565b6103957f00000000000000000000000000000000000000000000000000470de4df82000081565b6103957f00000000000000000000000000000000000000000000000000000000000dbba081565b6103957f00000000000000000000000000000000000000000000000000b1a2bc2ec5000081565b6103b6610929366004615153565b611c3d565b6106147f000000000000000000000000000000000000000000000000000000000000005a81565b6104607f000000000000000000000000000000000000000000000000000000000000000281565b7f000000000000000000000000b20193f43c9a7184f3cbed9bad59154da01488b46104a4565b6104607f000000000000000000000000000000000000000000000000000000000000001e81565b6103957f0000000000000000000000000000000000000000000000000011c37937e0800081565b6104607f000000000000000000000000000000000000000000000000000000000000005a81565b6103957f00000000000000000000000000000000000000000000000000000000000f424081565b60055461035390600160a01b900464ffffffffff1681565b610a5e614d30565b610a67826128ea565b60055482516001600160a01b03908116911614610b2657600554600154604051631b27682360e21b81527370effb18025d5718b975a453cb50cb6c3f00543d92636c9da08c92610ac8926001600160a01b03909216918791906004016151e1565b602060405180830381865af4158015610ae5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b09919061520d565b610b265760405163be6d74d960e01b815260040160405180910390fd5b610b2f82612fad565b92915050565b6000610b3f6130ed565b15610b6957507f000000000000000000000000000000000000000000000000000000000000000790565b600061ffff7f000000000000000000000000000000000000000000000000000000000000001e1615610bed5760075461ffff7f000000000000000000000000000000000000000000000000000000000000001e16906201518090610bd49064ffffffffff1642615245565b610bde9190615279565b610be89190615279565b610bf0565b60005b90506000610c2261ffff7f0000000000000000000000000000000000000000000000000000000000000001168361529d565b606554909150600090610c3a90839061ffff166152c6565b90507f000000000000000000000000000000000000000000000000000000000000003c61ffff168164ffffffffff161115610c98577f000000000000000000000000000000000000000000000000000000000000003c935050505090565b9392505050565b604051632474521560e21b81527f29f066ba98b1de62c9c969c781ec5d316c4e96752461c65aa1a1f8b71b81895560048201819052336024830152907f0000000000000000000000006d7c75d36931535c8cdbd2e5dbdc4644a61e1ee66001600160a01b0316906391d1485490604401602060405180830381865afa158015610d2c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d50919061520d565b610d6d57604051634ca8886760e01b815260040160405180910390fd5b60018290556040518281527f7fb536150735f6239dc94ea9260169d08c02e5442b3046e6b9f4f4dc46d8406c906020015b60405180910390a15050565b600060606000610db985613119565b60055486519192506001600160a01b03908116911603610e3657610de1858260a0015161346d565b7f6dc83a6200630225027dad34801b66484afdecbfff6ed4e071c2d930e25f46d9818587604051610e14939291906152e4565b60405180910390a15050604080516020810190915260008152600191506112cc565b610e3e613891565b6007547f000000000000000000000000000000000000000000000000000000000000708090610e749064ffffffffff1642615245565b64ffffffffff161015610e99576040516275f7b160e31b815260040160405180910390fd5b7f0000000000000000000000000000000000000000000000000011c37937e080008160a001511115610ede57604051637546bf8160e11b815260040160405180910390fd5b60055460608601516001600160a01b039182169116036110e6576000610f7f8260800151600560009054906101000a90046001600160a01b03166001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f799190615343565b906138b9565b90508160600151600560009054906101000a90046001600160a01b03166001600160a01b0316636fcb5f3d6040518163ffffffff1660e01b8152600401608060405180830381865afa158015610fd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ffd919061535c565b51101561101d5760405163d1f1451d60e01b815260040160405180910390fd5b670de0b6b3a76400006004548261103491906153c1565b61103e91906153d8565b8260600151600560009054906101000a90046001600160a01b03166001600160a01b0316636fcb5f3d6040518163ffffffff1660e01b8152600401608060405180830381865afa158015611096573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ba919061535c565b516110c591906153ec565b10156110e45760405163d1f1451d60e01b815260040160405180910390fd5b505b60006110f1866138d4565b90507f00000000000000000000000000000000000000000000000000470de4df8200008160c00151131561113857604051638e8e87d960e01b815260040160405180910390fd5b7f000000000000000000000000000000000000000000000000002386f26fc100008160e00151611167906153ff565b131561118657604051635fbb969b60e01b815260040160405180910390fd5b6000611190610b35565b61ffff16905086608001516001600160a01b031687602001516001600160a01b0316036111c5576111c26002826153d8565b90505b6000670de0b6b3a76400006112136111e086606001516139d2565b8961012001516111f0919061541b565b6111fd87604001516139d2565b86610120015161120d919061541b565b90613a00565b61121d919061544b565b9050600061016d61122d846139d2565b611237908461541b565b611241919061544b565b905061125085608001516139d2565b811361126f576040516316f55c9960e11b815260040160405180910390fd5b7f890916ed0fa0e4f234201e8e043e312221cbf025f6673980eca923556b3a877b858a8a8787876040516112a896959493929190615479565b60405180910390a16001604051806020016040528060008152509650965050505050505b9250929050565b604051632474521560e21b81527f29f066ba98b1de62c9c969c781ec5d316c4e96752461c65aa1a1f8b71b81895560048201819052336024830152907f0000000000000000000000006d7c75d36931535c8cdbd2e5dbdc4644a61e1ee66001600160a01b0316906391d1485490604401602060405180830381865afa158015611360573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611384919061520d565b6113a157604051634ca8886760e01b815260040160405180910390fd5b6003839055600482905582158015906113bc57506000600454115b80156113cc575060045460035410155b156113ea576040516317d1aa3960e31b815260040160405180910390fd5b6003541580156113fb575060045415155b806114125750600354158015906114125750600454155b15611430576040516317d1aa3960e31b815260040160405180910390fd5b60408051848152602081018490527f2522c552407bc03820bf5d7eaae11ff1d451b3a408500f5db2ced251a024db7f91015b60405180910390a1505050565b6005546001600160a01b0316331461149a5760405163ba6819f760e01b815260040160405180910390fd5b426114a760098383613a1b565b6114af613b9b565b5060095460ff7f000000000000000000000000000000000000000000000000000000000000005a811691161180156114ec57506114ea611768565b155b1561176457604080516080810182526009805460ff8082168452610100820416602084015262010000900464ffffffffff16828401528251610b60810193849052600093611593937f000000000000000000000000000000000000000000000000000000000000001e9390929091606084019190600a90605b9082845b81548152602001906001019080831161156957505050505081525050613c2090919063ffffffff16565b604080516080810182526009805460ff80821684526101008204166020808501919091526201000090910464ffffffffff16838501528351610b60810194859052600a80548252959650600095611635957f000000000000000000000000000000000000000000000000000000000000003c95949360608601939291605b91600b90850180831161156957505050505081525050613c2090919063ffffffff16565b604080516080810182526009805460ff80821684526101008204166020808501919091526201000090910464ffffffffff16838501528351610b60810194859052600a805482529596506000956116d7957f000000000000000000000000000000000000000000000000000000000000005a95949360608601939291605b91600b90850180831161156957505050505081525050613c2090919063ffffffff16565b905082851080156116e757508185105b80156116f257508085105b15611760576005805464ffffffffff60a01b1916600160a01b64ffffffffff8716021790556040805186815260208101859052908101839052606081018290527fb21f4046ce7ada58e6b837de39b02f7e71e34c526b4a88ebeff19feb47df20d39060800160405180910390a15b5050505b5050565b600554600090600160a01b900464ffffffffff1681036117885750600090565b60006117bb61ffff7f000000000000000000000000000000000000000000000000000000000000005a166201518061529d565b60055490915064ffffffffff808316916117de91600160a01b9091041642615245565b64ffffffffff16111591505090565b604051632474521560e21b81527f29f066ba98b1de62c9c969c781ec5d316c4e96752461c65aa1a1f8b71b81895560048201819052336024830152907f0000000000000000000000006d7c75d36931535c8cdbd2e5dbdc4644a61e1ee66001600160a01b0316906391d1485490604401602060405180830381865afa15801561187a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189e919061520d565b6118bb57604051634ca8886760e01b815260040160405180910390fd5b60028290556040518281527f86f1132636137ed5c3d54a7e920be1bc10378caf3f600eb15e67df2423fb182f90602001610d9e565b6005546001600160a01b0316331461191b5760405163ba6819f760e01b815260040160405180910390fd5b611923613b9b565b6119465761192f610b35565b6065805461ffff191661ffff929092169190911790555b60055481516001600160a01b039182169116811461199d576007805464ffffffffff421664ffffffffff19918216811790925583516001600160a01b03166000908152600660205260409020805490911690911790555b806001600160a01b031682606001516001600160a01b0316141580156119d95750806001600160a01b031682600001516001600160a01b031614155b15611ac95760608201516001600160a01b031660009081526006602052604081205464ffffffffff1690611a0b610b35565b61ffff169050611a1e816201518061529d565b60075464ffffffffff91821691611a3791859116615245565b64ffffffffff161015611a5557611a5060086001613c9e565b611a61565b611a6160086000613c9e565b606084810151600754604080516001600160a01b03909316835264ffffffffff9182166020840152858216908301528316918101919091527fec5778e96082e7b6d7c8cd6c03242aa325a9460fb2ca79ef07af28fdf69323409060800160405180910390a150505b600854610100900460ff16600a148015611b0e575060085461ffff7f00000000000000000000000000000000000000000000000000000000000000051660ff90911610155b1561176457611b1b613d9f565b6117646008805463ffffffff19169055565b600054610100900460ff1615808015611b4d5750600054600160ff909116105b80611b675750303b158015611b67575060005460ff166001145b611bcf5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015611bf2576000805461ff0019166101001790555b611bfb82613e86565b8015611764576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610d9e565b611c45614d30565b6005546000906001600160a01b03868116911614611cc457846001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c9b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cbf9190615507565b611d3b565b600560009054906101000a90046001600160a01b03166001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d3b9190615507565b90506000611d49828761402c565b90507370effb18025d5718b975a453cb50cb6c3f00543d63216db07f600560009054906101000a90046001600160a01b03167f000000000000000000000000b20193f43c9a7184f3cbed9bad59154da01488b46001600160a01b031663a13f67616040518163ffffffff1660e01b8152600401602060405180830381865afa158015611dd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dfd9190615507565b89858a8a6040518763ffffffff1660e01b8152600401611e229695949392919061553a565b61018060405180830381865af4158015611e40573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e649190615585565b9695505050505050565b6001600160a01b038216611764578060405163eac0d38960e01b8152600401611bc6919061562b565b805160c0810151905161ffff91821691161080611ec25750805160a0810151905161ffff9182169116115b80611ed55750805151600761ffff909116105b80611ee85750805151605a61ffff909116115b15611f36576040516389a6198960e01b815260206004820152601960248201527f73776170436f73744f66667365745f696e6974496e44617973000000000000006044820152606401611bc6565b600181600001516020015161ffff161080611f5d5750600a81600001516020015161ffff16115b15611fbf576040516389a6198960e01b815260206004820152602b60248201527f73776170436f73744f66667365745f7469676874656e5468726573686f6c644960448201526a6e56696f6c6174696f6e7360a81b6064820152608401611bc6565b600181600001516040015161ffff161080611fe65750600781600001516040015161ffff16115b15612034576040516389a6198960e01b815260206004820181905260248201527f73776170436f73744f66667365745f7469676874656e53746570496e446179736044820152606401611bc6565b600e81600001516060015161ffff16108061205b5750605a81600001516060015161ffff16115b156120b5576040516389a6198960e01b815260206004820152602360248201527f73776170436f73744f66667365745f72656c61785468726573686f6c64496e4460448201526261797360e81b6064820152608401611bc6565b600181600001516080015161ffff1610806120dc5750600781600001516080015161ffff16115b1561212a576040516389a6198960e01b815260206004820152601e60248201527f73776170436f73744f66667365745f72656c617853746570496e4461797300006044820152606401611bc6565b805160c081015160a09091015161ffff918216911611158061215857506008816000015160a0015161ffff16105b8061216f5750605a816000015160a0015161ffff16115b156121bd576040516389a6198960e01b815260206004820152601860248201527f73776170436f73744f66667365745f6d6178496e4461797300000000000000006044820152606401611bc6565b6007816000015160c0015161ffff1610806121e45750605a816000015160c0015161ffff16115b15612232576040516389a6198960e01b815260206004820152601860248201527f73776170436f73744f66667365745f6d696e496e4461797300000000000000006044820152606401611bc6565b61227c81602001516000015160ff166040518060400160405280601b81526020017f6e61764c6f6f6b6261636b5f6c6f6f6b6261636b31496e446179730000000000815250614185565b602081015151605b60ff9091161015806122a55750605b60ff1681602001516020015160ff1610155b806122be5750605b60ff1681602001516040015160ff16115b156122fe576040516389a6198960e01b815260206004820152600f60248201526e0dcc2ec98deded6c4c2c6d6bedac2f608b1b6044820152606401611bc6565b60208082015190810151905160ff9182169116101580612334575080602001516040015160ff1681602001516020015160ff1610155b15612376576040516389a6198960e01b81526020600482015260116024820152706e61764c6f6f6b6261636b5f737465707360781b6044820152606401611bc6565b6123a0816040015160600151604051806060016040528060258152602001615e3f602591396141a8565b6123ca816040015160400151604051806060016040528060268152602001615df8602691396141a8565b6123f4816040015160200151604051806060016040528060218152602001615e1e602191396141a8565b61241e816040015160000151604051806060016040528060238152602001615dd5602391396141a8565b606081015151620f42401015612470576040516389a6198960e01b81526020600482015260166024820152751b5bd9195b15d95a59da1d1cd7d8985cd9565a595b1960521b6044820152606401611bc6565b620f424081606001516020015111156124c4576040516389a6198960e01b81526020600482015260156024820152741b5bd9195b15d95a59da1d1cd7d99959565a595b19605a1b6044820152606401611bc6565b620f42408160600151604001511115612520576040516389a6198960e01b815260206004820152601b60248201527f6d6f64656c576569676874735f696e63656e746976655969656c6400000000006044820152606401611bc6565b620f42408160600151606001511115612574576040516389a6198960e01b81526020600482015260156024820152746d6f64656c576569676874735f736c617368696e6760581b6044820152606401611bc6565b620f424081606001516080015113156125d0576040516389a6198960e01b815260206004820152601e60248201527f6d6f64656c576569676874735f7072696365446973636f756e744578697400006044820152606401611bc6565b620f4240816060015160a00151131561262c576040516389a6198960e01b815260206004820152601f60248201527f6d6f64656c576569676874735f7072696365446973636f756e74456e746572006044820152606401611bc6565b620f4240816060015160c001511315612688576040516389a6198960e01b815260206004820152601960248201527f6d6f64656c576569676874735f70726963655072656d69756d000000000000006044820152606401611bc6565b6007816080015161ffff1610806126a75750605a816080015161ffff16115b156126f5576040516389a6198960e01b815260206004820152601a60248201527f7061757365526562616c616e6365506572696f64496e446179730000000000006044820152606401611bc6565b610e108160a00151108061270f575062278d008160a00151115b1561275d576040516389a6198960e01b815260206004820152601960248201527f726562616c616e636554696d65476170496e5365636f6e6473000000000000006044820152606401611bc6565b61278d8160c001516040518060400160405280600a8152602001696d61785072656d69756d60b01b8152506141d3565b6127bd8160e001516040518060400160405280600a8152602001696d61785072656d69756d60b01b8152506141d3565b610e1081610100015164ffffffffff1610806127e7575062093a8081610100015164ffffffffff16115b15612835576040516389a6198960e01b815260206004820152601b60248201527f7374616c6544617461546f6c6572616e6365496e5365636f6e647300000000006044820152606401611bc6565b6000816101200151128061285557506706f05b59d3b20000816101200151135b15612898576040516389a6198960e01b81526020600482015260126024820152711b585e105b1b1bddd959111a5cd8dbdd5b9d60721b6044820152606401611bc6565b6101f481610140015111156128e7576040516389a6198960e01b81526020600482015260146024820152736c73745072696365476170546f6c6572616e636560601b6044820152606401611bc6565b50565b61291d81600001516040518060400160405280600d81526020016c3232b9ba34b730ba34b7b724b760991b815250611e6e565b61295181606001516040518060400160405280600e81526020016d19195cdd1a5b985d1a5bdb93dd5d60921b815250611e6e565b61297e8160200151604051806040016040528060078152602001663a37b5b2b724b760c91b815250611e6e565b6129ac8160800151604051806040016040528060088152602001671d1bdad95b93dd5d60c21b815250611e6e565b6129da81604001516040518060400160405280600881526020016730b6b7bab73a24b760c11b815250614209565b612a098160a0015160405180604001604052806009815260200168185b5bdd5b9d13dd5d60ba1b815250614209565b8051612a149061422c565b612a21816060015161422c565b600560009054906101000a90046001600160a01b03166001600160a01b031663bf86d6906040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a98919061520d565b8015612ab4575060055481516001600160a01b03908116911614155b15612ad2576040516306c7e2e560e11b815260040160405180910390fd5b80606001516001600160a01b031681600001516001600160a01b031603612b0c576040516307737b6160e41b815260040160405180910390fd5b600554604080516338d52e0f60e01b815290516000926001600160a01b0316916338d52e0f9160048083019260209291908290030181865afa158015612b56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b7a9190615507565b60055483519192506001600160a01b03908116911603612bda57806001600160a01b031682602001516001600160a01b031614612bd557815160208301516040516349223f2f60e11b8152611bc6929190849060040161563e565b612ceb565b600082600001519050806001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c459190615507565b6001600160a01b031683602001516001600160a01b031614612ce9578260000151816001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ca4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cc89190615507565b84602001516040516349223f2f60e11b8152600401611bc69392919061563e565b505b60055460608301516001600160a01b03918216911603612df657806001600160a01b031682608001516001600160a01b031614612d495781606001518260800151826040516349223f2f60e11b8152600401611bc69392919061563e565b600560009054906101000a90046001600160a01b03166001600160a01b0316636fcb5f3d6040518163ffffffff1660e01b8152600401608060405180830381865afa158015612d9c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dc0919061535c565b5160a0830151111561176457608082015160405163477da5bf60e01b81526001600160a01b039091166004820152602401611bc6565b600082606001519050806001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015612e3d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e619190615507565b6001600160a01b031683608001516001600160a01b031614612f05578260600151816001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ec0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ee49190615507565b84608001516040516349223f2f60e11b8152600401611bc69392919061563e565b6005546040516370a0823160e01b81526001600160a01b039182166004820152908216906370a0823190602401602060405180830381865afa158015612f4f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f739190615343565b8360a001511115612fa857608083015160405163477da5bf60e01b81526001600160a01b039091166004820152602401611bc6565b505050565b612fb5614d30565b6000612fc98360800151846060015161402c565b90507370effb18025d5718b975a453cb50cb6c3f00543d63216db07f600560009054906101000a90046001600160a01b03167f000000000000000000000000b20193f43c9a7184f3cbed9bad59154da01488b46001600160a01b031663a13f67616040518163ffffffff1660e01b8152600401602060405180830381865afa158015613059573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061307d9190615507565b86606001518560018960a001516040518763ffffffff1660e01b81526004016130ab9695949392919061553a565b61018060405180830381865af41580156130c9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c989190615585565b600554600090600160a01b900464ffffffffff16158015906131145750613112611768565b155b905090565b6131526040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b600082608001516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613196573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131ba9190615672565b9050600083602001516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613200573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132249190615672565b60055460608601519192506001600160a01b0390811691600091168290036132565761325184600a615771565b6132be565b85606001516001600160a01b031663708b0b5b6040518163ffffffff1660e01b81526004016020604051808303816000875af115801561329a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132be9190615343565b90506000826001600160a01b031687600001516001600160a01b0316036132ef576132ea84600a615771565b613357565b86600001516001600160a01b031663708b0b5b6040518163ffffffff1660e01b81526004016020604051808303816000875af1158015613333573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133579190615343565b90506000836001600160a01b031688606001516001600160a01b031603613382578760a001516133a6565b61338d86600a615771565b60a089015161339c90856153c1565b6133a691906153d8565b90506000846001600160a01b031689600001516001600160a01b0316036133d15788604001516133f5565b6133dc86600a615771565b60408a01516133eb90856153c1565b6133f591906153d8565b9050600061340383836138b9565b90506000831561342f578361342083670de0b6b3a76400006153c1565b61342a91906153d8565b613432565b60005b6040805160c081018252968752602087019790975295850192909252606084019290925250608082015260a081019190915295945050505050565b60008260600151905060008060069050826001600160a01b031663bf86d6906040518163ffffffff1660e01b8152600401602060405180830381865afa1580156134bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134df919061520d565b1561350b57507f000000000000000000000000000000000000000000000000016345785d8a0000905060005b600560009054906101000a90046001600160a01b03166001600160a01b031663bf86d6906040518163ffffffff1660e01b8152600401602060405180830381865afa15801561355e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613582919061520d565b80156135ad5750817f00000000000000000000000000000000000000000000000000354a6ba7a18000115b156135d957507f00000000000000000000000000000000000000000000000000354a6ba7a18000905060015b6135e28561434f565b801561360d5750817f0000000000000000000000000000000000000000000000000011c37937e08000115b1561363957507f0000000000000000000000000000000000000000000000000011c37937e08000905060055b6136428561456c565b801561366d5750817f0000000000000000000000000000000000000000000000000011c37937e08000115b1561369957507f0000000000000000000000000000000000000000000000000011c37937e08000905060025b600554606086015160405163e225df1b60e01b81526001600160a01b03918216600482015291169063e225df1b90602401602060405180830381865afa1580156136e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061370b919061520d565b80156137365750817f0000000000000000000000000000000000000000000000000011c37937e08000115b1561376257507f0000000000000000000000000000000000000000000000000011c37937e08000905060035b817f00000000000000000000000000000000000000000000000000470de4df820000111561381457506004600061379884614762565b9050670de0b6b3a7640000811080156137b657506137b68682614979565b156137df577f00000000000000000000000000000000000000000000000000470de4df82000092505b6040518181527f63995d2aabf0fe9ae27a7d7f6bf4acae34f0b1700fb28086a13352b1ab7daad89060200160405180910390a1505b7ff5cd2d774b43b300136086f0759cc02fd561c8e82fe3e9ae3786561ae9bf5b5381838660405161384793929190615780565b60405180910390a181600003613870576040516379c30bc160e01b815260040160405180910390fd5b8184111561176057604051637546bf8160e11b815260040160405180910390fd5b613899611768565b156138b75760405163e628b94960e01b815260040160405180910390fd5b565b60008282106138ca57506000610b2f565b610c9882846153ec565b6138dc614d30565b60006138f08360200151846000015161402c565b90507370effb18025d5718b975a453cb50cb6c3f00543d63216db07f600560009054906101000a90046001600160a01b03167f000000000000000000000000b20193f43c9a7184f3cbed9bad59154da01488b46001600160a01b031663a13f67616040518163ffffffff1660e01b8152600401602060405180830381865afa158015613980573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139a49190615507565b866000015185600089604001516040518763ffffffff1660e01b81526004016130ab9695949392919061553a565b60006001600160ff1b038211156139fc5760405163d255e99f60e01b815260040160405180910390fd5b5090565b6000828212613a1157506000610b2f565b610c9882846157a8565b825464ffffffffff6201000090910481169082161015613a685782546040516328d7624d60e01b81526201000090910464ffffffffff908116600483015282166024820152604401611bc6565b82546201518090613a869062010000900464ffffffffff1683615245565b64ffffffffff1610613afc57825462010000900464ffffffffff1615613adf578254605b90613abe90610100900460ff1660016157c8565b613ac891906157e1565b835460ff919091166101000261ff00199091161783555b825466ffffffffff000019166201000064ffffffffff8316021783555b825482906001850190610100900460ff16605b8110613b1d57613b1d615803565b01558254605b60ff9091161015613b5f5782546001908490600090613b4690849060ff166157c8565b92506101000a81548160ff021916908360ff1602179055505b6040805183815264ffffffffff831660208201527fd18f60bba314274d4b3c7fc79e0a27db22275670859a4aa96cefe588a80cab1f9101611462565b6000613ba56130ed565b613baf5750600090565b6005805464ffffffffff60a01b191690556040517f325597e0208ab761674ac3e02ee5ddc7b06819d649638bb5182b05f15b05fa9890600090a1506065805461ffff19167f000000000000000000000000000000000000000000000000000000000000000761ffff16179055600190565b6000826000015160ff168260ff1610613c4c57604051632bdc4a3b60e01b815260040160405180910390fd5b6000605b838560200151605b613c6291906157c8565b613c6c9190615819565b613c7691906157e1565b905083606001518160ff16605b8110613c9157613c91615803565b6020020151949350505050565b815463ffff00001981166201000091829004600181901b61fffe169092021783556102001615158115613d1c57825463ffff000019811660016201000080840461ffff168217029182178655918591600091613d0391859160ff9081169116176157c8565b92506101000a81548160ff021916908360ff1602179055505b8015613d535782546001908490600090613d3a90849060ff16615819565b92506101000a81548160ff021916908360ff1602179055505b8254600a61010090910460ff161015612fa857825460019084908290613d82908290610100900460ff166157c8565b92506101000a81548160ff021916908360ff160217905550505050565b6000613da9610b35565b905060007f000000000000000000000000000000000000000000000000000000000000000261ffff168261ffff161115613e0a57613e077f000000000000000000000000000000000000000000000000000000000000000283615832565b90505b7f000000000000000000000000000000000000000000000000000000000000000761ffff168161ffff161015613e6f5750506065805461ffff19167f000000000000000000000000000000000000000000000000000000000000000761ffff16179055565b6065805461ffff831661ffff199091161790555050565b613eb1816040518060400160405280600981526020016817d85d5d1bd41bdbdb60ba1b815250611e6e565b7f000000000000000000000000b20193f43c9a7184f3cbed9bad59154da01488b46001600160a01b0316816001600160a01b031663f12baf5c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613f19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f3d9190615507565b6001600160a01b031614613f645760405163da4304b560e01b815260040160405180910390fd5b600580546001600160a01b0319166001600160a01b038316179055613fa97f000000000000000000000000000000000000000000000000000000000000708042615245565b6007805464ffffffffff191664ffffffffff92909216919091179055506065805461ffff19167f000000000000000000000000000000000000000000000000000000000000003c61ffff161790557f000000000000000000000000000000000000000000000000000000000000000a600155603260025560006003819055600455565b6000807f000000000000000000000000b20193f43c9a7184f3cbed9bad59154da01488b46001600160a01b031663f3c274f76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561408d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140b19190615507565b6005549091506001600160a01b039081169084160361413e576040516334ff2eeb60e01b81526001600160a01b0385811660048301528216906334ff2eeb906024016020604051808303816000875af1158015614112573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141369190615343565b915050610b2f565b826001600160a01b031663ae41ee4d6040518163ffffffff1660e01b81526004016020604051808303816000875af1158015614112573d6000803e3d6000fd5b5092915050565b8160000361176457806040516389a6198960e01b8152600401611bc6919061562b565b6703782dace9d9000082111561176457806040516389a6198960e01b8152600401611bc6919061562b565b6703782dace9d900008213806141e95750600082125b1561176457806040516389a6198960e01b8152600401611bc6919061562b565b816000036117645780604051634389d5ab60e01b8152600401611bc6919061562b565b6005546001600160a01b03908116908216036142455750565b600554604051635d344d0960e11b81526001600160a01b0383811660048301529091169063ba689a1290602401602060405180830381865afa15801561428f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142b3919061520d565b80614327575060055460405163e225df1b60e01b81526001600160a01b0383811660048301529091169063e225df1b90602401602060405180830381865afa158015614303573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614327919061520d565b6128e75760405163faef606760e01b81526001600160a01b0382166004820152602401611bc6565b6005546060820151604051630c8020a160e11b81526001600160a01b0391821660048201526000928392169063190041429060240160a060405180830381865afa1580156143a1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143c5919061584d565b90506143f56040518060400160405280600881526020016744657374496e666f60c01b8152508260600151614c3e565b60055460408051636fcb5f3d60e01b815290516000926001600160a01b031691636fcb5f3d9160048083019260809291908290030181865afa15801561443f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614463919061535c565b51604085015190915060009061447990836158bc565b90506000600560009054906101000a90046001600160a01b03166001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa1580156144d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144f49190615343565b6003549091508161450d85670de0b6b3a76400006153c1565b61451791906153d8565b10156145605760045461453190662386f26fc100006158bc565b8161454484670de0b6b3a76400006153c1565b61454e91906153d8565b10156145605750600195945050505050565b50600095945050505050565b6060810151600554604051630c8020a160e11b81526001600160a01b03808416600483015260009392849291169063190041429060240160a060405180830381865afa1580156145c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145e4919061584d565b90506146146040518060400160405280600881526020016744657374496e666f60c01b8152508260600151614c3e565b6005546040516370a0823160e01b81526001600160a01b0391821660048201526000918416906370a0823190602401602060405180830381865afa158015614660573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146849190615343565b9050600082608001516000146146b557608083015183516146a69084906153c1565b6146b091906153d8565b6146b8565b60005b9050600254600560009054906101000a90046001600160a01b03166001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa158015614710573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147349190615343565b61474690670de0b6b3a76400006153c1565b61475091906153d8565b61454e82670de0b6b3a76400006153c1565b600080620493e0905060006007905060006207a12090506000856001600160a01b031663c59d48476040518163ffffffff1660e01b8152600401602060405180830381865afa1580156147b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147dd9190615507565b6001600160a01b0316639fa6a6e36040518163ffffffff1660e01b81526004016000604051808303816000875af115801561481c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526148449190810190615cf3565b6080810151805191925090670de0b6b3a764000060005b8281101561496c57600084828151811061487757614877615803565b6020026020010151905060008061489383606001518c8b614c91565b604080860151815188815260208101859052918201839052606082015291935091507f02472faa99f17c3831b25bc1545db4d576d7f076957e433664f9fc028c46713e9060800160405180910390a16148f18964174876e8006153c1565b8360400151121580156149045750898110155b1561491c575060009c9b505050505050505050505050565b61492b8b64174876e8006153c1565b83604001511215801561493e5750898210155b15614958576149558567016345785d8a0000614d1a565b94505b5050508061496590615dbb565b905061485b565b5098975050505050505050565b60008160000361498b57506001610b2f565b6060830151600554604051630c8020a160e11b81526001600160a01b038084166004830152600092169063190041429060240160a060405180830381865afa1580156149db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906149ff919061584d565b9050614a2f6040518060400160405280600881526020016744657374496e666f60c01b8152508260600151614c3e565b6005546040516370a0823160e01b81526001600160a01b0391821660048201526000918416906370a0823190602401602060405180830381865afa158015614a7b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614a9f9190615343565b905060008260800151600014614ad05760808301518351614ac19084906153c1565b614acb91906153d8565b614ad3565b60005b905060008760a0015183614ae791906153ec565b604051631061be6560e01b8152600481018290529091506000906001600160a01b03871690631061be65906024016020604051808303816000875af1158015614b34573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614b589190615343565b9050600083828b60400151600560009054906101000a90046001600160a01b03166001600160a01b03166301e1d1146040518163ffffffff1660e01b8152600401602060405180830381865afa158015614bb6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614bda9190615343565b614be491906158bc565b614bee91906158bc565b614bf891906153ec565b90508015614c2e578881614c1484670de0b6b3a76400006153c1565b614c1e91906153d8565b1015975050505050505050610b2f565b6001975050505050505050610b2f565b64ffffffffff7f000000000000000000000000000000000000000000000000000000000002a30016614c7082426153ec565b11156117645781604051633766569560e21b8152600401611bc6919061562b565b600080600a815b81811015614d1057858782600a8110614cb357614cb3615803565b602002015162ffffff1610614cd057614ccd6001856158bc565b93505b848782600a8110614ce357614ce3615803565b602002015162ffffff1610614d0057614cfd6001846158bc565b92505b614d0981615dbb565b9050614c98565b5050935093915050565b6000818310614d295781610c98565b5090919050565b60405180610180016040528060006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b634e487b7160e01b600052604160045260246000fd5b60405161018081016001600160401b0381118282101715614dd357614dd3614d9a565b60405290565b60405160a081016001600160401b0381118282101715614dd357614dd3614d9a565b60405160e081016001600160401b0381118282101715614dd357614dd3614d9a565b604051601f8201601f191681016001600160401b0381118282101715614e4557614e45614d9a565b604052919050565b6001600160a01b03811681146128e757600080fd5b8035614e6d81614e4d565b919050565b600060c08284031215614e8457600080fd5b60405160c081018181106001600160401b0382111715614ea657614ea6614d9a565b6040529050808235614eb781614e4d565b81526020830135614ec781614e4d565b6020820152604083810135908201526060830135614ee481614e4d565b60608201526080830135614ef781614e4d565b608082015260a092830135920191909152919050565b600060c08284031215614f1f57600080fd5b610c988383614e72565b80516001600160a01b031682526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e08301526101008082015181840152506101208082015181840152506101408082015181840152506101608082015181840152505050565b6101808101610b2f8284614f29565b600060208284031215614fd157600080fd5b5035919050565b600080828403610240811215614fed57600080fd5b614ff78585614e72565b92506101808060bf198301121561500d57600080fd5b615015614db0565b915061502360c08601614e62565b825260e085013560208301526101008086013560408401526101208087013560608501526101408088013560808601526101608089013560a08701528489013560c08701526101a089013560e08701526101c0890135848701526101e08901358387015261020089013582870152610220890135818701525050505050809150509250929050565b6000815180845260005b818110156150d1576020818501810151868301820152016150b5565b506000602082860101526020601f19601f83011685010191505092915050565b821515815260406020820152600061510c60408301846150ab565b949350505050565b6000806040838503121561512757600080fd5b50508035926020909101359150565b60006020828403121561514857600080fd5b8135610c9881614e4d565b60008060006060848603121561516857600080fd5b833561517381614e4d565b925060208401356002811061518757600080fd5b929592945050506040919091013590565b80516001600160a01b039081168352602080830151821690840152604080830151908401526060808301518216908401526080808301519091169083015260a090810151910152565b6001600160a01b038416815261010081016151ff6020830185615198565b8260e0830152949350505050565b60006020828403121561521f57600080fd5b81518015158114610c9857600080fd5b634e487b7160e01b600052601160045260246000fd5b64ffffffffff82811682821603908082111561417e5761417e61522f565b634e487b7160e01b600052601260045260246000fd5b600064ffffffffff8084168061529157615291615263565b92169190910492915050565b64ffffffffff8181168382160280821691908281146152be576152be61522f565b505092915050565b64ffffffffff81811683821601908082111561417e5761417e61522f565b61030081016153288286805182526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a08301525050565b61533560c0830185614f29565b61510c610240830184615198565b60006020828403121561535557600080fd5b5051919050565b60006080828403121561536e57600080fd5b604051608081018181106001600160401b038211171561539057615390614d9a565b8060405250825181526020830151602082015260408301516040820152606083015160608201528091505092915050565b8082028115828204841417610b2f57610b2f61522f565b6000826153e7576153e7615263565b500490565b81810381811115610b2f57610b2f61522f565b6000600160ff1b82016154145761541461522f565b5060000390565b80820260008212600160ff1b841416156154375761543761522f565b8181058314821517610b2f57610b2f61522f565b60008261545a5761545a615263565b600160ff1b8214600019841416156154745761547461522f565b500590565b6104c081016154bd8289805182526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a08301525050565b6154ca60c0830188615198565b6154d8610180830187614f29565b6154e6610300830186614f29565b6104808201939093526104a00152949350505050565b8051614e6d81614e4d565b60006020828403121561551957600080fd5b8151610c9881614e4d565b634e487b7160e01b600052602160045260246000fd5b6001600160a01b0387811682528681166020830152851660408201526060810184905260c081016002841061557157615571615524565b608082019390935260a00152949350505050565b6000610180828403121561559857600080fd5b6155a0614db0565b6155a9836154fc565b81526020830151602082015260408301516040820152606083015160608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e08201526101008084015181830152506101208084015181830152506101408084015181830152506101608084015181830152508091505092915050565b602081526000610c9860208301846150ab565b6001600160a01b0393841681529183166020830152909116604082015260600190565b805160ff81168114614e6d57600080fd5b60006020828403121561568457600080fd5b610c9882615661565b600181815b808511156156c85781600019048211156156ae576156ae61522f565b808516156156bb57918102915b93841c9390800290615692565b509250929050565b6000826156df57506001610b2f565b816156ec57506000610b2f565b8160018114615702576002811461570c57615728565b6001915050610b2f565b60ff84111561571d5761571d61522f565b50506001821b610b2f565b5060208310610133831016604e8410600b841016171561574b575081810a610b2f565b615755838361568d565b80600019048211156157695761576961522f565b029392505050565b6000610c9860ff8416836156d0565b606081016007851061579457615794615524565b938152602081019290925260409091015290565b818103600083128015838313168383128216171561417e5761417e61522f565b60ff8181168382160190811115610b2f57610b2f61522f565b600060ff8316806157f4576157f4615263565b8060ff84160691505092915050565b634e487b7160e01b600052603260045260246000fd5b60ff8281168282160390811115610b2f57610b2f61522f565b61ffff82811682821603908082111561417e5761417e61522f565b600060a0828403121561585f57600080fd5b60405160a081018181106001600160401b038211171561588157615881614d9a565b806040525082518152602083015160208201526040830151604082015260608301516060820152608083015160808201528091505092915050565b80820180821115610b2f57610b2f61522f565b60006001600160401b038211156158e8576158e8614d9a565b5060051b60200190565b600082601f83011261590357600080fd5b81516020615918615913836158cf565b614e1d565b82815260059290921b8401810191818101908684111561593757600080fd5b8286015b84811015615952578051835291830191830161593b565b509695505050505050565b600082601f83011261596e57600080fd5b8151602061597e615913836158cf565b82815260059290921b8401810191818101908684111561599d57600080fd5b8286015b848110156159525780516159b481614e4d565b83529183019183016159a1565b805164ffffffffff81168114614e6d57600080fd5b600082601f8301126159e757600080fd5b815160206159f7615913836158cf565b82815260059290921b84018101918181019086841115615a1657600080fd5b8286015b8481101561595257615a2b816159c1565b8352918301918301615a1a565b600060a08284031215615a4a57600080fd5b615a52614dd9565b90508151815260208201516001600160401b0380821115615a7257600080fd5b615a7e8583860161595d565b60208401526040840151915080821115615a9757600080fd5b615aa3858386016158f2565b60408401526060840151915080821115615abc57600080fd5b50615ac9848285016159d6565b606083015250615adb60808301615661565b608082015292915050565b600082601f830112615af757600080fd5b6040516101408082018281106001600160401b0382111715615b1b57615b1b614d9a565b60405283018185821115615b2e57600080fd5b845b82811015615b5a57805162ffffff81168114615b4c5760008081fd5b825260209182019101615b30565b509195945050505050565b600082601f830112615b7657600080fd5b60405160a081018181106001600160401b0382111715615b9857615b98614d9a565b6040528060a0840185811115615bad57600080fd5b845b81811015615b5a57615bc0816159c1565b835260209283019201615baf565b600082601f830112615bdf57600080fd5b81516020615bef615913836158cf565b82815260059290921b84018101918181019086841115615c0e57600080fd5b8286015b848110156159525780516001600160401b0380821115615c325760008081fd5b90880190610280828b03601f1901811315615c4d5760008081fd5b615c55614dfb565b878401518152604080850151898301526060808601518284015260809150615c7f8e838801615ae6565b90830152615c918d6101c08701615b65565b9082015261026084015183811115615ca95760008081fd5b615cb78d8a838801016158f2565b60a083015250908301519082821115615cd05760008081fd5b615cde8c89848701016158f2565b60c08201528652505050918301918301615c12565b600060208284031215615d0557600080fd5b81516001600160401b0380821115615d1c57600080fd5b9083019060a08286031215615d3057600080fd5b615d38614dd9565b8251815260208301516020820152604083015182811115615d5857600080fd5b615d64878286016158f2565b604083015250606083015182811115615d7c57600080fd5b615d8887828601615a38565b606083015250608083015182811115615da057600080fd5b615dac87828601615bce565b60808301525095945050505050565b600060018201615dcd57615dcd61522f565b506001019056fe736c6970706167655f6d61784e6f726d616c4f7065726174696f6e536c697070616765736c6970706167655f6d6178456d657267656e63794f7065726174696f6e536c697070616765736c6970706167655f6d61785472696d4f7065726174696f6e536c697070616765736c6970706167655f6d617853687574646f776e4f7065726174696f6e536c697070616765a2646970667358221220ab2bdee6410846224b2d9cf0d4e87b83f7bb7c8ad64bfe253e759aa3da27e91f64736f6c63430008110033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000b20193f43c9a7184f3cbed9bad59154da01488b4000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000003c0000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000005a0000000000000000000000000000000000000000000000000011c37937e0800000000000000000000000000000000000000000000000000000470de4df820000000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000000000000000000000000000000354a6ba7a1800000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000dbba000000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000b71b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f4240000000000000000000000000000000000000000000000000000000000000005a0000000000000000000000000000000000000000000000000000000000007080000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000470de4df820000000000000000000000000000000000000000000000000000000000000002a30000000000000000000000000000000000000000000000000000b1a2bc2ec50000000000000000000000000000000000000000000000000000000000000000000a
-----Decoded View---------------
Arg [0] : _systemRegistry (address): 0xB20193f43C9a7184F3cbeD9bAD59154da01488b4
Arg [1] : conf (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
-----Encoded View---------------
29 Constructor Arguments found :
Arg [0] : 000000000000000000000000b20193f43c9a7184f3cbed9bad59154da01488b4
Arg [1] : 000000000000000000000000000000000000000000000000000000000000003c
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000005
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [4] : 000000000000000000000000000000000000000000000000000000000000001e
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [6] : 000000000000000000000000000000000000000000000000000000000000003c
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000007
Arg [8] : 000000000000000000000000000000000000000000000000000000000000001e
Arg [9] : 000000000000000000000000000000000000000000000000000000000000003c
Arg [10] : 000000000000000000000000000000000000000000000000000000000000005a
Arg [11] : 0000000000000000000000000000000000000000000000000011c37937e08000
Arg [12] : 00000000000000000000000000000000000000000000000000470de4df820000
Arg [13] : 000000000000000000000000000000000000000000000000016345785d8a0000
Arg [14] : 00000000000000000000000000000000000000000000000000354a6ba7a18000
Arg [15] : 00000000000000000000000000000000000000000000000000000000000f4240
Arg [16] : 00000000000000000000000000000000000000000000000000000000000f4240
Arg [17] : 00000000000000000000000000000000000000000000000000000000000dbba0
Arg [18] : 00000000000000000000000000000000000000000000000000000000000f4240
Arg [19] : 00000000000000000000000000000000000000000000000000000000000b71b0
Arg [20] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [21] : 00000000000000000000000000000000000000000000000000000000000f4240
Arg [22] : 000000000000000000000000000000000000000000000000000000000000005a
Arg [23] : 0000000000000000000000000000000000000000000000000000000000007080
Arg [24] : 000000000000000000000000000000000000000000000000002386f26fc10000
Arg [25] : 00000000000000000000000000000000000000000000000000470de4df820000
Arg [26] : 000000000000000000000000000000000000000000000000000000000002a300
Arg [27] : 00000000000000000000000000000000000000000000000000b1a2bc2ec50000
Arg [28] : 000000000000000000000000000000000000000000000000000000000000000a
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 31 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
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.