OCC_Modular.sol

OCC -> On-Chain Credit (Loan Management System)

Introduction

OCC stands for "On-Chain Credit".

A "Bullet" loan is an interest-only loan, with principal repaid in full at the end.

An "Amortization" loan is a principal and interest loan, with consistent payments until fully "Repaid".

This locker is responsible for handling accounting of loans.

This locker is responsible for handling payments and distribution of payments.

This locker is responsible for handling defaults and liquidations (if needed).

State Variables

TypeNameDescription

address

GBL

The ZivoeGlobals contract.

address

stablecoin

The stablecoin for this OCC contract.

address

underwriter

The entity that is allowed to underwrite (a.k.a. issue) loans.

address

OCT_YDL

Facilitates swaps and forwards distributedAsset() to YDL.

uint256

combineCounter

Incrementor for "combinations" mapping.

uint256

loanCounter

Incrementor for "loans" mapping.

uint256

BIPS

Private constant, 10000

mapping(uint256 => Combine)

combinations

Mapping of approved loan combinations.

mapping(uint256 => bool)

conversionToAmortization

Mapping of loans approved for conversion to amortization payment schedule.

mapping(uint256 => bool)

conversionToBullet

Mapping of loans approved for conversion to bullet payment schedule.

mapping(uint256 => uint256)

extensions

Mapping of loans approved for extension, key is the loan ID, output is paymentIntervals extension.

mapping(uint256 => Loan)

loans

Mapping of loans and their information, key is the ID of the loan, output is the Loan struct information.

mapping(uint256 => uint256)

refinancing

Mapping of loans approved for refinancing, key is the ID of the loan, output is APR it can refinance to.

Loan

This struct stores information for loans.

TypeNameDescription

address

borrower

The address that receives capital when the loan is funded.

uint256

principalOwed

The amount of principal still owed on the loan.

uint256

APR

The annualized percentage rate charged on the outstanding principal.

uint256

APRLateFee

The APR charged on the outstanding principal if payment is late.

uint256

paymentDueBy

The timestamp (in seconds) for when the next payment is due.

uint256

paymentsRemaining

The number of payments remaining until the loan is "Repaid".

uint256

term

The number of paymentIntervals that will occur (e.g. 12, 24).

uint256

paymentInterval

The interval of time between payments (in seconds).

uint256

offerExpiry

The block.timestamp at which the offer for this loan expires.

uint256

gracePeriod

The number of seconds a borrower has to makePayment() before default.

int8

paymentSchedule

The payment schedule of the loan (0 = "Bullet" or 1 = "Amortization").

state

The state of the loan.

Combine

This struct stores information for loan combinations.

TypeNameDescription

uint256[]

loans

The loans approved for combination.

uint256

term

The term of the resulting combined loan.

uint256

paymentInterval

The paymentInterval of the resulting combined loan.

uint256

gracePeriod

The gracePeriod of the resulting combined loan.

uint256

expires

The expiration of this combination.

int8

paymentSchedule

The paymentSchedule of the resulting combined loan.

bool

valid

The validity of the combination (if it can be executed).

LoanState

This enumerator tracks loan states.

StateDescription

Null

Default state, loan isn't offered yet.

Offered

Loan offer has been created, not accepted (it could have passed expiry date).

Active

Loan has been accepted, is currently receiving payments.

Repaid

Loan was accepted, and has been fully repaid.

Defaulted

Loan has defaulted, payments were missed, gracePeriod passed, and markDefault() called.

Cancelled

Loan offer was created, then cancelled prior to acceptance.

Resolved

Loan was accepted, then there was a default, then the full amount of principal was repaid.

Combined

Loan was accepted, then combined with other loans while active.

LoanSchedule

This enumerator tracks the payment schedule type for a loan.

StateDescription

Bullet

An interest-only loan, with principal repaid in full at the end.

Amortization

A principal and interest loan, with consistent payments until fully "Repaid".

Sections

Read Functions

Write Functions - Core

  • acceptOffer() - Funds and initiates a loan.

  • callLoan() - Pays off the loan in full, plus additional interest for paymentInterval.

  • cancelOffer() - Cancels a loan offer.

  • createOffer() - Create a loan offer.

  • makePayment() - Make a payment on a loan. Anyone is allowed to make a payment on someone's loan.

  • markDefault() - Mark a loan insolvent if a payment hasn't been made beyond the corresponding grace period.

  • markRepaid() - Underwriter specifies a loan has been repaid fully via interest deposits in terms of off-chain debt.

  • processPayment() - Process a payment for a loan, on behalf of another borrower.

  • resolveDefault() - Make a full (or partial) payment to resolve an insolvent loan.

  • supplyInterest() - Supply interest to a repaid loan (for arbitrary interest repayment).

  • updateOCTYDL() - Updates the OCT_YDL endpoint.

Write Functions - Loan Management

Events

Read Functions

canPush()

Permission for owner to call pushToLocker(). See ZivoeLocker.sol

 function canPush() public override pure returns (bool) { return true; }

canPull()

Permission for owner to call pullFromLocker(). See ZivoeLocker.sol

function canPull() public override pure returns (bool) { return true; }

canPullPartial()

Permission for owner to call pullFromLockerPartial(). See ZivoeLocker.sol

function canPullPartial() public override pure returns (bool) { return true; }

loanInfo()

Returns information for a given loan. Refer to Loan

function loanInfo(uint256 id) public view returns (
    address borrower, 
    int8 paymentSchedule,
    uint256[10] memory details
);
TypeNameDescription

uint256

id

The ID of the loan.

Returns

TypeNameDescription

address

borrower

The borrower of the loan.

int8

paymentSchedule

The structure of the payment schedule.

uint256[10]

details

Loan details. Refer to code block below ...

/// @return info The remaining information for the loan:
///                  info[0] = principalOwed
///                  info[1] = APR
///                  info[2] = APRLateFee
///                  info[3] = paymentDueBy
///                  info[4] = paymentsRemaining
///                  info[5] = term
///                  info[6] = paymentInterval
///                  info[7] = offerExpiry
///                  info[8] = gracePeriod
///                  info[9] = loanState

amountOwed()

Returns information for amount owed on next payment of a particular loan

function amountOwed(uint256 id) public view returns (
    uint256 principal, 
    uint256 interest,
    uint256 lateFee, 
    uint256 total
);
TypeNameDescription

uint256

id

The ID of the loan.

Returns

TypeNameDescription

uint256

principal

The amount of principal owed.

uint256

interest

The amount of interest owed.

uint256

lateFee

The amount of late fees owed.

uint256

total

Full amount owed, combining principal plus interest.

Write Functions - Core

acceptOffer()

Funds and initiates a loan.

function acceptOffer(uint256 id) external nonReentrant;
TypeNameDescription

uint256

id

The ID of the loan to pay off early.

Emits the OfferAccepted() event

callLoan()

Pays off the loan in full, plus additional interest for paymentInterval.

function callLoan(uint256 id) external nonReentrant;
TypeNameDescription

uint256

id

The ID of the loan to pay off early.

Emits the LoanCalled() event

cancelOffer()

Cancels a loan offer.

function cancelOffer(uint256 id) isUnderwriter external;
TypeNameDescription

uint256

id

The ID of the loan.

Emits the OfferCancelled() event

createOffer()

Create a loan offer.

function createOffer(
    address borrower,
    uint256 borrowAmount,
    uint256 APR,
    uint256 APRLateFee,
    uint256 term,
    uint256 paymentInterval,
    uint256 gracePeriod,
    int8 paymentSchedule
) isUnderwriter external;
TypeNameDescription

address

borrower

The address to borrow (that receives the loan)

uint256

borrowAmount

The amount to borrow (in other words, initial principal).

uint256

APR

The annualized percentage rate charged on the outstanding principal.

uint256

APRLateFee

The APR charged for late payments.

uint256

term

The term or "duration" of the loan (number of paymentIntervals that will occur).

uint256

paymentInterval

The interval of time between payments (in seconds).

uint256

gracePeriod

The number of seconds a borrower has to makePayment() before loan could default.

int8

paymentSchedule

The payment schedule type ("Bullet" or "Amortization").

Emits the OfferCreated() event

makePayment()

Make a payment on a loan. Anyone is allowed to make a payment on someone's loan.

function makePayment(uint256 id) external nonReentrant;
TypeNameDescription

uint256

id

The ID of the loan.

Emits the PaymentMade() event

markDefault()

Mark a loan insolvent if a payment hasn't been made beyond the corresponding grace period.

function markDefault(uint256 id) external isUnderwriter;
TypeNameDescription

uint256

id

The ID of the loan.

Emits the DefaultMarked() event

markRepaid()

Underwriter specifies a loan has been repaid fully via interest deposits in terms of off-chain debt.

function markRepaid(uint256 id) external isUnderwriter;
TypeNameDescription

uint256

id

The ID of the loan.

Emits the RepaidMarked() event

processPayment()

Process a payment for a loan, on behalf of another borrower.

function processPayment(uint256 id) external nonReentrant;
TypeNameDescription

uint256

id

The ID of the loan.

Emits the PaymentMade() event

resolveDefault()

Make a full (or partial) payment to resolve an insolvent loan.

function resolveDefault(uint256 id, uint256 amount) external;
TypeNameDescription

uint256

id

The ID of the loan.

uint256

amount

The amount of principal to pay down.

Emits the DefaultResolved() event

supplyInterest()

Supply interest to a repaid loan (for arbitrary interest repayment).

function supplyInterest(uint256 id, uint256 amount) external nonReentrant;
TypeNameDescription

uint256

id

The ID of the loan.

uint256

amount

The amount of interest to supply.

Emits the InterestSupplied() event

updateOCTYDL()

Updates the OCT_YDL endpoint.

function updateOCTYDL(address _OCT_YDL) external;
TypeNameDescription

address

_OCT_YDL

The new address for OCT_YDL.

Emits the UpdatedOCTYDL() event

Write Functions - Loan Management

applyCombine()

Combines multiple loans into a single loan.

function applyCombine(uint256 id) external;
TypeNameDescription

uint256

id

The ID to reference from "combinations" mapping.

Emits the CombineApplied() and CombineLoanCreated() event(s)

applyConversionToAmortization()

Converts a loan to amortization payment schedule.

function applyConversionToAmortization(uint256 id) external;
TypeNameDescription

uint256

id

The ID for the loan.

Emits the ConversionToAmortizationApplied() event

applyConversionBullet()

Converts a loan to bullet payment schedule.

function applyConversionToBullet(uint256 id) external;
TypeNameDescription

uint256

id

The ID for the loan.

Emits the ConversionToBulletApplied() event

applyExtension()

Applies an extension to a loan.

function applyExtension(uint256 id) external;
TypeNameDescription

uint256

id

The ID for the loan.

Emits the ExtensionApplied() event

applyRefinance()

Refinances a loan.

function applyRefinance(uint256 id) external;
TypeNameDescription

uint256

id

The ID for the loan.

Emits the RefinanceApplied()

approveCombine()

Approves a borrower for combining loans.

function approveCombine(
    uint256[] calldata loanIDs, 
    uint256 term,
    uint256 paymentInterval, 
    uint256 gracePeriod,
    int8 paymentSchedule
) external isUnderwriter;
TypeNameDescription

uint256[]

loanIDs

The IDs of the loans that can be combined.

uint256

term

The term that loans can be combined into.

uint256

paymentInterval

The paymentInterval that loans can be combined into.

uint256

gracePeriod

The number of seconds a borrower has to makePayment() before loan could default.

int8

paymentSchedule

The payment schedule of the loan (0 = "Bullet" or 1 = "Amortization").

Emits the CombineApproved() event

approveConversionToAmortization()

Approves a loan for conversion to amortization payment schedule.

function approveConversionToAmortization(uint256 id) external isUnderwriter;
TypeNameDescription

uint256

id

The ID for the loan.

Emits the ConversionToAmortizationApproved() event

approveConversionToBullet()

Approves a loan for conversion to bullet payment schedule.

function approveConversionToBullet(uint256 id) external isUnderwriter;
TypeNameDescription

uint256

id

The ID for the loan.

Emits the ConversionToBulletApproved() event

approveExtension()

Approves an extension for a loan.

function approveExtension(uint256 id, uint256 intervals) external isUnderwriter;
TypeNameDescription

uint256

id

The ID for the loan.

uint256

intervals

The amount of intervals to approve for extension.

Emits the ExtensionApproved() event

approveRefinance()

Approves a loan for refinancing.

function approveRefinance(uint256 id, uint256 apr) external isUnderwriter;
TypeNameDescription

uint256

id

The ID for the loan.

uint256

APR

The APR the loan can refinance to.

Emits the RefinanceApproved() event

unapproveCombine()

Unapproves a borrower for combining loans.

function unapproveCombine(uint256 id) external isUnderwriter;
TypeNameDescription

uint256

id

The ID of the combine to unapprove.

Emits the CombineUnapproved() event

unapproveConversionToAmortization()

Unapproves a loan for conversion to amortization payment schedule.

function unapproveConversionToAmortization(uint256 id) external isUnderwriter;
TypeNameDescription

uint256

id

The ID for the loan.

Emits the ConversionToAmortizationUnapproved() event

unapproveConversionBullet()

Unapproves a loan for conversion to bullet payment schedule.

function unapproveConversionToBullet(uint256 id) external isUnderwriter;
TypeNameDescription

uint256

id

The ID for the loan.

Emits the ConversionToBulletUnapproved() event

unapproveExtension()

Unapproves an extension for a loan.

function unapproveExtension(uint256 id) external isUnderwriter;
TypeNameDescription

uint256

id

The ID for the loan.

Emits the ExtensionUnapproved() event

unapproveRefinance()

Unapproves a loan for refinancing.

function unapproveRefinance(uint256 id) external isUnderwriter;
TypeNameDescription

uint256

id

The ID for the loan.

Emits the RefinanceUnapproved() event

Events

CombineApplied()

Emitted during applyCombine()

event CombineApplied(
    address indexed borrower, 
    uint256[] loanIDs, 
    uint256 term,
    uint256 paymentInterval,
    uint256 gracePeriod,
    int8 indexed paymentSchedule
);
TypeIndexedNameDescription

address

True

borrower

The borrower combining their loans.

uint256[]

False

loanIDs

The IDs of the loans that were combined.

uint256

False

term

The resulting term of the combined loan.

uint256

False

paymentInterval

The resulting paymentInterval of the combined loan.

uint256

False

gracePeriod

The resulting gracePeriod of the combined loan.

int8

True

paymentSchedule

The payment schedule of the combined loan (0 = "Bullet" or 1 = "Amortization").

CombineApproved()

Emitted during approveCombine()

event CombineApproved(
    uint256 indexed id, 
    uint256[] loanIDs,
    uint256 term,
    uint256 paymentInterval, 
    uint256 gracePeriod,
    uint256 expires,
    int8 indexed paymentSchedule
);
TypeIndexedNameDescription

uint256

True

id

The ID of the combination approval in "combinations" mapping.

uint256[]

False

loanIDs

The IDs of the loans that can be combined.

uint256

False

term

The resulting term of the combined loan that is permitted.

uint256

False

paymentInterval

The resulting paymentInterval of the combined loan.

uint256

False

gracePeriod

The resulting gracePeriod of the combined loan that is permitted.

uint256

False

expires

The expiration of this combination.

int8

True

paymentSchedule

The payment schedule of the combined loan (0 = "Bullet" or 1 = "Amortization").

CombineLoanCreated()

Emitted during applyCombine()

event CombineLoanCreated(
    address indexed borrower,
    uint256 indexed id,
    uint256 borrowAmount,
    uint256 APR,
    uint256 APRLateFee,
    uint256 paymentDueBy,
    uint256 term,
    uint256 paymentInterval,
    uint256 gracePeriod,
    int8 indexed paymentSchedule
);
TypeIndexedNameDescription

address

True

borrower

The address borrowing (that will receive the loan).

uint256

True

id

Identifier for the loan offer created.

uint256

False

borrowAmount

The amount to borrow (in other words, initial principal).

uint256

False

APR

The annualized percentage rate charged on the outstanding principal.

uint256

False

APRLateFee

The APR charged for late payments.

uint256

False

paymentDueBy

The timestamp (in seconds) for when the next payment is due.

uint256

False

term

The term or "duration" of the loan (number of paymentIntervals that will occur).

uint256

False

paymentInterval

The interval of time between payments (in seconds).

uint256

False

gracePeriod

The number of seconds a borrower has to makePayment() before loan could default.

int8

True

paymentSchedule

The payment schedule of the combined loan (0 = "Bullet" or 1 = "Amortization").

CombineUnapproved()

Emitted during unapproveCombine()

event CombineUnapproved(uint256 id);
TypeIndexedNameDescription

uint256

True

id

The ID of the combine to unapprove.

ConversionToAmortizationApplied()

Emitted during applyConversionToAmortization()

event ConversionToAmortizationApplied(uint256 indexed id);
TypeIndexedNameDescription

uint256

True

id

The loan ID converted to amortization payment schedule.

ConversionToAmortizationApproved()

Emitted during approveConversionToAmortization()

event ConversionToAmortizationApproved(uint256 indexed id);
TypeIndexedNameDescription

uint256

True

id

The loan ID approved for conversion.

ConversionToAmortizationUnapproved()

Emitted during unapproveConversionToAmortization()

event ConversionToAmortizationUnapproved(uint256 indexed id);
TypeIndexedNameDescription

uint256

True

id

The loan ID unapproved for conversion.

ConversionToBulletApplied()

Emitted during applyConversionBullet()

event ConversionToBulletApplied(uint256 indexed id);
TypeIndexedNameDescription

uint256

True

id

The loan ID converted to bullet payment schedule.

ConversionToBulletApproved()

Emitted during approveConversionToBullet()

event ConversionToBulletApproved(uint256 indexed id);
TypeIndexedNameDescription

uint256

True

id

The loan ID approved for conversion.

ConversionToBulletUnapproved()

Emitted during unapproveConversionBullet()

event ConversionToBulletUnapproved(uint256 indexed id);
TypeIndexedNameDescription

uint256

True

id

The loan ID unapproved for conversion.

DefaultMarked()

Emitted during markDefault()

event DefaultMarked(uint256 indexed id, uint256 principalDefaulted);
TypeIndexedNameDescription

uint256

True

id

Identifier for the loan which is now "defaulted".

uint256

False

principalDefaulted

The amount defaulted on.

DefaultResolved()

Emitted during resolveDefault()

event DefaultResolved(
    uint256 indexed id, 
    uint256 amount, 
    address indexed payee, 
    bool resolved
);
TypeIndexedNameDescription

uint256

True

id

The identifier for the loan in default that is resolved (or partially).

uint256

False

amount

The amount of principal paid back.

address

True

payee

The address responsible for resolving the default.

bool

False

resolved

Denotes if the loan is fully resolved (false if partial).

ExtensionApplied()

Emitted during applyExtension()

event ExtensionApplied(uint256 indexed id, uint256 intervals);
TypeIndexedNameDescription

uint256

True

id

The identifier of the loan extending its payment schedule.

uint256

False

interval

The number of intervals the loan is extended for.

ExtensionApproved()

Emitted during approveExtension()

event ExtensionApproved(uint256 indexed id, uint256 intervals);
TypeIndexedNameDescription

uint256

True

id

The identifier of the loan receiving approval for extension.

uint256

False

intervals

The number of intervals the approved loan may be extended.

ExtensionUnapproved()

Emitted during unapproveExtension()

event ExtensionUnapproved(uint256 indexed id);
TypeIndexedNameDescription

uint256

True

id

The identifier of the loan losing approval for extension.

InterestSupplied()

Emitted during supplyInterest()

event InterestSupplied(
    uint256 indexed id, 
    uint256 amount, 
    address indexed payee
);
TypeIndexedNameDescription

uint256

True

id

The identifier for the loan that is supplied additional interest.

uint256

False

amount

The amount of interest supplied.

address

True

payee

The address responsible for supplying additional interest.

LoanCalled()

Emitted during callLoan()

event LoanCalled(
    uint256 indexed id, 
    uint256 amount, 
    uint256 principal, 
    uint256 interest, 
    uint256 lateFee
);
TypeIndexedNameDescription

uint256

True

id

Identifier for the loan which was called.

uint256

False

amount

The total amount of the payment.

uint256

False

principal

The principal portion of "amount" paid.

uint256

False

interest

The interest portion of "amount" paid.

uint256

False

lateFee

The lateFee portion of "amount" paid.

OfferAccepted()

Emitted during acceptOffer()

event OfferAccepted(
    uint256 indexed id, 
    uint256 principal, 
    address indexed borrower, 
    uint256 paymentDueBy
);
TypeIndexedNameDescription

uint256

True

id

Identifier for the offer accepted.

uint256

False

principal

The amount of stablecoin lent out.

address

True

borrower

The address borrowing the amount (principal).

uint256

False

paymentDueBy

Timestamp (unix seconds) by which next payment is due.

OfferCancelled()

Emitted during cancelOffer()

event OfferCancelled(uint256 indexed id);
TypeIndexedNameDescription

uint256

True

id

Identifier for the loan offer cancelled.

OfferCreated()

Emitted during createOffer()

event OfferCreated(
    address indexed borrower,
    uint256 indexed id,
    uint256 borrowAmount,
    uint256 APR,
    uint256 APRLateFee,
    uint256 term,
    uint256 paymentInterval,
    uint256 offerExpiry,
    uint256 gracePeriod,
    int8 indexed paymentSchedule
);
TypeIndexedNameDescription

address

True

borrower

The address borrowing (that will receive the loan).

uint256

True

id

Identifier for the loan offer created.

uint256

False

borrowAmount

The amount to borrow (in other words, initial principal).

uint256

False

APR

The annualized percentage rate charged on the outstanding principal.

uint256

False

APRLateFee

The APR charged for late payments.

uint256

False

term

The term or "duration" of the loan (number of paymentIntervals that will occur).

uint256

False

paymentInterval

The interval of time between payments (in seconds).

uint256

False

offerExpiry

The block.timestamp at which the offer for this loan expires (hardcoded 2 weeks).

uint256

False

gracePeriod

The number of seconds a borrower has to makePayment() before loan could default.

int8

True

paymentSchedule

The payment schedule type ("Bullet" or "Amortization").

PaymentMade()

Emitted during makePayment() and processPayment()

event PaymentMade(
    uint256 indexed id, 
    address indexed payee, 
    uint256 amount, 
    uint256 principal, 
    uint256 interest, 
    uint256 lateFee, 
    uint256 nextPaymentDue
);
TypeIndexedNameDescription

uint256

True

id

Identifier for the loan on which payment is made.

address

True

payee

The address which made payment on the loan.

uint256

False

amount

The total amount of the payment.

uint256

False

principal

The principal portion of "amount" paid.

uint256

False

interest

The interest portion of "amount" paid.

uint256

False

lateFee

The lateFee portion of "amount" paid.

uint256

False

nextPaymentDue

The timestamp by which next payment is due.

RefinanceApplied()

Emitted during applyRefinance()

event RefinanceApplied(uint256 indexed id, uint256 APRNew, uint256 APRPrior);
TypeIndexedNameDescription

uint256

True

id

The loan ID refinancing its APR.

uint256

False

APRNew

The new APR of the loan.

uint256

False

APRPrior

The prior APR of the loan.

RefinanceApproved()

Emitted during approveRefinance()

event RefinanceApproved(uint256 indexed id, uint256 APR);
TypeIndexedNameDescription

uint256

True

id

The loan ID approved for refinance.

uint256

False

APR

The APR the loan is approved to refinance to.

RefinanceUnapproved()

Emitted during unapproveRefinance()

event RefinanceUnapproved(uint256 indexed id);
TypeIndexedNameDescription

uint256

True

id

The loan ID unapproved for refinance.

RepaidMarked()

Emitted during markRepaid()

event RepaidMarked(uint256 indexed id);
TypeIndexedNameDescription

uint256

True

id

Identifier for the loan which is now "repaid".

UpdatedOCTYDL()

Emitted during updateOCTYDL()

event UpdatedOCTYDL(address indexed newOCT, address indexed oldOCT);
TypeIndexedNameDescription

address

True

newOCT

The new OCT_YDL contract.

address

True

oldOCT

The old OCT_YDL contract.

Last updated

Zivoe Finance - Official Documentation