Lender
Inherits: Ledger
Author: Aloe Labs, Inc.
"Test everything; hold fast what is good." - 1 Thessalonians 5:21
Functions
constructor
constructor(address reserve) Ledger(reserve);
initialize
function initialize() external;
setRateModelAndReserveFactor
Sets the rateModel
and reserveFactor
. Only the FACTORY
can call this.
function setRateModelAndReserveFactor(IRateModel rateModel_, uint8 reserveFactor_) external;
setRewardsRate
Sets the rewards rate. May be 0. Only the FACTORY
can call this.
function setRewardsRate(uint64 rate) external;
Parameters
Name | Type | Description |
---|---|---|
rate | uint64 | The rewards rate, specified in [token units per second]. If non-zero, keep between 10^17 and 10^28 token units per year for smooth operation. Assuming FACTORY.rewardsToken() has 18 decimals, this is between 0.1 and 10 billion tokens per year. |
whitelist
Allows borrower
to call borrow
. One the FACTORY
can call this.
function whitelist(address borrower) external;
claimRewards
function claimRewards(address owner) external returns (uint96 earned);
deposit
Mints shares
to beneficiary
by depositing exactly amount
of underlying tokens
deposit
is more efficient than mint
and is the recommended way of depositing. Also
supports the additional flow where you prepay amount
instead of relying on approve/transferFrom.
function deposit(uint256 amount, address beneficiary, uint32 courierId) public returns (uint256 shares);
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | The amount of underlying tokens to deposit |
beneficiary | address | The receiver of shares |
courierId | uint32 | The ID of the courier (or 0, to indicate lack thereof) that will receive a cut of beneficiary 's future interest. Only takes effect when balanceOf(beneficiary) == 0 . In all other cases, pass 0 to avoid wasting gas on courier-related checks. |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The number of shares (banknotes) minted to beneficiary |
deposit
function deposit(uint256 amount, address beneficiary) external returns (uint256 shares);
mint
function mint(uint256 shares, address beneficiary) external returns (uint256 amount);
redeem
Burns shares
from owner
and sends amount
of underlying tokens to receiver
. If
owner
has a courier, additional shares will be transferred from owner
to the courier as a fee.
redeem
is more efficient than withdraw
and is the recommended way of withdrawing
function redeem(uint256 shares, address recipient, address owner) public returns (uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | The number of shares to burn in exchange for underlying tokens. To burn all your shares, you can pass maxRedeem(owner) . If maxRedeem(owner) is changing over time (due to a courier or high utilization) you can pass type(uint256).max and it will be computed in-place. |
recipient | address | The receiver of amount of underlying tokens |
owner | address | The user from whom shares are taken (for both the burn and possible fee transfer) |
Returns
Name | Type | Description |
---|---|---|
amount | uint256 | The number of underlying tokens transferred to recipient |
withdraw
function withdraw(uint256 amount, address recipient, address owner) external returns (uint256 shares);
borrow
Sends amount
of asset
to recipient
and increases msg.sender
's debt by units
function borrow(uint256 amount, address recipient) external returns (uint256 units);
repay
Reduces beneficiary
's debt by units
, assuming someone has pre-paid amount
of asset
. To repay
all debt for some account, call repay(borrowBalance(account), account)
.
To avoid frontrunning, amount
should be pre-paid in the same transaction as the repay
call.
function repay(uint256 amount, address beneficiary) external returns (uint256 units);
accrueInterest
function accrueInterest() public returns (uint72);
approve
function approve(address spender, uint256 shares) external returns (bool);
transfer
function transfer(address to, uint256 shares) external returns (bool);
transferFrom
function transferFrom(address from, address to, uint256 shares) external returns (bool);
permit
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
_transfer
Transfers shares
from from
to to
, iff neither of them have a courier
function _transfer(address from, address to, uint256 shares) private;
_mint
Make sure to do something with the return value, newTotalSupply
!
function _mint(
address to,
uint256 shares,
uint256 amount,
uint256 totalSupply_,
uint32 courierId
) private returns (uint256 newTotalSupply);
_burn
Make sure to do something with the return value, newTotalSupply
!
function _burn(
address from,
uint256 shares,
uint256 inventory,
uint256 totalSupply_
) private returns (uint256 newTotalSupply);
_load
function _load() private returns (Cache memory cache, uint256 inventory);
_save
function _save(Cache memory cache, bool didChangeBorrowBase) private;
Events
Approval
event Approval(address indexed owner, address indexed spender, uint256 amount);
Transfer
event Transfer(address indexed from, address indexed to, uint256 amount);
Deposit
event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares);
Withdraw
event Withdraw(address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares);
Borrow
event Borrow(address indexed caller, address indexed recipient, uint256 amount, uint256 units);
Repay
event Repay(address indexed caller, address indexed beneficiary, uint256 amount, uint256 units);
CreditCourier
event CreditCourier(uint32 indexed id, address indexed account);