Operator

Git Source

Inherits: OperatorStorage, ImTokenOperationTypes, OwnableUpgradeable, HypernativeFirewallProtected

Title: Operator core controller

Author: Merge Layers Inc.

Access-controlled operator logic for mTokens

Functions

onlyAllowedUser

Modifier to restrict access to allowed users only

modifier onlyAllowedUser(address user) ;

Parameters

NameTypeDescription
useraddressThe user address to check

ifNotBlacklisted

Modifier to check if user is not blacklisted

modifier ifNotBlacklisted(address user) ;

Parameters

NameTypeDescription
useraddressThe user address to check

constructor

Disables initializers for implementation contract

Note: oz-upgrades-unsafe-allow: constructor

constructor() ;

initFirewall

Initializes the firewall

function initFirewall(address _firewall) external onlyOwner;

Parameters

NameTypeDescription
_firewalladdressThe firewall address

setBlacklister

Sets the blacklist operator

function setBlacklister(address _blacklister) external onlyOwner;

Parameters

NameTypeDescription
_blacklisteraddressThe blacklist operator address

setBorrowSizeMin

Sets min borrow size per market

function setBorrowSizeMin(address[] calldata mTokens, uint256[] calldata amounts) external onlyOwner;

Parameters

NameTypeDescription
mTokensaddress[]The market address
amountsuint256[]The new size

setWhitelistedUser

Sets user whitelist status

function setWhitelistedUser(address user, bool state) external onlyOwner;

Parameters

NameTypeDescription
useraddressThe user address
stateboolThe new state

setWhitelistStatus

Sets the whitelist status

function setWhitelistStatus(bool status) external onlyOwner;

Parameters

NameTypeDescription
statusboolThe new status

setRolesOperator

Sets a new Operator for the market

function setRolesOperator(address _roles) external onlyOwner;

Parameters

NameTypeDescription
_rolesaddressThe new operator address

setPriceOracle

Sets a new price oracle

Admin function to set a new price oracle

function setPriceOracle(address newOracle) external onlyOwner;

Parameters

NameTypeDescription
newOracleaddressAddress of the new oracle

setCloseFactor

Sets the closeFactor used when liquidating borrows

Admin function to set closeFactor

function setCloseFactor(uint256 newCloseFactorMantissa) external onlyOwner;

Parameters

NameTypeDescription
newCloseFactorMantissauint256New close factor, scaled by 1e18

setCollateralFactor

Sets the collateralFactor for a market

Admin function to set per-market collateralFactor

function setCollateralFactor(address mToken, uint256 newCollateralFactorMantissa) external onlyOwner;

Parameters

NameTypeDescription
mTokenaddressThe market to set the factor on
newCollateralFactorMantissauint256The new collateral factor, scaled by 1e18

setLiquidationIncentive

Sets liquidationIncentive

Admin function to set liquidationIncentive

function setLiquidationIncentive(address market, uint256 newLiquidationIncentiveMantissa) external onlyOwner;

Parameters

NameTypeDescription
marketaddressMarket address
newLiquidationIncentiveMantissauint256New liquidationIncentive scaled by 1e18

supportMarket

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

NameTypeDescription
mTokenaddressThe address of the market (token) to list

setOutflowVolumeTimeWindow

Sets outflow volume time window

function setOutflowVolumeTimeWindow(uint256 newTimeWindow) external onlyOwner;

Parameters

NameTypeDescription
newTimeWindowuint256The new reset time window

setOutflowTimeLimitInUSD

Sets outflow volume limit

when 0, it means there's no limit

function setOutflowTimeLimitInUSD(uint256 amount) external onlyOwner;

Parameters

NameTypeDescription
amountuint256The new limit

resetOutflowVolume

Resets outflow volume

function resetOutflowVolume() external onlyOwner;

checkOutflowVolumeLimit

Verifies outflow volume limit

function checkOutflowVolumeLimit(uint256 amount) external;

Parameters

NameTypeDescription
amountuint256The amount to check

setMarketBorrowCaps

Set borrow caps for given mToken markets.

Borrowing that brings total borrows to or above borrow cap will revert. A value of 0 corresponds to unlimited borrowing.

function setMarketBorrowCaps(address[] calldata mTokens, uint256[] calldata newBorrowCaps)
    external
    onlyFirewallApproved;

Parameters

NameTypeDescription
mTokensaddress[]The addresses of the markets (tokens) to change the borrow caps for
newBorrowCapsuint256[]The new borrow cap values in underlying to be set.

setMarketSupplyCaps

Set supply caps for the given mToken markets.

Supplying that brings total supply to or above supply cap will revert. A value of 0 corresponds to unlimited supplying.

function setMarketSupplyCaps(address[] calldata mTokens, uint256[] calldata newSupplyCaps)
    external
    onlyFirewallApproved;

Parameters

NameTypeDescription
mTokensaddress[]The addresses of the markets (tokens) to change the supply caps for
newSupplyCapsuint256[]The new supply cap values in underlying to be set.

setPaused

Set pause for a specific operation

function setPaused(address mToken, ImTokenOperationTypes.OperationType _type, bool state)
    external
    onlyFirewallApproved;

Parameters

NameTypeDescription
mTokenaddressThe market token address
_typeImTokenOperationTypes.OperationTypeThe pause operation type
stateboolThe pause operation status

initialize

Initialize the contract

function initialize(address _rolesOperator, address _blacklistOperator, address _admin) external initializer;

Parameters

NameTypeDescription
_rolesOperatoraddressThe roles operator address
_blacklistOperatoraddressThe blacklist operator address
_adminaddressThe admin address

enterMarkets

Add assets to be included in account liquidity calculation

function enterMarkets(address[] calldata _mTokens)
    external
    override
    onlyAllowedUser(msg.sender)
    onlyFirewallApproved;

Parameters

NameTypeDescription
_mTokensaddress[]The list of addresses of the mToken markets to be enabled

enterMarketsWithSender

Add asset (msg.sender) to be included in account liquidity calculation

function enterMarketsWithSender(address _account) external override onlyAllowedUser(_account);

Parameters

NameTypeDescription
_accountaddressThe account to add for

exitMarket

Removes asset from sender's account liquidity calculation

Sender must not have an outstanding borrow balance in the asset, and must not be providing necessary collateral for an outstanding borrow.

function exitMarket(address _mToken) external override onlyFirewallApproved;

Parameters

NameTypeDescription
_mTokenaddressThe address of the asset to be removed

beforeMTokenTransfer

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
    ifNotBlacklisted(src)
    ifNotBlacklisted(dst)
    onlyFirewallApproved;

Parameters

NameTypeDescription
mTokenaddressThe market to verify the transfer against
srcaddressThe account which sources the tokens
dstaddressThe account which receives the tokens
transferTokensuint256The number of mTokens to transfer

beforeMTokenBorrow

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)
    ifNotBlacklisted(borrower)
    onlyFirewallApproved;

Parameters

NameTypeDescription
mTokenaddressThe market to verify the borrow against
borroweraddressThe account which would borrow the asset
borrowAmountuint256The amount of underlying the account would borrow

isPaused

Returns if operation is paused

function isPaused(address mToken, ImTokenOperationTypes.OperationType _type) external view override returns (bool);

Parameters

NameTypeDescription
mTokenaddressThe mToken to check
_typeImTokenOperationTypes.OperationTypethe operation type

Returns

NameTypeDescription
<none>boolpaused True if paused

getAssetsIn

Returns the assets an account has entered

function getAssetsIn(address _user) external view override returns (address[] memory mTokens);

Parameters

NameTypeDescription
_useraddressThe address of the account to pull assets for

Returns

NameTypeDescription
mTokensaddress[]A dynamic list with the assets the account has entered

checkMembership

Returns whether the given account is entered in the given asset

function checkMembership(address account, address mToken) external view returns (bool);

Parameters

NameTypeDescription
accountaddressThe address of the account to check
mTokenaddressThe mToken to check

Returns

NameTypeDescription
<none>boolTrue if the account is in the asset, otherwise false.

getAllMarkets

A list of all markets

function getAllMarkets() external view returns (address[] memory mTokens);

Returns

NameTypeDescription
mTokensaddress[]List of markets

isDeprecated

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

NameTypeDescription
mTokenaddressThe market to check if deprecated

Returns

NameTypeDescription
<none>booldeprecated True if deprecated

isMarketListed

Returns true/false

function isMarketListed(address mToken) external view override returns (bool);

Parameters

NameTypeDescription
mTokenaddress

Returns

NameTypeDescription
<none>boollisted True if market is listed

getHypotheticalAccountLiquidity

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

NameTypeDescription
accountaddressThe account to determine liquidity for
mTokenModifyaddressThe market to hypothetically redeem/borrow in
redeemTokensuint256The number of tokens to hypothetically redeem
borrowAmountuint256The amount of underlying to hypothetically borrow

Returns

NameTypeDescription
<none>uint256liquidity Account liquidity in excess of collateral requirements
<none>uint256shortfall Account shortfall below collateral requirements

beforeMTokenMint

Checks if the account should be allowed to mint tokens in the given market

function beforeMTokenMint(address mToken, address minter, address receiver)
    external
    view
    override
    onlyAllowedUser(minter)
    ifNotBlacklisted(minter)
    ifNotBlacklisted(receiver)
    onlyFirewallApproved
    onlyAllowedUser(minter);

Parameters

NameTypeDescription
mTokenaddressThe market to verify the mint against
minteraddressThe account which would supplies the assets
receiveraddressThe account which would get the minted tokens

afterMTokenMint

Validates mint and reverts on rejection. May emit logs.

function afterMTokenMint(address mToken) external view override;

Parameters

NameTypeDescription
mTokenaddressAsset being minted

beforeMTokenRedeem

Checks if the account should be allowed to redeem tokens in the given market

function beforeMTokenRedeem(address mToken, address redeemer, uint256 redeemTokens)
    external
    view
    override
    onlyAllowedUser(redeemer)
    ifNotBlacklisted(redeemer)
    onlyFirewallApproved;

Parameters

NameTypeDescription
mTokenaddressThe market to verify the redeem against
redeemeraddressThe account which would redeem the tokens
redeemTokensuint256The number of mTokens to exchange for the underlying asset in the market

beforeMTokenRepay

Checks if the account should be allowed to repay a borrow in the given market

function beforeMTokenRepay(address mToken, address borrower)
    external
    view
    onlyAllowedUser(borrower)
    onlyFirewallApproved;

Parameters

NameTypeDescription
mTokenaddressThe market to verify the repay against
borroweraddressThe account which would borrowed the asset

beforeMTokenLiquidate

Checks if the liquidation should be allowed to occur

function beforeMTokenLiquidate(
    address mTokenBorrowed,
    address mTokenCollateral,
    address borrower,
    uint256 repayAmount
) external view override onlyFirewallApproved;

Parameters

NameTypeDescription
mTokenBorrowedaddressAsset which was borrowed by the borrower
mTokenCollateraladdressAsset which was used as collateral and will be seized
borroweraddressThe address of the borrower
repayAmountuint256The amount of underlying being repaid

beforeMTokenSeize

Checks if the seizing of assets should be allowed to occur

function beforeMTokenSeize(address mTokenCollateral, address mTokenBorrowed, address liquidator)
    external
    view
    override
    ifNotBlacklisted(liquidator)
    onlyFirewallApproved;

Parameters

NameTypeDescription
mTokenCollateraladdressAsset which was used as collateral and will be seized
mTokenBorrowedaddressAsset which was borrowed by the borrower
liquidatoraddressThe address repaying the borrow and seizing the collateral

getUSDValueForAllMarkets

Returns USD value for all markets

function getUSDValueForAllMarkets() external view returns (uint256 sum);

Returns

NameTypeDescription
sumuint256The total USD value of all markets

beforeRebalancing

Checks if the account should be allowed to rebalance tokens

function beforeRebalancing(address mToken) external view override onlyFirewallApproved;

Parameters

NameTypeDescription
mTokenaddressThe market to verify the transfer against

firewallRegister

Registers an account with the firewall

function firewallRegister(address _account) public override(HypernativeFirewallProtected);

Parameters

NameTypeDescription
_accountaddressAccount to register

_convertMarketAmountToUSDValue

Converts a market amount to USD value

function _convertMarketAmountToUSDValue(uint256 amount, address mToken) internal view returns (uint256 usdValue);

Parameters

NameTypeDescription
amountuint256The amount to convert
mTokenaddressThe market to convert

Returns

NameTypeDescription
usdValueuint256The USD value of the amount

_activateMarket

Activates a market for a borrower

function _activateMarket(address _mToken, address borrower) private;

Parameters

NameTypeDescription
_mTokenaddressThe market to activate
borroweraddressThe borrower to activate the market for

_beforeRedeem

Checks if the redeemer is in the market and has sufficient liquidity

function _beforeRedeem(address mToken, address redeemer, uint256 redeemTokens) private view;

Parameters

NameTypeDescription
mTokenaddressThe market to check
redeemeraddressThe redeemer to check
redeemTokensuint256The number of tokens to redeem

_getHypotheticalAccountLiquidity

Gets the hypothetical account liquidity

function _getHypotheticalAccountLiquidity(
    address account,
    address mTokenModify,
    uint256 redeemTokens,
    uint256 borrowAmount
) private view returns (uint256, uint256);

Parameters

NameTypeDescription
accountaddressThe account to get the liquidity for
mTokenModifyaddressThe market to modify
redeemTokensuint256The number of tokens to redeem
borrowAmountuint256The amount of underlying to borrow

Returns

NameTypeDescription
<none>uint256liquidity The liquidity in excess of collateral requirements
<none>uint256shortfall The shortfall below collateral requirements

_isDeprecated

Checks if a market is deprecated

function _isDeprecated(address mToken) private view returns (bool);

Parameters

NameTypeDescription
mTokenaddressThe market address

Returns

NameTypeDescription
<none>booldeprecated True if the market is deprecated

Events

NewBlacklister

Emitted when blacklist operator is updated

event NewBlacklister(address indexed newBlacklister);

Parameters

NameTypeDescription
newBlacklisteraddressThe new blacklist operator address

Errors

Operator_AddressNotValid

Error thrown when address is not valid

error Operator_AddressNotValid();