Skip to content

Latest commit

 

History

History
740 lines (612 loc) · 22.2 KB

LoanTokenSettingsLowerAdmin.md

File metadata and controls

740 lines (612 loc) · 22.2 KB

LoanTokenSettingsLowerAdmin.sol

View Source: contracts/connectors/loantoken/modules/shared/LoanTokenSettingsLowerAdmin.sol

↗ Extends: LoanTokenLogicStorage

LoanTokenSettingsLowerAdmin contract

Events

event SetTransactionLimits(address[]  addresses, uint256[]  limits);
event ToggledFunctionPaused(string  functionId, bool  prevFlag, bool  newFlag);
event WithdrawRBTCTo(address indexed to, uint256  amount);

Modifiers

onlyAdmin

TODO: Check for restrictions in this contract.

modifier onlyAdmin() internal

Functions


getListFunctionSignatures

This function is MANDATORY, which will be called by LoanTokenLogicBeacon and be registered. Every new public function, the sginature needs to be included in this function. *

function getListFunctionSignatures() external pure
returns(functionSignatures bytes4[], moduleName bytes32)
Source Code
function getListFunctionSignatures()
        external
        pure
        returns (bytes4[] memory functionSignatures, bytes32 moduleName)
    {
        bytes4[] memory res = new bytes4[](13);
        res[0] = this.setAdmin.selector;
        res[1] = this.setPauser.selector;
        res[2] = this.setupLoanParams.selector;
        res[3] = this.disableLoanParams.selector;
        res[4] = this.setDemandCurve.selector;
        res[5] = this.toggleFunctionPause.selector;
        res[6] = this.setTransactionLimits.selector;
        res[7] = this.changeLoanTokenNameAndSymbol.selector;
        res[8] = this.pauser.selector;
        res[9] = this.setLiquidityMiningAddress.selector;
        res[10] = this.withdrawRBTCTo.selector;
        res[11] = this.getLiquidityMiningAddress.selector;
        res[12] = this.checkPause.selector;
        return (res, stringToBytes32("LoanTokenSettingsLowerAdmin"));
    }

setAdmin

Set admin account.

function setAdmin(address _admin) public nonpayable onlyOwner 

Arguments

Name Type Description
_admin address The address of the account to grant admin permissions.
Source Code
function setAdmin(address _admin) public onlyOwner {
        admin = _admin;
    }

setPauser

Set pauser account.

function setPauser(address _pauser) public nonpayable onlyOwner 

Arguments

Name Type Description
_pauser address The address of the account to grant pause permissions.
Source Code
function setPauser(address _pauser) public onlyOwner {
        pauser = _pauser;
    }

constructor

Fallback function not allowed

function () external nonpayable
Source Code
function() external {
        revert("LoanTokenSettingsLowerAdmin - fallback not allowed");
    }

setupLoanParams

Set loan token parameters. *

function setupLoanParams(struct LoanParamsStruct.LoanParams[] loanParamsList, bool areTorqueLoans) public nonpayable onlyAdmin 

Arguments

Name Type Description
loanParamsList struct LoanParamsStruct.LoanParams[] The array of loan parameters.
areTorqueLoans bool Whether the loan is a torque loan.
Source Code
function setupLoanParams(
        LoanParamsStruct.LoanParams[] memory loanParamsList,
        bool areTorqueLoans
    ) public onlyAdmin {
        bytes32[] memory loanParamsIdList;
        address _loanTokenAddress = loanTokenAddress;

        for (uint256 i = 0; i < loanParamsList.length; i++) {
            loanParamsList[i].loanToken = _loanTokenAddress;
            loanParamsList[i].maxLoanTerm = areTorqueLoans ? 0 : 28 days;
        }

        loanParamsIdList = ProtocolSettingsLike(sovrynContractAddress).setupLoanParams(
            loanParamsList
        );
        for (uint256 i = 0; i < loanParamsIdList.length; i++) {
            loanParamsIds[
                uint256(
                    keccak256(
                        abi.encodePacked(
                            loanParamsList[i].collateralToken,
                            areTorqueLoans /// isTorqueLoan
                        )
                    )
                )
            ] = loanParamsIdList[i];
        }
    }

disableLoanParams

Disable loan token parameters. *

function disableLoanParams(address[] collateralTokens, bool[] isTorqueLoans) external nonpayable onlyAdmin 

Arguments

Name Type Description
collateralTokens address[] The array of collateral tokens.
isTorqueLoans bool[] Whether the loan is a torque loan.
Source Code
function disableLoanParams(address[] calldata collateralTokens, bool[] calldata isTorqueLoans)
        external
        onlyAdmin
    {
        require(collateralTokens.length == isTorqueLoans.length, "count mismatch");

        bytes32[] memory loanParamsIdList = new bytes32[](collateralTokens.length);
        for (uint256 i = 0; i < collateralTokens.length; i++) {
            uint256 id =
                uint256(keccak256(abi.encodePacked(collateralTokens[i], isTorqueLoans[i])));
            loanParamsIdList[i] = loanParamsIds[id];
            delete loanParamsIds[id];
        }

        ProtocolSettingsLike(sovrynContractAddress).disableLoanParams(loanParamsIdList);
    }

setDemandCurve

Set loan token parameters about the demand curve. *

function setDemandCurve(uint256 _baseRate, uint256 _rateMultiplier, uint256 _lowUtilBaseRate, uint256 _lowUtilRateMultiplier, uint256 _targetLevel, uint256 _kinkLevel, uint256 _maxScaleRate) public nonpayable onlyAdmin 

Arguments

Name Type Description
_baseRate uint256 The interest rate.
_rateMultiplier uint256 The precision multiplier for base rate.
_lowUtilBaseRate uint256 The credit utilization rate (CUR) low value.
_lowUtilRateMultiplier uint256 The precision multiplier for low util base rate.
_targetLevel uint256 The target level.
_kinkLevel uint256 The level that interest rates cluster on kinked model.
_maxScaleRate uint256 The maximum rate of the scale.
Source Code
function setDemandCurve(
        uint256 _baseRate,
        uint256 _rateMultiplier,
        uint256 _lowUtilBaseRate,
        uint256 _lowUtilRateMultiplier,
        uint256 _targetLevel,
        uint256 _kinkLevel,
        uint256 _maxScaleRate
    ) public onlyAdmin {
        require(_rateMultiplier.add(_baseRate) <= WEI_PERCENT_PRECISION, "curve params too high");
        require(
            _lowUtilRateMultiplier.add(_lowUtilBaseRate) <= WEI_PERCENT_PRECISION,
            "curve params too high"
        );

        require(
            _targetLevel <= WEI_PERCENT_PRECISION && _kinkLevel <= WEI_PERCENT_PRECISION,
            "levels too high"
        );

        baseRate = _baseRate;
        rateMultiplier = _rateMultiplier;
        lowUtilBaseRate = _lowUtilBaseRate;
        lowUtilRateMultiplier = _lowUtilRateMultiplier;

        targetLevel = _targetLevel; /// 80 ether
        kinkLevel = _kinkLevel; /// 90 ether
        maxScaleRate = _maxScaleRate; /// 100 ether
    }

toggleFunctionPause

Set the pause flag for a function to true or false. *

function toggleFunctionPause(string funcId, bool isPaused) public nonpayable

Arguments

Name Type Description
funcId string The ID of a function, the selector.
isPaused bool true/false value of the flag.
Source Code
function toggleFunctionPause(
        string memory funcId, /// example: "mint(uint256,uint256)"
        bool isPaused
    ) public {
        bool paused;
        require(msg.sender == pauser, "onlyPauser");
        /// keccak256("iToken_FunctionPause")
        bytes32 slot =
            keccak256(
                abi.encodePacked(
                    bytes4(keccak256(abi.encodePacked(funcId))),
                    uint256(0xd46a704bc285dbd6ff5ad3863506260b1df02812f4f857c8cc852317a6ac64f2)
                )
            );
        assembly {
            paused := sload(slot)
        }
        require(paused != isPaused, "isPaused is already set to that value");
        assembly {
            sstore(slot, isPaused)
        }
        emit ToggledFunctionPaused(funcId, !isPaused, isPaused);
    }

setTransactionLimits

function setTransactionLimits(address[] addresses, uint256[] limits) public nonpayable onlyAdmin 

Arguments

Name Type Description
addresses address[] The token addresses.
limits uint256[] The limit denominated in the currency of the token address.
Source Code
function setTransactionLimits(address[] memory addresses, uint256[] memory limits)
        public
        onlyAdmin
    {
        require(addresses.length == limits.length, "mismatched array lengths");
        for (uint256 i = 0; i < addresses.length; i++) {
            transactionLimit[addresses[i]] = limits[i];
        }
        emit SetTransactionLimits(addresses, limits);
    }

changeLoanTokenNameAndSymbol

Update the loan token parameters.

function changeLoanTokenNameAndSymbol(string _name, string _symbol) public nonpayable onlyAdmin 

Arguments

Name Type Description
_name string The new name of the loan token.
_symbol string The new symbol of the loan token.
Source Code
function changeLoanTokenNameAndSymbol(string memory _name, string memory _symbol)
        public
        onlyAdmin
    {
        name = _name;
        symbol = _symbol;
    }

withdrawRBTCTo

Withdraws RBTC from the contract by Multisig.

function withdrawRBTCTo(address payable _receiverAddress, uint256 _amount) external nonpayable onlyOwner 

Arguments

Name Type Description
_receiverAddress address payable The address where the rBTC has to be transferred.
_amount uint256 The amount of rBTC to be transferred.
Source Code
function withdrawRBTCTo(address payable _receiverAddress, uint256 _amount) external onlyOwner {
        require(_receiverAddress != address(0), "receiver address invalid");
        require(_amount > 0, "non-zero withdraw amount expected");
        require(_amount <= address(this).balance, "withdraw amount cannot exceed balance");
        _receiverAddress.transfer(_amount);
        emit WithdrawRBTCTo(_receiverAddress, _amount);
    }

setLiquidityMiningAddress

sets the liquidity mining contract address

function setLiquidityMiningAddress(address LMAddress) external nonpayable onlyOwner 

Arguments

Name Type Description
LMAddress address the address of the liquidity mining contract
Source Code
function setLiquidityMiningAddress(address LMAddress) external onlyOwner {
        liquidityMiningAddress = LMAddress;
    }

getLiquidityMiningAddress

We need separate getter for newly added storage variable

function getLiquidityMiningAddress() public view
returns(address)
Source Code
function getLiquidityMiningAddress() public view returns (address) {
        return liquidityMiningAddress;
    }

checkPause

Check whether a function is paused. *

function checkPause(string funcId) public view
returns(isPaused bool)

Arguments

Name Type Description
funcId string The function ID, the selector. *

Returns

isPaused Whether the function is paused: true or false.

Source Code
function checkPause(string memory funcId) public view returns (bool isPaused) {
        bytes4 sig = bytes4(keccak256(abi.encodePacked(funcId)));
        bytes32 slot =
            keccak256(
                abi.encodePacked(
                    sig,
                    uint256(0xd46a704bc285dbd6ff5ad3863506260b1df02812f4f857c8cc852317a6ac64f2)
                )
            );
        assembly {
            isPaused := sload(slot)
        }
        return isPaused;
    }

Contracts