More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 38 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Get Rewards | 21594718 | 2 hrs ago | IN | 0 ETH | 0.00134744 | ||||
Get Rewards | 21594632 | 3 hrs ago | IN | 0 ETH | 0.00195487 | ||||
Get Rewards | 21594212 | 4 hrs ago | IN | 0 ETH | 0.00116388 | ||||
Claim Spectra Re... | 21587457 | 27 hrs ago | IN | 0 ETH | 0.00209086 | ||||
Get Rewards | 21584197 | 38 hrs ago | IN | 0 ETH | 0.00081732 | ||||
Get Rewards | 21578518 | 2 days ago | IN | 0 ETH | 0.00086721 | ||||
Claim Spectra Re... | 21575133 | 2 days ago | IN | 0 ETH | 0.00190354 | ||||
Get Rewards | 21571642 | 3 days ago | IN | 0 ETH | 0.00088772 | ||||
Claim Spectra Re... | 21564146 | 4 days ago | IN | 0 ETH | 0.00106855 | ||||
Get Rewards | 21560799 | 4 days ago | IN | 0 ETH | 0.00085502 | ||||
Claim Spectra Re... | 21554417 | 5 days ago | IN | 0 ETH | 0.00066176 | ||||
Get Rewards | 21552813 | 5 days ago | IN | 0 ETH | 0.00187449 | ||||
Claim Spectra Re... | 21544921 | 7 days ago | IN | 0 ETH | 0.0019861 | ||||
Claim Spectra Re... | 21540378 | 7 days ago | IN | 0 ETH | 0.00103994 | ||||
Get Rewards | 21539403 | 7 days ago | IN | 0 ETH | 0.0009815 | ||||
Get Rewards | 21539402 | 7 days ago | IN | 0 ETH | 0.00153338 | ||||
Get Rewards | 21519846 | 10 days ago | IN | 0 ETH | 0.00035658 | ||||
Get Rewards | 21513081 | 11 days ago | IN | 0 ETH | 0.00047005 | ||||
Claim Spectra Re... | 21509786 | 11 days ago | IN | 0 ETH | 0.00048347 | ||||
Get Rewards | 21507840 | 12 days ago | IN | 0 ETH | 0.00027266 | ||||
Get Rewards | 21505839 | 12 days ago | IN | 0 ETH | 0.00041114 | ||||
Get Rewards | 21495622 | 13 days ago | IN | 0 ETH | 0.00120463 | ||||
Get Rewards | 21495620 | 13 days ago | IN | 0 ETH | 0.00123922 | ||||
Get Rewards | 21495109 | 14 days ago | IN | 0 ETH | 0.00113406 | ||||
Claim Spectra Re... | 21487439 | 15 days ago | IN | 0 ETH | 0.00085186 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
CDPVaultSpectra
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 100 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.19; import {CDPVault, IRewardManager, CDPVaultConstants, CDPVaultConfig} from "./CDPVault.sol"; interface ISpectraRewardManager is IRewardManager { function campaignManager() external view returns (address); function updateIndexRewards() external; } interface ICampaignManager { function claim( address token, address rewardToken, uint256 earnedAmount, uint256 claimAmount, bytes32[] calldata merkleProof ) external; } bytes32 constant VAULT_REWARDS_ROLE = keccak256("VAULT_REWARDS_ROLE"); contract CDPVaultSpectra is CDPVault { constructor(CDPVaultConstants memory constants, CDPVaultConfig memory config) CDPVault(constants, config) {} function claimSpectraRewards( address rewardToken, uint256 earnedAmount, uint256 claimAmount, bytes32[] calldata merkleProof ) external onlyRole(VAULT_REWARDS_ROLE) { if (address(rewardManager) != address(0)) { ISpectraRewardManager spectraRewardManager = ISpectraRewardManager(address(rewardManager)); ICampaignManager(spectraRewardManager.campaignManager()).claim( address(token), rewardToken, earnedAmount, claimAmount, merkleProof ); spectraRewardManager.updateIndexRewards(); } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.19; import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {ICDPVaultBase, CDPVaultConstants, CDPVaultConfig} from "./interfaces/ICDPVault.sol"; import {IOracle} from "./interfaces/IOracle.sol"; import {WAD, toInt256, toUint64, max, min, add, sub, wmul, wdiv, wmulUp, abs} from "./utils/Math.sol"; import {Permission} from "./utils/Permission.sol"; import {Pause, PAUSER_ROLE} from "./utils/Pause.sol"; import {IPoolV3} from "./interfaces/IPoolV3.sol"; import {IChefIncentivesController} from "./reward/interfaces/IChefIncentivesController.sol"; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {CreditLogic} from "@gearbox-protocol/core-v3/contracts/libraries/CreditLogic.sol"; import {QuotasLogic} from "@gearbox-protocol/core-v3/contracts/libraries/QuotasLogic.sol"; import {IPoolQuotaKeeperV3} from "@gearbox-protocol/core-v3/contracts/interfaces/IPoolQuotaKeeperV3.sol"; interface IPoolV3Loop is IPoolV3 { function mintProfit(uint256 profit) external; function enter(address user, uint256 amount) external; function exit(address user, uint256 amount) external; function addAvailable(address user, int256 amount) external; } interface IRewardManager { function handleRewardsOnDeposit(address user, uint256 amount, int256 deltaCollateral) external; function handleRewardsOnWithdraw( address user, uint256 amount, int256 deltaCollateral ) external returns (address[] memory, uint256[] memory, address to); } // Authenticated Roles bytes32 constant VAULT_CONFIG_ROLE = keccak256("VAULT_CONFIG_ROLE"); bytes32 constant VAULT_UNWINDER_ROLE = keccak256("VAULT_UNWINDER_ROLE"); /// @title CDPVault /// @notice Base logic of a borrow vault for depositing collateral and drawing credit against it /// @dev All accrued interests is taken by the protocol as profit to be distributed to LP stakers, dLP stakers and the DAO contract CDPVault is AccessControl, Pause, Permission, ICDPVaultBase { /*////////////////////////////////////////////////////////////// LIBRARIES //////////////////////////////////////////////////////////////*/ using SafeERC20 for IERC20; using SafeCast for int256; /*////////////////////////////////////////////////////////////// CONSTANTS //////////////////////////////////////////////////////////////*/ // CDPVault Parameters /// @notice Oracle of the collateral token IOracle public immutable oracle; /// @notice collateral token IERC20 public immutable token; /// @notice Collateral token's decimals scale (10 ** decimals) uint256 public immutable tokenScale; uint256 constant INDEX_PRECISION = 10 ** 9; //uint16 constant PERCENTAGE_FACTOR = 1e4; //percentage plus two decimals IPoolV3 public immutable pool; IERC20 public immutable poolUnderlying; uint256 public immutable poolUnderlyingScale; /*////////////////////////////////////////////////////////////// STORAGE //////////////////////////////////////////////////////////////*/ struct VaultConfig { /// @notice Min. amount of debt that has to be generated by a position [wad] uint128 debtFloor; /// @notice Collateralization ratio below which a position can be liquidated [wad] uint64 liquidationRatio; } /// @notice CDPVault configuration VaultConfig public vaultConfig; // CDPVault Accounting /// @notice Sum of backed debt over all positions [wad] uint256 public totalDebt; struct DebtData { uint256 debt; uint256 cumulativeIndexNow; uint256 cumulativeIndexLastUpdate; uint128 cumulativeQuotaInterest; uint192 cumulativeQuotaIndexNow; uint192 cumulativeQuotaIndexLU; uint256 accruedInterest; // uint256 accruedFees; } // Position Accounting struct Position { uint256 collateral; // [wad] uint256 debt; // [wad] uint256 lastDebtUpdate; // [timestamp] uint256 cumulativeIndexLastUpdate; uint192 cumulativeQuotaIndexLU; uint128 cumulativeQuotaInterest; } /// @notice Map of user positions mapping(address => Position) public positions; struct LiquidationConfig { /// @notice Penalty applied during liquidation [wad] uint64 liquidationPenalty; /// @notice Discount on collateral during liquidation [wad] uint64 liquidationDiscount; } /// @notice Liquidation configuration LiquidationConfig public liquidationConfig; /// @notice Reward incentives controller IChefIncentivesController public rewardController; /// @notice Reward manager IRewardManager public rewardManager; /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event ModifyPosition(address indexed position, uint256 debt, uint256 collateral, uint256 totalDebt); event ModifyCollateralAndDebt( address indexed position, address indexed collateralizer, address indexed creditor, int256 deltaCollateral, int256 deltaDebt ); event SetParameter(bytes32 indexed parameter, uint256 data); event SetParameter(bytes32 indexed parameter, address data); event LiquidatePosition( address indexed position, uint256 collateralReleased, uint256 normalDebtRepaid, address indexed liquidator ); event VaultCreated(address indexed vault, address indexed token, address indexed owner); /*////////////////////////////////////////////////////////////// ERRORS //////////////////////////////////////////////////////////////*/ error CDPVault__modifyPosition_debtFloor(); error CDPVault__modifyCollateralAndDebt_notSafe(); error CDPVault__modifyCollateralAndDebt_noPermission(); error CDPVault__modifyCollateralAndDebt_maxUtilizationRatio(); error CDPVault__setParameter_unrecognizedParameter(); error CDPVault__liquidatePosition_notUnsafe(); error CDPVault__liquidatePosition_invalidSpotPrice(); error CDPVault__liquidatePosition_invalidParameters(); error CDPVault__noBadDebt(); error CDPVault__BadDebt(); error CDPVault__repayAmountNotEnough(); error CDPVault__tooHighRepayAmount(); error CDPVault__recoverERC20_invalidToken(); /*////////////////////////////////////////////////////////////// INITIALIZATION //////////////////////////////////////////////////////////////*/ constructor(CDPVaultConstants memory constants, CDPVaultConfig memory config) { pool = constants.pool; oracle = constants.oracle; token = constants.token; tokenScale = constants.tokenScale; poolUnderlying = IERC20(pool.underlyingToken()); poolUnderlyingScale = 10 ** IERC20Metadata(address(poolUnderlying)).decimals(); vaultConfig = VaultConfig({debtFloor: config.debtFloor, liquidationRatio: config.liquidationRatio}); liquidationConfig = LiquidationConfig({ liquidationPenalty: config.liquidationPenalty, liquidationDiscount: config.liquidationDiscount }); // Access Control Role Admin _grantRole(DEFAULT_ADMIN_ROLE, config.roleAdmin); _grantRole(VAULT_CONFIG_ROLE, config.vaultAdmin); _grantRole(PAUSER_ROLE, config.pauseAdmin); emit VaultCreated(address(this), address(token), config.roleAdmin); } /*////////////////////////////////////////////////////////////// CONFIGURATION //////////////////////////////////////////////////////////////*/ /// @notice Sets various variables for this contract /// @dev Sender has to be allowed to call this method /// @param parameter Name of the variable to set /// @param data New value to set for the variable [wad] function setParameter(bytes32 parameter, uint256 data) external whenNotPaused onlyRole(VAULT_CONFIG_ROLE) { if (parameter == "debtFloor") vaultConfig.debtFloor = uint128(data); else if (parameter == "liquidationRatio") vaultConfig.liquidationRatio = uint64(data); else if (parameter == "liquidationPenalty") liquidationConfig.liquidationPenalty = uint64(data); else if (parameter == "liquidationDiscount") liquidationConfig.liquidationDiscount = uint64(data); else revert CDPVault__setParameter_unrecognizedParameter(); emit SetParameter(parameter, data); } /// @notice Sets various address parameters for this contract /// @dev Sender has to be allowed to call this method /// @param parameter Name of the variable to set /// @param data New address to set for the variable function setParameter(bytes32 parameter, address data) external whenNotPaused onlyRole(VAULT_CONFIG_ROLE) { if (parameter == "rewardController") rewardController = IChefIncentivesController(data); else if (parameter == "rewardManager") rewardManager = IRewardManager(data); else revert CDPVault__setParameter_unrecognizedParameter(); emit SetParameter(parameter, data); } /*////////////////////////////////////////////////////////////// COLLATERAL BALANCE ADMINISTRATION //////////////////////////////////////////////////////////////*/ /// @notice Deposits collateral tokens into this contract and increases a user's collateral balance /// @dev The caller needs to approve this contract to transfer tokens on their behalf /// @param to Address of the user to attribute the collateral to /// @param amount Amount of tokens to deposit [tokenScale] /// @return tokenAmount Amount of collateral deposited [wad] function deposit(address to, uint256 amount) external returns (uint256 tokenAmount) { tokenAmount = wdiv(amount, tokenScale); int256 deltaCollateral = toInt256(tokenAmount); modifyCollateralAndDebt({ owner: to, collateralizer: msg.sender, creditor: msg.sender, deltaCollateral: deltaCollateral, deltaDebt: 0 }); } /// @notice Withdraws collateral tokens from this contract and decreases a user's collateral balance /// @param to Address of the user to withdraw tokens to /// @param amount Amount of tokens to withdraw [tokenScale] /// @return tokenAmount Amount of tokens withdrawn [wad] function withdraw(address to, uint256 amount) external returns (uint256 tokenAmount) { tokenAmount = wdiv(amount, tokenScale); int256 deltaCollateral = -toInt256(tokenAmount); modifyCollateralAndDebt({ owner: to, collateralizer: msg.sender, creditor: msg.sender, deltaCollateral: deltaCollateral, deltaDebt: 0 }); } /// @notice Borrows 'underlying tokens' against collateral /// @param borrower Address of the borrower /// @param position Address of the position /// @param amount Amount of debt to generate [Underlying token scale] /// @return borrowAmount Amount of debt created [wad] /// @dev The borrower will receive the amount of credit in the underlying token function borrow(address borrower, address position, uint256 amount) external returns (uint256 borrowAmount) { borrowAmount = wdiv(amount, poolUnderlyingScale); int256 deltaDebt = toInt256(borrowAmount); modifyCollateralAndDebt({ owner: position, collateralizer: position, creditor: borrower, deltaCollateral: 0, deltaDebt: deltaDebt }); } /// @notice Repays credit against collateral /// @param borrower Address of the borrower /// @param position Address of the position /// @param amount Amount of debt to repay [Underlying token scale] /// @dev The borrower will repay the amount of credit in the underlying token function repay(address borrower, address position, uint256 amount) external returns (uint256 repayAmount){ repayAmount = wdiv(amount, poolUnderlyingScale); int256 deltaDebt = -toInt256(repayAmount); modifyCollateralAndDebt({ owner: position, collateralizer: position, creditor: borrower, deltaCollateral: 0, deltaDebt: deltaDebt }); } /*////////////////////////////////////////////////////////////// PRICING //////////////////////////////////////////////////////////////*/ /// @notice Returns the current spot price of the collateral token /// @return _ Current spot price of the collateral token [wad] function spotPrice() public view returns (uint256) { return oracle.spot(address(token)); } function _handleTokenRewards(address owner, uint256 collateralAmountBefore, int256 deltaCollateral) internal { if (deltaCollateral > 0) { rewardManager.handleRewardsOnDeposit(owner, collateralAmountBefore, deltaCollateral); } else if (deltaCollateral < 0) { (address[] memory tokens, uint256[] memory rewardAmounts, address to) = rewardManager .handleRewardsOnWithdraw(owner, collateralAmountBefore, deltaCollateral); for (uint256 i = 0; i < tokens.length; i++) { if (rewardAmounts[i] != 0) { IERC20(tokens[i]).safeTransfer(to, rewardAmounts[i]); } } } } function getRewards(address owner) external { if (address(rewardManager) != address(0)) { (address[] memory tokens, uint256[] memory rewardAmounts, address to) = rewardManager .handleRewardsOnWithdraw(owner, positions[owner].collateral, 0); for (uint256 i = 0; i < tokens.length; i++) { if (rewardAmounts[i] != 0) { IERC20(tokens[i]).safeTransfer(to, rewardAmounts[i]); } } } } /*////////////////////////////////////////////////////////////// POSITION ADMINISTRATION //////////////////////////////////////////////////////////////*/ /// @notice Updates a position's collateral and debt balances /// @dev This is the only method which is allowed to modify a position's collateral and debt balances /// @param owner Address of the owner of the position /// @param position Position state /// @param newDebt New debt balance [wad] /// @param newCumulativeIndex New cumulative index /// @param deltaCollateral Amount of collateral to put up (+) or to remove (-) from the position [wad] /// @param totalDebt_ Total debt of the vault [wad] function _modifyPosition( address owner, Position memory position, uint256 newDebt, uint256 newCumulativeIndex, int256 deltaCollateral, uint256 totalDebt_ ) internal returns (Position memory) { uint256 currentDebt = position.debt; uint256 collateralBefore = position.collateral; // update collateral and debt amounts by the deltas position.collateral = add(position.collateral, deltaCollateral); position.debt = newDebt; // U:[CM-10,11] position.cumulativeIndexLastUpdate = newCumulativeIndex; // U:[CM-10,11] position.lastDebtUpdate = block.timestamp; // U:[CM-10,11] // position either has no debt or more debt than the debt floor if (position.debt != 0 && position.debt < uint256(vaultConfig.debtFloor)) revert CDPVault__modifyPosition_debtFloor(); // store the position's balances positions[owner] = position; // update the global debt balance if (newDebt > currentDebt) { totalDebt_ = totalDebt_ + (newDebt - currentDebt); } else { totalDebt_ = totalDebt_ - (currentDebt - newDebt); } totalDebt = totalDebt_; if (address(rewardController) != address(0)) { rewardController.handleActionAfter(owner, position.debt, totalDebt_); } if (address(rewardManager) != address(0)) _handleTokenRewards(owner, collateralBefore, deltaCollateral); emit ModifyPosition(owner, position.debt, position.collateral, totalDebt_); return position; } /// @notice Returns true if the collateral value is equal or greater than the debt function _isCollateralized( uint256 debt, uint256 collateralValue, uint256 liquidationRatio ) internal pure returns (bool) { return (wdiv(collateralValue, liquidationRatio) >= debt); } /// @notice Modifies a Position's collateral and debt balances /// @dev Checks that the global debt ceiling and the vault's debt ceiling have not been exceeded via the CDM, /// - that the Position is still safe after the modification, /// - that the msg.sender has the permission of the owner to decrease the collateral-to-debt ratio, /// - that the msg.sender has the permission of the collateralizer to put up new collateral, /// - that the msg.sender has the permission of the creditor to settle debt with their credit, /// - that that the vault debt floor is exceeded /// - that the vault minimum collateralization ratio is met /// @param owner Address of the owner of the position /// @param collateralizer Address of who puts up or receives the collateral delta /// @param creditor Address of who provides or receives the credit delta for the debt delta /// @param deltaCollateral Amount of collateral to put up (+) or to remove (-) from the position [wad] /// @param deltaDebt Amount of normalized debt (gross, before rate is applied) to generate (+) or /// to settle (-) on this position [wad] function modifyCollateralAndDebt( address owner, address collateralizer, address creditor, int256 deltaCollateral, int256 deltaDebt ) public { if ( // position is either more safe than before or msg.sender has the permission from the owner ((deltaDebt > 0 || deltaCollateral < 0) && !hasPermission(owner, msg.sender)) || // msg.sender has the permission of the collateralizer to collateralize the position using their cash (deltaCollateral > 0 && !hasPermission(collateralizer, msg.sender)) || // msg.sender has the permission of the creditor to use their credit to repay the debt (deltaDebt < 0 && !hasPermission(creditor, msg.sender)) ) revert CDPVault__modifyCollateralAndDebt_noPermission(); // if the vault is paused allow only debt decreases if (deltaDebt > 0 || deltaCollateral != 0) { _requireNotPaused(); } Position memory position = positions[owner]; DebtData memory debtData = _calcDebt(position); uint256 newDebt; uint256 newCumulativeIndex; uint256 profit; int256 quotaRevenueChange; if (deltaDebt > 0) { uint256 debtToIncrease = uint256(deltaDebt); // Internal debt calculation remains in 18-decimal precision (newDebt, newCumulativeIndex) = CreditLogic.calcIncrease( debtToIncrease, position.debt, debtData.cumulativeIndexNow, position.cumulativeIndexLastUpdate ); position.cumulativeQuotaInterest = debtData.cumulativeQuotaInterest; position.cumulativeQuotaIndexLU = debtData.cumulativeQuotaIndexNow; quotaRevenueChange = _calcQuotaRevenueChange(deltaDebt); uint256 scaledDebtIncrease = wmul(debtToIncrease, poolUnderlyingScale); pool.lendCreditAccount(scaledDebtIncrease, creditor); } else if (deltaDebt < 0) { uint256 debtToDecrease = abs(deltaDebt); uint256 maxRepayment = calcTotalDebt(debtData); if (debtToDecrease >= maxRepayment) { debtToDecrease = maxRepayment; deltaDebt = -toInt256(debtToDecrease); } uint256 scaledDebtDecrease = wmul(debtToDecrease, poolUnderlyingScale); poolUnderlying.safeTransferFrom(creditor, address(pool), scaledDebtDecrease); uint128 newCumulativeQuotaInterest; if (debtToDecrease == maxRepayment) { newDebt = 0; newCumulativeIndex = debtData.cumulativeIndexNow; profit = debtData.accruedInterest; newCumulativeQuotaInterest = 0; } else { (newDebt, newCumulativeIndex, profit, newCumulativeQuotaInterest) = calcDecrease( debtToDecrease, position.debt, debtData.cumulativeIndexNow, position.cumulativeIndexLastUpdate, debtData.cumulativeQuotaInterest ); } quotaRevenueChange = _calcQuotaRevenueChange(-int(debtData.debt - newDebt)); uint256 scaledRemainingDebt = wmul(debtData.debt - newDebt, poolUnderlyingScale); uint256 scaledProfit = wmul(profit, poolUnderlyingScale); pool.repayCreditAccount(scaledRemainingDebt, scaledProfit, 0); position.cumulativeQuotaInterest = newCumulativeQuotaInterest; position.cumulativeQuotaIndexLU = debtData.cumulativeQuotaIndexNow; } else { newDebt = position.debt; newCumulativeIndex = debtData.cumulativeIndexLastUpdate; } if (deltaCollateral > 0) { uint256 amount = wmul(deltaCollateral.toUint256(), tokenScale); token.safeTransferFrom(collateralizer, address(this), amount); } else if (deltaCollateral < 0) { uint256 amount = wmul(abs(deltaCollateral), tokenScale); token.safeTransfer(collateralizer, amount); } position = _modifyPosition(owner, position, newDebt, newCumulativeIndex, deltaCollateral, totalDebt); VaultConfig memory config = vaultConfig; uint256 spotPrice_ = spotPrice(); uint256 collateralValue = wmul(position.collateral, spotPrice_); if ( (deltaDebt > 0 || deltaCollateral < 0) && !_isCollateralized(calcTotalDebt(_calcDebt(position)), collateralValue, config.liquidationRatio) ) revert CDPVault__modifyCollateralAndDebt_notSafe(); if (quotaRevenueChange != 0) { int256 scaledQuotaRevenueChange = wmul(poolUnderlyingScale, quotaRevenueChange); IPoolV3(pool).updateQuotaRevenue(scaledQuotaRevenueChange); } emit ModifyCollateralAndDebt(owner, collateralizer, creditor, deltaCollateral, deltaDebt); } function _calcQuotaRevenueChange(int256 deltaDebt) internal view returns (int256 quotaRevenueChange) { uint16 rate = IPoolQuotaKeeperV3(poolQuotaKeeper()).getQuotaRate(address(token)); return QuotasLogic.calcQuotaRevenueChange(rate, deltaDebt); } function _calcDebt(Position memory position) internal view returns (DebtData memory cdd) { uint256 index = pool.baseInterestIndex(); cdd.debt = position.debt; cdd.cumulativeIndexNow = index; cdd.cumulativeIndexLastUpdate = position.cumulativeIndexLastUpdate; cdd.cumulativeQuotaIndexLU = position.cumulativeQuotaIndexLU; // Get cumulative quota interest (cdd.cumulativeQuotaInterest, cdd.cumulativeQuotaIndexNow) = _getQuotedTokensData(cdd); cdd.cumulativeQuotaInterest += position.cumulativeQuotaInterest; cdd.accruedInterest = CreditLogic.calcAccruedInterest(cdd.debt, cdd.cumulativeIndexLastUpdate, index); cdd.accruedInterest += cdd.cumulativeQuotaInterest; } /// @dev Returns quotas data for credit manager and credit account function _getQuotedTokensData( DebtData memory cdd ) internal view returns (uint128 outstandingQuotaInterest, uint192 cumulativeQuotaIndexNow) { cumulativeQuotaIndexNow = IPoolQuotaKeeperV3(poolQuotaKeeper()).cumulativeIndex(address(token)); uint128 outstandingInterestDelta = QuotasLogic.calcAccruedQuotaInterest( uint96(cdd.debt), cumulativeQuotaIndexNow, cdd.cumulativeQuotaIndexLU ); outstandingQuotaInterest = outstandingInterestDelta; // U:[CM-24] } /*////////////////////////////////////////////////////////////// LIQUIDATION //////////////////////////////////////////////////////////////*/ /// @notice Liquidates a single unsafe position by selling collateral at a discounted (`liquidationDiscount`) /// oracle price. The liquidator has to provide the amount he wants to repay or sell (`repayAmounts`) for /// the position. From that repay amount a penalty (`liquidationPenalty`) is subtracted to mitigate against /// profitable self liquidations. If the available collateral of a position is not sufficient to cover the debt /// the vault accumulates 'bad debt'. /// @dev The liquidator has to approve the vault to transfer the sum of `repayAmounts`. /// @param owner Owner of the position to liquidate /// @param repayAmount Amount the liquidator wants to repay [wad] function liquidatePosition(address owner, uint256 repayAmount) external whenNotPaused { // validate params if (owner == address(0) || repayAmount == 0) revert CDPVault__liquidatePosition_invalidParameters(); // load configs VaultConfig memory config = vaultConfig; LiquidationConfig memory liqConfig_ = liquidationConfig; // load liquidated position Position memory position = positions[owner]; DebtData memory debtData = _calcDebt(position); // load price and calculate discounted price uint256 spotPrice_ = spotPrice(); uint256 discountedPrice = wmul(spotPrice_, liqConfig_.liquidationDiscount); if (spotPrice_ == 0) revert CDPVault__liquidatePosition_invalidSpotPrice(); // Ensure that there's no bad debt if (calcTotalDebt(debtData) > wmul(position.collateral, discountedPrice)) revert CDPVault__BadDebt(); // compute collateral to take, debt to repay and penalty to pay uint256 takeCollateral = wdiv(repayAmount, discountedPrice); uint256 deltaDebt = wmul(repayAmount, liqConfig_.liquidationPenalty); uint256 penalty = wmul(repayAmount, WAD - liqConfig_.liquidationPenalty); if (takeCollateral > position.collateral) revert CDPVault__tooHighRepayAmount(); // verify that the position is indeed unsafe if (_isCollateralized(calcTotalDebt(debtData), wmul(position.collateral, spotPrice_), config.liquidationRatio)) revert CDPVault__liquidatePosition_notUnsafe(); // transfer the repay amount from the liquidator to the vault poolUnderlying.safeTransferFrom(msg.sender, address(pool), repayAmount - penalty); uint256 newDebt; uint256 profit; uint256 maxRepayment = calcTotalDebt(debtData); uint256 newCumulativeIndex; if (deltaDebt == maxRepayment) { newDebt = 0; newCumulativeIndex = debtData.cumulativeIndexNow; profit = debtData.accruedInterest; position.cumulativeQuotaInterest = 0; } else { (newDebt, newCumulativeIndex, profit, position.cumulativeQuotaInterest) = calcDecrease( deltaDebt, // delta debt debtData.debt, debtData.cumulativeIndexNow, // current cumulative base interest index in Ray debtData.cumulativeIndexLastUpdate, debtData.cumulativeQuotaInterest ); } position.cumulativeQuotaIndexLU = debtData.cumulativeQuotaIndexNow; // update liquidated position position = _modifyPosition(owner, position, newDebt, newCumulativeIndex, -toInt256(takeCollateral), totalDebt); uint256 scaledProfit = wmul(profit, poolUnderlyingScale); uint256 scaledRemainingDebt = wmul(debtData.debt - newDebt, poolUnderlyingScale); pool.repayCreditAccount(scaledRemainingDebt, scaledProfit, 0); // U:[CM-11] // transfer the collateral amount from the vault to the liquidator uint256 scaledTakeCollateral = wmul(takeCollateral, tokenScale); token.safeTransfer(msg.sender, scaledTakeCollateral); // Mint the penalty from the vault to the treasury poolUnderlying.safeTransferFrom(msg.sender, address(pool), penalty); IPoolV3Loop(address(pool)).mintProfit(penalty); if (debtData.debt - newDebt != 0) { uint256 scaledDeltaDebt = wmul(debtData.debt - newDebt, poolUnderlyingScale); IPoolV3(pool).updateQuotaRevenue(_calcQuotaRevenueChange(-int(scaledDeltaDebt))); // U:[PQK-15] } } /// @dev The liquidator has to approve the vault to transfer the sum of `repayAmounts`. /// @param owner Owner of the position to liquidate /// @param repayAmount Amount the liquidator wants to repay [wad] function liquidatePositionBadDebt(address owner, uint256 repayAmount) external whenNotPaused { // validate params if (owner == address(0) || repayAmount == 0) revert CDPVault__liquidatePosition_invalidParameters(); // load configs VaultConfig memory config = vaultConfig; LiquidationConfig memory liqConfig_ = liquidationConfig; // load liquidated position Position memory position = positions[owner]; DebtData memory debtData = _calcDebt(position); uint256 spotPrice_ = spotPrice(); if (spotPrice_ == 0) revert CDPVault__liquidatePosition_invalidSpotPrice(); // verify that the position is indeed unsafe if (_isCollateralized(calcTotalDebt(debtData), wmul(position.collateral, spotPrice_), config.liquidationRatio)) revert CDPVault__liquidatePosition_notUnsafe(); // load price and calculate discounted price uint256 discountedPrice = wmul(spotPrice_, liqConfig_.liquidationDiscount); // Ensure that the debt is greater than the collateral at discounted price if (calcTotalDebt(debtData) <= wmul(position.collateral, discountedPrice)) revert CDPVault__noBadDebt(); // compute collateral to take, debt to repay uint256 takeCollateral = wdiv(repayAmount, discountedPrice); if (takeCollateral < position.collateral) revert CDPVault__repayAmountNotEnough(); // account for bad debt takeCollateral = position.collateral; repayAmount = wmul(takeCollateral, discountedPrice); uint256 loss = calcTotalDebt(debtData) - repayAmount; // transfer the repay amount from the liquidator to the vault uint256 scaledRepayAmount = wmul(repayAmount, poolUnderlyingScale); poolUnderlying.safeTransferFrom(msg.sender, address(pool), scaledRepayAmount); position.cumulativeQuotaInterest = 0; position.cumulativeQuotaIndexLU = debtData.cumulativeQuotaIndexNow; // update liquidated position position = _modifyPosition( owner, position, 0, debtData.cumulativeIndexNow, -toInt256(takeCollateral), totalDebt ); uint256 scaledDebt = wmul(debtData.debt, poolUnderlyingScale); uint256 scaledInterest = wmul(debtData.accruedInterest, poolUnderlyingScale); uint256 scaledLoss = wmul(loss, poolUnderlyingScale); pool.repayCreditAccount(scaledDebt, scaledInterest, scaledLoss); // U:[CM-11] // transfer the collateral amount from the vault to the liquidator uint256 scaledTakeCollateral = wmul(takeCollateral, tokenScale); token.safeTransfer(msg.sender, scaledTakeCollateral); int256 quotaRevenueChange = _calcQuotaRevenueChange(-int(debtData.debt)); if (quotaRevenueChange != 0) { int256 scaledQuotaRevenueChange = wmul(poolUnderlyingScale, quotaRevenueChange); IPoolV3(pool).updateQuotaRevenue(scaledQuotaRevenueChange); // U:[PQK-15] } } /// @dev Computes new debt principal and interest index (and other values) after decreasing debt /// - Debt comprises of multiple components which are repaid in the following order: /// quota update fees => quota interest => base interest => debt principal. /// New values for all these components depend on what portion of each was repaid. /// - Debt principal, for example, only decreases if all previous components were fully repaid /// - The new credit account's interest index stays the same if base interest was not repaid at all, /// is set to the current interest index if base interest was repaid fully, and is a solution to /// the equation `debt * (indexNow / indexLastUpdate - 1) - delta = debt * (indexNow / indexNew - 1)` /// when only `delta` of accrued interest was repaid /// @param amount Amount of debt to repay /// @param debt Debt principal before repayment /// @param cumulativeIndexNow The current interest index /// @param cumulativeIndexLastUpdate Credit account's interest index as of last update /// @return newDebt Debt principal after repayment /// @return newCumulativeIndex Credit account's quota interest after repayment /// @return profit Amount of underlying tokens received as fees by the DAO /// @return newCumulativeQuotaInterest Credit account's accrued quota interest after repayment // @return newQuotaFees Amount of unpaid quota fees left after repayment function calcDecrease( uint256 amount, uint256 debt, uint256 cumulativeIndexNow, uint256 cumulativeIndexLastUpdate, uint128 cumulativeQuotaInterest ) internal pure returns (uint256 newDebt, uint256 newCumulativeIndex, uint256 profit, uint128 newCumulativeQuotaInterest) { uint256 amountToRepay = amount; if (cumulativeQuotaInterest != 0 && amountToRepay != 0) { // All interest accrued on the quota interest is taken by the DAO to be distributed to LP stakers, dLP stakers and the DAO if (amountToRepay >= cumulativeQuotaInterest) { amountToRepay -= cumulativeQuotaInterest; // U:[CL-3] profit += cumulativeQuotaInterest; // U:[CL-3] newCumulativeQuotaInterest = 0; // U:[CL-3] } else { // If amount is not enough to repay quota interest + DAO fee, then send all to the stakers uint256 quotaInterestPaid = amountToRepay; // U:[CL-3] profit += amountToRepay; // U:[CL-3] amountToRepay = 0; // U:[CL-3] newCumulativeQuotaInterest = uint128(cumulativeQuotaInterest - quotaInterestPaid); // U:[CL-3] } } else { newCumulativeQuotaInterest = cumulativeQuotaInterest; } if (amountToRepay != 0) { uint256 interestAccrued = CreditLogic.calcAccruedInterest({ amount: debt, cumulativeIndexLastUpdate: cumulativeIndexLastUpdate, cumulativeIndexNow: cumulativeIndexNow }); // All interest accrued on the base interest is taken by the DAO to be distributed to LP stakers, dLP stakers and the DAO if (amountToRepay >= interestAccrued) { amountToRepay -= interestAccrued; profit += interestAccrued; newCumulativeIndex = cumulativeIndexNow; } else { // If amount is not enough to repay interest, then send all to the stakers and update index profit += amountToRepay; // U:[CL-3] newCumulativeIndex = (INDEX_PRECISION * cumulativeIndexNow * cumulativeIndexLastUpdate) / (INDEX_PRECISION * cumulativeIndexNow - (INDEX_PRECISION * amountToRepay * cumulativeIndexLastUpdate) / debt); // U:[CL-3] amountToRepay = 0; // U:[CL-3] } } else { newCumulativeIndex = cumulativeIndexLastUpdate; } newDebt = debt - amountToRepay; } /// @dev Computes interest accrued since the last update function calcAccruedInterest( uint256 amount, uint256 cumulativeIndexLastUpdate, uint256 cumulativeIndexNow ) internal pure returns (uint256) { if (amount == 0) return 0; return (amount * cumulativeIndexNow) / cumulativeIndexLastUpdate - amount; } /// @notice Returns the total debt of a position /// @param position Address of the position /// @return totalDebt Total debt of the position [wad] function virtualDebt(address position) external view returns (uint256) { return calcTotalDebt(_calcDebt(positions[position])); } /// @dev Computes total debt, given raw debt data /// @param debtData See `DebtData` (must have debt data filled) function calcTotalDebt(DebtData memory debtData) internal pure returns (uint256) { return debtData.debt + debtData.accruedInterest; //+ debtData.accruedFees; } /// @notice Returns address of the quota keeper connected to the pool function poolQuotaKeeper() public view returns (address) { return IPoolV3(pool).poolQuotaKeeper(); // U:[CM-47] } /// @notice Returns quotas interest function quotasInterest(address position) external view returns (uint256) { DebtData memory debtData = _calcDebt(positions[position]); return debtData.cumulativeQuotaInterest; } /// @notice Returns debt data for a position function getDebtData(address position) external view returns (DebtData memory) { return _calcDebt(positions[position]); } /// @notice Returns debt data for a position function getDebtInfo( address position ) external view returns (uint256 debt, uint256 accruedInterest, uint256 cumulativeQuotaInterest) { DebtData memory debtData = _calcDebt(positions[position]); return (debtData.debt, debtData.accruedInterest, debtData.cumulativeQuotaInterest); } /*////////////////////////////////////////////////////////////// RECOVERY //////////////////////////////////////////////////////////////*/ /// @notice Recovers ERC20 tokens from the vault /// @param tokenAddress Address of the token to recover /// @param to Address to recover the token to /// @param tokenAmount Amount of the token to recover /// @dev The token to recover cannot be the same as the collateral token function recoverERC20(address tokenAddress, address to, uint256 tokenAmount) external onlyRole(DEFAULT_ADMIN_ROLE) { if (tokenAddress == address(token)) revert CDPVault__recoverERC20_invalidToken(); IERC20(tokenAddress).safeTransfer(to, tokenAmount); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ```solidity * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ```solidity * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules} * to enforce additional security measures for this role. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(account), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 amount) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value)); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value)); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to * 0 before setting it to a non-zero value. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0)); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token)); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.19; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol"; import {IOracle} from "./IOracle.sol"; import {IPause} from "./IPause.sol"; import {IPermission} from "./IPermission.sol"; import {IInterestRateModel} from "./IInterestRateModel.sol"; import {IPoolV3} from "./IPoolV3.sol"; // Deployment related structs struct CDPVaultConstants { IPoolV3 pool; IOracle oracle; IERC20 token; uint256 tokenScale; } struct CDPVaultConfig { uint128 debtFloor; uint64 liquidationRatio; uint64 liquidationPenalty; uint64 liquidationDiscount; address roleAdmin; address vaultAdmin; address pauseAdmin; } /// @title ICDPVaultBase /// @notice Interface for the CDPVault without `paused` to avoid unnecessary overriding of `paused` in CDPVault interface ICDPVaultBase is IAccessControl, IPause, IPermission { function pool() external view returns (IPoolV3); function oracle() external view returns (IOracle); function token() external view returns (IERC20); function tokenScale() external view returns (uint256); function poolUnderlying() external view returns (IERC20); function poolUnderlyingScale() external view returns (uint256); function vaultConfig() external view returns (uint128 debtFloor, uint64 liquidationRatio); function totalDebt() external view returns (uint256); function positions( address owner ) external view returns ( uint256 collateral, uint256 debt, uint256 lastDebtUpdate, uint256 cumulativeIndexLastUpdate, uint192 cumulativeQuotaIndexLU, uint128 cumulativeQuotaInterest ); function deposit(address to, uint256 amount) external returns (uint256); function withdraw(address to, uint256 amount) external returns (uint256); function spotPrice() external returns (uint256); function modifyCollateralAndDebt( address owner, address collateralizer, address creditor, int256 deltaCollateral, int256 deltaNormalDebt ) external; } /// @title ICDPVault /// @notice Interface for the CDPVault interface ICDPVault is ICDPVaultBase { function paused() external view returns (bool); function virtualDebt(address position) external view returns (uint256); function getAccruedInterest(address position) external view returns (uint256 accruedInterest); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.19; // Authenticated Roles bytes32 constant MANAGER_ROLE = keccak256("MANAGER_ROLE"); interface IOracle { function spot(address token) external view returns (uint256); function getStatus(address token) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.19; /* solhint-disable func-visibility, no-inline-assembly */ error Math__toInt256_overflow(); error Math__toUint64_overflow(); error Math__add_overflow_signed(); error Math__sub_overflow_signed(); error Math__mul_overflow_signed(); error Math__mul_overflow(); error Math__div_overflow(); uint256 constant WAD = 1e18; /// @dev Taken from https://github.com/Vectorized/solady/blob/6d706e05ef43cbed234c648f83c55f3a4bb0a520/src/utils/SafeCastLib.sol#L367 function toInt256(uint256 x) pure returns (int256) { if (x >= 1 << 255) revert Math__toInt256_overflow(); return int256(x); } /// @dev Taken from https://github.com/Vectorized/solady/blob/6d706e05ef43cbed234c648f83c55f3a4bb0a520/src/utils/SafeCastLib.sol#L53 function toUint64(uint256 x) pure returns (uint64) { if (x >= 1 << 64) revert Math__toUint64_overflow(); return uint64(x); } /// @dev Taken from https://github.com/Vectorized/solady/blob/6d706e05ef43cbed234c648f83c55f3a4bb0a520/src/utils/FixedPointMathLib.sol#L602 function abs(int256 x) pure returns (uint256 z) { assembly ("memory-safe") { let mask := sub(0, shr(255, x)) z := xor(mask, add(mask, x)) } } /// @dev Taken from https://github.com/Vectorized/solady/blob/6d706e05ef43cbed234c648f83c55f3a4bb0a520/src/utils/FixedPointMathLib.sol#L620 function min(uint256 x, uint256 y) pure returns (uint256 z) { assembly ("memory-safe") { z := xor(x, mul(xor(x, y), lt(y, x))) } } /// @dev Taken from https://github.com/Vectorized/solady/blob/6d706e05ef43cbed234c648f83c55f3a4bb0a520/src/utils/FixedPointMathLib.sol#L628 function min(int256 x, int256 y) pure returns (int256 z) { assembly ("memory-safe") { z := xor(x, mul(xor(x, y), slt(y, x))) } } /// @dev Taken from https://github.com/Vectorized/solady/blob/6d706e05ef43cbed234c648f83c55f3a4bb0a520/src/utils/FixedPointMathLib.sol#L636 function max(uint256 x, uint256 y) pure returns (uint256 z) { assembly ("memory-safe") { z := xor(x, mul(xor(x, y), gt(y, x))) } } /// @dev Taken from https://github.com/makerdao/dss/blob/fa4f6630afb0624d04a003e920b0d71a00331d98/src/vat.sol#L74 function add(uint256 x, int256 y) pure returns (uint256 z) { assembly ("memory-safe") { z := add(x, y) } if ((y > 0 && z < x) || (y < 0 && z > x)) revert Math__add_overflow_signed(); } /// @dev Taken from https://github.com/makerdao/dss/blob/fa4f6630afb0624d04a003e920b0d71a00331d98/src/vat.sol#L79 function sub(uint256 x, int256 y) pure returns (uint256 z) { assembly ("memory-safe") { z := sub(x, y) } if ((y > 0 && z > x) || (y < 0 && z < x)) revert Math__sub_overflow_signed(); } /// @dev Taken from https://github.com/makerdao/dss/blob/fa4f6630afb0624d04a003e920b0d71a00331d98/src/vat.sol#L84 function mul(uint256 x, int256 y) pure returns (int256 z) { unchecked { z = int256(x) * y; if (int256(x) < 0 || (y != 0 && z / y != int256(x))) revert Math__mul_overflow_signed(); } } /// @dev Equivalent to `(x * y) / WAD` rounded down. /// @dev Taken from https://github.com/Vectorized/solady/blob/6d706e05ef43cbed234c648f83c55f3a4bb0a520/src/utils/FixedPointMathLib.sol#L54 function wmul(uint256 x, uint256 y) pure returns (uint256 z) { assembly ("memory-safe") { // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`. if mul(y, gt(x, div(not(0), y))) { // Store the function selector of `Math__mul_overflow()`. mstore(0x00, 0xc4c5d7f5) // Revert with (offset, size). revert(0x1c, 0x04) } z := div(mul(x, y), WAD) } } function wmul(uint256 x, int256 y) pure returns (int256 z) { unchecked { z = mul(x, y) / int256(WAD); } } /// @dev Equivalent to `(x * y) / WAD` rounded up. /// @dev Taken from https://github.com/Vectorized/solady/blob/969a78905274b32cdb7907398c443f7ea212e4f4/src/utils/FixedPointMathLib.sol#L69C22-L69C22 function wmulUp(uint256 x, uint256 y) pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`. if mul(y, gt(x, div(not(0), y))) { // Store the function selector of `Math__mul_overflow()`. mstore(0x00, 0xc4c5d7f5) // Revert with (offset, size). revert(0x1c, 0x04) } z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD)) } } /// @dev Equivalent to `(x * WAD) / y` rounded down. /// @dev Taken from https://github.com/Vectorized/solady/blob/6d706e05ef43cbed234c648f83c55f3a4bb0a520/src/utils/FixedPointMathLib.sol#L84 function wdiv(uint256 x, uint256 y) pure returns (uint256 z) { assembly ("memory-safe") { // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`. if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) { // Store the function selector of `Math__div_overflow()`. mstore(0x00, 0xbcbede65) // Revert with (offset, size). revert(0x1c, 0x04) } z := div(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded up. /// @dev Taken from https://github.com/Vectorized/solady/blob/969a78905274b32cdb7907398c443f7ea212e4f4/src/utils/FixedPointMathLib.sol#L99 function wdivUp(uint256 x, uint256 y) pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`. if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) { // Store the function selector of `Math__div_overflow()`. mstore(0x00, 0xbcbede65) // Revert with (offset, size). revert(0x1c, 0x04) } z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y)) } } /// @dev Taken from https://github.com/makerdao/dss/blob/fa4f6630afb0624d04a003e920b0d71a00331d98/src/jug.sol#L62 function wpow(uint256 x, uint256 n, uint256 b) pure returns (uint256 z) { unchecked { assembly ("memory-safe") { switch n case 0 { z := b } default { switch x case 0 { z := 0 } default { switch mod(n, 2) case 0 { z := b } default { z := x } let half := div(b, 2) // for rounding. for { n := div(n, 2) } n { n := div(n, 2) } { let xx := mul(x, x) if shr(128, x) { revert(0, 0) } let xxRound := add(xx, half) if lt(xxRound, xx) { revert(0, 0) } x := div(xxRound, b) if mod(n, 2) { let zx := mul(z, x) if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0, 0) } let zxRound := add(zx, half) if lt(zxRound, zx) { revert(0, 0) } z := div(zxRound, b) } } } } } } } /// @dev Taken from https://github.com/Vectorized/solady/blob/cde0a5fb594da8655ba6bfcdc2e40a7c870c0cc0/src/utils/FixedPointMathLib.sol#L110 /// @dev Equivalent to `x` to the power of `y`. /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`. function wpow(int256 x, int256 y) pure returns (int256) { // Using `ln(x)` means `x` must be greater than 0. return wexp((wln(x) * y) / int256(WAD)); } /// @dev Taken from https://github.com/Vectorized/solady/blob/cde0a5fb594da8655ba6bfcdc2e40a7c870c0cc0/src/utils/FixedPointMathLib.sol#L116 /// @dev Returns `exp(x)`, denominated in `WAD`. function wexp(int256 x) pure returns (int256 r) { unchecked { // When the result is < 0.5 we return zero. This happens when // x <= floor(log(0.5e18) * 1e18) ~ -42e18 if (x <= -42139678854452767551) return r; /// @solidity memory-safe-assembly assembly { // When the result is > (2**255 - 1) / 1e18 we can not represent it as an // int. This happens when x >= floor(log((2**255 - 1) / 1e18) * 1e18) ~ 135. if iszero(slt(x, 135305999368893231589)) { mstore(0x00, 0xa37bfec9) // `ExpOverflow()`. revert(0x1c, 0x04) } } // x is now in the range (-42, 136) * 1e18. Convert to (-42, 136) * 2**96 // for more intermediate precision and a binary basis. This base conversion // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78. x = (x << 78) / 5 ** 18; // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers // of two such that exp(x) = exp(x') * 2**k, where k is an integer. // Solving this gives k = round(x / log(2)) and x' = x - k * log(2). int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96; x = x - k * 54916777467707473351141471128; // k is in the range [-61, 195]. // Evaluate using a (6, 7)-term rational approximation. // p is made monic, we'll multiply by a scale factor later. int256 y = x + 1346386616545796478920950773328; y = ((y * x) >> 96) + 57155421227552351082224309758442; int256 p = y + x - 94201549194550492254356042504812; p = ((p * y) >> 96) + 28719021644029726153956944680412240; p = p * x + (4385272521454847904659076985693276 << 96); // We leave p in 2**192 basis so we don't need to scale it back up for the division. int256 q = x - 2855989394907223263936484059900; q = ((q * x) >> 96) + 50020603652535783019961831881945; q = ((q * x) >> 96) - 533845033583426703283633433725380; q = ((q * x) >> 96) + 3604857256930695427073651918091429; q = ((q * x) >> 96) - 14423608567350463180887372962807573; q = ((q * x) >> 96) + 26449188498355588339934803723976023; /// @solidity memory-safe-assembly assembly { // Div in assembly because solidity adds a zero check despite the unchecked. // The q polynomial won't have zeros in the domain as all its roots are complex. // No scaling is necessary because p is already 2**96 too large. r := sdiv(p, q) } // r should be in the range (0.09, 0.25) * 2**96. // We now need to multiply r by: // * the scale factor s = ~6.031367120. // * the 2**k factor from the range reduction. // * the 1e18 / 2**96 factor for base conversion. // We do this all at once, with an intermediate result in 2**213 // basis, so the final right shift is always by a positive amount. r = int256((uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k)); } } /// @dev Taken from https://github.com/Vectorized/solady/blob/cde0a5fb594da8655ba6bfcdc2e40a7c870c0cc0/src/utils/FixedPointMathLib.sol#L184 /// @dev Returns `ln(x)`, denominated in `WAD`. function wln(int256 x) pure returns (int256 r) { unchecked { /// @solidity memory-safe-assembly assembly { if iszero(sgt(x, 0)) { mstore(0x00, 0x1615e638) // `LnWadUndefined()`. revert(0x1c, 0x04) } } // We want to convert x from 10**18 fixed point to 2**96 fixed point. // We do this by multiplying by 2**96 / 10**18. But since // ln(x * C) = ln(x) + ln(C), we can simply do nothing here // and add ln(2**96 / 10**18) at the end. // Compute k = log2(x) - 96, t = 159 - k = 255 - log2(x) = 255 ^ log2(x). int256 t; /// @solidity memory-safe-assembly assembly { t := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) t := or(t, shl(6, lt(0xffffffffffffffff, shr(t, x)))) t := or(t, shl(5, lt(0xffffffff, shr(t, x)))) t := or(t, shl(4, lt(0xffff, shr(t, x)))) t := or(t, shl(3, lt(0xff, shr(t, x)))) // forgefmt: disable-next-item t := xor( t, byte( and(0x1f, shr(shr(t, x), 0x8421084210842108cc6318c6db6d54be)), 0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff ) ) } // Reduce range of x to (1, 2) * 2**96 // ln(2^k * x) = k * ln(2) + ln(x) x = int256(uint256(x << uint256(t)) >> 159); // Evaluate using a (8, 8)-term rational approximation. // p is made monic, we will multiply by a scale factor later. int256 p = x + 3273285459638523848632254066296; p = ((p * x) >> 96) + 24828157081833163892658089445524; p = ((p * x) >> 96) + 43456485725739037958740375743393; p = ((p * x) >> 96) - 11111509109440967052023855526967; p = ((p * x) >> 96) - 45023709667254063763336534515857; p = ((p * x) >> 96) - 14706773417378608786704636184526; p = p * x - (795164235651350426258249787498 << 96); // We leave p in 2**192 basis so we don't need to scale it back up for the division. // q is monic by convention. int256 q = x + 5573035233440673466300451813936; q = ((q * x) >> 96) + 71694874799317883764090561454958; q = ((q * x) >> 96) + 283447036172924575727196451306956; q = ((q * x) >> 96) + 401686690394027663651624208769553; q = ((q * x) >> 96) + 204048457590392012362485061816622; q = ((q * x) >> 96) + 31853899698501571402653359427138; q = ((q * x) >> 96) + 909429971244387300277376558375; /// @solidity memory-safe-assembly assembly { // Div in assembly because solidity adds a zero check despite the unchecked. // The q polynomial is known not to have zeros in the domain. // No scaling required because p is already 2**96 too large. r := sdiv(p, q) } // r is in the range (0, 0.125) * 2**96 // Finalization, we need to: // * multiply by the scale factor s = 5.549… // * add ln(2**96 / 10**18) // * add k * ln(2) // * multiply by 10**18 / 2**96 = 5**18 >> 78 // mul s * 5e18 * 2**96, base is now 5**18 * 2**192 r *= 1677202110996718588342820967067443963516166; // add ln(2) * k * 5e18 * 2**192 r += 16597577552685614221487285958193947469193820559219878177908093499208371 * (159 - t); // add ln(2**96 / 10**18) * 5e18 * 2**192 r += 600920179829731861736702779321621459595472258049074101567377883020018308; // base conversion: mul 2**18 / 2**192 r >>= 174; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.19; import "../interfaces/IPermission.sol"; abstract contract Permission is IPermission { /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event ModifyPermission(address authorizer, address owner, address caller, bool grant); event SetPermittedAgent(address owner, address agent, bool grant); /*////////////////////////////////////////////////////////////// ERRORS //////////////////////////////////////////////////////////////*/ error Permission__modifyPermission_notPermitted(); /*////////////////////////////////////////////////////////////// STORAGE //////////////////////////////////////////////////////////////*/ // User Permissions /// @notice Map specifying whether a `caller` has the permission to perform an action on the `owner`'s behalf mapping(address owner => mapping(address caller => bool permitted)) private _permitted; /// @notice Map specifying whether an `agent` has the permission to modify the permissions of the `owner` mapping(address owner => mapping(address manager => bool permitted)) private _permittedAgents; /*////////////////////////////////////////////////////////////// FUNCTIONS //////////////////////////////////////////////////////////////*/ /// @notice Gives or revokes the permission for `caller` to perform an action on behalf of `msg.sender` /// @param caller Address of the caller to grant or revoke permission for /// @param permitted Whether to grant or revoke permission function modifyPermission(address caller, bool permitted) external { _permitted[msg.sender][caller] = permitted; emit ModifyPermission(msg.sender, msg.sender, caller, permitted); } /// @notice Gives or revokes the permission for `caller` to perform an action on behalf of `owner` /// @param owner Address of the owner /// @param caller Address of the caller to grant or revoke permission for /// @param permitted Whether to grant or revoke permission function modifyPermission(address owner, address caller, bool permitted) external { if (owner != msg.sender && !_permittedAgents[owner][msg.sender]) revert Permission__modifyPermission_notPermitted(); _permitted[owner][caller] = permitted; emit ModifyPermission(msg.sender, owner, caller, permitted); } /// @notice Gives or revokes the permission for the `agent` to modify the permissions of `msg.sender` /// @param agent Address of the agent to grant or revoke permission for /// @param permitted Whether to grant or revoke permission function setPermissionAgent(address agent, bool permitted) external { _permittedAgents[msg.sender][agent] = permitted; emit SetPermittedAgent(msg.sender, agent, permitted); } /// @notice Checks if `caller` has the permission to perform an action on behalf of `owner` /// @param owner Address of the owner /// @param caller Address of the caller /// @return _ whether `caller` has the permission function hasPermission(address owner, address caller) public view returns (bool) { return owner == caller || _permitted[owner][caller]; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.19; import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol"; import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol"; import {IPause} from "../interfaces/IPause.sol"; // Authenticated Roles bytes32 constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); abstract contract Pause is AccessControl, Pausable, IPause { /*////////////////////////////////////////////////////////////// STORAGE //////////////////////////////////////////////////////////////*/ uint256 public pausedAt; /*////////////////////////////////////////////////////////////// FUNCTIONS //////////////////////////////////////////////////////////////*/ function _pause() internal override { super._pause(); pausedAt = block.timestamp; } /// @notice Pauses the contract /// @dev Sender has to be allowed to call this method function pause() external onlyRole(PAUSER_ROLE) { _pause(); } /// @notice Unpauses the contract /// @dev Sender has to be allowed to call this method function unpause() external onlyRole(PAUSER_ROLE) { _unpause(); pausedAt = 0; } }
// 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 setTreasury(address treasury_) external; function setTotalDebtLimit(uint256 newLimit) external; function setCreditManagerDebtLimit(address creditManager, uint256 newLimit) external; function setWithdrawFee(uint256 newWithdrawFee) external; function mintProfit(uint256 amount) external; }
// SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.8.19; interface IChefIncentivesController { /** * @dev Called by the corresponding asset on any update that affects the rewards distribution * @param user The address of the user **/ function handleActionBefore(address user) external; /** * @dev Called by the corresponding asset on any update that affects the rewards distribution * @param user The address of the user * @param userBalance The balance of the user of the asset in the lending pool * @param totalSupply The total supply of the asset in the lending pool **/ function handleActionAfter(address user, uint256 userBalance, uint256 totalSupply) external; /** * @dev Called by the locking contracts after locking or unlocking happens * @param user The address of the user **/ function beforeLockUpdate(address user) external; /** * @notice Hook for lock update. * @dev Called by the locking contracts after locking or unlocking happens */ function afterLockUpdate(address _user) external; function addPool(address _token, uint256 _allocPoint) external; function claim(address _user, address[] calldata _tokens) external; function setClaimReceiver(address _user, address _receiver) external; function getRegisteredTokens() external view returns (address[] memory); function disqualifyUser(address _user, address _hunter) external returns (uint256 bounty); function bountyForUser(address _user) external view returns (uint256 bounty); function allPendingRewards(address _user) external view returns (uint256 pending); function claimAll(address _user) external; function claimBounty(address _user, bool _execute) external returns (bool issueBaseBounty); function setEligibilityExempt(address _address, bool _value) external; function manualStopEmissionsFor(address _user, address[] memory _tokens) external; function manualStopAllEmissionsFor(address _user) external; function setAddressWLstatus(address user, bool status) external; function toggleWhitelist() external; }
// 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: 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 {CollateralDebtData, CollateralTokenData} from "../interfaces/ICreditManagerV3.sol"; import {SECONDS_PER_YEAR, PERCENTAGE_FACTOR} from "@gearbox-protocol/core-v2/contracts/libraries/Constants.sol"; import {BitMask} from "./BitMask.sol"; uint256 constant INDEX_PRECISION = 10 ** 9; /// @title Credit logic library /// @notice Implements functions used for debt and repayment calculations library CreditLogic { using BitMask for uint256; using SafeCast for uint256; // ----------------- // // DEBT AND INTEREST // // ----------------- // /// @dev Computes growth since last update given yearly growth function calcLinearGrowth(uint256 value, uint256 timestampLastUpdate) internal view returns (uint256) { return value * (block.timestamp - timestampLastUpdate) / SECONDS_PER_YEAR; } /// @dev Computes interest accrued since the last update function calcAccruedInterest(uint256 amount, uint256 cumulativeIndexLastUpdate, uint256 cumulativeIndexNow) internal pure returns (uint256) { if (amount == 0) return 0; return (amount * cumulativeIndexNow) / cumulativeIndexLastUpdate - amount; // U:[CL-1] } /// @dev Computes total debt, given raw debt data /// @param collateralDebtData See `CollateralDebtData` (must have debt data filled) function calcTotalDebt(CollateralDebtData memory collateralDebtData) internal pure returns (uint256) { return collateralDebtData.debt + collateralDebtData.accruedInterest + collateralDebtData.accruedFees; } // ----------- // // LIQUIDATION // // ----------- // /// @dev Computes the amount of underlying tokens to send to the pool on credit account liquidation /// - First, liquidation premium and fee are subtracted from account's total value /// - The resulting value is then used to repay the debt to the pool, and any remaining fudns /// are send back to the account owner /// - If, however, funds are insufficient to fully repay the debt, the function will first reduce /// protocol profits before finally reporting a bad debt liquidation with loss /// @param collateralDebtData See `CollateralDebtData` (must have both collateral and debt data filled) /// @param feeLiquidation Liquidation fee charged by the DAO on the account collateral /// @param liquidationDiscount Percentage to discount account collateral by (equals 1 - liquidation premium) /// @param amountWithFeeFn Function that, given the exact amount of underlying tokens to receive, /// returns the amount that needs to be sent /// @param amountWithFeeFn Function that, given the exact amount of underlying tokens to send, /// returns the amount that will be received /// @return amountToPool Amount of underlying tokens to send to the pool /// @return remainingFunds Amount of underlying tokens to send to the credit account owner /// @return profit Amount of underlying tokens received as fees by the DAO /// @return loss Portion of account's debt that can't be repaid function calcLiquidationPayments( CollateralDebtData memory collateralDebtData, uint16 feeLiquidation, uint16 liquidationDiscount, function (uint256) view returns (uint256) amountWithFeeFn, function (uint256) view returns (uint256) amountMinusFeeFn ) internal view returns (uint256 amountToPool, uint256 remainingFunds, uint256 profit, uint256 loss) { amountToPool = calcTotalDebt(collateralDebtData); // U:[CL-4] uint256 debtWithInterest = collateralDebtData.debt + collateralDebtData.accruedInterest; uint256 totalValue = collateralDebtData.totalValue; uint256 totalFunds = totalValue * liquidationDiscount / PERCENTAGE_FACTOR; amountToPool += totalValue * feeLiquidation / PERCENTAGE_FACTOR; // U:[CL-4] uint256 amountToPoolWithFee = amountWithFeeFn(amountToPool); unchecked { if (totalFunds > amountToPoolWithFee) { remainingFunds = totalFunds - amountToPoolWithFee; // U:[CL-4] } else { amountToPoolWithFee = totalFunds; amountToPool = amountMinusFeeFn(totalFunds); // U:[CL-4] } if (amountToPool >= debtWithInterest) { profit = amountToPool - debtWithInterest; // U:[CL-4] } else { loss = debtWithInterest - amountToPool; // U:[CL-4] } } amountToPool = amountToPoolWithFee; // U:[CL-4] } // --------------------- // // LIQUIDATION THRESHOLD // // --------------------- // /// @dev Returns the current liquidation threshold based on token data /// @dev GearboxV3 supports liquidation threshold ramping, which means that the LT can be set to change dynamically /// from one value to another over time. LT changes linearly, starting at `ltInitial` and ending at `ltFinal`. /// To make LT static, the value can be written to `ltInitial` with ramp start set far in the future. function getLiquidationThreshold(uint16 ltInitial, uint16 ltFinal, uint40 timestampRampStart, uint24 rampDuration) internal view returns (uint16) { uint40 timestampRampEnd = timestampRampStart + rampDuration; if (block.timestamp <= timestampRampStart) { return ltInitial; // U:[CL-5] } else if (block.timestamp < timestampRampEnd) { return _getRampingLiquidationThreshold(ltInitial, ltFinal, timestampRampStart, timestampRampEnd); // U:[CL-5] } else { return ltFinal; // U:[CL-5] } } /// @dev Computes the LT during the ramping process function _getRampingLiquidationThreshold( uint16 ltInitial, uint16 ltFinal, uint40 timestampRampStart, uint40 timestampRampEnd ) internal view returns (uint16) { return uint16( (ltInitial * (timestampRampEnd - block.timestamp) + ltFinal * (block.timestamp - timestampRampStart)) / (timestampRampEnd - timestampRampStart) ); // U:[CL-5] } // ----------- // // MANAGE DEBT // // ----------- // /// @dev Computes new debt principal and interest index after increasing debt /// - The new debt principal is simply `debt + amount` /// - The new credit account's interest index is a solution to the equation /// `debt * (indexNow / indexLastUpdate - 1) = (debt + amount) * (indexNow / indexNew - 1)`, /// which essentially writes that interest accrued since last update remains the same /// @param amount Amount to increase debt by /// @param debt Debt principal before increase /// @param cumulativeIndexNow The current interest index /// @param cumulativeIndexLastUpdate Credit account's interest index as of last update /// @return newDebt Debt principal after increase /// @return newCumulativeIndex New credit account's interest index function calcIncrease(uint256 amount, uint256 debt, uint256 cumulativeIndexNow, uint256 cumulativeIndexLastUpdate) internal pure returns (uint256 newDebt, uint256 newCumulativeIndex) { if (debt == 0) return (amount, cumulativeIndexNow); newDebt = debt + amount; // U:[CL-2] newCumulativeIndex = ( (cumulativeIndexNow * newDebt * INDEX_PRECISION) / ((INDEX_PRECISION * cumulativeIndexNow * debt) / cumulativeIndexLastUpdate + INDEX_PRECISION * amount) ); // U:[CL-2] } /// @dev Computes new debt principal and interest index (and other values) after decreasing debt /// - Debt comprises of multiple components which are repaid in the following order: /// quota update fees => quota interest => base interest => debt principal. /// New values for all these components depend on what portion of each was repaid. /// - Debt principal, for example, only decreases if all previous components were fully repaid /// - The new credit account's interest index stays the same if base interest was not repaid at all, /// is set to the current interest index if base interest was repaid fully, and is a solution to /// the equation `debt * (indexNow / indexLastUpdate - 1) - delta = debt * (indexNow / indexNew - 1)` /// when only `delta` of accrued interest was repaid /// @param amount Amount of debt to repay /// @param debt Debt principal before repayment /// @param cumulativeIndexNow The current interest index /// @param cumulativeIndexLastUpdate Credit account's interest index as of last update /// @param cumulativeQuotaInterest Credit account's quota interest before repayment /// @param quotaFees Accrued quota fees /// @param feeInterest Fee on accrued interest (both base and quota) charged by the DAO /// @return newDebt Debt principal after repayment /// @return newCumulativeIndex Credit account's quota interest after repayment /// @return profit Amount of underlying tokens received as fees by the DAO /// @return newCumulativeQuotaInterest Credit account's accrued quota interest after repayment /// @return newQuotaFees Amount of unpaid quota fees left after repayment function calcDecrease( uint256 amount, uint256 debt, uint256 cumulativeIndexNow, uint256 cumulativeIndexLastUpdate, uint128 cumulativeQuotaInterest, uint128 quotaFees, uint16 feeInterest ) internal pure returns ( uint256 newDebt, uint256 newCumulativeIndex, uint256 profit, uint128 newCumulativeQuotaInterest, uint128 newQuotaFees ) { uint256 amountToRepay = amount; unchecked { if (quotaFees != 0) { if (amountToRepay > quotaFees) { newQuotaFees = 0; // U:[CL-3] amountToRepay -= quotaFees; profit = quotaFees; // U:[CL-3] } else { newQuotaFees = quotaFees - uint128(amountToRepay); // U:[CL-3] profit = amountToRepay; // U:[CL-3] amountToRepay = 0; } } } if (cumulativeQuotaInterest != 0 && amountToRepay != 0) { uint256 quotaProfit = (cumulativeQuotaInterest * feeInterest) / PERCENTAGE_FACTOR; if (amountToRepay >= cumulativeQuotaInterest + quotaProfit) { amountToRepay -= cumulativeQuotaInterest + quotaProfit; // U:[CL-3] profit += quotaProfit; // U:[CL-3] newCumulativeQuotaInterest = 0; // U:[CL-3] } else { // If amount is not enough to repay quota interest + DAO fee, then it is split pro-rata between them uint256 amountToPool = (amountToRepay * PERCENTAGE_FACTOR) / (PERCENTAGE_FACTOR + feeInterest); profit += amountToRepay - amountToPool; // U:[CL-3] amountToRepay = 0; // U:[CL-3] newCumulativeQuotaInterest = uint128(cumulativeQuotaInterest - amountToPool); // U:[CL-3] } } else { newCumulativeQuotaInterest = cumulativeQuotaInterest; } if (amountToRepay != 0) { uint256 interestAccrued = calcAccruedInterest({ amount: debt, cumulativeIndexLastUpdate: cumulativeIndexLastUpdate, cumulativeIndexNow: cumulativeIndexNow }); // U:[CL-3] uint256 profitFromInterest = (interestAccrued * feeInterest) / PERCENTAGE_FACTOR; // U:[CL-3] if (amountToRepay >= interestAccrued + profitFromInterest) { amountToRepay -= interestAccrued + profitFromInterest; profit += profitFromInterest; // U:[CL-3] newCumulativeIndex = cumulativeIndexNow; // U:[CL-3] } else { // If amount is not enough to repay base interest + DAO fee, then it is split pro-rata between them uint256 amountToPool = (amountToRepay * PERCENTAGE_FACTOR) / (PERCENTAGE_FACTOR + feeInterest); profit += amountToRepay - amountToPool; // U:[CL-3] amountToRepay = 0; // U:[CL-3] newCumulativeIndex = (INDEX_PRECISION * cumulativeIndexNow * cumulativeIndexLastUpdate) / ( INDEX_PRECISION * cumulativeIndexNow - (INDEX_PRECISION * amountToPool * cumulativeIndexLastUpdate) / debt ); // U:[CL-3] } } else { newCumulativeIndex = cumulativeIndexLastUpdate; // U:[CL-3] } newDebt = debt - amountToRepay; // U:[CL-3] } }
// 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; 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 // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts 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.8.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; import "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value)))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (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 // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.19; interface IPause { function pausedAt() external view returns (uint256); function pause() external; function unpause() external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.19; interface IPermission { function hasPermission(address owner, address caller) external view returns (bool); function modifyPermission(address caller, bool allowed) external; function modifyPermission(address owner, address caller, bool allowed) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.19; interface IInterestRateModel { function getIRS() external view returns (int64, uint64, uint64, uint64, uint256); function getAccruedInterest() external view returns (uint256 accruedInterest); function virtualRateAccumulator() external view returns (uint64 rateAccumulator); }
// 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 // OpenZeppelin Contracts (last updated v4.8.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 // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2022 pragma solidity ^0.8.10; /// @title IVersion /// @dev Declares a version function which returns the contract's version interface IVersion { /// @dev Returns 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; 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: BUSL-1.1 // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Foundation, 2023. pragma solidity ^0.8.17; import {IncorrectParameterException} from "../interfaces/IExceptions.sol"; uint256 constant UNDERLYING_TOKEN_MASK = 1; /// @title Bit mask library /// @notice Implements functions that manipulate bit masks /// Bit masks are utilized extensively by Gearbox to efficiently store token sets (enabled tokens on accounts /// or forbidden tokens) and check for set inclusion. A mask is a uint256 number that has its i-th bit set to /// 1 if i-th item is included into the set. For example, each token has a mask equal to 2**i, so set inclusion /// can be checked by checking tokenMask & setMask != 0. library BitMask { /// @dev Calculates an index of an item based on its mask (using a binary search) /// @dev The input should always have only 1 bit set, otherwise the result may be unpredictable function calcIndex(uint256 mask) internal pure returns (uint8 index) { if (mask == 0) revert IncorrectParameterException(); // U:[BM-1] uint16 lb = 0; // U:[BM-2] uint16 ub = 256; // U:[BM-2] uint16 mid = 128; // U:[BM-2] unchecked { while (true) { uint256 newMask = 1 << mid; if (newMask & mask != 0) return uint8(mid); // U:[BM-2] if (newMask > mask) ub = mid; // U:[BM-2] else lb = mid; // U:[BM-2] mid = (lb + ub) >> 1; // U:[BM-2] } } } /// @dev Calculates the number of `1` bits /// @param enabledTokensMask Bit mask to compute the number of `1` bits in function calcEnabledTokens(uint256 enabledTokensMask) internal pure returns (uint256 totalTokensEnabled) { unchecked { while (enabledTokensMask > 0) { enabledTokensMask &= enabledTokensMask - 1; // U:[BM-3] ++totalTokensEnabled; // U:[BM-3] } } } /// @dev Enables bits from the second mask in the first mask /// @param enabledTokenMask The initial mask /// @param bitsToEnable Mask of bits to enable function enable(uint256 enabledTokenMask, uint256 bitsToEnable) internal pure returns (uint256) { return enabledTokenMask | bitsToEnable; // U:[BM-4] } /// @dev Disables bits from the second mask in the first mask /// @param enabledTokenMask The initial mask /// @param bitsToDisable Mask of bits to disable function disable(uint256 enabledTokenMask, uint256 bitsToDisable) internal pure returns (uint256) { return enabledTokenMask & ~bitsToDisable; // U:[BM-4] } /// @dev Computes a new mask with sets of new enabled and disabled bits /// @dev bitsToEnable and bitsToDisable are applied sequentially to original mask /// @param enabledTokensMask The initial mask /// @param bitsToEnable Mask with bits to enable /// @param bitsToDisable Mask with bits to disable function enableDisable(uint256 enabledTokensMask, uint256 bitsToEnable, uint256 bitsToDisable) internal pure returns (uint256) { return (enabledTokensMask | bitsToEnable) & (~bitsToDisable); // U:[BM-5] } /// @dev Enables bits from the second mask in the first mask, skipping specified bits /// @param enabledTokenMask The initial mask /// @param bitsToEnable Mask with bits to enable /// @param invertedSkipMask An inversion of mask of immutable bits function enable(uint256 enabledTokenMask, uint256 bitsToEnable, uint256 invertedSkipMask) internal pure returns (uint256) { return enabledTokenMask | (bitsToEnable & invertedSkipMask); // U:[BM-6] } /// @dev Disables bits from the second mask in the first mask, skipping specified bits /// @param enabledTokenMask The initial mask /// @param bitsToDisable Mask with bits to disable /// @param invertedSkipMask An inversion of mask of immutable bits function disable(uint256 enabledTokenMask, uint256 bitsToDisable, uint256 invertedSkipMask) internal pure returns (uint256) { return enabledTokenMask & (~(bitsToDisable & invertedSkipMask)); // U:[BM-6] } /// @dev Computes a new mask with sets of new enabled and disabled bits, skipping some bits /// @dev bitsToEnable and bitsToDisable are applied sequentially to original mask. Skipmask is applied in both cases. /// @param enabledTokensMask The initial mask /// @param bitsToEnable Mask with bits to enable /// @param bitsToDisable Mask with bits to disable /// @param invertedSkipMask An inversion of mask of immutable bits function enableDisable( uint256 enabledTokensMask, uint256 bitsToEnable, uint256 bitsToDisable, uint256 invertedSkipMask ) internal pure returns (uint256) { return (enabledTokensMask | (bitsToEnable & invertedSkipMask)) & (~(bitsToDisable & invertedSkipMask)); // U:[BM-7] } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.0; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // 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();
{ "remappings": [ "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/", "permit2/=lib/permit2/src/", "forge-std/=lib/forge-std/src/", "prb-proxy/=lib/prb-proxy/src/", "layerzerolabs/=lib/layerzerolabs/contracts/", "aave-address-book/=lib/aave-address-book/src/", "@gearbox-protocol/core-v3/contracts/=lib/core-v3/contracts/", "@gearbox-protocol/core-v2/contracts/=lib/core-v2/contracts/", "pendle/=lib/pendle/contracts/", "tranchess/=lib/contract-core/contracts/", "@1inch/=lib/core-v3/node_modules/@1inch/", "@aave/core-v3/=lib/aave-address-book/lib/aave-v3-core/", "@aave/periphery-v3/=lib/aave-address-book/lib/aave-v3-periphery/", "@chainlink/=lib/core-v3/node_modules/@chainlink/", "@prb/test/=lib/prb-proxy/lib/prb-test/src/", "aave-v3-core/=lib/aave-address-book/lib/aave-v3-core/", "aave-v3-periphery/=lib/aave-address-book/lib/aave-v3-periphery/", "core-v2/=lib/core-v2/contracts/", "core-v3/=lib/core-v3/contracts/", "ds-test/=lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "forge-gas-snapshot/=lib/permit2/lib/forge-gas-snapshot/src/", "hardhat-deploy/=node_modules/hardhat-deploy/", "hardhat/=node_modules/hardhat/", "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "prb-test/=lib/prb-proxy/lib/prb-test/src/", "solmate/=lib/permit2/lib/solmate/" ], "optimizer": { "enabled": true, "runs": 100 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "viaIR": false, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"components":[{"internalType":"contract IPoolV3","name":"pool","type":"address"},{"internalType":"contract IOracle","name":"oracle","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"tokenScale","type":"uint256"}],"internalType":"struct CDPVaultConstants","name":"constants","type":"tuple"},{"components":[{"internalType":"uint128","name":"debtFloor","type":"uint128"},{"internalType":"uint64","name":"liquidationRatio","type":"uint64"},{"internalType":"uint64","name":"liquidationPenalty","type":"uint64"},{"internalType":"uint64","name":"liquidationDiscount","type":"uint64"},{"internalType":"address","name":"roleAdmin","type":"address"},{"internalType":"address","name":"vaultAdmin","type":"address"},{"internalType":"address","name":"pauseAdmin","type":"address"}],"internalType":"struct CDPVaultConfig","name":"config","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"CDPVault__BadDebt","type":"error"},{"inputs":[],"name":"CDPVault__liquidatePosition_invalidParameters","type":"error"},{"inputs":[],"name":"CDPVault__liquidatePosition_invalidSpotPrice","type":"error"},{"inputs":[],"name":"CDPVault__liquidatePosition_notUnsafe","type":"error"},{"inputs":[],"name":"CDPVault__modifyCollateralAndDebt_maxUtilizationRatio","type":"error"},{"inputs":[],"name":"CDPVault__modifyCollateralAndDebt_noPermission","type":"error"},{"inputs":[],"name":"CDPVault__modifyCollateralAndDebt_notSafe","type":"error"},{"inputs":[],"name":"CDPVault__modifyPosition_debtFloor","type":"error"},{"inputs":[],"name":"CDPVault__noBadDebt","type":"error"},{"inputs":[],"name":"CDPVault__recoverERC20_invalidToken","type":"error"},{"inputs":[],"name":"CDPVault__repayAmountNotEnough","type":"error"},{"inputs":[],"name":"CDPVault__setParameter_unrecognizedParameter","type":"error"},{"inputs":[],"name":"CDPVault__tooHighRepayAmount","type":"error"},{"inputs":[],"name":"Math__add_overflow_signed","type":"error"},{"inputs":[],"name":"Math__mul_overflow_signed","type":"error"},{"inputs":[],"name":"Math__toInt256_overflow","type":"error"},{"inputs":[],"name":"Permission__modifyPermission_notPermitted","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"collateralReleased","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"normalDebtRepaid","type":"uint256"},{"indexed":true,"internalType":"address","name":"liquidator","type":"address"}],"name":"LiquidatePosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":true,"internalType":"address","name":"collateralizer","type":"address"},{"indexed":true,"internalType":"address","name":"creditor","type":"address"},{"indexed":false,"internalType":"int256","name":"deltaCollateral","type":"int256"},{"indexed":false,"internalType":"int256","name":"deltaDebt","type":"int256"}],"name":"ModifyCollateralAndDebt","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"authorizer","type":"address"},{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"bool","name":"grant","type":"bool"}],"name":"ModifyPermission","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"position","type":"address"},{"indexed":false,"internalType":"uint256","name":"debt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateral","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"totalDebt","type":"uint256"}],"name":"ModifyPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"parameter","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"data","type":"uint256"}],"name":"SetParameter","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"parameter","type":"bytes32"},{"indexed":false,"internalType":"address","name":"data","type":"address"}],"name":"SetParameter","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"agent","type":"address"},{"indexed":false,"internalType":"bool","name":"grant","type":"bool"}],"name":"SetPermittedAgent","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":"vault","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"VaultCreated","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"position","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"borrow","outputs":[{"internalType":"uint256","name":"borrowAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"rewardToken","type":"address"},{"internalType":"uint256","name":"earnedAmount","type":"uint256"},{"internalType":"uint256","name":"claimAmount","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"}],"name":"claimSpectraRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"getDebtData","outputs":[{"components":[{"internalType":"uint256","name":"debt","type":"uint256"},{"internalType":"uint256","name":"cumulativeIndexNow","type":"uint256"},{"internalType":"uint256","name":"cumulativeIndexLastUpdate","type":"uint256"},{"internalType":"uint128","name":"cumulativeQuotaInterest","type":"uint128"},{"internalType":"uint192","name":"cumulativeQuotaIndexNow","type":"uint192"},{"internalType":"uint192","name":"cumulativeQuotaIndexLU","type":"uint192"},{"internalType":"uint256","name":"accruedInterest","type":"uint256"}],"internalType":"struct CDPVault.DebtData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"getDebtInfo","outputs":[{"internalType":"uint256","name":"debt","type":"uint256"},{"internalType":"uint256","name":"accruedInterest","type":"uint256"},{"internalType":"uint256","name":"cumulativeQuotaInterest","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"getRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"caller","type":"address"}],"name":"hasPermission","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"repayAmount","type":"uint256"}],"name":"liquidatePosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"repayAmount","type":"uint256"}],"name":"liquidatePositionBadDebt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"liquidationConfig","outputs":[{"internalType":"uint64","name":"liquidationPenalty","type":"uint64"},{"internalType":"uint64","name":"liquidationDiscount","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"collateralizer","type":"address"},{"internalType":"address","name":"creditor","type":"address"},{"internalType":"int256","name":"deltaCollateral","type":"int256"},{"internalType":"int256","name":"deltaDebt","type":"int256"}],"name":"modifyCollateralAndDebt","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"caller","type":"address"},{"internalType":"bool","name":"permitted","type":"bool"}],"name":"modifyPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"caller","type":"address"},{"internalType":"bool","name":"permitted","type":"bool"}],"name":"modifyPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"oracle","outputs":[{"internalType":"contract IOracle","name":"","type":"address"}],"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":"pausedAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pool","outputs":[{"internalType":"contract IPoolV3","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolQuotaKeeper","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolUnderlying","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolUnderlyingScale","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"positions","outputs":[{"internalType":"uint256","name":"collateral","type":"uint256"},{"internalType":"uint256","name":"debt","type":"uint256"},{"internalType":"uint256","name":"lastDebtUpdate","type":"uint256"},{"internalType":"uint256","name":"cumulativeIndexLastUpdate","type":"uint256"},{"internalType":"uint192","name":"cumulativeQuotaIndexLU","type":"uint192"},{"internalType":"uint128","name":"cumulativeQuotaInterest","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"quotasInterest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"recoverERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"position","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"repay","outputs":[{"internalType":"uint256","name":"repayAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rewardController","outputs":[{"internalType":"contract IChefIncentivesController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardManager","outputs":[{"internalType":"contract IRewardManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"parameter","type":"bytes32"},{"internalType":"uint256","name":"data","type":"uint256"}],"name":"setParameter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"parameter","type":"bytes32"},{"internalType":"address","name":"data","type":"address"}],"name":"setParameter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"agent","type":"address"},{"internalType":"bool","name":"permitted","type":"bool"}],"name":"setPermissionAgent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"spotPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenScale","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vaultConfig","outputs":[{"internalType":"uint128","name":"debtFloor","type":"uint128"},{"internalType":"uint64","name":"liquidationRatio","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"position","type":"address"}],"name":"virtualDebt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
6101406040523480156200001257600080fd5b5060405162004ace38038062004ace833981016040819052620000359162000418565b6001805460ff1916905581516001600160a01b0390811660e0819052602080850151831660805260408086015190931660a052606085015160c0528251632495a59960e01b815292518593859392632495a599926004808401938290030181865afa158015620000a9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000cf919062000547565b6001600160a01b03166101008190526040805163313ce56760e01b8152905163313ce567916004808201926020929091908290030181865afa1580156200011a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200014091906200056e565b6200014d90600a620006a6565b6101205260408051808201825282516001600160801b03168082526020808501516001600160401b03908116938201849052600580546001600160c01b031916909317600160801b909402939093179091558251808401845292840151821680845260608501519092169201829052600880546001600160801b031916909117680100000000000000009092029190911790556080810151620001f390600090620002b9565b620002297f7e2be3cffb06427cbcb9b1d12d4b78adcf14a2bf640e9bbdeb54bb711b65ec718260a00151620002b960201b60201c565b6200025f7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a8260c00151620002b960201b60201c565b80608001516001600160a01b031660a0516001600160a01b0316306001600160a01b03167f897c133dfbfe1f6239e98b4ffd7e4f6c86a62350a131a7a37790419f58af02f960405160405180910390a450505050620006b7565b620002c5828262000342565b6200033e576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620002fd3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff165b92915050565b604051608081016001600160401b03811182821017156200039e57634e487b7160e01b600052604160045260246000fd5b60405290565b60405160e081016001600160401b03811182821017156200039e57634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114620003eb57600080fd5b50565b80516001600160401b03811681146200040657600080fd5b919050565b80516200040681620003d5565b6000808284036101608112156200042e57600080fd5b60808112156200043d57600080fd5b620004476200036d565b84516200045481620003d5565b815260208501516200046681620003d5565b602082015260408501516200047b81620003d5565b604082015260608581015190820152925060e0607f19820112156200049f57600080fd5b50620004aa620003a4565b60808401516001600160801b0381168114620004c557600080fd5b8152620004d560a08501620003ee565b6020820152620004e860c08501620003ee565b6040820152620004fb60e08501620003ee565b60608201526200050f61010085016200040b565b60808201526200052361012085016200040b565b60a08201526200053761014085016200040b565b60c0820152809150509250929050565b6000602082840312156200055a57600080fd5b81516200056781620003d5565b9392505050565b6000602082840312156200058157600080fd5b815160ff811681146200056757600080fd5b634e487b7160e01b600052601160045260246000fd5b600181815b80851115620005ea578160001904821115620005ce57620005ce62000593565b80851615620005dc57918102915b93841c9390800290620005ae565b509250929050565b600082620006035750600162000367565b81620006125750600062000367565b81600181146200062b5760028114620006365762000656565b600191505062000367565b60ff8411156200064a576200064a62000593565b50506001821b62000367565b5060208310610133831016604e8410600b84101617156200067b575081810a62000367565b620006878383620005a9565b80600019048211156200069e576200069e62000593565b029392505050565b60006200056760ff841683620005f2565b60805160a05160c05160e051610100516101205161428562000849600039600081816102e60152818161086601528181610d8c01528181610e5901528181610e8b01528181610eb901528181610ff1015281816110ff015281816118020152818161183f0152818161201d015281816121190152818161221b01526124a101526000818161060a01528181610dbf015281816117430152818161195d015261214c01526000818161031b01528181610de201528181610f040152818161102f015281816117100152818161188a01528181611980015281816119bb01528181611a5201528181611d550152818161206a0152818161216f01528181612266015281816124df01526128bc01526000818161041301528181610f70015281816110af015281816118f6015281816123200152612790015260008181610785015281816107f401528181610ac301528181610fa3015281816111ea0152818161192901528181612353015281816123ae01528181612e7e01526132cb0152600081816105e30152610a9601526142856000f3fe608060405234801561001057600080fd5b506004361061027f5760003560e01c8063723507be1161015c578063a217fddf116100ce578063d9c70f5711610087578063d9c70f57146106c9578063de55f11e146106dc578063df4014d91461075a578063f3fef3a31461076d578063fc0c546a14610780578063fc7b9c18146107a757600080fd5b8063a217fddf1461066d578063be8da14b14610675578063c11e47341461067d578063c75a4b5e14610690578063cde68041146106a3578063d547741f146106b657600080fd5b80637dc0d1d0116101205780637dc0d1d0146105de5780637dff3797146106055780638309dbdd1461062c5780638456cb591461063f5780638cc5ce991461064757806391d148541461065a57600080fd5b8063723507be14610546578063745b5ef51461055957806376f899651461056c57806379ee54f71461057f5780637cc34bb41461059257600080fd5b80632f2ff15d116101f557806341c2f54c116101b957806341c2f54c1461045857806347e7ef241461046b5780635224372c1461047e57806355f575101461049157806357e2a73f146105285780635c975abb1461053b57600080fd5b80632f2ff15d146103fb578063342c02b11461040e57806336568abe14610435578063398482d8146104485780633f4ba83a1461045057600080fd5b80631c580ad5116102475780631c580ad51461033d5780631da649cf1461037b578063248a9ca31461038e578063280c37ef146103b15780632aa5270e146103c45780632e55d0f2146103f257600080fd5b806301ffc9a7146102845780630f4ef8a6146102ac5780631171bda9146102cc5780631665e3fe146102e157806316f0115b14610316575b600080fd5b6102976102923660046139fa565b6107b0565b60405190151581526020015b60405180910390f35b600a546102bf906001600160a01b031681565b6040516102a39190613a24565b6102df6102da366004613a4d565b6107e7565b005b6103087f000000000000000000000000000000000000000000000000000000000000000081565b6040519081526020016102a3565b6102bf7f000000000000000000000000000000000000000000000000000000000000000081565b60085461035b906001600160401b0380821691600160401b90041682565b604080516001600160401b039384168152929091166020830152016102a3565b610308610389366004613a4d565b61085e565b61030861039c366004613a8e565b60009081526020819052604090206001015490565b6102df6103bf366004613ab5565b6108b8565b6103d76103d2366004613aee565b61092f565b604080519384526020840192909252908201526060016102a3565b61030860025481565b6102df610409366004613b0b565b6109cf565b6103087f000000000000000000000000000000000000000000000000000000000000000081565b6102df610443366004613b0b565b6109f9565b610308610a7c565b6102df610b31565b6102df610466366004613b30565b610b6b565b610308610479366004613b30565b6110a7565b61030861048c366004613a4d565b6110f7565b6104e961049f366004613aee565b60076020526000908152604090208054600182015460028301546003840154600485015460059095015493949293919290916001600160c01b03909116906001600160801b031686565b6040805196875260208701959095529385019290925260608401526001600160c01b031660808301526001600160801b031660a082015260c0016102a3565b6102df610536366004613b5c565b611130565b60015460ff16610297565b6102df610554366004613bf4565b6112be565b610308610567366004613aee565b611443565b6102df61057a366004613b30565b6114d0565b6102df61058d366004613aee565b611ae9565b6005546105b7906001600160801b03811690600160801b90046001600160401b031682565b604080516001600160801b0390931683526001600160401b039091166020830152016102a3565b6102bf7f000000000000000000000000000000000000000000000000000000000000000081565b6102bf7f000000000000000000000000000000000000000000000000000000000000000081565b6102df61063a366004613c16565b611c27565b6102df611cf6565b6009546102bf906001600160a01b031681565b610297610668366004613b0b565b611d28565b610308600081565b6102bf611d51565b6102df61068b366004613b0b565b611dd5565b6102df61069e366004613c61565b611ea4565b6102976106b1366004613cbc565b6125b5565b6102df6106c4366004613b0b565b612603565b6102df6106d7366004613ab5565b612628565b6106ef6106ea366004613aee565b61268b565b6040516102a391908151815260208083015190820152604080830151908201526060808301516001600160801b0316908201526080808301516001600160c01b039081169183019190915260a0808401519091169082015260c0918201519181019190915260e00190565b610308610768366004613aee565b61270d565b61030861077b366004613b30565b612788565b6102bf7f000000000000000000000000000000000000000000000000000000000000000081565b61030860065481565b60006001600160e01b03198216637965db0b60e01b14806107e157506301ffc9a760e01b6001600160e01b03198316145b92915050565b60006107f2816127ca565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316036108445760405163df3f588760e01b815260040160405180910390fd5b6108586001600160a01b03851684846127d4565b50505050565b600061088a827f0000000000000000000000000000000000000000000000000000000000000000612837565b9050600061089782612886565b6108a090613d00565b90506108b0848587600085611ea4565b509392505050565b3360008181526004602090815260408083206001600160a01b03871680855290835292819020805460ff1916861515908117909155815194855291840192909252908201527f6501e8bfa2d3e686d62fe2c0c3275df594494583b0a63a70b7452d3eeb712bd6906060015b60405180910390a15050565b6001600160a01b0381166000908152600760209081526040808320815160c081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546001600160c01b03166080830152600501546001600160801b031660a08201528190819081906109ac906128b0565b805160c082015160609092015190979196506001600160801b0316945092505050565b6000828152602081905260409020600101546109ea816127ca565b6109f483836129e9565b505050565b6001600160a01b0381163314610a6e5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084015b60405180910390fd5b610a788282612a6d565b5050565b604051632cbf04c160e01b81526000906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690632cbf04c190610aeb907f000000000000000000000000000000000000000000000000000000000000000090600401613a24565b602060405180830381865afa158015610b08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b2c9190613d1c565b905090565b7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a610b5b816127ca565b610b63612ad2565b506000600255565b610b73612b1e565b6001600160a01b0382161580610b87575080155b15610ba557604051632bdc849360e21b815260040160405180910390fd5b604080518082018252600580546001600160801b0380821684526001600160401b03600160801b9092048216602080860191909152855180870187526008548085168252600160401b9004909316838201526001600160a01b038816600090815260078252868120875160c081018952815481526001820154938101939093526002810154978301979097526003870154606083015260048701546001600160c01b0316608083015295909301541660a08301529192610c64826128b0565b90506000610c70610a7c565b905080600003610c9357604051636ec7a8fb60e11b815260040160405180910390fd5b610cbe610c9f83612b66565b8451610cab9084612b79565b87602001516001600160401b0316612ba7565b15610cdc5760405163f87e38e960e01b815260040160405180910390fd5b6000610cf58286602001516001600160401b0316612b79565b9050610d05846000015182612b79565b610d0e84612b66565b11610d2c5760405163196e08b760e21b815260040160405180910390fd5b6000610d388883612837565b8551909150811015610d5d5760405163031e966360e01b815260040160405180910390fd5b508351610d6a8183612b79565b9750600088610d7886612b66565b610d829190613d35565b90506000610db08a7f0000000000000000000000000000000000000000000000000000000000000000612b79565b9050610e076001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016337f000000000000000000000000000000000000000000000000000000000000000084612bbe565b600060a088018190526080808801516001600160c01b0316908901526020870151610e4b918d918a9190610e3a88612886565b610e4390613d00565b600654612bf6565b96506000610e7d87600001517f0000000000000000000000000000000000000000000000000000000000000000612b79565b90506000610eaf8860c001517f0000000000000000000000000000000000000000000000000000000000000000612b79565b90506000610edd857f0000000000000000000000000000000000000000000000000000000000000000612b79565b6040516332a5417960e21b81526004810185905260248101849052604481018290529091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ca9505e490606401600060405180830381600087803b158015610f5057600080fd5b505af1158015610f64573d6000803e3d6000fd5b505050506000610f94877f0000000000000000000000000000000000000000000000000000000000000000612b79565b9050610fca6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001633836127d4565b6000610fe28b60000151610fdd90613d00565b612e63565b905080156110955760006110167f000000000000000000000000000000000000000000000000000000000000000083612f06565b604051636b22c77560e11b8152600481018290529091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063d6458eea90602401600060405180830381600087803b15801561107b57600080fd5b505af115801561108f573d6000803e3d6000fd5b50505050505b50505050505050505050505050505050565b60006110d3827f0000000000000000000000000000000000000000000000000000000000000000612837565b905060006110e082612886565b90506110f0843333846000611ea4565b5092915050565b6000611123827f0000000000000000000000000000000000000000000000000000000000000000612837565b905060006108a082612886565b7fce5edea930af7792c7c00eb1f483cf90e1090eb568e1ee0689369fb7278f947661115a816127ca565b600a546001600160a01b0316156112b657600a5460408051637daf3b7360e11b815290516001600160a01b0390921691829163fb5e76e69160048083019260209291908290030181865afa1580156111b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111da9190613d58565b6001600160a01b031663fa46d7ac7f000000000000000000000000000000000000000000000000000000000000000089898989896040518763ffffffff1660e01b815260040161122f96959493929190613d75565b600060405180830381600087803b15801561124957600080fd5b505af115801561125d573d6000803e3d6000fd5b50505050806001600160a01b031663f4c318326040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561129c57600080fd5b505af11580156112b0573d6000803e3d6000fd5b50505050505b505050505050565b6112c6612b1e565b7f7e2be3cffb06427cbcb9b1d12d4b78adcf14a2bf640e9bbdeb54bb711b65ec716112f0816127ca565b82683232b13a233637b7b960b91b0361132357600580546001600160801b0319166001600160801b038416179055611404565b826f6c69717569646174696f6e526174696f60801b03611367576005805467ffffffffffffffff60801b1916600160801b6001600160401b03851602179055611404565b82716c69717569646174696f6e50656e616c747960701b036113a4576008805467ffffffffffffffff19166001600160401b038416179055611404565b82721b1a5c5d5a59185d1a5bdb911a5cd8dbdd5b9d606a1b036113eb576008805467ffffffffffffffff60401b1916600160401b6001600160401b03851602179055611404565b604051638dd691e760e01b815260040160405180910390fd5b827f4327e67d6578eb2c9293fb22f9334006073ac1397c7100f5dd5adca09ad71c088360405161143691815260200190565b60405180910390a2505050565b6001600160a01b0381166000908152600760209081526040808320815160c081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546001600160c01b03166080830152600501546001600160801b031660a082015281906114bc906128b0565b606001516001600160801b03169392505050565b6114d8612b1e565b6001600160a01b03821615806114ec575080155b1561150a57604051632bdc849360e21b815260040160405180910390fd5b604080518082018252600580546001600160801b0380821684526001600160401b03600160801b9092048216602080860191909152855180870187526008548085168252600160401b9004909316838201526001600160a01b038816600090815260078252868120875160c081018952815481526001820154938101939093526002810154978301979097526003870154606083015260048701546001600160c01b0316608083015295909301541660a083015291926115c9826128b0565b905060006115d5610a7c565b905060006115f08286602001516001600160401b0316612b79565b90508160000361161357604051636ec7a8fb60e11b815260040160405180910390fd5b835161161f9082612b79565b61162884612b66565b11156116475760405163b53a43fd60e01b815260040160405180910390fd5b60006116538883612837565b9050600061166e8988600001516001600160401b0316612b79565b9050600061169c8a89600001516001600160401b0316670de0b6b3a76400006116979190613d35565b612b79565b87519091508311156116c15760405163542e88e560e11b815260040160405180910390fd5b6116ec6116cd87612b66565b88516116d99088612b79565b8b602001516001600160401b0316612ba7565b1561170a5760405163f87e38e960e01b815260040160405180910390fd5b61176b337f0000000000000000000000000000000000000000000000000000000000000000611739848e613d35565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016929190612bbe565b600080600061177989612b66565b905060008186036117a15750602089015160c08a0151600060a08d01819052945092506117d5565b6117be868b600001518c602001518d604001518e60600151612f30565b6001600160801b031660a08f015291955090935090505b6080808b01516001600160c01b0316908c01526117f88f8c8684610e3a8c612886565b9a506000611826847f0000000000000000000000000000000000000000000000000000000000000000612b79565b90506000611863868d6000015161183d9190613d35565b7f0000000000000000000000000000000000000000000000000000000000000000612b79565b6040516332a5417960e21b81526004810182905260248101849052600060448201529091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ca9505e490606401600060405180830381600087803b1580156118d657600080fd5b505af11580156118ea573d6000803e3d6000fd5b50505050600061191a8a7f0000000000000000000000000000000000000000000000000000000000000000612b79565b90506119506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001633836127d4565b6119a56001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016337f00000000000000000000000000000000000000000000000000000000000000008b612bbe565b60405163369a8cf560e21b8152600481018990527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063da6a33d490602401600060405180830381600087803b158015611a0757600080fd5b505af1158015611a1b573d6000803e3d6000fd5b50508e51611a2c9250899150613d35565b15611ad5576000611a46888f6000015161183d9190613d35565b90506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663d6458eea611a83610fdd84613d00565b6040518263ffffffff1660e01b8152600401611aa191815260200190565b600060405180830381600087803b158015611abb57600080fd5b505af1158015611acf573d6000803e3d6000fd5b50505050505b505050505050505050505050505050505050565b600a546001600160a01b031615611c2457600a546001600160a01b038281166000908152600760205260408082205490516363fcb8d760e11b815291938493849391169163c7f971ae91611b439188918690600401613dd8565b6000604051808303816000875af1158015611b62573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611b8a9190810190613ecd565b92509250925060005b8351811015611c1f57828181518110611bae57611bae613fa1565b6020026020010151600014611c0d57611c0d82848381518110611bd357611bd3613fa1565b6020026020010151868481518110611bed57611bed613fa1565b60200260200101516001600160a01b03166127d49092919063ffffffff16565b80611c1781613fb7565b915050611b93565b505050505b50565b6001600160a01b0383163314801590611c6457506001600160a01b038316600090815260046020908152604080832033845290915290205460ff16155b15611c8257604051638743d2ff60e01b815260040160405180910390fd5b6001600160a01b0383811660009081526003602090815260408083209386168352929052819020805460ff1916831515179055517fdcf2bd5a4c47afeb1792d170f6f5e6e528e30c6b546fffe62b697a11f8953b2b90611ce9903390869086908690613fd0565b60405180910390a1505050565b7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a611d20816127ca565b611c24613096565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663be8da14b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611db1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b2c9190613d58565b611ddd612b1e565b7f7e2be3cffb06427cbcb9b1d12d4b78adcf14a2bf640e9bbdeb54bb711b65ec71611e07816127ca565b826f3932bbb0b93221b7b73a3937b63632b960811b03611e4157600980546001600160a01b0319166001600160a01b038416179055611e74565b826c3932bbb0b93226b0b730b3b2b960991b036113eb57600a80546001600160a01b0319166001600160a01b0384161790555b827f83e498545bbe12d733822c752ac843578daa6554fe6f90753853156c3478e4f0836040516114369190613a24565b6000811380611eb35750600082125b8015611ec65750611ec485336125b5565b155b80611ee35750600082138015611ee35750611ee184336125b5565b155b80611f005750600081128015611f005750611efe83336125b5565b155b15611f1e57604051634c26249960e01b815260040160405180910390fd5b6000811380611f2c57508115155b15611f3957611f39612b1e565b6001600160a01b0385166000908152600760209081526040808320815160c081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546001600160c01b03166080830152600501546001600160801b031660a082015290611fb1826128b0565b905060008060008060008713156120cf576000879050611fdf81886020015188602001518a606001516130a4565b60608801516001600160801b031660a08a01526080808901516001600160c01b0316908a0152909550935061201388612e63565b91506000612041827f0000000000000000000000000000000000000000000000000000000000000000612b79565b60405163bf28068b60e01b8152600481018290526001600160a01b038d811660248301529192507f00000000000000000000000000000000000000000000000000000000000000009091169063bf28068b90604401600060405180830381600087803b1580156120b057600080fd5b505af11580156120c4573d6000803e3d6000fd5b505050505050612307565b60008712156122f85760ff87901c600090810380890118906120f087612b66565b90508082106121115780915061210582612886565b61210e90613d00565b98505b600061213d837f0000000000000000000000000000000000000000000000000000000000000000612b79565b90506121946001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168d7f000000000000000000000000000000000000000000000000000000000000000084612bbe565b60008284036121b85760009750886020015196508860c001519550600090506121e0565b6121d5848b602001518b602001518d606001518d60600151612f30565b929a50909850965090505b88516121fa906121f1908a90613d35565b610fdd90613d00565b94506000612211898b6000015161183d9190613d35565b9050600061223f887f0000000000000000000000000000000000000000000000000000000000000000612b79565b6040516332a5417960e21b81526004810184905260248101829052600060448201529091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063ca9505e490606401600060405180830381600087803b1580156122b257600080fd5b505af11580156122c6573d6000803e3d6000fd5b5050506001600160801b0390931660a08d01525050506080808901516001600160c01b0316908a015250612307915050565b85602001519350846040015192505b600088131561238157600061234461231e8a613130565b7f0000000000000000000000000000000000000000000000000000000000000000612b79565b905061237b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168c3084612bbe565b506123d7565b60008812156123d757600061239f60ff8a901c8203808b011861231e565b90506123d56001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168c836127d4565b505b6123e78b8786868c600654612bf6565b604080518082019091526005546001600160801b0381168252600160801b90046001600160401b031660208201529096506000612422610a7c565b90506000612434896000015183612b79565b905060008a1380612445575060008b125b8015612476575061247461246061245b8b6128b0565b612b66565b8285602001516001600160401b0316612ba7565b155b1561249457604051633f66923d60e01b815260040160405180910390fd5b83156125455760006124c67f000000000000000000000000000000000000000000000000000000000000000086612f06565b604051636b22c77560e11b8152600481018290529091507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063d6458eea90602401600060405180830381600087803b15801561252b57600080fd5b505af115801561253f573d6000803e3d6000fd5b50505050505b8b6001600160a01b03168d6001600160a01b03168f6001600160a01b03167f7ce3e27b99e7e2e42f0ddcb6f6679a25081a5fd4ca991bcd05c45e54daa997088e8e60405161259d929190918252602082015260400190565b60405180910390a45050505050505050505050505050565b6000816001600160a01b0316836001600160a01b031614806125fc57506001600160a01b0380841660009081526003602090815260408083209386168352929052205460ff165b9392505050565b60008281526020819052604090206001015461261e816127ca565b6109f48383612a6d565b3360008181526003602090815260408083206001600160a01b038716845290915290819020805460ff1916841515179055517fdcf2bd5a4c47afeb1792d170f6f5e6e528e30c6b546fffe62b697a11f8953b2b9161092391819086908690613fd0565b6126936139a2565b6001600160a01b038216600090815260076020908152604091829020825160c081018452815481526001820154928101929092526002810154928201929092526003820154606082015260048201546001600160c01b031660808201526005909101546001600160801b031660a08201526107e1906128b0565b6001600160a01b0381166000908152600760209081526040808320815160c081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546001600160c01b03166080830152600501546001600160801b031660a08201526107e19061245b906128b0565b60006127b4827f0000000000000000000000000000000000000000000000000000000000000000612837565b905060006127c182612886565b6110e090613d00565b611c248133613182565b6040516001600160a01b0383166024820152604481018290526109f490849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526131db565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218311670de0b6b3a7640000021582026128745763bcbede656000526004601cfd5b50670de0b6b3a7640000919091020490565b6000600160ff1b82106128ac57604051632db27c5360e01b815260040160405180910390fd5b5090565b6128b86139a2565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663faaba9e26040518163ffffffff1660e01b8152600401602060405180830381865afa158015612918573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061293c9190613d1c565b602080850151845283018190526060840151604084015260808401516001600160c01b031660a08401529050612971826132b0565b6001600160c01b031660808401526001600160801b03166060830181815260a0850151916129a0908390613ffa565b6001600160801b0316905250815160408301516129be919083613368565b60c0830181815260608401516001600160801b0316916129df90839061401a565b9052509092915050565b6129f38282611d28565b610a78576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055612a293390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b612a778282611d28565b15610a78576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b612ada6133a2565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051612b149190613a24565b60405180910390a1565b60015460ff1615612b645760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610a65565b565b60c081015181516000916107e19161401a565b600081600019048311820215612b975763c4c5d7f56000526004601cfd5b50670de0b6b3a764000091020490565b600083612bb48484612837565b1015949350505050565b6040516001600160a01b03808516602483015283166044820152606481018290526108589085906323b872dd60e01b90608401612800565b612c416040518060c001604052806000815260200160008152602001600081526020016000815260200160006001600160c01b0316815260200160006001600160801b031681525090565b60208601518651612c5281866133eb565b885260208801879052606088018690524260408901528615801590612c87575060055460208901516001600160801b03909116115b15612ca557604051634b2c23a160e11b815260040160405180910390fd5b6001600160a01b0389166000908152600760209081526040918290208a518155908a015160018201559089015160028201556060890151600382015560808901516004820180546001600160c01b0319166001600160c01b0390921691909117905560a0890151600590910180546001600160801b0319166001600160801b0390921691909117905581871115612d5157612d408288613d35565b612d4a908561401a565b9350612d68565b612d5b8783613d35565b612d659085613d35565b93505b60068490556009546001600160a01b031615612de9576009546020890151604051631d94f24d60e01b81526001600160a01b0390921691631d94f24d91612db6918d91908990600401613dd8565b600060405180830381600087803b158015612dd057600080fd5b505af1158015612de4573d6000803e3d6000fd5b505050505b600a546001600160a01b031615612e0557612e05898287613430565b602088810151895160408051928352928201529081018590526001600160a01b038a16907f5c97e4677e876dd60652844f112967ea027e30e6b2c479ef10dcafcfef253e8d9060600160405180910390a25095979650505050505050565b600080612e6e611d51565b6001600160a01b0316630ab3640f7f00000000000000000000000000000000000000000000000000000000000000006040518263ffffffff1660e01b8152600401612eb99190613a24565b602060405180830381865afa158015612ed6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612efa919061402d565b90506125fc8184613588565b6000670de0b6b3a7640000612f1b84846135a5565b81612f2857612f28614051565b059392505050565b6000808080886001600160801b03861615801590612f4d57508015155b15612fc157856001600160801b03168110612f9557612f756001600160801b03871682613d35565b9050612f8a6001600160801b0387168461401a565b925060009150612fc5565b80612fa0818561401a565b935060009150612fb9816001600160801b038916613d35565b925050612fc5565b8591505b8015613079576000612fd88a898b613368565b905080821061300157612feb8183613d35565b9150612ff7818561401a565b9350889450613073565b61300b828561401a565b9350898861301d84633b9aca00614067565b6130279190614067565b613031919061407e565b61303f8a633b9aca00614067565b6130499190613d35565b886130588b633b9aca00614067565b6130629190614067565b61306c919061407e565b9450600091505b5061307d565b8693505b613087818a613d35565b94505095509550955095915050565b61309e6135ee565b42600255565b600080846000036130b9575084905082613127565b6130c3868661401a565b91506130d386633b9aca00614067565b83866130e387633b9aca00614067565b6130ed9190614067565b6130f7919061407e565b613101919061401a565b633b9aca006131108487614067565b61311a9190614067565b613124919061407e565b90505b94509492505050565b6000808212156128ac5760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152606401610a65565b61318c8282611d28565b610a785761319981613629565b6131a483602061363b565b6040516020016131b59291906140b6565b60408051601f198184030181529082905262461bcd60e51b8252610a6591600401614125565b6000613230826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166137d69092919063ffffffff16565b90508051600014806132515750808060200190518101906132519190614158565b6109f45760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a65565b6000806132bb611d51565b6001600160a01b031663e08a03db7f00000000000000000000000000000000000000000000000000000000000000006040518263ffffffff1660e01b81526004016133069190613a24565b602060405180830381865afa158015613323573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133479190614175565b9050600061335e8460000151838660a001516137e5565b9491935090915050565b60008360000361337a575060006125fc565b83836133868483614067565b613390919061407e565b61339a9190613d35565b949350505050565b60015460ff16612b645760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610a65565b8181016000821380156133fd57508281105b80613412575060008212801561341257508281115b156107e1576040516354012a2960e11b815260040160405180910390fd5b60008113156134a457600a5460405163775c43d360e01b81526001600160a01b039091169063775c43d39061346d90869086908690600401613dd8565b600060405180830381600087803b15801561348757600080fd5b505af115801561349b573d6000803e3d6000fd5b50505050505050565b60008112156109f457600a546040516363fcb8d760e11b8152600091829182916001600160a01b03169063c7f971ae906134e690899089908990600401613dd8565b6000604051808303816000875af1158015613505573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261352d9190810190613ecd565b92509250925060005b835181101561349b5782818151811061355157613551613fa1565b60200260200101516000146135765761357682848381518110611bd357611bd3613fa1565b8061358081613fb7565b915050613536565b600061271061359b61ffff85168461419e565b6125fc91906141ce565b81810260008312806135d0575081158015906135d05750828282816135cc576135cc614051565b0514155b156107e157604051631eed389360e01b815260040160405180910390fd5b6135f6612b1e565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833612b07565b60606107e16001600160a01b03831660145b6060600061364a836002614067565b61365590600261401a565b6001600160401b0381111561366c5761366c613df9565b6040519080825280601f01601f191660200182016040528015613696576020820181803683370190505b509050600360fc1b816000815181106136b1576136b1613fa1565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106136e0576136e0613fa1565b60200101906001600160f81b031916908160001a9053506000613704846002614067565b61370f90600161401a565b90505b6001811115613787576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061374357613743613fa1565b1a60f81b82828151811061375957613759613fa1565b60200101906001600160f81b031916908160001a90535060049490941c93613780816141fc565b9050613712565b5083156125fc5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610a65565b606061339a8484600085613829565b60006b033b2e3c9fd0803ce80000006137fe8385614213565b61381f906001600160c01b03166bffffffffffffffffffffffff8716614067565b61339a919061407e565b60608247101561388a5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610a65565b600080866001600160a01b031685876040516138a69190614233565b60006040518083038185875af1925050503d80600081146138e3576040519150601f19603f3d011682016040523d82523d6000602084013e6138e8565b606091505b50915091506138f987838387613904565b979650505050505050565b6060831561397357825160000361396c576001600160a01b0385163b61396c5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a65565b508161339a565b61339a83838151156139885781518083602001fd5b8060405162461bcd60e51b8152600401610a659190614125565b6040518060e0016040528060008152602001600081526020016000815260200160006001600160801b0316815260200160006001600160c01b0316815260200160006001600160c01b03168152602001600081525090565b600060208284031215613a0c57600080fd5b81356001600160e01b0319811681146125fc57600080fd5b6001600160a01b0391909116815260200190565b6001600160a01b0381168114611c2457600080fd5b600080600060608486031215613a6257600080fd5b8335613a6d81613a38565b92506020840135613a7d81613a38565b929592945050506040919091013590565b600060208284031215613aa057600080fd5b5035919050565b8015158114611c2457600080fd5b60008060408385031215613ac857600080fd5b8235613ad381613a38565b91506020830135613ae381613aa7565b809150509250929050565b600060208284031215613b0057600080fd5b81356125fc81613a38565b60008060408385031215613b1e57600080fd5b823591506020830135613ae381613a38565b60008060408385031215613b4357600080fd5b8235613b4e81613a38565b946020939093013593505050565b600080600080600060808688031215613b7457600080fd5b8535613b7f81613a38565b9450602086013593506040860135925060608601356001600160401b0380821115613ba957600080fd5b818801915088601f830112613bbd57600080fd5b813581811115613bcc57600080fd5b8960208260051b8501011115613be157600080fd5b9699959850939650602001949392505050565b60008060408385031215613c0757600080fd5b50508035926020909101359150565b600080600060608486031215613c2b57600080fd5b8335613c3681613a38565b92506020840135613c4681613a38565b91506040840135613c5681613aa7565b809150509250925092565b600080600080600060a08688031215613c7957600080fd5b8535613c8481613a38565b94506020860135613c9481613a38565b93506040860135613ca481613a38565b94979396509394606081013594506080013592915050565b60008060408385031215613ccf57600080fd5b8235613cda81613a38565b91506020830135613ae381613a38565b634e487b7160e01b600052601160045260246000fd5b6000600160ff1b8201613d1557613d15613cea565b5060000390565b600060208284031215613d2e57600080fd5b5051919050565b818103818111156107e1576107e1613cea565b8051613d5381613a38565b919050565b600060208284031215613d6a57600080fd5b81516125fc81613a38565b6001600160a01b03878116825286166020820152604081018590526060810184905260a060808201819052810182905260006001600160fb1b03831115613dbb57600080fd5b8260051b808560c08501379190910160c001979650505050505050565b6001600160a01b039390931683526020830191909152604082015260600190565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715613e3757613e37613df9565b604052919050565b60006001600160401b03821115613e5857613e58613df9565b5060051b60200190565b600082601f830112613e7357600080fd5b81516020613e88613e8383613e3f565b613e0f565b82815260059290921b84018101918181019086841115613ea757600080fd5b8286015b84811015613ec25780518352918301918301613eab565b509695505050505050565b600080600060608486031215613ee257600080fd5b83516001600160401b0380821115613ef957600080fd5b818601915086601f830112613f0d57600080fd5b81516020613f1d613e8383613e3f565b82815260059290921b8401810191818101908a841115613f3c57600080fd5b948201945b83861015613f63578551613f5481613a38565b82529482019490820190613f41565b91890151919750909350505080821115613f7c57600080fd5b50613f8986828701613e62565b925050613f9860408501613d48565b90509250925092565b634e487b7160e01b600052603260045260246000fd5b600060018201613fc957613fc9613cea565b5060010190565b6001600160a01b039485168152928416602084015292166040820152901515606082015260800190565b6001600160801b038181168382160190808211156110f0576110f0613cea565b808201808211156107e1576107e1613cea565b60006020828403121561403f57600080fd5b815161ffff811681146125fc57600080fd5b634e487b7160e01b600052601260045260246000fd5b80820281158282048414176107e1576107e1613cea565b60008261408d5761408d614051565b500490565b60005b838110156140ad578181015183820152602001614095565b50506000910152565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b8152600083516140e8816017850160208801614092565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351614119816028840160208801614092565b01602801949350505050565b6020815260008251806020840152614144816040850160208701614092565b601f01601f19169190910160400192915050565b60006020828403121561416a57600080fd5b81516125fc81613aa7565b60006020828403121561418757600080fd5b81516001600160c01b03811681146125fc57600080fd5b80820260008212600160ff1b841416156141ba576141ba613cea565b81810583148215176107e1576107e1613cea565b6000826141dd576141dd614051565b600160ff1b8214600019841416156141f7576141f7613cea565b500590565b60008161420b5761420b613cea565b506000190190565b6001600160c01b038281168282160390808211156110f0576110f0613cea565b60008251614245818460208701614092565b919091019291505056fea26469706673582212202670f66150837e29765eb2e620cf4602c851a6f3c1148f7a5c45103d7cd6685964736f6c63430008130033000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab000000000000000000000000ed4e4f000c5fc8cf22f2bf2ea23e64f38a5fa2160000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000f43fc2c04ee00000000000000000000000000000000000000000000000000000dbd2fc137a300000000000000000000000000000000000000000000000000000d99a8cec7e200000000000000000000000000009b2205e4e62e333141117fc895dc77b558e2a2bc0000000000000000000000009b2205e4e62e333141117fc895dc77b558e2a2bc0000000000000000000000009b2205e4e62e333141117fc895dc77b558e2a2bc
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061027f5760003560e01c8063723507be1161015c578063a217fddf116100ce578063d9c70f5711610087578063d9c70f57146106c9578063de55f11e146106dc578063df4014d91461075a578063f3fef3a31461076d578063fc0c546a14610780578063fc7b9c18146107a757600080fd5b8063a217fddf1461066d578063be8da14b14610675578063c11e47341461067d578063c75a4b5e14610690578063cde68041146106a3578063d547741f146106b657600080fd5b80637dc0d1d0116101205780637dc0d1d0146105de5780637dff3797146106055780638309dbdd1461062c5780638456cb591461063f5780638cc5ce991461064757806391d148541461065a57600080fd5b8063723507be14610546578063745b5ef51461055957806376f899651461056c57806379ee54f71461057f5780637cc34bb41461059257600080fd5b80632f2ff15d116101f557806341c2f54c116101b957806341c2f54c1461045857806347e7ef241461046b5780635224372c1461047e57806355f575101461049157806357e2a73f146105285780635c975abb1461053b57600080fd5b80632f2ff15d146103fb578063342c02b11461040e57806336568abe14610435578063398482d8146104485780633f4ba83a1461045057600080fd5b80631c580ad5116102475780631c580ad51461033d5780631da649cf1461037b578063248a9ca31461038e578063280c37ef146103b15780632aa5270e146103c45780632e55d0f2146103f257600080fd5b806301ffc9a7146102845780630f4ef8a6146102ac5780631171bda9146102cc5780631665e3fe146102e157806316f0115b14610316575b600080fd5b6102976102923660046139fa565b6107b0565b60405190151581526020015b60405180910390f35b600a546102bf906001600160a01b031681565b6040516102a39190613a24565b6102df6102da366004613a4d565b6107e7565b005b6103087f0000000000000000000000000000000000000000000000000de0b6b3a764000081565b6040519081526020016102a3565b6102bf7f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab81565b60085461035b906001600160401b0380821691600160401b90041682565b604080516001600160401b039384168152929091166020830152016102a3565b610308610389366004613a4d565b61085e565b61030861039c366004613a8e565b60009081526020819052604090206001015490565b6102df6103bf366004613ab5565b6108b8565b6103d76103d2366004613aee565b61092f565b604080519384526020840192909252908201526060016102a3565b61030860025481565b6102df610409366004613b0b565b6109cf565b6103087f0000000000000000000000000000000000000000000000000de0b6b3a764000081565b6102df610443366004613b0b565b6109f9565b610308610a7c565b6102df610b31565b6102df610466366004613b30565b610b6b565b610308610479366004613b30565b6110a7565b61030861048c366004613a4d565b6110f7565b6104e961049f366004613aee565b60076020526000908152604090208054600182015460028301546003840154600485015460059095015493949293919290916001600160c01b03909116906001600160801b031686565b6040805196875260208701959095529385019290925260608401526001600160c01b031660808301526001600160801b031660a082015260c0016102a3565b6102df610536366004613b5c565b611130565b60015460ff16610297565b6102df610554366004613bf4565b6112be565b610308610567366004613aee565b611443565b6102df61057a366004613b30565b6114d0565b6102df61058d366004613aee565b611ae9565b6005546105b7906001600160801b03811690600160801b90046001600160401b031682565b604080516001600160801b0390931683526001600160401b039091166020830152016102a3565b6102bf7f000000000000000000000000ed4e4f000c5fc8cf22f2bf2ea23e64f38a5fa21681565b6102bf7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b6102df61063a366004613c16565b611c27565b6102df611cf6565b6009546102bf906001600160a01b031681565b610297610668366004613b0b565b611d28565b610308600081565b6102bf611d51565b6102df61068b366004613b0b565b611dd5565b6102df61069e366004613c61565b611ea4565b6102976106b1366004613cbc565b6125b5565b6102df6106c4366004613b0b565b612603565b6102df6106d7366004613ab5565b612628565b6106ef6106ea366004613aee565b61268b565b6040516102a391908151815260208083015190820152604080830151908201526060808301516001600160801b0316908201526080808301516001600160c01b039081169183019190915260a0808401519091169082015260c0918201519181019190915260e00190565b610308610768366004613aee565b61270d565b61030861077b366004613b30565b612788565b6102bf7f0000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d81565b61030860065481565b60006001600160e01b03198216637965db0b60e01b14806107e157506301ffc9a760e01b6001600160e01b03198316145b92915050565b60006107f2816127ca565b7f0000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d6001600160a01b0316846001600160a01b0316036108445760405163df3f588760e01b815260040160405180910390fd5b6108586001600160a01b03851684846127d4565b50505050565b600061088a827f0000000000000000000000000000000000000000000000000de0b6b3a7640000612837565b9050600061089782612886565b6108a090613d00565b90506108b0848587600085611ea4565b509392505050565b3360008181526004602090815260408083206001600160a01b03871680855290835292819020805460ff1916861515908117909155815194855291840192909252908201527f6501e8bfa2d3e686d62fe2c0c3275df594494583b0a63a70b7452d3eeb712bd6906060015b60405180910390a15050565b6001600160a01b0381166000908152600760209081526040808320815160c081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546001600160c01b03166080830152600501546001600160801b031660a08201528190819081906109ac906128b0565b805160c082015160609092015190979196506001600160801b0316945092505050565b6000828152602081905260409020600101546109ea816127ca565b6109f483836129e9565b505050565b6001600160a01b0381163314610a6e5760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084015b60405180910390fd5b610a788282612a6d565b5050565b604051632cbf04c160e01b81526000906001600160a01b037f000000000000000000000000ed4e4f000c5fc8cf22f2bf2ea23e64f38a5fa2161690632cbf04c190610aeb907f0000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d90600401613a24565b602060405180830381865afa158015610b08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b2c9190613d1c565b905090565b7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a610b5b816127ca565b610b63612ad2565b506000600255565b610b73612b1e565b6001600160a01b0382161580610b87575080155b15610ba557604051632bdc849360e21b815260040160405180910390fd5b604080518082018252600580546001600160801b0380821684526001600160401b03600160801b9092048216602080860191909152855180870187526008548085168252600160401b9004909316838201526001600160a01b038816600090815260078252868120875160c081018952815481526001820154938101939093526002810154978301979097526003870154606083015260048701546001600160c01b0316608083015295909301541660a08301529192610c64826128b0565b90506000610c70610a7c565b905080600003610c9357604051636ec7a8fb60e11b815260040160405180910390fd5b610cbe610c9f83612b66565b8451610cab9084612b79565b87602001516001600160401b0316612ba7565b15610cdc5760405163f87e38e960e01b815260040160405180910390fd5b6000610cf58286602001516001600160401b0316612b79565b9050610d05846000015182612b79565b610d0e84612b66565b11610d2c5760405163196e08b760e21b815260040160405180910390fd5b6000610d388883612837565b8551909150811015610d5d5760405163031e966360e01b815260040160405180910390fd5b508351610d6a8183612b79565b9750600088610d7886612b66565b610d829190613d35565b90506000610db08a7f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b9050610e076001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216337f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab84612bbe565b600060a088018190526080808801516001600160c01b0316908901526020870151610e4b918d918a9190610e3a88612886565b610e4390613d00565b600654612bf6565b96506000610e7d87600001517f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b90506000610eaf8860c001517f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b90506000610edd857f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b6040516332a5417960e21b81526004810185905260248101849052604481018290529091507f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab6001600160a01b03169063ca9505e490606401600060405180830381600087803b158015610f5057600080fd5b505af1158015610f64573d6000803e3d6000fd5b505050506000610f94877f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b9050610fca6001600160a01b037f0000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d1633836127d4565b6000610fe28b60000151610fdd90613d00565b612e63565b905080156110955760006110167f0000000000000000000000000000000000000000000000000de0b6b3a764000083612f06565b604051636b22c77560e11b8152600481018290529091507f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab6001600160a01b03169063d6458eea90602401600060405180830381600087803b15801561107b57600080fd5b505af115801561108f573d6000803e3d6000fd5b50505050505b50505050505050505050505050505050565b60006110d3827f0000000000000000000000000000000000000000000000000de0b6b3a7640000612837565b905060006110e082612886565b90506110f0843333846000611ea4565b5092915050565b6000611123827f0000000000000000000000000000000000000000000000000de0b6b3a7640000612837565b905060006108a082612886565b7fce5edea930af7792c7c00eb1f483cf90e1090eb568e1ee0689369fb7278f947661115a816127ca565b600a546001600160a01b0316156112b657600a5460408051637daf3b7360e11b815290516001600160a01b0390921691829163fb5e76e69160048083019260209291908290030181865afa1580156111b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111da9190613d58565b6001600160a01b031663fa46d7ac7f0000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d89898989896040518763ffffffff1660e01b815260040161122f96959493929190613d75565b600060405180830381600087803b15801561124957600080fd5b505af115801561125d573d6000803e3d6000fd5b50505050806001600160a01b031663f4c318326040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561129c57600080fd5b505af11580156112b0573d6000803e3d6000fd5b50505050505b505050505050565b6112c6612b1e565b7f7e2be3cffb06427cbcb9b1d12d4b78adcf14a2bf640e9bbdeb54bb711b65ec716112f0816127ca565b82683232b13a233637b7b960b91b0361132357600580546001600160801b0319166001600160801b038416179055611404565b826f6c69717569646174696f6e526174696f60801b03611367576005805467ffffffffffffffff60801b1916600160801b6001600160401b03851602179055611404565b82716c69717569646174696f6e50656e616c747960701b036113a4576008805467ffffffffffffffff19166001600160401b038416179055611404565b82721b1a5c5d5a59185d1a5bdb911a5cd8dbdd5b9d606a1b036113eb576008805467ffffffffffffffff60401b1916600160401b6001600160401b03851602179055611404565b604051638dd691e760e01b815260040160405180910390fd5b827f4327e67d6578eb2c9293fb22f9334006073ac1397c7100f5dd5adca09ad71c088360405161143691815260200190565b60405180910390a2505050565b6001600160a01b0381166000908152600760209081526040808320815160c081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546001600160c01b03166080830152600501546001600160801b031660a082015281906114bc906128b0565b606001516001600160801b03169392505050565b6114d8612b1e565b6001600160a01b03821615806114ec575080155b1561150a57604051632bdc849360e21b815260040160405180910390fd5b604080518082018252600580546001600160801b0380821684526001600160401b03600160801b9092048216602080860191909152855180870187526008548085168252600160401b9004909316838201526001600160a01b038816600090815260078252868120875160c081018952815481526001820154938101939093526002810154978301979097526003870154606083015260048701546001600160c01b0316608083015295909301541660a083015291926115c9826128b0565b905060006115d5610a7c565b905060006115f08286602001516001600160401b0316612b79565b90508160000361161357604051636ec7a8fb60e11b815260040160405180910390fd5b835161161f9082612b79565b61162884612b66565b11156116475760405163b53a43fd60e01b815260040160405180910390fd5b60006116538883612837565b9050600061166e8988600001516001600160401b0316612b79565b9050600061169c8a89600001516001600160401b0316670de0b6b3a76400006116979190613d35565b612b79565b87519091508311156116c15760405163542e88e560e11b815260040160405180910390fd5b6116ec6116cd87612b66565b88516116d99088612b79565b8b602001516001600160401b0316612ba7565b1561170a5760405163f87e38e960e01b815260040160405180910390fd5b61176b337f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab611739848e613d35565b6001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216929190612bbe565b600080600061177989612b66565b905060008186036117a15750602089015160c08a0151600060a08d01819052945092506117d5565b6117be868b600001518c602001518d604001518e60600151612f30565b6001600160801b031660a08f015291955090935090505b6080808b01516001600160c01b0316908c01526117f88f8c8684610e3a8c612886565b9a506000611826847f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b90506000611863868d6000015161183d9190613d35565b7f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b6040516332a5417960e21b81526004810182905260248101849052600060448201529091507f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab6001600160a01b03169063ca9505e490606401600060405180830381600087803b1580156118d657600080fd5b505af11580156118ea573d6000803e3d6000fd5b50505050600061191a8a7f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b90506119506001600160a01b037f0000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d1633836127d4565b6119a56001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216337f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab8b612bbe565b60405163369a8cf560e21b8152600481018990527f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab6001600160a01b03169063da6a33d490602401600060405180830381600087803b158015611a0757600080fd5b505af1158015611a1b573d6000803e3d6000fd5b50508e51611a2c9250899150613d35565b15611ad5576000611a46888f6000015161183d9190613d35565b90506001600160a01b037f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab1663d6458eea611a83610fdd84613d00565b6040518263ffffffff1660e01b8152600401611aa191815260200190565b600060405180830381600087803b158015611abb57600080fd5b505af1158015611acf573d6000803e3d6000fd5b50505050505b505050505050505050505050505050505050565b600a546001600160a01b031615611c2457600a546001600160a01b038281166000908152600760205260408082205490516363fcb8d760e11b815291938493849391169163c7f971ae91611b439188918690600401613dd8565b6000604051808303816000875af1158015611b62573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611b8a9190810190613ecd565b92509250925060005b8351811015611c1f57828181518110611bae57611bae613fa1565b6020026020010151600014611c0d57611c0d82848381518110611bd357611bd3613fa1565b6020026020010151868481518110611bed57611bed613fa1565b60200260200101516001600160a01b03166127d49092919063ffffffff16565b80611c1781613fb7565b915050611b93565b505050505b50565b6001600160a01b0383163314801590611c6457506001600160a01b038316600090815260046020908152604080832033845290915290205460ff16155b15611c8257604051638743d2ff60e01b815260040160405180910390fd5b6001600160a01b0383811660009081526003602090815260408083209386168352929052819020805460ff1916831515179055517fdcf2bd5a4c47afeb1792d170f6f5e6e528e30c6b546fffe62b697a11f8953b2b90611ce9903390869086908690613fd0565b60405180910390a1505050565b7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a611d20816127ca565b611c24613096565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b60007f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab6001600160a01b031663be8da14b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611db1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b2c9190613d58565b611ddd612b1e565b7f7e2be3cffb06427cbcb9b1d12d4b78adcf14a2bf640e9bbdeb54bb711b65ec71611e07816127ca565b826f3932bbb0b93221b7b73a3937b63632b960811b03611e4157600980546001600160a01b0319166001600160a01b038416179055611e74565b826c3932bbb0b93226b0b730b3b2b960991b036113eb57600a80546001600160a01b0319166001600160a01b0384161790555b827f83e498545bbe12d733822c752ac843578daa6554fe6f90753853156c3478e4f0836040516114369190613a24565b6000811380611eb35750600082125b8015611ec65750611ec485336125b5565b155b80611ee35750600082138015611ee35750611ee184336125b5565b155b80611f005750600081128015611f005750611efe83336125b5565b155b15611f1e57604051634c26249960e01b815260040160405180910390fd5b6000811380611f2c57508115155b15611f3957611f39612b1e565b6001600160a01b0385166000908152600760209081526040808320815160c081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546001600160c01b03166080830152600501546001600160801b031660a082015290611fb1826128b0565b905060008060008060008713156120cf576000879050611fdf81886020015188602001518a606001516130a4565b60608801516001600160801b031660a08a01526080808901516001600160c01b0316908a0152909550935061201388612e63565b91506000612041827f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b60405163bf28068b60e01b8152600481018290526001600160a01b038d811660248301529192507f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab9091169063bf28068b90604401600060405180830381600087803b1580156120b057600080fd5b505af11580156120c4573d6000803e3d6000fd5b505050505050612307565b60008712156122f85760ff87901c600090810380890118906120f087612b66565b90508082106121115780915061210582612886565b61210e90613d00565b98505b600061213d837f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b90506121946001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2168d7f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab84612bbe565b60008284036121b85760009750886020015196508860c001519550600090506121e0565b6121d5848b602001518b602001518d606001518d60600151612f30565b929a50909850965090505b88516121fa906121f1908a90613d35565b610fdd90613d00565b94506000612211898b6000015161183d9190613d35565b9050600061223f887f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b6040516332a5417960e21b81526004810184905260248101829052600060448201529091507f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab6001600160a01b03169063ca9505e490606401600060405180830381600087803b1580156122b257600080fd5b505af11580156122c6573d6000803e3d6000fd5b5050506001600160801b0390931660a08d01525050506080808901516001600160c01b0316908a015250612307915050565b85602001519350846040015192505b600088131561238157600061234461231e8a613130565b7f0000000000000000000000000000000000000000000000000de0b6b3a7640000612b79565b905061237b6001600160a01b037f0000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d168c3084612bbe565b506123d7565b60008812156123d757600061239f60ff8a901c8203808b011861231e565b90506123d56001600160a01b037f0000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d168c836127d4565b505b6123e78b8786868c600654612bf6565b604080518082019091526005546001600160801b0381168252600160801b90046001600160401b031660208201529096506000612422610a7c565b90506000612434896000015183612b79565b905060008a1380612445575060008b125b8015612476575061247461246061245b8b6128b0565b612b66565b8285602001516001600160401b0316612ba7565b155b1561249457604051633f66923d60e01b815260040160405180910390fd5b83156125455760006124c67f0000000000000000000000000000000000000000000000000de0b6b3a764000086612f06565b604051636b22c77560e11b8152600481018290529091507f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab6001600160a01b03169063d6458eea90602401600060405180830381600087803b15801561252b57600080fd5b505af115801561253f573d6000803e3d6000fd5b50505050505b8b6001600160a01b03168d6001600160a01b03168f6001600160a01b03167f7ce3e27b99e7e2e42f0ddcb6f6679a25081a5fd4ca991bcd05c45e54daa997088e8e60405161259d929190918252602082015260400190565b60405180910390a45050505050505050505050505050565b6000816001600160a01b0316836001600160a01b031614806125fc57506001600160a01b0380841660009081526003602090815260408083209386168352929052205460ff165b9392505050565b60008281526020819052604090206001015461261e816127ca565b6109f48383612a6d565b3360008181526003602090815260408083206001600160a01b038716845290915290819020805460ff1916841515179055517fdcf2bd5a4c47afeb1792d170f6f5e6e528e30c6b546fffe62b697a11f8953b2b9161092391819086908690613fd0565b6126936139a2565b6001600160a01b038216600090815260076020908152604091829020825160c081018452815481526001820154928101929092526002810154928201929092526003820154606082015260048201546001600160c01b031660808201526005909101546001600160801b031660a08201526107e1906128b0565b6001600160a01b0381166000908152600760209081526040808320815160c081018352815481526001820154938101939093526002810154918301919091526003810154606083015260048101546001600160c01b03166080830152600501546001600160801b031660a08201526107e19061245b906128b0565b60006127b4827f0000000000000000000000000000000000000000000000000de0b6b3a7640000612837565b905060006127c182612886565b6110e090613d00565b611c248133613182565b6040516001600160a01b0383166024820152604481018290526109f490849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526131db565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218311670de0b6b3a7640000021582026128745763bcbede656000526004601cfd5b50670de0b6b3a7640000919091020490565b6000600160ff1b82106128ac57604051632db27c5360e01b815260040160405180910390fd5b5090565b6128b86139a2565b60007f000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab6001600160a01b031663faaba9e26040518163ffffffff1660e01b8152600401602060405180830381865afa158015612918573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061293c9190613d1c565b602080850151845283018190526060840151604084015260808401516001600160c01b031660a08401529050612971826132b0565b6001600160c01b031660808401526001600160801b03166060830181815260a0850151916129a0908390613ffa565b6001600160801b0316905250815160408301516129be919083613368565b60c0830181815260608401516001600160801b0316916129df90839061401a565b9052509092915050565b6129f38282611d28565b610a78576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055612a293390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b612a778282611d28565b15610a78576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b612ada6133a2565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051612b149190613a24565b60405180910390a1565b60015460ff1615612b645760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610a65565b565b60c081015181516000916107e19161401a565b600081600019048311820215612b975763c4c5d7f56000526004601cfd5b50670de0b6b3a764000091020490565b600083612bb48484612837565b1015949350505050565b6040516001600160a01b03808516602483015283166044820152606481018290526108589085906323b872dd60e01b90608401612800565b612c416040518060c001604052806000815260200160008152602001600081526020016000815260200160006001600160c01b0316815260200160006001600160801b031681525090565b60208601518651612c5281866133eb565b885260208801879052606088018690524260408901528615801590612c87575060055460208901516001600160801b03909116115b15612ca557604051634b2c23a160e11b815260040160405180910390fd5b6001600160a01b0389166000908152600760209081526040918290208a518155908a015160018201559089015160028201556060890151600382015560808901516004820180546001600160c01b0319166001600160c01b0390921691909117905560a0890151600590910180546001600160801b0319166001600160801b0390921691909117905581871115612d5157612d408288613d35565b612d4a908561401a565b9350612d68565b612d5b8783613d35565b612d659085613d35565b93505b60068490556009546001600160a01b031615612de9576009546020890151604051631d94f24d60e01b81526001600160a01b0390921691631d94f24d91612db6918d91908990600401613dd8565b600060405180830381600087803b158015612dd057600080fd5b505af1158015612de4573d6000803e3d6000fd5b505050505b600a546001600160a01b031615612e0557612e05898287613430565b602088810151895160408051928352928201529081018590526001600160a01b038a16907f5c97e4677e876dd60652844f112967ea027e30e6b2c479ef10dcafcfef253e8d9060600160405180910390a25095979650505050505050565b600080612e6e611d51565b6001600160a01b0316630ab3640f7f0000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d6040518263ffffffff1660e01b8152600401612eb99190613a24565b602060405180830381865afa158015612ed6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612efa919061402d565b90506125fc8184613588565b6000670de0b6b3a7640000612f1b84846135a5565b81612f2857612f28614051565b059392505050565b6000808080886001600160801b03861615801590612f4d57508015155b15612fc157856001600160801b03168110612f9557612f756001600160801b03871682613d35565b9050612f8a6001600160801b0387168461401a565b925060009150612fc5565b80612fa0818561401a565b935060009150612fb9816001600160801b038916613d35565b925050612fc5565b8591505b8015613079576000612fd88a898b613368565b905080821061300157612feb8183613d35565b9150612ff7818561401a565b9350889450613073565b61300b828561401a565b9350898861301d84633b9aca00614067565b6130279190614067565b613031919061407e565b61303f8a633b9aca00614067565b6130499190613d35565b886130588b633b9aca00614067565b6130629190614067565b61306c919061407e565b9450600091505b5061307d565b8693505b613087818a613d35565b94505095509550955095915050565b61309e6135ee565b42600255565b600080846000036130b9575084905082613127565b6130c3868661401a565b91506130d386633b9aca00614067565b83866130e387633b9aca00614067565b6130ed9190614067565b6130f7919061407e565b613101919061401a565b633b9aca006131108487614067565b61311a9190614067565b613124919061407e565b90505b94509492505050565b6000808212156128ac5760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152606401610a65565b61318c8282611d28565b610a785761319981613629565b6131a483602061363b565b6040516020016131b59291906140b6565b60408051601f198184030181529082905262461bcd60e51b8252610a6591600401614125565b6000613230826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166137d69092919063ffffffff16565b90508051600014806132515750808060200190518101906132519190614158565b6109f45760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a65565b6000806132bb611d51565b6001600160a01b031663e08a03db7f0000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d6040518263ffffffff1660e01b81526004016133069190613a24565b602060405180830381865afa158015613323573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133479190614175565b9050600061335e8460000151838660a001516137e5565b9491935090915050565b60008360000361337a575060006125fc565b83836133868483614067565b613390919061407e565b61339a9190613d35565b949350505050565b60015460ff16612b645760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610a65565b8181016000821380156133fd57508281105b80613412575060008212801561341257508281115b156107e1576040516354012a2960e11b815260040160405180910390fd5b60008113156134a457600a5460405163775c43d360e01b81526001600160a01b039091169063775c43d39061346d90869086908690600401613dd8565b600060405180830381600087803b15801561348757600080fd5b505af115801561349b573d6000803e3d6000fd5b50505050505050565b60008112156109f457600a546040516363fcb8d760e11b8152600091829182916001600160a01b03169063c7f971ae906134e690899089908990600401613dd8565b6000604051808303816000875af1158015613505573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261352d9190810190613ecd565b92509250925060005b835181101561349b5782818151811061355157613551613fa1565b60200260200101516000146135765761357682848381518110611bd357611bd3613fa1565b8061358081613fb7565b915050613536565b600061271061359b61ffff85168461419e565b6125fc91906141ce565b81810260008312806135d0575081158015906135d05750828282816135cc576135cc614051565b0514155b156107e157604051631eed389360e01b815260040160405180910390fd5b6135f6612b1e565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833612b07565b60606107e16001600160a01b03831660145b6060600061364a836002614067565b61365590600261401a565b6001600160401b0381111561366c5761366c613df9565b6040519080825280601f01601f191660200182016040528015613696576020820181803683370190505b509050600360fc1b816000815181106136b1576136b1613fa1565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106136e0576136e0613fa1565b60200101906001600160f81b031916908160001a9053506000613704846002614067565b61370f90600161401a565b90505b6001811115613787576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061374357613743613fa1565b1a60f81b82828151811061375957613759613fa1565b60200101906001600160f81b031916908160001a90535060049490941c93613780816141fc565b9050613712565b5083156125fc5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610a65565b606061339a8484600085613829565b60006b033b2e3c9fd0803ce80000006137fe8385614213565b61381f906001600160c01b03166bffffffffffffffffffffffff8716614067565b61339a919061407e565b60608247101561388a5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610a65565b600080866001600160a01b031685876040516138a69190614233565b60006040518083038185875af1925050503d80600081146138e3576040519150601f19603f3d011682016040523d82523d6000602084013e6138e8565b606091505b50915091506138f987838387613904565b979650505050505050565b6060831561397357825160000361396c576001600160a01b0385163b61396c5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a65565b508161339a565b61339a83838151156139885781518083602001fd5b8060405162461bcd60e51b8152600401610a659190614125565b6040518060e0016040528060008152602001600081526020016000815260200160006001600160801b0316815260200160006001600160c01b0316815260200160006001600160c01b03168152602001600081525090565b600060208284031215613a0c57600080fd5b81356001600160e01b0319811681146125fc57600080fd5b6001600160a01b0391909116815260200190565b6001600160a01b0381168114611c2457600080fd5b600080600060608486031215613a6257600080fd5b8335613a6d81613a38565b92506020840135613a7d81613a38565b929592945050506040919091013590565b600060208284031215613aa057600080fd5b5035919050565b8015158114611c2457600080fd5b60008060408385031215613ac857600080fd5b8235613ad381613a38565b91506020830135613ae381613aa7565b809150509250929050565b600060208284031215613b0057600080fd5b81356125fc81613a38565b60008060408385031215613b1e57600080fd5b823591506020830135613ae381613a38565b60008060408385031215613b4357600080fd5b8235613b4e81613a38565b946020939093013593505050565b600080600080600060808688031215613b7457600080fd5b8535613b7f81613a38565b9450602086013593506040860135925060608601356001600160401b0380821115613ba957600080fd5b818801915088601f830112613bbd57600080fd5b813581811115613bcc57600080fd5b8960208260051b8501011115613be157600080fd5b9699959850939650602001949392505050565b60008060408385031215613c0757600080fd5b50508035926020909101359150565b600080600060608486031215613c2b57600080fd5b8335613c3681613a38565b92506020840135613c4681613a38565b91506040840135613c5681613aa7565b809150509250925092565b600080600080600060a08688031215613c7957600080fd5b8535613c8481613a38565b94506020860135613c9481613a38565b93506040860135613ca481613a38565b94979396509394606081013594506080013592915050565b60008060408385031215613ccf57600080fd5b8235613cda81613a38565b91506020830135613ae381613a38565b634e487b7160e01b600052601160045260246000fd5b6000600160ff1b8201613d1557613d15613cea565b5060000390565b600060208284031215613d2e57600080fd5b5051919050565b818103818111156107e1576107e1613cea565b8051613d5381613a38565b919050565b600060208284031215613d6a57600080fd5b81516125fc81613a38565b6001600160a01b03878116825286166020820152604081018590526060810184905260a060808201819052810182905260006001600160fb1b03831115613dbb57600080fd5b8260051b808560c08501379190910160c001979650505050505050565b6001600160a01b039390931683526020830191909152604082015260600190565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715613e3757613e37613df9565b604052919050565b60006001600160401b03821115613e5857613e58613df9565b5060051b60200190565b600082601f830112613e7357600080fd5b81516020613e88613e8383613e3f565b613e0f565b82815260059290921b84018101918181019086841115613ea757600080fd5b8286015b84811015613ec25780518352918301918301613eab565b509695505050505050565b600080600060608486031215613ee257600080fd5b83516001600160401b0380821115613ef957600080fd5b818601915086601f830112613f0d57600080fd5b81516020613f1d613e8383613e3f565b82815260059290921b8401810191818101908a841115613f3c57600080fd5b948201945b83861015613f63578551613f5481613a38565b82529482019490820190613f41565b91890151919750909350505080821115613f7c57600080fd5b50613f8986828701613e62565b925050613f9860408501613d48565b90509250925092565b634e487b7160e01b600052603260045260246000fd5b600060018201613fc957613fc9613cea565b5060010190565b6001600160a01b039485168152928416602084015292166040820152901515606082015260800190565b6001600160801b038181168382160190808211156110f0576110f0613cea565b808201808211156107e1576107e1613cea565b60006020828403121561403f57600080fd5b815161ffff811681146125fc57600080fd5b634e487b7160e01b600052601260045260246000fd5b80820281158282048414176107e1576107e1613cea565b60008261408d5761408d614051565b500490565b60005b838110156140ad578181015183820152602001614095565b50506000910152565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b8152600083516140e8816017850160208801614092565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351614119816028840160208801614092565b01602801949350505050565b6020815260008251806020840152614144816040850160208701614092565b601f01601f19169190910160400192915050565b60006020828403121561416a57600080fd5b81516125fc81613aa7565b60006020828403121561418757600080fd5b81516001600160c01b03811681146125fc57600080fd5b80820260008212600160ff1b841416156141ba576141ba613cea565b81810583148215176107e1576107e1613cea565b6000826141dd576141dd614051565b600160ff1b8214600019841416156141f7576141f7613cea565b500590565b60008161420b5761420b613cea565b506000190190565b6001600160c01b038281168282160390808211156110f0576110f0613cea565b60008251614245818460208701614092565b919091019291505056fea26469706673582212202670f66150837e29765eb2e620cf4602c851a6f3c1148f7a5c45103d7cd6685964736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab000000000000000000000000ed4e4f000c5fc8cf22f2bf2ea23e64f38a5fa2160000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000f43fc2c04ee00000000000000000000000000000000000000000000000000000dbd2fc137a300000000000000000000000000000000000000000000000000000d99a8cec7e200000000000000000000000000009b2205e4e62e333141117fc895dc77b558e2a2bc0000000000000000000000009b2205e4e62e333141117fc895dc77b558e2a2bc0000000000000000000000009b2205e4e62e333141117fc895dc77b558e2a2bc
-----Decoded View---------------
Arg [0] : constants (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [1] : config (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
-----Encoded View---------------
11 Constructor Arguments found :
Arg [0] : 000000000000000000000000a684eaf215ad323452e2b2bf6f817d4aa5c116ab
Arg [1] : 000000000000000000000000ed4e4f000c5fc8cf22f2bf2ea23e64f38a5fa216
Arg [2] : 0000000000000000000000002408569177553a427dd6956e1717f2fbe1a96f1d
Arg [3] : 0000000000000000000000000000000000000000000000000de0b6b3a7640000
Arg [4] : 0000000000000000000000000000000000000000000000000de0b6b3a7640000
Arg [5] : 0000000000000000000000000000000000000000000000000f43fc2c04ee0000
Arg [6] : 0000000000000000000000000000000000000000000000000dbd2fc137a30000
Arg [7] : 0000000000000000000000000000000000000000000000000d99a8cec7e20000
Arg [8] : 0000000000000000000000009b2205e4e62e333141117fc895dc77b558e2a2bc
Arg [9] : 0000000000000000000000009b2205e4e62e333141117fc895dc77b558e2a2bc
Arg [10] : 0000000000000000000000009b2205e4e62e333141117fc895dc77b558e2a2bc
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|---|---|---|---|---|
ETH | 100.00% | $0.162385 | 107,264.8124 | $17,418.2 |
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.