Skip to main content

GenericLogic

GenericLogic

Main entry point for senior LPs (a.k.a. capital providers) Automatically invests across borrower pools using an adjustable strategy.

SetRate

event SetRate(bytes32 loan, uint256 rate)

ChangeRate

event ChangeRate(bytes32 loan, uint256 newRate)

maturityDate

function maturityDate(struct DataTypes.Storage _poolStorage, bytes32 nft_) internal view returns (uint256 maturityDate_)

getter function for the maturityDate

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.Storage
nft_bytes32the id of the nft based on the hash of registry and tokenId

Return Values

NameTypeDescription
maturityDate_uint256the maturityDate of the nft

risk

function risk(struct DataTypes.Storage _poolStorage, bytes32 nft_) internal view returns (uint256 risk_)

getter function for the risk group

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.Storage
nft_bytes32the id of the nft based on the hash of registry and tokenId

Return Values

NameTypeDescription
risk_uint256the risk group of the nft

futureValue

function futureValue(struct DataTypes.Storage _poolStorage, bytes32 nft_) internal view returns (uint256 fv_)

getter function for the future value

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.Storage
nft_bytes32the id of the nft based on the hash of registry and tokenId

Return Values

NameTypeDescription
fv_uint256future value of the loan

recoveryRatePD

function recoveryRatePD(struct DataTypes.RiskScore[] riskScores, uint256 riskID, uint256 termLength) internal view returns (uint256 recoveryRatePD_)

getter function for the recovery rate PD

Parameters

NameTypeDescription
riskScoresstruct DataTypes.RiskScore[]
riskIDuint256id of a risk group
termLengthuint256

Return Values

NameTypeDescription
recoveryRatePD_uint256recovery rate PD of the risk group

borrowed

function borrowed(struct DataTypes.Storage _poolStorage, uint256 loan) internal view returns (uint256 borrowed_)

getter function for the borrowed amount

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.Storage
loanuint256id of a loan

Return Values

NameTypeDescription
borrowed_uint256borrowed amount of the loan

getRiskScoreByIdx

function getRiskScoreByIdx(struct DataTypes.RiskScore[] riskScores, uint256 idx) internal view returns (struct DataTypes.RiskScore)

UTILITY FUNCTION

toUint128

function toUint128(uint256 value) internal pure returns (uint128 converted)

converts a uint256 to uint128

Parameters

NameTypeDescription
valueuint256the value to be converted

Return Values

NameTypeDescription
converteduint128value to uint128

isLoanWrittenOff

function isLoanWrittenOff(struct DataTypes.Storage _poolStorage, uint256 loan) internal view returns (bool)

returns if a loan is written off

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.Storage
loanuint256the id of the loan

currentNAV

function currentNAV(struct DataTypes.Storage _poolStorage) internal view returns (uint256 nav_)

calculates and returns the current NAV

Return Values

NameTypeDescription
nav_uint256current NAV

currentNAVAsset

function currentNAVAsset(struct DataTypes.Storage _poolStorage, bytes32 tokenId) internal view returns (uint256)

currentPVs

function currentPVs(struct DataTypes.Storage _poolStorage) internal view returns (uint256 totalDiscount, uint256 overdue, uint256 writeOffs)

calculates the present value of the loans together with overdue and written off loans

Return Values

NameTypeDescription
totalDiscountuint256the present value of the loans
overdueuint256the present value of the overdue loans
writeOffsuint256the present value of the written off loans

currentAV

function currentAV(struct DataTypes.Storage _poolStorage, bytes32 tokenId) internal view returns (uint256 totalDiscount, uint256 overdue, uint256 writeOffs)

This function calculates the total discount, overdue and write offs of a loan.

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.StorageThe storage object for the pool.
tokenIdbytes32The ID of the loan.

Return Values

NameTypeDescription
totalDiscountuint256The total discount of the loan.
overdueuint256The amount that is overdue.
writeOffsuint256The amount that has been written off.

currentWriteOffs

function currentWriteOffs(struct DataTypes.Storage _poolStorage) internal view returns (uint256 sum)

returns the sum of all write off loans

Return Values

NameTypeDescription
sumuint256of all write off loans

calcUpdateNAV

function calcUpdateNAV(struct DataTypes.Storage _poolStorage) internal returns (uint256 nav_)

calculates and returns the current NAV and updates the state

Return Values

NameTypeDescription
nav_uint256current NAV

reCalcNAV

function reCalcNAV(struct DataTypes.Storage _poolStorage) internal returns (uint256 nav_)

re-calculates the nav in a non-optimized way the method is not updating the NAV to latest block.timestamp

Return Values

NameTypeDescription
nav_uint256current NAV

nftID

function nftID(uint256 loan) internal pure returns (bytes32 nftID_)

returns the nftID for the underlying collateral nft

Parameters

NameTypeDescription
loanuint256the loan id

Return Values

NameTypeDescription
nftID_bytes32the nftID of the loan

currentValidWriteOffGroup

function currentValidWriteOffGroup(struct DataTypes.Storage _poolStorage, uint256 loan) internal view returns (uint256 writeOffGroup_)

returns the current valid write off group of a loan

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.Storage
loanuint256the loan id

Return Values

NameTypeDescription
writeOffGroup_uint256the current valid write off group of a loan

debt

function debt(struct DataTypes.Storage _poolStorage, uint256 loan) internal view returns (uint256 loanDebt)

Calculates the debt of a loan based on its rate, interest rates and time elapsed since last update.

If there's no penalty, it simply returns the amount after charging interest to chi. Otherwise, it calculates the total debt by first applying interest to chi* then applies that to penaltyChi*._

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.StorageThe storage of the pool from which data is retrieved.
loanuint256The index of the loan for which we want to calculate the debt.

Return Values

NameTypeDescription
loanDebtuint256The calculated debt of the loan.

debtWithChi

function debtWithChi(struct DataTypes.Storage _poolStorage, uint256 loan, uint256 chi, uint256 penaltyChi) internal view returns (uint256 loanDebt)

Calculate the debt of a loan based on chi and penaltyChi.

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.StorageThe storage object of the pool.
loanuint256The amount of loan.
chiuint256The amount of chi.
penaltyChiuint256The amount of penalty chi.

Return Values

NameTypeDescription
loanDebtuint256The calculated debt of the loan.

chiAndPenaltyChi

function chiAndPenaltyChi(struct DataTypes.Storage _poolStorage, uint256 loan) internal view returns (uint256 chi, uint256 penaltyChi)

This function calculates chi and penaltyChi based on loan rate.

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.StorageThe storage object for the pool.
loanuint256The amount of loan taken by user.

Return Values

NameTypeDescription
chiuint256The calculated chi value.
penaltyChiuint256The calculated penalty chi value.

rateDebt

function rateDebt(struct DataTypes.Storage _poolStorage, uint256 rate) internal view returns (uint256 totalDebt)

Calculates total debt for a specific rate.

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.StorageThe storage object containing all pool data.
rateuint256The index of the rate to calculate the debt for.

Return Values

NameTypeDescription
totalDebtuint256The total debt calculated based on the specified rate and any applicable interest charges.

setRate

function setRate(struct DataTypes.Storage _poolStorage, uint256 loan, uint256 rate) internal

_This function sets the rate for a specific loan in the pool storage. Requirements:

  • The debt associated with the loan must be zero.
  • The specified rate category must already have been initiated._

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.StorageThe storage object for the pool.
loanuint256The ID of the loan to set the rate for.
rateuint256The new rate to set for the loan.

changeRate

function changeRate(struct DataTypes.Storage _poolStorage, uint256 loan, uint256 newRate) internal

Changes the interest rate of a loan.

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.StorageThe storage object of the pool.
loanuint256The ID of the loan.
newRateuint256The new interest rate to be set for the loan.

accrue

function accrue(struct DataTypes.Storage _poolStorage, uint256 loan) internal

Accrue the loan interest based on the loan type and update the pool storage.

Drip the interest to the pool from the specified loan.

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.StorageThe storage of the pool.
loanuint256The loan type for which we want to accrue interest.

drip

function drip(struct DataTypes.Storage _poolStorage, uint256 rate) internal

This function updates the chi value of a specific rate in the pool storage. It also handles penalties if they exist.

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.StorageThe Storage object containing all data for this contract.
rateuint256The index of the rate to update.

compounding

function compounding(uint256 chi, uint256 ratePerSecond, uint256 lastUpdated, uint256 _pie) internal view returns (uint256, uint256)

Interest functions This function provides compounding in seconds

Parameters

NameTypeDescription
chiuint256Accumulated interest rate over time
ratePerSeconduint256Interest rate accumulation per second in RAD(10ˆ27)
lastUpdateduint256When the interest rate was last updated
_pieuint256Total sum of all amounts accumulating under one interest rate, divided by that rate

Return Values

NameTypeDescription
[0]uint256The new accumulated rate, as well as the difference between the debt calculated with the old and new accumulated rates.
[1]uint256

chargeInterest

function chargeInterest(uint256 interestBearingAmount, uint256 ratePerSecond, uint256 lastUpdated) internal view returns (uint256)

This function charge interest on a interestBearingAmount

Parameters

NameTypeDescription
interestBearingAmountuint256is the interest bearing amount
ratePerSeconduint256Interest rate accumulation per second in RAD(10ˆ27)
lastUpdateduint256last time the interest has been charged

Return Values

NameTypeDescription
[0]uint256interestBearingAmount + interest

_chargeInterest

function _chargeInterest(uint256 interestBearingAmount, uint256 ratePerSecond, uint256 lastUpdated, uint256 current) internal pure returns (uint256)

Calculates the amount of interest to be charged on an interest bearing asset.

Parameters

NameTypeDescription
interestBearingAmountuint256The total value of the interest bearing asset.
ratePerSeconduint256The interest rate per second, as a fractional number (e.g., 1% = 0.01).
lastUpdateduint256The timestamp when the balance was last updated.
currentuint256The current timestamp.

Return Values

NameTypeDescription
[0]uint256The amount of interest to be charged on the asset.

toAmount

function toAmount(uint256 chi, uint256 _pie) internal pure returns (uint256)

This function converts an amount of pie into chi.

Parameters

NameTypeDescription
chiuint256The number of chi units that will be returned.
_pieuint256The number of pie units to convert.

Return Values

NameTypeDescription
[0]uint256The equivalent number of chi units.

toPie

function toPie(uint256 chi, uint256 amount) internal pure returns (uint256)

This function calculates how many pieces (pies) can be obtained from a given amount of chi.

Parameters

NameTypeDescription
chiuint256The number of chi units available for distribution.
amountuint256The total amount to distribute.

Return Values

NameTypeDescription
[0]uint256Returns the number of pies that can be made with the provided chi and amount.

getAsset

function getAsset(struct DataTypes.Storage _poolStorage, bytes32 agreementId) internal view returns (struct DataTypes.NFTDetails)

Function to get details about an asset from a pool storage

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.StorageThe storage of the pool where the agreement is stored
agreementIdbytes32The id of the agreement for which we want to retrieve the NFT details

Return Values

NameTypeDescription
[0]struct DataTypes.NFTDetailsReturns the details of the NFT associated with the given agreement ID

reserve

function reserve(struct DataTypes.Storage _poolStorage) internal view returns (uint256)

This function returns the total reserve of a pool which is sum of capital and income reserves.

Parameters

NameTypeDescription
_poolStoragestruct DataTypes.StorageThe storage object of the pool.

Return Values

NameTypeDescription
[0]uint256Total reserve amount in the pool.

unpackParamsForAgreementID

function unpackParamsForAgreementID(struct DataTypes.LoanEntry loan) internal view returns (struct UnpackLoanParamtersLib.InterestParams params)

Unpacks parameters from a loan entry to calculate interest rates and other terms.

This function unpacks the parameters of a loan, calculates the term length in seconds based on the amortization unit type, and returns an InterestParams struct containing all these values.

Parameters

NameTypeDescription
loanstruct DataTypes.LoanEntryThe loan entry from which to extract parameters.

Return Values

NameTypeDescription
paramsstruct UnpackLoanParamtersLib.InterestParamsA struct containing the principal amount, interest rate, start and end timestamps of the term, the amortization unit type, and the length of the term in amortization units.