View on GitHub

Sapling contracts

Sapling Contracts

Solidity API

ILendingPool

This interface defines LendingPool events, structs, and LoanDesk function hooks.

LoanDeskSet

event LoanDeskSet(address prevAddress, address newAddress)

Setter event

TreasurySet

event TreasurySet(address prevAddress, address newAddress)

Setter event

ProtocolRevenue

event ProtocolRevenue(address treasury, uint256 amount)

Event for when the protocol revenue is issued

LoanDefaulted

event LoanDefaulted(uint256 loanId, address borrower, uint256 stakerLoss, uint256 lenderLoss)

Event for when a loan is defaulted

OfferLiquidityAllocated

event OfferLiquidityAllocated(uint256 amount)

Event for when a liquidity is allocated for a loan offer

OfferLiquidityDeallocated

event OfferLiquidityDeallocated(uint256 amount)

Event for when the liquidity is removed from a loan offer

LoanRepaymentProcessed

event LoanRepaymentProcessed(uint256 loanId, address borrower, address payer, uint256 amount, uint256 interestAmount)

Event for when a loan repayments are made

onOfferAllocate

function onOfferAllocate(uint256 amount) external

Hook for a new loan offer. Caller must be the LoanDesk.

Name Type Description
amount uint256 Amount to be allocated for loan offers.

onOfferDeallocate

function onOfferDeallocate(uint256 amount) external

Hook for a loan offer amount update. Caller must be the LoanDesk.

Name Type Description
amount uint256 Previously allocated amount being returned.

onRepay

function onRepay(uint256 loanId, address borrower, address payer, uint256 transferAmount, uint256 interestPayable, uint256 borrowedTime) external

_Hook for repayments. Caller must be the LoanDesk.

 Parameters besides the loanId exists simply to avoid rereading it from the caller via additional inter 
 contract call. Avoiding a recursive call reduces gas and contract bytecode size._
Name Type Description
loanId uint256 ID of the loan which has just been borrowed
borrower address Borrower address
payer address Actual payer address
transferAmount uint256 Amount chargeable
interestPayable uint256 Amount of interest paid, this value is already included in the payment amount
borrowedTime uint256 Block timestamp when this loan was borrowed

onDefault

function onDefault(uint256 loanId, uint256 principalLoss, uint256 yieldLoss) external returns (uint256, uint256)

Hook for defaulting a loan. Caller must be the LoanDesk. Defaulting a loan will cover the loss using the staked funds. If these funds are not sufficient, the lenders will share the loss.

Name Type Description
loanId uint256 ID of the loan to default
principalLoss uint256 Unpaid principal amount to resolve
yieldLoss uint256 Unpaid yield amount to resolve

canOffer

function canOffer(uint256 amount) external view returns (bool)

View indicating whether or not a given loan can be offered by the staker.

Hook for checking if the lending pool can provide liquidity for the total offered loans amount.

Name Type Description
amount uint256 Amount to check for new loan allocation
Name Type Description
[0] bool True if the pool has sufficient lending liquidity, false otherwise