Skip to content

Latest commit

 

History

History
507 lines (422 loc) · 16 KB

LoanTokenLogicBeacon.md

File metadata and controls

507 lines (422 loc) · 16 KB

Loan Token Logic Beacon contract.

  • (LoanTokenLogicBeacon.sol)

View Source: contracts/connectors/loantoken/LoanTokenLogicBeacon.sol

↗ Extends: PausableOz

LoanTokenLogicBeacon contract

This contract stored the target logic implementation of LoanTokens which has the same logic implementation (LoanTokenLogicLM / LoanTokenLogicWrbtc) Apart from storing the target logic implementation, this contract also has a pause functionality. By implementing pause/unpause functionality in this beacon contract, we can pause the loan token that has the same Logic (LoanTokenLogicLM / LoanTokenLogicWrbtc) at one call. Meanwhile the pause/unpause function in the LoanTokenLogicProxy is used to pause/unpause specific LoanToken

Structs

LoanTokenLogicModuleUpdate

struct LoanTokenLogicModuleUpdate {
 address implementation,
 uint256 updateTimestamp
}

Contract Members

Constants & Variables

//private members
mapping(bytes4 => address) private logicTargets;
mapping(bytes32 => struct EnumerableBytes4Set.Bytes4Set) private activeFuncSignatureList;

//public members
mapping(bytes32 => struct LoanTokenLogicBeacon.LoanTokenLogicModuleUpdate[]) public moduleUpgradeLog;
mapping(bytes32 => uint256) public activeModuleIndex;

Modifiers

whenNotPaused

Modifier to make a function callable only when the contract is not paused. This is the overriden function from the pausable contract, so that we can use custom error message.

modifier whenNotPaused() internal

Functions


registerLoanTokenModule

Register the loanTokenModule (LoanTokenSettingsLowerAdmin, LoanTokenLogicLM / LoanTokenLogicWrbtc, etc) *

function registerLoanTokenModule(address loanTokenModuleAddress) external nonpayable onlyOwner 

Arguments

Name Type Description
loanTokenModuleAddress address The module target address
Source Code
function registerLoanTokenModule(address loanTokenModuleAddress) external onlyOwner {
        bytes32 moduleName = _registerLoanTokenModule(loanTokenModuleAddress);

        // Store the upgrade to the log
        moduleUpgradeLog[moduleName].push(
            LoanTokenLogicModuleUpdate(loanTokenModuleAddress, block.timestamp)
        );
        activeModuleIndex[moduleName] = moduleUpgradeLog[moduleName].length - 1;
    }

_registerLoanTokenModule

Register the loanTokenModule (LoanTokenSettingsLowerAdmin, LoanTokenLogicLM / LoanTokenLogicWrbtc, etc) *

function _registerLoanTokenModule(address loanTokenModuleAddress) private nonpayable
returns(bytes32)

Arguments

Name Type Description
loanTokenModuleAddress address the target logic of the loan token module *

Returns

the module name

Source Code
function _registerLoanTokenModule(address loanTokenModuleAddress) private returns (bytes32) {
        require(
            Address.isContract(loanTokenModuleAddress),
            "LoanTokenModuleAddress is not a contract"
        );

        // Get the list of function signature on this loanTokenModulesAddress
        (bytes4[] memory functionSignatureList, bytes32 moduleName) =
            ILoanTokenLogicModules(loanTokenModuleAddress).getListFunctionSignatures();

        /// register / update the module function signature address implementation
        for (uint256 i; i < functionSignatureList.length; i++) {
            require(functionSignatureList[i] != bytes4(0x0), "ERR_EMPTY_FUNC_SIGNATURE");
            logicTargets[functionSignatureList[i]] = loanTokenModuleAddress;
            if (!activeFuncSignatureList[moduleName].contains(functionSignatureList[i]))
                activeFuncSignatureList[moduleName].addBytes4(functionSignatureList[i]);
        }

        /// delete the "removed" module function signature in the current implementation
        bytes4[] memory activeSignatureListEnum =
            activeFuncSignatureList[moduleName].enumerate(
                0,
                activeFuncSignatureList[moduleName].length()
            );
        for (uint256 i; i < activeSignatureListEnum.length; i++) {
            bytes4 activeSigBytes = activeSignatureListEnum[i];
            if (logicTargets[activeSigBytes] != loanTokenModuleAddress) {
                logicTargets[activeSigBytes] = address(0);
                activeFuncSignatureList[moduleName].removeBytes4(activeSigBytes);
            }
        }

        return moduleName;
    }

getActiveFuncSignatureList

get all active function signature list based on the module name. *

function getActiveFuncSignatureList(bytes32 moduleName) public view
returns(signatureList bytes4[])

Arguments

Name Type Description
moduleName bytes32 in bytes32. *

Returns

the array of function signature.

Source Code
function getActiveFuncSignatureList(bytes32 moduleName)
        public
        view
        returns (bytes4[] memory signatureList)
    {
        signatureList = activeFuncSignatureList[moduleName].enumerate(
            0,
            activeFuncSignatureList[moduleName].length()
        );
        return signatureList;
    }

getModuleUpgradeLogLength

Get total length of the module upgrade log. *

function getModuleUpgradeLogLength(bytes32 moduleName) external view
returns(uint256)

Arguments

Name Type Description
moduleName bytes32 in bytes32. *

Returns

length of module upgrade log.

Source Code
function getModuleUpgradeLogLength(bytes32 moduleName) external view returns (uint256) {
        return moduleUpgradeLog[moduleName].length;
    }

rollback

This function will rollback particular module to the spesific index / version of deployment *

function rollback(bytes32 moduleName, uint256 index) external nonpayable onlyOwner 

Arguments

Name Type Description
moduleName bytes32 Name of module in bytes32 format
index uint256 index / version of previous deployment
Source Code
function rollback(bytes32 moduleName, uint256 index) external onlyOwner {
        address loanTokenModuleAddress = moduleUpgradeLog[moduleName][index].implementation;
        moduleName = _registerLoanTokenModule(loanTokenModuleAddress);
        activeModuleIndex[moduleName] = index;
    }

getTarget

External getter for target addresses.

function getTarget(bytes4 sig) external view whenNotPaused 
returns(address)

Arguments

Name Type Description
sig bytes4 The signature.

Returns

The address for a given signature.

Source Code
function getTarget(bytes4 sig) external view whenNotPaused returns (address) {
        return logicTargets[sig];
    }

getListFunctionSignatures

function getListFunctionSignatures() external pure
returns(bytes4[], moduleName bytes32)
Source Code
function getListFunctionSignatures()
        external
        pure
        returns (bytes4[] memory, bytes32 moduleName);

Contracts