Contract Overview
Balance:
0 DEV
My Name Tag:
Not Available
Txn Hash | Method |
Block
|
From
|
To
|
Value | [Txn Fee] | |||
---|---|---|---|---|---|---|---|---|---|
0x6c39df052bca3290a50068f43d5101d64e96230b38916f3a477fcd73312e7827 | 0x60806040 | 3134140 | 320 days 5 hrs ago | 0xb6010d7ac4a8e9fa3e88b25f287fe725f2215208 | IN | Create: QollateralManager | 0 DEV | 0.004067146687 |
[ Download CSV Export ]
Latest 25 internal transaction
[ Download CSV Export ]
Contract Name:
QollateralManager
Compiler Version
v0.8.10+commit.fc410830
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
//SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "./interfaces/IFixedRateMarket.sol"; import "./interfaces/IQAdmin.sol"; import "./interfaces/IQPriceOracle.sol"; import "./interfaces/IQollateralManager.sol"; import "./interfaces/moonwell/MTokenInterfaces.sol"; import "./libraries/QTypes.sol"; contract QollateralManager is Initializable, IQollateralManager { using SafeERC20 for IERC20; /// @notice Contract storing all global Qoda parameters IQAdmin private _qAdmin; /// @notice Contract for price oracle feeds IQPriceOracle private _qPriceOracle; /// @notice 0x0 null address for convenience address constant NULL = address(0); /// @notice Native Token (WETH equivalent) for convenience address constant _NATIVE_TOKEN_ADDRESS = 0x0000000000000000000000000000000000000802; /// @notice Use this for quick lookups of collateral balances by asset /// account => tokenAddress => balanceLocal mapping(address => mapping(IERC20 => uint)) private _collateralBalances; /// @notice Iterable list of all collateral addresses which an account has nonzero balance. /// Use this when calculating `collateralValue` for liquidity considerations /// account => tokenAddresses[] mapping(address => IERC20[]) private _iterableCollateralAddresses; /// @notice Iterable list of all markets which an account has participated. /// Use this when calculating `totalBorrowValue` for liquidity considerations /// account => fixedRateMarketAddresses[] mapping(address => IFixedRateMarket[]) private _iterableAccountMarkets; /// @notice Non-iterable list of collateral which an account has nonzero balance. /// Use this for quick lookups /// account => tokenAddress => bool; mapping(address => mapping(IERC20 => bool)) private _accountCollateral; /// @notice Non-iterable list of markets which an account has participated. /// Use this for quick lookups /// account => fixedRateMarketAddress => bool; mapping(address => mapping(IFixedRateMarket => bool)) private _accountMarkets; /// @notice Constructor for upgradeable contracts /// @param qAdminAddress_ Address of the `QAdmin` contract /// @param qPriceOracleAddress_ Address of the `QPriceOracle` contract function initialize(address qAdminAddress_, address qPriceOracleAddress_) external initializer { _qAdmin = IQAdmin(qAdminAddress_); _qPriceOracle = IQPriceOracle(qPriceOracleAddress_); } /// @notice Needed for receiving native token when redeeming from Moonwell receive() external payable {} modifier onlyAdmin() { require(_qAdmin.hasRole(_qAdmin.ADMIN_ROLE(), msg.sender), "QM0 only admin"); _; } modifier onlyMarket() { require(_qAdmin.hasRole(_qAdmin.MARKET_ROLE(), msg.sender), "QM1 only market"); _; } /** ADMIN/RESTRICTED FUNCTIONS **/ /// @notice Record when an account has either borrowed or lent into a /// `FixedRateMarket`. This is necessary because we need to iterate /// across all markets that an account has borrowed/lent to to calculate their /// `borrowValue`. Only the `FixedRateMarket` contract itself may call /// this function /// @param account User account /// @param market Address of the `FixedRateMarket` market function _addAccountMarket(address account, IFixedRateMarket market) external onlyMarket { // Record that account now has participated in this `FixedRateMarket` if(!_accountMarkets[account][market]){ _accountMarkets[account][market] = true; _iterableAccountMarkets[account].push(market); } /// Emit the event emit AddAccountMarket(account, address(market)); } /// @notice Transfer collateral balances from one account to another. Only /// `FixedRateMarket` contracts can call this restricted function. This is used /// for when a liquidator liquidates an account. /// @param token ERC20 token /// @param from Sender address /// @param to Recipient address /// @param amount Amount to transfer function _transferCollateral( IERC20 token, address from, address to, uint amount ) external onlyMarket { // Check `from` address has enough collateral balance require(amount <= _collateralBalances[from][token], "QM2 not enough collateral balance"); // Transfer the balance to recipient _subtractCollateral(from, token, amount); token.safeTransfer(to, amount); // Emit the event emit TransferCollateral(address(token), from, to, amount); } /** USER INTERFACE **/ /// @notice Users call this to deposit collateral to fund their borrows /// @param token ERC20 token /// @param amount Amount to deposit (in local ccy) /// @return uint New collateral balance function depositCollateral(IERC20 token, uint amount) external returns(uint) { return _depositCollateral(msg.sender, token, amount); } /// @notice Users call this to deposit collateral to fund their borrows, where their /// collateral is automatically wrapped into MTokens for convenience so users can /// automatically earn interest on their collateral. /// @param underlying Underlying ERC20 token /// @param amount Amount to deposit (in underlying local currency) /// @return uint New collateral balance (in MToken balance) function depositCollateralWithMTokenWrap(IERC20 underlying, uint amount) external returns(uint) { return _depositCollateralWithMTokenWrap(msg.sender, underlying, amount); } /// @notice Users call this to withdraw collateral /// @param token ERC20 token /// @param amount Amount to withdraw (in local ccy) /// @return uint New collateral balance function withdrawCollateral(IERC20 token, uint amount) external returns(uint) { return _withdrawCollateral(msg.sender, token, amount); } /// @notice Users call this to withdraw mToken collateral, where their /// collateral is automatically unwrapped into underlying tokens for /// convenience. /// @param mTokenAddress Yield-bearing token address /// @param amount Amount to withdraw (in mToken local currency) /// @return uint New collateral balance (in MToken balance) function withdrawCollateralWithMTokenUnwrap( address mTokenAddress, uint amount ) external returns(uint) { return _withdrawCollateralWithMTokenUnwrap(msg.sender, mTokenAddress, amount); } /** VIEW FUNCTIONS **/ /// @notice Get the address of the `QAdmin` contract /// @return address Address of `QAdmin` contract function qAdmin() external view returns(address){ return address(_qAdmin); } /// @notice Get the address of the `QPriceOracle` contract /// @return address Address of `QPriceOracle` contract function qPriceOracle() external view returns(address){ return address(_qPriceOracle); } /// @notice Get all enabled `Asset`s /// @return address[] iterable list of enabled `Asset`s function allAssets() external view returns(address[] memory) { return _qAdmin.allAssets(); } /// @notice Gets the `CollateralFactor` associated with a ERC20 token /// @param token ERC20 token /// @return uint Collateral Factor, scaled by 1e8 function collateralFactor(IERC20 token) external view returns(uint) { return _qAdmin.collateralFactor(token); } /// @notice Gets the `MarketFactor` associated with a ERC20 token /// @param token ERC20 token /// @return uint Market Factor, scaled by 1e8 function marketFactor(IERC20 token) external view returns(uint) { return _qAdmin.marketFactor(token); } /// @notice Return what the collateral ratio for an account would be /// with a hypothetical collateral withdraw/deposit and/or token borrow/lend. /// The collateral ratio is calculated as: /// (`virtualCollateralValue` / `virtualBorrowValue`) /// If the returned value falls below 1e8, the account can be liquidated /// @param account User account /// @param hypotheticalToken Currency of hypothetical withdraw / deposit /// @param withdrawAmount Amount of hypothetical withdraw in local currency /// @param depositAmount Amount of hypothetical deposit in local currency /// @param hypotheticalMarket Market of hypothetical borrow /// @param borrowAmount Amount of hypothetical borrow in local ccy /// @param lendAmount Amount of hypothetical lend in local ccy /// @return uint Hypothetical collateral ratio function hypotheticalCollateralRatio( address account, IERC20 hypotheticalToken, uint withdrawAmount, uint depositAmount, IFixedRateMarket hypotheticalMarket, uint borrowAmount, uint lendAmount ) external view returns(uint){ return _getHypotheticalCollateralRatio( account, hypotheticalToken, withdrawAmount, depositAmount, hypotheticalMarket, borrowAmount, lendAmount ); } /// @notice Return the current collateral ratio for an account. /// The collateral ratio is calculated as: /// (`virtualCollateralValue` / `virtualBorrowValue`) /// If the returned value falls below 1e8, the account can be liquidated /// @param account User account /// @return uint Collateral ratio function collateralRatio(address account) public view returns(uint){ return _getHypotheticalCollateralRatio( account, IERC20(NULL), 0, 0, IFixedRateMarket(NULL), 0, 0 ); } /// @notice Get the `collateralFactor` weighted value (in USD) of all the /// collateral deposited for an account /// @param account Account to query /// @return uint Total value of account in USD, scaled to 1e18 function virtualCollateralValue(address account) public view returns(uint){ return _getHypotheticalCollateralValue(account, IERC20(NULL), 0, 0, true); } /// @notice Get the `collateralFactor` weighted value (in USD) for the tokens /// deposited for an account /// @param account Account to query /// @param token ERC20 token /// @return uint Value of token collateral of account in USD, scaled to 1e18 function virtualCollateralValueByToken( address account, IERC20 token ) external view returns(uint){ return _getHypotheticalCollateralValueByToken(account, token, 0, 0, true); } /// @notice Return what the weighted total borrow value for an account would be with a hypothetical borrow /// @param account Account to query /// @param hypotheticalMarket Market of hypothetical borrow / lend /// @param borrowAmount Amount of hypothetical borrow in local ccy /// @param lendAmount Amount of hypothetical lend in local ccy /// @return uint Borrow value of account in USD, scaled to 1e18 function hypotheticalVirtualBorrowValue( address account, IFixedRateMarket hypotheticalMarket, uint borrowAmount, uint lendAmount ) external view returns(uint){ return _getHypotheticalBorrowValue(account, hypotheticalMarket, borrowAmount, lendAmount, true); } /// @notice Get the `marketFactor` weighted net borrows (i.e. borrows - lends) /// in USD summed across all `Market`s participated in by the user /// @param account Account to query /// @return uint Borrow value of account in USD, scaled to 1e18 function virtualBorrowValue(address account) public view returns(uint){ return _getHypotheticalBorrowValue(account, IFixedRateMarket(NULL), 0, 0, true); } /// @notice Get the `marketFactor` weighted net borrows (i.e. borrows - lends) /// in USD for a particular `Market` /// @param account Account to query /// @param market `FixedRateMarket` contract /// @return uint Borrow value of account in USD, scaled to 1e18 function virtualBorrowValueByMarket( address account, IFixedRateMarket market ) external view returns(uint){ return _getHypotheticalBorrowValueByMarket(account, market, 0, 0, true); } /// @notice Get the unweighted value (in USD) of all the collateral deposited /// for an account /// @param account Account to query /// @return uint Total value of account in USD, scaled to 1e18 function realCollateralValue(address account) external view returns(uint){ return _getHypotheticalCollateralValue(account, IERC20(NULL), 0, 0, false); } /// @notice Get the unweighted value (in USD) of the tokens deposited /// for an account /// @param account Account to query /// @param token ERC20 token /// @return uint Value of token collateral of account in USD, scaled to 1e18 function realCollateralValueByToken( address account, IERC20 token ) external view returns(uint){ return _getHypotheticalCollateralValueByToken(account, token, 0, 0, false); } /// @notice Get the unweighted current net value borrowed (i.e. borrows - lends) /// in USD summed across all `Market`s participated in by the user /// @param account Account to query /// @return uint Borrow value of account in USD, scaled to 1e18 function realBorrowValue(address account) external view returns(uint){ return _getHypotheticalBorrowValue(account, IFixedRateMarket(NULL), 0, 0, false); } /// @notice Get the unweighted current net value borrowed (i.e. borrows - lends) /// in USD for a particular `Market` /// @param account Account to query /// @param market `FixedRateMarket` contract /// @return uint Borrow value of account in USD, scaled to 1e18 function realBorrowValueByMarket( address account, IFixedRateMarket market ) external view returns(uint){ return _getHypotheticalBorrowValueByMarket(account, market, 0, 0, false); } /// @notice Get an account's maximum available borrow amount in a specific FixedRateMarket. /// For example, what is the maximum amount of GLMRJUL22 that an account can borrow /// while ensuring their account health continues to be acceptable? /// Note: This function will return 0 if market to borrow is disabled /// Note: This function will return creditLimit() if maximum amount allowed for one market exceeds creditLimit() /// Note: User can only borrow up to `initCollateralRatio` for their own protection against instant liquidations /// @param account User account /// @param borrowMarket Address of the `FixedRateMarket` market to borrow /// @return uint Maximum available amount user can borrow (in FV) without breaching `initCollateralRatio` function hypotheticalMaxBorrowFV(address account, IFixedRateMarket borrowMarket) external view returns(uint) { IERC20 borrowERC20 = borrowMarket.underlyingToken(); QTypes.Asset memory asset = _qAdmin.assets(borrowERC20); uint currentRatio = collateralRatio(account); uint initRatio = _qAdmin.initCollateralRatio(account); if (currentRatio <= initRatio) { return 0; } uint creditLimit = _qAdmin.creditLimit(account); // initCollateralRatio = virtualCollateralValue / (virtualBorrowValue + virtualMaxBorrowFV) // => virtualMaxBorrowFV = virtualCollateralValue / initCollateralRatio - virtualBorrowValue uint virtualCollateral = virtualCollateralValue(account); uint virtualBorrow = virtualBorrowValue(account); uint virtualUSD = (virtualCollateral * _qAdmin.MANTISSA_COLLATERAL_RATIO() / initRatio) - virtualBorrow; if (virtualUSD > creditLimit) { // borrow value should not breach credit limit virtualUSD = creditLimit; } uint realUSD = virtualUSD * asset.marketFactor / _qAdmin.MANTISSA_FACTORS(); uint valueLocal = _qPriceOracle.USDToLocal(borrowERC20, realUSD); uint marketLocalLend = borrowMarket.balanceOf(account); // qToken can also be counted towards borrowable amount return valueLocal + marketLocalLend; } /// @notice Get the minimum collateral ratio. Scaled by 1e8. /// @return uint Minimum collateral ratio function minCollateralRatio() external view returns(uint){ return _qAdmin.minCollateralRatio(msg.sender); } /// @notice Get the minimum collateral ratio for a user account. Scaled by 1e8. /// @param account User account /// @return uint Minimum collateral ratio function minCollateralRatio(address account) external view returns(uint){ return _qAdmin.minCollateralRatio(account); } /// @notice Get the initial collateral ratio. Scaled by 1e8 /// @return uint Initial collateral ratio function initCollateralRatio() external view returns(uint){ return _qAdmin.initCollateralRatio(msg.sender); } /// @notice Get the initial collateral ratio for a user account. Scaled by 1e8 /// @param account User account /// @return uint Initial collateral ratio function initCollateralRatio(address account) external view returns(uint){ return _qAdmin.initCollateralRatio(account); } /// @notice Get the close factor. Scaled by 1e8 /// @return uint Close factor function closeFactor() external view returns(uint){ return _qAdmin.closeFactor(); } /// @notice Get the liquidation incentive. Scaled by 1e8 /// @return uint Liquidation incentive function liquidationIncentive() external view returns(uint){ return _qAdmin.liquidationIncentive(); } /// @notice Use this for quick lookups of collateral balances by asset /// @param account User account /// @param token ERC20 token /// @return uint Balance in local function collateralBalance(address account, IERC20 token) external view returns(uint){ return _collateralBalances[account][token]; } /// @notice Get iterable list of collateral addresses which an account has nonzero balance. /// @param account User account /// @return address[] Iterable list of ERC20 token addresses function iterableCollateralAddresses(address account) external view returns(IERC20[] memory){ return _iterableCollateralAddresses[account]; } /// @notice Quick lookup of whether an account has a particular collateral /// @param account User account /// @param token ERC20 token addresses /// @return bool True if account has collateralized with given ERC20 token, false otherwise function accountCollateral(address account, IERC20 token) external view returns(bool) { return _accountCollateral[account][token]; } /// @notice Get iterable list of all Markets which an account has participated /// @param account User account /// @return address[] Iterable list of `FixedRateLoanMarket` contract addresses function iterableAccountMarkets(address account) external view returns(IFixedRateMarket[] memory){ return _iterableAccountMarkets[account]; } /// @notice Quick lookup of whether an account has participated in a Market /// @param account User account /// @param market`FixedRateLoanMarket` contract /// @return bool True if participated, false otherwise function accountMarkets(address account, IFixedRateMarket market) external view returns(bool){ return _accountMarkets[account][market]; } /// @notice Converts any local value into its value in USD using oracle feed price /// @param token ERC20 token /// @param amountLocal Amount denominated in terms of the ERC20 token /// @return uint Amount in USD, scaled to 1e18 function localToUSD( IERC20 token, uint amountLocal ) external view returns(uint){ return _qPriceOracle.localToUSD(token, amountLocal); } /// @notice Converts any value in USD into its value in local using oracle feed price /// @param token ERC20 token /// @param valueUSD Amount in USD /// @return uint Amount denominated in terms of the ERC20 token function USDToLocal( IERC20 token, uint valueUSD ) external view returns(uint){ return _qPriceOracle.USDToLocal(token, valueUSD); } /** INTERNAL FUNCTIONS **/ /// @notice Return what the collateral ratio for an account would be /// with a hypothetical collateral withdraw and/or token borrow. /// The collateral ratio is calculated as: /// (`virtualCollateralValue` / `virtualBorrowValue`) /// If the returned value falls below 1e8, the account can be liquidated /// @param account User account /// @param hypotheticalToken Currency of hypothetical withdraw / deposit /// @param withdrawAmount Amount of hypothetical withdraw in local currency /// @param depositAmount Amount of hypothetical deposit in local currency /// @param hypotheticalMarket Market of hypothetical borrow / lend /// @param borrowAmount Amount of hypothetical borrow in local ccy /// @param lendAmount Amount of hypothetical lend in local ccy /// @return uint Hypothetical collateral ratio function _getHypotheticalCollateralRatio( address account, IERC20 hypotheticalToken, uint withdrawAmount, uint depositAmount, IFixedRateMarket hypotheticalMarket, uint borrowAmount, uint lendAmount ) internal view returns(uint){ // The numerator is the weighted hypothetical collateral value uint num = _getHypotheticalCollateralValue( account, hypotheticalToken, withdrawAmount, depositAmount, true ); // The denominator is the weighted hypothetical borrow value uint denom = _getHypotheticalBorrowValue( account, hypotheticalMarket, borrowAmount, lendAmount, true ); if(denom == 0){ // Need to handle division by zero if account has no borrows return _qAdmin.UINT_MAX(); }else{ // Return the collateral ratio as a value from 0-1, scaled by 1e8 return num * _qAdmin.MANTISSA_COLLATERAL_RATIO() / denom; } } /// @notice Return what the total collateral value for an account would be /// with a hypothetical withdraw, with an option for weighted or unweighted value /// @param account Account to query /// @param hypotheticalToken Currency of hypothetical withdraw / deposit /// @param withdrawAmount Amount of hypothetical withdraw in local currency /// @param depositAmount Amount of hypothetical deposit in local currency /// @param applyCollateralFactor True to get the `collateralFactor` weighted value, false otherwise /// @return uint Total value of account in USD, scaled to 1e18 function _getHypotheticalCollateralValue( address account, IERC20 hypotheticalToken, uint withdrawAmount, uint depositAmount, bool applyCollateralFactor ) internal view returns(uint){ uint totalValueUSD = 0; // If user has never deposited collateral in `hypotheticalToken` before, it // will not be included in `_iterableCollateralAddresses` by default, so // it needs to be handled separately uint newTokenOffset = _qAdmin.assets(hypotheticalToken).isEnabled && !_accountCollateral[account][hypotheticalToken] ? 1 : 0; for (uint i = 0; i < _iterableCollateralAddresses[account].length + newTokenOffset; i++){ // Get the token address in i'th slot of `_iterableCollateralAddresses[account]` // or else the `hypotheticalToken` if it is not included in `iterableColalteralAddresses` IERC20 token = i < _iterableCollateralAddresses[account].length ? _iterableCollateralAddresses[account][i] : hypotheticalToken; // Check if token address matches token in target if(address(token) == address(hypotheticalToken)){ // Add value to total adjusted by hypothetical deposit / withdraw amount totalValueUSD += _getHypotheticalCollateralValueByToken( account, hypotheticalToken, withdrawAmount, depositAmount, applyCollateralFactor ); }else{ // Add value to total without adjustment totalValueUSD += _getHypotheticalCollateralValueByToken( account, token, 0, 0, applyCollateralFactor ); } } return totalValueUSD; } /// @notice Return what the collateral value by token for an account would be /// with a hypothetical withdraw, with an option for weighted or unweighted value /// @param account Account to query /// @param token ERC20 token /// @param withdrawAmount Amount of hypothetical withdraw in local currency /// @param depositAmount Amount of hypothetical deposit in local currency /// @param applyCollateralFactor True to get the `collateralFactor` weighted value, false otherwise /// @return uint Total value of account in USD, scaled to 1e18 function _getHypotheticalCollateralValueByToken( address account, IERC20 token, uint withdrawAmount, uint depositAmount, bool applyCollateralFactor ) internal view returns(uint){ // Withdraw amount must be less than collateral balance require(withdrawAmount <= _collateralBalances[account][token], "QM3 withdraw > collateral"); // Get the `Asset` associated to this token QTypes.Asset memory asset = _qAdmin.assets(token); // Value of collateral in any unsupported `Asset` is zero if(!asset.isEnabled){ return 0; } // Get the local balance of the account for the given `token` uint balanceLocal = _collateralBalances[account][token]; // Adjust by hypothetical withdraw / deposit amount. Guaranteed not to underflow balanceLocal = balanceLocal + depositAmount - withdrawAmount; // Convert the local balance to USD uint valueUSD = _qPriceOracle.localToUSD(token, balanceLocal); if(applyCollateralFactor){ // Apply the `collateralFactor` to get the discounted value of the asset valueUSD = valueUSD * asset.collateralFactor / _qAdmin.MANTISSA_FACTORS(); } return valueUSD; } /// @notice Return what the total borrow value for an account would be /// with a hypothetical borrow, with an option for weighted or unweighted value /// @param account Account to query /// @param hypotheticalMarket Market of hypothetical borrow / lend /// @param borrowAmount Amount of hypothetical borrow in local ccy /// @param lendAmount Amount of hypothetical lend in local ccy /// @param applyMarketFactor True to get the `marketFactor` weighted value, false otherwise /// @return uint Borrow value of account in USD, scaled to 1e18 function _getHypotheticalBorrowValue( address account, IFixedRateMarket hypotheticalMarket, uint borrowAmount, uint lendAmount, bool applyMarketFactor ) internal view returns(uint){ uint totalValueUSD = 0; // If user has never entered `hypotheticalMarket` before, it will not be // included in `_iterableAccountMarkets` by default, so it needs to be // handled separately uint newMarketOffset = _qAdmin.isMarketEnabled(hypotheticalMarket) && !_accountMarkets[account][hypotheticalMarket] ? 1 : 0; for (uint i = 0; i < _iterableAccountMarkets[account].length + newMarketOffset; i++) { // Get the market address in i'th slot of `_iterableAccountMarkets[account]` IFixedRateMarket market = i < _iterableAccountMarkets[account].length ? _iterableAccountMarkets[account][i] : hypotheticalMarket; // Check if the user is requesting to borrow more in this `Market` if(address(market) == address(hypotheticalMarket)){ // User requesting to borrow / lend in this `Market`, adjust amount accordingly totalValueUSD += _getHypotheticalBorrowValueByMarket( account, hypotheticalMarket, borrowAmount, lendAmount, applyMarketFactor ); }else{ // User not requesting to borrow more in this `Market`, just get current value totalValueUSD += _getHypotheticalBorrowValueByMarket( account, market, 0, 0, applyMarketFactor ); } } return totalValueUSD; } /// @notice Return what the borrow value by `Market` for an account would be /// with a hypothetical borrow, with an option for weighted or unweighted value /// @param account Account to query /// @param market Market of the hypothetical borrow / lend /// @param borrowAmount Amount of hypothetical borrow in local ccy /// @param lendAmount Amount of hypothetical lend in local ccy /// @param applyMarketFactor True to get the `marketFactor` weighted value, false otherwise /// @return uint Borrow value of account in USD (18 decimal places) function _getHypotheticalBorrowValueByMarket( address account, IFixedRateMarket market, uint borrowAmount, uint lendAmount, bool applyMarketFactor ) internal view returns(uint){ // Total `borrowsLocal` should be current borrow plus `borrowAmount` uint borrowsLocal = market.accountBorrows(account) + borrowAmount; // Total `lendsLocal` should be user's balance of qTokens plus `lendAmount` uint lendsLocal = market.balanceOf(account) + lendAmount; if(lendsLocal >= borrowsLocal){ // Default to zero if lends greater than borrows return 0; }else{ // Get the net amount being borrowed in local // Guaranteed not to underflow from the above check uint borrowValueLocal = borrowsLocal - lendsLocal; // Convert from local value to value in USD IERC20 token = market.underlyingToken(); QTypes.Asset memory asset = _qAdmin.assets(token); uint borrowValueUSD = _qPriceOracle.localToUSD(token, borrowValueLocal); if(applyMarketFactor){ // Apply the `marketFactor` to get the risk premium value of the borrow borrowValueUSD = borrowValueUSD * _qAdmin.MANTISSA_FACTORS() / asset.marketFactor; } return borrowValueUSD; } } /// @notice Users call this to deposit collateral to fund their borrows /// @param account Address of user /// @param token ERC20 token /// @param amount Amount to deposit (in local ccy) /// @return uint New collateral balance function _depositCollateral(address account, IERC20 token, uint amount) internal returns(uint) { // Transfer the collateral from the account to this contract uint balanceBefore = token.balanceOf(address(this)); token.safeTransferFrom(account, address(this), amount); uint balanceAfter = token.balanceOf(address(this)); // Get more accurate amount of user deposit uint actualDeposit = balanceAfter - balanceBefore; // Update internal account collateral balance mappings _addCollateral(account, token, actualDeposit); // Return the account's updated collateral balance for this token return _collateralBalances[account][token]; } /// @notice Users call this to deposit collateral to fund their borrows, where their /// collateral is automatically wrapped into MTokens for convenience so users can /// automatically earn interest on their collateral. /// @param account Address of the user /// @param underlying Underlying ERC20 token /// @param amount Amount to deposit (in underlying local currency) /// @return uint New collateral balance (in MToken balance) function _depositCollateralWithMTokenWrap( address account, IERC20 underlying, uint amount ) internal returns(uint) { // Get the address of the corresponding MToken address mTokenAddress = _qAdmin.underlyingToMToken(underlying); // Check that the MToken asset has been enabled as collateral require(mTokenAddress != address(0), "QM4 MToken unsupported"); // Transfer the underlying collateral from the account to this contract uint balanceBeforeUnderlying = underlying.balanceOf(address(this)); underlying.safeTransferFrom(account, address(this), amount); uint balanceAfterUnderlying = underlying.balanceOf(address(this)); // Get accurate amount of user deposit uint actualDepositUnderlying = balanceAfterUnderlying - balanceBeforeUnderlying; // Make underlying token approval // NOTE: This "approve" call should be safe as it only approves the bare // minimum transferred, but in general be careful of attacks here. We are // relying on the above "require" check that `mTokenAddress` is a safe // address, so we should make sure that only admin is able to add // `mTokenAddress` as a whitelisted address or else an attacker can // potentially drain funds underlying.approve(mTokenAddress, actualDepositUnderlying); if(address(underlying) == _NATIVE_TOKEN_ADDRESS) { // Hardcode special logic for native token ERC20 // Moonwell uses the Compound-style transferring of native token // so we must follow a different interface MGlimmerInterface mToken = MGlimmerInterface(mTokenAddress); // Forward user collateral to MToken uint balanceBeforeMToken = mToken.balanceOf(address(this)); mToken.mint{value: actualDepositUnderlying}(); uint balanceAfterMToken = mToken.balanceOf(address(this)); // Get accurate amount of mtokens minted uint actualDepositMToken = balanceAfterMToken - balanceBeforeMToken; // Update internal account collateral balance mappings _addCollateral(account, mToken, actualDepositMToken); return _collateralBalances[account][mToken]; } else { // Generic logic for all other ERC20 tokens using // ERC20 transfer function MErc20Interface mToken = MErc20Interface(mTokenAddress); // Forward user collateral to MToken uint balanceBeforeMToken = mToken.balanceOf(address(this)); mToken.mint(actualDepositUnderlying); uint balanceAfterMToken = mToken.balanceOf(address(this)); // Get accurate amount of mTokens minted uint actualDepositMToken = balanceAfterMToken - balanceBeforeMToken; // Update internal account collateral balance mappings _addCollateral(account, mToken, actualDepositMToken); return _collateralBalances[account][mToken]; } } /// @notice Users call this to withdraw collateral /// @param account Address of user /// @param token ERC20 token /// @param amount Amount to withdraw (in local ccy) /// @return uint New collateral balance function _withdrawCollateral(address account, IERC20 token, uint amount) internal returns(uint) { // Amount must be positive require(amount > 0, "QM5 withdraw must be positive"); // Get the hypothetical collateral ratio after withdrawal uint collateralRatio_ = _getHypotheticalCollateralRatio( account, token, amount, 0, IFixedRateMarket(NULL), 0, 0 ); // Check that the `collateralRatio` after withdrawal is still healthy. // User is only allowed to withdraw up to `_initCollateralRatio`, not // `_minCollateralRatio`, for their own protection against instant liquidations. require(collateralRatio_ >= _qAdmin.initCollateralRatio(account), "QM6 invalid withdraw amount"); // Update internal account collateral balance mappings _subtractCollateral(account, token, amount); // Send collateral from the protocol to the account token.safeTransfer(account, amount); // Emit the event emit WithdrawCollateral(account, address(token), amount); // Return the account's updated collateral balance for this token return _collateralBalances[account][token]; } /// @notice Users call this to withdraw mToken collateral, where their /// collateral is automatically unwrapped into underlying tokens for /// convenience. /// @param account Address of the user /// @param mTokenAddress Yield-bearing token address /// @param amount Amount to withdraw (in mToken local currency) /// @return uint New collateral balance (in MToken balance) function _withdrawCollateralWithMTokenUnwrap( address account, address mTokenAddress, uint amount ) internal returns(uint) { // Get the corresponding underlying address underlyingAddress = _qAdmin.assets(IERC20(mTokenAddress)).underlying; IERC20 underlying = IERC20(underlyingAddress); if(underlyingAddress == _NATIVE_TOKEN_ADDRESS) { // Hardcode special logic for native token ERC20 // Moonwell uses the Compound-style transferring of native token // so we must follow a different interface MGlimmerInterface mToken = MGlimmerInterface(mTokenAddress); // Redeem mTokens for underlying and return it to user uint balanceBeforeUnderlying = underlying.balanceOf(address(this)); mToken.redeem(amount); uint balanceAfterUnderlying = underlying.balanceOf(address(this)); // Get accurate amount of underlying redeemed uint actualAmountUnderlying = balanceAfterUnderlying - balanceBeforeUnderlying; // Update internal account collateral balance mappings _subtractCollateral(account, mToken, amount); // Send unwrapped underlying collateral from the protocol to the account underlying.transfer(account, actualAmountUnderlying); // Emit the event emit WithdrawCollateral(account, mTokenAddress, amount); } else { // Generic logic for all other ERC20 tokens using // ERC20 transfer function MErc20Interface mToken = MErc20Interface(mTokenAddress); // Redeem mTokens for underlying and return it to user uint balanceBeforeUnderlying = underlying.balanceOf(address(this)); mToken.redeem(amount); uint balanceAfterUnderlying = underlying.balanceOf(address(this)); // Get accurate amount of underlying redeemed uint actualAmountUnderlying = balanceAfterUnderlying - balanceBeforeUnderlying; // Update internal account collateral balance mappings _subtractCollateral(account, mToken, amount); // Send unwrapped underlying collateral from the protocol to the account underlying.transfer(account, actualAmountUnderlying); // Emit the event emit WithdrawCollateral(account, mTokenAddress, amount); } return _collateralBalances[account][IERC20(mTokenAddress)]; } /// @notice Add to internal account collateral balance and related mappings /// @param account User account /// @param token Currency which the collateral will be denominated in /// @param amount Amount to add function _addCollateral(address account, IERC20 token, uint amount) internal{ // Get the associated `Asset` to the token address QTypes.Asset memory asset = _qAdmin.assets(token); // Only enabled assets are supported as collateral require(asset.isEnabled, "QM7 asset unsupported"); // Record that sender now has collateral deposited in this currency // This should only be updated once per account when initially depositing // collateral in a new currency to ensure that the `_accountCollateral` mapping // remains unique if(!_accountCollateral[account][token]){ _iterableCollateralAddresses[account].push(token); _accountCollateral[account][token] = true; } // Record the increase in collateral balance for the account _collateralBalances[account][token] += amount; // Emit the event emit DepositCollateral(account, address(token), amount); } /// @notice Subtract from internal account collateral balance and related mappings /// @param account User account /// @param token Currency which the collateral will be denominated in /// @param amount Amount to subtract function _subtractCollateral(address account, IERC20 token, uint amount) internal{ // Check that user has enough collateral to be subtracted require(_collateralBalances[account][token] >= amount, "QM8 not enough collateral"); // Record the decrease in collateral balance for the account _collateralBalances[account][token] -= amount; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ``` * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original * initialization step. This is essential to configure modules that are added through upgrades and that require * initialization. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized < type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } }
// 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 (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
//SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IFixedRateMarket is IERC20Upgradeable, IERC20MetadataUpgradeable { /// @notice Emitted when a borrower repays borrow. /// Boolean flag `withQTokens`= true if repaid via qTokens, false otherwise. event RepayBorrow(address indexed borrower, uint amount, bool withQTokens); /// @notice Emitted when a borrower is liquidated event LiquidateBorrow( address indexed borrower, address indexed liquidator, uint amount, address collateralTokenAddress, uint reward ); /// @notice Emitted when a borrower and lender are matched for a fixed rate loan event FixedRateLoan( bytes32 indexed quoteId, address indexed borrower, address indexed lender, uint amountPV, uint amountFV, uint feeIncurred); /// @notice Emitted when an account cancels their Quote event CancelQuote(address indexed account, uint nonce); /// @notice Emitted when an account redeems their qTokens event RedeemQTokens(address indexed account, uint amount); /** USER INTERFACE **/ /// @notice Execute against Quote as a borrower. /// @param amountPV Amount that the borrower wants to execute as PV /// @param lender Account of the lender /// @param quoteType *Lender's* type preference, 0 for PV+APR, 1 for FV+APR /// @param quoteExpiryTime Timestamp after which the quote is no longer valid /// @param APR In decimal form scaled by 1e4 (ex. 10.52% = 1052) /// @param cashflow Can be PV or FV depending on `quoteType` /// @param nonce For uniqueness of signature /// @param signature signed hash of the Quote message /// @return uint, uint Loan amount (`amountPV`) and repayment amount (`amountFV`) function borrow( uint amountPV, address lender, uint8 quoteType, uint64 quoteExpiryTime, uint64 APR, uint cashflow, uint nonce, bytes memory signature ) external returns(uint, uint); /// @notice Execute against Quote as a lender. /// @param amountPV Amount that the lender wants to execute as PV /// @param borrower Account of the borrower /// @param quoteType *Borrower's* type preference, 0 for PV+APR, 1 for FV+APR /// @param quoteExpiryTime Timestamp after which the quote is no longer valid /// @param APR In decimal form scaled by 1e4 (ex. 10.52% = 1052) /// @param cashflow Can be PV or FV depending on `quoteType` /// @param nonce For uniqueness of signature /// @param signature signed hash of the Quote message /// @return uint, uint Loan amount (`amountPV`) and repayment amount (`amountFV`) function lend( uint amountPV, address borrower, uint8 quoteType, uint64 quoteExpiryTime, uint64 APR, uint cashflow, uint nonce, bytes memory signature ) external returns(uint, uint); /// @notice Borrower will make repayments to the smart contract, which /// holds the value in escrow until maturity to release to lenders. /// @param amount Amount to repay /// @return uint Remaining account borrow amount function repayBorrow(uint amount) external returns(uint); /// @notice By setting the nonce in `_voidNonces` to true, this is equivalent to /// invalidating the Quote (i.e. cancelling the quote) /// param nonce Nonce of the Quote to be cancelled function cancelQuote(uint nonce) external; /// @notice This function allows net lenders to redeem qTokens for the /// underlying token. Redemptions may only be permitted after loan maturity /// plus `_maturityGracePeriod`. The public interface redeems specified amount /// of qToken from existing balance. /// @param amount Amount of qTokens to redeem /// @return uint Amount of qTokens redeemed function redeemQTokensByRatio(uint amount) external returns(uint); /// @notice This function allows net lenders to redeem qTokens for the /// underlying token. Redemptions may only be permitted after loan maturity /// plus `_maturityGracePeriod`. The public interface redeems the entire qToken /// balance. /// @return uint Amount of qTokens redeemed function redeemAllQTokensByRatio() external returns(uint); /// @notice Get amount of qTokens user can redeem based on current loan repayment ratio /// @return uint amount of qTokens user can redeem function redeemableQTokens() external view returns(uint); /// @notice Get amount of qTokens user can redeem based on current loan repayment ratio /// @param account Account to query /// @return uint amount of qTokens user can redeem function redeemableQTokens(address account) external view returns(uint); /// @notice If an account is in danger of being undercollateralized (i.e. /// collateralRatio < 1.0) or has not repaid past maturity plus `_repaymentGracePeriod`, /// any user may liquidate that account by paying back the loan on behalf of the account. /// In return, the liquidator receives collateral belonging to the account equal in value to /// the repayment amount in USD plus the liquidation incentive amount as a bonus. /// @param borrower Address of account that is undercollateralized /// @param amount Amount to repay on behalf of account /// @param collateralToken Liquidator's choice of which currency to be paid in function liquidateBorrow( address borrower, uint amount, IERC20 collateralToken ) external; /** VIEW FUNCTIONS **/ /// @notice Get the address of the `QAdmin` contract /// @return address Address of `QAdmin` contract function qAdmin() external view returns(address); /// @notice Get the address of the `QollateralManager` /// @return address function qollateralManager() external view returns(address); /// @notice Get the address of the ERC20 token which the loan will be denominated /// @return IERC20 function underlyingToken() external view returns(IERC20); /// @notice Get the UNIX timestamp (in seconds) when the market matures /// @return uint function maturity() external view returns(uint); /// @notice Get the minimum quote size for this market /// @return uint Minimum quote size, in PV terms, local currency function minQuoteSize() external view returns(uint); /// @notice True if a nonce for a Quote is voided, false otherwise. /// Used for checking if a Quote is a duplicated. /// @param account Account to query /// @param nonce Nonce to query /// @return bool True if used, false otherwise function isNonceVoid(address account, uint nonce) external view returns(bool); /// @notice Get the total balance of borrows by user /// @param account Account to query /// @return uint Borrows function accountBorrows(address account) external view returns(uint); /// @notice Get the current total partial fill for a Quote /// @param quoteId ID of the Quote - this is the keccak256 hash of the signature /// @return uint Partial fill function quoteFill(bytes32 quoteId) external view returns(uint); /// @notice Get the `protocolFee` associated with this market /// @return uint annualized protocol fee, scaled by 1e4 function protocolFee() external view returns(uint); /// @notice Get the `protocolFee` associated with this market, prorated by time till maturity /// @param amount loan amount /// @param timeNow block timestamp for calculating time till maturity /// @return uint prorated protocol fee, scaled by 1e4 function proratedProtocolFee(uint amount, uint timeNow) external view returns(uint); /// @notice Get the `protocolFee` associated with this market, prorated by time till maturity from now /// @param amount loan amount /// @return uint prorated protocol fee, scaled by 1e4 function proratedProtocolFeeNow(uint amount) external view returns(uint); /// @notice Gets the current `redemptionRatio` where owned qTokens can be redeemed up to /// @return uint redemption ratio, capped and scaled by 1e18 function redemptionRatio() external view returns(uint); /// @notice Tokens redeemed across all users so far /// @return uint redeemed amount of qToken function tokensRedeemedTotal() external view returns(uint); /// @notice Get total protocol fee accrued in this market so far, in local currency /// @return uint accrued fee function totalAccruedFees() external view returns(uint); }
//SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; import "@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./IFixedRateMarket.sol"; import "../libraries/QTypes.sol"; interface IQAdmin is IAccessControlUpgradeable { /// @notice Emitted when a new FixedRateMarket is deployed event CreateFixedRateMarket(address indexed marketAddress, address indexed tokenAddress, uint maturity); /// @notice Emitted when a new `Asset` is added event AddAsset( address indexed tokenAddress, bool isYieldBearing, address oracleFeed, uint collateralFactor, uint marketFactor); /// @notice Emitted when setting `_qollateralManager` event SetQollateralManager(address qollateralManagerAddress); /// @notice Emitted when setting `_stakingEmissionsQontroller` event SetStakingEmissionsQontroller(address stakingEmissionsQontrollerAddress); /// @notice Emitted when setting `_tradingEmissionsQontroller` event SetTradingEmissionsQontroller(address tradingEmissionsQontrollerAddress); /// @notice Emitted when setting `_feeEmissionsQontroller` event SetFeeEmissionsQontroller(address feeEmissionsQontrollerAddress); /// @notice Emitted when setting `_veQoda` event SetVeQoda(address veQodaAddress); /// @notice Emitted when setting `collateralFactor` event SetCollateralFactor(address indexed tokenAddress, uint oldValue, uint newValue); /// @notice Emitted when setting `marketFactor` event SetMarketFactor(address indexed tokenAddress, uint oldValue, uint newValue); /// @notice Emitted when setting `minQuoteSize` event SetMinQuoteSize(address indexed tokenAddress, uint oldValue, uint newValue); /// @notice Emitted when `_minCollateralRatioDefault` and `_initCollateralRatioDefault` get updated event SetCollateralRatio(uint oldMinValue, uint oldInitValue, uint newMinValue, uint newInitValue); /// @notice Emitted when `CreditFacility` gets updated event SetCreditFacility(address account, bool oldEnabled, uint oldMinValue, uint oldInitValue, uint oldCreditValue, bool newEnabled, uint newMinValue, uint newInitValue, uint newCreditValue); /// @notice Emitted when `_closeFactor` gets updated event SetCloseFactor(uint oldValue, uint newValue); /// @notice Emitted when `_repaymentGracePeriod` gets updated event SetRepaymentGracePeriod(uint oldValue, uint newValue); /// @notice Emitted when `_maturityGracePeriod` gets updated event SetMaturityGracePeriod(uint oldValue, uint newValue); /// @notice Emitted when `_liquidationIncentive` gets updated event SetLiquidationIncentive(uint oldValue, uint newValue); /// @notice Emitted when `_protocolFee` gets updated event SetProtocolFee(uint oldValue, uint newValue); /** ADMIN FUNCTIONS **/ /// @notice Call upon initialization after deploying `QollateralManager` contract /// @param qollateralManagerAddress Address of `QollateralManager` deployment function _setQollateralManager(address qollateralManagerAddress) external; /// @notice Call upon initialization after deploying `StakingEmissionsQontroller` contract /// @param stakingEmissionsQontrollerAddress Address of `StakingEmissionsQontroller` deployment function _setStakingEmissionsQontroller(address stakingEmissionsQontrollerAddress) external; /// @notice Call upon initialization after deploying `TradingEmissionsQontroller` contract /// @param tradingEmissionsQontrollerAddress Address of `TradingEmissionsQontroller` deployment function _setTradingEmissionsQontroller(address tradingEmissionsQontrollerAddress) external; /// @notice Call upon initialization after deploying `FeeEmissionsQontroller` contract /// @param feeEmissionsQontrollerAddress Address of `FeeEmissionsQontroller` deployment function _setFeeEmissionsQontroller(address feeEmissionsQontrollerAddress) external; /// @notice Call upon initialization after deploying `veQoda` contract /// @param veQodaAddress Address of `veQoda` deployment function _setVeQoda(address veQodaAddress) external; /// @notice Set credit facility for specified account /// @param account_ account for credit facility adjustment /// @param enabled_ If credit facility should be enabled /// @param minCollateralRatio_ New minimum collateral ratio value /// @param initCollateralRatio_ New initial collateral ratio value /// @param creditLimit_ new credit limit in USD, scaled by 1e18 function _setCreditFacility(address account_, bool enabled_, uint minCollateralRatio_, uint initCollateralRatio_, uint creditLimit_) external; /// @notice Admin function for adding new Assets. An Asset must be added before it /// can be used as collateral or borrowed. Note: We can create functionality for /// allowing borrows of a token but not using it as collateral by setting /// `collateralFactor` to zero. /// @param token ERC20 token corresponding to the Asset /// @param isYieldBearing True if token bears interest (eg aToken, cToken, mToken, etc) /// @param underlying Address of the underlying token /// @param oracleFeed Chainlink price feed address /// @param collateralFactor 0.0 to 1.0 (scaled to 1e8) for discounting risky assets /// @param marketFactor 0.0 to 1.0 (scaled to 1e8) for premium on risky borrows function _addAsset( IERC20 token, bool isYieldBearing, address underlying, address oracleFeed, uint collateralFactor, uint marketFactor ) external; /// @notice Adds a new `FixedRateMarket` contract into the internal mapping of /// whitelisted market addresses /// @param market New `FixedRateMarket` contract address /// @param protocolFee_ Corresponding protocol fee in basis points /// @param minQuoteSize_ Size in PV terms, local currency function _addFixedRateMarket( IFixedRateMarket market, uint protocolFee_, uint minQuoteSize_ ) external; /// @notice Update the `collateralFactor` for a given `Asset` /// @param token ERC20 token corresponding to the Asset /// @param collateralFactor 0.0 to 1.0 (scaled to 1e8) for discounting risky assets function _setCollateralFactor(IERC20 token, uint collateralFactor) external; /// @notice Update the `marketFactor` for a given `Asset` /// @param token Address of the token corresponding to the Asset /// @param marketFactor 0.0 to 1.0 (scaled to 1e8) for discounting risky assets function _setMarketFactor(IERC20 token, uint marketFactor) external; /// @notice Set the minimum quote size for a particular `FixedRateMarket` /// @param market Address of the `FixedRateMarket` contract /// @param minQuoteSize_ Size in PV terms, local currency function _setMinQuoteSize(IFixedRateMarket market, uint minQuoteSize_) external; /// @notice Set the global minimum and initial collateral ratio /// @param minCollateralRatio_ New global minimum collateral ratio value /// @param initCollateralRatio_ New global initial collateral ratio value function _setCollateralRatio(uint minCollateralRatio_, uint initCollateralRatio_) external; /// @notice Set the global close factor /// @param closeFactor_ New close factor value function _setCloseFactor(uint closeFactor_) external; /// @notice Set the global repayment grace period /// @param repaymentGracePeriod_ New repayment grace period function _setRepaymentGracePeriod(uint repaymentGracePeriod_) external; /// @notice Set the global maturity grace period /// @param maturityGracePeriod_ New maturity grace period function _setMaturityGracePeriod(uint maturityGracePeriod_) external; /// @notice Set the global liquidation incetive /// @param liquidationIncentive_ New liquidation incentive value function _setLiquidationIncentive(uint liquidationIncentive_) external; /// @notice Set the global annualized protocol fees for each market in basis points /// @param market Address of the `FixedRateMarket` contract /// @param protocolFee_ New protocol fee value (scaled to 1e4) function _setProtocolFee(IFixedRateMarket market, uint protocolFee_) external; /// @notice Set the global threshold in USD for protocol fee transfer /// @param thresholdUSD_ New threshold USD value (scaled by 1e6) function _setThresholdUSD(uint thresholdUSD_) external; /** VIEW FUNCTIONS **/ function ADMIN_ROLE() external view returns(bytes32); function MARKET_ROLE() external view returns(bytes32); function MINTER_ROLE() external view returns(bytes32); function VETOKEN_ROLE() external view returns(bytes32); /// @notice Get the address of the `QollateralManager` contract function qollateralManager() external view returns(address); /// @notice Get the address of the `QPriceOracle` contract function qPriceOracle() external view returns(address); /// @notice Get the address of the `StakingEmissionsQontroller` contract function stakingEmissionsQontroller() external view returns(address); /// @notice Get the address of the `TradingEmissionsQontroller` contract function tradingEmissionsQontroller() external view returns(address); /// @notice Get the address of the `FeeEmissionsQontroller` contract function feeEmissionsQontroller() external view returns(address); /// @notice Get the address of the `veQoda` contract function veQoda() external view returns(address); /// @notice Get the credit limit with associated address, scaled by 1e18 function creditLimit(address account_) external view returns(uint); /// @notice Gets the `Asset` mapped to the address of a ERC20 token /// @param token ERC20 token /// @return QTypes.Asset Associated `Asset` function assets(IERC20 token) external view returns(QTypes.Asset memory); /// @notice Get all enabled `Asset`s /// @return address[] iterable list of enabled `Asset`s function allAssets() external view returns(address[] memory); /// @notice Gets the `CollateralFactor` associated with a ERC20 token /// @param token ERC20 token /// @return uint Collateral Factor, scaled by 1e8 function collateralFactor(IERC20 token) external view returns(uint); /// @notice Gets the `MarketFactor` associated with a ERC20 token /// @param token ERC20 token /// @return uint Market Factor, scaled by 1e8 function marketFactor(IERC20 token) external view returns(uint); /// @notice Gets the `maturities` associated with a ERC20 token /// @param token ERC20 token /// @return uint[] array of UNIX timestamps (in seconds) of the maturity dates function maturities(IERC20 token) external view returns(uint[] memory); /// @notice Get the MToken market corresponding to any underlying ERC20 /// tokenAddress => mTokenAddress function underlyingToMToken(IERC20 token) external view returns(address); /// @notice Gets the address of the `FixedRateMarket` contract /// @param token ERC20 token /// @param maturity UNIX timestamp of the maturity date /// @return IFixedRateMarket Address of `FixedRateMarket` contract function fixedRateMarkets(IERC20 token, uint maturity) external view returns(IFixedRateMarket); /// @notice Check whether an address is a valid FixedRateMarket address. /// Can be used for checks for inter-contract admin/restricted function call. /// @param market `FixedRateMarket` contract /// @return bool True if valid false otherwise function isMarketEnabled(IFixedRateMarket market) external view returns(bool); function minQuoteSize(IFixedRateMarket market) external view returns(uint); function minCollateralRatio() external view returns(uint); function minCollateralRatio(address account) external view returns(uint); function initCollateralRatio() external view returns(uint); function initCollateralRatio(address account) external view returns(uint); function closeFactor() external view returns(uint); function repaymentGracePeriod() external view returns(uint); function maturityGracePeriod() external view returns(uint); function liquidationIncentive() external view returns(uint); /// @notice Annualized protocol fee in basis points, scaled by 1e4 function protocolFee(IFixedRateMarket market) external view returns(uint); /// @notice threshold in USD where protocol fee from each market will be transferred into `FeeEmissionsQontroller` /// once this amount is reached, scaled by 1e6 function thresholdUSD() external view returns(uint); /// @notice 2**256 - 1 function UINT_MAX() external pure returns(uint); /// @notice Generic mantissa corresponding to ETH decimals function MANTISSA_DEFAULT() external pure returns(uint); /// @notice Mantissa for USD function MANTISSA_USD() external pure returns(uint); /// @notice Mantissa for collateral ratio function MANTISSA_COLLATERAL_RATIO() external pure returns(uint); /// @notice `assetFactor` and `marketFactor` have up to 8 decimal places precision function MANTISSA_FACTORS() external pure returns(uint); /// @notice Basis points have 4 decimal place precision function MANTISSA_BPS() external pure returns(uint); /// @notice Staked Qoda has 6 decimal place precision function MANTISSA_STAKING() external pure returns(uint); /// @notice `collateralFactor` cannot be above 1.0 function MAX_COLLATERAL_FACTOR() external pure returns(uint); /// @notice `marketFactor` cannot be above 1.0 function MAX_MARKET_FACTOR() external pure returns(uint); /// @notice version number of this contract, will be bumped upon contractual change function VERSION_NUMBER() external pure returns(string memory); }
//SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IQPriceOracle { /// @notice Converts any local value into its value in USD using oracle feed price /// @param token ERC20 token /// @param amountLocal Amount denominated in terms of the ERC20 token /// @return uint Amount in USD function localToUSD(IERC20 token, uint amountLocal) external view returns(uint); /// @notice Converts any value in USD into its value in local using oracle feed price /// @param token ERC20 token /// @param valueUSD Amount in USD /// @return uint Amount denominated in terms of the ERC20 token function USDToLocal(IERC20 token, uint valueUSD) external view returns(uint); /// @notice Convenience function for getting price feed from Chainlink oracle /// @param oracleFeed Address of the chainlink oracle feed /// @return answer uint256, decimals uint8 function priceFeed(address oracleFeed) external view returns(uint256, uint8); /// @notice Get the address of the `QAdmin` contract /// @return address Address of `QAdmin` contract function qAdmin() external view returns(address); }
//SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./IFixedRateMarket.sol"; interface IQollateralManager { /// @notice Emitted when an account deposits collateral into the contract event DepositCollateral(address indexed account, address tokenAddress, uint amount); /// @notice Emitted when an account withdraws collateral from the contract event WithdrawCollateral(address indexed account, address tokenAddress, uint amount); /// @notice Emitted when an account first interacts with the `Market` event AddAccountMarket(address indexed account, address indexed market); /// @notice Emitted when collateral is transferred from one account to another event TransferCollateral(address indexed tokenAddress, address indexed from, address indexed to, uint amount); /// @notice Constructor for upgradeable contracts /// @param qAdminAddress_ Address of the `QAdmin` contract /// @param qPriceOracleAddress_ Address of the `QPriceOracle` contract function initialize(address qAdminAddress_, address qPriceOracleAddress_) external; /** ADMIN/RESTRICTED FUNCTIONS **/ /// @notice Record when an account has either borrowed or lent into a /// `FixedRateMarket`. This is necessary because we need to iterate /// across all markets that an account has borrowed/lent to to calculate their /// `borrowValue`. Only the `FixedRateMarket` contract itself may call /// this function /// @param account User account /// @param market Address of the `FixedRateMarket` market function _addAccountMarket(address account, IFixedRateMarket market) external; /// @notice Transfer collateral balances from one account to another. Only /// `FixedRateMarket` contracts can call this restricted function. This is used /// for when a liquidator liquidates an account. /// @param token ERC20 token /// @param from Sender address /// @param to Recipient address /// @param amount Amount to transfer function _transferCollateral(IERC20 token, address from, address to, uint amount) external; /** USER INTERFACE **/ /// @notice Users call this to deposit collateral to fund their borrows /// @param token ERC20 token /// @param amount Amount to deposit (in local ccy) /// @return uint New collateral balance function depositCollateral(IERC20 token, uint amount) external returns(uint); /// @notice Users call this to deposit collateral to fund their borrows, where their /// collateral is automatically wrapped into MTokens for convenience so users can /// automatically earn interest on their collateral. /// @param underlying Underlying ERC20 token /// @param amount Amount to deposit (in underlying local currency) /// @return uint New collateral balance (in MToken balance) function depositCollateralWithMTokenWrap(IERC20 underlying, uint amount) external returns(uint); /// @notice Users call this to withdraw collateral /// @param token ERC20 token /// @param amount Amount to withdraw (in local ccy) /// @return uint New collateral balance function withdrawCollateral(IERC20 token, uint amount) external returns(uint); /// @notice Users call this to withdraw mToken collateral, where their /// collateral is automatically unwrapped into underlying tokens for /// convenience. /// @param mTokenAddress Yield-bearing token address /// @param amount Amount to withdraw (in mToken local currency) /// @return uint New collateral balance (in MToken balance) function withdrawCollateralWithMTokenUnwrap( address mTokenAddress, uint amount ) external returns(uint); /** VIEW FUNCTIONS **/ /// @notice Get the address of the `QAdmin` contract /// @return address Address of `QAdmin` contract function qAdmin() external view returns(address); /// @notice Get the address of the `QPriceOracle` contract /// @return address Address of `QPriceOracle` contract function qPriceOracle() external view returns(address); /// @notice Get all enabled `Asset`s /// @return address[] iterable list of enabled `Asset`s function allAssets() external view returns(address[] memory); /// @notice Gets the `CollateralFactor` associated with a ERC20 token /// @param token ERC20 token /// @return uint Collateral Factor, scaled by 1e8 function collateralFactor(IERC20 token) external view returns(uint); /// @notice Gets the `MarketFactor` associated with a ERC20 token /// @param token ERC20 token /// @return uint Market Factor, scaled by 1e8 function marketFactor(IERC20 token) external view returns(uint); /// @notice Return what the collateral ratio for an account would be /// with a hypothetical collateral withdraw/deposit and/or token borrow/lend. /// The collateral ratio is calculated as: /// (`virtualCollateralValue` / `virtualBorrowValue`) /// If the returned value falls below 1e8, the account can be liquidated /// @param account User account /// @param hypotheticalToken Currency of hypothetical withdraw / deposit /// @param withdrawAmount Amount of hypothetical withdraw in local currency /// @param depositAmount Amount of hypothetical deposit in local currency /// @param hypotheticalMarket Market of hypothetical borrow /// @param borrowAmount Amount of hypothetical borrow in local ccy /// @param lendAmount Amount of hypothetical lend in local ccy /// @return uint Hypothetical collateral ratio function hypotheticalCollateralRatio( address account, IERC20 hypotheticalToken, uint withdrawAmount, uint depositAmount, IFixedRateMarket hypotheticalMarket, uint borrowAmount, uint lendAmount ) external view returns(uint); /// @notice Return the current collateral ratio for an account. /// The collateral ratio is calculated as: /// (`virtualCollateralValue` / `virtualBorrowValue`) /// If the returned value falls below 1e8, the account can be liquidated /// @param account User account /// @return uint Collateral ratio function collateralRatio(address account) external view returns(uint); /// @notice Get the `collateralFactor` weighted value (in USD) of all the /// collateral deposited for an account /// @param account Account to query /// @return uint Total value of account in USD, scaled to 1e18 function virtualCollateralValue(address account) external view returns(uint); /// @notice Get the `collateralFactor` weighted value (in USD) for the tokens /// deposited for an account /// @param account Account to query /// @param token ERC20 token /// @return uint Value of token collateral of account in USD, scaled to 1e18 function virtualCollateralValueByToken( address account, IERC20 token ) external view returns(uint); /// @notice Get the `marketFactor` weighted net borrows (i.e. borrows - lends) /// in USD summed across all `Market`s participated in by the user /// @param account Account to query /// @return uint Borrow value of account in USD, scaled to 1e18 function virtualBorrowValue(address account) external view returns(uint); /// @notice Get the `marketFactor` weighted net borrows (i.e. borrows - lends) /// in USD for a particular `Market` /// @param account Account to query /// @param market `FixedRateMarket` contract /// @return uint Borrow value of account in USD, scaled to 1e18 function virtualBorrowValueByMarket( address account, IFixedRateMarket market ) external view returns(uint); /// @notice Return what the weighted total borrow value for an account would be with a hypothetical borrow /// @param account Account to query /// @param hypotheticalMarket Market of hypothetical borrow / lend /// @param borrowAmount Amount of hypothetical borrow in local ccy /// @param lendAmount Amount of hypothetical lend in local ccy /// @return uint Borrow value of account in USD, scaled to 1e18 function hypotheticalVirtualBorrowValue( address account, IFixedRateMarket hypotheticalMarket, uint borrowAmount, uint lendAmount ) external view returns(uint); /// @notice Get the unweighted value (in USD) of all the collateral deposited /// for an account /// @param account Account to query /// @return uint Total value of account in USD, scaled to 1e18 function realCollateralValue(address account) external view returns(uint); /// @notice Get the unweighted value (in USD) of the tokens deposited /// for an account /// @param account Account to query /// @param token ERC20 token /// @return uint Value of token collateral of account in USD, scaled to 1e18 function realCollateralValueByToken( address account, IERC20 token ) external view returns(uint); /// @notice Get the unweighted current net value borrowed (i.e. borrows - lends) /// in USD summed across all `Market`s participated in by the user /// @param account Account to query /// @return uint Borrow value of account in USD, scaled to 1e18 function realBorrowValue(address account) external view returns(uint); /// @notice Get the unweighted current net value borrowed (i.e. borrows - lends) /// in USD for a particular `Market` /// @param account Account to query /// @param market `FixedRateMarket` contract /// @return uint Borrow value of account in USD, scaled to 1e18 function realBorrowValueByMarket( address account, IFixedRateMarket market ) external view returns(uint); /// @notice Get an account's maximum available borrow amount in a specific FixedRateMarket. /// For example, what is the maximum amount of GLMRJUL22 that an account can borrow /// while ensuring their account health continues to be acceptable? /// Note: This function will return 0 if market to borrow is disabled /// Note: This function will return creditLimit() if maximum amount allowed for one market exceeds creditLimit() /// Note: User can only borrow up to `initCollateralRatio` for their own protection against instant liquidations /// @param account User account /// @param borrowMarket Address of the `FixedRateMarket` market to borrow /// @return uint Maximum available amount user can borrow (in FV) without breaching `initCollateralRatio` function hypotheticalMaxBorrowFV(address account, IFixedRateMarket borrowMarket) external view returns(uint); /// @notice Get the minimum collateral ratio. Scaled by 1e8. /// @return uint Minimum collateral ratio function minCollateralRatio() external view returns(uint); /// @notice Get the minimum collateral ratio for a user account. Scaled by 1e8. /// @param account User account /// @return uint Minimum collateral ratio function minCollateralRatio(address account) external view returns(uint); /// @notice Get the initial collateral ratio. Scaled by 1e8 /// @return uint Initial collateral ratio function initCollateralRatio() external view returns(uint); /// @notice Get the initial collateral ratio for a user account. Scaled by 1e8 /// @param account User account /// @return uint Initial collateral ratio function initCollateralRatio(address account) external view returns(uint); /// @notice Get the close factor. Scaled by 1e8 /// @return uint Close factor function closeFactor() external view returns(uint); /// @notice Get the liquidation incentive. Scaled by 1e8 /// @return uint Liquidation incentive function liquidationIncentive() external view returns(uint); /// @notice Use this for quick lookups of collateral balances by asset /// @param account User account /// @param token ERC20 token /// @return uint Balance in local function collateralBalance(address account, IERC20 token) external view returns(uint); /// @notice Get iterable list of collateral addresses which an account has nonzero balance. /// @param account User account /// @return address[] Iterable list of ERC20 token addresses function iterableCollateralAddresses(address account) external view returns(IERC20[] memory); /// @notice Quick lookup of whether an account has a particular collateral /// @param account User account /// @param token ERC20 token addresses /// @return bool True if account has collateralized with given ERC20 token, false otherwise function accountCollateral(address account, IERC20 token) external view returns(bool); /// @notice Get iterable list of all Markets which an account has participated /// @param account User account /// @return address[] Iterable list of `FixedRateLoanMarket` contract addresses function iterableAccountMarkets(address account) external view returns(IFixedRateMarket[] memory); /// @notice Quick lookup of whether an account has participated in a Market /// @param account User account /// @param market`FixedRateLoanMarket` contract /// @return bool True if participated, false otherwise function accountMarkets(address account, IFixedRateMarket market) external view returns(bool); /// @notice Converts any local value into its value in USD using oracle feed price /// @param token ERC20 token /// @param amountLocal Amount denominated in terms of the ERC20 token /// @return uint Amount in USD, scaled to 1e18 function localToUSD(IERC20 token, uint amountLocal) external view returns(uint); /// @notice Converts any value in USD into its value in local using oracle feed price /// @param token ERC20 token /// @param valueUSD Amount in USD /// @return uint Amount denominated in terms of the ERC20 token function USDToLocal(IERC20 token, uint valueUSD) external view returns(uint); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./InterestRateModel.sol"; interface MTokenInterface is IERC20 { function accrualBlockTimestamp() external view returns(uint); function exchangeRateStored() external view returns(uint); function getCash() external view returns(uint); function totalBorrows() external view returns(uint); function totalReserves() external view returns(uint); function reserveFactorMantissa() external view returns(uint); function interestRateModel() external view returns(InterestRateModel); } interface MErc20Interface is MTokenInterface { function mint(uint mintAmount) external returns (uint); function redeem(uint redeemTokens) external returns (uint); function redeemUnderlying(uint redeemAmount) external returns (uint); function borrow(uint borrowAmount) external returns (uint); function repayBorrow(uint repayAmount) external returns (uint); function repayBorrowBehalf(address borrower, uint repayAmount) external returns (uint); function liquidateBorrow(address borrower, uint repayAmount, MTokenInterface mTokenCollateral) external returns (uint); } interface MGlimmerInterface is MTokenInterface { function mint() external payable; function redeem(uint redeemTokens) external returns (uint); function redeemUnderlying(uint redeemAmount) external returns (uint); function borrow(uint borrowAmount) external returns (uint); function repayBorrow() external payable; function repayBorrowBehalf(address borrower) external payable; function liquidateBorrow(address borrower, MTokenInterface mTokenCollateral) external payable; }
//SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; library QTypes { /// @notice Contains all the details of an Asset. Assets must be defined /// before they can be used as collateral. /// @member isEnabled True if an asset is defined, false otherwise /// @member isYieldBearing True if token bears interest (eg aToken, cToken, mToken, etc) /// @member underlying Address of the underlying token /// @member oracleFeed Address of the corresponding chainlink oracle feed /// @member collateralFactor 0.0 to 1.0 (scaled to 1e8) for discounting risky assets /// @member marketFactor 0.0 1.0 for premium on risky borrows /// @member maturities Iterable storage for all enabled maturities struct Asset { bool isEnabled; bool isYieldBearing; address underlying; address oracleFeed; uint collateralFactor; uint marketFactor; uint[] maturities; } /// @notice Contains all the fields of a published Quote /// @notice quoteId ID of the quote - this is the keccak256 hash of signature /// @param marketAddress Address of `FixedRateLoanMarket` contract /// @param quoter Account of the Quoter /// @param quoteType 0 for PV+APR, 1 for FV+APR /// @param side 0 if Quoter is borrowing, 1 if Quoter is lending /// @param quoteExpiryTime Timestamp after which the quote is no longer valid /// @param APR In decimal form scaled by 1e4 (ex. 10.52% = 1052) /// @param cashflow Can be PV or FV depending on `quoteType` /// @param nonce For uniqueness of signature /// @param signature Signed hash of the Quote message struct Quote { bytes32 quoteId; address marketAddress; address quoter; uint8 quoteType; uint8 side; uint64 quoteExpiryTime; //if 0, then quote never expires uint64 APR; uint cashflow; uint nonce; bytes signature; } /// @notice Contains all the configurations customizable to an address /// @member enabled If config for an address is enabled. When enabled is false, credit limit is infinite even if value is 0 /// @member minCollateralRatio If collateral ratio falls below `_minCollateralRatio`, it is subject to liquidation. Scaled by 1e8 /// @member initCollateralRatio When initially taking a loan, collateral ratio must be higher than this. `initCollateralRatio` should always be higher than `minCollateralRatio`. Scaled by 1e8 /// @member creditLimit Allowed limit in virtual USD for each address to do uncollateralized borrow, scaled by 1e18 struct CreditFacility { bool enabled; uint minCollateralRatio; uint initCollateralRatio; uint creditLimit; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT // 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 IERC20Upgradeable { /** * @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 "../IERC20Upgradeable.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20MetadataUpgradeable is IERC20Upgradeable { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @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: UNLICENSED pragma solidity ^0.8.9; interface InterestRateModel { /** * @notice Calculates the current borrow interest rate per timestmp * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amount of reserves the market has * @return The borrow rate per timestmp (as a percentage, and scaled by 1e18) */ function getBorrowRate(uint cash, uint borrows, uint reserves) external view returns (uint); /** * @notice Calculates the current supply interest rate per timestmp * @param cash The total amount of cash the market has * @param borrows The total amount of borrows the market has outstanding * @param reserves The total amount of reserves the market has * @param reserveFactorMantissa The current reserve factor the market has * @return The supply rate per timestmp (as a percentage, and scaled by 1e18) */ function getSupplyRate(uint cash, uint borrows, uint reserves, uint reserveFactorMantissa) external view returns (uint); }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"market","type":"address"}],"name":"AddAccountMarket","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DepositCollateral","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TransferCollateral","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawCollateral","type":"event"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"valueUSD","type":"uint256"}],"name":"USDToLocal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IFixedRateMarket","name":"market","type":"address"}],"name":"_addAccountMarket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"_transferCollateral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"accountCollateral","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IFixedRateMarket","name":"market","type":"address"}],"name":"accountMarkets","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allAssets","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"closeFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"collateralBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"collateralFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"collateralRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"underlying","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositCollateralWithMTokenWrap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20","name":"hypotheticalToken","type":"address"},{"internalType":"uint256","name":"withdrawAmount","type":"uint256"},{"internalType":"uint256","name":"depositAmount","type":"uint256"},{"internalType":"contract IFixedRateMarket","name":"hypotheticalMarket","type":"address"},{"internalType":"uint256","name":"borrowAmount","type":"uint256"},{"internalType":"uint256","name":"lendAmount","type":"uint256"}],"name":"hypotheticalCollateralRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IFixedRateMarket","name":"borrowMarket","type":"address"}],"name":"hypotheticalMaxBorrowFV","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IFixedRateMarket","name":"hypotheticalMarket","type":"address"},{"internalType":"uint256","name":"borrowAmount","type":"uint256"},{"internalType":"uint256","name":"lendAmount","type":"uint256"}],"name":"hypotheticalVirtualBorrowValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"initCollateralRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initCollateralRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"qAdminAddress_","type":"address"},{"internalType":"address","name":"qPriceOracleAddress_","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"iterableAccountMarkets","outputs":[{"internalType":"contract IFixedRateMarket[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"iterableCollateralAddresses","outputs":[{"internalType":"contract IERC20[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liquidationIncentive","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amountLocal","type":"uint256"}],"name":"localToUSD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"marketFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"minCollateralRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minCollateralRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"qAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"qPriceOracle","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"realBorrowValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IFixedRateMarket","name":"market","type":"address"}],"name":"realBorrowValueByMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"realCollateralValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"realCollateralValueByToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"virtualBorrowValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IFixedRateMarket","name":"market","type":"address"}],"name":"virtualBorrowValueByMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"virtualCollateralValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"virtualCollateralValueByToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"mTokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawCollateralWithMTokenUnwrap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
608060405234801561001057600080fd5b50613932806100206000396000f3fe60806040526004361061021d5760003560e01c80637620647711610123578063a5d5db0c116100ab578063ce4013081161006f578063ce4013081461065f578063d820971a14610683578063e7602b9d146106a3578063f617bb84146106e9578063fbcc6f5e1461070957600080fd5b8063a5d5db0c146105ca578063b8f3ece1146105ea578063bfeabd0d146105ff578063c4c050f61461061f578063ca40742c1461063f57600080fd5b806384da2666116100f257806384da26661461052e5780638c765e94146105435780639c4d1ff7146105585780639ec321dc14610578578063a0ee95601461059857600080fd5b806376206477146104b957806376d708d7146104d95780637dee6c47146104ee5780637e26c7951461050e57600080fd5b80633b51cf0c116101a657806363c63d371161017557806363c63d3714610419578063643b67481461043957806365abacad146104595780636a6af3521461047957806375adbdab1461049957600080fd5b80633b51cf0c1461038a578063485cc955146103b757806352a494eb146103d95780636014e635146103f957600080fd5b8063257041f3116101ed578063257041f3146102c15780632a722581146102e1578063320cc768146103015780633416a91e1461034a578063350c35e91461036a57600080fd5b806225ce9f1461022957806305308b9f1461025e578063072557e2146102815780631de88a3d146102a157600080fd5b3661022457005b600080fd5b34801561023557600080fd5b50610249610244366004613316565b610729565b60405190151581526020015b60405180910390f35b34801561026a57600080fd5b50610273610759565b604051908152602001610255565b34801561028d57600080fd5b5061027361029c36600461334f565b6107d6565b3480156102ad57600080fd5b506102736102bc36600461336c565b61084d565b3480156102cd57600080fd5b506102736102dc366004613398565b610861565b3480156102ed57600080fd5b506102736102fc36600461336c565b610880565b34801561030d57600080fd5b5061024961031c366004613316565b6001600160a01b03918216600090815260066020908152604080832093909416825291909152205460ff1690565b34801561035657600080fd5b50610273610365366004613316565b6108f4565b34801561037657600080fd5b5061027361038536600461336c565b610905565b34801561039657600080fd5b506103aa6103a536600461334f565b610912565b6040516102559190613409565b3480156103c357600080fd5b506103d76103d2366004613316565b610988565b005b3480156103e557600080fd5b506103d76103f4366004613456565b610ad9565b34801561040557600080fd5b506102736104143660046134a7565b610cf3565b34801561042557600080fd5b50610273610434366004613316565b610d0c565b34801561044557600080fd5b50610273610454366004613316565b610d1d565b34801561046557600080fd5b5061027361047436600461334f565b61116b565b34801561048557600080fd5b5061027361049436600461334f565b61117d565b3480156104a557600080fd5b506102736104b4366004613316565b61118e565b3480156104c557600080fd5b506102736104d436600461334f565b61119f565b3480156104e557600080fd5b506103aa6111d9565b3480156104fa57600080fd5b5061027361050936600461336c565b611256565b34801561051a57600080fd5b50610273610529366004613316565b611289565b34801561053a57600080fd5b5061027361129a565b34801561054f57600080fd5b506102736112e9565b34801561056457600080fd5b5061027361057336600461334f565b61133d565b34801561058457600080fd5b5061027361059336600461334f565b611377565b3480156105a457600080fd5b506001546001600160a01b03165b6040516001600160a01b039091168152602001610255565b3480156105d657600080fd5b506102736105e536600461336c565b611389565b3480156105f657600080fd5b50610273611396565b34801561060b57600080fd5b5061027361061a36600461334f565b6113cc565b34801561062b57600080fd5b506103aa61063a36600461334f565b6113dd565b34801561064b57600080fd5b5061027361065a36600461334f565b611451565b34801561066b57600080fd5b506000546201000090046001600160a01b03166105b2565b34801561068f57600080fd5b5061027361069e36600461336c565b611465565b3480156106af57600080fd5b506102736106be366004613316565b6001600160a01b03918216600090815260026020908152604080832093909416825291909152205490565b3480156106f557600080fd5b506103d7610704366004613316565b611472565b34801561071557600080fd5b5061027361072436600461334f565b61165f565b6001600160a01b0380831660009081526005602090815260408083209385168352929052205460ff165b92915050565b60008060029054906101000a90046001600160a01b03166001600160a01b03166305308b9f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107d191906134ed565b905090565b60008054604051630392abf160e11b81526001600160a01b038481166004830152620100009092049091169063072557e2906024015b602060405180830381865afa158015610829573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061075391906134ed565b600061085a338484611699565b9392505050565b600061087288888888888888611b6f565b90505b979650505050505050565b600154604051632a72258160e01b81526000916001600160a01b031690632a722581906108b39086908690600401613506565b602060405180830381865afa1580156108d0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061085a91906134ed565b600061085a83836000806001611ca5565b600061085a338484611fc2565b6001600160a01b03811660009081526003602090815260409182902080548351818402810184019094528084526060939283018282801561097c57602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161095e575b50505050509050919050565b600054610100900460ff16158080156109a85750600054600160ff909116105b806109c25750303b1580156109c2575060005460ff166001145b610a2a5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084015b60405180910390fd5b6000805460ff191660011790558015610a4d576000805461ff0019166101001790555b6000805462010000600160b01b031916620100006001600160a01b038681169190910291909117909155600180546001600160a01b0319169184169190911790558015610ad4576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050565b60005460408051633e27ec9b60e01b81529051620100009092046001600160a01b0316916391d14854918391633e27ec9b916004808201926020929091908290030181865afa158015610b30573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b5491906134ed565b6040516001600160e01b031960e084901b1681526004810191909152336024820152604401602060405180830381865afa158015610b96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bba9190613534565b610bf85760405162461bcd60e51b815260206004820152600f60248201526e14534c481bdb9b1e481b585c9ad95d608a1b6044820152606401610a21565b6001600160a01b03808416600090815260026020908152604080832093881683529290522054811115610c775760405162461bcd60e51b815260206004820152602160248201527f514d32206e6f7420656e6f75676820636f6c6c61746572616c2062616c616e636044820152606560f81b6064820152608401610a21565b610c8283858361217d565b610c966001600160a01b0385168383612233565b816001600160a01b0316836001600160a01b0316856001600160a01b03167f29db89d45e1a802b4d55e202984fce9faf1d30aedf86503ff1ea0ed9ebb6420184604051610ce591815260200190565b60405180910390a450505050565b6000610d03858585856001612289565b95945050505050565b600061085a83836000806000612450565b600080826001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d82919061354f565b60008054604051631e23703160e31b81526001600160a01b038085166004830152939450919262010000909104169063f11b818890602401600060405180830381865afa158015610dd7573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610dff9190810190613676565b90506000610e0c86611451565b60008054604051639c4d1ff760e01b81526001600160a01b038a811660048301529394509192620100009091041690639c4d1ff790602401602060405180830381865afa158015610e61573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e8591906134ed565b9050808211610e9b576000945050505050610753565b600080546040516301f429f560e41b81526001600160a01b038a811660048301526201000090920490911690631f429f5090602401602060405180830381865afa158015610eed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f1191906134ed565b90506000610f1e89611377565b90506000610f2b8a61116b565b905060008185600060029054906101000a90046001600160a01b03166001600160a01b0316638b2f81d66040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f84573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fa891906134ed565b610fb29086613751565b610fbc9190613770565b610fc69190613792565b905083811115610fd35750825b60008060029054906101000a90046001600160a01b03166001600160a01b031663de01c9cb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611027573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061104b91906134ed565b60a089015161105a9084613751565b6110649190613770565b600154604051632a72258160e01b81529192506000916001600160a01b0390911690632a7225819061109c908d908690600401613506565b602060405180830381865afa1580156110b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110dd91906134ed565b6040516370a0823160e01b81526001600160a01b038f811660048301529192506000918e16906370a0823190602401602060405180830381865afa158015611129573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114d91906134ed565b905061115981836137a9565b9e9d5050505050505050505050505050565b60006107538260008060006001612289565b600061075382600080600080612289565b600061085a83836000806001612450565b60008054604051637620647760e01b81526001600160a01b038481166004830152620100009092049091169063762064779060240161080c565b6060600060029054906101000a90046001600160a01b03166001600160a01b03166376d708d76040518163ffffffff1660e01b8152600401600060405180830381865afa15801561122e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526107d191908101906137c1565b600154604051637dee6c4760e01b81526000916001600160a01b031690637dee6c47906108b39086908690600401613506565b600061085a83836000806000611ca5565b60008054604051630392abf160e11b8152336004820152620100009091046001600160a01b03169063072557e2906024015b602060405180830381865afa1580156107ad573d6000803e3d6000fd5b60008060029054906101000a90046001600160a01b03166001600160a01b0316638c765e946040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107ad573d6000803e3d6000fd5b60008054604051639c4d1ff760e01b81526001600160a01b0384811660048301526201000090920490911690639c4d1ff79060240161080c565b600061075382600080600060016126af565b600061085a33848461286e565b60008054604051639c4d1ff760e01b8152336004820152620100009091046001600160a01b031690639c4d1ff7906024016112cc565b6000610753826000806000806126af565b6001600160a01b03811660009081526004602090815260409182902080548351818402810184019094528084526060939283018282801561097c576020028201919060005260206000209081546001600160a01b0316815260019091019060200180831161095e5750505050509050919050565b600061075382600080600080600080611b6f565b600061085a3384846129a8565b60005460408051633e27ec9b60e01b81529051620100009092046001600160a01b0316916391d14854918391633e27ec9b916004808201926020929091908290030181865afa1580156114c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114ed91906134ed565b6040516001600160e01b031960e084901b1681526004810191909152336024820152604401602060405180830381865afa15801561152f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115539190613534565b6115915760405162461bcd60e51b815260206004820152600f60248201526e14534c481bdb9b1e481b585c9ad95d608a1b6044820152606401610a21565b6001600160a01b0380831660009081526006602090815260408083209385168352929052205460ff1661161b576001600160a01b038083166000818152600660209081526040808320948616808452948252808320805460ff1916600190811790915593835260048252822080549384018155825290200180546001600160a01b03191690911790555b806001600160a01b0316826001600160a01b03167f2c814b8b1df59b1bc4d0cc4be2f114e513254af06ca6a21a5a0784478c13a31760405160405180910390a35050565b60008054604051637de637af60e11b81526001600160a01b038481166004830152620100009092049091169063fbcc6f5e9060240161080c565b60008054604051630f9eed1b60e11b81526001600160a01b03858116600483015283926201000090041690631f3dda3690602401602060405180830381865afa1580156116ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061170e919061354f565b90506001600160a01b03811661175f5760405162461bcd60e51b815260206004820152601660248201527514534d0813551bdad95b881d5b9cdd5c1c1bdc9d195960521b6044820152606401610a21565b6040516370a0823160e01b81523060048201526000906001600160a01b038616906370a0823190602401602060405180830381865afa1580156117a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117ca91906134ed565b90506117e16001600160a01b038616873087612ea6565b6040516370a0823160e01b81523060048201526000906001600160a01b038716906370a0823190602401602060405180830381865afa158015611828573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061184c91906134ed565b9050600061185a8383613792565b60405163095ea7b360e01b81529091506001600160a01b0388169063095ea7b39061188b9087908590600401613506565b6020604051808303816000875af11580156118aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ce9190613534565b506001600160a01b0387166108021415611a64576040516370a0823160e01b815230600482015284906000906001600160a01b038316906370a0823190602401602060405180830381865afa15801561192b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061194f91906134ed565b9050816001600160a01b0316631249c58b846040518263ffffffff1660e01b81526004016000604051808303818588803b15801561198c57600080fd5b505af11580156119a0573d6000803e3d6000fd5b50506040516370a0823160e01b8152306004820152600093506001600160a01b03861692506370a0823191506024015b602060405180830381865afa1580156119ed573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a1191906134ed565b90506000611a1f8383613792565b9050611a2c8c8583612ee4565b5050506001600160a01b03808a16600090815260026020908152604080832094909316825292909252902054945061085a9350505050565b6040516370a0823160e01b815230600482015284906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015611aad573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ad191906134ed565b60405163140e25ad60e31b8152600481018590529091506001600160a01b0383169063a0712d68906024016020604051808303816000875af1158015611b1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b3f91906134ed565b506040516370a0823160e01b81523060048201526000906001600160a01b038416906370a08231906024016119d0565b600080611b808989898960016126af565b90506000611b928a8787876001612289565b905080611c1957600060029054906101000a90046001600160a01b03166001600160a01b031663782d2b536040518163ffffffff1660e01b8152600401602060405180830381865afa158015611bec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c1091906134ed565b92505050610875565b80600060029054906101000a90046001600160a01b03166001600160a01b0316638b2f81d66040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c6d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c9191906134ed565b611c9b9084613751565b611c109190613770565b604051636a0747a560e11b81526001600160a01b038681166004830152600091829186919088169063d40e8f4a90602401602060405180830381865afa158015611cf3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d1791906134ed565b611d2191906137a9565b6040516370a0823160e01b81526001600160a01b0389811660048301529192506000918691908916906370a0823190602401602060405180830381865afa158015611d70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d9491906134ed565b611d9e91906137a9565b9050818110611db257600092505050610d03565b6000611dbe8284613792565b90506000886001600160a01b0316632495a5996040518163ffffffff1660e01b8152600401602060405180830381865afa158015611e00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e24919061354f565b60008054604051631e23703160e31b81526001600160a01b038085166004830152939450919262010000909104169063f11b818890602401600060405180830381865afa158015611e79573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611ea19190810190613676565b600154604051637dee6c4760e01b81529192506000916001600160a01b0390911690637dee6c4790611ed99086908890600401613506565b602060405180830381865afa158015611ef6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f1a91906134ed565b90508715611fb5578160a00151600060029054906101000a90046001600160a01b03166001600160a01b031663de01c9cb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f9e91906134ed565b611fa89083613751565b611fb29190613770565b90505b9550610d03945050505050565b60008082116120135760405162461bcd60e51b815260206004820152601d60248201527f514d35207769746864726177206d75737420626520706f7369746976650000006044820152606401610a21565b6000612026858585600080600080611b6f565b600054604051639c4d1ff760e01b81526001600160a01b0388811660048301529293506201000090910490911690639c4d1ff790602401602060405180830381865afa15801561207a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061209e91906134ed565b8110156120ed5760405162461bcd60e51b815260206004820152601b60248201527f514d3620696e76616c696420776974686472617720616d6f756e7400000000006044820152606401610a21565b6120f885858561217d565b61210c6001600160a01b0385168685612233565b846001600160a01b03167f1607da8e9144035d8537941425741e9e3569c81d34a7f8e0c5c44635dc7169218585604051612147929190613506565b60405180910390a25050506001600160a01b03918216600090815260026020908152604080832093909416825291909152205490565b6001600160a01b038084166000908152600260209081526040808320938616835292905220548111156121f25760405162461bcd60e51b815260206004820152601960248201527f514d38206e6f7420656e6f75676820636f6c6c61746572616c000000000000006044820152606401610a21565b6001600160a01b03808416600090815260026020908152604080832093861683529290529081208054839290612229908490613792565b9091555050505050565b610ad48363a9059cbb60e01b8484604051602401612252929190613506565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526130bb565b6000805460405163bc9574ad60e01b81526001600160a01b03878116600483015283928392620100009091049091169063bc9574ad90602401602060405180830381865afa1580156122df573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123039190613534565b801561233557506001600160a01b038089166000908152600660209081526040808320938b168352929052205460ff16155b612340576000612343565b60015b60ff16905060005b6001600160a01b03891660009081526004602052604090205461236f9083906137a9565b811015612443576001600160a01b038916600090815260046020526040812054821061239b57886123db565b6001600160a01b038a1660009081526004602052604090208054839081106123c5576123c5613850565b6000918252602090912001546001600160a01b03165b9050886001600160a01b0316816001600160a01b03161415612415576124048a8a8a8a8a611ca5565b61240e90856137a9565b9350612430565b6124238a826000808a611ca5565b61242d90856137a9565b93505b508061243b81613866565b91505061234b565b5090979650505050505050565b6001600160a01b0380861660009081526002602090815260408083209388168352929052908120548411156124c75760405162461bcd60e51b815260206004820152601960248201527f514d33207769746864726177203e20636f6c6c61746572616c000000000000006044820152606401610a21565b60008054604051631e23703160e31b81526001600160a01b038881166004830152620100009092049091169063f11b818890602401600060405180830381865afa158015612519573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526125419190810190613676565b8051909150612554576000915050610d03565b6001600160a01b038088166000908152600260209081526040808320938a16835292905220548561258586836137a9565b61258f9190613792565b600154604051637dee6c4760e01b81529192506000916001600160a01b0390911690637dee6c47906125c7908b908690600401613506565b602060405180830381865afa1580156125e4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061260891906134ed565b905084156126a357600060029054906101000a90046001600160a01b03166001600160a01b031663de01c9cb6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612663573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061268791906134ed565b60808401516126969083613751565b6126a09190613770565b90505b98975050505050505050565b60008054604051631e23703160e31b81526001600160a01b03878116600483015283928392620100009091049091169063f11b818890602401600060405180830381865afa158015612705573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261272d9190810190613676565b51801561276057506001600160a01b038089166000908152600560209081526040808320938b168352929052205460ff16155b61276b57600061276e565b60015b60ff16905060005b6001600160a01b03891660009081526003602052604090205461279a9083906137a9565b811015612443576001600160a01b03891660009081526003602052604081205482106127c65788612806565b6001600160a01b038a1660009081526003602052604090208054839081106127f0576127f0613850565b6000918252602090912001546001600160a01b03165b9050886001600160a01b0316816001600160a01b031614156128405761282f8a8a8a8a8a612450565b61283990856137a9565b935061285b565b61284e8a826000808a612450565b61285890856137a9565b93505b508061286681613866565b915050612776565b6040516370a0823160e01b815230600482015260009081906001600160a01b038516906370a0823190602401602060405180830381865afa1580156128b7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128db91906134ed565b90506128f26001600160a01b038516863086612ea6565b6040516370a0823160e01b81523060048201526000906001600160a01b038616906370a0823190602401602060405180830381865afa158015612939573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061295d91906134ed565b9050600061296b8383613792565b9050612978878783612ee4565b505050506001600160a01b0392831660009081526002602090815260408083209490951682529290925250205490565b60008054604051631e23703160e31b81526001600160a01b0385811660048301528392620100009004169063f11b818890602401600060405180830381865afa1580156129f9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a219190810190613676565b604001519050806001600160a01b0381166108021415612c5b576040516370a0823160e01b815230600482015285906000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612a84573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612aa891906134ed565b60405163db006a7560e01b8152600481018890529091506001600160a01b0383169063db006a75906024016020604051808303816000875af1158015612af2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b1691906134ed565b506040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015612b5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b8291906134ed565b90506000612b908383613792565b9050612b9d8a858a61217d565b60405163a9059cbb60e01b81526001600160a01b0386169063a9059cbb90612bcb908d908590600401613506565b6020604051808303816000875af1158015612bea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c0e9190613534565b50896001600160a01b03167f1607da8e9144035d8537941425741e9e3569c81d34a7f8e0c5c44635dc7169218a8a604051612c4a929190613506565b60405180910390a250505050612e77565b6040516370a0823160e01b815230600482015285906000906001600160a01b038416906370a0823190602401602060405180830381865afa158015612ca4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cc891906134ed565b60405163db006a7560e01b8152600481018890529091506001600160a01b0383169063db006a75906024016020604051808303816000875af1158015612d12573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d3691906134ed565b506040516370a0823160e01b81523060048201526000906001600160a01b038516906370a0823190602401602060405180830381865afa158015612d7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612da291906134ed565b90506000612db08383613792565b9050612dbd8a858a61217d565b60405163a9059cbb60e01b81526001600160a01b0386169063a9059cbb90612deb908d908590600401613506565b6020604051808303816000875af1158015612e0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e2e9190613534565b50896001600160a01b03167f1607da8e9144035d8537941425741e9e3569c81d34a7f8e0c5c44635dc7169218a8a604051612e6a929190613506565b60405180910390a2505050505b505050506001600160a01b03918216600090815260026020908152604080832093909416825291909152205490565b6040516001600160a01b0380851660248301528316604482015260648101829052612ede9085906323b872dd60e01b90608401612252565b50505050565b60008054604051631e23703160e31b81526001600160a01b038581166004830152620100009092049091169063f11b818890602401600060405180830381865afa158015612f36573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612f5e9190810190613676565b8051909150612fa75760405162461bcd60e51b815260206004820152601560248201527414534dc8185cdcd95d081d5b9cdd5c1c1bdc9d1959605a1b6044820152606401610a21565b6001600160a01b0380851660009081526005602090815260408083209387168352929052205460ff16613034576001600160a01b0384811660008181526003602090815260408083208054600180820183559185528385200180546001600160a01b031916968a1696871790559383526005825280832094835293905291909120805460ff191690911790555b6001600160a01b0380851660009081526002602090815260408083209387168352929052908120805484929061306b9084906137a9565b92505081905550836001600160a01b03167fef12f18e2b6578b91b3c852c423ca8ee530f65f20f770e62a7ce8aa08e1ab77784846040516130ad929190613506565b60405180910390a250505050565b6000613110826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661318d9092919063ffffffff16565b805190915015610ad4578080602001905181019061312e9190613534565b610ad45760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a21565b606061319c84846000856131a4565b949350505050565b6060824710156132055760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610a21565b6001600160a01b0385163b61325c5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a21565b600080866001600160a01b0316858760405161327891906138ad565b60006040518083038185875af1925050503d80600081146132b5576040519150601f19603f3d011682016040523d82523d6000602084013e6132ba565b606091505b5091509150610875828286606083156132d457508161085a565b8251156132e45782518084602001fd5b8160405162461bcd60e51b8152600401610a2191906138c9565b6001600160a01b038116811461331357600080fd5b50565b6000806040838503121561332957600080fd5b8235613334816132fe565b91506020830135613344816132fe565b809150509250929050565b60006020828403121561336157600080fd5b813561085a816132fe565b6000806040838503121561337f57600080fd5b823561338a816132fe565b946020939093013593505050565b600080600080600080600060e0888a0312156133b357600080fd5b87356133be816132fe565b965060208801356133ce816132fe565b9550604088013594506060880135935060808801356133ec816132fe565b9699959850939692959460a0840135945060c09093013592915050565b6020808252825182820181905260009190848201906040850190845b8181101561344a5783516001600160a01b031683529284019291840191600101613425565b50909695505050505050565b6000806000806080858703121561346c57600080fd5b8435613477816132fe565b93506020850135613487816132fe565b92506040850135613497816132fe565b9396929550929360600135925050565b600080600080608085870312156134bd57600080fd5b84356134c8816132fe565b935060208501356134d8816132fe565b93969395505050506040820135916060013590565b6000602082840312156134ff57600080fd5b5051919050565b6001600160a01b03929092168252602082015260400190565b8051801515811461352f57600080fd5b919050565b60006020828403121561354657600080fd5b61085a8261351f565b60006020828403121561356157600080fd5b815161085a816132fe565b634e487b7160e01b600052604160045260246000fd5b60405160e0810167ffffffffffffffff811182821017156135a5576135a561356c565b60405290565b604051601f8201601f1916810167ffffffffffffffff811182821017156135d4576135d461356c565b604052919050565b805161352f816132fe565b600067ffffffffffffffff8211156136015761360161356c565b5060051b60200190565b600082601f83011261361c57600080fd5b8151602061363161362c836135e7565b6135ab565b82815260059290921b8401810191818101908684111561365057600080fd5b8286015b8481101561366b5780518352918301918301613654565b509695505050505050565b60006020828403121561368857600080fd5b815167ffffffffffffffff808211156136a057600080fd5b9083019060e082860312156136b457600080fd5b6136bc613582565b6136c58361351f565b81526136d36020840161351f565b60208201526136e4604084016135dc565b60408201526136f5606084016135dc565b60608201526080830151608082015260a083015160a082015260c08301518281111561372057600080fd5b61372c8782860161360b565b60c08301525095945050505050565b634e487b7160e01b600052601160045260246000fd5b600081600019048311821515161561376b5761376b61373b565b500290565b60008261378d57634e487b7160e01b600052601260045260246000fd5b500490565b6000828210156137a4576137a461373b565b500390565b600082198211156137bc576137bc61373b565b500190565b600060208083850312156137d457600080fd5b825167ffffffffffffffff8111156137eb57600080fd5b8301601f810185136137fc57600080fd5b805161380a61362c826135e7565b81815260059190911b8201830190838101908783111561382957600080fd5b928401925b82841015610875578351613841816132fe565b8252928401929084019061382e565b634e487b7160e01b600052603260045260246000fd5b600060001982141561387a5761387a61373b565b5060010190565b60005b8381101561389c578181015183820152602001613884565b83811115612ede5750506000910152565b600082516138bf818460208701613881565b9190910192915050565b60208152600082518060208401526138e8816040850160208701613881565b601f01601f1916919091016040019291505056fea2646970667358221220467c0e775f1c41392d2265845631d01b3ba0bdd964963a2f9131b671a48df7c464736f6c634300080a0033
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|