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
Type | Name | Description |
---|---|---|
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, |
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
Loan
This struct stores information for loans.
Type | Name | Description |
---|---|---|
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
Combine
This struct stores information for loan combinations.
Type | Name | Description |
---|---|---|
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
LoanState
This enumerator tracks loan states.
State | Description |
---|---|
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
LoanSchedule
This enumerator tracks the payment schedule type for a loan.
State | Description |
---|---|
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
canPush() - Permission for owner to call
pushToLocker()
. See ZivoeLocker.solcanPull() - Permission for owner to call
pullFromLocker()
. See ZivoeLocker.solcanPullPartial() - Permission for owner to call
pullFromLockerPartial()
. See ZivoeLocker.solloanInfo() - Returns information for a given loan. Refer to Loan
amountOwed() - Returns information for amount owed on next payment of a particular loan
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
applyCombine() - Combines multiple loans into a single loan.
applyConversionToAmortization() - Converts a loan to amortization payment schedule.
applyConversionBullet() - Converts a loan to bullet payment schedule.
applyExtension() - Applies an extension to a loan.
applyRefinance() - Refinances a loan.
approveCombine() - Approves a borrower for combining loans.
approveConversionToAmortization() - Approves a loan for conversion to amortization payment schedule.
approveConversionToBullet() - Approves a loan for conversion to bullet payment schedule.
approveExtension() - Approves an extension for a loan.
approveRefinance() - Approves a loan for refinancing.
unapproveCombine() - Unapproves a borrower for combining loans.
unapproveConversionToAmortization() - Unapproves a loan for conversion to amortization payment schedule.
unapproveConversionBullet() - Unapproves a loan for conversion to bullet payment schedule.
unapproveExtension() - Unapproves an extension for a loan.
unapproveRefinance() - Unapproves a loan for refinancing.
Read Functions
canPush()
canPush()
Permission for owner to call pushToLocker()
. See ZivoeLocker.sol
canPull()
canPull()
Permission for owner to call pullFromLocker()
. See ZivoeLocker.sol
canPullPartial()
canPullPartial()
Permission for owner to call pullFromLockerPartial()
. See ZivoeLocker.sol
loanInfo()
loanInfo()
Returns information for a given loan. Refer to Loan
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the loan. |
Returns
Type | Name | Description |
---|---|---|
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 ... |
amountOwed()
amountOwed()
Returns information for amount owed on next payment of a particular loan
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the loan. |
Returns
Type | Name | Description |
---|---|---|
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()
acceptOffer()
Funds and initiates a loan.
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the loan to pay off early. |
Emits the OfferAccepted() event
callLoan()
callLoan()
Pays off the loan in full, plus additional interest for paymentInterval.
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the loan to pay off early. |
Emits the LoanCalled() event
cancelOffer()
cancelOffer()
Cancels a loan offer.
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the loan. |
Emits the OfferCancelled() event
createOffer()
createOffer()
Create a loan offer.
Type | Name | Description |
---|---|---|
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()
makePayment()
Make a payment on a loan. Anyone is allowed to make a payment on someone's loan.
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the loan. |
Emits the PaymentMade() event
markDefault()
markDefault()
Mark a loan insolvent if a payment hasn't been made beyond the corresponding grace period.
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the loan. |
Emits the DefaultMarked() event
markRepaid()
markRepaid()
Underwriter specifies a loan has been repaid fully via interest deposits in terms of off-chain debt.
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the loan. |
Emits the RepaidMarked() event
processPayment()
processPayment()
Process a payment for a loan, on behalf of another borrower.
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the loan. |
Emits the PaymentMade() event
resolveDefault()
resolveDefault()
Make a full (or partial) payment to resolve an insolvent loan.
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the loan. |
uint256 | amount | The amount of principal to pay down. |
Emits the DefaultResolved() event
supplyInterest()
supplyInterest()
Supply interest to a repaid loan (for arbitrary interest repayment).
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the loan. |
uint256 | amount | The amount of interest to supply. |
Emits the InterestSupplied() event
updateOCTYDL()
updateOCTYDL()
Updates the OCT_YDL endpoint.
Type | Name | Description |
---|---|---|
address |
| The new address for OCT_YDL. |
Emits the UpdatedOCTYDL() event
Write Functions - Loan Management
applyCombine()
applyCombine()
Combines multiple loans into a single loan.
Type | Name | Description |
---|---|---|
uint256 | id | The ID to reference from "combinations" mapping. |
Emits the CombineApplied() and CombineLoanCreated() event(s)
applyConversionToAmortization()
applyConversionToAmortization()
Converts a loan to amortization payment schedule.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
Emits the ConversionToAmortizationApplied() event
applyConversionBullet()
applyConversionBullet()
Converts a loan to bullet payment schedule.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
Emits the ConversionToBulletApplied() event
applyExtension()
applyExtension()
Applies an extension to a loan.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
Emits the ExtensionApplied() event
applyRefinance()
applyRefinance()
Refinances a loan.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
Emits the RefinanceApplied()
approveCombine()
approveCombine()
Approves a borrower for combining loans.
Type | Name | Description |
---|---|---|
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()
approveConversionToAmortization()
Approves a loan for conversion to amortization payment schedule.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
Emits the ConversionToAmortizationApproved() event
approveConversionToBullet()
approveConversionToBullet()
Approves a loan for conversion to bullet payment schedule.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
Emits the ConversionToBulletApproved() event
approveExtension()
approveExtension()
Approves an extension for a loan.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
uint256 | intervals | The amount of intervals to approve for extension. |
Emits the ExtensionApproved() event
approveRefinance()
approveRefinance()
Approves a loan for refinancing.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
uint256 | APR | The APR the loan can refinance to. |
Emits the RefinanceApproved() event
unapproveCombine()
unapproveCombine()
Unapproves a borrower for combining loans.
Type | Name | Description |
---|---|---|
uint256 | id | The ID of the combine to unapprove. |
Emits the CombineUnapproved() event
unapproveConversionToAmortization()
unapproveConversionToAmortization()
Unapproves a loan for conversion to amortization payment schedule.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
Emits the ConversionToAmortizationUnapproved() event
unapproveConversionBullet()
unapproveConversionBullet()
Unapproves a loan for conversion to bullet payment schedule.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
Emits the ConversionToBulletUnapproved() event
unapproveExtension()
unapproveExtension()
Unapproves an extension for a loan.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
Emits the ExtensionUnapproved() event
unapproveRefinance()
unapproveRefinance()
Unapproves a loan for refinancing.
Type | Name | Description |
---|---|---|
uint256 | id | The ID for the loan. |
Emits the RefinanceUnapproved() event
Events
CombineApplied()
CombineApplied()
Emitted during applyCombine()
Type | Indexed | Name | Description |
---|---|---|---|
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()
CombineApproved()
Emitted during approveCombine()
Type | Indexed | Name | Description |
---|---|---|---|
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()
CombineLoanCreated()
Emitted during applyCombine()
Type | Indexed | Name | Description |
---|---|---|---|
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()
CombineUnapproved()
Emitted during unapproveCombine()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | The ID of the combine to unapprove. |
ConversionToAmortizationApplied()
ConversionToAmortizationApplied()
Emitted during applyConversionToAmortization()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | The loan ID converted to amortization payment schedule. |
ConversionToAmortizationApproved()
ConversionToAmortizationApproved()
Emitted during approveConversionToAmortization()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | The loan ID approved for conversion. |
ConversionToAmortizationUnapproved()
ConversionToAmortizationUnapproved()
Emitted during unapproveConversionToAmortization()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | The loan ID unapproved for conversion. |
ConversionToBulletApplied()
ConversionToBulletApplied()
Emitted during applyConversionBullet()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | The loan ID converted to bullet payment schedule. |
ConversionToBulletApproved()
ConversionToBulletApproved()
Emitted during approveConversionToBullet()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | The loan ID approved for conversion. |
ConversionToBulletUnapproved()
ConversionToBulletUnapproved()
Emitted during unapproveConversionBullet()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | The loan ID unapproved for conversion. |
DefaultMarked()
DefaultMarked()
Emitted during markDefault()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | Identifier for the loan which is now "defaulted". |
uint256 | False | principalDefaulted | The amount defaulted on. |
DefaultResolved()
DefaultResolved()
Emitted during resolveDefault()
Type | Indexed | Name | Description |
---|---|---|---|
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()
ExtensionApplied()
Emitted during applyExtension()
Type | Indexed | Name | Description |
---|---|---|---|
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()
ExtensionApproved()
Emitted during approveExtension()
Type | Indexed | Name | Description |
---|---|---|---|
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()
ExtensionUnapproved()
Emitted during unapproveExtension()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | The identifier of the loan losing approval for extension. |
InterestSupplied()
InterestSupplied()
Emitted during supplyInterest()
Type | Indexed | Name | Description |
---|---|---|---|
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()
LoanCalled()
Emitted during callLoan()
Type | Indexed | Name | Description |
---|---|---|---|
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()
OfferAccepted()
Emitted during acceptOffer()
Type | Indexed | Name | Description |
---|---|---|---|
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()
OfferCancelled()
Emitted during cancelOffer()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | Identifier for the loan offer cancelled. |
OfferCreated()
OfferCreated()
Emitted during createOffer()
Type | Indexed | Name | Description |
---|---|---|---|
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()
PaymentMade()
Emitted during makePayment() and processPayment()
Type | Indexed | Name | Description |
---|---|---|---|
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()
RefinanceApplied()
Emitted during applyRefinance()
Type | Indexed | Name | Description |
---|---|---|---|
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()
RefinanceApproved()
Emitted during approveRefinance()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | The loan ID approved for refinance. |
uint256 | False | APR | The APR the loan is approved to refinance to. |
RefinanceUnapproved()
RefinanceUnapproved()
Emitted during unapproveRefinance()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | The loan ID unapproved for refinance. |
RepaidMarked()
RepaidMarked()
Emitted during markRepaid()
Type | Indexed | Name | Description |
---|---|---|---|
uint256 | True | id | Identifier for the loan which is now "repaid". |
UpdatedOCTYDL()
UpdatedOCTYDL()
Emitted during updateOCTYDL()
Type | Indexed | Name | Description |
---|---|---|---|
address | True | newOCT | The new OCT_YDL contract. |
address | True | oldOCT | The old OCT_YDL contract. |
Last updated