View on GitHub

Sapling contracts

Sapling Contracts

Solidity API

SaplingLendingPool

Extends SaplingPoolContext with lending strategy.

loanDesk

address loanDesk

Address of the loan desk contract

treasury

address treasury

Address where the protocol fees are sent to

yieldSettledDay

uint256 yieldSettledDay

unix day on which the yield has been settled.

onlyLoanDesk

modifier onlyLoanDesk()

A modifier to limit access only to the loan desk contract

constructor

constructor() public

initialize

function initialize(address _poolToken, address _liquidityToken, address _accessControl, address _treasury, address _stakerAddress) public

Creates a Sapling pool.

Addresses must not be 0.

Name Type Description
_poolToken address ERC20 token contract address to be used as the pool issued token.
_liquidityToken address ERC20 token contract address to be used as pool liquidity currency.
_accessControl address Access control contract
_treasury address Address where the protocol fees are sent to
_stakerAddress address Staker address

setLoanDesk

function setLoanDesk(address _loanDesk) external

Links a new loan desk for the pool to use. Intended for use upon initial pool deployment.

Caller must be the governance. This setter may also be used to switch loan desks. If applicable: Outstanding loan operations must be concluded on the loan desk before the switch.

Name Type Description
_loanDesk address New LoanDesk address

setTreasury

function setTreasury(address _treasury) external

Designates a new treasury address for the pool.

Protocol fees will be sent to this address on every interest payment.

Name Type Description
_treasury address New treasury address

settleYield

function settleYield() public

Settle pending yield.

Calculates interest due since last update and increases preSettledYield, taking into account the protocol fee and the staker earnings.

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. Amount update can be due to offer update or cancellation. 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 loop call reduces gas, contract bytecode size, and reduces the risk of reentrancy._
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 amount can be offered.

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

canOpen

function canOpen() internal view returns (bool)

Indicates whether or not the contract can be opened in it’s current state.

Overrides a hook in SaplingStakerContext.

Name Type Description
[0] bool True if the conditions to open are met, false otherwise.

canClose

function canClose() internal view returns (bool)

Implementation of the abstract hook in SaplingManagedContext. Pool can be close when no funds remain committed to strategies.

strategizedFunds

function strategizedFunds() internal view returns (uint256)

Current amount of liquidity tokens in strategies, including both allocated and committed but excluding pending yield.

Overrides the same method in the base contract.

currentAPY

function currentAPY() external view returns (struct IPoolContext.APYBreakdown)

Estimate APY breakdown given the current pool state.

Name Type Description
[0] struct IPoolContext.APYBreakdown Current APY breakdown

breakdownEarnings

function breakdownEarnings(uint256 interestAmount) public view returns (uint256, uint256, uint256)

Breaks down an interest amount to shareholder yield, protocol fee and staker earnings.

Name Type Description
interestAmount uint256 Interest amount paid by the borrower
Name Type Description
[0] uint256 Amounts for (shareholderYield, protocolFee, stakerEarnings)
[1] uint256  
[2] uint256