API/On-chain reference

pool

essey_sui::pool — a lending pool for one market: cash in the loan coin, shares out, every loan floating on one borrow index. See Pool.

publiccreate#
Move
public fun create<C, L>(m: &Market<C, L>, base_bps: u64, slope1_bps: u64, slope2_bps: u64, ctx: &mut TxContext)

Needs: nothing. Shares a new pool for market m. EBadCurve unless base + slope1 + slope2 ≤ 100,000.

publicdeposit#
Move
public fun deposit<C, L>(p: &mut Pool<C, L>, c: Coin<L>, acc: &Access, clock: &Clock, ctx: &mut TxContext): PoolShare

Needs: the lending Access object, which must admit the sender for the deposit (access::assert_open_now). Accrues, then mints shares against book value with a 10⁶ virtual offset. EZeroAmount, EZeroShares.

publicredeem#
Move
public fun redeem<C, L>(p: &mut Pool<C, L>, s: PoolShare, clock: &Clock, ctx: &mut TxContext): Coin<L>

Needs: a PoolShare of this pool (EWrongPool), by value. Burns the whole share; EInsufficientCash if the pool's cash cannot pay it now.

Move
public fun split(s: &mut PoolShare, shares: u64, ctx: &mut TxContext): PoolShare
public fun join(s: &mut PoolShare, other: PoolShare)

Split off part of a share (EOverShares unless 0 < shares < s.shares), or join two shares of one pool (EWrongPool).

publicaccrue#
Move
public fun accrue<C, L>(p: &mut Pool<C, L>, clock: &Clock): u256

Permissionless. Grows the index to now at the rate the pool held since the last touch; every pool entry point calls it first.

Views#

FunctionReturns
index_at(p, clock): u256The index the next accrue will set; unchanged while nothing is lent.
total_assets(p, clock): u256Cash plus debt out.
utilization_bps(p): u64Debt out over cash plus debt out, as of the last touch.
rate_bps(p): u64The rate the index grows at until the next touch.
quote_bps(p, amount): u64The rate right after a draw of amount.
state(p)(cash, shares, debt out, base, slope1, slope2)
share_info(s)(pool_id, shares)
market_id(p): ID

Package-only#

lend gives loan::borrow_from_pool the cash, the opening index and the rate; settle takes a loan off the book with whatever came back, and a shortfall lowers the share price.

Abort codes#

1 EBadCurve, 2 EZeroAmount, 3 EZeroShares, 4 EWrongPool, 5 EInsufficientCash, 6 EOverShares.