Skip to content

Latest commit

 

History

History
358 lines (324 loc) · 13.1 KB

LoanTokenLogicLM.md

File metadata and controls

358 lines (324 loc) · 13.1 KB

LoanTokenLogicLM.sol

View Source: contracts/connectors/loantoken/modules/beaconLogicLM/LoanTokenLogicLM.sol

↗ Extends: LoanTokenLogicStandard

LoanTokenLogicLM contract

Functions


getListFunctionSignatures

This function is MANDATORY, which will be called by LoanTokenLogicBeacon and be registered. Every new public function, the signature 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[](32);

        // Loan Token Logic Standard
        res[0] = this.borrow.selector;
        res[1] = this.marginTrade.selector;
        res[2] = this.marginTradeAffiliate.selector;
        res[3] = this.transfer.selector;
        res[4] = this.transferFrom.selector;
        res[5] = this.profitOf.selector;
        res[6] = this.tokenPrice.selector;
        res[7] = this.checkpointPrice.selector;
        res[8] = this.marketLiquidity.selector;
        res[9] = this.avgBorrowInterestRate.selector;
        res[10] = this.borrowInterestRate.selector;
        res[11] = this.nextBorrowInterestRate.selector;
        res[12] = this.supplyInterestRate.selector;
        res[13] = this.nextSupplyInterestRate.selector;
        res[14] = this.totalSupplyInterestRate.selector;
        res[15] = this.totalAssetBorrow.selector;
        res[16] = this.totalAssetSupply.selector;
        res[17] = this.getMaxEscrowAmount.selector;
        res[18] = this.assetBalanceOf.selector;
        res[19] = this.getEstimatedMarginDetails.selector;
        res[20] = this.getDepositAmountForBorrow.selector;
        res[21] = this.getBorrowAmountForDeposit.selector;
        res[22] = this.checkPriceDivergence.selector;
        res[23] = this.calculateSupplyInterestRate.selector;

        // Loan Token LM & OVERLOADING function
        /**
         * @notice BE CAREFUL,
         * LoanTokenLogicStandard also has mint & burn function (overloading).
         * You need to compute the function signature manually --> bytes4(keccak256("mint(address,uint256,bool)"))
         */
        res[24] = bytes4(keccak256("mint(address,uint256)")); /// LoanTokenLogicStandard
        res[25] = bytes4(keccak256("mint(address,uint256,bool)")); /// LoanTokenLogicLM
        res[26] = bytes4(keccak256("burn(address,uint256)")); /// LoanTokenLogicStandard
        res[27] = bytes4(keccak256("burn(address,uint256,bool)")); /// LoanTokenLogicLM

        // Advanced Token
        res[28] = this.approve.selector;

        // Advanced Token Storage
        res[29] = this.totalSupply.selector;
        res[30] = this.balanceOf.selector;
        res[31] = this.allowance.selector;

        return (res, stringToBytes32("LoanTokenLogicLM"));
    }

mint

deposit into the lending pool and optionally participate at the Liquidity Mining Program

function mint(address receiver, uint256 depositAmount, bool useLM) external nonpayable nonReentrant globallyNonReentrant 
returns(minted uint256)

Arguments

Name Type Description
receiver address the receiver of the tokens
depositAmount uint256 The amount of underlying tokens provided on the loan. (Not the number of loan tokens to mint).
useLM bool if true -> deposit the pool tokens into the Liquidity Mining contract
Source Code
function mint(
        address receiver,
        uint256 depositAmount,
        bool useLM
    ) external nonReentrant globallyNonReentrant returns (uint256 minted) {
        if (useLM) return _mintWithLM(receiver, depositAmount);
        else return _mintToken(receiver, depositAmount);
    }

burn

withdraws from the lending pool and optionally retrieves the pool tokens from the Liquidity Mining Contract

function burn(address receiver, uint256 burnAmount, bool useLM) external nonpayable nonReentrant globallyNonReentrant 
returns(redeemed uint256)

Arguments

Name Type Description
receiver address the receiver of the underlying tokens. note: potetial LM rewards are always sent to the msg.sender
burnAmount uint256 The amount of pool tokens to redeem.
useLM bool if true -> deposit the pool tokens into the Liquidity Mining contract
Source Code
function burn(
        address receiver,
        uint256 burnAmount,
        bool useLM
    ) external nonReentrant globallyNonReentrant returns (uint256 redeemed) {
        if (useLM) redeemed = _burnFromLM(burnAmount);
        else redeemed = _burnToken(burnAmount);
        //this needs to be here and not in _burnTokens because of the WRBTC implementation
        if (redeemed != 0) {
            _safeTransfer(loanTokenAddress, receiver, redeemed, "asset transfer failed");
        }
    }

Contracts