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.
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.
public fun deposit<C, L>(p: &mut Pool<C, L>, c: Coin<L>, acc: &Access, clock: &Clock, ctx: &mut TxContext): PoolShareNeeds: 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.
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.
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).
public fun accrue<C, L>(p: &mut Pool<C, L>, clock: &Clock): u256Permissionless. Grows the index to now at the rate the pool held since the last touch; every pool entry point calls it first.
Views#
| Function | Returns |
|---|---|
index_at(p, clock): u256 | The index the next accrue will set; unchanged while nothing is lent. |
total_assets(p, clock): u256 | Cash plus debt out. |
utilization_bps(p): u64 | Debt out over cash plus debt out, as of the last touch. |
rate_bps(p): u64 | The rate the index grows at until the next touch. |
quote_bps(p, amount): u64 | The 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.