Operator
Inherits: OperatorStorage, ImTokenOperationTypes, OwnableUpgradeable
Note: oz-upgrades-unsafe-allow: constructor
constructor();
function initialize(address _rolesOperator, address _rewardDistributor, address _admin) public initializer;
modifier onlyAllowedUser(address user);
Sets user whitelist status
function setWhitelistedUser(address user, bool state) external onlyOwner;
Parameters
user
address
The user address
state
bool
The new staate
Enable user whitelist
function enableWhitelist() external onlyOwner;
Disable user whitelist
function disableWhitelist() external onlyOwner;
Sets a new Operator for the market
Admin function to set a new operator
function setRolesOperator(address _roles) external onlyOwner;
Sets a new price oracle
Admin function to set a new price oracle
function setPriceOracle(address newOracle) external onlyOwner;
Sets the closeFactor used when liquidating borrows
Admin function to set closeFactor
function setCloseFactor(uint256 newCloseFactorMantissa) external onlyOwner;
Parameters
newCloseFactorMantissa
uint256
New close factor, scaled by 1e18
Sets the collateralFactor for a market
Admin function to set per-market collateralFactor
function setCollateralFactor(address mToken, uint256 newCollateralFactorMantissa) external onlyOwner;
Parameters
mToken
address
The market to set the factor on
newCollateralFactorMantissa
uint256
The new collateral factor, scaled by 1e18
Sets liquidationIncentive
Admin function to set liquidationIncentive
function setLiquidationIncentive(address market, uint256 newLiquidationIncentiveMantissa) external onlyOwner;
Parameters
market
address
newLiquidationIncentiveMantissa
uint256
New liquidationIncentive scaled by 1e18
Add the market to the markets mapping and set it as listed
Admin function to set isListed and add support for the market
function supportMarket(address mToken) external onlyOwner;
Parameters
mToken
address
The address of the market (token) to list
Sets outflow volume time window
function setOutflowVolumeTimeWindow(uint256 newTimeWindow) external onlyOwner;
Parameters
newTimeWindow
uint256
The new reset time window
Sets outflow volume limit
when 0, it means there's no limit
function setOutflowTimeLimitInUSD(uint256 amount) external onlyOwner;
Parameters
amount
uint256
The new limit
Resets outflow volume
function resetOutflowVolume() external onlyOwner;
Verifies outflow volule limit
function checkOutflowVolumeLimit(uint256 amount) external;
Parameters
amount
uint256
The new limit
Set the given borrow caps for the given mToken markets. Borrowing that brings total borrows to or above borrow cap will revert.
function setMarketBorrowCaps(address[] calldata mTokens, uint256[] calldata newBorrowCaps) external;
Parameters
mTokens
address[]
The addresses of the markets (tokens) to change the borrow caps for
newBorrowCaps
uint256[]
The new borrow cap values in underlying to be set. A value of 0 corresponds to unlimited borrowing.
Set the given supply caps for the given mToken markets. Supplying that brings total supply to or above supply cap will revert.
function setMarketSupplyCaps(address[] calldata mTokens, uint256[] calldata newSupplyCaps) external;
Parameters
mTokens
address[]
The addresses of the markets (tokens) to change the supply caps for
newSupplyCaps
uint256[]
The new supply cap values in underlying to be set. A value of 0 corresponds to unlimited supplying.
Set pause for a specific operation
function setPaused(address mToken, ImTokenOperationTypes.OperationType _type, bool state) external;
Parameters
mToken
address
The market token address
_type
ImTokenOperationTypes.OperationType
The pause operation type
state
bool
The pause operation status
Admin function to change the Reward Distributor
function setRewardDistributor(address newRewardDistributor) external onlyOwner;
Parameters
newRewardDistributor
address
The address of the new Reward Distributor
Should return true
function isOperator() external pure override returns (bool);
Returns if operation is paused
function isPaused(address mToken, ImTokenOperationTypes.OperationType _type) external view override returns (bool);
Parameters
mToken
address
The mToken to check
_type
ImTokenOperationTypes.OperationType
the operation type
Returns the assets an account has entered
function getAssetsIn(address _user) external view override returns (address[] memory mTokens);
Parameters
_user
address
The address of the account to pull assets for
Returns
mTokens
address[]
A dynamic list with the assets the account has entered
Returns whether the given account is entered in the given asset
function checkMembership(address account, address mToken) external view returns (bool);
Parameters
account
address
The address of the account to check
mToken
address
The mToken to check
Returns
<none>
bool
True if the account is in the asset, otherwise false.
A list of all markets
function getAllMarkets() external view returns (address[] memory mTokens);
Returns true if the given mToken market has been deprecated
All borrows in a deprecated mToken market can be immediately liquidated
function isDeprecated(address mToken) external view override returns (bool);
Parameters
mToken
address
The market to check if deprecated
Returns true/false
function isMarketListed(address mToken) external view override returns (bool);
Determine the current account liquidity wrt collateral requirements
function getAccountLiquidity(address account) public view returns (uint256, uint256);
Returns
<none>
uint256
account liquidity in excess of collateral requirements, account shortfall below collateral requirements)
<none>
uint256
Determine what the account liquidity would be if the given amounts were redeemed/borrowed
function getHypotheticalAccountLiquidity(
address account,
address mTokenModify,
uint256 redeemTokens,
uint256 borrowAmount
) external view returns (uint256, uint256);
Parameters
account
address
The account to determine liquidity for
mTokenModify
address
The market to hypothetically redeem/borrow in
redeemTokens
uint256
The number of tokens to hypothetically redeem
borrowAmount
uint256
The amount of underlying to hypothetically borrow
Returns
<none>
uint256
hypothetical account liquidity in excess of collateral requirements, hypothetical account shortfall below collateral requirements)
<none>
uint256
Calculate number of tokens of collateral asset to seize given an underlying amount
Used in liquidation (called in mTokenBorrowed.liquidate)
function liquidateCalculateSeizeTokens(address mTokenBorrowed, address mTokenCollateral, uint256 actualRepayAmount)
external
view
returns (uint256);
Parameters
mTokenBorrowed
address
The address of the borrowed mToken
mTokenCollateral
address
The address of the collateral mToken
actualRepayAmount
uint256
The amount of mTokenBorrowed underlying to convert into mTokenCollateral tokens
Returns
<none>
uint256
number of mTokenCollateral tokens to be seized in a liquidation
Add assets to be included in account liquidity calculation
function enterMarkets(address[] calldata _mTokens) external override onlyAllowedUser(msg.sender);
Parameters
_mTokens
address[]
The list of addresses of the mToken markets to be enabled
Add asset (msg.sender) to be included in account liquidity calculation
function enterMarketsWithSender(address _account) external override onlyAllowedUser(_account);
Parameters
_account
address
The account to add for
Removes asset from sender's account liquidity calculation
Sender must not have an outstanding borrow balance in the asset, or be providing necessary collateral for an outstanding borrow.
function exitMarket(address _mToken) external override;
Parameters
_mToken
address
The address of the asset to be removed
Claim all the MALDA accrued by holder in all markets
function claimMalda(address holder) external override;
Parameters
holder
address
The address to claim MALDA for
Claim all the MALDA accrued by holder in the specified markets
function claimMalda(address holder, address[] memory mTokens) external override;
Parameters
holder
address
The address to claim MALDA for
mTokens
address[]
The list of markets to claim MALDA in
Claim all MALDA accrued by the holders
function claimMalda(address[] memory holders, address[] memory mTokens, bool borrowers, bool suppliers)
external
override;
Parameters
holders
address[]
The addresses to claim MALDA for
mTokens
address[]
The list of markets to claim MALDA in
borrowers
bool
Whether or not to claim MALDA earned by borrowing
suppliers
bool
Whether or not to claim MALDA earned by supplying
Returns USD value for all markets
function getUSDValueForAllMarkets() external view returns (uint256);
Checks whitelist status on withdrawOnExtension
function beforeWithdrawOnExtension(address user) external view onlyAllowedUser(user);
Parameters
user
address
The user to check
Checks whitelist status on borrowOnExtension
function beforeBorrowOnExtension(address user) external view onlyAllowedUser(user);
Parameters
user
address
The user to check
Checks if the account should be allowed to rebalance tokens
function beforeRebalancing(address mToken) external view override;
Parameters
mToken
address
The market to verify the transfer against
Checks if the account should be allowed to transfer tokens in the given market
function beforeMTokenTransfer(address mToken, address src, address dst, uint256 transferTokens) external override;
Parameters
mToken
address
The market to verify the transfer against
src
address
The account which sources the tokens
dst
address
The account which receives the tokens
transferTokens
uint256
The number of mTokens to transfer
Checks if the account should be allowed to mint tokens in the given market
function beforeMTokenMint(address mToken, address minter) external override onlyAllowedUser(minter);
Parameters
mToken
address
The market to verify the mint against
minter
address
The account which would get the minted tokens
Validates mint and reverts on rejection. May emit logs.
function afterMTokenMint(address mToken) external view override;
Parameters
mToken
address
Asset being minted
Checks if the account should be allowed to redeem tokens in the given market
function beforeMTokenRedeem(address mToken, address redeemer, uint256 redeemTokens)
external
override
onlyAllowedUser(redeemer);
Parameters
mToken
address
The market to verify the redeem against
redeemer
address
The account which would redeem the tokens
redeemTokens
uint256
The number of mTokens to exchange for the underlying asset in the market
Checks if the account should be allowed to borrow the underlying asset of the given market
function beforeMTokenBorrow(address mToken, address borrower, uint256 borrowAmount)
external
override
onlyAllowedUser(borrower);
Parameters
mToken
address
The market to verify the borrow against
borrower
address
The account which would borrow the asset
borrowAmount
uint256
The amount of underlying the account would borrow
Checks if the account should be allowed to repay a borrow in the given market
function beforeMTokenRepay(address mToken, address borrower) external onlyAllowedUser(borrower);
Parameters
mToken
address
The market to verify the repay against
borrower
address
The account which would borrowed the asset
Checks if the liquidation should be allowed to occur
function beforeMTokenLiquidate(address mTokenBorrowed, address mTokenCollateral, address borrower, uint256 repayAmount)
external
view
override
onlyAllowedUser(borrower);
Parameters
mTokenBorrowed
address
Asset which was borrowed by the borrower
mTokenCollateral
address
Asset which was used as collateral and will be seized
borrower
address
The address of the borrower
repayAmount
uint256
The amount of underlying being repaid
Checks if the seizing of assets should be allowed to occur
function beforeMTokenSeize(address mTokenCollateral, address mTokenBorrowed, address liquidator, address borrower)
external
override;
Parameters
mTokenCollateral
address
Asset which was used as collateral and will be seized
mTokenBorrowed
address
Asset which was borrowed by the borrower
liquidator
address
The address repaying the borrow and seizing the collateral
borrower
address
The address of the borrower
function _convertMarketAmountToUSDValue(uint256 amount, address mToken) internal view returns (uint256);
function _activateMarket(address _mToken, address borrower) private;
function _beforeRedeem(address mToken, address redeemer, uint256 redeemTokens) private view;
function _getHypotheticalAccountLiquidity(
address account,
address mTokenModify,
uint256 redeemTokens,
uint256 borrowAmount
) private view returns (uint256, uint256);
Notify reward distributor for supply index update
function _updateMaldaSupplyIndex(address mToken) private;
Parameters
mToken
address
The market whose supply index to update
Notify reward distributor for borrow index update
function _updateMaldaBorrowIndex(address mToken) private;
Parameters
mToken
address
The market whose borrow index to update
Notify reward distributor for supplier update
function _distributeSupplierMalda(address mToken, address supplier) private;
Parameters
mToken
address
The market in which the supplier is interacting
supplier
address
The address of the supplier to distribute MALDA to
Notify reward distributor for borrower update
Borrowers will not begin to accrue until after the first interaction with the protocol.
function _distributeBorrowerMalda(address mToken, address borrower) private;
Parameters
mToken
address
The market in which the borrower is interacting
borrower
address
The address of the borrower to distribute MALDA to
function _claim(address[] memory holders, address[] memory mTokens, bool borrowers, bool suppliers) private;
function _isDeprecated(address mToken) private view returns (bool);
Inherits: IOperator, IOperatorDefender, ExponentialNoError
Roles manager
IRoles public rolesOperator;
Oracle which gives the price of any given asset
address public oracleOperator;
Multiplier used to calculate the maximum repayAmount when liquidating a borrow
uint256 public closeFactorMantissa;
Multiplier representing the discount on collateral that a liquidator receives
mapping(address => uint256) public liquidationIncentiveMantissa;
Per-account mapping of "assets you are in", capped by maxAssets
mapping(address => address[]) public accountAssets;
Official mapping of mTokens -> Market metadata
Used e.g. to determine if a market is supported
mapping(address => IOperatorData.Market) public markets;
A list of all markets
address[] public allMarkets;
Borrow caps enforced by borrowAllowed for each mToken address. Defaults to zero which corresponds to unlimited borrowing.
mapping(address => uint256) public borrowCaps;
Supply caps enforced by supplyAllowed for each mToken address. Defaults to zero which corresponds to unlimited supplying.
mapping(address => uint256) public supplyCaps;
Reward Distributor to markets supply and borrow (including protocol token)
address public rewardDistributor;
Should return outflow limit
uint256 public limitPerTimePeriod;
Should return outflow volume
uint256 public cumulativeOutflowVolume;
Should return last reset time for outflow check
uint256 public lastOutflowResetTimestamp;
Should return the outflow volume time window
uint256 public outflowResetTimeWindow;
Returns true/false for user
mapping(address => bool) public userWhitelisted;
bool public whitelistEnabled;
mapping(address => mapping(ImTokenOperationTypes.OperationType => bool)) internal _paused;
uint256 internal constant CLOSE_FACTOR_MIN_MANTISSA = 0.05e18;
uint256 internal constant CLOSE_FACTOR_MAX_MANTISSA = 0.9e18;
uint256 internal constant COLLATERAL_FACTOR_MAX_MANTISSA = 0.9e18;
Emitted when user whitelist status is changed
event UserWhitelisted(address indexed user, bool state);
event WhitelistEnabled();
event WhitelistDisabled();
Emitted when pause status is changed
event ActionPaused(address indexed mToken, ImTokenOperationTypes.OperationType _type, bool state);
Emitted when reward distributor is changed
event NewRewardDistributor(address indexed oldRewardDistributor, address indexed newRewardDistributor);
Emitted when borrow cap for a mToken is changed
event NewBorrowCap(address indexed mToken, uint256 newBorrowCap);
Emitted when supply cap for a mToken is changed
event NewSupplyCap(address indexed mToken, uint256 newBorrowCap);
Emitted when an admin supports a market
event MarketListed(address mToken);
Emitted when an account enters a market
event MarketEntered(address indexed mToken, address indexed account);
Emitted when an account exits a market
event MarketExited(address indexed mToken, address indexed account);
Emitted Emitted when close factor is changed by admin
event NewCloseFactor(uint256 oldCloseFactorMantissa, uint256 newCloseFactorMantissa);
Emitted when a collateral factor is changed by admin
event NewCollateralFactor(
address indexed mToken, uint256 oldCollateralFactorMantissa, uint256 newCollateralFactorMantissa
);
Emitted when liquidation incentive is changed by admin
event NewLiquidationIncentive(
address market, uint256 oldLiquidationIncentiveMantissa, uint256 newLiquidationIncentiveMantissa
);
Emitted when price oracle is changed
event NewPriceOracle(address indexed oldPriceOracle, address indexed newPriceOracle);
Event emitted when rolesOperator is changed
event NewRolesOperator(address indexed oldRoles, address indexed newRoles);
Event emitted when outflow limit is updated
event OutflowLimitUpdated(address indexed sender, uint256 oldLimit, uint256 newLimit);
Event emitted when outflow reset time window is updated
event OutflowTimeWindowUpdated(uint256 oldWindow, uint256 newWindow);
Event emitted when outflow volume has been reset
event OutflowVolumeReset();
error Operator_Paused();
error Operator_Mismatch();
error Operator_OnlyAdmin();
error Operator_EmptyPrice();
error Operator_WrongMarket();
error Operator_InvalidInput();
error Operator_AssetNotFound();
error Operator_RepayingTooMuch();
error Operator_OnlyAdminOrRole();
error Operator_MarketNotListed();
error Operator_PriceFetchFailed();
error Operator_SenderMustBeToken();
error Operator_UserNotWhitelisted();
error Operator_MarketSupplyReached();
error Operator_RepayAmountNotValid();
error Operator_MarketAlreadyListed();
error Operator_OutflowVolumeReached();
error Operator_InvalidRolesOperator();
error Operator_InsufficientLiquidity();
error Operator_MarketBorrowCapReached();
error Operator_InvalidCollateralFactor();
error Operator_InvalidRewardDistributor();
error Operator_OracleUnderlyingFetchError();
error Operator_Deactivate_MarketBalanceOwed();
Local vars for avoiding stack-depth limits in calculating account liquidity. Note that mTokenBalance
is the number of mTokens the account owns in the market, whereas borrowBalance
is the amount of underlying that the account has borrowed.
struct AccountLiquidityLocalVars {
uint256 sumCollateral;
uint256 sumBorrowPlusEffects;
uint256 mTokenBalance;
uint256 borrowBalance;
uint256 exchangeRateMantissa;
uint256 oraclePriceMantissa;
Exp collateralFactor;
Exp exchangeRate;
Exp oraclePrice;
Exp tokensToDenom;
}
Last updated