Overview
S Balance
S Value
$0.00More Info
Private Name Tags
ContractCreator
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
9780254 | 12 hrs ago | Contract Creation | 0 S |
Loading...
Loading
Contract Name:
PoolQuotaKeeperV3
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 1000 runs
Other Settings:
london EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1 // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; pragma abicoder v1; import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; /// LIBS & TRAITS import {ACLNonReentrantTrait} from "../traits/ACLNonReentrantTrait.sol"; import {ContractsRegisterTrait} from "../traits/ContractsRegisterTrait.sol"; import {QuotasLogic} from "../libraries/QuotasLogic.sol"; import {IPoolV3} from "../interfaces/IPoolV3.sol"; import {IPoolQuotaKeeperV3, TokenQuotaParams, AccountQuota} from "../interfaces/IPoolQuotaKeeperV3.sol"; import {IGaugeV3} from "../interfaces/IGaugeV3.sol"; import {ICreditManagerV3} from "../interfaces/ICreditManagerV3.sol"; import {PERCENTAGE_FACTOR, RAY} from "@gearbox-protocol/core-v2/contracts/libraries/Constants.sol"; // EXCEPTIONS import "../interfaces/IExceptions.sol"; /// @title Pool quota keeper V3 /// @notice In Gearbox V3, quotas are used to limit the system exposure to risky assets. /// In order for a risky token to be counted towards credit account's collateral, account owner must "purchase" /// a quota for this token, which entails two kinds of payments: /// * interest that accrues over time with rates determined by the gauge (more suited to leveraged farming), and /// * increase fee that is charged when additional quota is purchased (more suited to leveraged trading). /// Quota keeper stores information about quotas of accounts in all credit managers connected to the pool, and /// performs calculations that help to keep pool's expected liquidity and credit managers' debt consistent. contract PoolQuotaKeeperV3 is IPoolQuotaKeeperV3, ACLNonReentrantTrait, ContractsRegisterTrait { using EnumerableSet for EnumerableSet.AddressSet; using QuotasLogic for TokenQuotaParams; /// @notice Contract version uint256 public constant override version = 3_00; /// @notice Address of the underlying token address public immutable override underlying; /// @notice Address of the pool address public immutable override pool; /// @dev The list of all allowed credit managers EnumerableSet.AddressSet internal creditManagerSet; /// @dev The list of all quoted tokens EnumerableSet.AddressSet internal quotaTokensSet; /// @notice Mapping from token to global token quota params mapping(address => TokenQuotaParams) internal totalQuotaParams; /// @dev Mapping from (creditAccount, token) to account's token quota params mapping(address => mapping(address => AccountQuota)) internal accountQuotas; /// @notice Address of the gauge address public override gauge; /// @notice Timestamp of the last quota rates update uint40 public override lastQuotaRateUpdate; /// @dev Ensures that function caller is gauge modifier gaugeOnly() { _revertIfCallerNotGauge(); _; } /// @dev Ensures that function caller is an allowed credit manager modifier creditManagerOnly() { _revertIfCallerNotCreditManager(); _; } /// @notice Constructor /// @param _pool Pool address constructor(address _pool) ACLNonReentrantTrait(IPoolV3(_pool).addressProvider()) ContractsRegisterTrait(IPoolV3(_pool).addressProvider()) { pool = _pool; // U:[PQK-1] underlying = IPoolV3(_pool).asset(); // U:[PQK-1] } // ----------------- // // QUOTAS MANAGEMENT // // ----------------- // /// @notice Updates credit account's quota for a token /// - Updates account's interest index /// - Updates account's quota by requested delta subject to the total quota limit (which is considered /// to be zero for tokens added to the quota keeper but not yet activated via `updateRates`) /// - Checks that the resulting quota is no less than the user-specified min desired value /// and no more than system-specified max allowed value /// - Updates pool's quota revenue /// @param creditAccount Credit account to update the quota for /// @param token Token to update the quota for /// @param requestedChange Requested quota change in pool's underlying asset units /// @param minQuota Minimum deisred quota amount /// @param maxQuota Maximum allowed quota amount /// @return caQuotaInterestChange Token quota interest accrued by account since the last update /// @return fees Quota increase fees, if any /// @return enableToken Whether the token needs to be enabled as collateral /// @return disableToken Whether the token needs to be disabled as collateral function updateQuota(address creditAccount, address token, int96 requestedChange, uint96 minQuota, uint96 maxQuota) external override creditManagerOnly // U:[PQK-4] returns (uint128 caQuotaInterestChange, uint128 fees, bool enableToken, bool disableToken) { int96 quotaChange; (caQuotaInterestChange, fees, quotaChange, enableToken, disableToken) = _updateQuota(creditAccount, token, requestedChange, minQuota, maxQuota); if (quotaChange != 0) { emit UpdateQuota({creditAccount: creditAccount, token: token, quotaChange: quotaChange}); } } /// @dev Implementation of `updateQuota` function _updateQuota(address creditAccount, address token, int96 requestedChange, uint96 minQuota, uint96 maxQuota) internal returns (uint128 caQuotaInterestChange, uint128 fees, int96 quotaChange, bool enableToken, bool disableToken) { AccountQuota storage accountQuota = accountQuotas[creditAccount][token]; TokenQuotaParams storage tokenQuotaParams = totalQuotaParams[token]; uint96 quoted = accountQuota.quota; (uint16 rate, uint192 tqCumulativeIndexLU, uint16 quotaIncreaseFee) = _getTokenQuotaParamsOrRevert(tokenQuotaParams); uint192 cumulativeIndexNow = QuotasLogic.cumulativeIndexSince(tqCumulativeIndexLU, rate, lastQuotaRateUpdate); // Accrued quota interest depends on the quota and thus must be computed before updating it caQuotaInterestChange = QuotasLogic.calcAccruedQuotaInterest(quoted, cumulativeIndexNow, accountQuota.cumulativeIndexLU); // U:[PQK-15] uint96 newQuoted; quotaChange = requestedChange; if (quotaChange > 0) { (uint96 totalQuoted, uint96 limit) = _getTokenQuotaTotalAndLimit(tokenQuotaParams); quotaChange = (rate == 0) ? int96(0) : QuotasLogic.calcActualQuotaChange(totalQuoted, limit, quotaChange); // U:[PQK-15] fees = uint128(uint256(uint96(quotaChange)) * quotaIncreaseFee / PERCENTAGE_FACTOR); // U:[PQK-15] newQuoted = quoted + uint96(quotaChange); if (quoted == 0 && newQuoted != 0) { enableToken = true; // U:[PQK-15] } tokenQuotaParams.totalQuoted = totalQuoted + uint96(quotaChange); // U:[PQK-15] } else { if (quotaChange == type(int96).min) { quotaChange = -int96(quoted); } uint96 absoluteChange = uint96(-quotaChange); newQuoted = quoted - absoluteChange; tokenQuotaParams.totalQuoted -= absoluteChange; // U:[PQK-15] if (quoted != 0 && newQuoted == 0) { disableToken = true; // U:[PQK-15] } } if (newQuoted < minQuota || newQuoted > maxQuota) revert QuotaIsOutOfBoundsException(); // U:[PQK-15] accountQuota.quota = newQuoted; // U:[PQK-15] accountQuota.cumulativeIndexLU = cumulativeIndexNow; // U:[PQK-15] int256 quotaRevenueChange = QuotasLogic.calcQuotaRevenueChange(rate, int256(quotaChange)); // U:[PQK-15] if (quotaRevenueChange != 0) { IPoolV3(pool).updateQuotaRevenue(quotaRevenueChange); // U:[PQK-15] } } /// @notice Removes credit account's quotas for provided tokens /// - Sets account's tokens quotas to zero /// - Optionally sets quota limits for tokens to zero, effectively preventing further exposure /// to them in extreme cases (e.g., liquidations with loss) /// - Does not update account's interest indexes (can be skipped since quotas are zero) /// - Decreases pool's quota revenue /// @param creditAccount Credit account to remove quotas for /// @param tokens Array of tokens to remove quotas for /// @param setLimitsToZero Whether tokens quota limits should be set to zero function removeQuotas(address creditAccount, address[] calldata tokens, bool setLimitsToZero) external override creditManagerOnly // U:[PQK-4] { int256 quotaRevenueChange; uint256 len = tokens.length; for (uint256 i; i < len;) { address token = tokens[i]; AccountQuota storage accountQuota = accountQuotas[creditAccount][token]; TokenQuotaParams storage tokenQuotaParams = totalQuotaParams[token]; uint96 quoted = accountQuota.quota; if (quoted != 0) { uint16 rate = tokenQuotaParams.rate; quotaRevenueChange += QuotasLogic.calcQuotaRevenueChange(rate, -int256(uint256(quoted))); // U:[PQK-16] tokenQuotaParams.totalQuoted -= quoted; // U:[PQK-16] accountQuota.quota = 0; // U:[PQK-16] emit UpdateQuota({creditAccount: creditAccount, token: token, quotaChange: -int96(quoted)}); } if (setLimitsToZero) { _setTokenLimit({tokenQuotaParams: tokenQuotaParams, token: token, limit: 0}); // U:[PQK-16] } unchecked { ++i; } } if (quotaRevenueChange != 0) { IPoolV3(pool).updateQuotaRevenue(quotaRevenueChange); // U:[PQK-16] } } /// @notice Updates credit account's interest indexes for provided tokens /// @param creditAccount Credit account to accrue interest for /// @param tokens Array tokens to accrue interest for function accrueQuotaInterest(address creditAccount, address[] calldata tokens) external override creditManagerOnly // U:[PQK-4] { uint256 len = tokens.length; uint40 lastQuotaRateUpdate_ = lastQuotaRateUpdate; unchecked { for (uint256 i; i < len; ++i) { address token = tokens[i]; AccountQuota storage accountQuota = accountQuotas[creditAccount][token]; TokenQuotaParams storage tokenQuotaParams = totalQuotaParams[token]; (uint16 rate, uint192 tqCumulativeIndexLU,) = _getTokenQuotaParamsOrRevert(tokenQuotaParams); // U:[PQK-17] accountQuota.cumulativeIndexLU = QuotasLogic.cumulativeIndexSince(tqCumulativeIndexLU, rate, lastQuotaRateUpdate_); // U:[PQK-17] } } } /// @notice Returns credit account's token quota and interest accrued since the last update /// @param creditAccount Account to compute the values for /// @param token Token to compute the values for /// @return quoted Account's token quota /// @return outstandingInterest Quota interest accrued since the last update function getQuotaAndOutstandingInterest(address creditAccount, address token) external view override returns (uint96 quoted, uint128 outstandingInterest) { AccountQuota storage accountQuota = accountQuotas[creditAccount][token]; uint192 cumulativeIndexNow = cumulativeIndex(token); quoted = accountQuota.quota; uint192 aqCumulativeIndexLU = accountQuota.cumulativeIndexLU; outstandingInterest = QuotasLogic.calcAccruedQuotaInterest(quoted, cumulativeIndexNow, aqCumulativeIndexLU); // U:[PQK-15] } /// @notice Returns current quota interest index for a token in ray function cumulativeIndex(address token) public view override returns (uint192) { TokenQuotaParams storage tokenQuotaParams = totalQuotaParams[token]; (uint16 rate, uint192 tqCumulativeIndexLU,) = _getTokenQuotaParamsOrRevert(tokenQuotaParams); return QuotasLogic.cumulativeIndexSince(tqCumulativeIndexLU, rate, lastQuotaRateUpdate); } /// @notice Returns quota interest rate for a token in bps function getQuotaRate(address token) external view override returns (uint16) { return totalQuotaParams[token].rate; } /// @notice Returns an array of all quoted tokens function quotedTokens() external view override returns (address[] memory) { return quotaTokensSet.values(); } /// @notice Whether a token is quoted function isQuotedToken(address token) external view override returns (bool) { return quotaTokensSet.contains(token); } /// @notice Returns account's quota params for a token function getQuota(address creditAccount, address token) external view override returns (uint96 quota, uint192 cumulativeIndexLU) { AccountQuota storage aq = accountQuotas[creditAccount][token]; return (aq.quota, aq.cumulativeIndexLU); } /// @notice Returns global quota params for a token function getTokenQuotaParams(address token) external view override returns ( uint16 rate, uint192 cumulativeIndexLU, uint16 quotaIncreaseFee, uint96 totalQuoted, uint96 limit, bool isActive ) { TokenQuotaParams memory tq = totalQuotaParams[token]; rate = tq.rate; cumulativeIndexLU = tq.cumulativeIndexLU; quotaIncreaseFee = tq.quotaIncreaseFee; totalQuoted = tq.totalQuoted; limit = tq.limit; isActive = rate != 0; } /// @notice Returns the pool's quota revenue (in units of underlying per year) function poolQuotaRevenue() external view virtual override returns (uint256 quotaRevenue) { address[] memory tokens = quotaTokensSet.values(); uint256 len = tokens.length; for (uint256 i; i < len;) { address token = tokens[i]; TokenQuotaParams storage tokenQuotaParams = totalQuotaParams[token]; (uint16 rate,,) = _getTokenQuotaParamsOrRevert(tokenQuotaParams); (uint256 totalQuoted,) = _getTokenQuotaTotalAndLimit(tokenQuotaParams); quotaRevenue += totalQuoted * rate / PERCENTAGE_FACTOR; unchecked { ++i; } } } /// @notice Returns the list of allowed credit managers function creditManagers() external view override returns (address[] memory) { return creditManagerSet.values(); // U:[PQK-10] } // ------------- // // CONFIGURATION // // ------------- // /// @notice Adds a new quota token /// @param token Address of the token function addQuotaToken(address token) external override gaugeOnly // U:[PQK-3] { if (quotaTokensSet.contains(token)) { revert TokenAlreadyAddedException(); // U:[PQK-6] } // The rate will be set during a general epoch update in the gauge quotaTokensSet.add(token); // U:[PQK-5] totalQuotaParams[token].cumulativeIndexLU = 1; // U:[PQK-5] emit AddQuotaToken(token); // U:[PQK-5] } /// @notice Updates quota rates /// - Updates global token cumulative indexes before changing rates /// - Queries new rates for all quoted tokens from the gauge /// - Sets new pool quota revenue function updateRates() external override gaugeOnly // U:[PQK-3] { address[] memory tokens = quotaTokensSet.values(); uint16[] memory rates = IGaugeV3(gauge).getRates(tokens); // U:[PQK-7] uint256 quotaRevenue; uint256 timestampLU = lastQuotaRateUpdate; uint256 len = tokens.length; for (uint256 i; i < len;) { address token = tokens[i]; uint16 rate = rates[i]; TokenQuotaParams storage tokenQuotaParams = totalQuotaParams[token]; // U:[PQK-7] (uint16 prevRate, uint192 tqCumulativeIndexLU,) = _getTokenQuotaParamsOrRevert(tokenQuotaParams); tokenQuotaParams.cumulativeIndexLU = QuotasLogic.cumulativeIndexSince(tqCumulativeIndexLU, prevRate, timestampLU); // U:[PQK-7] tokenQuotaParams.rate = rate; // U:[PQK-7] quotaRevenue += uint256(tokenQuotaParams.totalQuoted) * rate / PERCENTAGE_FACTOR; // U:[PQK-7] emit UpdateTokenQuotaRate(token, rate); // U:[PQK-7] unchecked { ++i; } } IPoolV3(pool).setQuotaRevenue(quotaRevenue); // U:[PQK-7] lastQuotaRateUpdate = uint40(block.timestamp); // U:[PQK-7] } /// @notice Sets a new gauge contract to compute quota rates /// @param _gauge Address of the new gauge contract function setGauge(address _gauge) external override configuratorOnly // U:[PQK-2] { if (gauge != _gauge) { gauge = _gauge; // U:[PQK-8] emit SetGauge(_gauge); // U:[PQK-8] } } /// @notice Adds an address to the set of allowed credit managers /// @param _creditManager Address of the new credit manager function addCreditManager(address _creditManager) external override configuratorOnly // U:[PQK-2] nonZeroAddress(_creditManager) registeredCreditManagerOnly(_creditManager) // U:[PQK-9] { if (ICreditManagerV3(_creditManager).pool() != pool) { revert IncompatibleCreditManagerException(); // U:[PQK-9] } if (!creditManagerSet.contains(_creditManager)) { creditManagerSet.add(_creditManager); // U:[PQK-10] emit AddCreditManager(_creditManager); // U:[PQK-10] } } /// @notice Sets the total quota limit for a token /// @param token Address of token to set the limit for /// @param limit The limit to set function setTokenLimit(address token, uint96 limit) external override controllerOnly // U:[PQK-2] { TokenQuotaParams storage tokenQuotaParams = totalQuotaParams[token]; _setTokenLimit(tokenQuotaParams, token, limit); } /// @dev Implementation of `setTokenLimit` function _setTokenLimit(TokenQuotaParams storage tokenQuotaParams, address token, uint96 limit) internal { if (!isInitialised(tokenQuotaParams)) { revert TokenIsNotQuotedException(); // U:[PQK-11] } if (tokenQuotaParams.limit != limit) { tokenQuotaParams.limit = limit; // U:[PQK-12] emit SetTokenLimit(token, limit); // U:[PQK-12] } } /// @notice Sets the one-time quota increase fee for a token /// @param token Token to set the fee for /// @param fee The new fee value in bps function setTokenQuotaIncreaseFee(address token, uint16 fee) external override controllerOnly // U:[PQK-2] { if (fee > PERCENTAGE_FACTOR) { revert IncorrectParameterException(); } TokenQuotaParams storage tokenQuotaParams = totalQuotaParams[token]; // U:[PQK-13] if (!isInitialised(tokenQuotaParams)) { revert TokenIsNotQuotedException(); } if (tokenQuotaParams.quotaIncreaseFee != fee) { tokenQuotaParams.quotaIncreaseFee = fee; // U:[PQK-13] emit SetQuotaIncreaseFee(token, fee); // U:[PQK-13] } } // --------- // // INTERNALS // // --------- // /// @dev Whether quota params for token are initialized function isInitialised(TokenQuotaParams storage tokenQuotaParams) internal view returns (bool) { return tokenQuotaParams.cumulativeIndexLU != 0; } /// @dev Efficiently loads quota params of a token from storage function _getTokenQuotaParamsOrRevert(TokenQuotaParams storage tokenQuotaParams) internal view returns (uint16 rate, uint192 cumulativeIndexLU, uint16 quotaIncreaseFee) { // rate = tokenQuotaParams.rate; // cumulativeIndexLU = tokenQuotaParams.cumulativeIndexLU; // quotaIncreaseFee = tokenQuotaParams.quotaIncreaseFee; assembly { let data := sload(tokenQuotaParams.slot) rate := and(data, 0xFFFF) cumulativeIndexLU := and(shr(16, data), 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) quotaIncreaseFee := shr(208, data) } if (cumulativeIndexLU == 0) { revert TokenIsNotQuotedException(); // U:[PQK-14] } } /// @dev Efficiently loads quota and limit of a token from storage function _getTokenQuotaTotalAndLimit(TokenQuotaParams storage tokenQuotaParams) internal view returns (uint96 totalQuoted, uint96 limit) { // totalQuoted = tokenQuotaParams.totalQuoted; // limit = tokenQuotaParams.limit; assembly { let data := sload(add(tokenQuotaParams.slot, 1)) totalQuoted := and(data, 0xFFFFFFFFFFFFFFFFFFFFFFFF) limit := shr(96, data) } } /// @dev Reverts if `msg.sender` is not an allowed credit manager function _revertIfCallerNotCreditManager() internal view { if (!creditManagerSet.contains(msg.sender)) { revert CallerNotCreditManagerException(); // U:[PQK-4] } } /// @dev Reverts if `msg.sender` is not gauge function _revertIfCallerNotGauge() internal view { if (msg.sender != gauge) revert CallerNotGaugeException(); // U:[PQK-3] } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ```solidity * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSet { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
// SPDX-License-Identifier: BUSL-1.1 // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol"; import {IACL} from "@gearbox-protocol/core-v2/contracts/interfaces/IACL.sol"; import { CallerNotControllerException, CallerNotPausableAdminException, CallerNotUnpausableAdminException } from "../interfaces/IExceptions.sol"; import {ACLTrait} from "./ACLTrait.sol"; import {ReentrancyGuardTrait} from "./ReentrancyGuardTrait.sol"; /// @title ACL non-reentrant trait /// @notice Extended version of `ACLTrait` that implements pausable functionality, /// reentrancy protection and external controller role abstract contract ACLNonReentrantTrait is ACLTrait, Pausable, ReentrancyGuardTrait { /// @notice Emitted when new external controller is set event NewController(address indexed newController); /// @notice External controller address address public controller; /// @dev Ensures that function caller is external controller or configurator modifier controllerOnly() { _ensureCallerIsControllerOrConfigurator(); _; } /// @dev Reverts if the caller is not controller or configurator /// @dev Used to cut contract size on modifiers function _ensureCallerIsControllerOrConfigurator() internal view { if (msg.sender != controller && !_isConfigurator({account: msg.sender})) { revert CallerNotControllerException(); } } /// @dev Ensures that function caller has pausable admin role modifier pausableAdminsOnly() { _ensureCallerIsPausableAdmin(); _; } /// @dev Reverts if the caller is not pausable admin /// @dev Used to cut contract size on modifiers function _ensureCallerIsPausableAdmin() internal view { if (!_isPausableAdmin({account: msg.sender})) { revert CallerNotPausableAdminException(); } } /// @dev Ensures that function caller has unpausable admin role modifier unpausableAdminsOnly() { _ensureCallerIsUnpausableAdmin(); _; } /// @dev Reverts if the caller is not unpausable admin /// @dev Used to cut contract size on modifiers function _ensureCallerIsUnpausableAdmin() internal view { if (!_isUnpausableAdmin({account: msg.sender})) { revert CallerNotUnpausableAdminException(); } } /// @notice Constructor /// @param addressProvider Address provider contract address constructor(address addressProvider) ACLTrait(addressProvider) { controller = IACL(acl).owner(); } /// @notice Pauses contract, can only be called by an account with pausable admin role function pause() external virtual pausableAdminsOnly { _pause(); } /// @notice Unpauses contract, can only be called by an account with unpausable admin role function unpause() external virtual unpausableAdminsOnly { _unpause(); } /// @notice Sets new external controller, can only be called by configurator function setController(address newController) external configuratorOnly { if (controller == newController) return; controller = newController; emit NewController(newController); } /// @dev Checks whether given account has pausable admin role function _isPausableAdmin(address account) internal view returns (bool) { return IACL(acl).isPausableAdmin(account); } /// @dev Checks whether given account has unpausable admin role function _isUnpausableAdmin(address account) internal view returns (bool) { return IACL(acl).isUnpausableAdmin(account); } }
// SPDX-License-Identifier: BUSL-1.1 // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; import {IContractsRegister} from "@gearbox-protocol/core-v2/contracts/interfaces/IContractsRegister.sol"; import {AP_CONTRACTS_REGISTER, IAddressProviderV3, NO_VERSION_CONTROL} from "../interfaces/IAddressProviderV3.sol"; import {RegisteredCreditManagerOnlyException, RegisteredPoolOnlyException} from "../interfaces/IExceptions.sol"; import {SanityCheckTrait} from "./SanityCheckTrait.sol"; /// @title Contracts register trait /// @notice Trait that simplifies validation of pools and credit managers abstract contract ContractsRegisterTrait is SanityCheckTrait { /// @notice Contracts register contract address address public immutable contractsRegister; /// @dev Ensures that given address is a registered credit manager modifier registeredPoolOnly(address addr) { _ensureRegisteredPool(addr); _; } /// @dev Ensures that given address is a registered pool modifier registeredCreditManagerOnly(address addr) { _ensureRegisteredCreditManager(addr); _; } /// @notice Constructor /// @param addressProvider Address provider contract address constructor(address addressProvider) nonZeroAddress(addressProvider) { contractsRegister = IAddressProviderV3(addressProvider).getAddressOrRevert(AP_CONTRACTS_REGISTER, NO_VERSION_CONTROL); } /// @dev Ensures that given address is a registered pool function _ensureRegisteredPool(address addr) internal view { if (!_isRegisteredPool(addr)) revert RegisteredPoolOnlyException(); } /// @dev Ensures that given address is a registered credit manager function _ensureRegisteredCreditManager(address addr) internal view { if (!_isRegisteredCreditManager(addr)) revert RegisteredCreditManagerOnlyException(); } /// @dev Whether given address is a registered pool function _isRegisteredPool(address addr) internal view returns (bool) { return IContractsRegister(contractsRegister).isPool(addr); } /// @dev Whether given address is a registered credit manager function _isRegisteredCreditManager(address addr) internal view returns (bool) { return IContractsRegister(contractsRegister).isCreditManager(addr); } }
// SPDX-License-Identifier: BUSL-1.1 // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {RAY, SECONDS_PER_YEAR, PERCENTAGE_FACTOR} from "@gearbox-protocol/core-v2/contracts/libraries/Constants.sol"; uint192 constant RAY_DIVIDED_BY_PERCENTAGE = uint192(RAY / PERCENTAGE_FACTOR); /// @title Quotas logic library library QuotasLogic { using SafeCast for uint256; /// @dev Computes the new interest index value, given the previous value, the interest rate, and time delta /// @dev Unlike pool's base interest, interest on quotas is not compounding, so additive index is used function cumulativeIndexSince(uint192 cumulativeIndexLU, uint16 rate, uint256 lastQuotaRateUpdate) internal view returns (uint192) { return uint192( uint256(cumulativeIndexLU) + RAY_DIVIDED_BY_PERCENTAGE * (block.timestamp - lastQuotaRateUpdate) * rate / SECONDS_PER_YEAR ); // U:[QL-1] } /// @dev Computes interest accrued on the quota since the last update function calcAccruedQuotaInterest(uint96 quoted, uint192 cumulativeIndexNow, uint192 cumulativeIndexLU) internal pure returns (uint128) { // `quoted` is `uint96`, and `cumulativeIndex / RAY` won't reach `2 ** 32` in reasonable time, so casting is safe return uint128(uint256(quoted) * (cumulativeIndexNow - cumulativeIndexLU) / RAY); // U:[QL-2] } /// @dev Computes the pool quota revenue change given the current rate and the quota change function calcQuotaRevenueChange(uint16 rate, int256 change) internal pure returns (int256) { return change * int256(uint256(rate)) / int16(PERCENTAGE_FACTOR); } /// @dev Upper-bounds requested quota increase such that the resulting total quota doesn't exceed the limit function calcActualQuotaChange(uint96 totalQuoted, uint96 limit, int96 requestedChange) internal pure returns (int96 quotaChange) { if (totalQuoted >= limit) { return 0; } unchecked { uint96 maxQuotaCapacity = limit - totalQuoted; // The function is never called with `requestedChange < 0`, so casting it to `uint96` is safe // With correct configuration, `limit < type(int96).max`, so casting `maxQuotaCapacity` to `int96` is safe return uint96(requestedChange) > maxQuotaCapacity ? int96(maxQuotaCapacity) : requestedChange; } } }
// SPDX-License-Identifier: MIT // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; pragma abicoder v1; import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol"; import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol"; import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.sol"; interface IPoolV3Events { /// @notice Emitted when depositing liquidity with referral code event Refer(address indexed onBehalfOf, uint256 indexed referralCode, uint256 amount); /// @notice Emitted when credit account borrows funds from the pool event Borrow(address indexed creditManager, address indexed creditAccount, uint256 amount); /// @notice Emitted when credit account's debt is repaid to the pool event Repay(address indexed creditManager, uint256 borrowedAmount, uint256 profit, uint256 loss); /// @notice Emitted when incurred loss can't be fully covered by burning treasury's shares event IncurUncoveredLoss(address indexed creditManager, uint256 loss); /// @notice Emitted when new interest rate model contract is set event SetInterestRateModel(address indexed newInterestRateModel); /// @notice Emitted when new pool quota keeper contract is set event SetPoolQuotaKeeper(address indexed newPoolQuotaKeeper); /// @notice Emitted when new total debt limit is set event SetTotalDebtLimit(uint256 limit); /// @notice Emitted when new credit manager is connected to the pool event AddCreditManager(address indexed creditManager); /// @notice Emitted when new debt limit is set for a credit manager event SetCreditManagerDebtLimit(address indexed creditManager, uint256 newLimit); /// @notice Emitted when new withdrawal fee is set event SetWithdrawFee(uint256 fee); } /// @title Pool V3 interface interface IPoolV3 is IVersion, IPoolV3Events, IERC4626, IERC20Permit { function addressProvider() external view returns (address); function underlyingToken() external view returns (address); function treasury() external view returns (address); function withdrawFee() external view returns (uint16); function creditManagers() external view returns (address[] memory); function availableLiquidity() external view returns (uint256); function expectedLiquidity() external view returns (uint256); function expectedLiquidityLU() external view returns (uint256); // ---------------- // // ERC-4626 LENDING // // ---------------- // function depositWithReferral(uint256 assets, address receiver, uint256 referralCode) external returns (uint256 shares); function mintWithReferral(uint256 shares, address receiver, uint256 referralCode) external returns (uint256 assets); // --------- // // BORROWING // // --------- // function totalBorrowed() external view returns (uint256); function totalDebtLimit() external view returns (uint256); function creditManagerBorrowed(address creditManager) external view returns (uint256); function creditManagerDebtLimit(address creditManager) external view returns (uint256); function creditManagerBorrowable(address creditManager) external view returns (uint256 borrowable); function lendCreditAccount(uint256 borrowedAmount, address creditAccount) external; function repayCreditAccount(uint256 repaidAmount, uint256 profit, uint256 loss) external; // ------------- // // INTEREST RATE // // ------------- // function interestRateModel() external view returns (address); function baseInterestRate() external view returns (uint256); function supplyRate() external view returns (uint256); function baseInterestIndex() external view returns (uint256); function baseInterestIndexLU() external view returns (uint256); function lastBaseInterestUpdate() external view returns (uint40); // ------ // // QUOTAS // // ------ // function poolQuotaKeeper() external view returns (address); function quotaRevenue() external view returns (uint256); function lastQuotaRevenueUpdate() external view returns (uint40); function updateQuotaRevenue(int256 quotaRevenueDelta) external; function setQuotaRevenue(uint256 newQuotaRevenue) external; // ------------- // // CONFIGURATION // // ------------- // function setInterestRateModel(address newInterestRateModel) external; function setPoolQuotaKeeper(address newPoolQuotaKeeper) external; function setTotalDebtLimit(uint256 newLimit) external; function setCreditManagerDebtLimit(address creditManager, uint256 newLimit) external; function setWithdrawFee(uint256 newWithdrawFee) external; }
// SPDX-License-Identifier: MIT // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.sol"; struct TokenQuotaParams { uint16 rate; uint192 cumulativeIndexLU; uint16 quotaIncreaseFee; uint96 totalQuoted; uint96 limit; } struct AccountQuota { uint96 quota; uint192 cumulativeIndexLU; } interface IPoolQuotaKeeperV3Events { /// @notice Emitted when account's quota for a token is updated event UpdateQuota(address indexed creditAccount, address indexed token, int96 quotaChange); /// @notice Emitted when token's quota rate is updated event UpdateTokenQuotaRate(address indexed token, uint16 rate); /// @notice Emitted when the gauge is updated event SetGauge(address indexed newGauge); /// @notice Emitted when a new credit manager is allowed event AddCreditManager(address indexed creditManager); /// @notice Emitted when a new token is added as quoted event AddQuotaToken(address indexed token); /// @notice Emitted when a new total quota limit is set for a token event SetTokenLimit(address indexed token, uint96 limit); /// @notice Emitted when a new one-time quota increase fee is set for a token event SetQuotaIncreaseFee(address indexed token, uint16 fee); } /// @title Pool quota keeper V3 interface interface IPoolQuotaKeeperV3 is IPoolQuotaKeeperV3Events, IVersion { function pool() external view returns (address); function underlying() external view returns (address); // ----------------- // // QUOTAS MANAGEMENT // // ----------------- // function updateQuota(address creditAccount, address token, int96 requestedChange, uint96 minQuota, uint96 maxQuota) external returns (uint128 caQuotaInterestChange, uint128 fees, bool enableToken, bool disableToken); function removeQuotas(address creditAccount, address[] calldata tokens, bool setLimitsToZero) external; function accrueQuotaInterest(address creditAccount, address[] calldata tokens) external; function getQuotaRate(address) external view returns (uint16); function cumulativeIndex(address token) external view returns (uint192); function isQuotedToken(address token) external view returns (bool); function getQuota(address creditAccount, address token) external view returns (uint96 quota, uint192 cumulativeIndexLU); function getTokenQuotaParams(address token) external view returns ( uint16 rate, uint192 cumulativeIndexLU, uint16 quotaIncreaseFee, uint96 totalQuoted, uint96 limit, bool isActive ); function getQuotaAndOutstandingInterest(address creditAccount, address token) external view returns (uint96 quoted, uint128 outstandingInterest); function poolQuotaRevenue() external view returns (uint256); function lastQuotaRateUpdate() external view returns (uint40); // ------------- // // CONFIGURATION // // ------------- // function gauge() external view returns (address); function setGauge(address _gauge) external; function creditManagers() external view returns (address[] memory); function addCreditManager(address _creditManager) external; function quotedTokens() external view returns (address[] memory); function addQuotaToken(address token) external; function updateRates() external; function setTokenLimit(address token, uint96 limit) external; function setTokenQuotaIncreaseFee(address token, uint16 fee) external; }
// SPDX-License-Identifier: MIT // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.sol"; import {IVotingContractV3} from "./IVotingContractV3.sol"; struct QuotaRateParams { uint16 minRate; uint16 maxRate; uint96 totalVotesLpSide; uint96 totalVotesCaSide; } struct UserVotes { uint96 votesLpSide; uint96 votesCaSide; } interface IGaugeV3Events { /// @notice Emitted when epoch is updated event UpdateEpoch(uint16 epochNow); /// @notice Emitted when a user submits a vote event Vote(address indexed user, address indexed token, uint96 votes, bool lpSide); /// @notice Emitted when a user removes a vote event Unvote(address indexed user, address indexed token, uint96 votes, bool lpSide); /// @notice Emitted when a new quota token is added in the PoolQuotaKeeper event AddQuotaToken(address indexed token, uint16 minRate, uint16 maxRate); /// @notice Emitted when quota interest rate parameters are changed event SetQuotaTokenParams(address indexed token, uint16 minRate, uint16 maxRate); /// @notice Emitted when the frozen epoch status changes event SetFrozenEpoch(bool status); } /// @title Gauge V3 interface interface IGaugeV3 is IGaugeV3Events, IVotingContractV3, IVersion { function pool() external view returns (address); function voter() external view returns (address); function updateEpoch() external; function epochLastUpdate() external view returns (uint16); function getRates(address[] calldata tokens) external view returns (uint16[] memory rates); function userTokenVotes(address user, address token) external view returns (uint96 votesLpSide, uint96 votesCaSide); function quotaRateParams(address token) external view returns (uint16 minRate, uint16 maxRate, uint96 totalVotesLpSide, uint96 totalVotesCaSide); // ------------- // // CONFIGURATION // // ------------- // function epochFrozen() external view returns (bool); function setFrozenEpoch(bool status) external; function isTokenAdded(address token) external view returns (bool); function addQuotaToken(address token, uint16 minRate, uint16 maxRate) external; function changeQuotaMinRate(address token, uint16 minRate) external; function changeQuotaMaxRate(address token, uint16 maxRate) external; }
// SPDX-License-Identifier: MIT // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.sol"; uint8 constant BOT_PERMISSIONS_SET_FLAG = 1; uint8 constant DEFAULT_MAX_ENABLED_TOKENS = 4; address constant INACTIVE_CREDIT_ACCOUNT_ADDRESS = address(1); /// @notice Debt management type /// - `INCREASE_DEBT` borrows additional funds from the pool, updates account's debt and cumulative interest index /// - `DECREASE_DEBT` repays debt components (quota interest and fees -> base interest and fees -> debt principal) /// and updates all corresponding state varibles (base interest index, quota interest and fees, debt). /// When repaying all the debt, ensures that account has no enabled quotas. enum ManageDebtAction { INCREASE_DEBT, DECREASE_DEBT } /// @notice Collateral/debt calculation mode /// - `GENERIC_PARAMS` returns generic data like account debt and cumulative indexes /// - `DEBT_ONLY` is same as `GENERIC_PARAMS` but includes more detailed debt info, like accrued base/quota /// interest and fees /// - `FULL_COLLATERAL_CHECK_LAZY` checks whether account is sufficiently collateralized in a lazy fashion, /// i.e. it stops iterating over collateral tokens once TWV reaches the desired target. /// Since it may return underestimated TWV, it's only available for internal use. /// - `DEBT_COLLATERAL` is same as `DEBT_ONLY` but also returns total value and total LT-weighted value of /// account's tokens, this mode is used during account liquidation /// - `DEBT_COLLATERAL_SAFE_PRICES` is same as `DEBT_COLLATERAL` but uses safe prices from price oracle enum CollateralCalcTask { GENERIC_PARAMS, DEBT_ONLY, FULL_COLLATERAL_CHECK_LAZY, DEBT_COLLATERAL, DEBT_COLLATERAL_SAFE_PRICES } struct CreditAccountInfo { uint256 debt; uint256 cumulativeIndexLastUpdate; uint128 cumulativeQuotaInterest; uint128 quotaFees; uint256 enabledTokensMask; uint16 flags; uint64 lastDebtUpdate; address borrower; } struct CollateralDebtData { uint256 debt; uint256 cumulativeIndexNow; uint256 cumulativeIndexLastUpdate; uint128 cumulativeQuotaInterest; uint256 accruedInterest; uint256 accruedFees; uint256 totalDebtUSD; uint256 totalValue; uint256 totalValueUSD; uint256 twvUSD; uint256 enabledTokensMask; uint256 quotedTokensMask; address[] quotedTokens; address _poolQuotaKeeper; } struct CollateralTokenData { address token; uint16 ltInitial; uint16 ltFinal; uint40 timestampRampStart; uint24 rampDuration; } struct RevocationPair { address spender; address token; } interface ICreditManagerV3Events { /// @notice Emitted when new credit configurator is set event SetCreditConfigurator(address indexed newConfigurator); } /// @title Credit manager V3 interface interface ICreditManagerV3 is IVersion, ICreditManagerV3Events { function pool() external view returns (address); function underlying() external view returns (address); function creditFacade() external view returns (address); function creditConfigurator() external view returns (address); function addressProvider() external view returns (address); function accountFactory() external view returns (address); function name() external view returns (string memory); // ------------------ // // ACCOUNT MANAGEMENT // // ------------------ // function openCreditAccount(address onBehalfOf) external returns (address); function closeCreditAccount(address creditAccount) external; function liquidateCreditAccount( address creditAccount, CollateralDebtData calldata collateralDebtData, address to, bool isExpired ) external returns (uint256 remainingFunds, uint256 loss); function manageDebt(address creditAccount, uint256 amount, uint256 enabledTokensMask, ManageDebtAction action) external returns (uint256 newDebt, uint256 tokensToEnable, uint256 tokensToDisable); function addCollateral(address payer, address creditAccount, address token, uint256 amount) external returns (uint256 tokensToEnable); function withdrawCollateral(address creditAccount, address token, uint256 amount, address to) external returns (uint256 tokensToDisable); function externalCall(address creditAccount, address target, bytes calldata callData) external returns (bytes memory result); function approveToken(address creditAccount, address token, address spender, uint256 amount) external; function revokeAdapterAllowances(address creditAccount, RevocationPair[] calldata revocations) external; // -------- // // ADAPTERS // // -------- // function adapterToContract(address adapter) external view returns (address targetContract); function contractToAdapter(address targetContract) external view returns (address adapter); function execute(bytes calldata data) external returns (bytes memory result); function approveCreditAccount(address token, uint256 amount) external; function setActiveCreditAccount(address creditAccount) external; function getActiveCreditAccountOrRevert() external view returns (address creditAccount); // ----------------- // // COLLATERAL CHECKS // // ----------------- // function priceOracle() external view returns (address); function fullCollateralCheck( address creditAccount, uint256 enabledTokensMask, uint256[] calldata collateralHints, uint16 minHealthFactor, bool useSafePrices ) external returns (uint256 enabledTokensMaskAfter); function isLiquidatable(address creditAccount, uint16 minHealthFactor) external view returns (bool); function calcDebtAndCollateral(address creditAccount, CollateralCalcTask task) external view returns (CollateralDebtData memory cdd); // ------ // // QUOTAS // // ------ // function poolQuotaKeeper() external view returns (address); function quotedTokensMask() external view returns (uint256); function updateQuota(address creditAccount, address token, int96 quotaChange, uint96 minQuota, uint96 maxQuota) external returns (uint256 tokensToEnable, uint256 tokensToDisable); // --------------------- // // CREDIT MANAGER PARAMS // // --------------------- // function maxEnabledTokens() external view returns (uint8); function fees() external view returns ( uint16 feeInterest, uint16 feeLiquidation, uint16 liquidationDiscount, uint16 feeLiquidationExpired, uint16 liquidationDiscountExpired ); function collateralTokensCount() external view returns (uint8); function getTokenMaskOrRevert(address token) external view returns (uint256 tokenMask); function getTokenByMask(uint256 tokenMask) external view returns (address token); function liquidationThresholds(address token) external view returns (uint16 lt); function ltParams(address token) external view returns (uint16 ltInitial, uint16 ltFinal, uint40 timestampRampStart, uint24 rampDuration); function collateralTokenByMask(uint256 tokenMask) external view returns (address token, uint16 liquidationThreshold); // ------------ // // ACCOUNT INFO // // ------------ // function creditAccountInfo(address creditAccount) external view returns ( uint256 debt, uint256 cumulativeIndexLastUpdate, uint128 cumulativeQuotaInterest, uint128 quotaFees, uint256 enabledTokensMask, uint16 flags, uint64 lastDebtUpdate, address borrower ); function getBorrowerOrRevert(address creditAccount) external view returns (address borrower); function flagsOf(address creditAccount) external view returns (uint16); function setFlagFor(address creditAccount, uint16 flag, bool value) external; function enabledTokensMaskOf(address creditAccount) external view returns (uint256); function creditAccounts() external view returns (address[] memory); function creditAccounts(uint256 offset, uint256 limit) external view returns (address[] memory); function creditAccountsLen() external view returns (uint256); // ------------- // // CONFIGURATION // // ------------- // function addToken(address token) external; function setCollateralTokenData( address token, uint16 ltInitial, uint16 ltFinal, uint40 timestampRampStart, uint24 rampDuration ) external; function setFees( uint16 feeInterest, uint16 feeLiquidation, uint16 liquidationDiscount, uint16 feeLiquidationExpired, uint16 liquidationDiscountExpired ) external; function setQuotedMask(uint256 quotedTokensMask) external; function setMaxEnabledTokens(uint8 maxEnabledTokens) external; function setContractAllowance(address adapter, address targetContract) external; function setCreditFacade(address creditFacade) external; function setPriceOracle(address priceOracle) external; function setCreditConfigurator(address creditConfigurator) external; }
// SPDX-License-Identifier: MIT // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2022 pragma solidity ^0.8.10; // Denominations uint256 constant WAD = 1e18; uint256 constant RAY = 1e27; uint16 constant PERCENTAGE_FACTOR = 1e4; //percentage plus two decimals // 25% of type(uint256).max uint256 constant ALLOWANCE_THRESHOLD = type(uint96).max >> 3; // FEE = 50% uint16 constant DEFAULT_FEE_INTEREST = 50_00; // 50% // LIQUIDATION_FEE 1.5% uint16 constant DEFAULT_FEE_LIQUIDATION = 1_50; // 1.5% // LIQUIDATION PREMIUM 4% uint16 constant DEFAULT_LIQUIDATION_PREMIUM = 4_00; // 4% // LIQUIDATION_FEE_EXPIRED 2% uint16 constant DEFAULT_FEE_LIQUIDATION_EXPIRED = 1_00; // 2% // LIQUIDATION PREMIUM EXPIRED 2% uint16 constant DEFAULT_LIQUIDATION_PREMIUM_EXPIRED = 2_00; // 2% // DEFAULT PROPORTION OF MAX BORROWED PER BLOCK TO MAX BORROWED PER ACCOUNT uint16 constant DEFAULT_LIMIT_PER_BLOCK_MULTIPLIER = 2; // Seconds in a year uint256 constant SECONDS_PER_YEAR = 365 days; uint256 constant SECONDS_PER_ONE_AND_HALF_YEAR = (SECONDS_PER_YEAR * 3) / 2; // OPERATIONS // Leverage decimals - 100 is equal to 2x leverage (100% * collateral amount + 100% * borrowed amount) uint8 constant LEVERAGE_DECIMALS = 100; // Maximum withdraw fee for pool in PERCENTAGE_FACTOR format uint8 constant MAX_WITHDRAW_FEE = 100; uint256 constant EXACT_INPUT = 1; uint256 constant EXACT_OUTPUT = 2; address constant UNIVERSAL_CONTRACT = 0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC;
// SPDX-License-Identifier: MIT // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; // ------- // // GENERAL // // ------- // /// @notice Thrown on attempting to set an important address to zero address error ZeroAddressException(); /// @notice Thrown when attempting to pass a zero amount to a funding-related operation error AmountCantBeZeroException(); /// @notice Thrown on incorrect input parameter error IncorrectParameterException(); /// @notice Thrown when balance is insufficient to perform an operation error InsufficientBalanceException(); /// @notice Thrown if parameter is out of range error ValueOutOfRangeException(); /// @notice Thrown when trying to send ETH to a contract that is not allowed to receive ETH directly error ReceiveIsNotAllowedException(); /// @notice Thrown on attempting to set an EOA as an important contract in the system error AddressIsNotContractException(address); /// @notice Thrown on attempting to receive a token that is not a collateral token or was forbidden error TokenNotAllowedException(); /// @notice Thrown on attempting to add a token that is already in a collateral list error TokenAlreadyAddedException(); /// @notice Thrown when attempting to use quota-related logic for a token that is not quoted in quota keeper error TokenIsNotQuotedException(); /// @notice Thrown on attempting to interact with an address that is not a valid target contract error TargetContractNotAllowedException(); /// @notice Thrown if function is not implemented error NotImplementedException(); // ------------------ // // CONTRACTS REGISTER // // ------------------ // /// @notice Thrown when an address is expected to be a registered credit manager, but is not error RegisteredCreditManagerOnlyException(); /// @notice Thrown when an address is expected to be a registered pool, but is not error RegisteredPoolOnlyException(); // ---------------- // // ADDRESS PROVIDER // // ---------------- // /// @notice Reverts if address key isn't found in address provider error AddressNotFoundException(); // ----------------- // // POOL, PQK, GAUGES // // ----------------- // /// @notice Thrown by pool-adjacent contracts when a credit manager being connected has a wrong pool address error IncompatibleCreditManagerException(); /// @notice Thrown when attempting to set an incompatible successor staking contract error IncompatibleSuccessorException(); /// @notice Thrown when attempting to vote in a non-approved contract error VotingContractNotAllowedException(); /// @notice Thrown when attempting to unvote more votes than there are error InsufficientVotesException(); /// @notice Thrown when attempting to borrow more than the second point on a two-point curve error BorrowingMoreThanU2ForbiddenException(); /// @notice Thrown when a credit manager attempts to borrow more than its limit in the current block, or in general error CreditManagerCantBorrowException(); /// @notice Thrown when attempting to connect a quota keeper to an incompatible pool error IncompatiblePoolQuotaKeeperException(); /// @notice Thrown when the quota is outside of min/max bounds error QuotaIsOutOfBoundsException(); // -------------- // // CREDIT MANAGER // // -------------- // /// @notice Thrown on failing a full collateral check after multicall error NotEnoughCollateralException(); /// @notice Thrown if an attempt to approve a collateral token to adapter's target contract fails error AllowanceFailedException(); /// @notice Thrown on attempting to perform an action for a credit account that does not exist error CreditAccountDoesNotExistException(); /// @notice Thrown on configurator attempting to add more than 255 collateral tokens error TooManyTokensException(); /// @notice Thrown if more than the maximum number of tokens were enabled on a credit account error TooManyEnabledTokensException(); /// @notice Thrown when attempting to execute a protocol interaction without active credit account set error ActiveCreditAccountNotSetException(); /// @notice Thrown when trying to update credit account's debt more than once in the same block error DebtUpdatedTwiceInOneBlockException(); /// @notice Thrown when trying to repay all debt while having active quotas error DebtToZeroWithActiveQuotasException(); /// @notice Thrown when a zero-debt account attempts to update quota error UpdateQuotaOnZeroDebtAccountException(); /// @notice Thrown when attempting to close an account with non-zero debt error CloseAccountWithNonZeroDebtException(); /// @notice Thrown when value of funds remaining on the account after liquidation is insufficient error InsufficientRemainingFundsException(); /// @notice Thrown when Credit Facade tries to write over a non-zero active Credit Account error ActiveCreditAccountOverridenException(); // ------------------- // // CREDIT CONFIGURATOR // // ------------------- // /// @notice Thrown on attempting to use a non-ERC20 contract or an EOA as a token error IncorrectTokenContractException(); /// @notice Thrown if the newly set LT if zero or greater than the underlying's LT error IncorrectLiquidationThresholdException(); /// @notice Thrown if borrowing limits are incorrect: minLimit > maxLimit or maxLimit > blockLimit error IncorrectLimitsException(); /// @notice Thrown if the new expiration date is less than the current expiration date or current timestamp error IncorrectExpirationDateException(); /// @notice Thrown if a contract returns a wrong credit manager or reverts when trying to retrieve it error IncompatibleContractException(); /// @notice Thrown if attempting to forbid an adapter that is not registered in the credit manager error AdapterIsNotRegisteredException(); // ------------- // // CREDIT FACADE // // ------------- // /// @notice Thrown when attempting to perform an action that is forbidden in whitelisted mode error ForbiddenInWhitelistedModeException(); /// @notice Thrown if credit facade is not expirable, and attempted aciton requires expirability error NotAllowedWhenNotExpirableException(); /// @notice Thrown if a selector that doesn't match any allowed function is passed to the credit facade in a multicall error UnknownMethodException(); /// @notice Thrown when trying to close an account with enabled tokens error CloseAccountWithEnabledTokensException(); /// @notice Thrown if a liquidator tries to liquidate an account with a health factor above 1 error CreditAccountNotLiquidatableException(); /// @notice Thrown if too much new debt was taken within a single block error BorrowedBlockLimitException(); /// @notice Thrown if the new debt principal for a credit account falls outside of borrowing limits error BorrowAmountOutOfLimitsException(); /// @notice Thrown if a user attempts to open an account via an expired credit facade error NotAllowedAfterExpirationException(); /// @notice Thrown if expected balances are attempted to be set twice without performing a slippage check error ExpectedBalancesAlreadySetException(); /// @notice Thrown if attempting to perform a slippage check when excepted balances are not set error ExpectedBalancesNotSetException(); /// @notice Thrown if balance of at least one token is less than expected during a slippage check error BalanceLessThanExpectedException(); /// @notice Thrown when trying to perform an action that is forbidden when credit account has enabled forbidden tokens error ForbiddenTokensException(); /// @notice Thrown when new forbidden tokens are enabled during the multicall error ForbiddenTokenEnabledException(); /// @notice Thrown when enabled forbidden token balance is increased during the multicall error ForbiddenTokenBalanceIncreasedException(); /// @notice Thrown when the remaining token balance is increased during the liquidation error RemainingTokenBalanceIncreasedException(); /// @notice Thrown if `botMulticall` is called by an address that is not approved by account owner or is forbidden error NotApprovedBotException(); /// @notice Thrown when attempting to perform a multicall action with no permission for it error NoPermissionException(uint256 permission); /// @notice Thrown when attempting to give a bot unexpected permissions error UnexpectedPermissionsException(); /// @notice Thrown when a custom HF parameter lower than 10000 is passed into the full collateral check error CustomHealthFactorTooLowException(); /// @notice Thrown when submitted collateral hint is not a valid token mask error InvalidCollateralHintException(); // ------ // // ACCESS // // ------ // /// @notice Thrown on attempting to call an access restricted function not as credit account owner error CallerNotCreditAccountOwnerException(); /// @notice Thrown on attempting to call an access restricted function not as configurator error CallerNotConfiguratorException(); /// @notice Thrown on attempting to call an access-restructed function not as account factory error CallerNotAccountFactoryException(); /// @notice Thrown on attempting to call an access restricted function not as credit manager error CallerNotCreditManagerException(); /// @notice Thrown on attempting to call an access restricted function not as credit facade error CallerNotCreditFacadeException(); /// @notice Thrown on attempting to call an access restricted function not as controller or configurator error CallerNotControllerException(); /// @notice Thrown on attempting to pause a contract without pausable admin rights error CallerNotPausableAdminException(); /// @notice Thrown on attempting to unpause a contract without unpausable admin rights error CallerNotUnpausableAdminException(); /// @notice Thrown on attempting to call an access restricted function not as gauge error CallerNotGaugeException(); /// @notice Thrown on attempting to call an access restricted function not as quota keeper error CallerNotPoolQuotaKeeperException(); /// @notice Thrown on attempting to call an access restricted function not as voter error CallerNotVoterException(); /// @notice Thrown on attempting to call an access restricted function not as allowed adapter error CallerNotAdapterException(); /// @notice Thrown on attempting to call an access restricted function not as migrator error CallerNotMigratorException(); /// @notice Thrown when an address that is not the designated executor attempts to execute a transaction error CallerNotExecutorException(); /// @notice Thrown on attempting to call an access restricted function not as veto admin error CallerNotVetoAdminException(); // ------------------- // // CONTROLLER TIMELOCK // // ------------------- // /// @notice Thrown when the new parameter values do not satisfy required conditions error ParameterChecksFailedException(); /// @notice Thrown when attempting to execute a non-queued transaction error TxNotQueuedException(); /// @notice Thrown when attempting to execute a transaction that is either immature or stale error TxExecutedOutsideTimeWindowException(); /// @notice Thrown when execution of a transaction fails error TxExecutionRevertedException(); /// @notice Thrown when the value of a parameter on execution is different from the value on queue error ParameterChangedAfterQueuedTxException(); // -------- // // BOT LIST // // -------- // /// @notice Thrown when attempting to set non-zero permissions for a forbidden or special bot error InvalidBotException(); // --------------- // // ACCOUNT FACTORY // // --------------- // /// @notice Thrown when trying to deploy second master credit account for a credit manager error MasterCreditAccountAlreadyDeployedException(); /// @notice Thrown when trying to rescue funds from a credit account that is currently in use error CreditAccountIsInUseException(); // ------------ // // PRICE ORACLE // // ------------ // /// @notice Thrown on attempting to set a token price feed to an address that is not a correct price feed error IncorrectPriceFeedException(); /// @notice Thrown on attempting to interact with a price feed for a token not added to the price oracle error PriceFeedDoesNotExistException(); /// @notice Thrown when price feed returns incorrect price for a token error IncorrectPriceException(); /// @notice Thrown when token's price feed becomes stale error StalePriceException();
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
// SPDX-License-Identifier: MIT // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2022 pragma solidity ^0.8.10; import { IVersion } from "./IVersion.sol"; interface IACLExceptions { /// @dev Thrown when attempting to delete an address from a set that is not a pausable admin error AddressNotPausableAdminException(address addr); /// @dev Thrown when attempting to delete an address from a set that is not a unpausable admin error AddressNotUnpausableAdminException(address addr); } interface IACLEvents { /// @dev Emits when a new admin is added that can pause contracts event PausableAdminAdded(address indexed newAdmin); /// @dev Emits when a Pausable admin is removed event PausableAdminRemoved(address indexed admin); /// @dev Emits when a new admin is added that can unpause contracts event UnpausableAdminAdded(address indexed newAdmin); /// @dev Emits when an Unpausable admin is removed event UnpausableAdminRemoved(address indexed admin); } /// @title ACL interface interface IACL is IACLEvents, IACLExceptions, IVersion { /// @dev Returns true if the address is a pausable admin and false if not /// @param addr Address to check function isPausableAdmin(address addr) external view returns (bool); /// @dev Returns true if the address is unpausable admin and false if not /// @param addr Address to check function isUnpausableAdmin(address addr) external view returns (bool); /// @dev Returns true if an address has configurator rights /// @param account Address to check function isConfigurator(address account) external view returns (bool); /// @dev Returns address of configurator function owner() external view returns (address); }
// SPDX-License-Identifier: BUSL-1.1 // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; import {IACL} from "@gearbox-protocol/core-v2/contracts/interfaces/IACL.sol"; import {AP_ACL, IAddressProviderV3, NO_VERSION_CONTROL} from "../interfaces/IAddressProviderV3.sol"; import {CallerNotConfiguratorException} from "../interfaces/IExceptions.sol"; import {SanityCheckTrait} from "./SanityCheckTrait.sol"; /// @title ACL trait /// @notice Utility class for ACL (access-control list) consumers abstract contract ACLTrait is SanityCheckTrait { /// @notice ACL contract address address public immutable acl; /// @notice Constructor /// @param addressProvider Address provider contract address constructor(address addressProvider) nonZeroAddress(addressProvider) { acl = IAddressProviderV3(addressProvider).getAddressOrRevert(AP_ACL, NO_VERSION_CONTROL); } /// @dev Ensures that function caller has configurator role modifier configuratorOnly() { _ensureCallerIsConfigurator(); _; } /// @dev Reverts if the caller is not the configurator /// @dev Used to cut contract size on modifiers function _ensureCallerIsConfigurator() internal view { if (!_isConfigurator({account: msg.sender})) { revert CallerNotConfiguratorException(); } } /// @dev Checks whether given account has configurator role function _isConfigurator(address account) internal view returns (bool) { return IACL(acl).isConfigurator(account); } }
// SPDX-License-Identifier: BUSL-1.1 // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; uint8 constant NOT_ENTERED = 1; uint8 constant ENTERED = 2; /// @title Reentrancy guard trait /// @notice Same as OpenZeppelin's `ReentrancyGuard` but only uses 1 byte of storage instead of 32 abstract contract ReentrancyGuardTrait { uint8 internal _reentrancyStatus = NOT_ENTERED; /// @dev Prevents a contract from calling itself, directly or indirectly. /// Calling a `nonReentrant` function from another `nonReentrant` /// function is not supported. It is possible to prevent this from happening /// by making the `nonReentrant` function external, and making it call a /// `private` function that does the actual work. modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true _ensureNotEntered(); // Any calls to nonReentrant after this point will fail _reentrancyStatus = ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _reentrancyStatus = NOT_ENTERED; } /// @dev Reverts if the contract is currently entered /// @dev Used to cut contract size on modifiers function _ensureNotEntered() internal view { require(_reentrancyStatus != ENTERED, "ReentrancyGuard: reentrant call"); } }
// SPDX-License-Identifier: MIT // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2022 pragma solidity ^0.8.10; import { IVersion } from "./IVersion.sol"; interface IContractsRegisterEvents { /// @dev Emits when a new pool is registered in the system event NewPoolAdded(address indexed pool); /// @dev Emits when a new Credit Manager is registered in the system event NewCreditManagerAdded(address indexed creditManager); } interface IContractsRegister is IContractsRegisterEvents, IVersion { // // POOLS // /// @dev Returns the array of registered pools function getPools() external view returns (address[] memory); /// @dev Returns a pool address from the list under the passed index /// @param i Index of the pool to retrieve function pools(uint256 i) external view returns (address); /// @return Returns the number of registered pools function getPoolsCount() external view returns (uint256); /// @dev Returns true if the passed address is a pool function isPool(address) external view returns (bool); // // CREDIT MANAGERS // /// @dev Returns the array of registered Credit Managers function getCreditManagers() external view returns (address[] memory); /// @dev Returns a Credit Manager's address from the list under the passed index /// @param i Index of the Credit Manager to retrieve function creditManagers(uint256 i) external view returns (address); /// @return Returns the number of registered Credit Managers function getCreditManagersCount() external view returns (uint256); /// @dev Returns true if the passed address is a Credit Manager function isCreditManager(address) external view returns (bool); }
// SPDX-License-Identifier: MIT // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; import {IVersion} from "@gearbox-protocol/core-v2/contracts/interfaces/IVersion.sol"; uint256 constant NO_VERSION_CONTROL = 0; bytes32 constant AP_CONTRACTS_REGISTER = "CONTRACTS_REGISTER"; bytes32 constant AP_ACL = "ACL"; bytes32 constant AP_PRICE_ORACLE = "PRICE_ORACLE"; bytes32 constant AP_ACCOUNT_FACTORY = "ACCOUNT_FACTORY"; bytes32 constant AP_DATA_COMPRESSOR = "DATA_COMPRESSOR"; bytes32 constant AP_TREASURY = "TREASURY"; bytes32 constant AP_GEAR_TOKEN = "GEAR_TOKEN"; bytes32 constant AP_WETH_TOKEN = "WETH_TOKEN"; bytes32 constant AP_WETH_GATEWAY = "WETH_GATEWAY"; bytes32 constant AP_ROUTER = "ROUTER"; bytes32 constant AP_BOT_LIST = "BOT_LIST"; bytes32 constant AP_GEAR_STAKING = "GEAR_STAKING"; bytes32 constant AP_ZAPPER_REGISTER = "ZAPPER_REGISTER"; interface IAddressProviderV3Events { /// @notice Emitted when an address is set for a contract key event SetAddress(bytes32 indexed key, address indexed value, uint256 indexed version); } /// @title Address provider V3 interface interface IAddressProviderV3 is IAddressProviderV3Events, IVersion { function addresses(bytes32 key, uint256 _version) external view returns (address); function getAddressOrRevert(bytes32 key, uint256 _version) external view returns (address result); function setAddress(bytes32 key, address value, bool saveVersion) external; }
// SPDX-License-Identifier: BUSL-1.1 // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; import {ZeroAddressException} from "../interfaces/IExceptions.sol"; /// @title Sanity check trait abstract contract SanityCheckTrait { /// @dev Ensures that passed address is non-zero modifier nonZeroAddress(address addr) { _revertIfZeroAddress(addr); _; } /// @dev Reverts if address is zero function _revertIfZeroAddress(address addr) private pure { if (addr == address(0)) revert ZeroAddressException(); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toUint248(uint256 value) internal pure returns (uint248) { require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits"); return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toUint240(uint256 value) internal pure returns (uint240) { require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits"); return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toUint232(uint256 value) internal pure returns (uint232) { require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits"); return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.2._ */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toUint216(uint256 value) internal pure returns (uint216) { require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits"); return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toUint208(uint256 value) internal pure returns (uint208) { require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits"); return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toUint200(uint256 value) internal pure returns (uint200) { require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits"); return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toUint192(uint256 value) internal pure returns (uint192) { require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits"); return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toUint184(uint256 value) internal pure returns (uint184) { require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits"); return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toUint176(uint256 value) internal pure returns (uint176) { require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits"); return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toUint168(uint256 value) internal pure returns (uint168) { require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits"); return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toUint160(uint256 value) internal pure returns (uint160) { require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits"); return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toUint152(uint256 value) internal pure returns (uint152) { require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits"); return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toUint144(uint256 value) internal pure returns (uint144) { require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits"); return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toUint136(uint256 value) internal pure returns (uint136) { require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits"); return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v2.5._ */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toUint120(uint256 value) internal pure returns (uint120) { require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits"); return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toUint112(uint256 value) internal pure returns (uint112) { require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits"); return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toUint104(uint256 value) internal pure returns (uint104) { require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits"); return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.2._ */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toUint88(uint256 value) internal pure returns (uint88) { require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits"); return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toUint80(uint256 value) internal pure returns (uint80) { require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits"); return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toUint72(uint256 value) internal pure returns (uint72) { require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits"); return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v2.5._ */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toUint56(uint256 value) internal pure returns (uint56) { require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits"); return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toUint48(uint256 value) internal pure returns (uint48) { require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits"); return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toUint40(uint256 value) internal pure returns (uint40) { require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits"); return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v2.5._ */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toUint24(uint256 value) internal pure returns (uint24) { require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits"); return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v2.5._ */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v2.5._ */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. * * _Available since v3.0._ */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toInt248(int256 value) internal pure returns (int248 downcasted) { downcasted = int248(value); require(downcasted == value, "SafeCast: value doesn't fit in 248 bits"); } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toInt240(int256 value) internal pure returns (int240 downcasted) { downcasted = int240(value); require(downcasted == value, "SafeCast: value doesn't fit in 240 bits"); } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toInt232(int256 value) internal pure returns (int232 downcasted) { downcasted = int232(value); require(downcasted == value, "SafeCast: value doesn't fit in 232 bits"); } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.7._ */ function toInt224(int256 value) internal pure returns (int224 downcasted) { downcasted = int224(value); require(downcasted == value, "SafeCast: value doesn't fit in 224 bits"); } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toInt216(int256 value) internal pure returns (int216 downcasted) { downcasted = int216(value); require(downcasted == value, "SafeCast: value doesn't fit in 216 bits"); } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toInt208(int256 value) internal pure returns (int208 downcasted) { downcasted = int208(value); require(downcasted == value, "SafeCast: value doesn't fit in 208 bits"); } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toInt200(int256 value) internal pure returns (int200 downcasted) { downcasted = int200(value); require(downcasted == value, "SafeCast: value doesn't fit in 200 bits"); } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toInt192(int256 value) internal pure returns (int192 downcasted) { downcasted = int192(value); require(downcasted == value, "SafeCast: value doesn't fit in 192 bits"); } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toInt184(int256 value) internal pure returns (int184 downcasted) { downcasted = int184(value); require(downcasted == value, "SafeCast: value doesn't fit in 184 bits"); } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toInt176(int256 value) internal pure returns (int176 downcasted) { downcasted = int176(value); require(downcasted == value, "SafeCast: value doesn't fit in 176 bits"); } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toInt168(int256 value) internal pure returns (int168 downcasted) { downcasted = int168(value); require(downcasted == value, "SafeCast: value doesn't fit in 168 bits"); } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toInt160(int256 value) internal pure returns (int160 downcasted) { downcasted = int160(value); require(downcasted == value, "SafeCast: value doesn't fit in 160 bits"); } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toInt152(int256 value) internal pure returns (int152 downcasted) { downcasted = int152(value); require(downcasted == value, "SafeCast: value doesn't fit in 152 bits"); } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toInt144(int256 value) internal pure returns (int144 downcasted) { downcasted = int144(value); require(downcasted == value, "SafeCast: value doesn't fit in 144 bits"); } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toInt136(int256 value) internal pure returns (int136 downcasted) { downcasted = int136(value); require(downcasted == value, "SafeCast: value doesn't fit in 136 bits"); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128 downcasted) { downcasted = int128(value); require(downcasted == value, "SafeCast: value doesn't fit in 128 bits"); } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toInt120(int256 value) internal pure returns (int120 downcasted) { downcasted = int120(value); require(downcasted == value, "SafeCast: value doesn't fit in 120 bits"); } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toInt112(int256 value) internal pure returns (int112 downcasted) { downcasted = int112(value); require(downcasted == value, "SafeCast: value doesn't fit in 112 bits"); } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toInt104(int256 value) internal pure returns (int104 downcasted) { downcasted = int104(value); require(downcasted == value, "SafeCast: value doesn't fit in 104 bits"); } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.7._ */ function toInt96(int256 value) internal pure returns (int96 downcasted) { downcasted = int96(value); require(downcasted == value, "SafeCast: value doesn't fit in 96 bits"); } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toInt88(int256 value) internal pure returns (int88 downcasted) { downcasted = int88(value); require(downcasted == value, "SafeCast: value doesn't fit in 88 bits"); } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toInt80(int256 value) internal pure returns (int80 downcasted) { downcasted = int80(value); require(downcasted == value, "SafeCast: value doesn't fit in 80 bits"); } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toInt72(int256 value) internal pure returns (int72 downcasted) { downcasted = int72(value); require(downcasted == value, "SafeCast: value doesn't fit in 72 bits"); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64 downcasted) { downcasted = int64(value); require(downcasted == value, "SafeCast: value doesn't fit in 64 bits"); } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toInt56(int256 value) internal pure returns (int56 downcasted) { downcasted = int56(value); require(downcasted == value, "SafeCast: value doesn't fit in 56 bits"); } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toInt48(int256 value) internal pure returns (int48 downcasted) { downcasted = int48(value); require(downcasted == value, "SafeCast: value doesn't fit in 48 bits"); } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toInt40(int256 value) internal pure returns (int40 downcasted) { downcasted = int40(value); require(downcasted == value, "SafeCast: value doesn't fit in 40 bits"); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32 downcasted) { downcasted = int32(value); require(downcasted == value, "SafeCast: value doesn't fit in 32 bits"); } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toInt24(int256 value) internal pure returns (int24 downcasted) { downcasted = int24(value); require(downcasted == value, "SafeCast: value doesn't fit in 24 bits"); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16 downcasted) { downcasted = int16(value); require(downcasted == value, "SafeCast: value doesn't fit in 16 bits"); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8 downcasted) { downcasted = int8(value); require(downcasted == value, "SafeCast: value doesn't fit in 8 bits"); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. * * _Available since v3.0._ */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4626.sol) pragma solidity ^0.8.0; import "../token/ERC20/IERC20.sol"; import "../token/ERC20/extensions/IERC20Metadata.sol"; /** * @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626]. * * _Available since v4.7._ */ interface IERC4626 is IERC20, IERC20Metadata { event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares); event Withdraw( address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares ); /** * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing. * * - MUST be an ERC-20 token contract. * - MUST NOT revert. */ function asset() external view returns (address assetTokenAddress); /** * @dev Returns the total amount of the underlying asset that is “managed” by Vault. * * - SHOULD include any compounding that occurs from yield. * - MUST be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT revert. */ function totalAssets() external view returns (uint256 totalManagedAssets); /** * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal * scenario where all the conditions are met. * * - MUST NOT be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT show any variations depending on the caller. * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange. * - MUST NOT revert. * * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and * from. */ function convertToShares(uint256 assets) external view returns (uint256 shares); /** * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal * scenario where all the conditions are met. * * - MUST NOT be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT show any variations depending on the caller. * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange. * - MUST NOT revert. * * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and * from. */ function convertToAssets(uint256 shares) external view returns (uint256 assets); /** * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver, * through a deposit call. * * - MUST return a limited value if receiver is subject to some deposit limit. * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited. * - MUST NOT revert. */ function maxDeposit(address receiver) external view returns (uint256 maxAssets); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given * current on-chain conditions. * * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit * call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called * in the same transaction. * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the * deposit would be accepted, regardless if the user has enough tokens approved, etc. * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by depositing. */ function previewDeposit(uint256 assets) external view returns (uint256 shares); /** * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens. * * - MUST emit the Deposit event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * deposit execution, and are accounted for during deposit. * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not * approving enough underlying tokens to the Vault contract, etc). * * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token. */ function deposit(uint256 assets, address receiver) external returns (uint256 shares); /** * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call. * - MUST return a limited value if receiver is subject to some mint limit. * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted. * - MUST NOT revert. */ function maxMint(address receiver) external view returns (uint256 maxShares); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given * current on-chain conditions. * * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call * in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the * same transaction. * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint * would be accepted, regardless if the user has enough tokens approved, etc. * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by minting. */ function previewMint(uint256 shares) external view returns (uint256 assets); /** * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens. * * - MUST emit the Deposit event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint * execution, and are accounted for during mint. * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not * approving enough underlying tokens to the Vault contract, etc). * * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token. */ function mint(uint256 shares, address receiver) external returns (uint256 assets); /** * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the * Vault, through a withdraw call. * * - MUST return a limited value if owner is subject to some withdrawal limit or timelock. * - MUST NOT revert. */ function maxWithdraw(address owner) external view returns (uint256 maxAssets); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block, * given current on-chain conditions. * * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw * call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if * called * in the same transaction. * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though * the withdrawal would be accepted, regardless if the user has enough shares, etc. * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by depositing. */ function previewWithdraw(uint256 assets) external view returns (uint256 shares); /** * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver. * * - MUST emit the Withdraw event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * withdraw execution, and are accounted for during withdraw. * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner * not having enough shares, etc). * * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed. * Those methods should be performed separately. */ function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares); /** * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault, * through a redeem call. * * - MUST return a limited value if owner is subject to some withdrawal limit or timelock. * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock. * - MUST NOT revert. */ function maxRedeem(address owner) external view returns (uint256 maxShares); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block, * given current on-chain conditions. * * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call * in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the * same transaction. * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the * redemption would be accepted, regardless if the user has enough shares, etc. * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by redeeming. */ function previewRedeem(uint256 shares) external view returns (uint256 assets); /** * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver. * * - MUST emit the Withdraw event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * redeem execution, and are accounted for during redeem. * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner * not having enough shares, etc). * * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed. * Those methods should be performed separately. */ function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2022 pragma solidity ^0.8.10; /// @title Version interface /// @notice Defines contract version interface IVersion { /// @notice Contract version function version() external view returns (uint256); }
// SPDX-License-Identifier: MIT // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; interface IVotingContractV3 { function vote(address user, uint96 votes, bytes calldata extraData) external; function unvote(address user, uint96 votes, bytes calldata extraData) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 amount) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
{ "remappings": [ "@1inch/=node_modules/@1inch/", "@arbitrum/=node_modules/@arbitrum/", "@chainlink/=node_modules/@chainlink/", "@eth-optimism/=node_modules/@eth-optimism/", "@gearbox-protocol/=node_modules/@gearbox-protocol/", "@openzeppelin/=node_modules/@openzeppelin/", "@redstone-finance/=node_modules/@redstone-finance/", "ds-test/=lib/forge-std/lib/ds-test/src/", "eth-gas-reporter/=node_modules/eth-gas-reporter/", "forge-std/=lib/forge-std/src/" ], "optimizer": { "enabled": true, "runs": 1000 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "viaIR": false, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_pool","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"CallerNotConfiguratorException","type":"error"},{"inputs":[],"name":"CallerNotControllerException","type":"error"},{"inputs":[],"name":"CallerNotCreditManagerException","type":"error"},{"inputs":[],"name":"CallerNotGaugeException","type":"error"},{"inputs":[],"name":"CallerNotPausableAdminException","type":"error"},{"inputs":[],"name":"CallerNotUnpausableAdminException","type":"error"},{"inputs":[],"name":"IncompatibleCreditManagerException","type":"error"},{"inputs":[],"name":"IncorrectParameterException","type":"error"},{"inputs":[],"name":"QuotaIsOutOfBoundsException","type":"error"},{"inputs":[],"name":"RegisteredCreditManagerOnlyException","type":"error"},{"inputs":[],"name":"TokenAlreadyAddedException","type":"error"},{"inputs":[],"name":"TokenIsNotQuotedException","type":"error"},{"inputs":[],"name":"ZeroAddressException","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"creditManager","type":"address"}],"name":"AddCreditManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"AddQuotaToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newController","type":"address"}],"name":"NewController","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newGauge","type":"address"}],"name":"SetGauge","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint16","name":"fee","type":"uint16"}],"name":"SetQuotaIncreaseFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint96","name":"limit","type":"uint96"}],"name":"SetTokenLimit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"creditAccount","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"int96","name":"quotaChange","type":"int96"}],"name":"UpdateQuota","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint16","name":"rate","type":"uint16"}],"name":"UpdateTokenQuotaRate","type":"event"},{"inputs":[{"internalType":"address","name":"creditAccount","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"accrueQuotaInterest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"acl","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_creditManager","type":"address"}],"name":"addCreditManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"addQuotaToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"contractsRegister","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"controller","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"creditManagers","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"cumulativeIndex","outputs":[{"internalType":"uint192","name":"","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gauge","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"creditAccount","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"getQuota","outputs":[{"internalType":"uint96","name":"quota","type":"uint96"},{"internalType":"uint192","name":"cumulativeIndexLU","type":"uint192"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"creditAccount","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"getQuotaAndOutstandingInterest","outputs":[{"internalType":"uint96","name":"quoted","type":"uint96"},{"internalType":"uint128","name":"outstandingInterest","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getQuotaRate","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getTokenQuotaParams","outputs":[{"internalType":"uint16","name":"rate","type":"uint16"},{"internalType":"uint192","name":"cumulativeIndexLU","type":"uint192"},{"internalType":"uint16","name":"quotaIncreaseFee","type":"uint16"},{"internalType":"uint96","name":"totalQuoted","type":"uint96"},{"internalType":"uint96","name":"limit","type":"uint96"},{"internalType":"bool","name":"isActive","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"isQuotedToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastQuotaRateUpdate","outputs":[{"internalType":"uint40","name":"","type":"uint40"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolQuotaRevenue","outputs":[{"internalType":"uint256","name":"quotaRevenue","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"quotedTokens","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"creditAccount","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"bool","name":"setLimitsToZero","type":"bool"}],"name":"removeQuotas","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newController","type":"address"}],"name":"setController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_gauge","type":"address"}],"name":"setGauge","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint96","name":"limit","type":"uint96"}],"name":"setTokenLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint16","name":"fee","type":"uint16"}],"name":"setTokenQuotaIncreaseFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"underlying","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"creditAccount","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"int96","name":"requestedChange","type":"int96"},{"internalType":"uint96","name":"minQuota","type":"uint96"},{"internalType":"uint96","name":"maxQuota","type":"uint96"}],"name":"updateQuota","outputs":[{"internalType":"uint128","name":"caQuotaInterestChange","type":"uint128"},{"internalType":"uint128","name":"fees","type":"uint128"},{"internalType":"bool","name":"enableToken","type":"bool"},{"internalType":"bool","name":"disableToken","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateRates","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
61010060408190526000805461ff00191690911790553480156200002257600080fd5b506040516200282b3803806200282b833981810160405260208110156200004857600080fd5b505160408051630a55006360e21b815290516001600160a01b03831691632954018c9160048083019260209291908290030181865afa15801562000090573d6000803e3d6000fd5b505050506040513d6020811015620000a757600080fd5b505160408051630a55006360e21b815290516001600160a01b03841691632954018c9160048083019260209291908290030181865afa158015620000ef573d6000803e3d6000fd5b505050506040513d60208110156200010657600080fd5b50518080620001158162000349565b604051632bdad0e360e11b8152621050d360ea1b6004820152600060248201526001600160a01b038316906357b5a1c690604401602060405180830381865afa15801562000167573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200018d919062000374565b6001600160a01b031660808190526000805460ff1916905560408051638da5cb5b60e01b81529051919350638da5cb5b92506004808201926020929091908290030181865afa158015620001e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200020b919062000374565b600080546001600160a01b0392909216620100000262010000600160b01b03199092169190911790555080620002418162000349565b604051632bdad0e360e11b81527121a7a72a2920a1aa29afa922a3a4a9aa22a960711b6004820152600060248201526001600160a01b038316906357b5a1c690604401602060405180830381865afa158015620002a2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002c8919062000374565b6001600160a01b0390811660a052831660e0819052604080516338d52e0f60e01b815290519193506338d52e0f92506004808201926020929091908290030181865afa1580156200031d573d6000803e3d6000fd5b505050506040513d60208110156200033457600080fd5b50516001600160a01b031660c05250620003a6565b6001600160a01b0381166200037157604051635919af9760e11b815260040160405180910390fd5b50565b6000602082840312156200038757600080fd5b81516001600160a01b03811681146200039f57600080fd5b9392505050565b60805160a05160c05160e051612413620004186000396000818161031601528181610e8c015281816111dc0152818161158c0152611b9e0152600061056001526000818161058701526121c301526000818161074701528181611ea601528181611ffa015261210401526124136000f3fe608060405234801561001057600080fd5b50600436106101da5760003560e01c80637a0c7b2111610104578063dac54431116100a2578063eb9860a311610071578063eb9860a3146107d1578063f3ef1813146107d9578063f77c47911461083b578063fcde5ddc1461085457600080fd5b8063dac544311461073a578063de28735914610742578063e08a03db14610769578063e26b2f63146107ab57600080fd5b8063a6f19c84116100de578063a6f19c84146105d7578063b26453f6146105ea578063bd42a06f1461061f578063d9b94b061461071457600080fd5b80637a0c7b21146105825780638456cb59146105a957806392eefe9b146105b157600080fd5b80633c3821f41161017c578063582792371161014b578063582792371461045b5780635c975abb146104b3578063604ca15f146104ce5780636f307dc31461055b57600080fd5b80633c3821f41461040a5780633f4ba83a1461041257806354fd4d501461041a57806355a68ed31461043557600080fd5b8063112024ff116101b8578063112024ff146102df57806316f0115b1461031157806326d6a2f414610354578063364395ee146103e457600080fd5b8063099b9bd7146101df5780630ab3640f146102115780630db1b8ca1461025f575b600080fd5b61020f600480360360408110156101f557600080fd5b5080356001600160a01b0316906020013561ffff166108d6565b005b6102486004803603602081101561022757600080fd5b50356001600160a01b031660009081526005602052604090205461ffff1690565b6040805161ffff9092168252519081900360200190f35b61020f6004803603604081101561027557600080fd5b6001600160a01b0382351691908101906040810160208201356401000000008111156102a057600080fd5b8201836020820111156102b257600080fd5b803590602001918460208302840111640100000000831117156102d457600080fd5b5090925090506109f6565b6007546102f790600160a01b900464ffffffffff1681565b6040805164ffffffffff9092168252519081900360200190f35b6103387f000000000000000000000000000000000000000000000000000000000000000081565b604080516001600160a01b039092168252519081900360200190f35b6103b96004803603604081101561036a57600080fd5b506001600160a01b0381358116600090815260066020908152604080832094820135909316825292909252902080546001909101546001600160601b03909116916001600160c01b0390911690565b604080516001600160601b0390931683526001600160c01b0390911660208301528051918290030190f35b61020f600480360360208110156103fa57600080fd5b50356001600160a01b0316610ae1565b61020f610bb1565b61020f610f46565b61042361012c81565b60408051918252519081900360200190f35b61020f6004803603602081101561044b57600080fd5b50356001600160a01b0316610f58565b610463610fd8565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561049f578181015183820152602001610487565b505050509050019250505060405180910390f35b60005460ff165b604080519115158252519081900360200190f35b61051e600480360360a08110156104e457600080fd5b506001600160a01b0381358116916020810135909116906040810135600b0b906001600160601b0360608201358116916080013516610fe9565b604080516fffffffffffffffffffffffffffffffff9586168152939094166020840152901515828401521515606082015290519081900360800190f35b6103387f000000000000000000000000000000000000000000000000000000000000000081565b6103387f000000000000000000000000000000000000000000000000000000000000000081565b61020f61107a565b61020f600480360360208110156105c757600080fd5b50356001600160a01b031661108a565b600754610338906001600160a01b031681565b61020f6004803603604081101561060057600080fd5b5080356001600160a01b031690602001356001600160601b0316611115565b6106c66004803603602081101561063557600080fd5b50356001600160a01b0316600090815260056020908152604091829020825160a081018452815461ffff8082168084526201000083046001600160c01b0316958401869052600160d01b909204169482018590526001909201546001600160601b03808216606084018190526c01000000000000000000000000909204166080909201829052919492939285151590565b6040805161ffff97881681526001600160c01b03909616602087015293909516848401526001600160601b03918216606085015216608083015291151560a082015290519081900360c00190f35b6104ba6004803603602081101561072a57600080fd5b50356001600160a01b0316611140565b610463611162565b6103387f000000000000000000000000000000000000000000000000000000000000000081565b61078f6004803603602081101561077f57600080fd5b50356001600160a01b031661116e565b604080516001600160c01b039092168252519081900360200190f35b61020f600480360360208110156107c157600080fd5b50356001600160a01b03166111be565b6104236112fc565b610807600480360360408110156107ef57600080fd5b506001600160a01b03813581169160200135166113ad565b604080516001600160601b0390931683526fffffffffffffffffffffffffffffffff90911660208301528051918290030190f35b600054610338906201000090046001600160a01b031681565b61020f6004803603606081101561086a57600080fd5b6001600160a01b03823516919081019060408101602082013564010000000081111561089557600080fd5b8201836020820111156108a757600080fd5b803590602001918460208302840111640100000000831117156108c957600080fd5b9193509150351515611417565b6108de611610565b61271061ffff8216111561091e576040517f47fbaa9700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038216600090815260056020526040902080546201000090046001600160c01b031661096457604051632fed18cf60e21b815260040160405180910390fd5b805461ffff838116600160d01b90920416146109f157805461ffff8316600160d01b81027fffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffffffff90921691909117825560408051918252516001600160a01b038516917f1f985277936e1ecc9dd715575b48f1c6f18902eeb1a1b3a32779122296e64a66919081900360200190a25b505050565b6109fe61166e565b6007548190600160a01b900464ffffffffff1660005b82811015610ad9576000858583818110610a3057610a306121f4565b6001600160a01b038a81166000908152600660209081526040808320948202969096013590921680825292825284812060059092529384209194509290915080610a79836116b4565b5091509150610a9081838964ffffffffff166116f7565b600194850180547fffffffffffffffff000000000000000000000000000000000000000000000000166001600160c01b0392909216919091179055505050919091019050610a14565b505050505050565b610ae9611769565b6001600160a01b03811660009081526004602052604090205415610b39576040517f2e5a5c7700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610b446003826117ad565b506001600160a01b03811660008181526005602052604080822080547fffffffffffff000000000000000000000000000000000000000000000000ffff1662010000179055517f7401ff10219be3dd6d26cc491114a8ae5a0e13ac3af651aae1286afad365947d9190a250565b610bb9611769565b6000610bc560036117c2565b6007546040517f67bd79a20000000000000000000000000000000000000000000000000000000081526020600482018181528451602484015284519495506000946001600160a01b03909416936367bd79a2938793839260449092019181860191028083838b5b83811015610c44578181015183820152602001610c2c565b5050505090500192505050600060405180830381865afa158015610c6c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015610c9557600080fd5b8101908080516040519392919084640100000000821115610cb557600080fd5b908301906020820185811115610cca57600080fd5b8251866020820283011164010000000082111715610ce757600080fd5b82525081516020918201928201910280838360005b83811015610d14578181015183820152602001610cfc565b505050509190910160405250506007548551939450600093600160a01b90910464ffffffffff1692509050825b81811015610e89576000868281518110610d5d57610d5d6121f4565b602002602001015190506000868381518110610d7b57610d7b6121f4565b6020908102919091018101516001600160a01b03841660009081526005909252604082209092509080610dad836116b4565b5091509150610dbd81838a6116f7565b83547fffffffffffff000000000000000000000000000000000000000000000000000016620100006001600160c01b03929092169190910261ffff19161761ffff85169081178455600184015461271091610e20916001600160601b0316612220565b610e2a919061224d565b610e34908a612261565b6040805161ffff871681529051919a506001600160a01b038716917ffb19913ea8fcd2e3d22d200707473d031876b05d1ecb42173e73292ed910ac859181900360200190a28560010195505050505050610d41565b507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663275df3ad846040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015610ef057600080fd5b505af1158015610f04573d6000803e3d6000fd5b5050600780547fffffffffffffff0000000000ffffffffffffffffffffffffffffffffffffffff16600160a01b4264ffffffffff160217905550505050505050565b610f4e6117cf565b610f5661180e565b565b610f60611860565b6007546001600160a01b03828116911614610fd557600780547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0383169081179091556040517f17228b08e4c958112a0827a6d8dc8475dba58dd068a3d400800a606794db02a690600090a25b50565b6060610fe460036117c2565b905090565b600080600080610ff761166e565b60006110068a8a8a8a8a61189f565b9398509196509094509092509050600b81900b1561106d57886001600160a01b03168a6001600160a01b03167f22cce666192befd41ad1b89f8592d35a7ce7c6960853f89ada56db03bb61b096836040518082600b0b815260200191505060405180910390a35b5095509550955095915050565b611082611c31565b610f56611c70565b611092611860565b6000546001600160a01b03828116620100009092041614610fd557600080547fffffffffffffffffffff0000000000000000000000000000000000000000ffff16620100006001600160a01b03841690810291909117825560405190917fe253457d9ad994ca9682fc3bbc38c890dca73a2d5ecee3809e548bac8b00d7c691a250565b61111d611610565b6001600160a01b03821660009081526005602052604090206109f1818484611cad565b6001600160a01b03811660009081526004602052604081205415155b92915050565b6060610fe460016117c2565b6001600160a01b03811660009081526005602052604081208180611191836116b4565b5060075491935091506111b59082908490600160a01b900464ffffffffff166116f7565b95945050505050565b6111c6611860565b806111d081611d90565b816111da81611dd0565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b03166316f0115b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611242573d6000803e3d6000fd5b505050506040513d602081101561125857600080fd5b50516001600160a01b03161461129a576040517f2e47790c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0383166000908152600260205260409020546109f1576112c26001846117ad565b506040516001600160a01b038416907fbca7ba46bb626fab79d5a673d0d8293df21968a25350c4d71433f98600618f5f90600090a2505050565b60008061130960036117c2565b805190915060005b818110156113a757600083828151811061132d5761132d6121f4565b6020908102919091018101516001600160a01b03811660009081526005909252604082209092509061135e826116b4565b505060018301549091506001600160601b031661271061138261ffff841683612220565b61138c919061224d565b6113969089612261565b975084600101945050505050611311565b50505090565b6001600160a01b03808316600090815260066020908152604080832093851683529290529081208190816113e08561116e565b825460018401546001600160601b0390911695509091506001600160c01b031661140b858383611e0f565b93505050509250929050565b61141f61166e565b600082815b81811015611583576000868683818110611440576114406121f4565b6001600160a01b038b811660009081526006602090815260408083209482029690960135909216808252928252848120600590925293909320835491945091506001600160601b0316801561156257815461ffff166114b0816114ab6001600160601b038516612274565b611e4e565b6114ba9089612290565b60018401805491995083916000906114dc9084906001600160601b03166122b8565b82546001600160601b039182166101009390930a92830291909202199091161790555083546bffffffffffffffffffffffff191684556001600160a01b03808616908d167f22cce666192befd41ad1b89f8592d35a7ce7c6960853f89ada56db03bb61b09661154a856122df565b60408051600b9290920b8252519081900360200190a3505b87156115745761157482856000611cad565b84600101945050505050611424565b508115610ad9577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d6458eea836040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156115f057600080fd5b505af1158015611604573d6000803e3d6000fd5b50505050505050505050565b6000546201000090046001600160a01b03163314801590611637575061163533611e6b565b155b15610f56576040517f0129bb9900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b33600090815260026020526040902054610f56576040517f1f51116700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b805461ffff811690601081901c6001600160c01b03169060d01c60008290036116f057604051632fed18cf60e21b815260040160405180910390fd5b9193909250565b60006301e1338061ffff841661170d844261230a565b6117256127106b033b2e3c9fd0803ce800000061224d565b6001600160c01b03166117389190612220565b6117429190612220565b61174c919061224d565b61175f906001600160c01b038616612261565b90505b9392505050565b6007546001600160a01b03163314610f56576040517f5dd0cb2400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000611762836001600160a01b038416611f14565b6060600061176283611f63565b6117d833611fbf565b610f56576040517f16e29ab700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61181661202b565b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b61186933611e6b565b610f56576040517f61081c1500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038086166000908152600660209081526040808320938816835292815282822060059091529181208254919283928392839283929091906001600160601b03168380806118f2856116b4565b925092509250600061191f8385600760149054906101000a900464ffffffffff1664ffffffffff166116f7565b600188015490915061193d90869083906001600160c01b0316611e0f565b9b5060008f9a5060008b600b0b1315611a1c5760018701546001600160601b0381169060601c61ffff87161561197d5761197882828f612082565b611980565b60005b9c5061271061ffff168561ffff168e6001600160601b03166119a29190612220565b6119ac919061224d565b9d506119b88d8961231d565b92506001600160601b0388161580156119d957506001600160601b03831615155b156119e35760019b505b6119ed8d8361231d565b60018a0180546bffffffffffffffffffffffff19166001600160601b039290921691909117905550611ac99050565b6b800000000000000000000000600b8c900b01611a3f57611a3c866122df565b9a505b6000611a4a8c6122df565b9050611a5681886122b8565b6001890180549193508291600090611a789084906001600160601b03166122b8565b92506101000a8154816001600160601b0302191690836001600160601b03160217905550866001600160601b0316600014158015611abd57506001600160601b038216155b15611ac757600199505b505b8e6001600160601b0316816001600160601b03161080611afa57508d6001600160601b0316816001600160601b0316115b15611b31576040517fba04a99a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b87546bffffffffffffffffffffffff19166001600160601b0382161788556001880180547fffffffffffffffff000000000000000000000000000000000000000000000000166001600160c01b0384161790556000611b9486600b8e900b611e4e565b90508015611c1b577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d6458eea826040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015611c0257600080fd5b505af1158015611c16573d6000803e3d6000fd5b505050505b5050505050505050509550955095509550959050565b611c3a336120c9565b610f56576040517fd794b1e700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611c78612135565b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586118433390565b82546201000090046001600160c01b0316611cdb57604051632fed18cf60e21b815260040160405180910390fd5b60018301546001600160601b038281166c0100000000000000000000000090920416146109f1576001830180546001600160601b0383166c0100000000000000000000000081027fffffffffffffffff000000000000000000000000ffffffffffffffffffffffff9092169190911790915560408051918252516001600160a01b038416917f86089ad7ab4cb6d03a20ccb3176599b628f4a4b80ceacf88369108bf10ffa1c9919081900360200190a2505050565b6001600160a01b038116610fd5576040517fb2335f2e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611dd981612188565b610fd5576040517fbc6a488a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006b033b2e3c9fd0803ce8000000611e28838561233d565b611e44906001600160c01b03166001600160601b038716612220565b61175f919061224d565b6000612710611e6161ffff85168461235d565b611762919061238d565b6040517f5f259aba0000000000000000000000000000000000000000000000000000000081526001600160a01b0382811660048301526000917f000000000000000000000000000000000000000000000000000000000000000090911690635f259aba906024015b602060405180830381865afa158015611ef0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061115c91906123bb565b6000818152600183016020526040812054611f5b5750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561115c565b50600061115c565b606081600001805480602002602001604051908101604052809291908181526020018280548015611fb357602002820191906000526020600020905b815481526020019060010190808311611f9f575b50505050509050919050565b6040517fd4eb5db00000000000000000000000000000000000000000000000000000000081526001600160a01b0382811660048301526000917f00000000000000000000000000000000000000000000000000000000000000009091169063d4eb5db090602401611ed3565b60005460ff16610f565760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f742070617573656400000000000000000000000060448201526064015b60405180910390fd5b6000826001600160601b0316846001600160601b0316106120a557506000611762565b8383036001600160601b03808216908416116120c157826111b5565b949350505050565b6040517f3a41ec640000000000000000000000000000000000000000000000000000000081526001600160a01b0382811660048301526000917f000000000000000000000000000000000000000000000000000000000000000090911690633a41ec6490602401611ed3565b60005460ff1615610f565760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401612079565b6040517f6fbc6f6b0000000000000000000000000000000000000000000000000000000081526001600160a01b0382811660048301526000917f000000000000000000000000000000000000000000000000000000000000000090911690636fbc6f6b90602401611ed3565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761115c5761115c61220a565b634e487b7160e01b600052601260045260246000fd5b60008261225c5761225c612237565b500490565b8082018082111561115c5761115c61220a565b6000600160ff1b82036122895761228961220a565b5060000390565b80820182811260008312801582168215821617156122b0576122b061220a565b505092915050565b6001600160601b038281168282160390808211156122d8576122d861220a565b5092915050565b600081600b0b6b7fffffffffffffffffffffff1981036123015761230161220a565b60000392915050565b8181038181111561115c5761115c61220a565b6001600160601b038181168382160190808211156122d8576122d861220a565b6001600160c01b038281168282160390808211156122d8576122d861220a565b80820260008212600160ff1b841416156123795761237961220a565b818105831482151761115c5761115c61220a565b60008261239c5761239c612237565b600160ff1b8214600019841416156123b6576123b661220a565b500590565b6000602082840312156123cd57600080fd5b8151801515811461176257600080fdfea26469706673582212209bfcdc28c7ccebcd3ba0458c0fb2fc26039615ebb11cabcdc8ea8be36767e97f64736f6c634300081100330000000000000000000000006f6bda069fb05bab5e83b22fbdb54cbdf33f78ee
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101da5760003560e01c80637a0c7b2111610104578063dac54431116100a2578063eb9860a311610071578063eb9860a3146107d1578063f3ef1813146107d9578063f77c47911461083b578063fcde5ddc1461085457600080fd5b8063dac544311461073a578063de28735914610742578063e08a03db14610769578063e26b2f63146107ab57600080fd5b8063a6f19c84116100de578063a6f19c84146105d7578063b26453f6146105ea578063bd42a06f1461061f578063d9b94b061461071457600080fd5b80637a0c7b21146105825780638456cb59146105a957806392eefe9b146105b157600080fd5b80633c3821f41161017c578063582792371161014b578063582792371461045b5780635c975abb146104b3578063604ca15f146104ce5780636f307dc31461055b57600080fd5b80633c3821f41461040a5780633f4ba83a1461041257806354fd4d501461041a57806355a68ed31461043557600080fd5b8063112024ff116101b8578063112024ff146102df57806316f0115b1461031157806326d6a2f414610354578063364395ee146103e457600080fd5b8063099b9bd7146101df5780630ab3640f146102115780630db1b8ca1461025f575b600080fd5b61020f600480360360408110156101f557600080fd5b5080356001600160a01b0316906020013561ffff166108d6565b005b6102486004803603602081101561022757600080fd5b50356001600160a01b031660009081526005602052604090205461ffff1690565b6040805161ffff9092168252519081900360200190f35b61020f6004803603604081101561027557600080fd5b6001600160a01b0382351691908101906040810160208201356401000000008111156102a057600080fd5b8201836020820111156102b257600080fd5b803590602001918460208302840111640100000000831117156102d457600080fd5b5090925090506109f6565b6007546102f790600160a01b900464ffffffffff1681565b6040805164ffffffffff9092168252519081900360200190f35b6103387f0000000000000000000000006f6bda069fb05bab5e83b22fbdb54cbdf33f78ee81565b604080516001600160a01b039092168252519081900360200190f35b6103b96004803603604081101561036a57600080fd5b506001600160a01b0381358116600090815260066020908152604080832094820135909316825292909252902080546001909101546001600160601b03909116916001600160c01b0390911690565b604080516001600160601b0390931683526001600160c01b0390911660208301528051918290030190f35b61020f600480360360208110156103fa57600080fd5b50356001600160a01b0316610ae1565b61020f610bb1565b61020f610f46565b61042361012c81565b60408051918252519081900360200190f35b61020f6004803603602081101561044b57600080fd5b50356001600160a01b0316610f58565b610463610fd8565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561049f578181015183820152602001610487565b505050509050019250505060405180910390f35b60005460ff165b604080519115158252519081900360200190f35b61051e600480360360a08110156104e457600080fd5b506001600160a01b0381358116916020810135909116906040810135600b0b906001600160601b0360608201358116916080013516610fe9565b604080516fffffffffffffffffffffffffffffffff9586168152939094166020840152901515828401521515606082015290519081900360800190f35b6103387f00000000000000000000000029219dd400f2bf60e5a23d13be72b486d403889481565b6103387f000000000000000000000000f2b8e0f4705cec47a8b8eb7dbc29b3322198058b81565b61020f61107a565b61020f600480360360208110156105c757600080fd5b50356001600160a01b031661108a565b600754610338906001600160a01b031681565b61020f6004803603604081101561060057600080fd5b5080356001600160a01b031690602001356001600160601b0316611115565b6106c66004803603602081101561063557600080fd5b50356001600160a01b0316600090815260056020908152604091829020825160a081018452815461ffff8082168084526201000083046001600160c01b0316958401869052600160d01b909204169482018590526001909201546001600160601b03808216606084018190526c01000000000000000000000000909204166080909201829052919492939285151590565b6040805161ffff97881681526001600160c01b03909616602087015293909516848401526001600160601b03918216606085015216608083015291151560a082015290519081900360c00190f35b6104ba6004803603602081101561072a57600080fd5b50356001600160a01b0316611140565b610463611162565b6103387f000000000000000000000000ad131da4bddb40ebb5ceeaea87067553d431389581565b61078f6004803603602081101561077f57600080fd5b50356001600160a01b031661116e565b604080516001600160c01b039092168252519081900360200190f35b61020f600480360360208110156107c157600080fd5b50356001600160a01b03166111be565b6104236112fc565b610807600480360360408110156107ef57600080fd5b506001600160a01b03813581169160200135166113ad565b604080516001600160601b0390931683526fffffffffffffffffffffffffffffffff90911660208301528051918290030190f35b600054610338906201000090046001600160a01b031681565b61020f6004803603606081101561086a57600080fd5b6001600160a01b03823516919081019060408101602082013564010000000081111561089557600080fd5b8201836020820111156108a757600080fd5b803590602001918460208302840111640100000000831117156108c957600080fd5b9193509150351515611417565b6108de611610565b61271061ffff8216111561091e576040517f47fbaa9700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038216600090815260056020526040902080546201000090046001600160c01b031661096457604051632fed18cf60e21b815260040160405180910390fd5b805461ffff838116600160d01b90920416146109f157805461ffff8316600160d01b81027fffffffff0000ffffffffffffffffffffffffffffffffffffffffffffffffffff90921691909117825560408051918252516001600160a01b038516917f1f985277936e1ecc9dd715575b48f1c6f18902eeb1a1b3a32779122296e64a66919081900360200190a25b505050565b6109fe61166e565b6007548190600160a01b900464ffffffffff1660005b82811015610ad9576000858583818110610a3057610a306121f4565b6001600160a01b038a81166000908152600660209081526040808320948202969096013590921680825292825284812060059092529384209194509290915080610a79836116b4565b5091509150610a9081838964ffffffffff166116f7565b600194850180547fffffffffffffffff000000000000000000000000000000000000000000000000166001600160c01b0392909216919091179055505050919091019050610a14565b505050505050565b610ae9611769565b6001600160a01b03811660009081526004602052604090205415610b39576040517f2e5a5c7700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610b446003826117ad565b506001600160a01b03811660008181526005602052604080822080547fffffffffffff000000000000000000000000000000000000000000000000ffff1662010000179055517f7401ff10219be3dd6d26cc491114a8ae5a0e13ac3af651aae1286afad365947d9190a250565b610bb9611769565b6000610bc560036117c2565b6007546040517f67bd79a20000000000000000000000000000000000000000000000000000000081526020600482018181528451602484015284519495506000946001600160a01b03909416936367bd79a2938793839260449092019181860191028083838b5b83811015610c44578181015183820152602001610c2c565b5050505090500192505050600060405180830381865afa158015610c6c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015610c9557600080fd5b8101908080516040519392919084640100000000821115610cb557600080fd5b908301906020820185811115610cca57600080fd5b8251866020820283011164010000000082111715610ce757600080fd5b82525081516020918201928201910280838360005b83811015610d14578181015183820152602001610cfc565b505050509190910160405250506007548551939450600093600160a01b90910464ffffffffff1692509050825b81811015610e89576000868281518110610d5d57610d5d6121f4565b602002602001015190506000868381518110610d7b57610d7b6121f4565b6020908102919091018101516001600160a01b03841660009081526005909252604082209092509080610dad836116b4565b5091509150610dbd81838a6116f7565b83547fffffffffffff000000000000000000000000000000000000000000000000000016620100006001600160c01b03929092169190910261ffff19161761ffff85169081178455600184015461271091610e20916001600160601b0316612220565b610e2a919061224d565b610e34908a612261565b6040805161ffff871681529051919a506001600160a01b038716917ffb19913ea8fcd2e3d22d200707473d031876b05d1ecb42173e73292ed910ac859181900360200190a28560010195505050505050610d41565b507f0000000000000000000000006f6bda069fb05bab5e83b22fbdb54cbdf33f78ee6001600160a01b031663275df3ad846040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015610ef057600080fd5b505af1158015610f04573d6000803e3d6000fd5b5050600780547fffffffffffffff0000000000ffffffffffffffffffffffffffffffffffffffff16600160a01b4264ffffffffff160217905550505050505050565b610f4e6117cf565b610f5661180e565b565b610f60611860565b6007546001600160a01b03828116911614610fd557600780547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0383169081179091556040517f17228b08e4c958112a0827a6d8dc8475dba58dd068a3d400800a606794db02a690600090a25b50565b6060610fe460036117c2565b905090565b600080600080610ff761166e565b60006110068a8a8a8a8a61189f565b9398509196509094509092509050600b81900b1561106d57886001600160a01b03168a6001600160a01b03167f22cce666192befd41ad1b89f8592d35a7ce7c6960853f89ada56db03bb61b096836040518082600b0b815260200191505060405180910390a35b5095509550955095915050565b611082611c31565b610f56611c70565b611092611860565b6000546001600160a01b03828116620100009092041614610fd557600080547fffffffffffffffffffff0000000000000000000000000000000000000000ffff16620100006001600160a01b03841690810291909117825560405190917fe253457d9ad994ca9682fc3bbc38c890dca73a2d5ecee3809e548bac8b00d7c691a250565b61111d611610565b6001600160a01b03821660009081526005602052604090206109f1818484611cad565b6001600160a01b03811660009081526004602052604081205415155b92915050565b6060610fe460016117c2565b6001600160a01b03811660009081526005602052604081208180611191836116b4565b5060075491935091506111b59082908490600160a01b900464ffffffffff166116f7565b95945050505050565b6111c6611860565b806111d081611d90565b816111da81611dd0565b7f0000000000000000000000006f6bda069fb05bab5e83b22fbdb54cbdf33f78ee6001600160a01b0316836001600160a01b03166316f0115b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611242573d6000803e3d6000fd5b505050506040513d602081101561125857600080fd5b50516001600160a01b03161461129a576040517f2e47790c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0383166000908152600260205260409020546109f1576112c26001846117ad565b506040516001600160a01b038416907fbca7ba46bb626fab79d5a673d0d8293df21968a25350c4d71433f98600618f5f90600090a2505050565b60008061130960036117c2565b805190915060005b818110156113a757600083828151811061132d5761132d6121f4565b6020908102919091018101516001600160a01b03811660009081526005909252604082209092509061135e826116b4565b505060018301549091506001600160601b031661271061138261ffff841683612220565b61138c919061224d565b6113969089612261565b975084600101945050505050611311565b50505090565b6001600160a01b03808316600090815260066020908152604080832093851683529290529081208190816113e08561116e565b825460018401546001600160601b0390911695509091506001600160c01b031661140b858383611e0f565b93505050509250929050565b61141f61166e565b600082815b81811015611583576000868683818110611440576114406121f4565b6001600160a01b038b811660009081526006602090815260408083209482029690960135909216808252928252848120600590925293909320835491945091506001600160601b0316801561156257815461ffff166114b0816114ab6001600160601b038516612274565b611e4e565b6114ba9089612290565b60018401805491995083916000906114dc9084906001600160601b03166122b8565b82546001600160601b039182166101009390930a92830291909202199091161790555083546bffffffffffffffffffffffff191684556001600160a01b03808616908d167f22cce666192befd41ad1b89f8592d35a7ce7c6960853f89ada56db03bb61b09661154a856122df565b60408051600b9290920b8252519081900360200190a3505b87156115745761157482856000611cad565b84600101945050505050611424565b508115610ad9577f0000000000000000000000006f6bda069fb05bab5e83b22fbdb54cbdf33f78ee6001600160a01b031663d6458eea836040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b1580156115f057600080fd5b505af1158015611604573d6000803e3d6000fd5b50505050505050505050565b6000546201000090046001600160a01b03163314801590611637575061163533611e6b565b155b15610f56576040517f0129bb9900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b33600090815260026020526040902054610f56576040517f1f51116700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b805461ffff811690601081901c6001600160c01b03169060d01c60008290036116f057604051632fed18cf60e21b815260040160405180910390fd5b9193909250565b60006301e1338061ffff841661170d844261230a565b6117256127106b033b2e3c9fd0803ce800000061224d565b6001600160c01b03166117389190612220565b6117429190612220565b61174c919061224d565b61175f906001600160c01b038616612261565b90505b9392505050565b6007546001600160a01b03163314610f56576040517f5dd0cb2400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000611762836001600160a01b038416611f14565b6060600061176283611f63565b6117d833611fbf565b610f56576040517f16e29ab700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61181661202b565b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b61186933611e6b565b610f56576040517f61081c1500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038086166000908152600660209081526040808320938816835292815282822060059091529181208254919283928392839283929091906001600160601b03168380806118f2856116b4565b925092509250600061191f8385600760149054906101000a900464ffffffffff1664ffffffffff166116f7565b600188015490915061193d90869083906001600160c01b0316611e0f565b9b5060008f9a5060008b600b0b1315611a1c5760018701546001600160601b0381169060601c61ffff87161561197d5761197882828f612082565b611980565b60005b9c5061271061ffff168561ffff168e6001600160601b03166119a29190612220565b6119ac919061224d565b9d506119b88d8961231d565b92506001600160601b0388161580156119d957506001600160601b03831615155b156119e35760019b505b6119ed8d8361231d565b60018a0180546bffffffffffffffffffffffff19166001600160601b039290921691909117905550611ac99050565b6b800000000000000000000000600b8c900b01611a3f57611a3c866122df565b9a505b6000611a4a8c6122df565b9050611a5681886122b8565b6001890180549193508291600090611a789084906001600160601b03166122b8565b92506101000a8154816001600160601b0302191690836001600160601b03160217905550866001600160601b0316600014158015611abd57506001600160601b038216155b15611ac757600199505b505b8e6001600160601b0316816001600160601b03161080611afa57508d6001600160601b0316816001600160601b0316115b15611b31576040517fba04a99a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b87546bffffffffffffffffffffffff19166001600160601b0382161788556001880180547fffffffffffffffff000000000000000000000000000000000000000000000000166001600160c01b0384161790556000611b9486600b8e900b611e4e565b90508015611c1b577f0000000000000000000000006f6bda069fb05bab5e83b22fbdb54cbdf33f78ee6001600160a01b031663d6458eea826040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015611c0257600080fd5b505af1158015611c16573d6000803e3d6000fd5b505050505b5050505050505050509550955095509550959050565b611c3a336120c9565b610f56576040517fd794b1e700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611c78612135565b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586118433390565b82546201000090046001600160c01b0316611cdb57604051632fed18cf60e21b815260040160405180910390fd5b60018301546001600160601b038281166c0100000000000000000000000090920416146109f1576001830180546001600160601b0383166c0100000000000000000000000081027fffffffffffffffff000000000000000000000000ffffffffffffffffffffffff9092169190911790915560408051918252516001600160a01b038416917f86089ad7ab4cb6d03a20ccb3176599b628f4a4b80ceacf88369108bf10ffa1c9919081900360200190a2505050565b6001600160a01b038116610fd5576040517fb2335f2e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611dd981612188565b610fd5576040517fbc6a488a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006b033b2e3c9fd0803ce8000000611e28838561233d565b611e44906001600160c01b03166001600160601b038716612220565b61175f919061224d565b6000612710611e6161ffff85168461235d565b611762919061238d565b6040517f5f259aba0000000000000000000000000000000000000000000000000000000081526001600160a01b0382811660048301526000917f000000000000000000000000ad131da4bddb40ebb5ceeaea87067553d431389590911690635f259aba906024015b602060405180830381865afa158015611ef0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061115c91906123bb565b6000818152600183016020526040812054611f5b5750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915561115c565b50600061115c565b606081600001805480602002602001604051908101604052809291908181526020018280548015611fb357602002820191906000526020600020905b815481526020019060010190808311611f9f575b50505050509050919050565b6040517fd4eb5db00000000000000000000000000000000000000000000000000000000081526001600160a01b0382811660048301526000917f000000000000000000000000ad131da4bddb40ebb5ceeaea87067553d43138959091169063d4eb5db090602401611ed3565b60005460ff16610f565760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f742070617573656400000000000000000000000060448201526064015b60405180910390fd5b6000826001600160601b0316846001600160601b0316106120a557506000611762565b8383036001600160601b03808216908416116120c157826111b5565b949350505050565b6040517f3a41ec640000000000000000000000000000000000000000000000000000000081526001600160a01b0382811660048301526000917f000000000000000000000000ad131da4bddb40ebb5ceeaea87067553d431389590911690633a41ec6490602401611ed3565b60005460ff1615610f565760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401612079565b6040517f6fbc6f6b0000000000000000000000000000000000000000000000000000000081526001600160a01b0382811660048301526000917f000000000000000000000000f2b8e0f4705cec47a8b8eb7dbc29b3322198058b90911690636fbc6f6b90602401611ed3565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761115c5761115c61220a565b634e487b7160e01b600052601260045260246000fd5b60008261225c5761225c612237565b500490565b8082018082111561115c5761115c61220a565b6000600160ff1b82036122895761228961220a565b5060000390565b80820182811260008312801582168215821617156122b0576122b061220a565b505092915050565b6001600160601b038281168282160390808211156122d8576122d861220a565b5092915050565b600081600b0b6b7fffffffffffffffffffffff1981036123015761230161220a565b60000392915050565b8181038181111561115c5761115c61220a565b6001600160601b038181168382160190808211156122d8576122d861220a565b6001600160c01b038281168282160390808211156122d8576122d861220a565b80820260008212600160ff1b841416156123795761237961220a565b818105831482151761115c5761115c61220a565b60008261239c5761239c612237565b600160ff1b8214600019841416156123b6576123b661220a565b500590565b6000602082840312156123cd57600080fd5b8151801515811461176257600080fdfea26469706673582212209bfcdc28c7ccebcd3ba0458c0fb2fc26039615ebb11cabcdc8ea8be36767e97f64736f6c63430008110033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000006f6bda069fb05bab5e83b22fbdb54cbdf33f78ee
-----Decoded View---------------
Arg [0] : _pool (address): 0x6F6bda069FB05baB5E83B22FbDb54CBdF33f78ee
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000006f6bda069fb05bab5e83b22fbdb54cbdf33f78ee
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 31 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ 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.