Ledger

Git Source

State Variables

FACTORY

Factory public immutable FACTORY;

RESERVE

address public immutable RESERVE;

totalSupply

Doesn't include reserve inflation. If you want that, use stats()

uint112 public totalSupply;

lastBalance

Used in lieu of asset.balanceOf to prevent inflation attacks

uint112 public lastBalance;

lastAccrualTime

The last block.timestamp at which interest accrued

uint32 public lastAccrualTime;

borrowBase

The principle of all outstanding loans as if they were taken out at borrowIndex = ONE

uint184 public borrowBase;

borrowIndex

Tracks all-time growth of borrow interest. Starts at ONE and increases monotonically over time

uint72 public borrowIndex;

borrows

The principle of a given user's loan as if it was taken out at borrowIndex = ONE

mapping(address => uint256) public borrows;

balances

Highest 32 bits are the referral code, next 112 are the principle, lowest 112 are the shares.

mapping(address => uint256) public balances;

allowance

mapping(address => mapping(address => uint256)) public allowance;

nonces

mapping(address => uint256) public nonces;

rateModel

rateModel.getYieldPerSecond is given 100000 gas, and the output is clamped to MAX_RATE. If the call reverts, it's treated the same as if it returned 0.

IRateModel public rateModel;

reserveFactor

The portion of interest that accrues to the RESERVE. Expressed as a reciprocal, e.g. 16 β†’ 6.25%

uint8 public reserveFactor;

Functions

constructor

constructor(address reserve);

supportsInterface

Returns true if this contract implements the interface defined by interfaceId

function supportsInterface(bytes4 interfaceId) external pure returns (bool);

name

The name of the banknote.

function name() external view returns (string memory);

symbol

The symbol of the banknote.

function symbol() external view returns (string memory);

decimals

The number of decimals the banknote uses. Matches the underlying token.

function decimals() external view returns (uint8);

asset

The address of the underlying token.

function asset() public pure returns (ERC20);

peer

The address of the other Lender in the market

function peer() public view returns (address);

DOMAIN_SEPARATOR

The domain separator for EIP-2612

function DOMAIN_SEPARATOR() public view returns (bytes32);

stats

Gets basic lending statistics as if accrueInterest were just called.

function stats() external view returns (uint72, uint256, uint256, uint256);

Returns

NameTypeDescription
<none>uint72The updated borrowIndex
<none>uint256The sum of all banknote balances, in underlying units (i.e. totalAssets)
<none>uint256The sum of all outstanding debts, in underlying units
<none>uint256The sum of all banknote balances. Will differ from totalSupply due to reserves inflation

rewardsRate

The rewards rate, specified as [token units per second]

function rewardsRate() external view returns (uint64 rate);

rewardsOf

All rewards earned by account that have not yet been paid out

function rewardsOf(address account) external view returns (uint96);

courierOf

The ID of the referrer associated with account's deposit. If 0, they have no courier.

function courierOf(address account) external view returns (uint32);

principleOf

The lending principle of account. Only tracked if they have a courier.

function principleOf(address account) external view returns (uint256);

balanceOf

The number of shares held by account

function balanceOf(address account) public view returns (uint256);

underlyingBalance

The amount of asset owed to account after accruing the latest interest, i.e. the value that maxWithdraw would return if outstanding borrows weren't a constraint. Fees owed to couriers are automatically subtracted from this value in real-time, but couriers themselves won't receive earnings until users redeem or withdraw.

Because of the fees, βˆ‘underlyingBalances != totalAssets

function underlyingBalance(address account) external view returns (uint256);

underlyingBalanceStored

The amount of asset owed to account before accruing the latest interest. See underlyingBalance for details.

An underestimate; more gas efficient than underlyingBalance

function underlyingBalanceStored(address account) external view returns (uint256);

borrowBalance

The amount of asset owed by account after accruing the latest interest. If one calls repay(borrowBalance(account), account), the account will be left with a borrow balance of 0.

function borrowBalance(address account) external view returns (uint256);

borrowBalanceStored

The amount of asset owed by account before accruing the latest interest.

function borrowBalanceStored(address account) external view returns (uint256);

totalAssets

The total amount of asset under management

convertToShares(totalAssets()) != totalSupply() due to reserves inflation. If you need the up-to-date supply, use stats()

function totalAssets() external view returns (uint256);

convertToShares

function convertToShares(uint256 assets) public view returns (uint256);

convertToAssets

function convertToAssets(uint256 shares) public view returns (uint256);

previewDeposit

function previewDeposit(uint256 assets) public view returns (uint256);

previewMint

function previewMint(uint256 shares) public view returns (uint256);

previewRedeem

function previewRedeem(uint256 shares) public view returns (uint256);

previewWithdraw

function previewWithdraw(uint256 assets) public view returns (uint256);

maxDeposit

Returns a conservative estimate of the maximum amount of asset() that can be deposited into the Vault for receiver, through a deposit call.

Should return the precise maximum. In this case that'd be on the order of 2^112 with constraints coming from both lastBalance and totalSupply, which changes during interest accrual. Instead of doing complicated math, we provide a constant conservative estimate of 2^96.

function maxDeposit(address) external pure returns (uint256);

Returns

NameTypeDescription
<none>uint256The maximum amount of asset() that can be deposited

maxMint

Returns a conservative estimate of the maximum number of Vault shares that can be minted for receiver, through a mint call.

Should return the precise maximum. In this case that'd be on the order of 2^112 with constraints coming from both lastBalance and totalSupply, which changes during interest accrual. Instead of doing complicated math, we provide a constant conservative estimate of 2^96.

function maxMint(address) external pure returns (uint256);

Returns

NameTypeDescription
<none>uint256The maximum number of Vault shares that can be minted

maxRedeem

Returns the maximum number of Vault shares that can be redeemed in the Vault by owner, through a redeem call.

function maxRedeem(address owner) public view returns (uint256);

Parameters

NameTypeDescription
owneraddressThe address that would burn Vault shares when redeeming

Returns

NameTypeDescription
<none>uint256The maximum number of Vault shares that can be redeemed

maxWithdraw

Returns the maximum amount of asset() that can be withdrawn from the Vault by owner, through a withdraw call.

function maxWithdraw(address owner) external view returns (uint256);

Parameters

NameTypeDescription
owneraddressThe address that would burn Vault shares when withdrawing

Returns

NameTypeDescription
<none>uint256The maximum amount of asset() that can be withdrawn

_previewInterest

Accrues interest up to the current block.timestamp. Updates and returns cache, but doesn't write anything to storage.

function _previewInterest(Cache memory cache) internal view returns (Cache memory, uint256, uint256);

_convertToShares

function _convertToShares(
    uint256 assets,
    uint256 inventory,
    uint256 totalSupply_,
    bool roundUp
) internal pure returns (uint256);

_convertToAssets

function _convertToAssets(
    uint256 shares,
    uint256 inventory,
    uint256 totalSupply_,
    bool roundUp
) internal pure returns (uint256);

_nominalShares

The account's balance, minus any shares earned by their courier

function _nominalShares(
    address account,
    uint256 inventory,
    uint256 totalSupply_
) private view returns (uint256 balance);

_getCache

function _getCache() internal view returns (Cache memory);

Structs

Cache

struct Cache {
    uint256 totalSupply;
    uint256 lastBalance;
    uint256 lastAccrualTime;
    uint256 borrowBase;
    uint256 borrowIndex;
}