More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 92 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Harvest | 16591961 | 804 days ago | IN | 0 ETH | 0.03374935 | ||||
Harvest | 16274742 | 848 days ago | IN | 0 ETH | 0.01149159 | ||||
Harvest | 15976835 | 889 days ago | IN | 0 ETH | 0.02151206 | ||||
Harvest | 15951999 | 893 days ago | IN | 0 ETH | 0.01314043 | ||||
Harvest | 15941473 | 894 days ago | IN | 0 ETH | 0.02555534 | ||||
Harvest | 15660706 | 934 days ago | IN | 0 ETH | 0.00463696 | ||||
Harvest | 15637113 | 937 days ago | IN | 0 ETH | 0.00783068 | ||||
Harvest | 15569852 | 946 days ago | IN | 0 ETH | 0.01250404 | ||||
Harvest | 15119619 | 1017 days ago | IN | 0 ETH | 0.00848703 | ||||
Harvest | 15005788 | 1036 days ago | IN | 0 ETH | 0.02419008 | ||||
Harvest | 15005783 | 1036 days ago | IN | 0 ETH | 0.02427441 | ||||
Harvest | 15005516 | 1036 days ago | IN | 0 ETH | 0.03067688 | ||||
Harvest | 14997382 | 1037 days ago | IN | 0 ETH | 0.03128405 | ||||
Harvest | 14987289 | 1039 days ago | IN | 0 ETH | 0.04779428 | ||||
Harvest | 14973088 | 1042 days ago | IN | 0 ETH | 0.02127164 | ||||
Harvest | 14909487 | 1053 days ago | IN | 0 ETH | 0.02420333 | ||||
Harvest | 14829284 | 1066 days ago | IN | 0 ETH | 0.0103543 | ||||
Harvest | 14827010 | 1066 days ago | IN | 0 ETH | 0.04588535 | ||||
Harvest | 14826967 | 1066 days ago | IN | 0 ETH | 0.01718118 | ||||
Harvest | 14797817 | 1071 days ago | IN | 0 ETH | 0.01897583 | ||||
Harvest | 14762396 | 1076 days ago | IN | 0 ETH | 0.0819076 | ||||
Harvest | 14760239 | 1077 days ago | IN | 0 ETH | 0.20129077 | ||||
Harvest | 14760153 | 1077 days ago | IN | 0 ETH | 0.25603524 | ||||
Harvest | 14759991 | 1077 days ago | IN | 0 ETH | 0.34133514 | ||||
Harvest | 14758432 | 1077 days ago | IN | 0 ETH | 0.0958825 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xFd04BcE2...0B5e22461 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
Strategy
Compiler Version
v0.8.7+commit.e28d00a7
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; import "./StrategyEvents.sol"; /// @title Strategy /// @author Forked from https://github.com/Grandthrax/yearnV2-generic-lender-strat /// @notice A lender optimisation strategy for any ERC20 asset /// @dev This strategy works by taking plugins designed for standard lending platforms /// It automatically chooses the best yield generating platform and adjusts accordingly /// The adjustment is sub optimal so there is an additional option to manually set position contract Strategy is StrategyEvents, BaseStrategy { using SafeERC20 for IERC20; using Address for address; // ======================== References to contracts ============================ IGenericLender[] public lenders; // ======================== Parameters ========================================= uint256 public withdrawalThreshold = 1e14; // ============================== Constructor ================================== /// @notice Constructor of the `Strategy` /// @param _poolManager Address of the `PoolManager` lending to this strategy /// @param _rewards The token given to reward keepers. /// @param governorList List of addresses with governor privilege /// @param guardian Address of the guardian constructor( address _poolManager, IERC20 _rewards, address[] memory governorList, address guardian ) BaseStrategy(_poolManager, _rewards, governorList, guardian) { require(guardian != address(0) && address(_rewards) != address(0), "0"); } // ========================== Internal Mechanics =============================== /// @notice Frees up profit plus `_debtOutstanding`. /// @param _debtOutstanding Amount to withdraw /// @return _profit Profit freed by the call /// @return _loss Loss discovered by the call /// @return _debtPayment Amount freed to reimburse the debt /// @dev If `_debtOutstanding` is more than we can free we get as much as possible. function _prepareReturn(uint256 _debtOutstanding) internal override returns ( uint256 _profit, uint256 _loss, uint256 _debtPayment ) { _profit = 0; _loss = 0; //for clarity _debtPayment = _debtOutstanding; uint256 lentAssets = lentTotalAssets(); uint256 looseAssets = want.balanceOf(address(this)); uint256 total = looseAssets + lentAssets; if (lentAssets == 0) { // No position to harvest or profit to report if (_debtPayment > looseAssets) { // We can only return looseAssets _debtPayment = looseAssets; } return (_profit, _loss, _debtPayment); } uint256 debt = poolManager.strategies(address(this)).totalStrategyDebt; if (total > debt) { _profit = total - debt; uint256 amountToFree = _profit + _debtPayment; // We need to add outstanding to our profit // don't need to do logic if there is nothing to free if (amountToFree > 0 && looseAssets < amountToFree) { // Withdraw what we can withdraw _withdrawSome(amountToFree - looseAssets); uint256 newLoose = want.balanceOf(address(this)); // If we dont have enough money adjust _debtOutstanding and only change profit if needed if (newLoose < amountToFree) { if (_profit > newLoose) { _profit = newLoose; _debtPayment = 0; } else { _debtPayment = Math.min(newLoose - _profit, _debtPayment); } } } } else { // Serious loss should never happen but if it does lets record it accurately _loss = debt - total; uint256 amountToFree = _loss + _debtPayment; if (amountToFree > 0 && looseAssets < amountToFree) { // Withdraw what we can withdraw _withdrawSome(amountToFree - looseAssets); uint256 newLoose = want.balanceOf(address(this)); // If we dont have enough money adjust `_debtOutstanding` and only change profit if needed if (newLoose < amountToFree) { if (_loss > newLoose) { _loss = newLoose; _debtPayment = 0; } else { _debtPayment = Math.min(newLoose - _loss, _debtPayment); } } } } } /// @notice Estimates highest and lowest apr lenders among a `lendersList` /// @param lendersList List of all the lender contracts associated to this strategy /// @return _lowest The index of the lender in the `lendersList` with lowest apr /// @return _lowestApr The lowest apr /// @return _highest The index of the lender with highest apr /// @return _potential The potential apr of this lender if funds are moved from lowest to highest /// @dev `lendersList` is kept as a parameter to avoid multiplying reads in storage to the `lenders` /// array function _estimateAdjustPosition(IGenericLender[] memory lendersList) internal view returns ( uint256 _lowest, uint256 _lowestApr, uint256 _highest, uint256 _potential ) { //all loose assets are to be invested uint256 looseAssets = want.balanceOf(address(this)); // our simple algo // get the lowest apr strat // cycle through and see who could take its funds plus want for the highest apr _lowestApr = type(uint256).max; _lowest = 0; uint256 lowestNav = 0; uint256 highestApr = 0; _highest = 0; for (uint256 i = 0; i < lendersList.length; i++) { uint256 aprAfterDeposit = lendersList[i].aprAfterDeposit(looseAssets); if (aprAfterDeposit > highestApr) { highestApr = aprAfterDeposit; _highest = i; } if (lendersList[i].hasAssets()) { uint256 apr = lendersList[i].apr(); if (apr < _lowestApr) { _lowestApr = apr; _lowest = i; lowestNav = lendersList[i].nav(); } } } //if we can improve apr by withdrawing we do so _potential = lendersList[_highest].aprAfterDeposit(lowestNav + looseAssets); } /// @notice Function called by keepers to adjust the position /// @dev The algorithm moves assets from lowest return to highest /// like a very slow idiot bubble sort function _adjustPosition() internal override { // Emergency exit is dealt with at beginning of harvest if (emergencyExit) { return; } // Storing the `lenders` array in a cache variable IGenericLender[] memory lendersList = lenders; // We just keep all money in want if we dont have any lenders if (lendersList.length == 0) { return; } (uint256 lowest, uint256 lowestApr, uint256 highest, uint256 potential) = _estimateAdjustPosition(lendersList); if (potential > lowestApr) { // Apr should go down after deposit so won't be withdrawing from self lendersList[lowest].withdrawAll(); } uint256 bal = want.balanceOf(address(this)); if (bal > 0) { want.safeTransfer(address(lendersList[highest]), bal); lendersList[highest].deposit(); } } /// @notice Withdraws a given amount from lenders /// @param _amount The amount to withdraw /// @dev Cycle through withdrawing from worst rate first function _withdrawSome(uint256 _amount) internal returns (uint256 amountWithdrawn) { IGenericLender[] memory lendersList = lenders; if (lendersList.length == 0) { return 0; } // Don't withdraw dust if (_amount < withdrawalThreshold) { return 0; } amountWithdrawn = 0; // In most situations this will only run once. Only big withdrawals will be a gas guzzler uint256 j = 0; while (amountWithdrawn < _amount) { uint256 lowestApr = type(uint256).max; uint256 lowest = 0; for (uint256 i = 0; i < lendersList.length; i++) { if (lendersList[i].hasAssets()) { uint256 apr = lendersList[i].apr(); if (apr < lowestApr) { lowestApr = apr; lowest = i; } } } if (!lendersList[lowest].hasAssets()) { return amountWithdrawn; } amountWithdrawn = amountWithdrawn + lendersList[lowest].withdraw(_amount - amountWithdrawn); j++; // To avoid want infinite loop if (j >= 6) { return amountWithdrawn; } } } /// @notice Liquidates up to `_amountNeeded` of `want` of this strategy's positions, /// irregardless of slippage. Any excess will be re-invested with `_adjustPosition()`. /// This function should return the amount of `want` tokens made available by the /// liquidation. If there is a difference between them, `_loss` indicates whether the /// difference is due to a realized loss, or if there is some other sitution at play /// (e.g. locked funds) where the amount made available is less than what is needed. /// /// NOTE: The invariant `_liquidatedAmount + _loss <= _amountNeeded` should always be maintained function _liquidatePosition(uint256 _amountNeeded) internal override returns (uint256 _amountFreed, uint256 _loss) { uint256 _balance = want.balanceOf(address(this)); if (_balance >= _amountNeeded) { //if we don't set reserve here withdrawer will be sent our full balance return (_amountNeeded, 0); } else { uint256 received = _withdrawSome(_amountNeeded - _balance) + (_balance); if (received >= _amountNeeded) { return (_amountNeeded, 0); } else { return (received, 0); } } } /// @notice Liquidates everything and returns the amount that got freed. /// This function is used during emergency exit instead of `_prepareReturn()` to /// liquidate all of the Strategy's positions back to the Manager. function _liquidateAllPositions() internal override returns (uint256 _amountFreed) { (_amountFreed, ) = _liquidatePosition(estimatedTotalAssets()); } // ========================== View Functions =================================== struct LendStatus { string name; uint256 assets; uint256 rate; address add; } /// @notice View function to check the current state of the strategy /// @return Returns the status of all lenders attached the strategy function lendStatuses() external view returns (LendStatus[] memory) { uint256 lendersListLength = lenders.length; LendStatus[] memory statuses = new LendStatus[](lendersListLength); for (uint256 i = 0; i < lendersListLength; i++) { LendStatus memory s; s.name = lenders[i].lenderName(); s.add = address(lenders[i]); s.assets = lenders[i].nav(); s.rate = lenders[i].apr(); statuses[i] = s; } return statuses; } /// @notice View function to check the total assets lent function lentTotalAssets() public view returns (uint256) { uint256 nav = 0; for (uint256 i = 0; i < lenders.length; i++) { nav = nav + lenders[i].nav(); } return nav; } /// @notice View function to check the total assets managed by the strategy function estimatedTotalAssets() public view override returns (uint256 nav) { nav = lentTotalAssets() + want.balanceOf(address(this)); } /// @notice View function to check the number of lending platforms function numLenders() external view returns (uint256) { return lenders.length; } /// @notice The weighted apr of all lenders. sum(nav * apr)/totalNav function estimatedAPR() external view returns (uint256) { uint256 bal = estimatedTotalAssets(); if (bal == 0) { return 0; } uint256 weightedAPR = 0; for (uint256 i = 0; i < lenders.length; i++) { weightedAPR = weightedAPR + lenders[i].weightedApr(); } return weightedAPR / bal; } /// @notice Prevents the governance from withdrawing want tokens function _protectedTokens() internal view override returns (address[] memory) { address[] memory protected = new address[](1); protected[0] = address(want); return protected; } // ============================ Governance ===================================== struct LenderRatio { address lender; //share x 1000 uint16 share; } /// @notice Reallocates all funds according to a new distributions /// @param _newPositions List of shares to specify the new allocation /// @dev Share must add up to 1000. 500 means 50% etc /// @dev This code has been forked, so we have not thoroughly tested it on our own function manualAllocation(LenderRatio[] memory _newPositions) external onlyRole(GUARDIAN_ROLE) { IGenericLender[] memory lendersList = lenders; uint256 share = 0; for (uint256 i = 0; i < lendersList.length; i++) { lendersList[i].withdrawAll(); } uint256 assets = want.balanceOf(address(this)); for (uint256 i = 0; i < _newPositions.length; i++) { bool found = false; //might be annoying and expensive to do this second loop but worth it for safety for (uint256 j = 0; j < lendersList.length; j++) { if (address(lendersList[j]) == _newPositions[i].lender) { found = true; } } require(found, "94"); share = share + _newPositions[i].share; uint256 toSend = (assets * _newPositions[i].share) / 1000; want.safeTransfer(_newPositions[i].lender, toSend); IGenericLender(_newPositions[i].lender).deposit(); } require(share == 1000, "95"); } /// @notice Changes the withdrawal threshold /// @param _threshold The new withdrawal threshold /// @dev governor, guardian or `PoolManager` only function setWithdrawalThreshold(uint256 _threshold) external onlyRole(GUARDIAN_ROLE) { withdrawalThreshold = _threshold; } /// @notice Add lenders for the strategy to choose between /// @param newLender The adapter to the added lending platform /// @dev Governor, guardian or `PoolManager` only function addLender(IGenericLender newLender) external onlyRole(GUARDIAN_ROLE) { require(newLender.strategy() == address(this), "96"); for (uint256 i = 0; i < lenders.length; i++) { require(address(newLender) != address(lenders[i]), "97"); } lenders.push(newLender); emit AddLender(address(newLender)); } /// @notice Removes a lending platform and fails if total withdrawal is impossible /// @param lender The address of the adapter to the lending platform to remove function safeRemoveLender(address lender) external onlyRole(GUARDIAN_ROLE) { _removeLender(lender, false); } /// @notice Removes a lending platform and even if total withdrawal is impossible /// @param lender The address of the adapter to the lending platform to remove function forceRemoveLender(address lender) external onlyRole(GUARDIAN_ROLE) { _removeLender(lender, true); } /// @notice Internal function to handle lending platform removing /// @param lender The address of the adapter for the lending platform to remove /// @param force Whether it is required that all the funds are withdrawn prior to removal function _removeLender(address lender, bool force) internal { IGenericLender[] memory lendersList = lenders; for (uint256 i = 0; i < lendersList.length; i++) { if (lender == address(lendersList[i])) { bool allWithdrawn = lendersList[i].withdrawAll(); if (!force) { require(allWithdrawn, "98"); } // Put the last index here // then remove last index if (i != lendersList.length - 1) { lenders[i] = lendersList[lendersList.length - 1]; } // Pop shortens array by 1 thereby deleting the last index lenders.pop(); // If balance to spend we might as well put it into the best lender if (want.balanceOf(address(this)) > 0) { _adjustPosition(); } emit RemoveLender(lender); return; } } require(false, "94"); } // ========================== Manager functions ================================ /// @notice Adds a new guardian address and echoes the change to the contracts /// that interact with this collateral `PoolManager` /// @param _guardian New guardian address /// @dev This internal function has to be put in this file because `AccessControl` is not defined /// in `PoolManagerInternal` function addGuardian(address _guardian) external override onlyRole(POOLMANAGER_ROLE) { // Granting the new role // Access control for this contract _grantRole(GUARDIAN_ROLE, _guardian); // Propagating the new role in other contract for (uint256 i = 0; i < lenders.length; i++) { lenders[i].grantRole(GUARDIAN_ROLE, _guardian); } } /// @notice Revokes the guardian role and propagates the change to other contracts /// @param guardian Old guardian address to revoke function revokeGuardian(address guardian) external override onlyRole(POOLMANAGER_ROLE) { _revokeRole(GUARDIAN_ROLE, guardian); for (uint256 i = 0; i < lenders.length; i++) { lenders[i].revokeRole(GUARDIAN_ROLE, guardian); } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount ) external returns (bool); /** * @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); }
// SPDX-License-Identifier: MIT 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 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 pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 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 assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; /** * @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); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a / b + (a % b == 0 ? 0 : 1); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import './pool/IUniswapV3PoolImmutables.sol'; import './pool/IUniswapV3PoolState.sol'; import './pool/IUniswapV3PoolDerivedState.sol'; import './pool/IUniswapV3PoolActions.sol'; import './pool/IUniswapV3PoolOwnerActions.sol'; import './pool/IUniswapV3PoolEvents.sol'; /// @title The interface for a Uniswap V3 Pool /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform /// to the ERC20 specification /// @dev The pool interface is broken up into many smaller pieces interface IUniswapV3Pool is IUniswapV3PoolImmutables, IUniswapV3PoolState, IUniswapV3PoolDerivedState, IUniswapV3PoolActions, IUniswapV3PoolOwnerActions, IUniswapV3PoolEvents { }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissionless pool actions /// @notice Contains pool methods that can be called by anyone interface IUniswapV3PoolActions { /// @notice Sets the initial price for the pool /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96 function initialize(uint160 sqrtPriceX96) external; /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends /// on tickLower, tickUpper, the amount of liquidity, and the current price. /// @param recipient The address for which the liquidity will be created /// @param tickLower The lower tick of the position in which to add liquidity /// @param tickUpper The upper tick of the position in which to add liquidity /// @param amount The amount of liquidity to mint /// @param data Any data that should be passed through to the callback /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback function mint( address recipient, int24 tickLower, int24 tickUpper, uint128 amount, bytes calldata data ) external returns (uint256 amount0, uint256 amount1); /// @notice Collects tokens owed to a position /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity. /// @param recipient The address which should receive the fees collected /// @param tickLower The lower tick of the position for which to collect fees /// @param tickUpper The upper tick of the position for which to collect fees /// @param amount0Requested How much token0 should be withdrawn from the fees owed /// @param amount1Requested How much token1 should be withdrawn from the fees owed /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0 /// @dev Fees must be collected separately via a call to #collect /// @param tickLower The lower tick of the position for which to burn liquidity /// @param tickUpper The upper tick of the position for which to burn liquidity /// @param amount How much liquidity to burn /// @return amount0 The amount of token0 sent to the recipient /// @return amount1 The amount of token1 sent to the recipient function burn( int24 tickLower, int24 tickUpper, uint128 amount ) external returns (uint256 amount0, uint256 amount1); /// @notice Swap token0 for token1, or token1 for token0 /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback /// @param recipient The address to receive the output of the swap /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0 /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this /// value after the swap. If one for zero, the price cannot be greater than this value after the swap /// @param data Any data to be passed through to the callback /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data ) external returns (int256 amount0, int256 amount1); /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling /// with 0 amount{0,1} and sending the donation amount(s) from the callback /// @param recipient The address which will receive the token0 and token1 amounts /// @param amount0 The amount of token0 to send /// @param amount1 The amount of token1 to send /// @param data Any data to be passed through to the callback function flash( address recipient, uint256 amount0, uint256 amount1, bytes calldata data ) external; /// @notice Increase the maximum number of price and liquidity observations that this pool will store /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to /// the input observationCardinalityNext. /// @param observationCardinalityNext The desired minimum number of observations for the pool to store function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that is not stored /// @notice Contains view functions to provide information about the pool that is computed rather than stored on the /// blockchain. The functions here may have variable gas costs. interface IUniswapV3PoolDerivedState { /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, /// you must call it with secondsAgos = [3600, 0]. /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio. /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block /// timestamp function observe(uint32[] calldata secondsAgos) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s); /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed. /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first /// snapshot is taken and the second snapshot is taken. /// @param tickLower The lower tick of the range /// @param tickUpper The upper tick of the range /// @return tickCumulativeInside The snapshot of the tick accumulator for the range /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range /// @return secondsInside The snapshot of seconds per liquidity for the range function snapshotCumulativesInside(int24 tickLower, int24 tickUpper) external view returns ( int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Events emitted by a pool /// @notice Contains all events emitted by the pool interface IUniswapV3PoolEvents { /// @notice Emitted exactly once by a pool when #initialize is first called on the pool /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96 /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool event Initialize(uint160 sqrtPriceX96, int24 tick); /// @notice Emitted when liquidity is minted for a given position /// @param sender The address that minted the liquidity /// @param owner The owner of the position and recipient of any minted liquidity /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity minted to the position range /// @param amount0 How much token0 was required for the minted liquidity /// @param amount1 How much token1 was required for the minted liquidity event Mint( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted when fees are collected by the owner of a position /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees /// @param owner The owner of the position for which fees are collected /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount0 The amount of token0 fees collected /// @param amount1 The amount of token1 fees collected event Collect( address indexed owner, address recipient, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount0, uint128 amount1 ); /// @notice Emitted when a position's liquidity is removed /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect /// @param owner The owner of the position for which liquidity is removed /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity to remove /// @param amount0 The amount of token0 withdrawn /// @param amount1 The amount of token1 withdrawn event Burn( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted by the pool for any swaps between token0 and token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the output of the swap /// @param amount0 The delta of the token0 balance of the pool /// @param amount1 The delta of the token1 balance of the pool /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96 /// @param liquidity The liquidity of the pool after the swap /// @param tick The log base 1.0001 of price of the pool after the swap event Swap( address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick ); /// @notice Emitted by the pool for any flashes of token0/token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the tokens from flash /// @param amount0 The amount of token0 that was flashed /// @param amount1 The amount of token1 that was flashed /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee event Flash( address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint256 paid0, uint256 paid1 ); /// @notice Emitted by the pool for increases to the number of observations that can be stored /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index /// just before a mint/swap/burn. /// @param observationCardinalityNextOld The previous value of the next observation cardinality /// @param observationCardinalityNextNew The updated value of the next observation cardinality event IncreaseObservationCardinalityNext( uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew ); /// @notice Emitted when the protocol fee is changed by the pool /// @param feeProtocol0Old The previous value of the token0 protocol fee /// @param feeProtocol1Old The previous value of the token1 protocol fee /// @param feeProtocol0New The updated value of the token0 protocol fee /// @param feeProtocol1New The updated value of the token1 protocol fee event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New); /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner /// @param sender The address that collects the protocol fees /// @param recipient The address that receives the collected protocol fees /// @param amount0 The amount of token0 protocol fees that is withdrawn /// @param amount0 The amount of token1 protocol fees that is withdrawn event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that never changes /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values interface IUniswapV3PoolImmutables { /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface /// @return The contract address function factory() external view returns (address); /// @notice The first of the two tokens of the pool, sorted by address /// @return The token contract address function token0() external view returns (address); /// @notice The second of the two tokens of the pool, sorted by address /// @return The token contract address function token1() external view returns (address); /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 /// @return The fee function fee() external view returns (uint24); /// @notice The pool tick spacing /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... /// This value is an int24 to avoid casting even though it is always positive. /// @return The tick spacing function tickSpacing() external view returns (int24); /// @notice The maximum amount of position liquidity that can use any tick in the range /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool /// @return The max amount of liquidity per tick function maxLiquidityPerTick() external view returns (uint128); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissioned pool actions /// @notice Contains pool methods that may only be called by the factory owner interface IUniswapV3PoolOwnerActions { /// @notice Set the denominator of the protocol's % share of the fees /// @param feeProtocol0 new protocol fee for token0 of the pool /// @param feeProtocol1 new protocol fee for token1 of the pool function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; /// @notice Collect the protocol fee accrued to the pool /// @param recipient The address to which collected protocol fees should be sent /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 /// @return amount0 The protocol fee collected in token0 /// @return amount1 The protocol fee collected in token1 function collectProtocol( address recipient, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that can change /// @notice These methods compose the pool's state, and can change with any frequency including multiple times /// per transaction interface IUniswapV3PoolState { /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas /// when accessed externally. /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value /// tick The current tick of the pool, i.e. according to the last tick transition that was run. /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick /// boundary. /// observationIndex The index of the last oracle observation that was written, /// observationCardinality The current maximum number of observations stored in the pool, /// observationCardinalityNext The next maximum number of observations, to be updated when the observation. /// feeProtocol The protocol fee for both tokens of the pool. /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0 /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee. /// unlocked Whether the pool is currently locked to reentrancy function slot0() external view returns ( uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked ); /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal0X128() external view returns (uint256); /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal1X128() external view returns (uint256); /// @notice The amounts of token0 and token1 that are owed to the protocol /// @dev Protocol fees will never exceed uint128 max in either token function protocolFees() external view returns (uint128 token0, uint128 token1); /// @notice The currently in range liquidity available to the pool /// @dev This value has no relationship to the total liquidity across all ticks function liquidity() external view returns (uint128); /// @notice Look up information about a specific tick in the pool /// @param tick The tick to look up /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or /// tick upper, /// liquidityNet how much liquidity changes when the pool price crosses the tick, /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0, /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1, /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick, /// secondsOutside the seconds spent on the other side of the tick from the current tick, /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false. /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0. /// In addition, these values are only relative and must be used only in comparison to previous snapshots for /// a specific position. function ticks(int24 tick) external view returns ( uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128, int56 tickCumulativeOutside, uint160 secondsPerLiquidityOutsideX128, uint32 secondsOutside, bool initialized ); /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information function tickBitmap(int16 wordPosition) external view returns (uint256); /// @notice Returns the information about a position by the position's key /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper /// @return _liquidity The amount of liquidity in the position, /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke, /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke, /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke, /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke function positions(bytes32 key) external view returns ( uint128 _liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); /// @notice Returns data about a specific observation index /// @param index The element of the observations array to fetch /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time /// ago, rather than at a specific index in the array. /// @return blockTimestamp The timestamp of the observation, /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp, /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp, /// Returns initialized whether the observation has been initialized and the values are safe to use function observations(uint256 index) external view returns ( uint32 blockTimestamp, int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128, bool initialized ); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.7; import "@openzeppelin/contracts/utils/Context.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; import "../interfaces/IAccessControl.sol"; /** * @dev This contract is fully forked from OpenZeppelin `AccessControl`. * The only difference is the removal of the ERC165 implementation as it's not * needed in Angle. * * Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControl is Context, IAccessControl { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role, _msgSender()); _; } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/ */ function _checkRole(bytes32 role, address account) internal view { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(uint160(account), 20), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external override { require(account == _msgSender(), "71"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== */ function _setupRole(bytes32 role, address account) internal { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal { emit RoleAdminChanged(role, getRoleAdmin(role), adminRole); _roles[role].adminRole = adminRole; } function _grantRole(bytes32 role, address account) internal { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } function _revokeRole(bytes32 role, address account) internal { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; /// @title IAccessControl /// @author Forked from OpenZeppelin /// @notice Interface for `AccessControl` contracts interface IAccessControl { function hasRole(bytes32 role, address account) external view returns (bool); function getRoleAdmin(bytes32 role) external view returns (bytes32); function grantRole(bytes32 role, address account) external; function revokeRole(bytes32 role, address account) external; function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; interface IERC721 is IERC165 { function balanceOf(address owner) external view returns (uint256 balance); function ownerOf(uint256 tokenId) external view returns (address owner); function safeTransferFrom( address from, address to, uint256 tokenId ) external; function transferFrom( address from, address to, uint256 tokenId ) external; function approve(address to, uint256 tokenId) external; function getApproved(uint256 tokenId) external view returns (address operator); function setApprovalForAll(address operator, bool _approved) external; function isApprovedForAll(address owner, address operator) external view returns (bool); function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; } interface IERC721Metadata is IERC721 { function name() external view returns (string memory); function symbol() external view returns (string memory); function tokenURI(uint256 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; import "./IAccessControl.sol"; /// @title IFeeManagerFunctions /// @author Angle Core Team /// @dev Interface for the `FeeManager` contract interface IFeeManagerFunctions is IAccessControl { // ================================= Keepers =================================== function updateUsersSLP() external; function updateHA() external; // ================================= Governance ================================ function deployCollateral( address[] memory governorList, address guardian, address _perpetualManager ) external; function setFees( uint256[] memory xArray, uint64[] memory yArray, uint8 typeChange ) external; function setHAFees(uint64 _haFeeDeposit, uint64 _haFeeWithdraw) external; } /// @title IFeeManager /// @author Angle Core Team /// @notice Previous interface with additionnal getters for public variables and mappings /// @dev We need these getters as they are used in other contracts of the protocol interface IFeeManager is IFeeManagerFunctions { function stableMaster() external view returns (address); function perpetualManager() external view returns (address); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; import "./IAccessControl.sol"; /// @title IGenericLender /// @author Yearn with slight modifications from Angle Core Team /// @dev Interface for the `GenericLender` contract, the base interface for contracts interacting /// with lending and yield farming platforms interface IGenericLender is IAccessControl { function lenderName() external view returns (string memory); function nav() external view returns (uint256); function strategy() external view returns (address); function apr() external view returns (uint256); function weightedApr() external view returns (uint256); function withdraw(uint256 amount) external returns (uint256); function emergencyWithdraw(uint256 amount) external; function deposit() external; function withdrawAll() external returns (bool); function hasAssets() external view returns (bool); function aprAfterDeposit(uint256 amount) external view returns (uint256); function sweep(address _token, address to) external; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; /// @title IOracle /// @author Angle Core Team /// @notice Interface for Angle's oracle contracts reading oracle rates from both UniswapV3 and Chainlink /// from just UniswapV3 or from just Chainlink interface IOracle { function read() external view returns (uint256); function readAll() external view returns (uint256 lowerRate, uint256 upperRate); function readLower() external view returns (uint256); function readUpper() external view returns (uint256); function readQuote(uint256 baseAmount) external view returns (uint256); function readQuoteLower(uint256 baseAmount) external view returns (uint256); function inBase() external view returns (uint256); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; import "./IERC721.sol"; import "./IFeeManager.sol"; import "./IOracle.sol"; import "./IAccessControl.sol"; /// @title Interface of the contract managing perpetuals /// @author Angle Core Team /// @dev Front interface, meaning only user-facing functions interface IPerpetualManagerFront is IERC721Metadata { function openPerpetual( address owner, uint256 amountBrought, uint256 amountCommitted, uint256 maxOracleRate, uint256 minNetMargin ) external returns (uint256 perpetualID); function closePerpetual( uint256 perpetualID, address to, uint256 minCashOutAmount ) external; function addToPerpetual(uint256 perpetualID, uint256 amount) external; function removeFromPerpetual( uint256 perpetualID, uint256 amount, address to ) external; function liquidatePerpetuals(uint256[] memory perpetualIDs) external; function forceClosePerpetuals(uint256[] memory perpetualIDs) external; // ========================= External View Functions ============================= function getCashOutAmount(uint256 perpetualID, uint256 rate) external view returns (uint256, uint256); function isApprovedOrOwner(address spender, uint256 perpetualID) external view returns (bool); } /// @title Interface of the contract managing perpetuals /// @author Angle Core Team /// @dev This interface does not contain user facing functions, it just has functions that are /// interacted with in other parts of the protocol interface IPerpetualManagerFunctions is IAccessControl { // ================================= Governance ================================ function deployCollateral( address[] memory governorList, address guardian, IFeeManager feeManager, IOracle oracle_ ) external; function setFeeManager(IFeeManager feeManager_) external; function setHAFees( uint64[] memory _xHAFees, uint64[] memory _yHAFees, uint8 deposit ) external; function setTargetAndLimitHAHedge(uint64 _targetHAHedge, uint64 _limitHAHedge) external; function setKeeperFeesLiquidationRatio(uint64 _keeperFeesLiquidationRatio) external; function setKeeperFeesCap(uint256 _keeperFeesLiquidationCap, uint256 _keeperFeesClosingCap) external; function setKeeperFeesClosing(uint64[] memory _xKeeperFeesClosing, uint64[] memory _yKeeperFeesClosing) external; function setLockTime(uint64 _lockTime) external; function setBoundsPerpetual(uint64 _maxLeverage, uint64 _maintenanceMargin) external; function pause() external; function unpause() external; // ==================================== Keepers ================================ function setFeeKeeper(uint64 feeDeposit, uint64 feesWithdraw) external; // =============================== StableMaster ================================ function setOracle(IOracle _oracle) external; } /// @title IPerpetualManager /// @author Angle Core Team /// @notice Previous interface with additionnal getters for public variables interface IPerpetualManager is IPerpetualManagerFunctions { function poolManager() external view returns (address); function oracle() external view returns (address); function targetHAHedge() external view returns (uint64); function totalHedgeAmount() external view returns (uint256); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; import "./IFeeManager.sol"; import "./IPerpetualManager.sol"; import "./IOracle.sol"; // Struct for the parameters associated to a strategy interacting with a collateral `PoolManager` // contract struct StrategyParams { // Timestamp of last report made by this strategy // It is also used to check if a strategy has been initialized uint256 lastReport; // Total amount the strategy is expected to have uint256 totalStrategyDebt; // The share of the total assets in the `PoolManager` contract that the `strategy` can access to. uint256 debtRatio; } /// @title IPoolManagerFunctions /// @author Angle Core Team /// @notice Interface for the collateral poolManager contracts handling each one type of collateral for /// a given stablecoin /// @dev Only the functions used in other contracts of the protocol are left here interface IPoolManagerFunctions { // ============================ Constructor ==================================== function deployCollateral( address[] memory governorList, address guardian, IPerpetualManager _perpetualManager, IFeeManager feeManager, IOracle oracle ) external; // ============================ Yield Farming ================================== function creditAvailable() external view returns (uint256); function debtOutstanding() external view returns (uint256); function report( uint256 _gain, uint256 _loss, uint256 _debtPayment ) external; // ============================ Governance ===================================== function addGovernor(address _governor) external; function removeGovernor(address _governor) external; function setGuardian(address _guardian, address guardian) external; function revokeGuardian(address guardian) external; function setFeeManager(IFeeManager _feeManager) external; // ============================= Getters ======================================= function getBalance() external view returns (uint256); function getTotalAsset() external view returns (uint256); } /// @title IPoolManager /// @author Angle Core Team /// @notice Previous interface with additionnal getters for public variables and mappings /// @dev Used in other contracts of the protocol interface IPoolManager is IPoolManagerFunctions { function stableMaster() external view returns (address); function perpetualManager() external view returns (address); function token() external view returns (address); function feeManager() external view returns (address); function totalDebt() external view returns (uint256); function strategies(address _strategy) external view returns (StrategyParams memory); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; import "./IAccessControl.sol"; /// @title IStrategy /// @author Inspired by Yearn with slight changes from Angle Core Team /// @notice Interface for yield farming strategies interface IStrategy is IAccessControl { function estimatedAPR() external view returns (uint256); function poolManager() external view returns (address); function want() external view returns (address); function isActive() external view returns (bool); function estimatedTotalAssets() external view returns (uint256); function harvestTrigger(uint256 callCost) external view returns (bool); function harvest() external; function withdraw(uint256 _amountNeeded) external returns (uint256 amountFreed, uint256 _loss); function setEmergencyExit() external; function addGuardian(address _guardian) external; function revokeGuardian(address _guardian) external; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; import "./BaseStrategyEvents.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; /// @title BaseStrategy /// @author Forked from https://github.com/yearn/yearn-managers/blob/master/contracts/BaseStrategy.sol /// @notice `BaseStrategy` implements all of the required functionalities to interoperate /// with the `PoolManager` Contract. /// @dev This contract should be inherited and the abstract methods implemented to adapt the `Strategy` /// to the particular needs it has to create a return. abstract contract BaseStrategy is BaseStrategyEvents, AccessControl { using SafeERC20 for IERC20; uint256 public constant BASE = 10**18; uint256 public constant SECONDSPERYEAR = 31556952; /// @notice Role for `PoolManager` only bytes32 public constant POOLMANAGER_ROLE = keccak256("POOLMANAGER_ROLE"); /// @notice Role for guardians and governors bytes32 public constant GUARDIAN_ROLE = keccak256("GUARDIAN_ROLE"); // ======================== References to contracts ============================ /// @notice Reference to the protocol's collateral `PoolManager` IPoolManager public poolManager; /// @notice Reference to the ERC20 farmed by this strategy IERC20 public want; /// @notice Base of the ERC20 token farmed by this strategy uint256 public wantBase; //@notice Reference to the ERC20 distributed as a reward by the strategy IERC20 public rewards; // ============================ Parameters ===================================== /// @notice The minimum number of seconds between harvest calls. See /// `setMinReportDelay()` for more details uint256 public minReportDelay; /// @notice The maximum number of seconds between harvest calls. See /// `setMaxReportDelay()` for more details uint256 public maxReportDelay; /// @notice Use this to adjust the threshold at which running a debt causes a /// harvest trigger. See `setDebtThreshold()` for more details uint256 public debtThreshold; /// @notice See note on `setEmergencyExit()` bool public emergencyExit; /// @notice The minimum amount moved for a call to `havest` to /// be "justifiable". See `setRewardAmountAndMinimumAmountMoved()` for more details uint256 public minimumAmountMoved; /// @notice Reward obtained by calling harvest /// @dev If this is null rewards is not currently being distributed uint256 public rewardAmount; // ============================ Constructor ==================================== /// @notice Constructor of the `BaseStrategy` /// @param _poolManager Address of the `PoolManager` lending collateral to this strategy /// @param _rewards The token given to reward keepers /// @param governorList List of the governor addresses of the protocol /// @param guardian Address of the guardian constructor( address _poolManager, IERC20 _rewards, address[] memory governorList, address guardian ) { poolManager = IPoolManager(_poolManager); want = IERC20(poolManager.token()); wantBase = 10**(IERC20Metadata(address(want)).decimals()); // The token given as a reward to keepers should be different from the token handled by the // strategy require(address(_rewards) != address(want), "92"); rewards = _rewards; // Initializing variables minReportDelay = 0; maxReportDelay = 86400; debtThreshold = 100 * BASE; minimumAmountMoved = 0; rewardAmount = 0; emergencyExit = false; // AccessControl // Governor is guardian so no need for a governor role // `PoolManager` is guardian as well to allow for more flexibility _setupRole(POOLMANAGER_ROLE, address(_poolManager)); for (uint256 i = 0; i < governorList.length; i++) { require(governorList[i] != address(0), "0"); _setupRole(GUARDIAN_ROLE, governorList[i]); } _setupRole(GUARDIAN_ROLE, guardian); _setRoleAdmin(POOLMANAGER_ROLE, POOLMANAGER_ROLE); _setRoleAdmin(GUARDIAN_ROLE, POOLMANAGER_ROLE); // Give `PoolManager` unlimited access (might save gas) want.safeIncreaseAllowance(address(poolManager), type(uint256).max); } // ========================== Core functions =================================== /// @notice Harvests the Strategy, recognizing any profits or losses and adjusting /// the Strategy's position. /// @dev In the rare case the Strategy is in emergency shutdown, this will exit /// the Strategy's position. /// @dev When `harvest()` is called, the Strategy reports to the Manager (via /// `poolManager.report()`), so in some cases `harvest()` must be called in order /// to take in profits, to borrow newly available funds from the Manager, or /// otherwise adjust its position. In other cases `harvest()` must be /// called to report to the Manager on the Strategy's position, especially if /// any losses have occurred. /// @dev As keepers may directly profit from this function, there may be front-running problems with miners bots, /// we may have to put an access control logic for this function to only allow white-listed addresses to act /// as keepers for the protocol function harvest() external { uint256 profit = 0; uint256 loss = 0; uint256 debtOutstanding = poolManager.debtOutstanding(); uint256 debtPayment = 0; if (emergencyExit) { // Free up as much capital as possible uint256 amountFreed = _liquidateAllPositions(); if (amountFreed < debtOutstanding) { loss = debtOutstanding - amountFreed; } else if (amountFreed > debtOutstanding) { profit = amountFreed - debtOutstanding; } debtPayment = debtOutstanding - loss; } else { // Free up returns for Manager to pull (profit, loss, debtPayment) = _prepareReturn(debtOutstanding); } emit Harvested(profit, loss, debtPayment, debtOutstanding); // Taking into account the rewards to distribute // This should be done before reporting to the `PoolManager` // because the `PoolManager` will update the params.lastReport of the strategy if (rewardAmount > 0) { uint256 lastReport = poolManager.strategies(address(this)).lastReport; if ( (block.timestamp - lastReport >= minReportDelay) && // Should not trigger if we haven't waited long enough since previous harvest ((block.timestamp - lastReport >= maxReportDelay) || // If hasn't been called in a while (debtPayment > debtThreshold) || // If the debt was too high (loss > 0) || // If some loss occured (minimumAmountMoved < want.balanceOf(address(this)) + profit)) // If the amount moved was significant ) { rewards.safeTransfer(msg.sender, rewardAmount); } } // Allows Manager to take up to the "harvested" balance of this contract, // which is the amount it has earned since the last time it reported to // the Manager. poolManager.report(profit, loss, debtPayment); // Check if free returns are left, and re-invest them _adjustPosition(); } /// @notice Withdraws `_amountNeeded` to `poolManager`. /// @param _amountNeeded How much `want` to withdraw. /// @return amountFreed How much `want` withdrawn. /// @return _loss Any realized losses /// @dev This may only be called by the `PoolManager` function withdraw(uint256 _amountNeeded) external onlyRole(POOLMANAGER_ROLE) returns (uint256 amountFreed, uint256 _loss) { // Liquidate as much as possible `want` (up to `_amountNeeded`) (amountFreed, _loss) = _liquidatePosition(_amountNeeded); // Send it directly back (NOTE: Using `msg.sender` saves some gas here) want.safeTransfer(msg.sender, amountFreed); // NOTE: Reinvest anything leftover on next `tend`/`harvest` } // ============================ View functions ================================= /// @notice Provides an accurate estimate for the total amount of assets /// (principle + return) that this Strategy is currently managing, /// denominated in terms of `want` tokens. /// This total should be "realizable" e.g. the total value that could /// *actually* be obtained from this Strategy if it were to divest its /// entire position based on current on-chain conditions. /// @return The estimated total assets in this Strategy. /// @dev Care must be taken in using this function, since it relies on external /// systems, which could be manipulated by the attacker to give an inflated /// (or reduced) value produced by this function, based on current on-chain /// conditions (e.g. this function is possible to influence through /// flashloan attacks, oracle manipulations, or other DeFi attack /// mechanisms). function estimatedTotalAssets() public view virtual returns (uint256); /// @notice Provides an indication of whether this strategy is currently "active" /// in that it is managing an active position, or will manage a position in /// the future. This should correlate to `harvest()` activity, so that Harvest /// events can be tracked externally by indexing agents. /// @return True if the strategy is actively managing a position. function isActive() public view returns (bool) { return estimatedTotalAssets() > 0; } /// @notice Provides a signal to the keeper that `harvest()` should be called. The /// keeper will provide the estimated gas cost that they would pay to call /// `harvest()`, and this function should use that estimate to make a /// determination if calling it is "worth it" for the keeper. This is not /// the only consideration into issuing this trigger, for example if the /// position would be negatively affected if `harvest()` is not called /// shortly, then this can return `true` even if the keeper might be "at a /// loss" /// @return `true` if `harvest()` should be called, `false` otherwise. /// @dev `callCostInWei` must be priced in terms of `wei` (1e-18 ETH). /// @dev See `min/maxReportDelay`, `debtThreshold` to adjust the /// strategist-controlled parameters that will influence whether this call /// returns `true` or not. These parameters will be used in conjunction /// with the parameters reported to the Manager (see `params`) to determine /// if calling `harvest()` is merited. /// @dev This function has been tested in a branch different from the main branch function harvestTrigger() external view virtual returns (bool) { StrategyParams memory params = poolManager.strategies(address(this)); // Should not trigger if we haven't waited long enough since previous harvest if (block.timestamp - params.lastReport < minReportDelay) return false; // Should trigger if hasn't been called in a while if (block.timestamp - params.lastReport >= maxReportDelay) return true; // If some amount is owed, pay it back // NOTE: Since debt is based on deposits, it makes sense to guard against large // changes to the value from triggering a harvest directly through user // behavior. This should ensure reasonable resistance to manipulation // from user-initiated withdrawals as the outstanding debt fluctuates. uint256 outstanding = poolManager.debtOutstanding(); if (outstanding > debtThreshold) return true; // Check for profits and losses uint256 total = estimatedTotalAssets(); // Trigger if we have a loss to report if (total + debtThreshold < params.totalStrategyDebt) return true; uint256 profit = 0; if (total > params.totalStrategyDebt) profit = total - params.totalStrategyDebt; // We've earned a profit! // Otherwise, only trigger if it "makes sense" economically (gas cost // is <N% of value moved) uint256 credit = poolManager.creditAvailable(); return (minimumAmountMoved < credit + profit); } // ============================ Internal Functions ============================= /// @notice Performs any Strategy unwinding or other calls necessary to capture the /// "free return" this Strategy has generated since the last time its core /// position(s) were adjusted. Examples include unwrapping extra rewards. /// This call is only used during "normal operation" of a Strategy, and /// should be optimized to minimize losses as much as possible. /// /// This method returns any realized profits and/or realized losses /// incurred, and should return the total amounts of profits/losses/debt /// payments (in `want` tokens) for the Manager's accounting (e.g. /// `want.balanceOf(this) >= _debtPayment + _profit`). /// /// `_debtOutstanding` will be 0 if the Strategy is not past the configured /// debt limit, otherwise its value will be how far past the debt limit /// the Strategy is. The Strategy's debt limit is configured in the Manager. /// /// NOTE: `_debtPayment` should be less than or equal to `_debtOutstanding`. /// It is okay for it to be less than `_debtOutstanding`, as that /// should only used as a guide for how much is left to pay back. /// Payments should be made to minimize loss from slippage, debt, /// withdrawal fees, etc. /// /// See `poolManager.debtOutstanding()`. function _prepareReturn(uint256 _debtOutstanding) internal virtual returns ( uint256 _profit, uint256 _loss, uint256 _debtPayment ); /// @notice Performs any adjustments to the core position(s) of this Strategy given /// what change the Manager made in the "investable capital" available to the /// Strategy. Note that all "free capital" in the Strategy after the report /// was made is available for reinvestment. Also note that this number /// could be 0, and you should handle that scenario accordingly. function _adjustPosition() internal virtual; /// @notice Liquidates up to `_amountNeeded` of `want` of this strategy's positions, /// irregardless of slippage. Any excess will be re-invested with `_adjustPosition()`. /// This function should return the amount of `want` tokens made available by the /// liquidation. If there is a difference between them, `_loss` indicates whether the /// difference is due to a realized loss, or if there is some other sitution at play /// (e.g. locked funds) where the amount made available is less than what is needed. /// /// NOTE: The invariant `_liquidatedAmount + _loss <= _amountNeeded` should always be maintained function _liquidatePosition(uint256 _amountNeeded) internal virtual returns (uint256 _liquidatedAmount, uint256 _loss); /// @notice Liquidates everything and returns the amount that got freed. /// This function is used during emergency exit instead of `_prepareReturn()` to /// liquidate all of the Strategy's positions back to the Manager. function _liquidateAllPositions() internal virtual returns (uint256 _amountFreed); /// @notice Override this to add all tokens/tokenized positions this contract /// manages on a *persistent* basis (e.g. not just for swapping back to /// want ephemerally). /// /// NOTE: Do *not* include `want`, already included in `sweep` below. /// /// Example: /// ``` /// function _protectedTokens() internal override view returns (address[] memory) { /// address[] memory protected = new address[](3); /// protected[0] = tokenA; /// protected[1] = tokenB; /// protected[2] = tokenC; /// return protected; /// } /// ``` function _protectedTokens() internal view virtual returns (address[] memory); // ============================== Governance =================================== /// @notice Activates emergency exit. Once activated, the Strategy will exit its /// position upon the next harvest, depositing all funds into the Manager as /// quickly as is reasonable given on-chain conditions. /// @dev This may only be called by the `PoolManager`, because when calling this the `PoolManager` should at the same /// time update the debt ratio /// @dev This function can only be called once by the `PoolManager` contract /// @dev See `poolManager.setEmergencyExit()` and `harvest()` for further details. function setEmergencyExit() external onlyRole(POOLMANAGER_ROLE) { emergencyExit = true; emit EmergencyExitActivated(); } /// @notice Used to change `rewards`. /// @param _rewards The address to use for pulling rewards. function setRewards(IERC20 _rewards) external onlyRole(GUARDIAN_ROLE) { require(address(_rewards) != address(0) && address(_rewards) != address(want), "92"); rewards = _rewards; emit UpdatedRewards(address(_rewards)); } /// @notice Used to change the reward amount and the `minimumAmountMoved` parameter /// @param _rewardAmount The new amount of reward given to keepers /// @param _minimumAmountMoved The new minimum amount of collateral moved for a call to `harvest` to be /// considered profitable and justifying a reward given to the keeper calling the function /// @dev A null reward amount corresponds to reward distribution being deactivated function setRewardAmountAndMinimumAmountMoved(uint256 _rewardAmount, uint256 _minimumAmountMoved) external onlyRole(GUARDIAN_ROLE) { rewardAmount = _rewardAmount; minimumAmountMoved = _minimumAmountMoved; emit UpdatedRewardAmountAndMinimumAmountMoved(_rewardAmount, _minimumAmountMoved); } /// @notice Used to change `minReportDelay`. `minReportDelay` is the minimum number /// of blocks that should pass for `harvest()` to be called. /// @param _delay The minimum number of seconds to wait between harvests. /// @dev For external keepers (such as the Keep3r network), this is the minimum /// time between jobs to wait. (see `harvestTrigger()` /// for more details.) function setMinReportDelay(uint256 _delay) external onlyRole(GUARDIAN_ROLE) { minReportDelay = _delay; emit UpdatedMinReportDelayed(_delay); } /// @notice Used to change `maxReportDelay`. `maxReportDelay` is the maximum number /// of blocks that should pass for `harvest()` to be called. /// @param _delay The maximum number of seconds to wait between harvests. /// @dev For external keepers (such as the Keep3r network), this is the maximum /// time between jobs to wait. (see `harvestTrigger()` /// for more details.) function setMaxReportDelay(uint256 _delay) external onlyRole(GUARDIAN_ROLE) { maxReportDelay = _delay; emit UpdatedMaxReportDelayed(_delay); } /// @notice Sets how far the Strategy can go into loss without a harvest and report /// being required. /// @param _debtThreshold How big of a loss this Strategy may carry without /// @dev By default this is 0, meaning any losses would cause a harvest which /// will subsequently report the loss to the Manager for tracking. (See /// `harvestTrigger()` for more details.) function setDebtThreshold(uint256 _debtThreshold) external onlyRole(GUARDIAN_ROLE) { debtThreshold = _debtThreshold; emit UpdatedDebtThreshold(_debtThreshold); } /// @notice Removes tokens from this Strategy that are not the type of tokens /// managed by this Strategy. This may be used in case of accidentally /// sending the wrong kind of token to this Strategy. /// /// Tokens will be sent to `governance()`. /// /// This will fail if an attempt is made to sweep `want`, or any tokens /// that are protected by this Strategy. /// /// This may only be called by governance. /// @param _token The token to transfer out of this `PoolManager`. /// @param to Address to send the tokens to. /// @dev /// Implement `_protectedTokens()` to specify any additional tokens that /// should be protected from sweeping in addition to `want`. function sweep(address _token, address to) external onlyRole(GUARDIAN_ROLE) { require(_token != address(want), "93"); address[] memory __protectedTokens = _protectedTokens(); for (uint256 i = 0; i < __protectedTokens.length; i++) // In the strategy we use so far, the only protectedToken is the want token // and this has been checked above require(_token != __protectedTokens[i], "93"); IERC20(_token).safeTransfer(to, IERC20(_token).balanceOf(address(this))); } // ============================ Manager functions ============================== /// @notice Adds a new guardian address and echoes the change to the contracts /// that interact with this collateral `PoolManager` /// @param _guardian New guardian address /// @dev This internal function has to be put in this file because Access Control is not defined /// in PoolManagerInternal function addGuardian(address _guardian) external virtual; /// @notice Revokes the guardian role and propagates the change to other contracts /// @param guardian Old guardian address to revoke function revokeGuardian(address guardian) external virtual; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "../external/AccessControl.sol"; import "../interfaces/IStrategy.sol"; import "../interfaces/IPoolManager.sol"; /// @title BaseStrategyEvents /// @author Angle Core Team /// @notice Events used in the abstract `BaseStrategy` contract contract BaseStrategyEvents { // So indexers can keep track of this event Harvested(uint256 profit, uint256 loss, uint256 debtPayment, uint256 debtOutstanding); event UpdatedMinReportDelayed(uint256 delay); event UpdatedMaxReportDelayed(uint256 delay); event UpdatedDebtThreshold(uint256 debtThreshold); event UpdatedRewards(address rewards); event UpdatedIsRewardActivated(bool activated); event UpdatedRewardAmountAndMinimumAmountMoved(uint256 _rewardAmount, uint256 _minimumAmountMoved); event EmergencyExitActivated(); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; import "./BaseStrategy.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/utils/Address.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; import "../interfaces/IGenericLender.sol"; import "../interfaces/IOracle.sol"; /// @title StrategyEvents /// @author Angle Core Team /// @notice Events used in `Strategy` contracts contract StrategyEvents { event AddLender(address indexed lender); event RemoveLender(address indexed lender); }
{ "evmVersion": "london", "libraries": {}, "metadata": { "bytecodeHash": "ipfs", "useLiteralContent": true }, "optimizer": { "enabled": true, "runs": 1000000 }, "remappings": [], "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_poolManager","type":"address"},{"internalType":"contract IERC20","name":"_rewards","type":"address"},{"internalType":"address[]","name":"governorList","type":"address[]"},{"internalType":"address","name":"guardian","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"lender","type":"address"}],"name":"AddLender","type":"event"},{"anonymous":false,"inputs":[],"name":"EmergencyExitActivated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"profit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"loss","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"debtPayment","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"debtOutstanding","type":"uint256"}],"name":"Harvested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"lender","type":"address"}],"name":"RemoveLender","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"debtThreshold","type":"uint256"}],"name":"UpdatedDebtThreshold","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"activated","type":"bool"}],"name":"UpdatedIsRewardActivated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"delay","type":"uint256"}],"name":"UpdatedMaxReportDelayed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"delay","type":"uint256"}],"name":"UpdatedMinReportDelayed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_rewardAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_minimumAmountMoved","type":"uint256"}],"name":"UpdatedRewardAmountAndMinimumAmountMoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"rewards","type":"address"}],"name":"UpdatedRewards","type":"event"},{"inputs":[],"name":"BASE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GUARDIAN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POOLMANAGER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SECONDSPERYEAR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_guardian","type":"address"}],"name":"addGuardian","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IGenericLender","name":"newLender","type":"address"}],"name":"addLender","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"debtThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"emergencyExit","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"estimatedAPR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"estimatedTotalAssets","outputs":[{"internalType":"uint256","name":"nav","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"lender","type":"address"}],"name":"forceRemoveLender","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"harvestTrigger","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lendStatuses","outputs":[{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"rate","type":"uint256"},{"internalType":"address","name":"add","type":"address"}],"internalType":"struct Strategy.LendStatus[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"lenders","outputs":[{"internalType":"contract IGenericLender","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lentTotalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"lender","type":"address"},{"internalType":"uint16","name":"share","type":"uint16"}],"internalType":"struct Strategy.LenderRatio[]","name":"_newPositions","type":"tuple[]"}],"name":"manualAllocation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"maxReportDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minReportDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumAmountMoved","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"numLenders","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolManager","outputs":[{"internalType":"contract IPoolManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"guardian","type":"address"}],"name":"revokeGuardian","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewards","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"lender","type":"address"}],"name":"safeRemoveLender","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_debtThreshold","type":"uint256"}],"name":"setDebtThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"setEmergencyExit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_delay","type":"uint256"}],"name":"setMaxReportDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_delay","type":"uint256"}],"name":"setMinReportDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_rewardAmount","type":"uint256"},{"internalType":"uint256","name":"_minimumAmountMoved","type":"uint256"}],"name":"setRewardAmountAndMinimumAmountMoved","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_rewards","type":"address"}],"name":"setRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_threshold","type":"uint256"}],"name":"setWithdrawalThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"to","type":"address"}],"name":"sweep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"want","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wantBase","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amountNeeded","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"amountFreed","type":"uint256"},{"internalType":"uint256","name":"_loss","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawalThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106102ff5760003560e01c80637a4b1c141161019c578063af648c3d116100ee578063ec38a86211610097578063f7b2a7be11610071578063f7b2a7be1461066b578063fcc5f59a14610674578063fcf2d0ad1461068957600080fd5b8063ec38a8621461063d578063efbb5cb014610650578063f017c92f1461065857600080fd5b8063d547741f116100c8578063d547741f146105fb578063dc4c90d31461060e578063ec342ad01461062e57600080fd5b8063af648c3d146105cd578063b8dc491b146105e0578063bb927c46146105f357600080fd5b806395e80c5011610150578063a217fddf1161012a578063a217fddf146105a7578063a526d83b146105af578063af306e16146105c257600080fd5b806395e80c50146105765780639987a78a1461057f5780639ec5a8941461058757600080fd5b806391d148541161018157806391d148541461050c578063929eea211461055057806393084b341461056357600080fd5b80637a4b1c14146104e65780638baf2957146104f957600080fd5b806328b7ccf7116102555780634641257d116102095780635a5cd45e116101e35780635a5cd45e146104c257806376ee75d8146104ca5780637985fd51146104dd57600080fd5b80634641257d1461049a5780634786b0cb146104a25780635641ec03146104b557600080fd5b80632f2ff15d1161023a5780632f2ff15d1461046157806336568abe1461047457806339a172a81461048757600080fd5b806328b7ccf7146104305780632e1a7d4d1461043957600080fd5b80631d12f28b116102b757806322f3e2d41161029157806322f3e2d4146103ce578063248a9ca3146103e657806324ea54f41461040957600080fd5b80631d12f28b146103775780631f1fcd51146103805780632270900b146103c557600080fd5b80630e6e15f0116102e85780630e6e15f0146103475780630f969b871461034f5780631919167a1461036457600080fd5b80630b6d1d17146103045780630c016dc014610320575b600080fd5b61030d60035481565b6040519081526020015b60405180910390f35b61030d7f5916f72c85af4ac6f7e34636ecc97619c4b2085da099a5d28f3e58436cfbe56281565b61030d610691565b61036261035d366004614469565b61077e565b005b6103626103723660046145ce565b6107e6565b61030d60075481565b6002546103a09073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610317565b61030d60095481565b6103d6610859565b6040519015158152602001610317565b61030d6103f4366004614469565b60009081526020819052604090206001015490565b61030d7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a504181565b61030d60065481565b61044c610447366004614469565b61086a565b60408051928352602083019190915201610317565b61036261046f366004614482565b6108d0565b610362610482366004614482565b6108fb565b610362610495366004614469565b61098d565b6103626109ed565b6103626104b0366004614469565b610db9565b6008546103d69060ff1681565b61030d610dea565b6103626104d83660046142eb565b610efc565b61030d600c5481565b6103626104f436600461435e565b610f32565b6103626105073660046142eb565b6113dc565b6103d661051a366004614482565b60009182526020828152604080842073ffffffffffffffffffffffffffffffffffffffff93909316845291905290205460ff1690565b6103a061055e366004614469565b611412565b6103626105713660046142eb565b611449565b61030d60055481565b6103d66116e5565b6004546103a09073ffffffffffffffffffffffffffffffffffffffff1681565b61030d600081565b6103626105bd3660046142eb565b61198c565b61030d6301e1855881565b6103626105db3660046142eb565b611ac8565b6103626105ee366004614325565b611c04565b600b5461030d565b610362610609366004614482565b611e4f565b6001546103a09073ffffffffffffffffffffffffffffffffffffffff1681565b61030d670de0b6b3a764000081565b61036261064b3660046142eb565b611e75565b61030d611fb9565b610362610666366004614469565b612072565b61030d600a5481565b61067c6120d2565b60405161031791906146d7565b610362612487565b600080805b600b5481101561077857600b81815481106106b3576106b36149c0565b60009182526020918290200154604080517fc1590cd7000000000000000000000000000000000000000000000000000000008152905173ffffffffffffffffffffffffffffffffffffffff9092169263c1590cd792600480840193829003018186803b15801561072257600080fd5b505afa158015610736573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075a91906145b5565b6107649083614821565b91508061077081614929565b915050610696565b50919050565b7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a50416107a981336126ad565b60078290556040518281527fa68ba126373d04c004c5748c300c9fca12bd444b3d4332e261f3bd2bac4a8600906020015b60405180910390a15050565b7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a504161081181336126ad565b600a839055600982905560408051848152602081018490527fdaff913ea4d37057da105d5a295361e69916b5d23e9b9344461783060ab1fde6910160405180910390a1505050565b600080610864611fb9565b11905090565b6000807f5916f72c85af4ac6f7e34636ecc97619c4b2085da099a5d28f3e58436cfbe56261089881336126ad565b6108a18461277d565b60025491945092506108ca9073ffffffffffffffffffffffffffffffffffffffff163385612876565b50915091565b6000828152602081905260409020600101546108ec81336126ad565b6108f683836128cc565b505050565b73ffffffffffffffffffffffffffffffffffffffff8116331461097f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f373100000000000000000000000000000000000000000000000000000000000060448201526064015b60405180910390fd5b61098982826129bc565b5050565b7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a50416109b881336126ad565b60058290556040518281527f587ccf9e93454be6553cb6b85ec1d488fb3179c5c5eff6738cb15083b890ae03906020016107da565b6000806000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663bf3759b56040518163ffffffff1660e01b815260040160206040518083038186803b158015610a5a57600080fd5b505afa158015610a6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a9291906145b5565b60085490915060009060ff1615610aef576000610aad612a73565b905082811015610ac857610ac181846148b1565b9350610add565b82811115610add57610ada83826148b1565b94505b610ae784846148b1565b915050610b00565b610af882612a85565b919550935090505b6040805185815260208101859052908101829052606081018390527f4c0f499ffe6befa0ca7c826b0916cf87bea98de658013e76938489368d60d5099060800160405180910390a1600a5415610d19576001546040517f39ebf82300000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906339ebf8239060240160606040518083038186803b158015610bba57600080fd5b505afa158015610bce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bf29190614559565b51600554909150610c0382426148b1565b10158015610ce85750600654610c1982426148b1565b101580610c27575060075482115b80610c325750600084115b80610ce857506002546040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152869173ffffffffffffffffffffffffffffffffffffffff16906370a082319060240160206040518083038186803b158015610ca157600080fd5b505afa158015610cb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd991906145b5565b610ce39190614821565b600954105b15610d1757600a54600454610d179173ffffffffffffffffffffffffffffffffffffffff909116903390612876565b505b6001546040517fa1d9bafc00000000000000000000000000000000000000000000000000000000815260048101869052602481018590526044810183905273ffffffffffffffffffffffffffffffffffffffff9091169063a1d9bafc90606401600060405180830381600087803b158015610d9357600080fd5b505af1158015610da7573d6000803e3d6000fd5b50505050610db3612e48565b50505050565b7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a5041610de481336126ad565b50600c55565b600080610df5611fb9565b905080610e0457600091505090565b6000805b600b54811015610eea57600b8181548110610e2557610e256149c0565b60009182526020918290200154604080517f116ac4a3000000000000000000000000000000000000000000000000000000008152905173ffffffffffffffffffffffffffffffffffffffff9092169263116ac4a392600480840193829003018186803b158015610e9457600080fd5b505afa158015610ea8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ecc91906145b5565b610ed69083614821565b915080610ee281614929565b915050610e08565b50610ef58282614839565b9250505090565b7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a5041610f2781336126ad565b6109898260016130f4565b7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a5041610f5d81336126ad565b6000600b805480602002602001604051908101604052809291908181526020018280548015610fc257602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311610f97575b505050505090506000805b825181101561108257828181518110610fe857610fe86149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1663853828b66040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561103757600080fd5b505af115801561104b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061106f9190614447565b508061107a81614929565b915050610fcd565b506002546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906370a082319060240160206040518083038186803b1580156110ed57600080fd5b505afa158015611101573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061112591906145b5565b905060005b8551811015611369576000805b85518110156111c157878381518110611152576111526149c0565b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff16868281518110611186576111866149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1614156111af57600191505b806111b981614929565b915050611137565b5080611229576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f39340000000000000000000000000000000000000000000000000000000000006044820152606401610976565b86828151811061123b5761123b6149c0565b60200260200101516020015161ffff16846112569190614821565b935060006103e888848151811061126f5761126f6149c0565b60200260200101516020015161ffff168561128a9190614874565b6112949190614839565b90506112d78884815181106112ab576112ab6149c0565b60209081029190910101515160025473ffffffffffffffffffffffffffffffffffffffff169083612876565b8783815181106112e9576112e96149c0565b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff1663d0e30db06040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561133c57600080fd5b505af1158015611350573d6000803e3d6000fd5b505050505050808061136190614929565b91505061112a565b50816103e8146113d5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f39350000000000000000000000000000000000000000000000000000000000006044820152606401610976565b5050505050565b7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a504161140781336126ad565b6109898260006130f4565b600b818154811061142257600080fd5b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff16905081565b7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a504161147481336126ad565b3073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1663a8c62e766040518163ffffffff1660e01b815260040160206040518083038186803b1580156114d157600080fd5b505afa1580156114e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115099190614308565b73ffffffffffffffffffffffffffffffffffffffff1614611586576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f39360000000000000000000000000000000000000000000000000000000000006044820152606401610976565b60005b600b5481101561164657600b81815481106115a6576115a66149c0565b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff84811691161415611634576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f39370000000000000000000000000000000000000000000000000000000000006044820152606401610976565b8061163e81614929565b915050611589565b50600b805460018101825560009182527f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db90180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff851690811790915560405190917f1e7b117a6591133f0b36fc2c24d59f8465d806fdcad63aa33246b45fd62c89ff91a25050565b6001546040517f39ebf823000000000000000000000000000000000000000000000000000000008152306004820152600091829173ffffffffffffffffffffffffffffffffffffffff909116906339ebf8239060240160606040518083038186803b15801561175357600080fd5b505afa158015611767573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061178b9190614559565b60055481519192509061179e90426148b1565b10156117ac57600091505090565b60065481516117bb90426148b1565b106117c857600191505090565b600154604080517fbf3759b5000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff169163bf3759b5916004808301926020929190829003018186803b15801561183357600080fd5b505afa158015611847573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061186b91906145b5565b90506007548111156118805760019250505090565b600061188a611fb9565b905082602001516007548261189f9190614821565b10156118af576001935050505090565b600083602001518211156118cf5760208401516118cc90836148b1565b90505b600154604080517f112c1f9b000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff169163112c1f9b916004808301926020929190829003018186803b15801561193a57600080fd5b505afa15801561194e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061197291906145b5565b905061197e8282614821565b600954109550505050505090565b7f5916f72c85af4ac6f7e34636ecc97619c4b2085da099a5d28f3e58436cfbe5626119b781336126ad565b6119e17f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a5041836128cc565b60005b600b548110156108f657600b8181548110611a0157611a016149c0565b6000918252602090912001546040517f2f2ff15d0000000000000000000000000000000000000000000000000000000081527f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a5041600482015273ffffffffffffffffffffffffffffffffffffffff858116602483015290911690632f2ff15d90604401600060405180830381600087803b158015611a9d57600080fd5b505af1158015611ab1573d6000803e3d6000fd5b505050508080611ac090614929565b9150506119e4565b7f5916f72c85af4ac6f7e34636ecc97619c4b2085da099a5d28f3e58436cfbe562611af381336126ad565b611b1d7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a5041836129bc565b60005b600b548110156108f657600b8181548110611b3d57611b3d6149c0565b6000918252602090912001546040517fd547741f0000000000000000000000000000000000000000000000000000000081527f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a5041600482015273ffffffffffffffffffffffffffffffffffffffff85811660248301529091169063d547741f90604401600060405180830381600087803b158015611bd957600080fd5b505af1158015611bed573d6000803e3d6000fd5b505050508080611bfc90614929565b915050611b20565b7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a5041611c2f81336126ad565b60025473ffffffffffffffffffffffffffffffffffffffff84811691161415611cb4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f39330000000000000000000000000000000000000000000000000000000000006044820152606401610976565b6000611cbe613531565b905060005b8151811015611d8d57818181518110611cde57611cde6149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161415611d7b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f39330000000000000000000000000000000000000000000000000000000000006044820152606401610976565b80611d8581614929565b915050611cc3565b506040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152610db390849073ffffffffffffffffffffffffffffffffffffffff8716906370a082319060240160206040518083038186803b158015611df957600080fd5b505afa158015611e0d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e3191906145b5565b73ffffffffffffffffffffffffffffffffffffffff87169190612876565b600082815260208190526040902060010154611e6b81336126ad565b6108f683836129bc565b7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a5041611ea081336126ad565b73ffffffffffffffffffffffffffffffffffffffff821615801590611ee0575060025473ffffffffffffffffffffffffffffffffffffffff838116911614155b611f46576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f39320000000000000000000000000000000000000000000000000000000000006044820152606401610976565b600480547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff84169081179091556040519081527fafbb66abf8f3b719799940473a4052a3717cdd8e40fb6c8a3faadab316b1a069906020016107da565b6002546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906370a082319060240160206040518083038186803b15801561202357600080fd5b505afa158015612037573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061205b91906145b5565b612063610691565b61206d9190614821565b905090565b7f55435dd261a4b9b3364963f7738a7a662ad9c84396d64be3365284bb7f0a504161209d81336126ad565b60068290556040518281527f7fd31e3883d9e7c41653edef31884ea4a1a984887df34a28f2315ddd15a5caf9906020016107da565b600b5460609060008167ffffffffffffffff8111156120f3576120f36149ef565b60405190808252806020026020018201604052801561216557816020015b6121526040518060800160405280606081526020016000815260200160008152602001600073ffffffffffffffffffffffffffffffffffffffff1681525090565b8152602001906001900390816121115790505b50905060005b82811015612480576121b46040518060800160405280606081526020016000815260200160008152602001600073ffffffffffffffffffffffffffffffffffffffff1681525090565b600b82815481106121c7576121c76149c0565b6000918252602082200154604080517f8b202176000000000000000000000000000000000000000000000000000000008152905173ffffffffffffffffffffffffffffffffffffffff90921692638b20217692600480840193829003018186803b15801561223457600080fd5b505afa158015612248573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820160405261228e91908101906144a7565b8152600b8054839081106122a4576122a46149c0565b60009182526020909120015473ffffffffffffffffffffffffffffffffffffffff166060820152600b8054839081106122df576122df6149c0565b60009182526020918290200154604080517fc1590cd7000000000000000000000000000000000000000000000000000000008152905173ffffffffffffffffffffffffffffffffffffffff9092169263c1590cd792600480840193829003018186803b15801561234e57600080fd5b505afa158015612362573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061238691906145b5565b6020820152600b80548390811061239f5761239f6149c0565b60009182526020918290200154604080517f57ded9c9000000000000000000000000000000000000000000000000000000008152905173ffffffffffffffffffffffffffffffffffffffff909216926357ded9c992600480840193829003018186803b15801561240e57600080fd5b505afa158015612422573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061244691906145b5565b604082015282518190849084908110612461576124616149c0565b602002602001018190525050808061247890614929565b91505061216b565b5092915050565b7f5916f72c85af4ac6f7e34636ecc97619c4b2085da099a5d28f3e58436cfbe5626124b281336126ad565b600880547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790556040517f17fa25a1c2ac074f71f0cf4f6af525c06fab7d83eff5ffcf6df5277f2919ae2490600090a150565b6040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff8381166024830152600091839186169063dd62ed3e9060440160206040518083038186803b15801561257b57600080fd5b505afa15801561258f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125b391906145b5565b6125bd9190614821565b60405173ffffffffffffffffffffffffffffffffffffffff8516602482015260448101829052909150610db39085907f095ea7b300000000000000000000000000000000000000000000000000000000906064015b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091526135ae565b60606126a384846000856136ba565b90505b9392505050565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16610989576127038173ffffffffffffffffffffffffffffffffffffffff16601461383a565b61270e83602061383a565b60405160200161271f929190614656565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290527f08c379a000000000000000000000000000000000000000000000000000000000825261097691600401614796565b6002546040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526000918291829173ffffffffffffffffffffffffffffffffffffffff16906370a082319060240160206040518083038186803b1580156127eb57600080fd5b505afa1580156127ff573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061282391906145b5565b905083811061283757509192600092509050565b60008161284c61284782886148b1565b613a7d565b6128569190614821565b905084811061286b5750929360009350915050565b946000945092505050565b60405173ffffffffffffffffffffffffffffffffffffffff83166024820152604481018290526108f69084907fa9059cbb0000000000000000000000000000000000000000000000000000000090606401612612565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff166109895760008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff85168452909152902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905561295e3390565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16156109895760008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000610778612a80611fb9565b61277d565b6000808281612a92610691565b6002546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015291925060009173ffffffffffffffffffffffffffffffffffffffff909116906370a082319060240160206040518083038186803b158015612b0157600080fd5b505afa158015612b15573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b3991906145b5565b90506000612b478383614821565b905082612b625781841115612b5a578193505b505050612e41565b6001546040517f39ebf82300000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906339ebf8239060240160606040518083038186803b158015612bcc57600080fd5b505afa158015612be0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c049190614559565b60200151905080821115612d2c57612c1c81836148b1565b96506000612c2a8689614821565b9050600081118015612c3b57508084105b15612d2657612c4d61284785836148b1565b506002546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906370a082319060240160206040518083038186803b158015612cb857600080fd5b505afa158015612ccc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cf091906145b5565b905081811015612d245780891115612d0e5780985060009650612d24565b612d21612d1b8a836148b1565b88613e35565b96505b505b50612e3c565b612d3682826148b1565b95506000612d448688614821565b9050600081118015612d5557508084105b15612e3a57612d6761284785836148b1565b506002546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906370a082319060240160206040518083038186803b158015612dd257600080fd5b505afa158015612de6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e0a91906145b5565b905081811015612e385780881115612e285780975060009650612e38565b612e35612d1b89836148b1565b96505b505b505b505050505b9193909250565b60085460ff1615612e5557565b6000600b805480602002602001604051908101604052809291908181526020018280548015612eba57602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311612e8f575b50505050509050805160001415612ece5750565b600080600080612edd85613e4b565b935093509350935082811115612f8857848481518110612eff57612eff6149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1663853828b66040518163ffffffff1660e01b8152600401602060405180830381600087803b158015612f4e57600080fd5b505af1158015612f62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f869190614447565b505b6002546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906370a082319060240160206040518083038186803b158015612ff257600080fd5b505afa158015613006573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061302a91906145b5565b905080156130ec57613072868481518110613047576130476149c0565b602090810291909101015160025473ffffffffffffffffffffffffffffffffffffffff169083612876565b858381518110613084576130846149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1663d0e30db06040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156130d357600080fd5b505af11580156130e7573d6000803e3d6000fd5b505050505b505050505050565b6000600b80548060200260200160405190810160405280929190818152602001828054801561315957602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff16815260019091019060200180831161312e575b5050505050905060005b81518110156134ce5781818151811061317e5761317e6149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1614156134bc5760008282815181106131cd576131cd6149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1663853828b66040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561321c57600080fd5b505af1158015613230573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132549190614447565b9050836132c257806132c2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f39380000000000000000000000000000000000000000000000000000000000006044820152606401610976565b600183516132d091906148b1565b82146133595782600184516132e591906148b1565b815181106132f5576132f56149c0565b6020026020010151600b8381548110613310576133106149c0565b9060005260206000200160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b600b80548061336a5761336a614991565b6000828152602081207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff908301810180547fffffffffffffffffffffffff00000000000000000000000000000000000000001690559091019091556002546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff909116906370a082319060240160206040518083038186803b15801561342e57600080fd5b505afa158015613442573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061346691906145b5565b111561347457613474612e48565b60405173ffffffffffffffffffffffffffffffffffffffff8616907f95c84dbc5fd872c46b0e4290775a1a4ea1c8d760f9e4d38f48ba71b6f9a667db90600090a25050505050565b806134c681614929565b915050613163565b506040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f39340000000000000000000000000000000000000000000000000000000000006044820152606401610976565b60408051600180825281830190925260609160009190602080830190803683375050600254825192935073ffffffffffffffffffffffffffffffffffffffff1691839150600090613584576135846149c0565b73ffffffffffffffffffffffffffffffffffffffff90921660209283029190910190910152919050565b6000613610826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff166126949092919063ffffffff16565b8051909150156108f6578080602001905181019061362e9190614447565b6108f6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610976565b60608247101561374c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610976565b843b6137b4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610976565b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516137dd919061463a565b60006040518083038185875af1925050503d806000811461381a576040519150601f19603f3d011682016040523d82523d6000602084013e61381f565b606091505b509150915061382f828286614298565b979650505050505050565b60606000613849836002614874565b613854906002614821565b67ffffffffffffffff81111561386c5761386c6149ef565b6040519080825280601f01601f191660200182016040528015613896576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106138cd576138cd6149c0565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110613930576139306149c0565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600061396c846002614874565b613977906001614821565b90505b6001811115613a14577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106139b8576139b86149c0565b1a60f81b8282815181106139ce576139ce6149c0565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c93613a0d816148f4565b905061397a565b5083156126a6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610976565b600080600b805480602002602001604051908101604052809291908181526020018280548015613ae357602002820191906000526020600020905b815473ffffffffffffffffffffffffffffffffffffffff168152600190910190602001808311613ab8575b50505050509050805160001415613afd5750600092915050565b600c54831015613b105750600092915050565b6000915060005b83831015613e2e577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000805b8451811015613ca757848181518110613b5f57613b5f6149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff16635be9b2d36040518163ffffffff1660e01b815260040160206040518083038186803b158015613bac57600080fd5b505afa158015613bc0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613be49190614447565b15613c95576000858281518110613bfd57613bfd6149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff166357ded9c96040518163ffffffff1660e01b815260040160206040518083038186803b158015613c4a57600080fd5b505afa158015613c5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c8291906145b5565b905083811015613c93578093508192505b505b80613c9f81614929565b915050613b44565b50838181518110613cba57613cba6149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff16635be9b2d36040518163ffffffff1660e01b815260040160206040518083038186803b158015613d0757600080fd5b505afa158015613d1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d3f9190614447565b613d4c5750505050919050565b838181518110613d5e57613d5e6149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff16632e1a7d4d8688613d8d91906148b1565b6040518263ffffffff1660e01b8152600401613dab91815260200190565b602060405180830381600087803b158015613dc557600080fd5b505af1158015613dd9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dfd91906145b5565b613e079086614821565b945082613e1381614929565b93505060068310613e275750505050919050565b5050613b17565b5050919050565b6000818310613e4457816126a6565b5090919050565b6002546040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152600091829182918291829173ffffffffffffffffffffffffffffffffffffffff16906370a082319060240160206040518083038186803b158015613ebd57600080fd5b505afa158015613ed1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ef591906145b5565b90507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9350600094506000806000945060005b88518110156141dc576000898281518110613f4557613f456149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1663149a4ae4866040518263ffffffff1660e01b8152600401613f8791815260200190565b60206040518083038186803b158015613f9f57600080fd5b505afa158015613fb3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613fd791906145b5565b905082811115613fe8578092508196505b898281518110613ffa57613ffa6149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff16635be9b2d36040518163ffffffff1660e01b815260040160206040518083038186803b15801561404757600080fd5b505afa15801561405b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061407f9190614447565b156141c95760008a8381518110614098576140986149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff166357ded9c96040518163ffffffff1660e01b815260040160206040518083038186803b1580156140e557600080fd5b505afa1580156140f9573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061411d91906145b5565b9050888110156141c7578098508299508a838151811061413f5761413f6149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1663c1590cd76040518163ffffffff1660e01b815260040160206040518083038186803b15801561418c57600080fd5b505afa1580156141a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141c491906145b5565b94505b505b50806141d481614929565b915050613f28565b508785815181106141ef576141ef6149c0565b602002602001015173ffffffffffffffffffffffffffffffffffffffff1663149a4ae4848461421e9190614821565b6040518263ffffffff1660e01b815260040161423c91815260200190565b60206040518083038186803b15801561425457600080fd5b505afa158015614268573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061428c91906145b5565b93505050509193509193565b606083156142a75750816126a6565b8251156142b75782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109769190614796565b6000602082840312156142fd57600080fd5b81356126a681614a1e565b60006020828403121561431a57600080fd5b81516126a681614a1e565b6000806040838503121561433857600080fd5b823561434381614a1e565b9150602083013561435381614a1e565b809150509250929050565b6000602080838503121561437157600080fd5b823567ffffffffffffffff8082111561438957600080fd5b818501915085601f83011261439d57600080fd5b8135818111156143af576143af6149ef565b6143bd848260051b016147d2565b8181528481019250838501600683901b850186018910156143dd57600080fd5b600094505b8285101561443b57604080828b0312156143fb57600080fd5b6144036147a9565b823561440e81614a1e565b81528288013561ffff8116811461442457600080fd5b8189015285526001959095019493860193016143e2565b50979650505050505050565b60006020828403121561445957600080fd5b815180151581146126a657600080fd5b60006020828403121561447b57600080fd5b5035919050565b6000806040838503121561449557600080fd5b82359150602083013561435381614a1e565b6000602082840312156144b957600080fd5b815167ffffffffffffffff808211156144d157600080fd5b818401915084601f8301126144e557600080fd5b8151818111156144f7576144f76149ef565b61452860207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116016147d2565b915080825285602082850101111561453f57600080fd5b6145508160208401602086016148c8565b50949350505050565b60006060828403121561456b57600080fd5b6040516060810181811067ffffffffffffffff8211171561458e5761458e6149ef565b80604052508251815260208301516020820152604083015160408201528091505092915050565b6000602082840312156145c757600080fd5b5051919050565b600080604083850312156145e157600080fd5b50508035926020909101359150565b600081518084526146088160208601602086016148c8565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6000825161464c8184602087016148c8565b9190910192915050565b7f416363657373436f6e74726f6c3a206163636f756e742000000000000000000081526000835161468e8160178501602088016148c8565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516146cb8160288401602088016148c8565b01602801949350505050565b60006020808301818452808551808352604092508286019150828160051b87010184880160005b83811015614788577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0898403018552815160808151818652614742828701826145f0565b838b0151878c0152898401518a88015260609384015173ffffffffffffffffffffffffffffffffffffffff169390960192909252505093860193908601906001016146fe565b509098975050505050505050565b6020815260006126a660208301846145f0565b6040805190810167ffffffffffffffff811182821017156147cc576147cc6149ef565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715614819576148196149ef565b604052919050565b6000821982111561483457614834614962565b500190565b60008261486f577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156148ac576148ac614962565b500290565b6000828210156148c3576148c3614962565b500390565b60005b838110156148e35781810151838201526020016148cb565b83811115610db35750506000910152565b60008161490357614903614962565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561495b5761495b614962565b5060010190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b73ffffffffffffffffffffffffffffffffffffffff81168114614a4057600080fd5b5056fea2646970667358221220657cead704b990e2bf05d8f6b506c3c175169e956948a9cc49c7a2d7cb49886d64736f6c63430008070033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.