Lender.sol

This document describes the functions, attributes and modifiers in Lender.sol

Lender

Git Source

Author: Sourabh Marathe, Julian Traversa, Rob Robbins

The lender contract executes loans on behalf of users

The contract holds the principal tokens and mints an ERC-5095 tokens to users to represent their loans

State Variables

HOLD

minimum wait before the admin may withdraw funds or change the fee rate

uint256 public constant HOLD = 3 days;

admin

address that is allowed to set and withdraw fees, disable principals, etc. It is commonly used in the authorized modifier.

address public admin;

marketPlace

address of the MarketPlace contract, used to access the markets mapping

address public marketPlace;

paused

mapping that determines if a principal has been paused by the admin

mapping(uint8 => bool) public paused;

halted

flag that allows admin to stop all lending and minting across the entire protocol

bool public halted;

swivelAddr

contract used to execute swaps on Swivel's exchange

address public immutable swivelAddr;

pendleAddr

a SushiSwap router used by Pendle to execute swaps

address public immutable pendleAddr;

apwineAddr

a pool router used by APWine to execute swaps

address public immutable apwineAddr;

premiums

a mapping that tracks the amount of unswapped premium by market. This underlying is later transferred to the Redeemer during Swivel's redeem call

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

feenominator

this value determines the amount of fees paid on loans

uint256 public feenominator;

feeChange

represents a point in time where the feenominator may change

uint256 public feeChange;

MIN_FEENOMINATOR

represents a minimum that the feenominator must exceed

uint256 public constant MIN_FEENOMINATOR = 500;

fees

maps underlying tokens to the amount of fees accumulated for that token

mapping(address => uint256) public fees;

withdrawals

maps a token address to a point in time, a hold, after which a withdrawal can be made

mapping(address => uint256) public withdrawals;

_NOT_ENTERED

uint256 private constant _NOT_ENTERED = 1;

_ENTERED

uint256 private constant _ENTERED = 2;

_status

uint256 private _status = _NOT_ENTERED;

MAX_VALUE

maximum amount of value that can flow through a protocol in a day (in USD)

uint256 public constant MAX_VALUE = 2_000_000e27;

protocolFlow

maps protocols to how much value, in USD, has flowed through each protocol

mapping(uint8 => uint256) public protocolFlow;

periodStart

timestamp from which values flowing through protocol has begun

mapping(uint8 => uint256) public periodStart;

etherPrice

estimated price of ether, set by the admin

uint256 public etherPrice = 2_500;

Functions

authorized

ensures that only a certain address can call the function

modifier authorized(address a);

Parameters

unpaused

reverts on all markets where the paused mapping returns true

modifier unpaused(address u, uint256 m, uint8 p);

Parameters

matured

reverts if called after maturity

modifier matured(uint256 m);

Parameters

nonReentrant

prevents users from re-entering contract

modifier nonReentrant();

constructor

initializes the Lender contract

constructor(address s, address p, address a);

Parameters

approve

approves the redeemer contract to spend the principal tokens held by the lender contract.

function approve(address u, uint256 m, address r) external authorized(admin) returns (bool);

Parameters

Returns

approve

bulk approves the usage of addresses at the given ERC20 addresses.

the lengths of the inputs must match because the arrays are paired by index

function approve(address[] calldata u, address[] calldata a) external authorized(admin) returns (bool);

Parameters

Returns

approve

approves market contracts that require lender approval

function approve(address u, address a, address e, address n, address p) external authorized(marketPlace);

Parameters

setAdmin

sets the admin address

function setAdmin(address a) external authorized(admin) returns (bool);

Parameters

Returns

setFee

sets the feenominator to the given value

function setFee(uint256 f) external authorized(admin) returns (bool);

Parameters

Returns

setMarketPlace

sets the address of the marketplace contract which contains the addresses of all the fixed rate markets

function setMarketPlace(address m) external authorized(admin) returns (bool);

Parameters

Returns

setEtherPrice

sets the ethereum price which is used in rate limiting

function setEtherPrice(uint256 p) external authorized(admin) returns (bool);

Parameters

Returns

mint

mint swaps the sender's principal tokens for Illuminate's ERC5095 tokens in effect, this opens a new fixed rate position for the sender on Illuminate

function mint(uint8 p, address u, uint256 m, uint256 a) external nonReentrant unpaused(u, m, p) returns (bool);

Parameters

Returns

lend

lend method for the Illuminate and Yield protocols

function lend(uint8 p, address u, uint256 m, uint256 a, address y, uint256 minimum)
    external
    nonReentrant
    unpaused(u, m, p)
    matured(m)
    returns (uint256);

Parameters

Returns

lend

lend method signature for Swivel

function lend(
    uint8 p,
    address u,
    uint256 m,
    uint256[] memory a,
    address y,
    Swivel.Order[] calldata o,
    Swivel.Components[] calldata s,
    bool e,
    uint256 premiumSlippage
) external nonReentrant unpaused(u, m, p) matured(m) returns (uint256);

Parameters

Returns

lend

lend method signature for Element

function lend(uint8 p, address u, uint256 m, uint256 a, uint256 r, uint256 d, address e, bytes32 i)
    external
    nonReentrant
    unpaused(u, m, p)
    matured(m)
    returns (uint256);

Parameters

Returns

lend

lend method signature for Pendle

function lend(uint8 p, address u, uint256 m, uint256 a, uint256 r, Pendle.ApproxParams calldata g, address market)
    external
    nonReentrant
    unpaused(u, m, p)
    matured(m)
    returns (uint256);

Parameters

Returns

lend

lend method signature for Tempus and APWine

function lend(uint8 p, address u, uint256 m, uint256 a, uint256 r, uint256 d, address x)
    external
    nonReentrant
    unpaused(u, m, p)
    matured(m)
    returns (uint256);

Parameters

Returns

lend

lend method signature for Sense

this method can be called before maturity to lend to Sense while minting Illuminate tokens

Sense provides a [divider] contract that splits [target] assets (underlying) into PTs and YTs. Each [target] asset has a [series] of contracts, each identifiable by their [maturity].

function lend(uint8 p, address u, uint256 m, uint128 a, uint256 r, address x, uint256 s, address adapter)
    external
    nonReentrant
    unpaused(u, m, p)
    matured(m)
    returns (uint256);

Parameters

Returns

lend

lend method signature for Notional

function lend(uint8 p, address u, uint256 m, uint256 a, uint256 r)
    external
    nonReentrant
    unpaused(u, m, p)
    matured(m)
    returns (uint256);

Parameters

Returns

scheduleWithdrawal

allows the admin to schedule the withdrawal of tokens

function scheduleWithdrawal(address e) external authorized(admin) returns (bool);

Parameters

Returns

blockWithdrawal

emergency function to block unplanned withdrawals

function blockWithdrawal(address e) external authorized(admin) returns (bool);

Parameters

Returns

scheduleFeeChange

allows the admin to schedule a change to the fee denominators

function scheduleFeeChange() external authorized(admin) returns (bool);

blockFeeChange

Emergency function to block unplanned changes to fee structure

function blockFeeChange() external authorized(admin) returns (bool);

withdraw

allows the admin to withdraw the given token, provided the holding period has been observed

function withdraw(address e) external authorized(admin) returns (bool);

Parameters

Returns

withdrawFee

withdraws accumulated lending fees of the underlying token

function withdrawFee(address e) external authorized(admin) returns (bool);

Parameters

Returns

pause

pauses a market and prevents execution of all lending for that principal

function pause(uint8 p, bool b) external authorized(admin) returns (bool);

Parameters

Returns

pauseIlluminate

pauses Illuminate's redeem, mint and lend methods from being used

function pauseIlluminate(bool b) external authorized(admin) returns (bool);

Parameters

Returns

transferFYTs

Tranfers FYTs to Redeemer (used specifically for APWine redemptions)

function transferFYTs(address f, uint256 a) external authorized(IMarketPlace(marketPlace).redeemer());

Parameters

transferPremium

Transfers premium from the market to Redeemer (used specifically for Swivel redemptions)

function transferPremium(address u, uint256 m) external authorized(IMarketPlace(marketPlace).redeemer());

Parameters

batch

Allows batched call to self (this contract).

function batch(bytes[] calldata c) external payable returns (bytes[] memory results);

Parameters

yield

swaps underlying premium via a Yield Space Pool

this method is only used by the Yield, Illuminate and Swivel protocols

function yield(address u, address y, uint256 a, address r, address p, uint256 m) internal returns (uint256);

Parameters

Returns

swivelAmount

returns the amount of underlying tokens to be used in a Swivel lend

function swivelAmount(uint256[] memory a) internal pure returns (uint256);

swivelVerify

reverts if any orders are not for the market

function swivelVerify(Swivel.Order[] memory o, address u) internal pure;

elementSwap

executes a swap for and verifies receipt of Element PTs

function elementSwap(address e, Element.SingleSwap memory s, Element.FundManagement memory f, uint256 r, uint256 d)
    internal
    returns (uint256);

apwineTokenPath

returns array token path required for APWine's swap method

function apwineTokenPath() internal pure returns (uint256[] memory);

Returns

apwinePairPath

returns array pair path required for APWine's swap method

function apwinePairPath() internal pure returns (uint256[] memory);

Returns

principalToken

retrieves the ERC5095 token for the given market

function principalToken(address u, uint256 m) internal returns (address);

Parameters

Returns

convertDecimals

converts principal decimal amount to underlying's decimal amount

function convertDecimals(address u, address p, uint256 a) internal view returns (uint256);

Parameters

Returns

rateLimit

limits the amount of funds (in USD value) that can flow through a principal in a day

function rateLimit(uint8 p, address u, uint256 a) internal returns (bool);

Parameters

Returns

Events

Lend

emitted upon lending to a protocol

event Lend(
    uint8 principal,
    address indexed underlying,
    uint256 indexed maturity,
    uint256 returned,
    uint256 spent,
    address sender
);

Mint

emitted upon minting Illuminate principal tokens

event Mint(uint8 principal, address indexed underlying, uint256 indexed maturity, uint256 amount);

ScheduleWithdrawal

emitted upon scheduling a withdrawal

event ScheduleWithdrawal(address indexed token, uint256 hold);

BlockWithdrawal

emitted upon blocking a scheduled withdrawal

event BlockWithdrawal(address indexed token);

SetAdmin

emitted upon changing the admin

event SetAdmin(address indexed admin);

SetFee

emitted upon setting the fee rate

event SetFee(uint256 indexed fee);

ScheduleFeeChange

emitted upon scheduling a fee change

event ScheduleFeeChange(uint256 when);

BlockFeeChange

emitted upon blocking a scheduled fee change

event BlockFeeChange();

PausePrincipal

emitted upon pausing or unpausing of a principal

event PausePrincipal(uint8 principal, bool indexed state);

PauseIlluminate

emitted upon pausing or unpausing minting, lending and redeeming

event PauseIlluminate(bool state);

Last updated