Skip to content

Latest commit

 

History

History
310 lines (277 loc) · 11.3 KB

InterestUser.md

File metadata and controls

310 lines (277 loc) · 11.3 KB

The Interest User contract.

  • This contract pays loan interests. (InterestUser.sol)

View Source: contracts/mixins/InterestUser.sol

↗ Extends: VaultController, FeesHelper ↘ Derived Contracts: LoanClosingsShared, LoanMaintenance, LoanOpenings

InterestUser contract

Events

event PayInterestTransfer(address indexed interestToken, address indexed lender, uint256  effectiveInterest);

Functions


_payInterest

Internal function to pay interest of a loan.

function _payInterest(address lender, address interestToken) internal nonpayable

Arguments

Name Type Description
lender address The account address of the lender.
interestToken address The token address to pay interest with.
Source Code
function _payInterest(address lender, address interestToken) internal {
        LenderInterest storage lenderInterestLocal = lenderInterest[lender][interestToken];

        uint256 interestOwedNow = 0;
        if (lenderInterestLocal.owedPerDay != 0 && lenderInterestLocal.updatedTimestamp != 0) {
            interestOwedNow = block
                .timestamp
                .sub(lenderInterestLocal.updatedTimestamp)
                .mul(lenderInterestLocal.owedPerDay)
                .div(1 days);

            lenderInterestLocal.updatedTimestamp = block.timestamp;

            if (interestOwedNow > lenderInterestLocal.owedTotal)
                interestOwedNow = lenderInterestLocal.owedTotal;

            if (interestOwedNow != 0) {
                lenderInterestLocal.paidTotal = lenderInterestLocal.paidTotal.add(interestOwedNow);
                lenderInterestLocal.owedTotal = lenderInterestLocal.owedTotal.sub(interestOwedNow);

                _payInterestTransfer(lender, interestToken, interestOwedNow);
            }
        } else {
            lenderInterestLocal.updatedTimestamp = block.timestamp;
        }
    }

_payInterestTransfer

Internal function to transfer tokens for the interest of a loan.

function _payInterestTransfer(address lender, address interestToken, uint256 interestOwedNow) internal nonpayable

Arguments

Name Type Description
lender address The account address of the lender.
interestToken address The token address to pay interest with.
interestOwedNow uint256 The amount of interest to pay.
Source Code
function _payInterestTransfer(
        address lender,
        address interestToken,
        uint256 interestOwedNow
    ) internal {
        uint256 lendingFee = interestOwedNow.mul(lendingFeePercent).div(10**20);
        /// TODO: refactor: data incapsulation violation and DRY design principles
        /// uint256 lendingFee = interestOwedNow.mul(lendingFeePercent).divCeil(10**20); is better but produces errors in tests because of this

        _payLendingFee(lender, interestToken, lendingFee);

        /// Transfers the interest to the lender, less the interest fee.
        vaultWithdraw(interestToken, lender, interestOwedNow.sub(lendingFee));

        /// Event Log
        emit PayInterestTransfer(interestToken, lender, interestOwedNow.sub(lendingFee));
    }

Contracts