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
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 => 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.
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").
Combine
Combine
This struct stores information for loan combinations.
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.
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.
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
function canPush() public override pure returns (bool) { return true; }
canPull()
canPull()
Permission for owner to call pullFromLocker()
. See ZivoeLocker.sol
function canPull() public override pure returns (bool) { return true; }
canPullPartial()
canPullPartial()
Permission for owner to call pullFromLockerPartial()
. See ZivoeLocker.sol
function canPullPartial() public override pure returns (bool) { return true; }
loanInfo()
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
);
uint256
id
The ID of the loan.
Returns
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()
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
);
uint256
id
The ID of the loan.
Returns
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.
function acceptOffer(uint256 id) external nonReentrant;
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.
function callLoan(uint256 id) external nonReentrant;
uint256
id
The ID of the loan to pay off early.
Emits the LoanCalled() event
cancelOffer()
cancelOffer()
Cancels a loan offer.
function cancelOffer(uint256 id) isUnderwriter external;
uint256
id
The ID of the loan.
Emits the OfferCancelled() event
createOffer()
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;
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.
function makePayment(uint256 id) external nonReentrant;
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.
function markDefault(uint256 id) external isUnderwriter;
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.
function markRepaid(uint256 id) external isUnderwriter;
uint256
id
The ID of the loan.
Emits the RepaidMarked() event
processPayment()
processPayment()
Process a payment for a loan, on behalf of another borrower.
function processPayment(uint256 id) external nonReentrant;
uint256
id
The ID of the loan.
Emits the PaymentMade() event
resolveDefault()
resolveDefault()
Make a full (or partial) payment to resolve an insolvent loan.
function resolveDefault(uint256 id, uint256 amount) external;
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).
function supplyInterest(uint256 id, uint256 amount) external nonReentrant;
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.
function updateOCTYDL(address _OCT_YDL) external;
address
_OCT_YDL
The new address for OCT_YDL.
Emits the UpdatedOCTYDL() event
Write Functions - Loan Management
applyCombine()
applyCombine()
Combines multiple loans into a single loan.
function applyCombine(uint256 id) external;
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.
function applyConversionToAmortization(uint256 id) external;
uint256
id
The ID for the loan.
Emits the ConversionToAmortizationApplied() event
applyConversionBullet()
applyConversionBullet()
Converts a loan to bullet payment schedule.
function applyConversionToBullet(uint256 id) external;
uint256
id
The ID for the loan.
Emits the ConversionToBulletApplied() event
applyExtension()
applyExtension()
Applies an extension to a loan.
function applyExtension(uint256 id) external;
uint256
id
The ID for the loan.
Emits the ExtensionApplied() event
applyRefinance()
applyRefinance()
Refinances a loan.
function applyRefinance(uint256 id) external;
uint256
id
The ID for the loan.
Emits the RefinanceApplied()
approveCombine()
approveCombine()
Approves a borrower for combining loans.
function approveCombine(
uint256[] calldata loanIDs,
uint256 term,
uint256 paymentInterval,
uint256 gracePeriod,
int8 paymentSchedule
) external isUnderwriter;
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.
function approveConversionToAmortization(uint256 id) external isUnderwriter;
uint256
id
The ID for the loan.
Emits the ConversionToAmortizationApproved() event
approveConversionToBullet()
approveConversionToBullet()
Approves a loan for conversion to bullet payment schedule.
function approveConversionToBullet(uint256 id) external isUnderwriter;
uint256
id
The ID for the loan.
Emits the ConversionToBulletApproved() event
approveExtension()
approveExtension()
Approves an extension for a loan.
function approveExtension(uint256 id, uint256 intervals) external isUnderwriter;
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.
function approveRefinance(uint256 id, uint256 apr) external isUnderwriter;
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.
function unapproveCombine(uint256 id) external isUnderwriter;
uint256
id
The ID of the combine to unapprove.
Emits the CombineUnapproved() event
unapproveConversionToAmortization()
unapproveConversionToAmortization()
Unapproves a loan for conversion to amortization payment schedule.
function unapproveConversionToAmortization(uint256 id) external isUnderwriter;
uint256
id
The ID for the loan.
Emits the ConversionToAmortizationUnapproved() event
unapproveConversionBullet()
unapproveConversionBullet()
Unapproves a loan for conversion to bullet payment schedule.
function unapproveConversionToBullet(uint256 id) external isUnderwriter;
uint256
id
The ID for the loan.
Emits the ConversionToBulletUnapproved() event
unapproveExtension()
unapproveExtension()
Unapproves an extension for a loan.
function unapproveExtension(uint256 id) external isUnderwriter;
uint256
id
The ID for the loan.
Emits the ExtensionUnapproved() event
unapproveRefinance()
unapproveRefinance()
Unapproves a loan for refinancing.
function unapproveRefinance(uint256 id) external isUnderwriter;
uint256
id
The ID for the loan.
Emits the RefinanceUnapproved() event
Events
CombineApplied()
CombineApplied()
Emitted during applyCombine()
event CombineApplied(
address indexed borrower,
uint256[] loanIDs,
uint256 term,
uint256 paymentInterval,
uint256 gracePeriod,
int8 indexed paymentSchedule
);
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()
event CombineApproved(
uint256 indexed id,
uint256[] loanIDs,
uint256 term,
uint256 paymentInterval,
uint256 gracePeriod,
uint256 expires,
int8 indexed paymentSchedule
);
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()
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
);
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()
event CombineUnapproved(uint256 id);
uint256
True
id
The ID of the combine to unapprove.
ConversionToAmortizationApplied()
ConversionToAmortizationApplied()
Emitted during applyConversionToAmortization()
event ConversionToAmortizationApplied(uint256 indexed id);
uint256
True
id
The loan ID converted to amortization payment schedule.
ConversionToAmortizationApproved()
ConversionToAmortizationApproved()
Emitted during approveConversionToAmortization()
event ConversionToAmortizationApproved(uint256 indexed id);
uint256
True
id
The loan ID approved for conversion.
ConversionToAmortizationUnapproved()
ConversionToAmortizationUnapproved()
Emitted during unapproveConversionToAmortization()
event ConversionToAmortizationUnapproved(uint256 indexed id);
uint256
True
id
The loan ID unapproved for conversion.
ConversionToBulletApplied()
ConversionToBulletApplied()
Emitted during applyConversionBullet()
event ConversionToBulletApplied(uint256 indexed id);
uint256
True
id
The loan ID converted to bullet payment schedule.
ConversionToBulletApproved()
ConversionToBulletApproved()
Emitted during approveConversionToBullet()
event ConversionToBulletApproved(uint256 indexed id);
uint256
True
id
The loan ID approved for conversion.
ConversionToBulletUnapproved()
ConversionToBulletUnapproved()
Emitted during unapproveConversionBullet()
event ConversionToBulletUnapproved(uint256 indexed id);
uint256
True
id
The loan ID unapproved for conversion.
DefaultMarked()
DefaultMarked()
Emitted during markDefault()
event DefaultMarked(uint256 indexed id, uint256 principalDefaulted);
uint256
True
id
Identifier for the loan which is now "defaulted".
uint256
False
principalDefaulted
The amount defaulted on.
DefaultResolved()
DefaultResolved()
Emitted during resolveDefault()
event DefaultResolved(
uint256 indexed id,
uint256 amount,
address indexed payee,
bool resolved
);
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()
event ExtensionApplied(uint256 indexed id, uint256 intervals);
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()
event ExtensionApproved(uint256 indexed id, uint256 intervals);
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()
event ExtensionUnapproved(uint256 indexed id);
uint256
True
id
The identifier of the loan losing approval for extension.
InterestSupplied()
InterestSupplied()
Emitted during supplyInterest()
event InterestSupplied(
uint256 indexed id,
uint256 amount,
address indexed payee
);
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()
event LoanCalled(
uint256 indexed id,
uint256 amount,
uint256 principal,
uint256 interest,
uint256 lateFee
);
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()
event OfferAccepted(
uint256 indexed id,
uint256 principal,
address indexed borrower,
uint256 paymentDueBy
);
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()
event OfferCancelled(uint256 indexed id);
uint256
True
id
Identifier for the loan offer cancelled.
OfferCreated()
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
);
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()
event PaymentMade(
uint256 indexed id,
address indexed payee,
uint256 amount,
uint256 principal,
uint256 interest,
uint256 lateFee,
uint256 nextPaymentDue
);
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()
event RefinanceApplied(uint256 indexed id, uint256 APRNew, uint256 APRPrior);
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()
event RefinanceApproved(uint256 indexed id, uint256 APR);
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()
event RefinanceUnapproved(uint256 indexed id);
uint256
True
id
The loan ID unapproved for refinance.
RepaidMarked()
RepaidMarked()
Emitted during markRepaid()
event RepaidMarked(uint256 indexed id);
uint256
True
id
Identifier for the loan which is now "repaid".
UpdatedOCTYDL()
UpdatedOCTYDL()
Emitted during updateOCTYDL()
event UpdatedOCTYDL(address indexed newOCT, address indexed oldOCT);
address
True
newOCT
The new OCT_YDL contract.
address
True
oldOCT
The old OCT_YDL contract.
Last updated