ERC-20
Overview
Max Total Supply
5.880811 multiposition-CLR
Holders
3
Market
Onchain Market Cap
$0.00
Circulating Supply Market Cap
-
Other Info
Token Contract (WITH 18 Decimals)
Balance
3.499742 multiposition-CLRValue
$0.00Loading...
Loading
Loading...
Loading
Loading...
Loading
# | Exchange | Pair | Price | 24H Volume | % Volume |
---|
Contract Name:
Cellar
Compiler Version
v0.8.16+commit.07a7930e
Optimization Enabled:
Yes with 20 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import { ERC4626, SafeERC20 } from "./ERC4626.sol"; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import { Multicall } from "./Multicall.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { SafeCast } from "src/utils/SafeCast.sol"; import { Registry } from "src/Registry.sol"; import { SwapRouter } from "src/modules/swap-router/SwapRouter.sol"; import { PriceRouter } from "src/modules/price-router/PriceRouter.sol"; import { IGravity } from "src/interfaces/external/IGravity.sol"; import { AddressArray } from "src/utils/AddressArray.sol"; import { Math } from "../utils/Math.sol"; import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol"; /** * @title Sommelier Cellar * @notice A composable ERC4626 that can use a set of other ERC4626 or ERC20 positions to earn yield. * @author Brian Le */ contract Cellar is ERC4626, Ownable, ReentrancyGuard { using AddressArray for address[]; using AddressArray for ERC20[]; using SafeERC20 for ERC20; using SafeCast for uint256; using SafeCast for int256; using Math for uint256; // ========================================= POSITIONS CONFIG ========================================= /** * @notice Emitted when a position is added. * @param position address of position that was added * @param index index that position was added at */ event PositionAdded(address indexed position, uint256 index); /** * @notice Emitted when a position is removed. * @param position address of position that was removed * @param index index that position was removed from */ event PositionRemoved(address indexed position, uint256 index); /** * @notice Emitted when a position is replaced. * @param oldPosition address of position at index before being replaced * @param newPosition address of position at index after being replaced * @param index index of position replaced */ event PositionReplaced(address indexed oldPosition, address indexed newPosition, uint256 index); /** * @notice Emitted when the positions at two indexes are swapped. * @param newPosition1 address of position (previously at index2) that replaced index1. * @param newPosition2 address of position (previously at index1) that replaced index2. * @param index1 index of first position involved in the swap * @param index2 index of second position involved in the swap. */ event PositionSwapped(address indexed newPosition1, address indexed newPosition2, uint256 index1, uint256 index2); /** * @notice Attempted an operation on an untrusted position. * @param position address of the position */ error Cellar__UntrustedPosition(address position); /** * @notice Attempted to add a position that is already being used. * @param position address of the position */ error Cellar__PositionAlreadyUsed(address position); /** * @notice Attempted an action on a position that is required to be empty before the action can be performed. * @param position address of the non-empty position * @param sharesRemaining amount of shares remaining in the position */ error Cellar__PositionNotEmpty(address position, uint256 sharesRemaining); /** * @notice Attempted an operation with an asset that was different then the one expected. * @param asset address of the asset * @param expectedAsset address of the expected asset */ error Cellar__AssetMismatch(address asset, address expectedAsset); /** * @notice Attempted an action on a position that is not being used by the cellar but must be for * the operation to succeed. * @param position address of the invalid position */ error Cellar__InvalidPosition(address position); /** * @notice Attempted to remove holding position. */ error Cellar__RemoveHoldingPosition(); /** * @notice Attempted to add a position when the position array is full. * @param maxPositions maximum number of positions that can be used */ error Cellar__PositionArrayFull(uint256 maxPositions); /** * @notice Value specifying the interface a position uses. * @param ERC20 an ERC20 token * @param ERC4626 an ERC4626 vault * @param Cellar a cellar */ enum PositionType { ERC20, ERC4626, Cellar } /** * @notice Addresses of the positions currently used by the cellar. */ address[] public positions; /** * @notice Tell whether a position is currently used. */ mapping(address => bool) public isPositionUsed; /** * @notice Get the type related to a position. */ mapping(address => PositionType) public getPositionType; /** * @notice Get the addresses of the positions current used by the cellar. */ function getPositions() external view returns (address[] memory) { return positions; } /** * @notice Maximum amount of positions a cellar can use at once. */ uint8 public constant MAX_POSITIONS = 32; /** * @notice Insert a trusted position to the list of positions used by the cellar at a given index. * @param index index at which to insert the position * @param position address of position to add */ function addPosition(uint256 index, address position) external onlyOwner whenNotShutdown { if (positions.length >= MAX_POSITIONS) revert Cellar__PositionArrayFull(MAX_POSITIONS); if (!isTrusted[position]) revert Cellar__UntrustedPosition(position); // Check if position is already being used. if (isPositionUsed[position]) revert Cellar__PositionAlreadyUsed(position); // Add new position at a specified index. positions.add(index, position); isPositionUsed[position] = true; emit PositionAdded(position, index); } /** * @notice Push a trusted position to the end of the list of positions used by the cellar. * @dev If you know you are going to add a position to the end of the array, this is more * efficient then `addPosition`. * @param position address of position to add */ function pushPosition(address position) external onlyOwner whenNotShutdown { // if (positions.length >= MAX_POSITIONS) revert Cellar__PositionArrayFull(MAX_POSITIONS); // if (!isTrusted[position]) revert Cellar__UntrustedPosition(position); // // Check if position is already being used. // if (isPositionUsed[position]) revert Cellar__PositionAlreadyUsed(position); // // Add new position to the end of the positions. // positions.push(position); // isPositionUsed[position] = true; // emit PositionAdded(position, positions.length - 1); } /** * @notice Remove the position at a given index from the list of positions used by the cellar. * @param index index at which to remove the position */ function removePosition(uint256 index) external onlyOwner { // Get position being removed. address position = positions[index]; // Only remove position if it is empty, and if it is not the holding position. uint256 positionBalance = _balanceOf(position); if (positionBalance > 0) revert Cellar__PositionNotEmpty(position, positionBalance); if (position == holdingPosition) revert Cellar__RemoveHoldingPosition(); // Remove position at the given index. positions.remove(index); isPositionUsed[position] = false; emit PositionRemoved(position, index); } /** * @notice Remove the last position in the list of positions used by the cellar. * @dev If you know you are going to remove a position from the end of the array, this is more * efficient then `removePosition`. */ function popPosition() external onlyOwner { // Get the index of the last position and last position itself. // uint256 index = positions.length - 1; // address position = positions[index]; // // Only remove position if it is empty, and if it is not the holding position. // uint256 positionBalance = _balanceOf(position); // if (positionBalance > 0) revert Cellar__PositionNotEmpty(position, positionBalance); // if (position == holdingPosition) revert Cellar__RemoveHoldingPosition(); // // Remove last position. // positions.pop(); // isPositionUsed[position] = false; // emit PositionRemoved(position, index); } /** * @notice Replace a position at a given index with a new position. * @param index index at which to replace the position * @param newPosition address of position to replace with */ function replacePosition(uint256 index, address newPosition) external onlyOwner whenNotShutdown { if (!isTrusted[newPosition]) revert Cellar__UntrustedPosition(newPosition); if (isPositionUsed[newPosition]) revert Cellar__PositionAlreadyUsed(newPosition); // Store the old position before its replaced. address oldPosition = positions[index]; // Only remove position if it is empty, and if it is not the holding position. uint256 positionBalance = _balanceOf(oldPosition); if (positionBalance > 0) revert Cellar__PositionNotEmpty(oldPosition, positionBalance); if (oldPosition == holdingPosition) revert Cellar__RemoveHoldingPosition(); // Replace old position with new position. positions[index] = newPosition; isPositionUsed[oldPosition] = false; isPositionUsed[newPosition] = true; emit PositionReplaced(oldPosition, newPosition, index); } /** * @notice Swap the positions at two given indexes. * @param index1 index of first position to swap * @param index2 index of second position to swap */ function swapPositions(uint256 index1, uint256 index2) external onlyOwner { // Get the new positions that will be at each index. address newPosition1 = positions[index2]; address newPosition2 = positions[index1]; // Swap positions. (positions[index1], positions[index2]) = (newPosition1, newPosition2); emit PositionSwapped(newPosition1, newPosition2, index1, index2); } // ============================================ TRUST CONFIG ============================================ /** * @notice Emitted when trust for a position is changed. * @param position address of position that trust was changed for * @param isTrusted whether the position is trusted */ event TrustChanged(address indexed position, bool isTrusted); /** * @notice Attempted to trust a position not being used. * @param position address of the invalid position */ error Cellar__PositionPricingNotSetUp(address position); /** * @notice Addresses of the positions currently used by the cellar. */ uint256 public constant PRICE_ROUTER_REGISTRY_SLOT = 2; /** * @notice Tell whether a position is trusted. */ mapping(address => bool) public isTrusted; /** * @notice Trust a position to be used by the cellar. * @param position address of position to trust * @param positionType value specifying the interface the position uses */ function trustPosition(address position, PositionType positionType) external onlyOwner { // Trust position. isTrusted[position] = true; // Set position type. getPositionType[position] = positionType; // Now that position type is set up, check that asset of position is supported for pricing operations. ERC20 positionAsset = _assetOf(position); if (!PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT)).isSupported(positionAsset)) revert Cellar__PositionPricingNotSetUp(address(positionAsset)); emit TrustChanged(position, true); } /** * @notice Distrust a position to prevent it from being used by the cellar. * @param position address of position to distrust */ function distrustPosition(address position) external onlyOwner { // // Distrust position. // isTrusted[position] = false; // // Only remove position if it is not being used, is empty, and if it is // // not the holding position. // if (isPositionUsed[position]) { // uint256 positionBalance = _balanceOf(position); // if (positionBalance > 0) revert Cellar__PositionNotEmpty(position, positionBalance); // if (position == holdingPosition) revert Cellar__RemoveHoldingPosition(); // positions.remove(position); // isPositionUsed[position] = false; // } // // NOTE: After position has been removed, SP should be notified on the // // UI that the position can no longer be used and to exit the position // // or rebalance its assets into another position ASAP. // emit TrustChanged(position, false); } // ============================================ WITHDRAW CONFIG ============================================ /** * @notice Emitted when withdraw type configuration is changed. * @param oldType previous withdraw type * @param newType new withdraw type */ event WithdrawTypeChanged(WithdrawType oldType, WithdrawType newType); /** * @notice The withdraw type to use for the cellar. * @param ORDERLY use `positions` in specify the order in which assets are withdrawn (eg. * `positions[0]` is withdrawn from first); least impactful positions (position * that will have its core positions impacted the least by having funds removed) * should be withdrawn from first and most impactful position should be last * @param PROPORTIONAL pull assets from each position proportionally when withdrawing, used if * trying to maintain a specific ratio */ enum WithdrawType { ORDERLY, PROPORTIONAL } /** * @notice The withdraw type to used by the cellar. */ WithdrawType public withdrawType; /** * @notice Set the withdraw type used by the cellar. * @param newWithdrawType value of the new withdraw type to use */ function setWithdrawType(WithdrawType newWithdrawType) external onlyOwner { emit WithdrawTypeChanged(withdrawType, newWithdrawType); withdrawType = newWithdrawType; } // ============================================ HOLDINGS CONFIG ============================================ /** * @notice Emitted when the holdings position is changed. * @param oldPosition address of the old holdings position * @param newPosition address of the new holdings position */ event HoldingPositionChanged(address indexed oldPosition, address indexed newPosition); /** * @notice The "default" position which uses the same asset as the cellar. It is the position * deposited assets will automatically go into (perhaps while waiting to be rebalanced * to other positions) and commonly the first position withdrawn assets will be pulled * from if using orderly withdraws. * @dev MUST accept the same asset as the cellar's `asset`. MUST be a position present in * `positions`. Should be a static (eg. just holding) or lossless (eg. lending on Aave) * position. Should not be expensive to move assets in or out of as this will occur * frequently. It is highly recommended to choose a "simple" holding position. */ address public holdingPosition; /** * @notice Set the holding position used by the cellar. * @param newHoldingPosition address of the new holding position to use */ function setHoldingPosition(address newHoldingPosition) external onlyOwner { if (!isPositionUsed[newHoldingPosition]) revert Cellar__InvalidPosition(newHoldingPosition); ERC20 holdingPositionAsset = _assetOf(newHoldingPosition); if (holdingPositionAsset != asset) revert Cellar__AssetMismatch(address(holdingPositionAsset), address(asset)); emit HoldingPositionChanged(holdingPosition, newHoldingPosition); holdingPosition = newHoldingPosition; } // ============================================ ACCRUAL STORAGE ============================================ /** * @notice Timestamp of when the last accrual occurred. * @dev Used for determining the amount of platform fees that can be taken during an accrual period. */ uint64 public lastAccrual; // =============================================== FEES CONFIG =============================================== /** * @notice Emitted when platform fees is changed. * @param oldPlatformFee value platform fee was changed from * @param newPlatformFee value platform fee was changed to */ event PlatformFeeChanged(uint64 oldPlatformFee, uint64 newPlatformFee); /** * @notice Emitted when performance fees is changed. * @param oldPerformanceFee value performance fee was changed from * @param newPerformanceFee value performance fee was changed to */ event PerformanceFeeChanged(uint64 oldPerformanceFee, uint64 newPerformanceFee); /** * @notice Emitted when fees distributor is changed. * @param oldFeesDistributor address of fee distributor was changed from * @param newFeesDistributor address of fee distributor was changed to */ event FeesDistributorChanged(bytes32 oldFeesDistributor, bytes32 newFeesDistributor); /** * @notice Emitted when strategist performance fee cut is changed. * @param oldPerformanceCut value strategist performance fee cut was changed from * @param newPerformanceCut value strategist performance fee cut was changed to */ event StrategistPerformanceCutChanged(uint64 oldPerformanceCut, uint64 newPerformanceCut); /** * @notice Emitted when strategist platform fee cut is changed. * @param oldPlatformCut value strategist platform fee cut was changed from * @param newPlatformCut value strategist platform fee cut was changed to */ event StrategistPlatformCutChanged(uint64 oldPlatformCut, uint64 newPlatformCut); /** * @notice Emitted when strategists payout address is changed. * @param oldPayoutAddress value strategists payout address was changed from * @param newPayoutAddress value strategists payout address was changed to */ event StrategistPayoutAddressChanged(address oldPayoutAddress, address newPayoutAddress); /** * @notice Attempted to use an invalid cosmos address. */ error Cellar__InvalidCosmosAddress(); /** * @notice Attempted to change strategist fee cut with invalid value. */ error Cellar__InvalidFeeCut(); /** * @notice Attempted to change performance/platform fee with invalid value. */ error Cellar__InvalidFee(); /** * @notice Data related to fees. * @param highWatermark Stores the share price to be used as a High Watermark to calculate performance fees. * @param strategistPerformanceCut Determines how much performance fees go to strategist. * This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%). * @param strategistPlatformCut Determines how much platform fees go to strategist. * This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%). * @param platformFee The percentage of total assets accrued as platform fees over a year. This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%). * @param performanceFee The percentage of total assets accrued as platform fees over a year. * This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%). * @param feesDistributor Cosmos address of module that distributes fees, specified as a hex value. * The Gravity contract expects a 32-byte value formatted in a specific way. * @param strategistPayoutAddress Address to send the strategists fee shares. */ struct FeeData { uint256 highWatermark; uint64 strategistPerformanceCut; uint64 strategistPlatformCut; uint64 platformFee; uint64 performanceFee; bytes32 feesDistributor; address strategistPayoutAddress; } /** * @notice Stores all fee data for cellar. */ FeeData public feeData = FeeData({ highWatermark: 0, strategistPerformanceCut: 0.75e18, strategistPlatformCut: 0.75e18, platformFee: 0.01e18, performanceFee: 0.1e18, feesDistributor: hex"000000000000000000000000b813554b423266bbd4c16c32fa383394868c1f55", // 20 bytes, so need 12 bytes of zero strategistPayoutAddress: address(0) }); uint64 public constant MAX_PERFORMANCE_FEE = 0.5e18; uint64 public constant MAX_PLATFORM_FEE = 0.2e18; uint64 public constant MAX_FEE_CUT = 1e18; /** * @notice Set the percentage of platform fees accrued over a year. * @param newPlatformFee value out of 1e18 that represents new platform fee percentage */ function setPlatformFee(uint64 newPlatformFee) external onlyOwner { if (newPlatformFee > MAX_PLATFORM_FEE) revert Cellar__InvalidFee(); emit PlatformFeeChanged(feeData.platformFee, newPlatformFee); feeData.platformFee = newPlatformFee; } /** * @notice Set the percentage of performance fees accrued from yield. * @param newPerformanceFee value out of 1e18 that represents new performance fee percentage */ function setPerformanceFee(uint64 newPerformanceFee) external onlyOwner { if (newPerformanceFee > MAX_PERFORMANCE_FEE) revert Cellar__InvalidFee(); emit PerformanceFeeChanged(feeData.performanceFee, newPerformanceFee); feeData.performanceFee = newPerformanceFee; } /** * @notice Set the address of the fee distributor on the Sommelier chain. * @dev IMPORTANT: Ensure that the address is formatted in the specific way that the Gravity contract * expects it to be. * @param newFeesDistributor formatted address of the new fee distributor module */ function setFeesDistributor(bytes32 newFeesDistributor) external onlyOwner { if (uint256(newFeesDistributor) > type(uint160).max) revert Cellar__InvalidCosmosAddress(); emit FeesDistributorChanged(feeData.feesDistributor, newFeesDistributor); feeData.feesDistributor = newFeesDistributor; } /** * @notice Sets the Strategists cut of performance fees * @param cut the performance cut for the strategist */ function setStrategistPerformanceCut(uint64 cut) external onlyOwner { if (cut > MAX_FEE_CUT) revert Cellar__InvalidFeeCut(); emit StrategistPerformanceCutChanged(feeData.strategistPerformanceCut, cut); feeData.strategistPerformanceCut = cut; } /** * @notice Sets the Strategists cut of platform fees * @param cut the platform cut for the strategist */ function setStrategistPlatformCut(uint64 cut) external onlyOwner { if (cut > MAX_FEE_CUT) revert Cellar__InvalidFeeCut(); emit StrategistPlatformCutChanged(feeData.strategistPlatformCut, cut); feeData.strategistPlatformCut = cut; } /** * @notice Sets the Strategists payout address * @param payout the new strategist payout address */ function setStrategistPayoutAddress(address payout) external onlyOwner { emit StrategistPayoutAddressChanged(feeData.strategistPayoutAddress, payout); feeData.strategistPayoutAddress = payout; } // ============================================= LIMITS CONFIG ============================================= /** * @notice Emitted when the liquidity limit is changed. * @param oldLimit amount the limit was changed from * @param newLimit amount the limit was changed to */ event LiquidityLimitChanged(uint256 oldLimit, uint256 newLimit); /** * @notice Emitted when the deposit limit is changed. * @param oldLimit amount the limit was changed from * @param newLimit amount the limit was changed to */ event DepositLimitChanged(uint256 oldLimit, uint256 newLimit); /** * @notice Attempted deposit more than the max deposit. * @param assets the assets user attempted to deposit * @param maxDeposit the max assets that can be deposited */ error Cellar__DepositRestricted(uint256 assets, uint256 maxDeposit); /** * @notice Maximum amount of assets that can be managed by the cellar. Denominated in the same decimals * as the current asset. * @dev Set to `type(uint256).max` to have no limit. */ uint256 public liquidityLimit = type(uint256).max; /** * @notice Maximum amount of assets per wallet. Denominated in the same decimals as the current asset. * @dev Set to `type(uint256).max` to have no limit. */ uint256 public depositLimit = type(uint256).max; /** * @notice Set the maximum liquidity that cellar can manage. Uses the same decimals as the current asset. * @param newLimit amount of assets to set as the new limit */ function setLiquidityLimit(uint256 newLimit) external onlyOwner { emit LiquidityLimitChanged(liquidityLimit, newLimit); liquidityLimit = newLimit; } /** * @notice Set the per-wallet deposit limit. Uses the same decimals as the current asset. * @param newLimit amount of assets to set as the new limit */ function setDepositLimit(uint256 newLimit) external onlyOwner { emit DepositLimitChanged(depositLimit, newLimit); depositLimit = newLimit; } // =========================================== EMERGENCY LOGIC =========================================== /** * @notice Emitted when cellar emergency state is changed. * @param isShutdown whether the cellar is shutdown */ event ShutdownChanged(bool isShutdown); /** * @notice Attempted action was prevented due to contract being shutdown. */ error Cellar__ContractShutdown(); /** * @notice Attempted action was prevented due to contract not being shutdown. */ error Cellar__ContractNotShutdown(); /** * @notice Whether or not the contract is shutdown in case of an emergency. */ bool public isShutdown; /** * @notice Prevent a function from being called during a shutdown. */ modifier whenNotShutdown() { if (isShutdown) revert Cellar__ContractShutdown(); _; } /** * @notice Shutdown the cellar. Used in an emergency or if the cellar has been deprecated. * @dev In the case where */ function initiateShutdown() external whenNotShutdown onlyOwner { isShutdown = true; emit ShutdownChanged(true); } /** * @notice Restart the cellar. */ function liftShutdown() external onlyOwner { if (!isShutdown) revert Cellar__ContractNotShutdown(); isShutdown = false; emit ShutdownChanged(false); } // =========================================== CONSTRUCTOR =========================================== /** * @notice Address of the platform's registry contract. Used to get the latest address of modules. */ Registry public immutable registry; /** * @dev Owner should be set to the Gravity Bridge, which relays instructions from the Steward * module to the cellars. * https://github.com/PeggyJV/steward * https://github.com/cosmos/gravity-bridge/blob/main/solidity/contracts/Gravity.sol * @param _registry address of the platform's registry contract * @param _asset address of underlying token used for the for accounting, depositing, and withdrawing * @param _positions addresses of the positions to initialize the cellar with * @param _positionTypes types of each positions used * @param _holdingPosition address of the position to use as the holding position * @param _withdrawType withdraw type to use for the cellar * @param _name name of this cellar's share token * @param _name symbol of this cellar's share token * @param _strategistPayout The address to send the strategists fee shares. */ constructor( Registry _registry, ERC20 _asset, address[] memory _positions, PositionType[] memory _positionTypes, address _holdingPosition, WithdrawType _withdrawType, string memory _name, string memory _symbol, address _strategistPayout ) ERC4626(_asset, _name, _symbol) Ownable() { registry = _registry; // Initialize positions. positions = _positions; ERC20 positionAsset; for (uint256 i; i < _positions.length; i++) { address position = _positions[i]; if (isPositionUsed[position]) revert Cellar__PositionAlreadyUsed(position); isTrusted[position] = true; isPositionUsed[position] = true; getPositionType[position] = _positionTypes[i]; positionAsset = _assetOf(position); if (!PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT)).isSupported(positionAsset)) revert Cellar__PositionPricingNotSetUp(address(positionAsset)); } // Initialize holding position. if (!isPositionUsed[_holdingPosition]) revert Cellar__InvalidPosition(_holdingPosition); ERC20 holdingPositionAsset = _assetOf(_holdingPosition); if (holdingPositionAsset != _asset) revert Cellar__AssetMismatch(address(holdingPositionAsset), address(_asset)); holdingPosition = _holdingPosition; // Initialize withdraw type. withdrawType = _withdrawType; // Initialize last accrual timestamp to time that cellar was created, otherwise the first // `accrue` will take platform fees from 1970 to the time it is called. lastAccrual = uint64(block.timestamp); feeData.strategistPayoutAddress = _strategistPayout; // Transfer ownership to the Gravity Bridge. address gravityBridge = _registry.getAddress(0); transferOwnership(gravityBridge); } // =========================================== CORE LOGIC =========================================== /** * @notice Emitted when withdraws are made from a position. * @param position the position assets were withdrawn from * @param amount the amount of assets withdrawn */ event PulledFromPosition(address indexed position, uint256 amount); /** * @notice Emitted when share locking period is changed. * @param oldPeriod the old locking period * @param newPeriod the new locking period */ event ShareLockingPeriodChanged(uint256 oldPeriod, uint256 newPeriod); /** * @notice Attempted an action with zero shares. */ error Cellar__ZeroShares(); /** * @notice Attempted an action with zero assets. */ error Cellar__ZeroAssets(); /** * @notice Withdraw did not withdraw all assets. * @param assetsOwed the remaining assets owed that were not withdrawn. */ error Cellar__IncompleteWithdraw(uint256 assetsOwed); /** * @notice Attempted to withdraw an illiquid position. * @param illiquidPosition the illiquid position. */ error Cellar__IlliquidWithdraw(address illiquidPosition); /** * @notice Attempted to set `shareLockPeriod` to an invalid number. */ error Cellar__InvalidShareLockPeriod(); /** * @notice Attempted to burn shares when they are locked. * @param blockSharesAreUnlocked the block number when caller can transfer/redeem shares * @param currentBlock the current block number. */ error Cellar__SharesAreLocked(uint256 blockSharesAreUnlocked, uint256 currentBlock); /** * @notice Attempted deposit on behalf of a user without being approved. */ error Cellar__NotApprovedToDepositOnBehalf(address depositor); /** * @notice Shares must be locked for atleaset 8 blocks after minting. */ uint256 public constant MINIMUM_SHARE_LOCK_PERIOD = 8; /** * @notice Shares can be locked for at most 256 blocks after minting. */ uint256 public constant MAXIMUM_SHARE_LOCK_PERIOD = 256; /** * @notice After deposits users must wait `shareLockPeriod` blocks before being able to transfer or withdraw their shares. */ uint256 public shareLockPeriod = 10; /** * @notice mapping that stores every users last block they minted shares. */ mapping(address => uint256) public userShareLockStartBlock; /** * @notice Allows share lock period to be updated. * @param newLock the new lock period */ function setShareLockPeriod(uint256 newLock) external onlyOwner { if (newLock < MINIMUM_SHARE_LOCK_PERIOD || newLock > MAXIMUM_SHARE_LOCK_PERIOD) revert Cellar__InvalidShareLockPeriod(); uint256 oldLockingPeriod = shareLockPeriod; shareLockPeriod = newLock; emit ShareLockingPeriodChanged(oldLockingPeriod, newLock); } /** * @notice helper function that checks enough blocks have passed to unlock shares. * @param owner the address of the user to check */ function _checkIfSharesLocked(address owner) internal view { uint256 lockBlock = userShareLockStartBlock[owner]; if (lockBlock != 0) { uint256 blockSharesAreUnlocked = lockBlock + shareLockPeriod; if (blockSharesAreUnlocked > block.number) revert Cellar__SharesAreLocked(blockSharesAreUnlocked, block.number); } } /** * @notice modifies before transfer hook to check that shares are not locked * @param from the address transferring shares */ function _beforeTokenTransfer( address from, address, uint256 ) internal view override { _checkIfSharesLocked(from); } /** * @notice called at the beginning of deposit. * @param assets amount of assets deposited by user. * @param receiver address receiving the shares. */ function beforeDeposit( uint256 assets, uint256, address receiver ) internal override whenNotShutdown { if (msg.sender != receiver) { if (!registry.approvedForDepositOnBehalf(msg.sender)) revert Cellar__NotApprovedToDepositOnBehalf(msg.sender); } uint256 maxAssets = maxDeposit(receiver); if (assets > maxAssets) revert Cellar__DepositRestricted(assets, maxAssets); feeData.highWatermark += assets; } /** * @notice called at the end of deposit. * @param assets amount of assets deposited by user. */ function afterDeposit( uint256 assets, uint256, address receiver ) internal override { _depositTo(holdingPosition, assets); userShareLockStartBlock[receiver] = block.number; } /** * @notice called at the beginning of withdraw. * @param assets amount of assets withdrawn by user. */ function beforeWithdraw( uint256 assets, uint256, address, address owner ) internal override { // Make sure users shares are not locked. _checkIfSharesLocked(owner); // Need to check if assets is greater than the high watermark // because if the performanceFee is set to zero, and all cellar shares are redeemed, // if the cellar has earned any yield, assets will be greater than the high watermark. // Becuase the high watermark is only updated when performance fees are minted. uint256 highWatermark = feeData.highWatermark; feeData.highWatermark = assets > highWatermark ? 0 : highWatermark - assets; } /** * @notice Deposits assets into the cellar, and returns shares to receiver. * @param assets amount of assets deposited by user. * @param receiver address to receive the shares. * @return shares amount of shares given for deposit. */ function deposit(uint256 assets, address receiver) public override nonReentrant returns (uint256 shares) { uint256 _totalAssets = totalAssets(); _takePerformanceFees(_totalAssets); // Check for rounding error since we round down in previewDeposit. if ((shares = _convertToShares(assets, _totalAssets)) == 0) revert Cellar__ZeroShares(); beforeDeposit(assets, shares, receiver); // Need to transfer before minting or ERC777s could reenter. asset.safeTransferFrom(msg.sender, address(this), assets); _mint(receiver, shares); emit Deposit(msg.sender, receiver, assets, shares); afterDeposit(assets, shares, receiver); } /** * @notice Mints shares from the cellar, and returns shares to receiver. * @param shares amount of shares requested by user. * @param receiver address to receive the shares. * @return assets amount of assets deposited into the cellar. */ function mint(uint256 shares, address receiver) public override nonReentrant returns (uint256 assets) { uint256 _totalAssets = totalAssets(); _takePerformanceFees(_totalAssets); // previewMintRoundsUp, but iniital mint could return zero assets, so check for rounding error. if ((assets = _previewMint(shares, _totalAssets)) == 0) revert Cellar__ZeroAssets(); // No need to check for rounding error, previewMint rounds up. beforeDeposit(assets, shares, receiver); // Need to transfer before minting or ERC777s could reenter. asset.safeTransferFrom(msg.sender, address(this), assets); _mint(receiver, shares); emit Deposit(msg.sender, receiver, assets, shares); afterDeposit(assets, shares, receiver); } /** * @notice helper function that checks if msg.sender has the allowance to spend owner's shares. * @dev reverts if msg.sender != owner, and msg.sender does not have enough allowance. */ function _checkAllowance(address owner, uint256 shares) internal { if (msg.sender != owner) { _spendAllowance(owner, msg.sender, shares); } } /** * @notice Withdraw assets from the cellar by redeeming shares. * @dev Unlike conventional ERC4626 contracts, this may not always return one asset to the receiver. * Since there are no swaps involved in this function, the receiver may receive multiple * assets. The value of all the assets returned will be equal to the amount defined by * `assets` denominated in the `asset` of the cellar (eg. if `asset` is USDC and `assets` * is 1000, then the receiver will receive $1000 worth of assets in either one or many * tokens). * @param assets equivalent value of the assets withdrawn, denominated in the cellar's asset * @param receiver address that will receive withdrawn assets * @param owner address that owns the shares being redeemed * @return shares amount of shares redeemed */ function withdraw( uint256 assets, address receiver, address owner ) public override nonReentrant returns (uint256 shares) { // Get data efficiently. ( uint256 _totalAssets, // Store totalHoldings and pass into _withdrawInOrder if no stack errors. address[] memory _positions, ERC20[] memory positionAssets, uint256[] memory positionBalances, uint256[] memory withdrawableBalances ) = _getData(); _takePerformanceFees(_totalAssets); // No need to check for rounding error, `previewWithdraw` rounds up. shares = _previewWithdraw(assets, _totalAssets); beforeWithdraw(assets, shares, receiver, owner); _checkAllowance(owner, shares); uint256 totalShares = totalSupply(); _burn(owner, shares); emit Withdraw(msg.sender, receiver, owner, assets, shares); withdrawType == WithdrawType.ORDERLY ? _withdrawInOrder(assets, receiver, _positions, positionAssets, positionBalances, withdrawableBalances) : _withdrawInProportion(shares, totalShares, receiver, _positions, positionBalances, withdrawableBalances); afterWithdraw(assets, shares, receiver, owner); } /** * @notice Redeem shares to withdraw assets from the cellar. * @dev Unlike conventional ERC4626 contracts, this may not always return one asset to the receiver. * Since there are no swaps involved in this function, the receiver may receive multiple * assets. The value of all the assets returned will be equal to the amount defined by * `assets` denominated in the `asset` of the cellar (eg. if `asset` is USDC and `assets` * is 1000, then the receiver will receive $1000 worth of assets in either one or many * tokens). * @param shares amount of shares to redeem * @param receiver address that will receive withdrawn assets * @param owner address that owns the shares being redeemed * @return assets equivalent value of the assets withdrawn, denominated in the cellar's asset */ function redeem( uint256 shares, address receiver, address owner ) public override nonReentrant returns (uint256 assets) { // Get data efficiently. ( uint256 _totalAssets, // Store totalHoldings and pass into _withdrawInOrder if no stack errors. address[] memory _positions, ERC20[] memory positionAssets, uint256[] memory positionBalances, uint256[] memory withdrawableBalances ) = _getData(); _takePerformanceFees(_totalAssets); _checkAllowance(owner, shares); // Check for rounding error since we round down in previewRedeem. if ((assets = _convertToAssets(shares, _totalAssets)) == 0) revert Cellar__ZeroAssets(); beforeWithdraw(assets, shares, receiver, owner); uint256 totalShares = totalSupply(); _burn(owner, shares); emit Withdraw(msg.sender, receiver, owner, assets, shares); withdrawType == WithdrawType.ORDERLY ? _withdrawInOrder(assets, receiver, _positions, positionAssets, positionBalances, withdrawableBalances) : _withdrawInProportion(shares, totalShares, receiver, _positions, positionBalances, withdrawableBalances); afterWithdraw(assets, shares, receiver, owner); } /** * @dev Withdraw from positions in the order defined by `positions`. Used if the withdraw type * is `ORDERLY`. * @param assets the amount of assets to withdraw from cellar * @param receiver the address to sent withdrawn assets to * @param _positions positions to withdraw from * @param positionAssets underlying asset for each position * @param positionBalances underlying balances for each position */ function _withdrawInOrder( uint256 assets, address receiver, address[] memory _positions, ERC20[] memory positionAssets, uint256[] memory positionBalances, uint256[] memory withdrawableBalances ) internal { // Get the price router. PriceRouter priceRouter = PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT)); for (uint256 i; i < _positions.length; i++) { // Move on to next position if this one is empty. if (positionBalances[i] == 0) continue; uint256 onePositionAsset = 10**positionAssets[i].decimals(); uint256 exchangeRate = priceRouter.getExchangeRate(positionAssets[i], asset); // Denominate withdrawable position balance in cellar's asset. uint256 totalWithdrawableBalanceInAssets = withdrawableBalances[i].mulDivDown( exchangeRate, onePositionAsset ); // We want to pull as much as we can from this position, but no more than needed. uint256 amount; if (totalWithdrawableBalanceInAssets > assets) { amount = assets.mulDivDown(onePositionAsset, exchangeRate); assets = 0; } else { amount = withdrawableBalances[i]; assets = assets - totalWithdrawableBalanceInAssets; } // Withdraw from position. _withdrawFrom(_positions[i], amount, receiver); emit PulledFromPosition(_positions[i], amount); // Stop if no more assets to withdraw. if (assets == 0) break; } // If withdraw did not remove all assets owed, revert. if (assets > 0) revert Cellar__IncompleteWithdraw(assets); } /** * @dev Withdraw from each position proportional to that of shares redeemed. Used if the * withdraw type is `PROPORTIONAL`. * @dev It is possible that the `amount` calculated to withdraw is zero. This is only a problem * for a low percision ERC20, which we have no plans to support. * @param shares the user is burning to withdraw * @param totalShares the total amount of oustanding shares * @param receiver the address to sent withdrawn assets to * @param _positions positions to withdraw from * @param positionBalances underlying balances for each position */ function _withdrawInProportion( uint256 shares, uint256 totalShares, address receiver, address[] memory _positions, uint256[] memory positionBalances, uint256[] memory withdrawableBalances ) internal { // Withdraw assets from positions in proportion to shares redeemed. for (uint256 i; i < _positions.length; i++) { address position = _positions[i]; uint256 positionBalance = positionBalances[i]; // Move on to next position if this one is empty. if (positionBalance == 0) continue; // Get the amount of assets to withdraw from this position based on proportion to shares redeemed. uint256 amount = positionBalance.mulDivDown(shares, totalShares); // If straetgist locks the enirety of a positions funds, then all withdraw calls revert. // If this happens, goverance should vote out malicious strategist, then change withdraw type to in oder, and move bad position to back of queue. if (amount > withdrawableBalances[i]) revert Cellar__IlliquidWithdraw(position); // Withdraw from position to receiver. _withdrawFrom(position, amount, receiver); emit PulledFromPosition(position, amount); } } // ========================================= ACCOUNTING LOGIC ========================================= /** * @notice The total amount of assets in the cellar. * @dev EIP4626 states totalAssets needs to be inclusive of fees. * Since performance fees mint shares, total assets remains unchanged, * so this implementation is inclusive of fees even though it does not explicitly show it. * @dev EIP4626 states totalAssets must not revert, but it is possible for `totalAssets` to revert * so it does NOT conform to ERC4626 standards. */ function totalAssets() public view override returns (uint256 assets) { uint256 numOfPositions = positions.length; ERC20[] memory positionAssets = new ERC20[](numOfPositions); uint256[] memory balances = new uint256[](numOfPositions); for (uint256 i; i < numOfPositions; i++) { address position = positions[i]; positionAssets[i] = _assetOf(position); balances[i] = _balanceOf(position); } PriceRouter priceRouter = PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT)); assets = priceRouter.getValues(positionAssets, balances, asset); } /** * @notice The total amount of assets in the cellar. * @dev Excludes locked yield that hasn't been distributed. */ function totalAssetsWithdrawable() public view returns (uint256 assets) { uint256 numOfPositions = positions.length; ERC20[] memory positionAssets = new ERC20[](numOfPositions); uint256[] memory balances = new uint256[](numOfPositions); for (uint256 i; i < numOfPositions; i++) { address position = positions[i]; positionAssets[i] = _assetOf(position); balances[i] = _withdrawableFrom(position); } PriceRouter priceRouter = PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT)); assets = priceRouter.getValues(positionAssets, balances, asset); } /** * @notice The amount of assets that the cellar would exchange for the amount of shares provided. * @notice is NOT inclusive of performance fees. * @param shares amount of shares to convert * @return assets the shares can be exchanged for */ function convertToAssets(uint256 shares) public view override returns (uint256 assets) { assets = _convertToAssets(shares, totalAssets()); } /** * @notice The amount of shares that the cellar would exchange for the amount of assets provided. * @param assets amount of assets to convert * @return shares the assets can be exchanged for */ function convertToShares(uint256 assets) public view override returns (uint256 shares) { shares = _convertToShares(assets, totalAssets()); } /** * @notice Simulate the effects of minting shares at the current block, given current on-chain conditions. * @param shares amount of shares to mint * @return assets that will be deposited */ function previewMint(uint256 shares) public view override returns (uint256 assets) { uint256 _totalAssets = totalAssets(); uint256 feeInAssets = _previewPerformanceFees(_totalAssets); assets = _previewMint(shares, _totalAssets - feeInAssets); } /** * @notice Simulate the effects of withdrawing assets at the current block, given current on-chain conditions. * @param assets amount of assets to withdraw * @return shares that will be redeemed */ function previewWithdraw(uint256 assets) public view override returns (uint256 shares) { uint256 _totalAssets = totalAssets(); uint256 feeInAssets = _previewPerformanceFees(_totalAssets); shares = _previewWithdraw(assets, _totalAssets - feeInAssets); } /** * @notice Simulate the effects of depositing assets at the current block, given current on-chain conditions. * @param assets amount of assets to deposit * @return shares that will be minted */ function previewDeposit(uint256 assets) public view override returns (uint256 shares) { uint256 _totalAssets = totalAssets(); uint256 feeInAssets = _previewPerformanceFees(_totalAssets); shares = _convertToShares(assets, _totalAssets - feeInAssets); } /** * @notice Simulate the effects of redeeming shares at the current block, given current on-chain conditions. * @param shares amount of shares to redeem * @return assets that will be returned */ function previewRedeem(uint256 shares) public view override returns (uint256 assets) { uint256 _totalAssets = totalAssets(); uint256 feeInAssets = _previewPerformanceFees(_totalAssets); assets = _convertToAssets(shares, _totalAssets - feeInAssets); } /** * @notice Returns the max amount withdrawable by a user inclusive of performance fees * @param owner address to check maxWithdraw of. * @return the max amount of assets withdrawable by `owner`. */ function maxWithdraw(address owner) public view override returns (uint256) { // Get amount of assets to withdraw with fees accounted for. uint256 _totalAssets = totalAssets(); uint256 feeInAssets = _previewPerformanceFees(_totalAssets); uint256 assets = _convertToAssets(balanceOf(owner), _totalAssets - feeInAssets); if (withdrawType == WithdrawType.ORDERLY) { uint256 withdrawable = totalAssetsWithdrawable(); return assets <= withdrawable ? assets : withdrawable; } else { (, , , uint256[] memory positionBalances, uint256[] memory withdrawableBalances) = _getData(); uint256 totalShares = totalSupply(); uint256 shares = balanceOf(owner); uint256 smallestPercentWithdrawable = 1e18; for (uint256 i = 0; i < withdrawableBalances.length; i++) { if (positionBalances[i] == 0) continue; if (withdrawableBalances[i] == 0) return 0; uint256 percentWithdrawable = withdrawableBalances[i].mulDivDown(1e18, positionBalances[i]); if (percentWithdrawable < smallestPercentWithdrawable) smallestPercentWithdrawable = percentWithdrawable; } uint256 userOwnershipPercent = shares.mulDivDown(1e18, totalShares); return userOwnershipPercent <= smallestPercentWithdrawable ? assets : _totalAssets.mulDivDown(smallestPercentWithdrawable, 1e18); } } /** * @dev Used to more efficiently convert amount of shares to assets using a stored `totalAssets` value. */ function _convertToAssets(uint256 shares, uint256 _totalAssets) internal view returns (uint256 assets) { uint256 totalShares = totalSupply(); assets = totalShares == 0 ? shares.changeDecimals(18, asset.decimals()) : shares.mulDivDown(_totalAssets, totalShares); } /** * @dev Used to more efficiently convert amount of assets to shares using a stored `totalAssets` value. */ function _convertToShares(uint256 assets, uint256 _totalAssets) internal view returns (uint256 shares) { uint256 totalShares = totalSupply(); shares = totalShares == 0 ? assets.changeDecimals(asset.decimals(), 18) : assets.mulDivDown(totalShares, _totalAssets); } /** * @dev Used to more efficiently simulate minting shares using a stored `totalAssets` value. */ function _previewMint(uint256 shares, uint256 _totalAssets) internal view returns (uint256 assets) { uint256 totalShares = totalSupply(); assets = totalShares == 0 ? shares.changeDecimals(18, asset.decimals()) : shares.mulDivUp(_totalAssets, totalShares); } /** * @dev Used to more efficiently simulate withdrawing assets using a stored `totalAssets` value. */ function _previewWithdraw(uint256 assets, uint256 _totalAssets) internal view returns (uint256 shares) { uint256 totalShares = totalSupply(); shares = totalShares == 0 ? assets.changeDecimals(asset.decimals(), 18) : assets.mulDivUp(totalShares, _totalAssets); } /** * @dev Used to efficiently get and store accounting information to avoid having to expensively * recompute it. */ function _getData() internal view returns ( uint256 _totalAssets, address[] memory _positions, ERC20[] memory positionAssets, uint256[] memory positionBalances, uint256[] memory withdrawableBalances ) { uint256 len = positions.length; _positions = new address[](len); positionAssets = new ERC20[](len); positionBalances = new uint256[](len); positionBalances = new uint256[](len); withdrawableBalances = new uint256[](len); for (uint256 i; i < len; i++) { address position = positions[i]; _positions[i] = position; positionAssets[i] = _assetOf(position); positionBalances[i] = _balanceOf(position); withdrawableBalances[i] = _withdrawableFrom(position); } PriceRouter priceRouter = PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT)); _totalAssets = priceRouter.getValues(positionAssets, positionBalances, asset); } // =========================================== POSITION LOGIC =========================================== /** * @notice Emitted on rebalancing positions. * @param fromPosition the address of the position rebalanced from * @param toPosition the address of the position rebalanced to * @param assetsFrom the amount of assets withdrawn from the position rebalanced from * @param assetsTo the amount of assets desposited to the position rebalanced to */ event Rebalance(address indexed fromPosition, address indexed toPosition, uint256 assetsFrom, uint256 assetsTo); /** * @notice Emitted on when the rebalance deviation is changed. * @param oldDeviation the old rebalance deviation * @param newDeviation the new rebalance deviation */ event RebalanceDeviationChanged(uint256 oldDeviation, uint256 newDeviation); /** * @notice totalAssets deviated outside the range set by `allowedRebalanceDeviation`. * @param assets the total assets in the cellar * @param min the minimum allowed assets * @param max the maximum allowed assets */ error Cellar__TotalAssetDeviatedOutsideRange(uint256 assets, uint256 min, uint256 max); /** * @notice Total shares in a cellar changed when they should stay constant. * @param current the current amount of total shares * @param expected the expected amount of total shares */ error Cellar__TotalSharesMustRemainConstant(uint256 current, uint256 expected); /** * @notice Total shares in a cellar changed when they should stay constant. * @param requested the requested rebalance deviation * @param max the max rebalance deviation. */ error Cellar__InvalidRebalanceDeviation(uint256 requested, uint256 max); uint64 public constant MAX_REBALANCE_DEVIATION = 0.1e18; /** * @notice The percent the total assets of a cellar may deviate during a rebalance call. */ uint256 public allowedRebalanceDeviation = 0.003e18; // Currently set to 0.3% /** * @notice Allows governance to change this cellars rebalance deviation. * @param newDeviation the new reabalance deviation value. */ function setRebalanceDeviation(uint256 newDeviation) external onlyOwner { if (newDeviation > MAX_REBALANCE_DEVIATION) revert Cellar__InvalidRebalanceDeviation(newDeviation, MAX_REBALANCE_DEVIATION); uint256 oldDeviation = allowedRebalanceDeviation; allowedRebalanceDeviation = newDeviation; emit RebalanceDeviationChanged(oldDeviation, newDeviation); } /** * @notice Move assets between positions. To move assets from/to this cellar's holdings, specify * the address of this cellar as the `fromPosition`/`toPosition`. * @param fromPosition address of the position to move assets from * @param toPosition address of the position to move assets to * @param assetsFrom amount of assets to move from the from position */ function rebalance( address fromPosition, address toPosition, uint256 assetsFrom, SwapRouter.Exchange exchange, bytes calldata params ) external onlyOwner whenNotShutdown nonReentrant returns (uint256 assetsTo) { // Check that position being rebalanced to is currently being used. if (!isPositionUsed[toPosition]) revert Cellar__InvalidPosition(address(toPosition)); // Before making any external calls save the current `totalAssets` and `totalSupply`. uint256 assets = totalAssets(); uint256 totalShares = totalSupply(); // Withdraw from position. _withdrawFrom(fromPosition, assetsFrom, address(this)); // Swap to the asset of the other position if necessary. ERC20 fromAsset = _assetOf(fromPosition); ERC20 toAsset = _assetOf(toPosition); assetsTo = fromAsset != toAsset ? _swap(fromAsset, toAsset, assetsFrom, exchange, params, address(this)) : assetsFrom; // Deposit into position. _depositTo(toPosition, assetsTo); // After making every external call, check that the totalAssets haas not deviated significantly, and that totalShares is the same. uint256 minimumAllowedAssets = assets.mulDivUp((1e18 - allowedRebalanceDeviation), 1e18); uint256 maximumAllowedAssets = assets.mulDivDown((1e18 + allowedRebalanceDeviation), 1e18); assets = totalAssets(); if (assets > maximumAllowedAssets || assets < minimumAllowedAssets) revert Cellar__TotalAssetDeviatedOutsideRange(assets, minimumAllowedAssets, maximumAllowedAssets); if (totalShares != totalSupply()) revert Cellar__TotalSharesMustRemainConstant(totalSupply(), totalShares); emit Rebalance(fromPosition, toPosition, assetsFrom, assetsTo); } // ============================================ LIMITS LOGIC ============================================ /** * @notice Total amount of assets that can be deposited for a user. * @dev This function does not take into account performance fees. * Performance fees would reduce `receiver`s `ownedAssets`, * making the `assets` value returned lower than actual * @param receiver address of account that would receive the shares * @return assets maximum amount of assets that can be deposited */ function maxDeposit(address receiver) public view override returns (uint256 assets) { if (isShutdown) return 0; uint256 asssetDepositLimit = depositLimit; uint256 asssetLiquidityLimit = liquidityLimit; if (asssetDepositLimit == type(uint256).max && asssetLiquidityLimit == type(uint256).max) return type(uint256).max; // Get data efficiently. uint256 _totalAssets = totalAssets(); uint256 ownedAssets = _convertToAssets(balanceOf(receiver), _totalAssets); uint256 leftUntilDepositLimit = asssetDepositLimit.subMinZero(ownedAssets); uint256 leftUntilLiquidityLimit = asssetLiquidityLimit.subMinZero(_totalAssets); // Only return the more relevant of the two. assets = Math.min(leftUntilDepositLimit, leftUntilLiquidityLimit); } /** * @notice Total amount of shares that can be minted for a user. * @dev This function does not take into account performance fees. * Performance fees would reduce `receiver`s `ownedAssets`, * making the `shares` value returned lower than actual * @param receiver address of account that would receive the shares * @return shares maximum amount of shares that can be minted */ function maxMint(address receiver) public view override returns (uint256 shares) { if (isShutdown) return 0; uint256 asssetDepositLimit = depositLimit; uint256 asssetLiquidityLimit = liquidityLimit; if (asssetDepositLimit == type(uint256).max && asssetLiquidityLimit == type(uint256).max) return type(uint256).max; // Get data efficiently. uint256 _totalAssets = totalAssets(); uint256 ownedAssets = _convertToAssets(balanceOf(receiver), _totalAssets); uint256 leftUntilDepositLimit = asssetDepositLimit.subMinZero(ownedAssets); uint256 leftUntilLiquidityLimit = asssetLiquidityLimit.subMinZero(_totalAssets); // Only return the more relevant of the two. shares = _convertToShares(Math.min(leftUntilDepositLimit, leftUntilLiquidityLimit), _totalAssets); } // ========================================= FEES LOGIC ========================================= /** * @notice Emitted when High Watermark is reset. * @param newHighWatermark new high watermark */ event HighWatermarkReset(uint256 newHighWatermark); /** * @notice Attempted to send fee shares to strategist payout address, when address is not set. */ error Cellar__PayoutNotSet(); /** * @notice Resets High Watermark to equal current total assets. * @notice This function can be abused by Strategists, so it should only be callable by governance. */ function resetHighWatermark() external onlyOwner { uint256 _totalAssets = totalAssets(); feeData.highWatermark = _totalAssets; emit HighWatermarkReset(_totalAssets); } /** * @notice Calculates how many assets Strategist would earn performance fees * @param _totalAssets uint256 value of the total assets in the cellar * @return feeInAssets amount of assets to take as fees */ function _previewPerformanceFees(uint256 _totalAssets) internal view returns (uint256 feeInAssets) { uint64 performanceFee = feeData.performanceFee; if (performanceFee == 0 || _totalAssets == 0) return 0; uint256 highWatermark = feeData.highWatermark; if (_totalAssets > highWatermark) { uint256 yield = _totalAssets - highWatermark; feeInAssets = yield.mulWadDown(performanceFee); } } /** * @notice Mints cellar performance fee shares if current share price is above high watermark * @dev If performance fees are minted, the resulting HWM will be greater than the current share price * since performance fees dilute share value. * @param _totalAssets uint256 value of the total assets in the cellar */ function _takePerformanceFees(uint256 _totalAssets) internal { uint256 feeInAssets = _previewPerformanceFees(_totalAssets); if (feeInAssets > 0) { uint256 platformFeesInShares = _convertToFees(_convertToShares(feeInAssets, _totalAssets)); if (platformFeesInShares > 0) { feeData.highWatermark = _totalAssets; _mint(address(this), platformFeesInShares); } } } /** * @dev Calculate the amount of fees to mint such that value of fees after minting is not diluted. */ function _convertToFees(uint256 feesInShares) internal view returns (uint256 fees) { // Saves an SLOAD. uint256 totalShares = totalSupply(); // Get the amount of fees to mint. Without this, the value of fees minted would be slightly // diluted because total shares increased while total assets did not. This counteracts that. if (totalShares > feesInShares) { // Denominator is greater than zero uint256 denominator = totalShares - feesInShares; fees = feesInShares.mulDivUp(totalShares, denominator); } // If denominator is less than or equal to zero, `fees` should be zero. } /** * @notice Emitted when platform fees are send to the Sommelier chain. * @param feesInSharesRedeemed amount of fees redeemed for assets to send * @param feesInAssetsSent amount of assets fees were redeemed for that were sent */ event SendFees(uint256 feesInSharesRedeemed, uint256 feesInAssetsSent); /** * @notice Transfer accrued fees to the Sommelier chain to distribute. * @dev Fees are accrued as shares and redeemed upon transfer. * @dev assumes cellar's accounting asset is able to be transferred and sent to Cosmos */ function sendFees() external nonReentrant { address strategistPayoutAddress = feeData.strategistPayoutAddress; if (strategistPayoutAddress == address(0)) revert Cellar__PayoutNotSet(); uint256 _totalAssets = totalAssets(); // Since this action mints shares, calculate outstanding performance fees due. _takePerformanceFees(_totalAssets); uint256 totalFees = balanceOf(address(this)); uint256 strategistFeeSharesDue = totalFees.mulWadDown(feeData.strategistPerformanceCut); // Calculate platform fees earned. uint256 elapsedTime = block.timestamp - lastAccrual; uint256 platformFeeInAssets = (_totalAssets * elapsedTime * feeData.platformFee) / 1e18 / 365 days; uint256 platformFees = _convertToFees(_convertToShares(platformFeeInAssets, _totalAssets)); _mint(address(this), platformFees); totalFees += platformFees; strategistFeeSharesDue += platformFees.mulWadDown(feeData.strategistPlatformCut); if (strategistFeeSharesDue > 0) { //transfer shares to strategist _transfer(address(this), strategistPayoutAddress, strategistFeeSharesDue); totalFees -= strategistFeeSharesDue; } lastAccrual = uint32(block.timestamp); // Redeem our fee shares for assets to send to the fee distributor module. uint256 assets = _convertToAssets(totalFees, _totalAssets); if (assets > 0) { // Without this, assets paid out as fees would be counted as a loss. feeData.highWatermark -= assets; _burn(address(this), totalFees); // Transfer assets to a fee distributor on the Sommelier chain. IGravity gravityBridge = IGravity(registry.getAddress(0)); asset.safeApprove(address(gravityBridge), assets); gravityBridge.sendToCosmos(address(asset), feeData.feesDistributor, assets); } emit SendFees(totalFees, assets); } // ========================================== HELPER FUNCTIONS ========================================== /** * @dev Deposit into a position according to its position type and update related state. * @param position address to deposit funds into * @param assets the amount of assets to deposit into the position */ function _depositTo(address position, uint256 assets) internal { PositionType positionType = getPositionType[position]; // Deposit into position. if (positionType == PositionType.ERC4626 || positionType == PositionType.Cellar) { ERC4626(position).asset().safeApprove(position, assets); ERC4626(position).deposit(assets, address(this)); } } /** * @dev Withdraw from a position according to its position type and update related state. * @param position address to withdraw funds from * @param assets the amount of assets to withdraw from the position * @param receiver the address to sent withdrawn assets to */ function _withdrawFrom( address position, uint256 assets, address receiver ) internal { PositionType positionType = getPositionType[position]; // Withdraw from position. if (positionType == PositionType.ERC4626 || positionType == PositionType.Cellar) { ERC4626(position).withdraw(assets, receiver, address(this)); } else { if (receiver != address(this)) ERC20(position).safeTransfer(receiver, assets); } } /** * @dev Get the withdrawable balance of a position according to its position type. * @param position position to get the withdrawable balance of */ function _withdrawableFrom(address position) internal view returns (uint256) { PositionType positionType = getPositionType[position]; if (positionType == PositionType.ERC4626 || positionType == PositionType.Cellar) { return ERC4626(position).maxWithdraw(address(this)); } else { return ERC20(position).balanceOf(address(this)); } } /** * @dev Get the balance of a position according to its position type. * @dev For ERC4626 position balances, this uses `previewRedeem` as opposed * to `convertToAssets` so that balanceOf ERC4626 positions includes fees taken on withdraw. * @param position position to get the balance of */ function _balanceOf(address position) internal view returns (uint256) { PositionType positionType = getPositionType[position]; if (positionType == PositionType.ERC4626 || positionType == PositionType.Cellar) { return ERC4626(position).previewRedeem(ERC4626(position).balanceOf(address(this))); } else { return ERC20(position).balanceOf(address(this)); } } /** * @dev Get the asset of a position according to its position type. * @param position to get the asset of */ function _assetOf(address position) internal view returns (ERC20) { PositionType positionType = getPositionType[position]; if (positionType == PositionType.ERC4626 || positionType == PositionType.Cellar) { return ERC4626(position).asset(); } else { return ERC20(position); } } /** * @notice Attempted to swap with bad parameters. */ error Cellar__WrongSwapParams(); /** * @dev Perform a swap using the swap router and check that it behaves as expected. * @param assetIn the asset to sell * @param amountIn the amount of `assetIn` to sell * @param exchange the exchange to sell `assetIn` on * @param params Abi encoded swap parameters dependent on the `exchange` selected. * Refer to SwapRouter.sol for `params` makeup * @param receiver the address to send the swapped assets to */ function _swap( ERC20 assetIn, ERC20 assetOut, uint256 amountIn, SwapRouter.Exchange exchange, bytes calldata params, address receiver ) internal returns (uint256 amountOut) { // Store the expected amount of the asset in that we expect to have after the swap. uint256 expectedAssetsInAfter = assetIn.balanceOf(address(this)) - amountIn; // Get the address of the latest swap router. SwapRouter swapRouter = SwapRouter(registry.getAddress(1)); // Approve swap router to swap assets. assetIn.safeApprove(address(swapRouter), amountIn); // Perform swap. amountOut = swapRouter.swap(exchange, params, receiver, assetIn, assetOut); // Check that the amount of assets swapped is what is expected. Will revert if the `params` // specified a different amount of assets to swap then `amountIn`. if (assetIn.balanceOf(address(this)) != expectedAssetsInAfter) revert Cellar__WrongSwapParams(); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; import { ERC20Permit } from "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol"; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { Math } from "src/utils/Math.sol"; /// @notice Minimal ERC4626 tokenized Vault implementation. /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/mixins/ERC4626.sol) abstract contract ERC4626 is ERC20, ERC20Permit { using SafeERC20 for ERC20; using Math for uint256; /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares); event Withdraw( address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares ); /*////////////////////////////////////////////////////////////// IMMUTABLES //////////////////////////////////////////////////////////////*/ ERC20 public asset; constructor( ERC20 _asset, string memory _name, string memory _symbol ) ERC20(_name, _symbol) ERC20Permit(_name) { asset = _asset; } /*////////////////////////////////////////////////////////////// DEPOSIT/WITHDRAWAL LOGIC //////////////////////////////////////////////////////////////*/ function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares) { // Check for rounding error since we round down in previewDeposit. require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES"); beforeDeposit(assets, shares, receiver); // Need to transfer before minting or ERC777s could reenter. asset.safeTransferFrom(msg.sender, address(this), assets); _mint(receiver, shares); emit Deposit(msg.sender, receiver, assets, shares); afterDeposit(assets, shares, receiver); } function mint(uint256 shares, address receiver) public virtual returns (uint256 assets) { assets = previewMint(shares); // No need to check for rounding error, previewMint rounds up. beforeDeposit(assets, shares, receiver); // Need to transfer before minting or ERC777s could reenter. asset.safeTransferFrom(msg.sender, address(this), assets); _mint(receiver, shares); emit Deposit(msg.sender, receiver, assets, shares); afterDeposit(assets, shares, receiver); } function withdraw( uint256 assets, address receiver, address owner ) public virtual returns (uint256 shares) { shares = previewWithdraw(assets); // No need to check for rounding error, previewWithdraw rounds up. if (msg.sender != owner) { _spendAllowance(owner, msg.sender, shares); } beforeWithdraw(assets, shares, receiver, owner); _burn(owner, shares); emit Withdraw(msg.sender, receiver, owner, assets, shares); asset.safeTransfer(receiver, assets); afterWithdraw(assets, shares, receiver, owner); } function redeem( uint256 shares, address receiver, address owner ) public virtual returns (uint256 assets) { if (msg.sender != owner) { _spendAllowance(owner, msg.sender, shares); } // Check for rounding error since we round down in previewRedeem. require((assets = previewRedeem(shares)) != 0, "ZERO_ASSETS"); beforeWithdraw(assets, shares, receiver, owner); _burn(owner, shares); emit Withdraw(msg.sender, receiver, owner, assets, shares); asset.safeTransfer(receiver, assets); afterWithdraw(assets, shares, receiver, owner); } /*////////////////////////////////////////////////////////////// ACCOUNTING LOGIC //////////////////////////////////////////////////////////////*/ function totalAssets() public view virtual returns (uint256); function convertToShares(uint256 assets) public view virtual returns (uint256) { uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. return supply == 0 ? assets : assets.mulDivDown(supply, totalAssets()); } function convertToAssets(uint256 shares) public view virtual returns (uint256) { uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. return supply == 0 ? shares : shares.mulDivDown(totalAssets(), supply); } function previewDeposit(uint256 assets) public view virtual returns (uint256) { return convertToShares(assets); } function previewMint(uint256 shares) public view virtual returns (uint256) { uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. return supply == 0 ? shares : shares.mulDivUp(totalAssets(), supply); } function previewWithdraw(uint256 assets) public view virtual returns (uint256) { uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. return supply == 0 ? assets : assets.mulDivUp(supply, totalAssets()); } function previewRedeem(uint256 shares) public view virtual returns (uint256) { return convertToAssets(shares); } /*////////////////////////////////////////////////////////////// DEPOSIT/WITHDRAWAL LIMIT LOGIC //////////////////////////////////////////////////////////////*/ function maxDeposit(address) public view virtual returns (uint256) { return type(uint256).max; } function maxMint(address) public view virtual returns (uint256) { return type(uint256).max; } function maxWithdraw(address owner) public view virtual returns (uint256) { return convertToAssets(balanceOf(owner)); } function maxRedeem(address owner) public view virtual returns (uint256) { return balanceOf(owner); } /*////////////////////////////////////////////////////////////// INTERNAL HOOKS LOGIC //////////////////////////////////////////////////////////////*/ function beforeDeposit( uint256 assets, uint256 shares, address receiver ) internal virtual {} function afterDeposit( uint256 assets, uint256 shares, address receiver ) internal virtual {} function beforeWithdraw( uint256 assets, uint256 shares, address receiver, address owner ) internal virtual {} function afterWithdraw( uint256 assets, uint256 shares, address receiver, address owner ) internal virtual {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.0; import { IMulticall } from "src/interfaces/IMulticall.sol"; /** * @title Multicall * @notice Enables calling multiple methods in a single call to the contract * From: https://github.com/Uniswap/v3-periphery/contracts/base/Multicall.sol */ abstract contract Multicall is IMulticall { /// @inheritdoc IMulticall function multicall(bytes[] calldata data) public payable override returns (bytes[] memory results) { results = new bytes[](data.length); for (uint256 i = 0; i < data.length; i++) { (bool success, bytes memory result) = address(this).delegatecall(data[i]); if (!success) { // Next 5 lines from https://ethereum.stackexchange.com/a/83577 // solhint-disable-next-line reason-string if (result.length < 68) revert(); assembly { result := add(result, 0x04) } revert(abi.decode(result, (string))); } results[i] = result; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.4.1) (utils/math/SafeCast.sol) pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toUint248(uint256 value) internal pure returns (uint248) { require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits"); return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toUint240(uint256 value) internal pure returns (uint240) { require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits"); return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toUint232(uint256 value) internal pure returns (uint232) { require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits"); return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.2._ */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toUint216(uint256 value) internal pure returns (uint216) { require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits"); return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toUint208(uint256 value) internal pure returns (uint208) { require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits"); return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toUint200(uint256 value) internal pure returns (uint200) { require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits"); return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toUint192(uint256 value) internal pure returns (uint192) { require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits"); return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toUint184(uint256 value) internal pure returns (uint184) { require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits"); return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toUint176(uint256 value) internal pure returns (uint176) { require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits"); return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toUint168(uint256 value) internal pure returns (uint168) { require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits"); return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toUint160(uint256 value) internal pure returns (uint160) { require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits"); return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toUint152(uint256 value) internal pure returns (uint152) { require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits"); return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toUint144(uint256 value) internal pure returns (uint144) { require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits"); return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toUint136(uint256 value) internal pure returns (uint136) { require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits"); return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v2.5._ */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toUint120(uint256 value) internal pure returns (uint120) { require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits"); return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toUint112(uint256 value) internal pure returns (uint112) { require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits"); return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toUint104(uint256 value) internal pure returns (uint104) { require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits"); return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.2._ */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toUint88(uint256 value) internal pure returns (uint88) { require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits"); return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toUint80(uint256 value) internal pure returns (uint80) { require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits"); return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toUint72(uint256 value) internal pure returns (uint72) { require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits"); return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v2.5._ */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toUint56(uint256 value) internal pure returns (uint56) { require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits"); return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toUint48(uint256 value) internal pure returns (uint48) { require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits"); return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toUint40(uint256 value) internal pure returns (uint40) { require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits"); return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v2.5._ */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toUint24(uint256 value) internal pure returns (uint24) { require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits"); return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v2.5._ */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v2.5._ */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. * * _Available since v3.0._ */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toInt248(int256 value) internal pure returns (int248) { require(value >= type(int248).min && value <= type(int248).max, "SafeCast: value doesn't fit in 248 bits"); return int248(value); } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toInt240(int256 value) internal pure returns (int240) { require(value >= type(int240).min && value <= type(int240).max, "SafeCast: value doesn't fit in 240 bits"); return int240(value); } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toInt232(int256 value) internal pure returns (int232) { require(value >= type(int232).min && value <= type(int232).max, "SafeCast: value doesn't fit in 232 bits"); return int232(value); } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.7._ */ function toInt224(int256 value) internal pure returns (int224) { require(value >= type(int224).min && value <= type(int224).max, "SafeCast: value doesn't fit in 224 bits"); return int224(value); } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toInt216(int256 value) internal pure returns (int216) { require(value >= type(int216).min && value <= type(int216).max, "SafeCast: value doesn't fit in 216 bits"); return int216(value); } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toInt208(int256 value) internal pure returns (int208) { require(value >= type(int208).min && value <= type(int208).max, "SafeCast: value doesn't fit in 208 bits"); return int208(value); } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toInt200(int256 value) internal pure returns (int200) { require(value >= type(int200).min && value <= type(int200).max, "SafeCast: value doesn't fit in 200 bits"); return int200(value); } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toInt192(int256 value) internal pure returns (int192) { require(value >= type(int192).min && value <= type(int192).max, "SafeCast: value doesn't fit in 192 bits"); return int192(value); } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toInt184(int256 value) internal pure returns (int184) { require(value >= type(int184).min && value <= type(int184).max, "SafeCast: value doesn't fit in 184 bits"); return int184(value); } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toInt176(int256 value) internal pure returns (int176) { require(value >= type(int176).min && value <= type(int176).max, "SafeCast: value doesn't fit in 176 bits"); return int176(value); } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toInt168(int256 value) internal pure returns (int168) { require(value >= type(int168).min && value <= type(int168).max, "SafeCast: value doesn't fit in 168 bits"); return int168(value); } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toInt160(int256 value) internal pure returns (int160) { require(value >= type(int160).min && value <= type(int160).max, "SafeCast: value doesn't fit in 160 bits"); return int160(value); } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toInt152(int256 value) internal pure returns (int152) { require(value >= type(int152).min && value <= type(int152).max, "SafeCast: value doesn't fit in 152 bits"); return int152(value); } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toInt144(int256 value) internal pure returns (int144) { require(value >= type(int144).min && value <= type(int144).max, "SafeCast: value doesn't fit in 144 bits"); return int144(value); } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toInt136(int256 value) internal pure returns (int136) { require(value >= type(int136).min && value <= type(int136).max, "SafeCast: value doesn't fit in 136 bits"); return int136(value); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128) { require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits"); return int128(value); } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toInt120(int256 value) internal pure returns (int120) { require(value >= type(int120).min && value <= type(int120).max, "SafeCast: value doesn't fit in 120 bits"); return int120(value); } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toInt112(int256 value) internal pure returns (int112) { require(value >= type(int112).min && value <= type(int112).max, "SafeCast: value doesn't fit in 112 bits"); return int112(value); } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toInt104(int256 value) internal pure returns (int104) { require(value >= type(int104).min && value <= type(int104).max, "SafeCast: value doesn't fit in 104 bits"); return int104(value); } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.7._ */ function toInt96(int256 value) internal pure returns (int96) { require(value >= type(int96).min && value <= type(int96).max, "SafeCast: value doesn't fit in 96 bits"); return int96(value); } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toInt88(int256 value) internal pure returns (int88) { require(value >= type(int88).min && value <= type(int88).max, "SafeCast: value doesn't fit in 88 bits"); return int88(value); } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toInt80(int256 value) internal pure returns (int80) { require(value >= type(int80).min && value <= type(int80).max, "SafeCast: value doesn't fit in 80 bits"); return int80(value); } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toInt72(int256 value) internal pure returns (int72) { require(value >= type(int72).min && value <= type(int72).max, "SafeCast: value doesn't fit in 72 bits"); return int72(value); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64) { require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits"); return int64(value); } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toInt56(int256 value) internal pure returns (int56) { require(value >= type(int56).min && value <= type(int56).max, "SafeCast: value doesn't fit in 56 bits"); return int56(value); } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toInt48(int256 value) internal pure returns (int48) { require(value >= type(int48).min && value <= type(int48).max, "SafeCast: value doesn't fit in 48 bits"); return int48(value); } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toInt40(int256 value) internal pure returns (int40) { require(value >= type(int40).min && value <= type(int40).max, "SafeCast: value doesn't fit in 40 bits"); return int40(value); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32) { require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits"); return int32(value); } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toInt24(int256 value) internal pure returns (int24) { require(value >= type(int24).min && value <= type(int24).max, "SafeCast: value doesn't fit in 24 bits"); return int24(value); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16) { require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits"); return int16(value); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8) { require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits"); return int8(value); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. * * _Available since v3.0._ */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } /** * @dev Converts an unsigned uint256 into a signed int248. * * Requirements: * * - input must be less than or equal to maxInt248. * * _Available since v3.0._ */ function toInt248(uint256 value) internal pure returns (int248) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint248(type(int248).max), "SafeCast: value doesn't fit in an int248"); return int248(int256(value)); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; contract Registry is Ownable { // ============================================= ADDRESS CONFIG ============================================= /** * @notice Emitted when the address of a contract is changed. * @param id value representing the unique ID tied to the changed contract * @param oldAddress address of the contract before the change * @param newAddress address of the contract after the contract */ event AddressChanged(uint256 indexed id, address oldAddress, address newAddress); /** * @notice Attempted to set the address of a contract that is not registered. * @param id id of the contract that is not registered */ error Registry__ContractNotRegistered(uint256 id); /** * @notice Emitted when depositor privilege changes. * @param depositor depositor address * @param state the new state of the depositor privilege */ event DepositorOnBehalfChanged(address depositor, bool state); /** * @notice The unique ID that the next registered contract will have. */ uint256 public nextId; /** * @notice Get the address associated with an id. */ mapping(uint256 => address) public getAddress; /** * @notice In order for an address to make deposits on behalf of users they must be approved. */ mapping(address => bool) public approvedForDepositOnBehalf; /** * @notice toggles a depositors ability to deposit into cellars on behalf of users. */ function setApprovedForDepositOnBehalf(address depositor, bool state) external onlyOwner { approvedForDepositOnBehalf[depositor] = state; emit DepositorOnBehalfChanged(depositor, state); } /** * @notice Set the address of the contract at a given id. */ function setAddress(uint256 id, address newAddress) external onlyOwner { if (id >= nextId) revert Registry__ContractNotRegistered(id); emit AddressChanged(id, getAddress[id], newAddress); getAddress[id] = newAddress; } // ============================================= INITIALIZATION ============================================= /** * @param gravityBridge address of GravityBridge contract * @param swapRouter address of SwapRouter contract * @param priceRouter address of PriceRouter contract */ constructor( address gravityBridge, address swapRouter, address priceRouter ) Ownable() { _register(gravityBridge); _register(swapRouter); _register(priceRouter); } // ============================================ REGISTER CONFIG ============================================ /** * @notice Emitted when a new contract is registered. * @param id value representing the unique ID tied to the new contract * @param newContract address of the new contract */ event Registered(uint256 indexed id, address indexed newContract); /** * @notice Register the address of a new contract. * @param newContract address of the new contract to register */ function register(address newContract) external onlyOwner { _register(newContract); } function _register(address newContract) internal { getAddress[nextId] = newContract; emit Registered(nextId, newContract); nextId++; } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import { Multicall } from "src/base/Multicall.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { IUniswapV2Router02 as IUniswapV2Router } from "src/interfaces/external/IUniswapV2Router02.sol"; import { IUniswapV3Router } from "src/interfaces/external/IUniswapV3Router.sol"; /** * @title Sommelier Swap Router * @notice Provides a universal interface allowing Sommelier contracts to interact with multiple * different exchanges to perform swaps. * @dev Perform multiple swaps using Multicall. * @author crispymangoes, Brian Le */ contract SwapRouter is Multicall { using SafeERC20 for ERC20; /** * @param UNIV2 Uniswap V2 * @param UNIV3 Uniswap V3 */ enum Exchange { UNIV2, UNIV3 } /** * @notice Get the selector of the function to call in order to perform swap with a given exchange. */ mapping(Exchange => bytes4) public getExchangeSelector; // ========================================== CONSTRUCTOR ========================================== /** * @notice Uniswap V2 swap router contract. */ IUniswapV2Router public immutable uniswapV2Router; // 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D /** * @notice Uniswap V3 swap router contract. */ IUniswapV3Router public immutable uniswapV3Router; // 0xE592427A0AEce92De3Edee1F18E0157C05861564 /** * @param _uniswapV2Router address of the Uniswap V2 swap router contract * @param _uniswapV3Router address of the Uniswap V3 swap router contract */ constructor(IUniswapV2Router _uniswapV2Router, IUniswapV3Router _uniswapV3Router) { // Set up all exchanges. uniswapV2Router = _uniswapV2Router; uniswapV3Router = _uniswapV3Router; // Set up mapping between IDs and selectors. getExchangeSelector[Exchange.UNIV2] = SwapRouter(this).swapWithUniV2.selector; getExchangeSelector[Exchange.UNIV3] = SwapRouter(this).swapWithUniV3.selector; } // ======================================= SWAP OPERATIONS ======================================= /** * @notice Attempted to perform a swap that reverted without a message. */ error SwapRouter__SwapReverted(); /** * @notice Attempted to perform a swap with mismatched assetIn and swap data. * @param actual the address encoded into the swap data * @param expected the address passed in with assetIn */ error SwapRouter__AssetInMisMatch(address actual, address expected); /** * @notice Attempted to perform a swap with mismatched assetOut and swap data. * @param actual the address encoded into the swap data * @param expected the address passed in with assetIn */ error SwapRouter__AssetOutMisMatch(address actual, address expected); /** * @notice Perform a swap using a supported exchange. * @param exchange value dictating which exchange to use to make the swap * @param swapData encoded data used for the swap * @param receiver address to send the received assets to * @return amountOut amount of assets received from the swap */ function swap( Exchange exchange, bytes memory swapData, address receiver, ERC20 assetIn, ERC20 assetOut ) external returns (uint256 amountOut) { // Route swap call to appropriate function using selector. (bool success, bytes memory result) = address(this).delegatecall( abi.encodeWithSelector(getExchangeSelector[exchange], swapData, receiver, assetIn, assetOut) ); if (!success) { // If there is return data, the call reverted with a reason or a custom error so we // bubble up the error message. if (result.length > 0) { assembly { let returndata_size := mload(result) revert(add(32, result), returndata_size) } } else { revert SwapRouter__SwapReverted(); } } amountOut = abi.decode(result, (uint256)); } /** * @notice Perform a swap using Uniswap V2. * @param swapData bytes variable storing the following swap information: * address[] path: array of addresses dictating what swap path to follow * uint256 amount: amount of the first asset in the path to swap * uint256 amountOutMin: the minimum amount of the last asset in the path to receive * @param receiver address to send the received assets to * @return amountOut amount of assets received from the swap */ function swapWithUniV2( bytes memory swapData, address receiver, ERC20 assetIn, ERC20 assetOut ) public returns (uint256 amountOut) { (address[] memory path, uint256 amount, uint256 amountOutMin) = abi.decode( swapData, (address[], uint256, uint256) ); // Check that path matches assetIn and assetOut. if (assetIn != ERC20(path[0])) revert SwapRouter__AssetInMisMatch(path[0], address(assetIn)); if (assetOut != ERC20(path[path.length - 1])) revert SwapRouter__AssetOutMisMatch(path[path.length - 1], address(assetOut)); // Transfer assets to this contract to swap. assetIn.safeTransferFrom(msg.sender, address(this), amount); // Approve assets to be swapped through the router. assetIn.safeApprove(address(uniswapV2Router), amount); // Execute the swap. uint256[] memory amountsOut = uniswapV2Router.swapExactTokensForTokens( amount, amountOutMin, path, receiver, block.timestamp + 60 ); amountOut = amountsOut[amountsOut.length - 1]; } /** * @notice Perform a swap using Uniswap V3. * @param swapData bytes variable storing the following swap information * address[] path: array of addresses dictating what swap path to follow * uint24[] poolFees: array of pool fees dictating what swap pools to use * uint256 amount: amount of the first asset in the path to swap * uint256 amountOutMin: the minimum amount of the last asset in the path to receive * @param receiver address to send the received assets to * @return amountOut amount of assets received from the swap */ function swapWithUniV3( bytes memory swapData, address receiver, ERC20 assetIn, ERC20 assetOut ) public returns (uint256 amountOut) { (address[] memory path, uint24[] memory poolFees, uint256 amount, uint256 amountOutMin) = abi.decode( swapData, (address[], uint24[], uint256, uint256) ); // Check that path matches assetIn and assetOut. if (assetIn != ERC20(path[0])) revert SwapRouter__AssetInMisMatch(path[0], address(assetIn)); if (assetOut != ERC20(path[path.length - 1])) revert SwapRouter__AssetOutMisMatch(path[path.length - 1], address(assetOut)); // Transfer assets to this contract to swap. assetIn.safeTransferFrom(msg.sender, address(this), amount); // Approve assets to be swapped through the router. assetIn.safeApprove(address(uniswapV3Router), amount); // Encode swap parameters. bytes memory encodePackedPath = abi.encodePacked(address(assetIn)); for (uint256 i = 1; i < path.length; i++) encodePackedPath = abi.encodePacked(encodePackedPath, poolFees[i - 1], path[i]); // Execute the swap. amountOut = uniswapV3Router.exactInput( IUniswapV3Router.ExactInputParams({ path: encodePackedPath, recipient: receiver, deadline: block.timestamp + 60, amountIn: amount, amountOutMinimum: amountOutMin }) ); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { FeedRegistryInterface } from "@chainlink/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol"; import { AggregatorV2V3Interface } from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol"; import { IChainlinkAggregator } from "src/interfaces/external/IChainlinkAggregator.sol"; import { Denominations } from "@chainlink/contracts/src/v0.8/Denominations.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import { Math } from "src/utils/Math.sol"; /** * @title Sommelier Price Router * @notice Provides a universal interface allowing Sommelier contracts to retrieve secure pricing * data from Chainlink. * @author crispymangoes, Brian Le */ contract PriceRouter is Ownable { using SafeERC20 for ERC20; using SafeCast for int256; using Math for uint256; event AddAsset(address indexed asset); // =========================================== ASSETS CONFIG =========================================== /** * @param minPrice minimum price in USD for the asset before reverting * @param maxPrice maximum price in USD for the asset before reverting * @param isPriceRangeInETH if true price range values are given in ETH, if false price range is given in USD * @param heartbeat maximum allowed time that can pass with no update before price data is considered stale * @param isSupported whether this asset is supported by the platform or not */ struct AssetConfig { uint256 minPrice; uint256 maxPrice; bool isPriceRangeInETH; uint96 heartbeat; bool isSupported; } /** * @notice Get the asset data for a given asset. */ mapping(ERC20 => AssetConfig) public getAssetConfig; uint96 public constant DEFAULT_HEART_BEAT = 1 days; // ======================================= ADAPTOR OPERATIONS ======================================= /** * @notice Attempted to set a minimum price below the Chainlink minimum price (with buffer). * @param minPrice minimum price attempted to set * @param bufferedMinPrice minimum price that can be set including buffer */ error PriceRouter__InvalidMinPrice(uint256 minPrice, uint256 bufferedMinPrice); /** * @notice Attempted to set a maximum price above the Chainlink maximum price (with buffer). * @param maxPrice maximum price attempted to set * @param bufferedMaxPrice maximum price that can be set including buffer */ error PriceRouter__InvalidMaxPrice(uint256 maxPrice, uint256 bufferedMaxPrice); /** * @notice Attempted to add an invalid asset. * @param asset address of the invalid asset */ error PriceRouter__InvalidAsset(address asset); /** * @notice Attempted to add an asset with a certain price range denomination, but actual denomination was different. * @param expected price range denomination * @param actual price range denomination * @dev If an asset has price feeds in USD and ETH, the feed in USD is favored */ error PriceRouter__PriceRangeDenominationMisMatch(bool expected, bool actual); /** * @notice Attempted to add an asset with invalid min/max prices. * @param min price * @param max price */ error PriceRouter__MinPriceGreaterThanMaxPrice(uint256 min, uint256 max); /** * @notice Add an asset for the price router to support. * @param asset address of asset to support on the platform * @param minPrice minimum price in USD with 8 decimals for the asset before reverting, * set to `0` to use Chainlink's default * @param maxPrice maximum price in USD with 8 decimals for the asset before reverting, * set to `0` to use Chainlink's default * @param heartbeat maximum amount of time that can pass without the price data being updated * before reverting, set to `0` to use the default of 1 day */ function addAsset( ERC20 asset, uint256 minPrice, uint256 maxPrice, bool rangeInETH, uint96 heartbeat ) external onlyOwner { if (address(asset) == address(0)) revert PriceRouter__InvalidAsset(address(asset)); // Use Chainlink to get the min and max of the asset. ERC20 assetToQuery = _remap(asset); (uint256 minFromChainklink, uint256 maxFromChainlink, bool isETH) = _getPriceRange(assetToQuery); // Check if callers expected price range denomination matches actual. if (rangeInETH != isETH) revert PriceRouter__PriceRangeDenominationMisMatch(rangeInETH, isETH); // Add a ~10% buffer to minimum and maximum price from Chainlink because Chainlink can stop updating // its price before/above the min/max price. uint256 bufferedMinPrice = minFromChainklink.mulWadDown(1.1e18); uint256 bufferedMaxPrice = maxFromChainlink.mulWadDown(0.9e18); if (minPrice == 0) { minPrice = bufferedMinPrice; } else { if (minPrice < bufferedMinPrice) revert PriceRouter__InvalidMinPrice(minPrice, bufferedMinPrice); } if (maxPrice == 0) { maxPrice = bufferedMaxPrice; } else { if (maxPrice > bufferedMaxPrice) revert PriceRouter__InvalidMaxPrice(maxPrice, bufferedMaxPrice); } if (minPrice >= maxPrice) revert PriceRouter__MinPriceGreaterThanMaxPrice(minPrice, maxPrice); getAssetConfig[asset] = AssetConfig({ minPrice: minPrice, maxPrice: maxPrice, isPriceRangeInETH: isETH, heartbeat: heartbeat != 0 ? heartbeat : DEFAULT_HEART_BEAT, isSupported: true }); emit AddAsset(address(asset)); } function isSupported(ERC20 asset) external view returns (bool) { return getAssetConfig[asset].isSupported; } // ======================================= PRICING OPERATIONS ======================================= /** * @notice Get the value of an asset in terms of another asset. * @param baseAsset address of the asset to get the price of in terms of the quote asset * @param amount amount of the base asset to price * @param quoteAsset address of the asset that the base asset is priced in terms of * @return value value of the amount of base assets specified in terms of the quote asset */ function getValue( ERC20 baseAsset, uint256 amount, ERC20 quoteAsset ) external view returns (uint256 value) { value = amount.mulDivDown(getExchangeRate(baseAsset, quoteAsset), 10**baseAsset.decimals()); } /** * @notice Attempted an operation with arrays of unequal lengths that were expected to be equal length. */ error PriceRouter__LengthMismatch(); /** * @notice Get the total value of multiple assets in terms of another asset. * @param baseAssets addresses of the assets to get the price of in terms of the quote asset * @param amounts amounts of each base asset to price * @param quoteAsset address of the assets that the base asset is priced in terms of * @return value total value of the amounts of each base assets specified in terms of the quote asset */ function getValues( ERC20[] memory baseAssets, uint256[] memory amounts, ERC20 quoteAsset ) external view returns (uint256 value) { uint256 numOfAssets = baseAssets.length; if (numOfAssets != amounts.length) revert PriceRouter__LengthMismatch(); uint8 quoteAssetDecimals = quoteAsset.decimals(); for (uint256 i; i < numOfAssets; i++) { ERC20 baseAsset = baseAssets[i]; value += amounts[i].mulDivDown( _getExchangeRate(baseAsset, quoteAsset, quoteAssetDecimals), 10**baseAsset.decimals() ); } } /** * @notice Get the exchange rate between two assets. * @param baseAsset address of the asset to get the exchange rate of in terms of the quote asset * @param quoteAsset address of the asset that the base asset is exchanged for * @return exchangeRate rate of exchange between the base asset and the quote asset */ function getExchangeRate(ERC20 baseAsset, ERC20 quoteAsset) public view returns (uint256 exchangeRate) { exchangeRate = _getExchangeRate(baseAsset, quoteAsset, quoteAsset.decimals()); } /** * @notice Get the exchange rates between multiple assets and another asset. * @param baseAssets addresses of the assets to get the exchange rates of in terms of the quote asset * @param quoteAsset address of the asset that the base assets are exchanged for * @return exchangeRates rate of exchange between the base assets and the quote asset */ function getExchangeRates(ERC20[] memory baseAssets, ERC20 quoteAsset) external view returns (uint256[] memory exchangeRates) { uint8 quoteAssetDecimals = quoteAsset.decimals(); uint256 numOfAssets = baseAssets.length; exchangeRates = new uint256[](numOfAssets); for (uint256 i; i < numOfAssets; i++) exchangeRates[i] = _getExchangeRate(baseAssets[i], quoteAsset, quoteAssetDecimals); } /** * @notice Get the minimum and maximum valid price for an asset. * @param asset address of the asset to get the price range of * @return min minimum valid price for the asset * @return max maximum valid price for the asset */ function getPriceRange(ERC20 asset) public view returns ( uint256 min, uint256 max, bool isETH ) { AssetConfig memory config = getAssetConfig[asset]; if (!config.isSupported) revert PriceRouter__UnsupportedAsset(address(asset)); (min, max, isETH) = (config.minPrice, config.maxPrice, config.isPriceRangeInETH); } /** * @notice Get the minimum and maximum valid prices for an asset. * @param _assets addresses of the assets to get the price ranges for * @return min minimum valid price for each asset * @return max maximum valid price for each asset */ function getPriceRanges(ERC20[] memory _assets) external view returns ( uint256[] memory min, uint256[] memory max, bool[] memory isETH ) { uint256 numOfAssets = _assets.length; (min, max, isETH) = (new uint256[](numOfAssets), new uint256[](numOfAssets), new bool[](numOfAssets)); for (uint256 i; i < numOfAssets; i++) (min[i], max[i], isETH[i]) = getPriceRange(_assets[i]); } // =========================================== HELPER FUNCTIONS =========================================== ERC20 private constant WETH = ERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); ERC20 private constant WBTC = ERC20(0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599); function _remap(ERC20 asset) internal pure returns (ERC20) { if (asset == WETH) return ERC20(Denominations.ETH); if (asset == WBTC) return ERC20(Denominations.BTC); return asset; } /** * @notice Gets the exchange rate between a base and a quote asset * @param baseAsset the asset to convert into quoteAsset * @param quoteAsset the asset base asset is converted into * @return exchangeRate value of base asset in terms of quote asset */ function _getExchangeRate( ERC20 baseAsset, ERC20 quoteAsset, uint8 quoteAssetDecimals ) internal view returns (uint256 exchangeRate) { exchangeRate = getValueInUSD(baseAsset).mulDivDown(10**quoteAssetDecimals, getValueInUSD(quoteAsset)); } /** * @notice Attempted to update the asset to one that is not supported by the platform. * @param asset address of the unsupported asset */ error PriceRouter__UnsupportedAsset(address asset); /** * @notice Attempted an operation to price an asset that under its minimum valid price. * @param asset address of the asset that is under its minimum valid price * @param price price of the asset * @param minPrice minimum valid price of the asset */ error PriceRouter__AssetBelowMinPrice(address asset, uint256 price, uint256 minPrice); /** * @notice Attempted an operation to price an asset that under its maximum valid price. * @param asset address of the asset that is under its maximum valid price * @param price price of the asset * @param maxPrice maximum valid price of the asset */ error PriceRouter__AssetAboveMaxPrice(address asset, uint256 price, uint256 maxPrice); /** * @notice Attempted to fetch a price for an asset that has not been updated in too long. * @param asset address of the asset thats price is stale * @param timeSinceLastUpdate seconds since the last price update * @param heartbeat maximum allowed time between price updates */ error PriceRouter__StalePrice(address asset, uint256 timeSinceLastUpdate, uint256 heartbeat); // =========================================== CHAINLINK PRICING FUNCTIONS ===========================================\ /** * @notice Feed Registry contract used to get chainlink data feeds, use getFeed!! */ FeedRegistryInterface public constant feedRegistry = FeedRegistryInterface(0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf); /** * @notice Could not find an asset's price in USD or ETH. * @param asset address of the asset */ error PriceRouter__PriceNotAvailable(address asset); /** * @notice Interacts with Chainlink feed registry and first tries to get `asset` price in USD, * if that fails, then it tries to get `asset` price in ETH, and then converts the answer into USD. * @param asset the ERC20 token to get the price of. * @return price the price of `asset` in USD */ function getValueInUSD(ERC20 asset) public view returns (uint256 price) { AssetConfig memory config = getAssetConfig[asset]; // Make sure asset is supported. if (!config.isSupported) revert PriceRouter__UnsupportedAsset(address(asset)); // Remap asset if need be. asset = _remap(asset); if (!config.isPriceRangeInETH) { // Price feed is in USD. (, int256 _price, , uint256 _timestamp, ) = feedRegistry.latestRoundData(address(asset), Denominations.USD); price = _price.toUint256(); _checkPriceFeed(asset, price, _timestamp, config); } else { // Price feed is in ETH. (, int256 _price, , uint256 _timestamp, ) = feedRegistry.latestRoundData(address(asset), Denominations.ETH); price = _price.toUint256(); _checkPriceFeed(asset, price, _timestamp, config); // Convert price from ETH to USD. price = _price.toUint256().mulWadDown(_getExchangeRateFromETHToUSD()); } } /** * @notice Could not find an asset's price range in USD or ETH. * @param asset address of the asset */ error PriceRouter__PriceRangeNotAvailable(address asset); /** * @notice Interacts with Chainlink feed registry and first tries to get `asset` price range in USD, * if that fails, then it tries to get `asset` price range in ETH, and then converts the range into USD. * @param asset the ERC20 token to get the price range of. * @return min the minimum price where Chainlink nodes stop updating the oracle * @return max the maximum price where Chainlink nodes stop updating the oracle */ function _getPriceRange(ERC20 asset) internal view returns ( uint256 min, uint256 max, bool isETH ) { try feedRegistry.getFeed(address(asset), Denominations.USD) returns (AggregatorV2V3Interface aggregator) { IChainlinkAggregator chainlinkAggregator = IChainlinkAggregator(address(aggregator)); min = uint256(uint192(chainlinkAggregator.minAnswer())); max = uint256(uint192(chainlinkAggregator.maxAnswer())); isETH = false; } catch { // If we can't find the USD price, then try the ETH price. try feedRegistry.getFeed(address(asset), Denominations.ETH) returns (AggregatorV2V3Interface aggregator) { IChainlinkAggregator chainlinkAggregator = IChainlinkAggregator(address(aggregator)); min = uint256(uint192(chainlinkAggregator.minAnswer())); max = uint256(uint192(chainlinkAggregator.maxAnswer())); isETH = true; } catch { revert PriceRouter__PriceRangeNotAvailable(address(asset)); } } } /** * @notice helper function to grab pricing data for ETH in USD * @return exchangeRate the exchange rate for ETH in terms of USD * @dev It is inefficient to re-calculate _checkPriceFeed for ETH -> USD multiple times for a single TX, * but this is done in the explicit way because it is simpler and less prone to logic errors. */ function _getExchangeRateFromETHToUSD() internal view returns (uint256 exchangeRate) { (, int256 _price, , uint256 _timestamp, ) = feedRegistry.latestRoundData(Denominations.ETH, Denominations.USD); exchangeRate = _price.toUint256(); _checkPriceFeed(WETH, exchangeRate, _timestamp, getAssetConfig[WETH]); } /** * @notice helper function to validate a price feed is safe to use. * @param asset ERC20 asset price feed data is for. * @param value the price value the price feed gave. * @param timestamp the last timestamp the price feed was updated. * @param config the assets config storing min price, max price, and heartbeat requirements. */ function _checkPriceFeed( ERC20 asset, uint256 value, uint256 timestamp, AssetConfig memory config ) internal view { uint256 minPrice = config.minPrice; if (value < minPrice) revert PriceRouter__AssetBelowMinPrice(address(asset), value, minPrice); uint256 maxPrice = config.maxPrice; if (value > maxPrice) revert PriceRouter__AssetAboveMaxPrice(address(asset), value, maxPrice); uint256 heartbeat = config.heartbeat; uint256 timeSinceLastUpdate = block.timestamp - timestamp; if (timeSinceLastUpdate > heartbeat) revert PriceRouter__StalePrice(address(asset), timeSinceLastUpdate, heartbeat); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; interface IGravity { function sendToCosmos( address _tokenContract, bytes32 _destination, uint256 _amount ) external; }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; /** * @notice A library to extend the address array data type. */ library AddressArray { // =========================================== ADDRESS STORAGE =========================================== /** * @notice Add an address to the array at a given index. * @param array address array to add the address to * @param index index to add the address at * @param value address to add to the array */ function add( address[] storage array, uint256 index, address value ) internal { uint256 len = array.length; array.push(array[len - 1]); for (uint256 i = len - 1; i > index; i--) array[i] = array[i - 1]; array[index] = value; } /** * @notice Remove an address from the array at a given index. * @param array address array to remove the address from * @param index index to remove the address at */ function remove(address[] storage array, uint256 index) internal { uint256 len = array.length; require(index < len, "Index out of bounds"); for (uint256 i = index; i < len - 1; i++) array[i] = array[i + 1]; array.pop(); } /** * @notice Remove the first occurrence of a value in an array. * @param array address array to remove the address from * @param value address to remove from the array */ function remove(address[] storage array, address value) internal { uint256 len = array.length; for (uint256 i; i < len; i++) if (array[i] == value) { for (i; i < len - 1; i++) array[i] = array[i + 1]; array.pop(); return; } revert("Value not found"); } /** * @notice Check whether an array contains an address. * @param array address array to check * @param value address to check for */ function contains(address[] storage array, address value) internal view returns (bool) { for (uint256 i; i < array.length; i++) if (value == array[i]) return true; return false; } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; library Math { /** * @notice Substract with a floor of 0 for the result. */ function subMinZero(uint256 x, uint256 y) internal pure returns (uint256) { return x > y ? x - y : 0; } /** * @notice Used to change the decimals of precision used for an amount. */ function changeDecimals( uint256 amount, uint8 fromDecimals, uint8 toDecimals ) internal pure returns (uint256) { if (fromDecimals == toDecimals) { return amount; } else if (fromDecimals < toDecimals) { return amount * 10**(toDecimals - fromDecimals); } else { return amount / 10**(fromDecimals - toDecimals); } } // ===================================== OPENZEPPELIN'S MATH ===================================== function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } // ================================= SOLMATE's FIXEDPOINTMATHLIB ================================= uint256 public constant WAD = 1e18; // The scalar of ETH and most ERC20s. function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down. } function mulDivDown( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 z) { assembly { // Store x * y in z for now. z := mul(x, y) // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y)) if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) { revert(0, 0) } // Divide z by the denominator. z := div(z, denominator) } } function mulDivUp( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 z) { assembly { // Store x * y in z for now. z := mul(x, y) // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y)) if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) { revert(0, 0) } // First, divide z - 1 by the denominator and add 1. // We allow z - 1 to underflow if z is 0, because we multiply the // end result by 0 if z is zero, ensuring we return 0 if z is zero. z := mul(iszero(iszero(z)), add(div(sub(z, 1), denominator), 1)) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/extensions/draft-ERC20Permit.sol) pragma solidity ^0.8.0; import "./draft-IERC20Permit.sol"; import "../ERC20.sol"; import "../../../utils/cryptography/draft-EIP712.sol"; import "../../../utils/cryptography/ECDSA.sol"; import "../../../utils/Counters.sol"; /** * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. * * _Available since v3.4._ */ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { using Counters for Counters.Counter; mapping(address => Counters.Counter) private _nonces; // solhint-disable-next-line var-name-mixedcase bytes32 private constant _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); /** * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`. * However, to ensure consistency with the upgradeable transpiler, we will continue * to reserve a slot. * @custom:oz-renamed-from _PERMIT_TYPEHASH */ // solhint-disable-next-line var-name-mixedcase bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT; /** * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. * * It's a good idea to use the same `name` that is defined as the ERC20 token name. */ constructor(string memory name) EIP712(name, "1") {} /** * @dev See {IERC20Permit-permit}. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual override { require(block.timestamp <= deadline, "ERC20Permit: expired deadline"); bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline)); bytes32 hash = _hashTypedDataV4(structHash); address signer = ECDSA.recover(hash, v, r, s); require(signer == owner, "ERC20Permit: invalid signature"); _approve(owner, spender, value); } /** * @dev See {IERC20Permit-nonces}. */ function nonces(address owner) public view virtual override returns (uint256) { return _nonces[owner].current(); } /** * @dev See {IERC20Permit-DOMAIN_SEPARATOR}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view override returns (bytes32) { return _domainSeparatorV4(); } /** * @dev "Consume a nonce": return the current value and increment. * * _Available since v4.1._ */ function _useNonce(address owner) internal virtual returns (uint256 current) { Counters.Counter storage nonce = _nonces[owner]; current = nonce.current(); nonce.increment(); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.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)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.0; /// @title Multicall interface /// @notice Enables calling multiple methods in a single call to the contract // From: https://github.com/Uniswap/v3-periphery/contracts/interfaces/IMulticall.sol interface IMulticall { /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed /// @dev The `msg.value` should not be trusted for any method callable from multicall. /// @param data The encoded function data for each of the calls to make to this contract /// @return results The results from each of the calls passed in via data function multicall(bytes[] calldata data) external payable returns (bytes[] memory results); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity >=0.8.0; interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns ( uint256 amountA, uint256 amountB, uint256 liquidity ); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); function removeLiquidity( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETH( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountToken, uint256 amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETHWithPermit( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountToken, uint256 amountETH); function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapTokensForExactTokens( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactETHForTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapTokensForExactETH( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactTokensForETH( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapETHForExactTokens( uint256 amountOut, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function quote( uint256 amountA, uint256 reserveA, uint256 reserveB ) external pure returns (uint256 amountB); function getAmountOut( uint256 amountIn, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountOut); function getAmountIn( uint256 amountOut, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountIn); function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts); function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.0; /// @title Callback for IUniswapV3PoolActions#swap /// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface interface IUniswapV3SwapCallback { /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap. /// @dev In the implementation you must pay the pool tokens owed for the swap. /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory. /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped. /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token0 to the pool. /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token1 to the pool. /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call function uniswapV3SwapCallback( int256 amount0Delta, int256 amount1Delta, bytes calldata data ) external; } /// @title Router token swapping functionality /// @notice Functions for swapping tokens via Uniswap V3 interface IUniswapV3Router is IUniswapV3SwapCallback { struct ExactInputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; uint160 sqrtPriceLimitX96; } /// @notice Swaps `amountIn` of one token for as much as possible of another token /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata /// @return amountOut The amount of the received token function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut); struct ExactInputParams { bytes path; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; } /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata /// @return amountOut The amount of the received token function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut); struct ExactOutputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 deadline; uint256 amountOut; uint256 amountInMaximum; uint160 sqrtPriceLimitX96; } /// @notice Swaps as little as possible of one token for `amountOut` of another token /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata /// @return amountIn The amount of the input token function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn); struct ExactOutputParams { bytes path; address recipient; uint256 deadline; uint256 amountOut; uint256 amountInMaximum; } /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed) /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata /// @return amountIn The amount of the input token function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; pragma abicoder v2; import "./AggregatorV2V3Interface.sol"; interface FeedRegistryInterface { struct Phase { uint16 phaseId; uint80 startingAggregatorRoundId; uint80 endingAggregatorRoundId; } event FeedProposed( address indexed asset, address indexed denomination, address indexed proposedAggregator, address currentAggregator, address sender ); event FeedConfirmed( address indexed asset, address indexed denomination, address indexed latestAggregator, address previousAggregator, uint16 nextPhaseId, address sender ); // V3 AggregatorV3Interface function decimals(address base, address quote) external view returns (uint8); function description(address base, address quote) external view returns (string memory); function version(address base, address quote) external view returns (uint256); function latestRoundData(address base, address quote) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function getRoundData( address base, address quote, uint80 _roundId ) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); // V2 AggregatorInterface function latestAnswer(address base, address quote) external view returns (int256 answer); function latestTimestamp(address base, address quote) external view returns (uint256 timestamp); function latestRound(address base, address quote) external view returns (uint256 roundId); function getAnswer( address base, address quote, uint256 roundId ) external view returns (int256 answer); function getTimestamp( address base, address quote, uint256 roundId ) external view returns (uint256 timestamp); // Registry getters function getFeed(address base, address quote) external view returns (AggregatorV2V3Interface aggregator); function getPhaseFeed( address base, address quote, uint16 phaseId ) external view returns (AggregatorV2V3Interface aggregator); function isFeedEnabled(address aggregator) external view returns (bool); function getPhase( address base, address quote, uint16 phaseId ) external view returns (Phase memory phase); // Round helpers function getRoundFeed( address base, address quote, uint80 roundId ) external view returns (AggregatorV2V3Interface aggregator); function getPhaseRange( address base, address quote, uint16 phaseId ) external view returns (uint80 startingRoundId, uint80 endingRoundId); function getPreviousRoundId( address base, address quote, uint80 roundId ) external view returns (uint80 previousRoundId); function getNextRoundId( address base, address quote, uint80 roundId ) external view returns (uint80 nextRoundId); // Feed management function proposeFeed( address base, address quote, address aggregator ) external; function confirmFeed( address base, address quote, address aggregator ) external; // Proposed aggregator function getProposedFeed(address base, address quote) external view returns (AggregatorV2V3Interface proposedAggregator); function proposedGetRoundData( address base, address quote, uint80 roundId ) external view returns ( uint80 id, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function proposedLatestRoundData(address base, address quote) external view returns ( uint80 id, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); // Phases function getCurrentPhaseId(address base, address quote) external view returns (uint16 currentPhaseId); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./AggregatorInterface.sol"; import "./AggregatorV3Interface.sol"; interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface {}
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol"; interface IChainlinkAggregator is AggregatorV2V3Interface { function maxAnswer() external view returns (int192); function minAnswer() external view returns (int192); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; library Denominations { address public constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; address public constant BTC = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB; // Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217 address public constant USD = address(840); address public constant GBP = address(826); address public constant EUR = address(978); address public constant JPY = address(392); address public constant KRW = address(410); address public constant CNY = address(156); address public constant AUD = address(36); address public constant CAD = address(124); address public constant CHF = address(756); address public constant ARS = address(32); address public constant PHP = address(608); address public constant NZD = address(554); address public constant SGD = address(702); address public constant NGN = address(566); address public constant ZAR = address(710); address public constant RUB = address(643); address public constant INR = address(356); address public constant BRL = address(986); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.4.1) (utils/math/SafeCast.sol) pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toUint248(uint256 value) internal pure returns (uint248) { require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits"); return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toUint240(uint256 value) internal pure returns (uint240) { require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits"); return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toUint232(uint256 value) internal pure returns (uint232) { require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits"); return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.2._ */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toUint216(uint256 value) internal pure returns (uint216) { require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits"); return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toUint208(uint256 value) internal pure returns (uint208) { require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits"); return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toUint200(uint256 value) internal pure returns (uint200) { require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits"); return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toUint192(uint256 value) internal pure returns (uint192) { require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits"); return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toUint184(uint256 value) internal pure returns (uint184) { require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits"); return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toUint176(uint256 value) internal pure returns (uint176) { require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits"); return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toUint168(uint256 value) internal pure returns (uint168) { require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits"); return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toUint160(uint256 value) internal pure returns (uint160) { require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits"); return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toUint152(uint256 value) internal pure returns (uint152) { require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits"); return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toUint144(uint256 value) internal pure returns (uint144) { require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits"); return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toUint136(uint256 value) internal pure returns (uint136) { require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits"); return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v2.5._ */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toUint120(uint256 value) internal pure returns (uint120) { require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits"); return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toUint112(uint256 value) internal pure returns (uint112) { require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits"); return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toUint104(uint256 value) internal pure returns (uint104) { require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits"); return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.2._ */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toUint88(uint256 value) internal pure returns (uint88) { require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits"); return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toUint80(uint256 value) internal pure returns (uint80) { require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits"); return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toUint72(uint256 value) internal pure returns (uint72) { require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits"); return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v2.5._ */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toUint56(uint256 value) internal pure returns (uint56) { require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits"); return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toUint48(uint256 value) internal pure returns (uint48) { require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits"); return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toUint40(uint256 value) internal pure returns (uint40) { require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits"); return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v2.5._ */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toUint24(uint256 value) internal pure returns (uint24) { require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits"); return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v2.5._ */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v2.5._ */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. * * _Available since v3.0._ */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toInt248(int256 value) internal pure returns (int248) { require(value >= type(int248).min && value <= type(int248).max, "SafeCast: value doesn't fit in 248 bits"); return int248(value); } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toInt240(int256 value) internal pure returns (int240) { require(value >= type(int240).min && value <= type(int240).max, "SafeCast: value doesn't fit in 240 bits"); return int240(value); } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toInt232(int256 value) internal pure returns (int232) { require(value >= type(int232).min && value <= type(int232).max, "SafeCast: value doesn't fit in 232 bits"); return int232(value); } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.7._ */ function toInt224(int256 value) internal pure returns (int224) { require(value >= type(int224).min && value <= type(int224).max, "SafeCast: value doesn't fit in 224 bits"); return int224(value); } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toInt216(int256 value) internal pure returns (int216) { require(value >= type(int216).min && value <= type(int216).max, "SafeCast: value doesn't fit in 216 bits"); return int216(value); } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toInt208(int256 value) internal pure returns (int208) { require(value >= type(int208).min && value <= type(int208).max, "SafeCast: value doesn't fit in 208 bits"); return int208(value); } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toInt200(int256 value) internal pure returns (int200) { require(value >= type(int200).min && value <= type(int200).max, "SafeCast: value doesn't fit in 200 bits"); return int200(value); } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toInt192(int256 value) internal pure returns (int192) { require(value >= type(int192).min && value <= type(int192).max, "SafeCast: value doesn't fit in 192 bits"); return int192(value); } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toInt184(int256 value) internal pure returns (int184) { require(value >= type(int184).min && value <= type(int184).max, "SafeCast: value doesn't fit in 184 bits"); return int184(value); } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toInt176(int256 value) internal pure returns (int176) { require(value >= type(int176).min && value <= type(int176).max, "SafeCast: value doesn't fit in 176 bits"); return int176(value); } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toInt168(int256 value) internal pure returns (int168) { require(value >= type(int168).min && value <= type(int168).max, "SafeCast: value doesn't fit in 168 bits"); return int168(value); } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toInt160(int256 value) internal pure returns (int160) { require(value >= type(int160).min && value <= type(int160).max, "SafeCast: value doesn't fit in 160 bits"); return int160(value); } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toInt152(int256 value) internal pure returns (int152) { require(value >= type(int152).min && value <= type(int152).max, "SafeCast: value doesn't fit in 152 bits"); return int152(value); } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toInt144(int256 value) internal pure returns (int144) { require(value >= type(int144).min && value <= type(int144).max, "SafeCast: value doesn't fit in 144 bits"); return int144(value); } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toInt136(int256 value) internal pure returns (int136) { require(value >= type(int136).min && value <= type(int136).max, "SafeCast: value doesn't fit in 136 bits"); return int136(value); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128) { require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits"); return int128(value); } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toInt120(int256 value) internal pure returns (int120) { require(value >= type(int120).min && value <= type(int120).max, "SafeCast: value doesn't fit in 120 bits"); return int120(value); } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toInt112(int256 value) internal pure returns (int112) { require(value >= type(int112).min && value <= type(int112).max, "SafeCast: value doesn't fit in 112 bits"); return int112(value); } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toInt104(int256 value) internal pure returns (int104) { require(value >= type(int104).min && value <= type(int104).max, "SafeCast: value doesn't fit in 104 bits"); return int104(value); } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.7._ */ function toInt96(int256 value) internal pure returns (int96) { require(value >= type(int96).min && value <= type(int96).max, "SafeCast: value doesn't fit in 96 bits"); return int96(value); } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toInt88(int256 value) internal pure returns (int88) { require(value >= type(int88).min && value <= type(int88).max, "SafeCast: value doesn't fit in 88 bits"); return int88(value); } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toInt80(int256 value) internal pure returns (int80) { require(value >= type(int80).min && value <= type(int80).max, "SafeCast: value doesn't fit in 80 bits"); return int80(value); } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toInt72(int256 value) internal pure returns (int72) { require(value >= type(int72).min && value <= type(int72).max, "SafeCast: value doesn't fit in 72 bits"); return int72(value); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64) { require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits"); return int64(value); } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toInt56(int256 value) internal pure returns (int56) { require(value >= type(int56).min && value <= type(int56).max, "SafeCast: value doesn't fit in 56 bits"); return int56(value); } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toInt48(int256 value) internal pure returns (int48) { require(value >= type(int48).min && value <= type(int48).max, "SafeCast: value doesn't fit in 48 bits"); return int48(value); } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toInt40(int256 value) internal pure returns (int40) { require(value >= type(int40).min && value <= type(int40).max, "SafeCast: value doesn't fit in 40 bits"); return int40(value); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32) { require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits"); return int32(value); } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toInt24(int256 value) internal pure returns (int24) { require(value >= type(int24).min && value <= type(int24).max, "SafeCast: value doesn't fit in 24 bits"); return int24(value); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16) { require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits"); return int16(value); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8) { require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits"); return int8(value); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. * * _Available since v3.0._ */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/cryptography/draft-EIP712.sol) pragma solidity ^0.8.0; import "./ECDSA.sol"; /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. * * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible, * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding * they need in their contracts using a combination of `abi.encode` and `keccak256`. * * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA * ({_hashTypedDataV4}). * * The implementation of the domain separator was designed to be as efficient as possible while still properly updating * the chain id to protect against replay attacks on an eventual fork of the chain. * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. * * _Available since v3.4._ */ abstract contract EIP712 { /* solhint-disable var-name-mixedcase */ // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to // invalidate the cached domain separator if the chain id changes. bytes32 private immutable _CACHED_DOMAIN_SEPARATOR; uint256 private immutable _CACHED_CHAIN_ID; address private immutable _CACHED_THIS; bytes32 private immutable _HASHED_NAME; bytes32 private immutable _HASHED_VERSION; bytes32 private immutable _TYPE_HASH; /* solhint-enable var-name-mixedcase */ /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ constructor(string memory name, string memory version) { bytes32 hashedName = keccak256(bytes(name)); bytes32 hashedVersion = keccak256(bytes(version)); bytes32 typeHash = keccak256( "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)" ); _HASHED_NAME = hashedName; _HASHED_VERSION = hashedVersion; _CACHED_CHAIN_ID = block.chainid; _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion); _CACHED_THIS = address(this); _TYPE_HASH = typeHash; } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view returns (bytes32) { if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) { return _CACHED_DOMAIN_SEPARATOR; } else { return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION); } } function _buildDomainSeparator( bytes32 typeHash, bytes32 nameHash, bytes32 versionHash ) private view returns (bytes32) { return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this))); } /** * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this * function returns the hash of the fully encoded EIP712 message for this domain. * * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: * * ```solidity * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( * keccak256("Mail(address to,string contents)"), * mailTo, * keccak256(bytes(mailContents)) * ))); * address signer = ECDSA.recover(digest, signature); * ``` */ function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) { return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.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 } 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"); } else if (error == RecoverError.InvalidSignatureV) { revert("ECDSA: invalid signature 'v' 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) { // Check the signature length // - case 65: r,s,v signature (standard) // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._ 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 if (signature.length == 64) { bytes32 r; bytes32 vs; // 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)) vs := mload(add(signature, 0x40)) } return tryRecover(hash, r, vs); } 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 (v != 27 && v != 28) { return (address(0), RecoverError.InvalidSignatureV); } // 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 (utils/Counters.sol) pragma solidity ^0.8.0; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids. * * Include with `using Counters for Counters.Counter;` */ library Counters { struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { unchecked { counter._value += 1; } } function decrement(Counter storage counter) internal { uint256 value = counter._value; require(value > 0, "Counter: decrement overflow"); unchecked { counter._value = value - 1; } } function reset(Counter storage counter) internal { counter._value = 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface AggregatorInterface { function latestAnswer() external view returns (int256); function latestTimestamp() external view returns (uint256); function latestRound() external view returns (uint256); function getAnswer(uint256 roundId) external view returns (int256); function getTimestamp(uint256 roundId) external view returns (uint256); event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt); event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface AggregatorV3Interface { function decimals() external view returns (uint8); function description() external view returns (string memory); function version() external view returns (uint256); // getRoundData and latestRoundData should both raise "No data present" // if they do not have data to report, instead of returning unset values // which could be misinterpreted as actual reported values. function getRoundData(uint80 _roundId) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function latestRoundData() external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_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) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @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] = _HEX_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": [ "@chainlink/=lib/chainlink/", "@ds-test/=lib/forge-std/lib/ds-test/src/", "@ensdomains/=node_modules/@ensdomains/", "@forge-std/=lib/forge-std/src/", "@openzeppelin/=lib/openzeppelin-contracts/", "@solmate/=lib/solmate/src/", "@uniswap/v3-core/=lib/v3-core/", "@uniswap/v3-periphery/=lib/v3-periphery/", "chainlink/=lib/chainlink/", "ds-test/=lib/forge-std/lib/ds-test/src/", "eth-gas-reporter/=node_modules/eth-gas-reporter/", "forge-std/=lib/forge-std/src/", "hardhat/=node_modules/hardhat/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "solmate/=lib/solmate/src/" ], "optimizer": { "enabled": true, "runs": 20 }, "metadata": { "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract Registry","name":"_registry","type":"address"},{"internalType":"contract ERC20","name":"_asset","type":"address"},{"internalType":"address[]","name":"_positions","type":"address[]"},{"internalType":"enum Cellar.PositionType[]","name":"_positionTypes","type":"uint8[]"},{"internalType":"address","name":"_holdingPosition","type":"address"},{"internalType":"enum Cellar.WithdrawType","name":"_withdrawType","type":"uint8"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"address","name":"_strategistPayout","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"expectedAsset","type":"address"}],"name":"Cellar__AssetMismatch","type":"error"},{"inputs":[],"name":"Cellar__ContractNotShutdown","type":"error"},{"inputs":[],"name":"Cellar__ContractShutdown","type":"error"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"maxDeposit","type":"uint256"}],"name":"Cellar__DepositRestricted","type":"error"},{"inputs":[{"internalType":"address","name":"illiquidPosition","type":"address"}],"name":"Cellar__IlliquidWithdraw","type":"error"},{"inputs":[{"internalType":"uint256","name":"assetsOwed","type":"uint256"}],"name":"Cellar__IncompleteWithdraw","type":"error"},{"inputs":[],"name":"Cellar__InvalidCosmosAddress","type":"error"},{"inputs":[],"name":"Cellar__InvalidFee","type":"error"},{"inputs":[],"name":"Cellar__InvalidFeeCut","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"Cellar__InvalidPosition","type":"error"},{"inputs":[{"internalType":"uint256","name":"requested","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"Cellar__InvalidRebalanceDeviation","type":"error"},{"inputs":[],"name":"Cellar__InvalidShareLockPeriod","type":"error"},{"inputs":[{"internalType":"address","name":"depositor","type":"address"}],"name":"Cellar__NotApprovedToDepositOnBehalf","type":"error"},{"inputs":[],"name":"Cellar__PayoutNotSet","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"Cellar__PositionAlreadyUsed","type":"error"},{"inputs":[{"internalType":"uint256","name":"maxPositions","type":"uint256"}],"name":"Cellar__PositionArrayFull","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"},{"internalType":"uint256","name":"sharesRemaining","type":"uint256"}],"name":"Cellar__PositionNotEmpty","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"Cellar__PositionPricingNotSetUp","type":"error"},{"inputs":[],"name":"Cellar__RemoveHoldingPosition","type":"error"},{"inputs":[{"internalType":"uint256","name":"blockSharesAreUnlocked","type":"uint256"},{"internalType":"uint256","name":"currentBlock","type":"uint256"}],"name":"Cellar__SharesAreLocked","type":"error"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"min","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"Cellar__TotalAssetDeviatedOutsideRange","type":"error"},{"inputs":[{"internalType":"uint256","name":"current","type":"uint256"},{"internalType":"uint256","name":"expected","type":"uint256"}],"name":"Cellar__TotalSharesMustRemainConstant","type":"error"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"Cellar__UntrustedPosition","type":"error"},{"inputs":[],"name":"Cellar__WrongSwapParams","type":"error"},{"inputs":[],"name":"Cellar__ZeroAssets","type":"error"},{"inputs":[],"name":"Cellar__ZeroShares","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldLimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"DepositLimitChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"oldFeesDistributor","type":"bytes32"},{"indexed":false,"internalType":"bytes32","name":"newFeesDistributor","type":"bytes32"}],"name":"FeesDistributorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newHighWatermark","type":"uint256"}],"name":"HighWatermarkReset","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldPosition","type":"address"},{"indexed":true,"internalType":"address","name":"newPosition","type":"address"}],"name":"HoldingPositionChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldLimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"LiquidityLimitChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPerformanceFee","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPerformanceFee","type":"uint64"}],"name":"PerformanceFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPlatformFee","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPlatformFee","type":"uint64"}],"name":"PlatformFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"PositionAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"PositionRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldPosition","type":"address"},{"indexed":true,"internalType":"address","name":"newPosition","type":"address"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"PositionReplaced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newPosition1","type":"address"},{"indexed":true,"internalType":"address","name":"newPosition2","type":"address"},{"indexed":false,"internalType":"uint256","name":"index1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"index2","type":"uint256"}],"name":"PositionSwapped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"PulledFromPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"fromPosition","type":"address"},{"indexed":true,"internalType":"address","name":"toPosition","type":"address"},{"indexed":false,"internalType":"uint256","name":"assetsFrom","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assetsTo","type":"uint256"}],"name":"Rebalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldDeviation","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newDeviation","type":"uint256"}],"name":"RebalanceDeviationChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feesInSharesRedeemed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feesInAssetsSent","type":"uint256"}],"name":"SendFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldPeriod","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newPeriod","type":"uint256"}],"name":"ShareLockingPeriodChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isShutdown","type":"bool"}],"name":"ShutdownChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldPayoutAddress","type":"address"},{"indexed":false,"internalType":"address","name":"newPayoutAddress","type":"address"}],"name":"StrategistPayoutAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPerformanceCut","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPerformanceCut","type":"uint64"}],"name":"StrategistPerformanceCutChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPlatformCut","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPlatformCut","type":"uint64"}],"name":"StrategistPlatformCutChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"bool","name":"isTrusted","type":"bool"}],"name":"TrustChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum Cellar.WithdrawType","name":"oldType","type":"uint8"},{"indexed":false,"internalType":"enum Cellar.WithdrawType","name":"newType","type":"uint8"}],"name":"WithdrawTypeChanged","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAXIMUM_SHARE_LOCK_PERIOD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_FEE_CUT","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_PERFORMANCE_FEE","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_PLATFORM_FEE","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_POSITIONS","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_REBALANCE_DEVIATION","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINIMUM_SHARE_LOCK_PERIOD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRICE_ROUTER_REGISTRY_SLOT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"position","type":"address"}],"name":"addPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allowedRebalanceDeviation","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"depositLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"distrustPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeData","outputs":[{"internalType":"uint256","name":"highWatermark","type":"uint256"},{"internalType":"uint64","name":"strategistPerformanceCut","type":"uint64"},{"internalType":"uint64","name":"strategistPlatformCut","type":"uint64"},{"internalType":"uint64","name":"platformFee","type":"uint64"},{"internalType":"uint64","name":"performanceFee","type":"uint64"},{"internalType":"bytes32","name":"feesDistributor","type":"bytes32"},{"internalType":"address","name":"strategistPayoutAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"getPositionType","outputs":[{"internalType":"enum Cellar.PositionType","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPositions","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"holdingPosition","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initiateShutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isPositionUsed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isShutdown","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isTrusted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastAccrual","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liftShutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"liquidityLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"popPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"positions","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"pushPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"fromPosition","type":"address"},{"internalType":"address","name":"toPosition","type":"address"},{"internalType":"uint256","name":"assetsFrom","type":"uint256"},{"internalType":"enum SwapRouter.Exchange","name":"exchange","type":"uint8"},{"internalType":"bytes","name":"params","type":"bytes"}],"name":"rebalance","outputs":[{"internalType":"uint256","name":"assetsTo","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"contract Registry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"removePosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"address","name":"newPosition","type":"address"}],"name":"replacePosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"resetHighWatermark","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sendFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"setDepositLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"newFeesDistributor","type":"bytes32"}],"name":"setFeesDistributor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newHoldingPosition","type":"address"}],"name":"setHoldingPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLimit","type":"uint256"}],"name":"setLiquidityLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"newPerformanceFee","type":"uint64"}],"name":"setPerformanceFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"newPlatformFee","type":"uint64"}],"name":"setPlatformFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newDeviation","type":"uint256"}],"name":"setRebalanceDeviation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLock","type":"uint256"}],"name":"setShareLockPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"payout","type":"address"}],"name":"setStrategistPayoutAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"cut","type":"uint64"}],"name":"setStrategistPerformanceCut","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"cut","type":"uint64"}],"name":"setStrategistPlatformCut","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum Cellar.WithdrawType","name":"newWithdrawType","type":"uint8"}],"name":"setWithdrawType","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shareLockPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index1","type":"uint256"},{"internalType":"uint256","name":"index2","type":"uint256"}],"name":"swapPositions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssetsWithdrawable","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"position","type":"address"},{"internalType":"enum Cellar.PositionType","name":"positionType","type":"uint8"}],"name":"trustPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userShareLockStartBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawType","outputs":[{"internalType":"enum Cellar.WithdrawType","name":"","type":"uint8"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
6102406040526000610160819052670a688906bd8b00006101808190526101a052662386f26fc100006101c05267016345785d8a00006101e05273b813554b423266bbd4c16c32fa383394868c1f55610200819052610220829052600f919091557f016345785d8a0000002386f26fc100000a688906bd8b00000a688906bd8b0000601055601155601280546001600160a01b03191690556000196013819055601455600a601655660aa87bee538000601855348015620000bf57600080fd5b5060405162006e3138038062006e31833981016040819052620000e29162000ab7565b8783838180604051806040016040528060018152602001603160f81b8152508484816003908162000114919062000c58565b50600462000123828262000c58565b5050825160208085019190912083518483012060e08290526101008190524660a0818152604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f81880181905281830187905260608201869052608082019490945230818401528151808203909301835260c0019052805194019390932091935091906080523060c052610120525050600780546001600160a01b0319166001600160a01b03979097169690961790955550620001f29350620001ec925062000619915050565b6200061d565b60016009556001600160a01b0389166101405286516200021a90600a9060208a019062000813565b506000805b88518110156200046057600089828151811062000240576200024062000d24565b6020908102919091018101516001600160a01b0381166000908152600b90925260409091205490915060ff16156200029b57604051630af67d9160e31b81526001600160a01b03821660048201526024015b60405180910390fd5b6001600160a01b0381166000908152600d602090815260408083208054600160ff199182168117909255600b9093529220805490911690911790558851899083908110620002ed57620002ed62000d24565b6020908102919091018101516001600160a01b0383166000908152600c9092526040909120805460ff191660018360028111156200032f576200032f62000d3a565b02179055506200033f816200066f565b61014051604051635c9fcd8560e11b8152600260048201529194506001600160a01b03169063b93f9b0a90602401602060405180830381865afa1580156200038b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003b1919062000d50565b604051634f129c5360e01b81526001600160a01b0385811660048301529190911690634f129c5390602401602060405180830381865afa158015620003fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000420919062000d70565b6200044a57604051637eb56edb60e11b81526001600160a01b038416600482015260240162000292565b5080620004578162000d94565b9150506200021f565b506001600160a01b0386166000908152600b602052604090205460ff16620004a757604051631ec7bcd360e01b81526001600160a01b038716600482015260240162000292565b6000620004b4876200066f565b9050896001600160a01b0316816001600160a01b031614620004fd5760405163298473c760e11b81526001600160a01b0380831660048301528b16602482015260440162000292565b600e8054610100600160a81b031981166101006001600160a01b038b160290811783558892916001600160a81b03191660ff1990911617600183818111156200054a576200054a62000d3a565b0217905550600e8054600160a81b600160e81b031916600160a81b426001600160401b031602179055601280546001600160a01b0319166001600160a01b0385811691909117909155604051635c9fcd8560e11b8152600060048201819052918d169063b93f9b0a90602401602060405180830381865afa158015620005d4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620005fa919062000d50565b9050620006078162000742565b50505050505050505050505062000dbc565b3390565b600880546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6001600160a01b0381166000908152600c602052604081205460ff166001816002811115620006a257620006a262000d3a565b1480620006c357506002816002811115620006c157620006c162000d3a565b145b156200073557826001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000708573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200072e919062000d50565b9392505050565b5090919050565b50919050565b6008546001600160a01b031633146200079e5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640162000292565b6001600160a01b038116620008055760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b606482015260840162000292565b62000810816200061d565b50565b8280548282559060005260206000209081019282156200086b579160200282015b828111156200086b57825182546001600160a01b0319166001600160a01b0390911617825560209092019160019091019062000834565b50620008799291506200087d565b5090565b5b808211156200087957600081556001016200087e565b6001600160a01b03811681146200081057600080fd5b8051620008b78162000894565b919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715620008fd57620008fd620008bc565b604052919050565b60006001600160401b03821115620009215762000921620008bc565b5060051b60200190565b600082601f8301126200093d57600080fd5b8151602062000956620009508362000905565b620008d2565b82815260059290921b840181019181810190868411156200097657600080fd5b8286015b848110156200099e578051620009908162000894565b83529183019183016200097a565b509695505050505050565b600082601f830112620009bb57600080fd5b81516020620009ce620009508362000905565b82815260059290921b84018101918181019086841115620009ee57600080fd5b8286015b848110156200099e5780516003811062000a0c5760008081fd5b8352918301918301620009f2565b805160028110620008b757600080fd5b600082601f83011262000a3c57600080fd5b81516001600160401b0381111562000a585762000a58620008bc565b602062000a6e601f8301601f19168201620008d2565b828152858284870101111562000a8357600080fd5b60005b8381101562000aa357858101830151828201840152820162000a86565b506000928101909101919091529392505050565b60008060008060008060008060006101208a8c03121562000ad757600080fd5b62000ae28a620008aa565b985062000af260208b01620008aa565b60408b01519098506001600160401b038082111562000b1057600080fd5b62000b1e8d838e016200092b565b985060608c015191508082111562000b3557600080fd5b62000b438d838e01620009a9565b975062000b5360808d01620008aa565b965062000b6360a08d0162000a1a565b955060c08c015191508082111562000b7a57600080fd5b62000b888d838e0162000a2a565b945060e08c015191508082111562000b9f57600080fd5b5062000bae8c828d0162000a2a565b92505062000bc06101008b01620008aa565b90509295985092959850929598565b600181811c9082168062000be457607f821691505b6020821081036200073c57634e487b7160e01b600052602260045260246000fd5b601f82111562000c5357600081815260208120601f850160051c8101602086101562000c2e5750805b601f850160051c820191505b8181101562000c4f5782815560010162000c3a565b5050505b505050565b81516001600160401b0381111562000c745762000c74620008bc565b62000c8c8162000c85845462000bcf565b8462000c05565b602080601f83116001811462000cc4576000841562000cab5750858301515b600019600386901b1c1916600185901b17855562000c4f565b600085815260208120601f198616915b8281101562000cf55788860151825594840194600190910190840162000cd4565b508582101562000d145787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052602160045260246000fd5b60006020828403121562000d6357600080fd5b81516200072e8162000894565b60006020828403121562000d8357600080fd5b815180151581146200072e57600080fd5b60006001820162000db557634e487b7160e01b600052601160045260246000fd5b5060010190565b60805160a05160c05160e051610100516101205161014051615fe962000e486000396000818161064f01528181610bbc01528181612e8f0152818161313f01528181613ca4015281816141d6015281816147b40152614b6601526000613a7301526000613ac201526000613a9d015260006139f601526000613a2001526000613a4a0152615fe96000f3fe608060405234801561001057600080fd5b50600436106103e05760003560e01c806395d89b411161020d578063c046742211610121578063c046742214610878578063c244245a1461088b578063c63d75b614610894578063c6e6f592146108a7578063c85e5e13146108ba578063ce96cb77146108c2578063d505accf146108d5578063d905777e146108e8578063dd62ed3e146108fb578063df05a52a1461090e578063dff90b5b14610921578063e39448e014610929578063e753e60014610943578063ecf70858146109da578063eef33eca146109e3578063ef8b30f7146109f2578063f2fde38b14610a05578063f7b24e0814610a18578063fc44459114610a20578063fc4d43be14610a40578063fdd230b914610a5357600080fd5b806395d89b41146106e157806396a0f591146106e957806396d64879146106fc57806399fbab881461071f5780639b6fd18e146107325780639c552ca8146107455780639c5f00c2146107585780639e35c65b146107705780639fdb11b6146107a0578063a457c2d7146107a9578063a8144e48146107bc578063a9059cbb146107c4578063b0a75d36146107d7578063b3d7f6b9146107ea578063b460af94146107fd578063b5292a9914610810578063ba08765214610823578063bd83721a14610836578063bdc8144b14610849578063bdca91651461085c578063bf86d6901461086b57600080fd5b8063472090fe11610304578063472090fe1461055f5780634cdad506146105825780634eca8a8314610595578063530a3714146105a857806358384573146105bb5780635a400d25146105ce5780635e2c576e146105d65780636e553f65146105de5780636e85f183146105f15780636ff1c02a1461060457806370a082311461061357806370af7df614610626578063715018a61461063957806372163715146106415780637b1039991461064a5780637b3baab4146106715780637ecebe001461068b578063802758601461069e5780638b0cebf7146106b35780638da5cb5b146106c657806394bf804d146106ce57600080fd5b806251a3b7146103e557806301e1d114146104005780630402ab631461040857806306fdde031461041157806307a2d13a14610426578063095ea7b3146104395780630a28a4771461045c5780630a680e181461046f57806318160ddd1461047957806323b872dd146104815780632f3b5a13146104945780633076fdc5146104a7578063313ce567146104af5780633644e515146104c4578063389a7294146104cc57806338d52e0f146104df57806339509351146104ff5780633998a681146105125780633cf99a4614610539578063402d267d1461054c575b600080fd5b6103ed600881565b6040519081526020015b60405180910390f35b6103ed610a66565b6103ed61010081565b610419610cb2565b6040516103f791906156e5565b6103ed610434366004615718565b610d44565b61044c610447366004615746565b610d5d565b60405190151581526020016103f7565b6103ed61046a366004615718565b610d75565b610477610daa565b005b6002546103ed565b61044c61048f366004615772565b610e4c565b6104776104a23660046157c0565b610e72565b610477610f08565b60125b60405160ff90911681526020016103f7565b6103ed610f39565b6103ed6104da3660046157dd565b610f48565b6007546104f2906001600160a01b031681565b6040516103f7919061588f565b61044c61050d366004615746565b6111a2565b6105216702c68af0bb14000081565b6040516001600160401b0390911681526020016103f7565b6104776105473660046158a3565b6111c4565b6103ed61055a3660046158cc565b61129a565b61044c61056d3660046158cc565b600b6020526000908152604090205460ff1681565b6103ed610590366004615718565b61132c565b6104776105a33660046158e9565b611354565b6104776105b6366004615718565b6114b1565b6104776105c9366004615919565b611560565b6103ed600281565b6104776116ac565b6103ed6105ec3660046158e9565b611739565b6104776105ff366004615718565b611835565b61052167016345785d8a000081565b6103ed6106213660046158cc565b6118cc565b6104776106343660046158a3565b6118e7565b6104776119c2565b6103ed60135481565b6104f27f000000000000000000000000000000000000000000000000000000000000000081565b600e5461052190600160a81b90046001600160401b031681565b6103ed6106993660046158cc565b6119fb565b6106a6611a19565b6040516103f7919061593b565b6104776106c13660046158cc565b611a7a565b6104f2611b99565b6103ed6106dc3660046158e9565b611ba8565b610419611c98565b6104776106f73660046158e9565b611ca7565b61044c61070a3660046158cc565b600d6020526000908152604090205460ff1681565b6104f261072d366004615718565b611e99565b6104776107403660046158a3565b611ec3565b610477610753366004615718565b611f8e565b600e546104f29061010090046001600160a01b031681565b61079361077e3660046158cc565b600c6020526000908152604090205460ff1681565b6040516103f7919061599e565b6103ed60165481565b61044c6107b7366004615746565b612025565b6103ed6120ab565b61044c6107d2366004615746565b6121e7565b6104776107e53660046158cc565b6121f5565b6103ed6107f8366004615718565b61228d565b6103ed61080b3660046159b8565b6122ba565b61047761081e3660046158a3565b6123e6565b6103ed6108313660046159b8565b6124c1565b6104776108443660046158cc565b6125f6565b610477610857366004615718565b612628565b6105216706f05b59d3b2000081565b60155461044c9060ff1681565b610477610886366004615718565b612697565b6103ed60185481565b6103ed6108a23660046158cc565b6127bd565b6103ed6108b5366004615718565b612846565b610477612859565b6103ed6108d03660046158cc565b6128d0565b6104776108e3366004615a09565b612a99565b6103ed6108f63660046158cc565b612bfd565b6103ed610909366004615a7a565b612c08565b61047761091c366004615718565b612c33565b610477612ca2565b600e546109369060ff1681565b6040516103f79190615ab8565b600f5460105460115460125461098b93926001600160401b0380821693600160401b8304821693600160801b8404831693600160c01b9004909216916001600160a01b031687565b604080519788526001600160401b039687166020890152948616948701949094529184166060860152909216608084015260a08301919091526001600160a01b031660c082015260e0016103f7565b6103ed60145481565b610521670de0b6b3a764000081565b6103ed610a00366004615718565b612fd7565b610477610a133660046158cc565b612fff565b6104b2602081565b6103ed610a2e3660046158cc565b60176020526000908152604090205481565b610477610a4e366004615ac5565b61309c565b610477610a613660046158cc565b613279565b600a5460009081816001600160401b03811115610a8557610a85615af7565b604051908082528060200260200182016040528015610aae578160200160208202803683370190505b5090506000826001600160401b03811115610acb57610acb615af7565b604051908082528060200260200182016040528015610af4578160200160208202803683370190505b50905060005b83811015610ba2576000600a8281548110610b1757610b17615b0d565b6000918252602090912001546001600160a01b03169050610b37816132cc565b848381518110610b4957610b49615b0d565b60200260200101906001600160a01b031690816001600160a01b031681525050610b728161338d565b838381518110610b8457610b84615b0d565b60209081029190910101525080610b9a81615b39565b915050610afa565b50604051635c9fcd8560e11b8152600260048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015610c0b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2f9190615b52565b60075460405163b333a17560e01b81529192506001600160a01b038084169263b333a17592610c68928892889290911690600401615b6f565b602060405180830381865afa158015610c85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca99190615c01565b94505050505090565b606060038054610cc190615c1a565b80601f0160208091040260200160405190810160405280929190818152602001828054610ced90615c1a565b8015610d3a5780601f10610d0f57610100808354040283529160200191610d3a565b820191906000526020600020905b815481529060010190602001808311610d1d57829003601f168201915b5050505050905090565b6000610d5782610d52610a66565b6134df565b92915050565b600033610d6b818585613587565b5060019392505050565b600080610d80610a66565b90506000610d8d826136ab565b9050610da284610d9d8385615c4e565b613711565b949350505050565b60155460ff1615610dce576040516337a5332d60e11b815260040160405180910390fd5b33610dd7611b99565b6001600160a01b031614610e065760405162461bcd60e51b8152600401610dfd90615c61565b60405180910390fd5b6015805460ff191660019081179091556040519081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c906020015b60405180910390a1565b600033610e5a8582856137a8565b610e65858585613822565b60019150505b9392505050565b33610e7b611b99565b6001600160a01b031614610ea15760405162461bcd60e51b8152600401610dfd90615c61565b600e546040517f19365927bf52f7e956d376b3546402dda3827c062c7a6942431a255d212947e891610eda9160ff909116908490615c96565b60405180910390a1600e805482919060ff191660018381811115610f0057610f00615988565b021790555050565b33610f11611b99565b6001600160a01b031614610f375760405162461bcd60e51b8152600401610dfd90615c61565b565b6000610f436139e9565b905090565b600033610f53611b99565b6001600160a01b031614610f795760405162461bcd60e51b8152600401610dfd90615c61565b60155460ff1615610f9d576040516337a5332d60e11b815260040160405180910390fd5b600260095403610fbf5760405162461bcd60e51b8152600401610dfd90615cbc565b60026009556001600160a01b0386166000908152600b602052604090205460ff16610fff5785604051631ec7bcd360e01b8152600401610dfd919061588f565b6000611009610a66565b9050600061101660025490565b9050611023898830613b10565b600061102e8a6132cc565b9050600061103b8a6132cc565b9050806001600160a01b0316826001600160a01b03160361105c578861106b565b61106b82828b8b8b8b30613c05565b94506110778a86613e39565b60006110a2601854670de0b6b3a76400006110929190615c4e565b8690670de0b6b3a7640000613f78565b905060006110cf601854670de0b6b3a76400006110bf9190615cf3565b8790670de0b6b3a7640000613fa6565b90506110d9610a66565b9550808611806110e857508186105b156111175760405163628cc47560e11b8152600481018790526024810183905260448101829052606401610dfd565b600254851461113f5760025485604051632b40145960e21b8152600401610dfd929190615d06565b8b6001600160a01b03168d6001600160a01b03167ffea7a9a6e25cd0bbbfa80ce0c7646e61ee5e0551b3fdaaff0642e6f6adcc72e28d8a604051611184929190615d06565b60405180910390a35050600160095550929998505050505050505050565b600033610d6b8185856111b58383612c08565b6111bf9190615cf3565b613587565b336111cd611b99565b6001600160a01b0316146111f35760405162461bcd60e51b8152600401610dfd90615c61565b6706f05b59d3b200006001600160401b038216111561122557604051632e15286d60e11b815260040160405180910390fd5b6010546040517f27dd3ae8ff7f5e3d77ae68ed36dc780d2ab40a4ffdda18d805cb41eea39c28949161126a91600160c01b9091046001600160401b0316908490615d14565b60405180910390a1601080546001600160401b03909216600160c01b026001600160c01b03909216919091179055565b60155460009060ff16156112b057506000919050565b601454601354600019821480156112c8575060001981145b156112d857506000199392505050565b60006112e2610a66565b905060006112f86112f2876118cc565b836134df565b905060006113068583613fc5565b905060006113148585613fc5565b90506113208282613fdf565b98975050505050505050565b600080611337610a66565b90506000611344826136ab565b9050610da284610d528385615c4e565b3361135d611b99565b6001600160a01b0316146113835760405162461bcd60e51b8152600401610dfd90615c61565b60155460ff16156113a7576040516337a5332d60e11b815260040160405180910390fd5b600a546020116113cd5760405163f025236d60e01b815260206004820152602401610dfd565b6001600160a01b0381166000908152600d602052604090205460ff16611408578060405163699f66b160e11b8152600401610dfd919061588f565b6001600160a01b0381166000908152600b602052604090205460ff16156114445780604051630af67d9160e31b8152600401610dfd919061588f565b611450600a8383613fee565b6001600160a01b0381166000818152600b602052604090819020805460ff19166001179055517fcff5c8a08884d2fad939a9e0f0bf729a4f9af6111a573b4d1f11396c8711646d906114a59085815260200190565b60405180910390a25050565b336114ba611b99565b6001600160a01b0316146114e05760405162461bcd60e51b8152600401610dfd90615c61565b67016345785d8a000081111561151a576040516302d2a90f60e51b81526004810182905267016345785d8a00006024820152604401610dfd565b60188054908290556040517fdf4be33b2e9e3dd4d9e0e85645aea428494a0644a72c51d6a15aedae6b66a3ff906115549083908590615d06565b60405180910390a15050565b33611569611b99565b6001600160a01b03161461158f5760405162461bcd60e51b8152600401610dfd90615c61565b6000600a82815481106115a4576115a4615b0d565b6000918252602082200154600a80546001600160a01b03909216935090859081106115d1576115d1615b0d565b9060005260206000200160009054906101000a90046001600160a01b031690508181600a868154811061160657611606615b0d565b906000526020600020016000600a878154811061162557611625615b0d565b600091825260209091200180546001600160a01b0319166001600160a01b0394851617905581546101009190910a808402199091169383160292909217909155604051828216918416907f3cae4f5796f9d19fa1dcfaacae5a9811c008f6f517a3ec689d903d6f699e49559061169e9088908890615d06565b60405180910390a350505050565b336116b5611b99565b6001600160a01b0316146116db5760405162461bcd60e51b8152600401610dfd90615c61565b60155460ff166116fe5760405163ec7165bf60e01b815260040160405180910390fd5b6015805460ff19169055604051600081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c90602001610e42565b600060026009540361175d5760405162461bcd60e51b8152600401610dfd90615cbc565b6002600955600061176c610a66565b90506117778161412f565b611781848261416c565b9150816000036117a45760405163426f153760e11b815260040160405180910390fd5b6117af84838561418b565b6007546117c7906001600160a01b03163330876142bd565b6117d18383614328565b826001600160a01b0316336001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78685604051611816929190615d06565b60405180910390a3611829848385614401565b50600160095592915050565b3361183e611b99565b6001600160a01b0316146118645760405162461bcd60e51b8152600401610dfd90615c61565b6001600160a01b0381111561188c5760405163019b5e3160e21b815260040160405180910390fd5b6011546040517f513ac19cbbaaad4e450c732ed37635178b7d83bf8e84a940ffe7e052c9c7caa2916118bf918490615d06565b60405180910390a1601155565b6001600160a01b031660009081526020819052604090205490565b336118f0611b99565b6001600160a01b0316146119165760405162461bcd60e51b8152600401610dfd90615c61565b6702c68af0bb1400006001600160401b038216111561194857604051632e15286d60e11b815260040160405180910390fd5b6010546040517f44ada261ff5c9aacbf8d0687294799c8e3e0810ecc1eafd97419dfc31db5d5239161198d91600160801b9091046001600160401b0316908490615d14565b60405180910390a1601080546001600160401b03909216600160801b0267ffffffffffffffff60801b19909216919091179055565b336119cb611b99565b6001600160a01b0316146119f15760405162461bcd60e51b8152600401610dfd90615c61565b610f37600061443a565b6001600160a01b038116600090815260056020526040812054610d57565b6060600a805480602002602001604051908101604052809291908181526020018280548015610d3a57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611a53575050505050905090565b33611a83611b99565b6001600160a01b031614611aa95760405162461bcd60e51b8152600401610dfd90615c61565b6001600160a01b0381166000908152600b602052604090205460ff16611ae45780604051631ec7bcd360e01b8152600401610dfd919061588f565b6000611aef826132cc565b6007549091506001600160a01b03808316911614611b315760075460405163298473c760e11b8152610dfd9183916001600160a01b0390911690600401615d2e565b600e546040516001600160a01b0380851692610100900416907f7f835fbf43c4d05a9c4ea5cafa09fbb3b0307d12956ceedce43fd7a339e5046e90600090a350600e80546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b6008546001600160a01b031690565b6000600260095403611bcc5760405162461bcd60e51b8152600401610dfd90615cbc565b60026009556000611bdb610a66565b9050611be68161412f565b611bf0848261448c565b915081600003611c1357604051639768300560e01b815260040160405180910390fd5b611c1e82858561418b565b600754611c36906001600160a01b03163330856142bd565b611c408385614328565b826001600160a01b0316336001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78487604051611c85929190615d06565b60405180910390a3611829828585614401565b606060048054610cc190615c1a565b33611cb0611b99565b6001600160a01b031614611cd65760405162461bcd60e51b8152600401610dfd90615c61565b60155460ff1615611cfa576040516337a5332d60e11b815260040160405180910390fd5b6001600160a01b0381166000908152600d602052604090205460ff16611d35578060405163699f66b160e11b8152600401610dfd919061588f565b6001600160a01b0381166000908152600b602052604090205460ff1615611d715780604051630af67d9160e31b8152600401610dfd919061588f565b6000600a8381548110611d8657611d86615b0d565b60009182526020822001546001600160a01b03169150611da58261338d565b90508015611dca578181604051638454689f60e01b8152600401610dfd929190615d48565b600e546001600160a01b03610100909104811690831603611dfe5760405163747795ff60e11b815260040160405180910390fd5b82600a8581548110611e1257611e12615b0d565b600091825260208083209190910180546001600160a01b0319166001600160a01b03948516179055848316808352600b82526040808420805460ff1990811690915594881680855293819020805490951660011790945592518781529192917fbc86f8061de00ffd666cfe05f6607130d211483a428a9d8961ecf9544fa836b4910161169e565b600a8181548110611ea957600080fd5b6000918252602090912001546001600160a01b0316905081565b33611ecc611b99565b6001600160a01b031614611ef25760405162461bcd60e51b8152600401610dfd90615c61565b670de0b6b3a76400006001600160401b0382161115611f2457604051633d0203e560e01b815260040160405180910390fd5b6010546040517fc79399093f73f1ff8c2f8279aa9e8803b694c60016c344ecfc2a89fd77c004db91611f63916001600160401b03909116908490615d14565b60405180910390a16010805467ffffffffffffffff19166001600160401b0392909216919091179055565b33611f97611b99565b6001600160a01b031614611fbd5760405162461bcd60e51b8152600401610dfd90615c61565b6008811080611fcd575061010081115b15611feb57604051633a60233f60e21b815260040160405180910390fd5b60168054908290556040517f227ff5c6b5ffb395236b09fd1b472bb128b36eaa17556633feefe28e94411f24906115549083908590615d06565b600033816120338286612c08565b9050838110156120935760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610dfd565b6120a08286868403613587565b506001949350505050565b600a5460009081816001600160401b038111156120ca576120ca615af7565b6040519080825280602002602001820160405280156120f3578160200160208202803683370190505b5090506000826001600160401b0381111561211057612110615af7565b604051908082528060200260200182016040528015612139578160200160208202803683370190505b50905060005b83811015610ba2576000600a828154811061215c5761215c615b0d565b6000918252602090912001546001600160a01b0316905061217c816132cc565b84838151811061218e5761218e615b0d565b60200260200101906001600160a01b031690816001600160a01b0316815250506121b7816144ab565b8383815181106121c9576121c9615b0d565b602090810291909101015250806121df81615b39565b91505061213f565b600033610d6b818585613822565b336121fe611b99565b6001600160a01b0316146122245760405162461bcd60e51b8152600401610dfd90615c61565b6012546040517f51dbb5a65bb22737861a63ec12ba6ce78a98631e9404b0567a2eaf7a06fc544d91612263916001600160a01b03909116908490615d2e565b60405180910390a1601280546001600160a01b0319166001600160a01b0392909216919091179055565b600080612298610a66565b905060006122a5826136ab565b9050610da2846122b58385615c4e565b61448c565b60006002600954036122de5760405162461bcd60e51b8152600401610dfd90615cbc565b60026009556000808080806122f1614529565b945094509450945094506123048561412f565b61230e8986613711565b955061231c89878a8a6148ac565b61232687876148db565b600061233160025490565b905061233d88886148f6565b876001600160a01b0316896001600160a01b0316336001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8d8b60405161238c929190615d06565b60405180910390a46000600e5460ff1660018111156123ad576123ad615988565b146123c5576123c087828b888787614a3e565b6123d3565b6123d38a8a87878787614b4d565b5050600160095550929695505050505050565b336123ef611b99565b6001600160a01b0316146124155760405162461bcd60e51b8152600401610dfd90615c61565b670de0b6b3a76400006001600160401b038216111561244757604051633d0203e560e01b815260040160405180910390fd5b6010546040517fb5cc994a260a85a42d6588668221571ae0a14f0a28f9e4817a5195262102c8689161248c91600160401b9091046001600160401b0316908490615d14565b60405180910390a1601080546001600160401b03909216600160401b0267ffffffffffffffff60401b19909216919091179055565b60006002600954036124e55760405162461bcd60e51b8152600401610dfd90615cbc565b60026009556000808080806124f8614529565b9450945094509450945061250b8561412f565b612515878a6148db565b61251f89866134df565b95508560000361254257604051639768300560e01b815260040160405180910390fd5b61254e868a8a8a6148ac565b600061255960025490565b9050612565888b6148f6565b876001600160a01b0316896001600160a01b0316336001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8a8e6040516125b4929190615d06565b60405180910390a46000600e5460ff1660018111156125d5576125d5615988565b146125e8576123c08a828b888787614a3e565b6123c0878a87878787614b4d565b336125ff611b99565b6001600160a01b0316146126255760405162461bcd60e51b8152600401610dfd90615c61565b50565b33612631611b99565b6001600160a01b0316146126575760405162461bcd60e51b8152600401610dfd90615c61565b7fcfb5a454b8aa7dc04ecb5bc1410b2a57969ca1d67f66d565196f60c6f99754046014548260405161268a929190615d06565b60405180910390a1601455565b336126a0611b99565b6001600160a01b0316146126c65760405162461bcd60e51b8152600401610dfd90615c61565b6000600a82815481106126db576126db615b0d565b60009182526020822001546001600160a01b031691506126fa8261338d565b9050801561271f578181604051638454689f60e01b8152600401610dfd929190615d48565b600e546001600160a01b036101009091048116908316036127535760405163747795ff60e11b815260040160405180910390fd5b61275e600a84614e63565b6001600160a01b0382166000818152600b602052604090819020805460ff19169055517f03c78e4e20a72b1f577a63b54524c684ce73d2e414970ee606bb0b7a9004aa9c906127b09086815260200190565b60405180910390a2505050565b60155460009060ff16156127d357506000919050565b601454601354600019821480156127eb575060001981145b156127fb57506000199392505050565b6000612805610a66565b905060006128156112f2876118cc565b905060006128238583613fc5565b905060006128318585613fc5565b90506113206128408383613fdf565b8561416c565b6000610d5782612854610a66565b61416c565b33612862611b99565b6001600160a01b0316146128885760405162461bcd60e51b8152600401610dfd90615c61565b6000612892610a66565b600f8190556040518181529091507f875561ddc342b12981103d85be8db6375a88982d4cf58d411e38715ae46833309060200160405180910390a150565b6000806128db610a66565b905060006128e8826136ab565b905060006129026128f8866118cc565b610d528486615c4e565b90506000600e5460ff16600181111561291d5761291d615988565b0361294857600061292c6120ab565b90508082111561293c578061293e565b815b9695505050505050565b600080612953614529565b94509450505050600061296560025490565b90506000612972896118cc565b9050670de0b6b3a764000060005b8451811015612a505785818151811061299b5761299b615b0d565b602002602001015160000315612a3e578481815181106129bd576129bd615b0d565b60200260200101516000036129dd575060009a9950505050505050505050565b6000612a2e670de0b6b3a76400008884815181106129fd576129fd615b0d565b6020026020010151888581518110612a1757612a17615b0d565b6020026020010151613fa69092919063ffffffff16565b905082811015612a3c578092505b505b80612a4881615b39565b915050612980565b506000612a6683670de0b6b3a764000086613fa6565b905081811115612a8857612a838983670de0b6b3a7640000613fa6565b612a8a565b865b9b9a5050505050505050505050565b83421115612ae95760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606401610dfd565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9888888612b188c614f7d565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506000612b7382614fa3565b90506000612b8382878787614ff1565b9050896001600160a01b0316816001600160a01b031614612be65760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606401610dfd565b612bf18a8a8a613587565b50505050505050505050565b6000610d57826118cc565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b33612c3c611b99565b6001600160a01b031614612c625760405162461bcd60e51b8152600401610dfd90615c61565b7f1f21432dd7b8ead64d2e7c06a74baf13783b2d2f7153f099e2c4cabc3c5dbec660135482604051612c95929190615d06565b60405180910390a1601355565b600260095403612cc45760405162461bcd60e51b8152600401610dfd90615cbc565b60026009556012546001600160a01b031680612cf35760405163dc13611360e01b815260040160405180910390fd5b6000612cfd610a66565b9050612d088161412f565b6000612d13306118cc565b601054909150600090612d309083906001600160401b0316615019565b600e54909150600090612d5390600160a81b90046001600160401b031642615c4e565b6010549091506000906301e1338090670de0b6b3a764000090600160801b90046001600160401b0316612d868589615d61565b612d909190615d61565b612d9a9190615d80565b612da49190615d80565b90506000612dba612db5838861416c565b61502e565b9050612dc63082614328565b612dd08186615cf3565b601054909550612df1908290600160401b90046001600160401b0316615019565b612dfb9085615cf3565b93508315612e1b57612e0e308886613822565b612e188486615c4e565b94505b600e805467ffffffffffffffff60a81b19164263ffffffff16600160a81b021790556000612e4986886134df565b90508015612f8f5780600f6000016000828254612e669190615c4e565b90915550612e76905030876148f6565b604051635c9fcd8560e11b8152600060048201819052907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015612ede573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f029190615b52565b600754909150612f1c906001600160a01b0316828461505d565b600754601154604051631ffbe7f960e01b81526001600160a01b03928316600482015260248101919091526044810184905290821690631ffbe7f990606401600060405180830381600087803b158015612f7557600080fd5b505af1158015612f89573d6000803e3d6000fd5b50505050505b7f15e3e2a76a6839c244c1ed0a821c233ce8af552dffcb856089eae6cbbbb71ea68682604051612fc0929190615d06565b60405180910390a150506001600955505050505050565b600080612fe2610a66565b90506000612fef826136ab565b9050610da2846128548385615c4e565b33613008611b99565b6001600160a01b03161461302e5760405162461bcd60e51b8152600401610dfd90615c61565b6001600160a01b0381166130935760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dfd565b6126258161443a565b336130a5611b99565b6001600160a01b0316146130cb5760405162461bcd60e51b8152600401610dfd90615c61565b6001600160a01b0382166000908152600d602090815260408083208054600160ff199182168117909255600c9093529220805484939192169083600281111561311657613116615988565b02179055506000613126836132cc565b604051635c9fcd8560e11b8152600260048201529091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b93f9b0a90602401602060405180830381865afa15801561318e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131b29190615b52565b6001600160a01b0316634f129c53826040518263ffffffff1660e01b81526004016131dd919061588f565b602060405180830381865afa1580156131fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061321e9190615da2565b61323d5780604051637eb56edb60e11b8152600401610dfd919061588f565b604051600181526001600160a01b038416907fd600b9348603c6deff34b4e0b28b60e1c8036c806741b9e6d90032e7f37dd27f906020016127b0565b33613282611b99565b6001600160a01b0316146132a85760405162461bcd60e51b8152600401610dfd90615c61565b60155460ff1615612625576040516337a5332d60e11b815260040160405180910390fd5b6001600160a01b0381166000908152600c602052604081205460ff1660018160028111156132fc576132fc615988565b14806133195750600281600281111561331757613317615988565b145b1561338057826001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561335c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6b9190615b52565b5090919050565b50919050565b6001600160a01b0381166000908152600c602052604081205460ff1660018160028111156133bd576133bd615988565b14806133da575060028160028111156133d8576133d8615988565b145b156134b3576040516370a0823160e01b81526001600160a01b03841690634cdad5069082906370a082319061341390309060040161588f565b602060405180830381865afa158015613430573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134549190615c01565b6040518263ffffffff1660e01b815260040161347291815260200190565b602060405180830381865afa15801561348f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6b9190615c01565b6040516370a0823160e01b81526001600160a01b038416906370a082319061347290309060040161588f565b6000806134eb60025490565b90508015613503576134fe848483613fa6565b610da2565b610da26012600760009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561355b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061357f9190615dc4565b869190615160565b6001600160a01b0383166135e95760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610dfd565b6001600160a01b03821661364a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610dfd565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b601054600090600160c01b90046001600160401b03168015806136cc575082155b156136da5750600092915050565b600f548084111561370a5760006136f18286615c4e565b9050613706816001600160401b038516615019565b9350505b5050919050565b60008061371d60025490565b90508015613730576134fe848285613f78565b6007546040805163313ce56760e01b81529051610da2926001600160a01b03169163313ce5679160048083019260209291908290030181865afa15801561377b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061379f9190615dc4565b85906012615160565b60006137b48484612c08565b9050600019811461381c578181101561380f5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610dfd565b61381c8484848403613587565b50505050565b6001600160a01b0383166138865760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610dfd565b6001600160a01b0382166138e85760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610dfd565b6138f38383836151c9565b6001600160a01b0383166000908152602081905260409020548181101561396b5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610dfd565b6001600160a01b038085166000908152602081905260408082208585039055918516815290812080548492906139a2908490615cf3565b92505081905550826001600160a01b0316846001600160a01b0316600080516020615f94833981519152846040516139dc91815260200190565b60405180910390a361381c565b6000306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148015613a4257507f000000000000000000000000000000000000000000000000000000000000000046145b15613a6c57507f000000000000000000000000000000000000000000000000000000000000000090565b50604080517f00000000000000000000000000000000000000000000000000000000000000006020808301919091527f0000000000000000000000000000000000000000000000000000000000000000828401527f000000000000000000000000000000000000000000000000000000000000000060608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b6001600160a01b0383166000908152600c602052604090205460ff166001816002811115613b4057613b40615988565b1480613b5d57506002816002811115613b5b57613b5b615988565b145b15613be157604051632d182be560e21b8152600481018490526001600160a01b03838116602483015230604483015285169063b460af94906064016020604051808303816000875af1158015613bb7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613bdb9190615c01565b5061381c565b6001600160a01b038216301461381c5761381c6001600160a01b03851683856151d2565b60008086896001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613c35919061588f565b602060405180830381865afa158015613c52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c769190615c01565b613c809190615c4e565b604051635c9fcd8560e11b8152600160048201529091506000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063b93f9b0a90602401602060405180830381865afa158015613ceb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d0f9190615b52565b9050613d256001600160a01b038b16828a61505d565b806001600160a01b0316632dfe1690888888888f8f6040518763ffffffff1660e01b8152600401613d5b96959493929190615de1565b6020604051808303816000875af1158015613d7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d9e9190615c01565b9250818a6001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613dcd919061588f565b602060405180830381865afa158015613dea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e0e9190615c01565b14613e2c57604051630a9213b560e21b815260040160405180910390fd5b5050979650505050505050565b6001600160a01b0382166000908152600c602052604090205460ff166001816002811115613e6957613e69615988565b1480613e8657506002816002811115613e8457613e84615988565b145b15613f7357613f028383856001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ece573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ef29190615b52565b6001600160a01b0316919061505d565b604051636e553f6560e01b8152600481018390523060248201526001600160a01b03841690636e553f65906044016020604051808303816000875af1158015613f4f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061381c9190615c01565b505050565b828202811515841585830485141716613f9057600080fd5b6001826001830304018115150290509392505050565b828202811515841585830485141716613fbe57600080fd5b0492915050565b6000818311613fd5576000610e6b565b610e6b8284615c4e565b60008183106133805781610e6b565b82548380613ffd600184615c4e565b8154811061400d5761400d615b0d565b600091825260208083209091015483546001818101865594845291832090910180546001600160a01b0319166001600160a01b03909216919091179055906140559083615c4e565b90505b838111156140e7578461406c600183615c4e565b8154811061407c5761407c615b0d565b9060005260206000200160009054906101000a90046001600160a01b03168582815481106140ac576140ac615b0d565b600091825260209091200180546001600160a01b0319166001600160a01b0392909216919091179055806140df81615e3e565b915050614058565b50818484815481106140fb576140fb615b0d565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555050505050565b600061413a826136ab565b90508015614168576000614151612db5838561416c565b90508015613f7357600f839055613f733082614328565b5050565b60008061417860025490565b90508015613730576134fe848285613fa6565b60155460ff16156141af576040516337a5332d60e11b815260040160405180910390fd5b336001600160a01b0382161461426b57604051635551e1b560e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690635551e1b59061420b90339060040161588f565b602060405180830381865afa158015614228573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061424c9190615da2565b61426b57336040516334871f2560e21b8152600401610dfd919061588f565b60006142768261129a565b90508084111561429d578381604051632d21eb8760e21b8152600401610dfd929190615d06565b83600f60000160008282546142b29190615cf3565b909155505050505050565b6040516001600160a01b038085166024830152831660448201526064810182905261381c9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526151f1565b6001600160a01b03821661437e5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610dfd565b61438a600083836151c9565b806002600082825461439c9190615cf3565b90915550506001600160a01b038216600090815260208190526040812080548392906143c9908490615cf3565b90915550506040518181526001600160a01b03831690600090600080516020615f948339815191529060200160405180910390a35050565b600e5461441c9061010090046001600160a01b031684613e39565b6001600160a01b031660009081526017602052604090204390555050565b600880546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60008061449860025490565b90508015613503576134fe848483613f78565b6001600160a01b0381166000908152600c602052604081205460ff1660018160028111156144db576144db615988565b14806144f8575060028160028111156144f6576144f6615988565b145b156134b35760405163ce96cb7760e01b81526001600160a01b0384169063ce96cb779061347290309060040161588f565b600a54600090606090819081908190806001600160401b0381111561455057614550615af7565b604051908082528060200260200182016040528015614579578160200160208202803683370190505b509450806001600160401b0381111561459457614594615af7565b6040519080825280602002602001820160405280156145bd578160200160208202803683370190505b509350806001600160401b038111156145d8576145d8615af7565b604051908082528060200260200182016040528015614601578160200160208202803683370190505b509250806001600160401b0381111561461c5761461c615af7565b604051908082528060200260200182016040528015614645578160200160208202803683370190505b509250806001600160401b0381111561466057614660615af7565b604051908082528060200260200182016040528015614689578160200160208202803683370190505b50915060005b8181101561479a576000600a82815481106146ac576146ac615b0d565b9060005260206000200160009054906101000a90046001600160a01b03169050808783815181106146df576146df615b0d565b60200260200101906001600160a01b031690816001600160a01b031681525050614708816132cc565b86838151811061471a5761471a615b0d565b60200260200101906001600160a01b031690816001600160a01b0316815250506147438161338d565b85838151811061475557614755615b0d565b60200260200101818152505061476a816144ab565b84838151811061477c5761477c615b0d565b6020908102919091010152508061479281615b39565b91505061468f565b50604051635c9fcd8560e11b8152600260048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015614803573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148279190615b52565b60075460405163b333a17560e01b81529192506001600160a01b038084169263b333a17592614860928a928a9290911690600401615b6f565b602060405180830381865afa15801561487d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148a19190615c01565b965050509091929394565b6148b5816152c3565b600f548085116148ce576148c98582615c4e565b6148d1565b60005b600f555050505050565b336001600160a01b03831614614168576141688233836137a8565b6001600160a01b0382166149565760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610dfd565b614962826000836151c9565b6001600160a01b038216600090815260208190526040902054818110156149d65760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610dfd565b6001600160a01b0383166000908152602081905260408120838303905560028054849290614a05908490615c4e565b90915550506040518281526000906001600160a01b03851690600080516020615f948339815191529060200160405180910390a3505050565b60005b8351811015614b44576000848281518110614a5e57614a5e615b0d565b602002602001015190506000848381518110614a7c57614a7c615b0d565b6020026020010151905080600003614a95575050614b32565b6000614aa2828b8b613fa6565b9050848481518110614ab657614ab6615b0d565b6020026020010151811115614ae0578260405163f2018f6f60e01b8152600401610dfd919061588f565b614aeb83828a613b10565b826001600160a01b03167f94ad37a0f8935c0acdd1ccffe9aad296bfc8d0a1dd2d0cfbac79405c5f86ed8282604051614b2691815260200190565b60405180910390a25050505b80614b3c81615b39565b915050614a41565b50505050505050565b604051635c9fcd8560e11b8152600260048201526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015614bb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614bd99190615b52565b905060005b8551811015614e4057838181518110614bf957614bf9615b0d565b602002602001015160000315614e2e576000858281518110614c1d57614c1d615b0d565b60200260200101516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614c62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614c869190615dc4565b614c9190600a615f39565b90506000836001600160a01b031663baaa61be888581518110614cb657614cb6615b0d565b60209081029190910101516007546040516001600160e01b031960e085901b168152614cef92916001600160a01b031690600401615d2e565b602060405180830381865afa158015614d0c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614d309190615c01565b90506000614d4b8284888781518110612a1757612a17615b0d565b905060008b821115614d6d57614d628c8585613fa6565b905060009b50614d98565b868581518110614d7f57614d7f615b0d565b60200260200101519050818c614d959190615c4e565b9b505b614dbc8a8681518110614dad57614dad615b0d565b6020026020010151828d613b10565b898581518110614dce57614dce615b0d565b60200260200101516001600160a01b03167f94ad37a0f8935c0acdd1ccffe9aad296bfc8d0a1dd2d0cfbac79405c5f86ed8282604051614e1091815260200190565b60405180910390a28b600003614e295750505050614e40565b505050505b80614e3881615b39565b915050614bde565b508615614b445760405163cc5ea39b60e01b815260048101889052602401610dfd565b8154808210614eaa5760405162461bcd60e51b8152602060048201526013602482015272496e646578206f7574206f6620626f756e647360681b6044820152606401610dfd565b815b614eb7600183615c4e565b811015614f455783614eca826001615cf3565b81548110614eda57614eda615b0d565b9060005260206000200160009054906101000a90046001600160a01b0316848281548110614f0a57614f0a615b0d565b600091825260209091200180546001600160a01b0319166001600160a01b039290921691909117905580614f3d81615b39565b915050614eac565b5082805480614f5657614f56615f48565b600082815260209020810160001990810180546001600160a01b0319169055019055505050565b6001600160a01b0381166000908152600560205260409020805460018101825590613387565b6000610d57614fb06139e9565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b600080600061500287878787615319565b9150915061500f816153fc565b5095945050505050565b6000610e6b8383670de0b6b3a7640000613fa6565b60008061503a60025490565b9050828111156133875760006150508483615c4e565b9050610da2848383613f78565b8015806150d65750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e906150939030908690600401615d2e565b602060405180830381865afa1580156150b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906150d49190615c01565b155b6151415760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dfd565b613f738363095ea7b360e01b84846040516024016142f1929190615d48565b60008160ff168360ff1603615176575082610e6b565b8160ff168360ff1610156151aa5761518e8383615f5e565b61519990600a615f39565b6151a39085615d61565b9050610e6b565b6151b48284615f5e565b6151bf90600a615f39565b6151a39085615d80565b613f73836152c3565b613f738363a9059cbb60e01b84846040516024016142f1929190615d48565b6000615246826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166155ad9092919063ffffffff16565b805190915015613f7357808060200190518101906152649190615da2565b613f735760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dfd565b6001600160a01b0381166000908152601760205260409020548015614168576000601654826152f29190615cf3565b905043811115613f735780436040516306f8ee3f60e21b8152600401610dfd929190615d06565b6000806fa2a8918ca85bafe22016d0b997e4df60600160ff1b0383111561534657506000905060036153f3565b8460ff16601b1415801561535e57508460ff16601c14155b1561536f57506000905060046153f3565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa1580156153c3573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166153ec576000600192509250506153f3565b9150600090505b94509492505050565b600081600481111561541057615410615988565b036154185750565b600181600481111561542c5761542c615988565b036154745760405162461bcd60e51b815260206004820152601860248201527745434453413a20696e76616c6964207369676e617475726560401b6044820152606401610dfd565b600281600481111561548857615488615988565b036154d55760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610dfd565b60038160048111156154e9576154e9615988565b036155415760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610dfd565b600481600481111561555557615555615988565b036126255760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b6064820152608401610dfd565b6060610da28484600085856001600160a01b0385163b61560f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dfd565b600080866001600160a01b0316858760405161562b9190615f77565b60006040518083038185875af1925050503d8060008114615668576040519150601f19603f3d011682016040523d82523d6000602084013e61566d565b606091505b509150915061567d828286615688565b979650505050505050565b60608315615697575081610e6b565b8251156156a75782518084602001fd5b8160405162461bcd60e51b8152600401610dfd91906156e5565b60005b838110156156dc5781810151838201526020016156c4565b50506000910152565b60208152600082518060208401526157048160408501602087016156c1565b601f01601f19169190910160400192915050565b60006020828403121561572a57600080fd5b5035919050565b6001600160a01b038116811461262557600080fd5b6000806040838503121561575957600080fd5b823561576481615731565b946020939093013593505050565b60008060006060848603121561578757600080fd5b833561579281615731565b925060208401356157a281615731565b929592945050506040919091013590565b6002811061262557600080fd5b6000602082840312156157d257600080fd5b8135610e6b816157b3565b60008060008060008060a087890312156157f657600080fd5b863561580181615731565b9550602087013561581181615731565b9450604087013593506060870135615828816157b3565b925060808701356001600160401b038082111561584457600080fd5b818901915089601f83011261585857600080fd5b81358181111561586757600080fd5b8a602082850101111561587957600080fd5b6020830194508093505050509295509295509295565b6001600160a01b0391909116815260200190565b6000602082840312156158b557600080fd5b81356001600160401b0381168114610e6b57600080fd5b6000602082840312156158de57600080fd5b8135610e6b81615731565b600080604083850312156158fc57600080fd5b82359150602083013561590e81615731565b809150509250929050565b6000806040838503121561592c57600080fd5b50508035926020909101359150565b6020808252825182820181905260009190848201906040850190845b8181101561597c5783516001600160a01b031683529284019291840191600101615957565b50909695505050505050565b634e487b7160e01b600052602160045260246000fd5b60208101600383106159b2576159b2615988565b91905290565b6000806000606084860312156159cd57600080fd5b8335925060208401356159df81615731565b915060408401356159ef81615731565b809150509250925092565b60ff8116811461262557600080fd5b600080600080600080600060e0888a031215615a2457600080fd5b8735615a2f81615731565b96506020880135615a3f81615731565b955060408801359450606088013593506080880135615a5d816159fa565b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215615a8d57600080fd5b8235615a9881615731565b9150602083013561590e81615731565b6002811061262557612625615988565b602081016159b283615aa8565b60008060408385031215615ad857600080fd5b8235615ae381615731565b915060208301356003811061590e57600080fd5b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201615b4b57615b4b615b23565b5060010190565b600060208284031215615b6457600080fd5b8151610e6b81615731565b606080825284519082018190526000906020906080840190828801845b82811015615bb15781516001600160a01b031684529284019290840190600101615b8c565b5050508381038285015285518082528683019183019060005b81811015615be657835183529284019291840191600101615bca565b50506001600160a01b03861660408601529250610da2915050565b600060208284031215615c1357600080fd5b5051919050565b600181811c90821680615c2e57607f821691505b60208210810361338757634e487b7160e01b600052602260045260246000fd5b81810381811115610d5757610d57615b23565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60408101615ca384615aa8565b838252615caf83615aa8565b8260208301529392505050565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b80820180821115610d5757610d57615b23565b918252602082015260400190565b6001600160401b0392831681529116602082015260400190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b03929092168252602082015260400190565b6000816000190483118215151615615d7b57615d7b615b23565b500290565b600082615d9d57634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215615db457600080fd5b81518015158114610e6b57600080fd5b600060208284031215615dd657600080fd5b8151610e6b816159fa565b615dea87615aa8565b86815260a060208201528460a0820152848660c0830137600060c08683018101919091526001600160a01b039485166040830152928416606082015292166080830152601f909201601f1916010192915050565b600081615e4d57615e4d615b23565b506000190190565b600181815b80851115615e90578160001904821115615e7657615e76615b23565b80851615615e8357918102915b93841c9390800290615e5a565b509250929050565b600082615ea757506001610d57565b81615eb457506000610d57565b8160018114615eca5760028114615ed457615ef0565b6001915050610d57565b60ff841115615ee557615ee5615b23565b50506001821b610d57565b5060208310610133831016604e8410600b8410161715615f13575081810a610d57565b615f1d8383615e55565b8060001904821115615f3157615f31615b23565b029392505050565b6000610e6b60ff841683615e98565b634e487b7160e01b600052603160045260246000fd5b60ff8281168282160390811115610d5757610d57615b23565b60008251615f898184602087016156c1565b919091019291505056feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220a85925649ed959b8c45a1ef33ff9ac5931cf03ad90fded6d1f381c8d9e940c4464736f6c634300081000330000000000000000000000008fbbf5e28837beb54ba9003b974a5ddfb4feb370000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000260000000000000000000000000baf7d863b4504d520797efef4434f2067c1142c50000000000000000000000000000000000000000000000000000000000000003000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001d4d756c7469706f736974696f6e2043656c6c6172204c5020546f6b656e00000000000000000000000000000000000000000000000000000000000000000000116d756c7469706f736974696f6e2d434c52000000000000000000000000000000
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106103e05760003560e01c806395d89b411161020d578063c046742211610121578063c046742214610878578063c244245a1461088b578063c63d75b614610894578063c6e6f592146108a7578063c85e5e13146108ba578063ce96cb77146108c2578063d505accf146108d5578063d905777e146108e8578063dd62ed3e146108fb578063df05a52a1461090e578063dff90b5b14610921578063e39448e014610929578063e753e60014610943578063ecf70858146109da578063eef33eca146109e3578063ef8b30f7146109f2578063f2fde38b14610a05578063f7b24e0814610a18578063fc44459114610a20578063fc4d43be14610a40578063fdd230b914610a5357600080fd5b806395d89b41146106e157806396a0f591146106e957806396d64879146106fc57806399fbab881461071f5780639b6fd18e146107325780639c552ca8146107455780639c5f00c2146107585780639e35c65b146107705780639fdb11b6146107a0578063a457c2d7146107a9578063a8144e48146107bc578063a9059cbb146107c4578063b0a75d36146107d7578063b3d7f6b9146107ea578063b460af94146107fd578063b5292a9914610810578063ba08765214610823578063bd83721a14610836578063bdc8144b14610849578063bdca91651461085c578063bf86d6901461086b57600080fd5b8063472090fe11610304578063472090fe1461055f5780634cdad506146105825780634eca8a8314610595578063530a3714146105a857806358384573146105bb5780635a400d25146105ce5780635e2c576e146105d65780636e553f65146105de5780636e85f183146105f15780636ff1c02a1461060457806370a082311461061357806370af7df614610626578063715018a61461063957806372163715146106415780637b1039991461064a5780637b3baab4146106715780637ecebe001461068b578063802758601461069e5780638b0cebf7146106b35780638da5cb5b146106c657806394bf804d146106ce57600080fd5b806251a3b7146103e557806301e1d114146104005780630402ab631461040857806306fdde031461041157806307a2d13a14610426578063095ea7b3146104395780630a28a4771461045c5780630a680e181461046f57806318160ddd1461047957806323b872dd146104815780632f3b5a13146104945780633076fdc5146104a7578063313ce567146104af5780633644e515146104c4578063389a7294146104cc57806338d52e0f146104df57806339509351146104ff5780633998a681146105125780633cf99a4614610539578063402d267d1461054c575b600080fd5b6103ed600881565b6040519081526020015b60405180910390f35b6103ed610a66565b6103ed61010081565b610419610cb2565b6040516103f791906156e5565b6103ed610434366004615718565b610d44565b61044c610447366004615746565b610d5d565b60405190151581526020016103f7565b6103ed61046a366004615718565b610d75565b610477610daa565b005b6002546103ed565b61044c61048f366004615772565b610e4c565b6104776104a23660046157c0565b610e72565b610477610f08565b60125b60405160ff90911681526020016103f7565b6103ed610f39565b6103ed6104da3660046157dd565b610f48565b6007546104f2906001600160a01b031681565b6040516103f7919061588f565b61044c61050d366004615746565b6111a2565b6105216702c68af0bb14000081565b6040516001600160401b0390911681526020016103f7565b6104776105473660046158a3565b6111c4565b6103ed61055a3660046158cc565b61129a565b61044c61056d3660046158cc565b600b6020526000908152604090205460ff1681565b6103ed610590366004615718565b61132c565b6104776105a33660046158e9565b611354565b6104776105b6366004615718565b6114b1565b6104776105c9366004615919565b611560565b6103ed600281565b6104776116ac565b6103ed6105ec3660046158e9565b611739565b6104776105ff366004615718565b611835565b61052167016345785d8a000081565b6103ed6106213660046158cc565b6118cc565b6104776106343660046158a3565b6118e7565b6104776119c2565b6103ed60135481565b6104f27f0000000000000000000000008fbbf5e28837beb54ba9003b974a5ddfb4feb37081565b600e5461052190600160a81b90046001600160401b031681565b6103ed6106993660046158cc565b6119fb565b6106a6611a19565b6040516103f7919061593b565b6104776106c13660046158cc565b611a7a565b6104f2611b99565b6103ed6106dc3660046158e9565b611ba8565b610419611c98565b6104776106f73660046158e9565b611ca7565b61044c61070a3660046158cc565b600d6020526000908152604090205460ff1681565b6104f261072d366004615718565b611e99565b6104776107403660046158a3565b611ec3565b610477610753366004615718565b611f8e565b600e546104f29061010090046001600160a01b031681565b61079361077e3660046158cc565b600c6020526000908152604090205460ff1681565b6040516103f7919061599e565b6103ed60165481565b61044c6107b7366004615746565b612025565b6103ed6120ab565b61044c6107d2366004615746565b6121e7565b6104776107e53660046158cc565b6121f5565b6103ed6107f8366004615718565b61228d565b6103ed61080b3660046159b8565b6122ba565b61047761081e3660046158a3565b6123e6565b6103ed6108313660046159b8565b6124c1565b6104776108443660046158cc565b6125f6565b610477610857366004615718565b612628565b6105216706f05b59d3b2000081565b60155461044c9060ff1681565b610477610886366004615718565b612697565b6103ed60185481565b6103ed6108a23660046158cc565b6127bd565b6103ed6108b5366004615718565b612846565b610477612859565b6103ed6108d03660046158cc565b6128d0565b6104776108e3366004615a09565b612a99565b6103ed6108f63660046158cc565b612bfd565b6103ed610909366004615a7a565b612c08565b61047761091c366004615718565b612c33565b610477612ca2565b600e546109369060ff1681565b6040516103f79190615ab8565b600f5460105460115460125461098b93926001600160401b0380821693600160401b8304821693600160801b8404831693600160c01b9004909216916001600160a01b031687565b604080519788526001600160401b039687166020890152948616948701949094529184166060860152909216608084015260a08301919091526001600160a01b031660c082015260e0016103f7565b6103ed60145481565b610521670de0b6b3a764000081565b6103ed610a00366004615718565b612fd7565b610477610a133660046158cc565b612fff565b6104b2602081565b6103ed610a2e3660046158cc565b60176020526000908152604090205481565b610477610a4e366004615ac5565b61309c565b610477610a613660046158cc565b613279565b600a5460009081816001600160401b03811115610a8557610a85615af7565b604051908082528060200260200182016040528015610aae578160200160208202803683370190505b5090506000826001600160401b03811115610acb57610acb615af7565b604051908082528060200260200182016040528015610af4578160200160208202803683370190505b50905060005b83811015610ba2576000600a8281548110610b1757610b17615b0d565b6000918252602090912001546001600160a01b03169050610b37816132cc565b848381518110610b4957610b49615b0d565b60200260200101906001600160a01b031690816001600160a01b031681525050610b728161338d565b838381518110610b8457610b84615b0d565b60209081029190910101525080610b9a81615b39565b915050610afa565b50604051635c9fcd8560e11b8152600260048201526000907f0000000000000000000000008fbbf5e28837beb54ba9003b974a5ddfb4feb3706001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015610c0b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c2f9190615b52565b60075460405163b333a17560e01b81529192506001600160a01b038084169263b333a17592610c68928892889290911690600401615b6f565b602060405180830381865afa158015610c85573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca99190615c01565b94505050505090565b606060038054610cc190615c1a565b80601f0160208091040260200160405190810160405280929190818152602001828054610ced90615c1a565b8015610d3a5780601f10610d0f57610100808354040283529160200191610d3a565b820191906000526020600020905b815481529060010190602001808311610d1d57829003601f168201915b5050505050905090565b6000610d5782610d52610a66565b6134df565b92915050565b600033610d6b818585613587565b5060019392505050565b600080610d80610a66565b90506000610d8d826136ab565b9050610da284610d9d8385615c4e565b613711565b949350505050565b60155460ff1615610dce576040516337a5332d60e11b815260040160405180910390fd5b33610dd7611b99565b6001600160a01b031614610e065760405162461bcd60e51b8152600401610dfd90615c61565b60405180910390fd5b6015805460ff191660019081179091556040519081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c906020015b60405180910390a1565b600033610e5a8582856137a8565b610e65858585613822565b60019150505b9392505050565b33610e7b611b99565b6001600160a01b031614610ea15760405162461bcd60e51b8152600401610dfd90615c61565b600e546040517f19365927bf52f7e956d376b3546402dda3827c062c7a6942431a255d212947e891610eda9160ff909116908490615c96565b60405180910390a1600e805482919060ff191660018381811115610f0057610f00615988565b021790555050565b33610f11611b99565b6001600160a01b031614610f375760405162461bcd60e51b8152600401610dfd90615c61565b565b6000610f436139e9565b905090565b600033610f53611b99565b6001600160a01b031614610f795760405162461bcd60e51b8152600401610dfd90615c61565b60155460ff1615610f9d576040516337a5332d60e11b815260040160405180910390fd5b600260095403610fbf5760405162461bcd60e51b8152600401610dfd90615cbc565b60026009556001600160a01b0386166000908152600b602052604090205460ff16610fff5785604051631ec7bcd360e01b8152600401610dfd919061588f565b6000611009610a66565b9050600061101660025490565b9050611023898830613b10565b600061102e8a6132cc565b9050600061103b8a6132cc565b9050806001600160a01b0316826001600160a01b03160361105c578861106b565b61106b82828b8b8b8b30613c05565b94506110778a86613e39565b60006110a2601854670de0b6b3a76400006110929190615c4e565b8690670de0b6b3a7640000613f78565b905060006110cf601854670de0b6b3a76400006110bf9190615cf3565b8790670de0b6b3a7640000613fa6565b90506110d9610a66565b9550808611806110e857508186105b156111175760405163628cc47560e11b8152600481018790526024810183905260448101829052606401610dfd565b600254851461113f5760025485604051632b40145960e21b8152600401610dfd929190615d06565b8b6001600160a01b03168d6001600160a01b03167ffea7a9a6e25cd0bbbfa80ce0c7646e61ee5e0551b3fdaaff0642e6f6adcc72e28d8a604051611184929190615d06565b60405180910390a35050600160095550929998505050505050505050565b600033610d6b8185856111b58383612c08565b6111bf9190615cf3565b613587565b336111cd611b99565b6001600160a01b0316146111f35760405162461bcd60e51b8152600401610dfd90615c61565b6706f05b59d3b200006001600160401b038216111561122557604051632e15286d60e11b815260040160405180910390fd5b6010546040517f27dd3ae8ff7f5e3d77ae68ed36dc780d2ab40a4ffdda18d805cb41eea39c28949161126a91600160c01b9091046001600160401b0316908490615d14565b60405180910390a1601080546001600160401b03909216600160c01b026001600160c01b03909216919091179055565b60155460009060ff16156112b057506000919050565b601454601354600019821480156112c8575060001981145b156112d857506000199392505050565b60006112e2610a66565b905060006112f86112f2876118cc565b836134df565b905060006113068583613fc5565b905060006113148585613fc5565b90506113208282613fdf565b98975050505050505050565b600080611337610a66565b90506000611344826136ab565b9050610da284610d528385615c4e565b3361135d611b99565b6001600160a01b0316146113835760405162461bcd60e51b8152600401610dfd90615c61565b60155460ff16156113a7576040516337a5332d60e11b815260040160405180910390fd5b600a546020116113cd5760405163f025236d60e01b815260206004820152602401610dfd565b6001600160a01b0381166000908152600d602052604090205460ff16611408578060405163699f66b160e11b8152600401610dfd919061588f565b6001600160a01b0381166000908152600b602052604090205460ff16156114445780604051630af67d9160e31b8152600401610dfd919061588f565b611450600a8383613fee565b6001600160a01b0381166000818152600b602052604090819020805460ff19166001179055517fcff5c8a08884d2fad939a9e0f0bf729a4f9af6111a573b4d1f11396c8711646d906114a59085815260200190565b60405180910390a25050565b336114ba611b99565b6001600160a01b0316146114e05760405162461bcd60e51b8152600401610dfd90615c61565b67016345785d8a000081111561151a576040516302d2a90f60e51b81526004810182905267016345785d8a00006024820152604401610dfd565b60188054908290556040517fdf4be33b2e9e3dd4d9e0e85645aea428494a0644a72c51d6a15aedae6b66a3ff906115549083908590615d06565b60405180910390a15050565b33611569611b99565b6001600160a01b03161461158f5760405162461bcd60e51b8152600401610dfd90615c61565b6000600a82815481106115a4576115a4615b0d565b6000918252602082200154600a80546001600160a01b03909216935090859081106115d1576115d1615b0d565b9060005260206000200160009054906101000a90046001600160a01b031690508181600a868154811061160657611606615b0d565b906000526020600020016000600a878154811061162557611625615b0d565b600091825260209091200180546001600160a01b0319166001600160a01b0394851617905581546101009190910a808402199091169383160292909217909155604051828216918416907f3cae4f5796f9d19fa1dcfaacae5a9811c008f6f517a3ec689d903d6f699e49559061169e9088908890615d06565b60405180910390a350505050565b336116b5611b99565b6001600160a01b0316146116db5760405162461bcd60e51b8152600401610dfd90615c61565b60155460ff166116fe5760405163ec7165bf60e01b815260040160405180910390fd5b6015805460ff19169055604051600081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c90602001610e42565b600060026009540361175d5760405162461bcd60e51b8152600401610dfd90615cbc565b6002600955600061176c610a66565b90506117778161412f565b611781848261416c565b9150816000036117a45760405163426f153760e11b815260040160405180910390fd5b6117af84838561418b565b6007546117c7906001600160a01b03163330876142bd565b6117d18383614328565b826001600160a01b0316336001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78685604051611816929190615d06565b60405180910390a3611829848385614401565b50600160095592915050565b3361183e611b99565b6001600160a01b0316146118645760405162461bcd60e51b8152600401610dfd90615c61565b6001600160a01b0381111561188c5760405163019b5e3160e21b815260040160405180910390fd5b6011546040517f513ac19cbbaaad4e450c732ed37635178b7d83bf8e84a940ffe7e052c9c7caa2916118bf918490615d06565b60405180910390a1601155565b6001600160a01b031660009081526020819052604090205490565b336118f0611b99565b6001600160a01b0316146119165760405162461bcd60e51b8152600401610dfd90615c61565b6702c68af0bb1400006001600160401b038216111561194857604051632e15286d60e11b815260040160405180910390fd5b6010546040517f44ada261ff5c9aacbf8d0687294799c8e3e0810ecc1eafd97419dfc31db5d5239161198d91600160801b9091046001600160401b0316908490615d14565b60405180910390a1601080546001600160401b03909216600160801b0267ffffffffffffffff60801b19909216919091179055565b336119cb611b99565b6001600160a01b0316146119f15760405162461bcd60e51b8152600401610dfd90615c61565b610f37600061443a565b6001600160a01b038116600090815260056020526040812054610d57565b6060600a805480602002602001604051908101604052809291908181526020018280548015610d3a57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611a53575050505050905090565b33611a83611b99565b6001600160a01b031614611aa95760405162461bcd60e51b8152600401610dfd90615c61565b6001600160a01b0381166000908152600b602052604090205460ff16611ae45780604051631ec7bcd360e01b8152600401610dfd919061588f565b6000611aef826132cc565b6007549091506001600160a01b03808316911614611b315760075460405163298473c760e11b8152610dfd9183916001600160a01b0390911690600401615d2e565b600e546040516001600160a01b0380851692610100900416907f7f835fbf43c4d05a9c4ea5cafa09fbb3b0307d12956ceedce43fd7a339e5046e90600090a350600e80546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b6008546001600160a01b031690565b6000600260095403611bcc5760405162461bcd60e51b8152600401610dfd90615cbc565b60026009556000611bdb610a66565b9050611be68161412f565b611bf0848261448c565b915081600003611c1357604051639768300560e01b815260040160405180910390fd5b611c1e82858561418b565b600754611c36906001600160a01b03163330856142bd565b611c408385614328565b826001600160a01b0316336001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78487604051611c85929190615d06565b60405180910390a3611829828585614401565b606060048054610cc190615c1a565b33611cb0611b99565b6001600160a01b031614611cd65760405162461bcd60e51b8152600401610dfd90615c61565b60155460ff1615611cfa576040516337a5332d60e11b815260040160405180910390fd5b6001600160a01b0381166000908152600d602052604090205460ff16611d35578060405163699f66b160e11b8152600401610dfd919061588f565b6001600160a01b0381166000908152600b602052604090205460ff1615611d715780604051630af67d9160e31b8152600401610dfd919061588f565b6000600a8381548110611d8657611d86615b0d565b60009182526020822001546001600160a01b03169150611da58261338d565b90508015611dca578181604051638454689f60e01b8152600401610dfd929190615d48565b600e546001600160a01b03610100909104811690831603611dfe5760405163747795ff60e11b815260040160405180910390fd5b82600a8581548110611e1257611e12615b0d565b600091825260208083209190910180546001600160a01b0319166001600160a01b03948516179055848316808352600b82526040808420805460ff1990811690915594881680855293819020805490951660011790945592518781529192917fbc86f8061de00ffd666cfe05f6607130d211483a428a9d8961ecf9544fa836b4910161169e565b600a8181548110611ea957600080fd5b6000918252602090912001546001600160a01b0316905081565b33611ecc611b99565b6001600160a01b031614611ef25760405162461bcd60e51b8152600401610dfd90615c61565b670de0b6b3a76400006001600160401b0382161115611f2457604051633d0203e560e01b815260040160405180910390fd5b6010546040517fc79399093f73f1ff8c2f8279aa9e8803b694c60016c344ecfc2a89fd77c004db91611f63916001600160401b03909116908490615d14565b60405180910390a16010805467ffffffffffffffff19166001600160401b0392909216919091179055565b33611f97611b99565b6001600160a01b031614611fbd5760405162461bcd60e51b8152600401610dfd90615c61565b6008811080611fcd575061010081115b15611feb57604051633a60233f60e21b815260040160405180910390fd5b60168054908290556040517f227ff5c6b5ffb395236b09fd1b472bb128b36eaa17556633feefe28e94411f24906115549083908590615d06565b600033816120338286612c08565b9050838110156120935760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610dfd565b6120a08286868403613587565b506001949350505050565b600a5460009081816001600160401b038111156120ca576120ca615af7565b6040519080825280602002602001820160405280156120f3578160200160208202803683370190505b5090506000826001600160401b0381111561211057612110615af7565b604051908082528060200260200182016040528015612139578160200160208202803683370190505b50905060005b83811015610ba2576000600a828154811061215c5761215c615b0d565b6000918252602090912001546001600160a01b0316905061217c816132cc565b84838151811061218e5761218e615b0d565b60200260200101906001600160a01b031690816001600160a01b0316815250506121b7816144ab565b8383815181106121c9576121c9615b0d565b602090810291909101015250806121df81615b39565b91505061213f565b600033610d6b818585613822565b336121fe611b99565b6001600160a01b0316146122245760405162461bcd60e51b8152600401610dfd90615c61565b6012546040517f51dbb5a65bb22737861a63ec12ba6ce78a98631e9404b0567a2eaf7a06fc544d91612263916001600160a01b03909116908490615d2e565b60405180910390a1601280546001600160a01b0319166001600160a01b0392909216919091179055565b600080612298610a66565b905060006122a5826136ab565b9050610da2846122b58385615c4e565b61448c565b60006002600954036122de5760405162461bcd60e51b8152600401610dfd90615cbc565b60026009556000808080806122f1614529565b945094509450945094506123048561412f565b61230e8986613711565b955061231c89878a8a6148ac565b61232687876148db565b600061233160025490565b905061233d88886148f6565b876001600160a01b0316896001600160a01b0316336001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8d8b60405161238c929190615d06565b60405180910390a46000600e5460ff1660018111156123ad576123ad615988565b146123c5576123c087828b888787614a3e565b6123d3565b6123d38a8a87878787614b4d565b5050600160095550929695505050505050565b336123ef611b99565b6001600160a01b0316146124155760405162461bcd60e51b8152600401610dfd90615c61565b670de0b6b3a76400006001600160401b038216111561244757604051633d0203e560e01b815260040160405180910390fd5b6010546040517fb5cc994a260a85a42d6588668221571ae0a14f0a28f9e4817a5195262102c8689161248c91600160401b9091046001600160401b0316908490615d14565b60405180910390a1601080546001600160401b03909216600160401b0267ffffffffffffffff60401b19909216919091179055565b60006002600954036124e55760405162461bcd60e51b8152600401610dfd90615cbc565b60026009556000808080806124f8614529565b9450945094509450945061250b8561412f565b612515878a6148db565b61251f89866134df565b95508560000361254257604051639768300560e01b815260040160405180910390fd5b61254e868a8a8a6148ac565b600061255960025490565b9050612565888b6148f6565b876001600160a01b0316896001600160a01b0316336001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8a8e6040516125b4929190615d06565b60405180910390a46000600e5460ff1660018111156125d5576125d5615988565b146125e8576123c08a828b888787614a3e565b6123c0878a87878787614b4d565b336125ff611b99565b6001600160a01b0316146126255760405162461bcd60e51b8152600401610dfd90615c61565b50565b33612631611b99565b6001600160a01b0316146126575760405162461bcd60e51b8152600401610dfd90615c61565b7fcfb5a454b8aa7dc04ecb5bc1410b2a57969ca1d67f66d565196f60c6f99754046014548260405161268a929190615d06565b60405180910390a1601455565b336126a0611b99565b6001600160a01b0316146126c65760405162461bcd60e51b8152600401610dfd90615c61565b6000600a82815481106126db576126db615b0d565b60009182526020822001546001600160a01b031691506126fa8261338d565b9050801561271f578181604051638454689f60e01b8152600401610dfd929190615d48565b600e546001600160a01b036101009091048116908316036127535760405163747795ff60e11b815260040160405180910390fd5b61275e600a84614e63565b6001600160a01b0382166000818152600b602052604090819020805460ff19169055517f03c78e4e20a72b1f577a63b54524c684ce73d2e414970ee606bb0b7a9004aa9c906127b09086815260200190565b60405180910390a2505050565b60155460009060ff16156127d357506000919050565b601454601354600019821480156127eb575060001981145b156127fb57506000199392505050565b6000612805610a66565b905060006128156112f2876118cc565b905060006128238583613fc5565b905060006128318585613fc5565b90506113206128408383613fdf565b8561416c565b6000610d5782612854610a66565b61416c565b33612862611b99565b6001600160a01b0316146128885760405162461bcd60e51b8152600401610dfd90615c61565b6000612892610a66565b600f8190556040518181529091507f875561ddc342b12981103d85be8db6375a88982d4cf58d411e38715ae46833309060200160405180910390a150565b6000806128db610a66565b905060006128e8826136ab565b905060006129026128f8866118cc565b610d528486615c4e565b90506000600e5460ff16600181111561291d5761291d615988565b0361294857600061292c6120ab565b90508082111561293c578061293e565b815b9695505050505050565b600080612953614529565b94509450505050600061296560025490565b90506000612972896118cc565b9050670de0b6b3a764000060005b8451811015612a505785818151811061299b5761299b615b0d565b602002602001015160000315612a3e578481815181106129bd576129bd615b0d565b60200260200101516000036129dd575060009a9950505050505050505050565b6000612a2e670de0b6b3a76400008884815181106129fd576129fd615b0d565b6020026020010151888581518110612a1757612a17615b0d565b6020026020010151613fa69092919063ffffffff16565b905082811015612a3c578092505b505b80612a4881615b39565b915050612980565b506000612a6683670de0b6b3a764000086613fa6565b905081811115612a8857612a838983670de0b6b3a7640000613fa6565b612a8a565b865b9b9a5050505050505050505050565b83421115612ae95760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606401610dfd565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9888888612b188c614f7d565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e0016040516020818303038152906040528051906020012090506000612b7382614fa3565b90506000612b8382878787614ff1565b9050896001600160a01b0316816001600160a01b031614612be65760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606401610dfd565b612bf18a8a8a613587565b50505050505050505050565b6000610d57826118cc565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b33612c3c611b99565b6001600160a01b031614612c625760405162461bcd60e51b8152600401610dfd90615c61565b7f1f21432dd7b8ead64d2e7c06a74baf13783b2d2f7153f099e2c4cabc3c5dbec660135482604051612c95929190615d06565b60405180910390a1601355565b600260095403612cc45760405162461bcd60e51b8152600401610dfd90615cbc565b60026009556012546001600160a01b031680612cf35760405163dc13611360e01b815260040160405180910390fd5b6000612cfd610a66565b9050612d088161412f565b6000612d13306118cc565b601054909150600090612d309083906001600160401b0316615019565b600e54909150600090612d5390600160a81b90046001600160401b031642615c4e565b6010549091506000906301e1338090670de0b6b3a764000090600160801b90046001600160401b0316612d868589615d61565b612d909190615d61565b612d9a9190615d80565b612da49190615d80565b90506000612dba612db5838861416c565b61502e565b9050612dc63082614328565b612dd08186615cf3565b601054909550612df1908290600160401b90046001600160401b0316615019565b612dfb9085615cf3565b93508315612e1b57612e0e308886613822565b612e188486615c4e565b94505b600e805467ffffffffffffffff60a81b19164263ffffffff16600160a81b021790556000612e4986886134df565b90508015612f8f5780600f6000016000828254612e669190615c4e565b90915550612e76905030876148f6565b604051635c9fcd8560e11b8152600060048201819052907f0000000000000000000000008fbbf5e28837beb54ba9003b974a5ddfb4feb3706001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015612ede573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f029190615b52565b600754909150612f1c906001600160a01b0316828461505d565b600754601154604051631ffbe7f960e01b81526001600160a01b03928316600482015260248101919091526044810184905290821690631ffbe7f990606401600060405180830381600087803b158015612f7557600080fd5b505af1158015612f89573d6000803e3d6000fd5b50505050505b7f15e3e2a76a6839c244c1ed0a821c233ce8af552dffcb856089eae6cbbbb71ea68682604051612fc0929190615d06565b60405180910390a150506001600955505050505050565b600080612fe2610a66565b90506000612fef826136ab565b9050610da2846128548385615c4e565b33613008611b99565b6001600160a01b03161461302e5760405162461bcd60e51b8152600401610dfd90615c61565b6001600160a01b0381166130935760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dfd565b6126258161443a565b336130a5611b99565b6001600160a01b0316146130cb5760405162461bcd60e51b8152600401610dfd90615c61565b6001600160a01b0382166000908152600d602090815260408083208054600160ff199182168117909255600c9093529220805484939192169083600281111561311657613116615988565b02179055506000613126836132cc565b604051635c9fcd8560e11b8152600260048201529091507f0000000000000000000000008fbbf5e28837beb54ba9003b974a5ddfb4feb3706001600160a01b03169063b93f9b0a90602401602060405180830381865afa15801561318e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131b29190615b52565b6001600160a01b0316634f129c53826040518263ffffffff1660e01b81526004016131dd919061588f565b602060405180830381865afa1580156131fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061321e9190615da2565b61323d5780604051637eb56edb60e11b8152600401610dfd919061588f565b604051600181526001600160a01b038416907fd600b9348603c6deff34b4e0b28b60e1c8036c806741b9e6d90032e7f37dd27f906020016127b0565b33613282611b99565b6001600160a01b0316146132a85760405162461bcd60e51b8152600401610dfd90615c61565b60155460ff1615612625576040516337a5332d60e11b815260040160405180910390fd5b6001600160a01b0381166000908152600c602052604081205460ff1660018160028111156132fc576132fc615988565b14806133195750600281600281111561331757613317615988565b145b1561338057826001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561335c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6b9190615b52565b5090919050565b50919050565b6001600160a01b0381166000908152600c602052604081205460ff1660018160028111156133bd576133bd615988565b14806133da575060028160028111156133d8576133d8615988565b145b156134b3576040516370a0823160e01b81526001600160a01b03841690634cdad5069082906370a082319061341390309060040161588f565b602060405180830381865afa158015613430573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134549190615c01565b6040518263ffffffff1660e01b815260040161347291815260200190565b602060405180830381865afa15801561348f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e6b9190615c01565b6040516370a0823160e01b81526001600160a01b038416906370a082319061347290309060040161588f565b6000806134eb60025490565b90508015613503576134fe848483613fa6565b610da2565b610da26012600760009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561355b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061357f9190615dc4565b869190615160565b6001600160a01b0383166135e95760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610dfd565b6001600160a01b03821661364a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610dfd565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b601054600090600160c01b90046001600160401b03168015806136cc575082155b156136da5750600092915050565b600f548084111561370a5760006136f18286615c4e565b9050613706816001600160401b038516615019565b9350505b5050919050565b60008061371d60025490565b90508015613730576134fe848285613f78565b6007546040805163313ce56760e01b81529051610da2926001600160a01b03169163313ce5679160048083019260209291908290030181865afa15801561377b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061379f9190615dc4565b85906012615160565b60006137b48484612c08565b9050600019811461381c578181101561380f5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610dfd565b61381c8484848403613587565b50505050565b6001600160a01b0383166138865760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610dfd565b6001600160a01b0382166138e85760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610dfd565b6138f38383836151c9565b6001600160a01b0383166000908152602081905260409020548181101561396b5760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610dfd565b6001600160a01b038085166000908152602081905260408082208585039055918516815290812080548492906139a2908490615cf3565b92505081905550826001600160a01b0316846001600160a01b0316600080516020615f94833981519152846040516139dc91815260200190565b60405180910390a361381c565b6000306001600160a01b037f000000000000000000000000a953f0c594365b821a847e7b9f4722e33852669916148015613a4257507f000000000000000000000000000000000000000000000000000000000000000146145b15613a6c57507f5e76f6b8c0cce6181ab8fa52f88f4ea526931d88342516d038ed5d4b983d7c4e90565b50604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6020808301919091527f6219da4561cc661c6a61749637fc9f9c872f01996b3738d9ac76cdb68e6043e4828401527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b6001600160a01b0383166000908152600c602052604090205460ff166001816002811115613b4057613b40615988565b1480613b5d57506002816002811115613b5b57613b5b615988565b145b15613be157604051632d182be560e21b8152600481018490526001600160a01b03838116602483015230604483015285169063b460af94906064016020604051808303816000875af1158015613bb7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613bdb9190615c01565b5061381c565b6001600160a01b038216301461381c5761381c6001600160a01b03851683856151d2565b60008086896001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613c35919061588f565b602060405180830381865afa158015613c52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c769190615c01565b613c809190615c4e565b604051635c9fcd8560e11b8152600160048201529091506000906001600160a01b037f0000000000000000000000008fbbf5e28837beb54ba9003b974a5ddfb4feb370169063b93f9b0a90602401602060405180830381865afa158015613ceb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d0f9190615b52565b9050613d256001600160a01b038b16828a61505d565b806001600160a01b0316632dfe1690888888888f8f6040518763ffffffff1660e01b8152600401613d5b96959493929190615de1565b6020604051808303816000875af1158015613d7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d9e9190615c01565b9250818a6001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613dcd919061588f565b602060405180830381865afa158015613dea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613e0e9190615c01565b14613e2c57604051630a9213b560e21b815260040160405180910390fd5b5050979650505050505050565b6001600160a01b0382166000908152600c602052604090205460ff166001816002811115613e6957613e69615988565b1480613e8657506002816002811115613e8457613e84615988565b145b15613f7357613f028383856001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ece573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ef29190615b52565b6001600160a01b0316919061505d565b604051636e553f6560e01b8152600481018390523060248201526001600160a01b03841690636e553f65906044016020604051808303816000875af1158015613f4f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061381c9190615c01565b505050565b828202811515841585830485141716613f9057600080fd5b6001826001830304018115150290509392505050565b828202811515841585830485141716613fbe57600080fd5b0492915050565b6000818311613fd5576000610e6b565b610e6b8284615c4e565b60008183106133805781610e6b565b82548380613ffd600184615c4e565b8154811061400d5761400d615b0d565b600091825260208083209091015483546001818101865594845291832090910180546001600160a01b0319166001600160a01b03909216919091179055906140559083615c4e565b90505b838111156140e7578461406c600183615c4e565b8154811061407c5761407c615b0d565b9060005260206000200160009054906101000a90046001600160a01b03168582815481106140ac576140ac615b0d565b600091825260209091200180546001600160a01b0319166001600160a01b0392909216919091179055806140df81615e3e565b915050614058565b50818484815481106140fb576140fb615b0d565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555050505050565b600061413a826136ab565b90508015614168576000614151612db5838561416c565b90508015613f7357600f839055613f733082614328565b5050565b60008061417860025490565b90508015613730576134fe848285613fa6565b60155460ff16156141af576040516337a5332d60e11b815260040160405180910390fd5b336001600160a01b0382161461426b57604051635551e1b560e01b81526001600160a01b037f0000000000000000000000008fbbf5e28837beb54ba9003b974a5ddfb4feb3701690635551e1b59061420b90339060040161588f565b602060405180830381865afa158015614228573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061424c9190615da2565b61426b57336040516334871f2560e21b8152600401610dfd919061588f565b60006142768261129a565b90508084111561429d578381604051632d21eb8760e21b8152600401610dfd929190615d06565b83600f60000160008282546142b29190615cf3565b909155505050505050565b6040516001600160a01b038085166024830152831660448201526064810182905261381c9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526151f1565b6001600160a01b03821661437e5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610dfd565b61438a600083836151c9565b806002600082825461439c9190615cf3565b90915550506001600160a01b038216600090815260208190526040812080548392906143c9908490615cf3565b90915550506040518181526001600160a01b03831690600090600080516020615f948339815191529060200160405180910390a35050565b600e5461441c9061010090046001600160a01b031684613e39565b6001600160a01b031660009081526017602052604090204390555050565b600880546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60008061449860025490565b90508015613503576134fe848483613f78565b6001600160a01b0381166000908152600c602052604081205460ff1660018160028111156144db576144db615988565b14806144f8575060028160028111156144f6576144f6615988565b145b156134b35760405163ce96cb7760e01b81526001600160a01b0384169063ce96cb779061347290309060040161588f565b600a54600090606090819081908190806001600160401b0381111561455057614550615af7565b604051908082528060200260200182016040528015614579578160200160208202803683370190505b509450806001600160401b0381111561459457614594615af7565b6040519080825280602002602001820160405280156145bd578160200160208202803683370190505b509350806001600160401b038111156145d8576145d8615af7565b604051908082528060200260200182016040528015614601578160200160208202803683370190505b509250806001600160401b0381111561461c5761461c615af7565b604051908082528060200260200182016040528015614645578160200160208202803683370190505b509250806001600160401b0381111561466057614660615af7565b604051908082528060200260200182016040528015614689578160200160208202803683370190505b50915060005b8181101561479a576000600a82815481106146ac576146ac615b0d565b9060005260206000200160009054906101000a90046001600160a01b03169050808783815181106146df576146df615b0d565b60200260200101906001600160a01b031690816001600160a01b031681525050614708816132cc565b86838151811061471a5761471a615b0d565b60200260200101906001600160a01b031690816001600160a01b0316815250506147438161338d565b85838151811061475557614755615b0d565b60200260200101818152505061476a816144ab565b84838151811061477c5761477c615b0d565b6020908102919091010152508061479281615b39565b91505061468f565b50604051635c9fcd8560e11b8152600260048201526000907f0000000000000000000000008fbbf5e28837beb54ba9003b974a5ddfb4feb3706001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015614803573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148279190615b52565b60075460405163b333a17560e01b81529192506001600160a01b038084169263b333a17592614860928a928a9290911690600401615b6f565b602060405180830381865afa15801561487d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148a19190615c01565b965050509091929394565b6148b5816152c3565b600f548085116148ce576148c98582615c4e565b6148d1565b60005b600f555050505050565b336001600160a01b03831614614168576141688233836137a8565b6001600160a01b0382166149565760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610dfd565b614962826000836151c9565b6001600160a01b038216600090815260208190526040902054818110156149d65760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610dfd565b6001600160a01b0383166000908152602081905260408120838303905560028054849290614a05908490615c4e565b90915550506040518281526000906001600160a01b03851690600080516020615f948339815191529060200160405180910390a3505050565b60005b8351811015614b44576000848281518110614a5e57614a5e615b0d565b602002602001015190506000848381518110614a7c57614a7c615b0d565b6020026020010151905080600003614a95575050614b32565b6000614aa2828b8b613fa6565b9050848481518110614ab657614ab6615b0d565b6020026020010151811115614ae0578260405163f2018f6f60e01b8152600401610dfd919061588f565b614aeb83828a613b10565b826001600160a01b03167f94ad37a0f8935c0acdd1ccffe9aad296bfc8d0a1dd2d0cfbac79405c5f86ed8282604051614b2691815260200190565b60405180910390a25050505b80614b3c81615b39565b915050614a41565b50505050505050565b604051635c9fcd8560e11b8152600260048201526000907f0000000000000000000000008fbbf5e28837beb54ba9003b974a5ddfb4feb3706001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015614bb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614bd99190615b52565b905060005b8551811015614e4057838181518110614bf957614bf9615b0d565b602002602001015160000315614e2e576000858281518110614c1d57614c1d615b0d565b60200260200101516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614c62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614c869190615dc4565b614c9190600a615f39565b90506000836001600160a01b031663baaa61be888581518110614cb657614cb6615b0d565b60209081029190910101516007546040516001600160e01b031960e085901b168152614cef92916001600160a01b031690600401615d2e565b602060405180830381865afa158015614d0c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614d309190615c01565b90506000614d4b8284888781518110612a1757612a17615b0d565b905060008b821115614d6d57614d628c8585613fa6565b905060009b50614d98565b868581518110614d7f57614d7f615b0d565b60200260200101519050818c614d959190615c4e565b9b505b614dbc8a8681518110614dad57614dad615b0d565b6020026020010151828d613b10565b898581518110614dce57614dce615b0d565b60200260200101516001600160a01b03167f94ad37a0f8935c0acdd1ccffe9aad296bfc8d0a1dd2d0cfbac79405c5f86ed8282604051614e1091815260200190565b60405180910390a28b600003614e295750505050614e40565b505050505b80614e3881615b39565b915050614bde565b508615614b445760405163cc5ea39b60e01b815260048101889052602401610dfd565b8154808210614eaa5760405162461bcd60e51b8152602060048201526013602482015272496e646578206f7574206f6620626f756e647360681b6044820152606401610dfd565b815b614eb7600183615c4e565b811015614f455783614eca826001615cf3565b81548110614eda57614eda615b0d565b9060005260206000200160009054906101000a90046001600160a01b0316848281548110614f0a57614f0a615b0d565b600091825260209091200180546001600160a01b0319166001600160a01b039290921691909117905580614f3d81615b39565b915050614eac565b5082805480614f5657614f56615f48565b600082815260209020810160001990810180546001600160a01b0319169055019055505050565b6001600160a01b0381166000908152600560205260409020805460018101825590613387565b6000610d57614fb06139e9565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b600080600061500287878787615319565b9150915061500f816153fc565b5095945050505050565b6000610e6b8383670de0b6b3a7640000613fa6565b60008061503a60025490565b9050828111156133875760006150508483615c4e565b9050610da2848383613f78565b8015806150d65750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e906150939030908690600401615d2e565b602060405180830381865afa1580156150b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906150d49190615c01565b155b6151415760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dfd565b613f738363095ea7b360e01b84846040516024016142f1929190615d48565b60008160ff168360ff1603615176575082610e6b565b8160ff168360ff1610156151aa5761518e8383615f5e565b61519990600a615f39565b6151a39085615d61565b9050610e6b565b6151b48284615f5e565b6151bf90600a615f39565b6151a39085615d80565b613f73836152c3565b613f738363a9059cbb60e01b84846040516024016142f1929190615d48565b6000615246826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166155ad9092919063ffffffff16565b805190915015613f7357808060200190518101906152649190615da2565b613f735760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dfd565b6001600160a01b0381166000908152601760205260409020548015614168576000601654826152f29190615cf3565b905043811115613f735780436040516306f8ee3f60e21b8152600401610dfd929190615d06565b6000806fa2a8918ca85bafe22016d0b997e4df60600160ff1b0383111561534657506000905060036153f3565b8460ff16601b1415801561535e57508460ff16601c14155b1561536f57506000905060046153f3565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa1580156153c3573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166153ec576000600192509250506153f3565b9150600090505b94509492505050565b600081600481111561541057615410615988565b036154185750565b600181600481111561542c5761542c615988565b036154745760405162461bcd60e51b815260206004820152601860248201527745434453413a20696e76616c6964207369676e617475726560401b6044820152606401610dfd565b600281600481111561548857615488615988565b036154d55760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610dfd565b60038160048111156154e9576154e9615988565b036155415760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610dfd565b600481600481111561555557615555615988565b036126255760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604482015261756560f01b6064820152608401610dfd565b6060610da28484600085856001600160a01b0385163b61560f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dfd565b600080866001600160a01b0316858760405161562b9190615f77565b60006040518083038185875af1925050503d8060008114615668576040519150601f19603f3d011682016040523d82523d6000602084013e61566d565b606091505b509150915061567d828286615688565b979650505050505050565b60608315615697575081610e6b565b8251156156a75782518084602001fd5b8160405162461bcd60e51b8152600401610dfd91906156e5565b60005b838110156156dc5781810151838201526020016156c4565b50506000910152565b60208152600082518060208401526157048160408501602087016156c1565b601f01601f19169190910160400192915050565b60006020828403121561572a57600080fd5b5035919050565b6001600160a01b038116811461262557600080fd5b6000806040838503121561575957600080fd5b823561576481615731565b946020939093013593505050565b60008060006060848603121561578757600080fd5b833561579281615731565b925060208401356157a281615731565b929592945050506040919091013590565b6002811061262557600080fd5b6000602082840312156157d257600080fd5b8135610e6b816157b3565b60008060008060008060a087890312156157f657600080fd5b863561580181615731565b9550602087013561581181615731565b9450604087013593506060870135615828816157b3565b925060808701356001600160401b038082111561584457600080fd5b818901915089601f83011261585857600080fd5b81358181111561586757600080fd5b8a602082850101111561587957600080fd5b6020830194508093505050509295509295509295565b6001600160a01b0391909116815260200190565b6000602082840312156158b557600080fd5b81356001600160401b0381168114610e6b57600080fd5b6000602082840312156158de57600080fd5b8135610e6b81615731565b600080604083850312156158fc57600080fd5b82359150602083013561590e81615731565b809150509250929050565b6000806040838503121561592c57600080fd5b50508035926020909101359150565b6020808252825182820181905260009190848201906040850190845b8181101561597c5783516001600160a01b031683529284019291840191600101615957565b50909695505050505050565b634e487b7160e01b600052602160045260246000fd5b60208101600383106159b2576159b2615988565b91905290565b6000806000606084860312156159cd57600080fd5b8335925060208401356159df81615731565b915060408401356159ef81615731565b809150509250925092565b60ff8116811461262557600080fd5b600080600080600080600060e0888a031215615a2457600080fd5b8735615a2f81615731565b96506020880135615a3f81615731565b955060408801359450606088013593506080880135615a5d816159fa565b9699959850939692959460a0840135945060c09093013592915050565b60008060408385031215615a8d57600080fd5b8235615a9881615731565b9150602083013561590e81615731565b6002811061262557612625615988565b602081016159b283615aa8565b60008060408385031215615ad857600080fd5b8235615ae381615731565b915060208301356003811061590e57600080fd5b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201615b4b57615b4b615b23565b5060010190565b600060208284031215615b6457600080fd5b8151610e6b81615731565b606080825284519082018190526000906020906080840190828801845b82811015615bb15781516001600160a01b031684529284019290840190600101615b8c565b5050508381038285015285518082528683019183019060005b81811015615be657835183529284019291840191600101615bca565b50506001600160a01b03861660408601529250610da2915050565b600060208284031215615c1357600080fd5b5051919050565b600181811c90821680615c2e57607f821691505b60208210810361338757634e487b7160e01b600052602260045260246000fd5b81810381811115610d5757610d57615b23565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60408101615ca384615aa8565b838252615caf83615aa8565b8260208301529392505050565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b80820180821115610d5757610d57615b23565b918252602082015260400190565b6001600160401b0392831681529116602082015260400190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b03929092168252602082015260400190565b6000816000190483118215151615615d7b57615d7b615b23565b500290565b600082615d9d57634e487b7160e01b600052601260045260246000fd5b500490565b600060208284031215615db457600080fd5b81518015158114610e6b57600080fd5b600060208284031215615dd657600080fd5b8151610e6b816159fa565b615dea87615aa8565b86815260a060208201528460a0820152848660c0830137600060c08683018101919091526001600160a01b039485166040830152928416606082015292166080830152601f909201601f1916010192915050565b600081615e4d57615e4d615b23565b506000190190565b600181815b80851115615e90578160001904821115615e7657615e76615b23565b80851615615e8357918102915b93841c9390800290615e5a565b509250929050565b600082615ea757506001610d57565b81615eb457506000610d57565b8160018114615eca5760028114615ed457615ef0565b6001915050610d57565b60ff841115615ee557615ee5615b23565b50506001821b610d57565b5060208310610133831016604e8410600b8410161715615f13575081810a610d57565b615f1d8383615e55565b8060001904821115615f3157615f31615b23565b029392505050565b6000610e6b60ff841683615e98565b634e487b7160e01b600052603160045260246000fd5b60ff8281168282160390811115610d5757610d57615b23565b60008251615f898184602087016156c1565b919091019291505056feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa2646970667358221220a85925649ed959b8c45a1ef33ff9ac5931cf03ad90fded6d1f381c8d9e940c4464736f6c63430008100033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000008fbbf5e28837beb54ba9003b974a5ddfb4feb370000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000260000000000000000000000000baf7d863b4504d520797efef4434f2067c1142c50000000000000000000000000000000000000000000000000000000000000003000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001d4d756c7469706f736974696f6e2043656c6c6172204c5020546f6b656e00000000000000000000000000000000000000000000000000000000000000000000116d756c7469706f736974696f6e2d434c52000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _registry (address): 0x8fbBF5E28837beb54ba9003b974A5DDfb4Feb370
Arg [1] : _asset (address): 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
Arg [2] : _positions (address[]): 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2,0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599
Arg [3] : _positionTypes (uint8[]): 0,0,0
Arg [4] : _holdingPosition (address): 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
Arg [5] : _withdrawType (uint8): 0
Arg [6] : _name (string): Multiposition Cellar LP Token
Arg [7] : _symbol (string): multiposition-CLR
Arg [8] : _strategistPayout (address): 0xbaf7d863B4504D520797EFef4434F2067C1142c5
-----Encoded View---------------
21 Constructor Arguments found :
Arg [0] : 0000000000000000000000008fbbf5e28837beb54ba9003b974a5ddfb4feb370
Arg [1] : 000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000120
Arg [3] : 00000000000000000000000000000000000000000000000000000000000001a0
Arg [4] : 000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000220
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000260
Arg [8] : 000000000000000000000000baf7d863b4504d520797efef4434f2067c1142c5
Arg [9] : 0000000000000000000000000000000000000000000000000000000000000003
Arg [10] : 000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
Arg [11] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [12] : 0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599
Arg [13] : 0000000000000000000000000000000000000000000000000000000000000003
Arg [14] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [15] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [16] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [17] : 000000000000000000000000000000000000000000000000000000000000001d
Arg [18] : 4d756c7469706f736974696f6e2043656c6c6172204c5020546f6b656e000000
Arg [19] : 0000000000000000000000000000000000000000000000000000000000000011
Arg [20] : 6d756c7469706f736974696f6e2d434c52000000000000000000000000000000
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.