ILoanManagerBase

Git Source

Author: bull.haus

Base contract for loan actions containing all storage definitions.

Errors

NotAuthorized

Performing actions on other user's loan configs revert with NotAuthorized.

error NotAuthorized();

Structs

LoanConfigAssetUsage

Record containing all accepted asset ids and corresponding usage config.

All asset usages on loans (paying collateral, interest, changing collateral) have to use the exact same array of assets as defined upon creating a loan.

Loan configurations accept a list of price feeds (bitmask, where LSB is price feed index 0, MSB is price feed index 7).

assetId list of all accepted asset ids

priceFeedIndices list of all accepted price feed indices as bitfield (index 0 = LSB, index 7 = MSB)

useCollateral list of booleans indicating whether asset[i] can be used for collateral payments

useInterest list of booleans indicating whether asset[i] can be used for interest payments

struct LoanConfigAssetUsage {
    uint256[] assetId;
    uint8[] priceFeedIndices;
    bool[] useCollateral;
    bool[] useInterest;
}

CollateralAssets

List of collateral asset amounts and chosen price feed indices.

The array index corresponds to the arrays in LoanConfigAssetUsage.

amount list of collateral amounts for each asset. This value must be 0 when useCollateral == false for the corresponding asset.

priceFeedIndex chosen price feed index for each asset, where contrary to the bitfield in LoanConfigAssetUsage, this value is an integer value of exactly one chosen price feed. Only price feeds accepted in LoanConfigAssetUsage for this specific asset are allowed.

struct CollateralAssets {
    uint256[] amount;
    uint8[] priceFeedIndex;
}

LoanConfig

Contract-managed part of loan configurations.

The user-defined part is in LoanConfigUser and LoanAssets. Users cannot update this data, as it would change any ongoing loans. It should be deleted and re-created instead.

lender The creator of the loan config, and the initial lender of all loans created from this config.

enabled true when the loan config can be used for new loans, false otherwise.

totalLoanAmount Sum of loan amounts of all open loans created from this config.

config User-defined loan config settings.

assetUsage User-defined config asset usage settings.

struct LoanConfig {
    address lender;
    bool enabled;
    uint256 totalLoanAmount;
    LoanConfigUser config;
    LoanConfigAssetUsage assetUsage;
}

LoanConfigLimits

Platform limits to loan configurations.

These values are stored only once in the contract, but used in calculations many times. To avoid casting from uint8 to uint256, all values are stored as uint256.

minTerms: minimum amount of terms of a loan (1).

maxTerms: maximum amount of terms of a loan (10).

minInterestPromille: minimum interest rate in promille (percent * 10) (20).

maxInterestPromille: maximum interest rate in promille (percent * 10) (120).

interestPromilleResolution: interest rate resolution (interest rate % resolution == 0) (10).

minCollateralPercentageMinus100: minimum collateral percentage, minus "100" (20 == 120%).

maxCollateralPercentageMinus100: maximum collateral percentage, minus "100" (250 == 350%).

minSafetyBufferPercentage: minimum safety buffer percentage.

maxSafetyBufferPercentage: maximum safety buffer percentage.

maxLoanConfigsPerAsset: maximum amount of loan configurations per user per asset (10).

struct LoanConfigLimits {
    uint256 minTerms;
    uint256 maxTerms;
    uint256 minInterestPromille;
    uint256 maxInterestPromille;
    uint256 interestPromilleResolution;
    uint256 minCollateralPercentageMinus100;
    uint256 maxCollateralPercentageMinus100;
    uint256 minSafetyBufferPercentage;
    uint256 maxSafetyBufferPercentage;
    uint256 maxLoanConfigsPerAsset;
}

LoanConfigUser

Lender-defined part of loan configurations.

minLoanAmount: minimum amount of the loan asset per loan.

maxLoanAmount: maximum amount of the loan asset per loan.

maxTotalLoanAmount: maximum amount of open loans, taken for this specific loan config. Paid back loans are deducted from this value, if and only if the corresponding LoaNFT is held by LoanConfig.lender at the time of repayment.

assetId: loan asset id.

liquidationType: ignored in the current implementation, added for forward compatibility.

termPaymentType: required payments on each passing term; can be paid in advance.

acceptedPriceFeeds: accepted price feeds as bitmask.

interestPromille: interest of loan expressed in 0.1 percent (promille).

terms: amount of terms (30 days) for the loan.

collateralPercentageMinus100: minimum collateral percentage before liquidation, minus 100 (e.g. 0 = 100%, 50 = 150%, 100 = 200%).

safetyBufferPercentage: minimum safety buffer. Minimum collateral percentage when changing is collateralPercentageMinus100 + 100 + safetyBufferPercentage.

acceptSignedTerms: ignored in the current implementation, added for forward compatibility.

struct LoanConfigUser {
    uint256 minLoanAmount;
    uint256 maxLoanAmount;
    uint256 maxTotalLoanAmount;
    uint256 assetId;
    LiquidationType liquidationType;
    TermPaymentType termPaymentType;
    uint8 acceptedPriceFeeds;
    uint8 interestPromille;
    uint8 terms;
    uint8 collateralPercentageMinus100;
    uint8 safetyBufferPercentage;
    bool acceptSignedTerms;
}

LoanInfo

Contract-managed part of loans.

borrower: loan taker, collateral payer.

loanStart: block.timestamp of start of loan.

pendingPrincipalAmount: pending loan amount to repay.

pendingInterestAmount: pending amount of loan asset interest to repay.

loan: loan parameters as defined by borrower, within the limits of the lender-defined loan configuration.

collateralAssets: price feeds for all assets, and asset amounts for currently used collateral assets

struct LoanInfo {
    address borrower;
    uint256 loanStart;
    uint256 pendingPrincipalAmount;
    uint256 pendingInterestAmount;
    LoanInfoUser loan;
    CollateralAssets collateralAssets;
}

LoanInfoUser

Borrower-defined part of loans.

configId: configuration from which the loan is created.

loanAmount: amount of loan asset borrowed.

priceFeedIndex: chosen price feed index to determine current value for borrowed asset.

struct LoanInfoUser {
    uint256 configId;
    uint256 loanAmount;
    uint8 priceFeedIndex;
}

Enums

LiquidationType

Type of liquidation supported on loans taken from this configuration.

This is added for forward compatibility, as loans will be optionally non-liquidatable.

enum LiquidationType {
    None,
    All,
    Collateral
}

TermPaymentType

Type of required term payment on loans.

The option to pay only principal each term is not possible, as the platform has a hard requirement to pay at least the same interest share as principal share.

None: borrower is required to pay interest and principal only at the end of the loan.

Interest: borrower is required to pay a linear share of the total interest each term.

InterestAndPrincipal: borrower is required to pay a linear share of the total interest each term, as well as a linear share of the total principal.

enum TermPaymentType {
    None,
    Interest,
    InterestAndPrincipal
}