On-chain reference
The Essey on Sui Move package, module by module: every public function, what it checks, and what it needs to be called.
Unaudited demo publish. The live testnet lending package is 0x6786d695be37759278a0769b311fd9381b44baaea86f6a969619a7df8c9a61b4. Private-flow packages and the three shielded pools are on Network and at GET /v1/private/config.
Modules#
| Module | What it holds |
|---|---|
| treasury | Treasuries, OwnerCaps, AgentCaps, limits, lend mandates, sealed-room consents. |
| offer | Standing offers. |
| loan | Loans, deeds, lender claims; fill, repay, liquidate, write off, default, refinance. |
| borrower | The borrower desk: borrowing between two treasuries. |
| pool | The lending pool and its floating index. |
| loan_room | Sealed rooms. |
| market | Risk parameters and price math for one collateral/loan pair. |
| price, pyth_oracle | The price Reading and the Pyth adapter. |
| interest | Interest and index math. |
Private-flow packages#
The private loan room and the gated sale room run on their own packages. Their ids are served at GET /v1/private/config; how the flows fit together is in Private rooms.
The lending package checks the same Access object (access in GET /v1/config) before every entry that takes funds in: offer::post, loan::fill, loan::borrow_from_pool, pool::deposit, loan_room::settle, and the borrower desk's fill, borrow_pool, refinance_offer and refinance_pool. access::assert_open_now refuses while the gate is paused (EPaused); in CLOSED mode it admits operators only (ENotOperator), in INVITE mode operators and holders of an unexpired invite within its per-loan and lifetime caps (ENoInvite, EInviteExpired, EOverMaxLoan, EOverLifetime), in PUBLIC mode everyone.
| Package | What it holds |
|---|---|
| privacy | ShieldedPool<C> (module pool), one per coin, and its note tree (module merkle_tree): deposits, private notes, nullifiers. |
| essey_access | The access gate: CLOSED, INVITE or PUBLIC. Checked by the private flows and by the lending package. |
| essey_sui | PrivateLoanRoom<C, L> (module private_room). |
| sale_room | The gated sale room, including the shielded pool bid. |
| essey_oracle_pyth | The Pyth adapter (module pyth_oracle). |
The code cannot change#
The testnet package is immutable. It was published and made immutable in the same transaction: the publish was followed by 0x2::package::make_immutable, which consumes the package's UpgradeCap, and the transaction left no UpgradeCap behind. The publish transaction created the package as immutable, the market Registry and the MarketAdminCap, and no UpgradeCap. No one can replace or upgrade the code that holds treasuries, loans and pools.
What the MarketAdminCap can and cannot do#
One MarketAdminCap exists, created by the publish and held by the publishing address.
It can:
- create a market for a new collateral/loan pair, at most one per pair;
- propose new borrow-limit, liquidation-line and bonus values for a market, and cancel a proposal. A proposal is public (a
ParamsProposedevent with the values and the time it takes effect) and takes effect only when someone callscommitat least two days later, within fixed bounds.
It cannot: change a market's oracle or price feed (fixed at creation), move or take funds from any treasury, pool, loan, deed or lender claim, read or alter a sealed bid, or change the code. It has no direct hold on a loan, but through the liquidation line it can affect open loans, as described next. Outside market.move no Move function takes a MarketAdminCap.
What a parameter change can do to open loans. The liquidation line applies to every open loan in the market, so lowering it can make loans liquidatable. The cap can lower it in steps: a proposal of borrow limit 0 and liquidation line 20% passes the bounds, and once the borrow limit is 0 a second proposal may set the line to 0, at which point every loan with any debt is over the line. What a liquidation then does is fixed by the code: the liquidator pays the whole debt, so the lender is made whole; the liquidator takes collateral worth the debt plus the bonus (at most 15%), valued at spot; everything above that stays in the loan for the borrower to claim. A borrower's loss is at most the bonus on what it owed.
The notice. Every proposal is a public ParamsProposed event naming the new values and when they can take effect, at least two days ahead; no change takes effect before then. That is the window to repay or add collateral, which are never refused because of the price.
Capabilities#
| Capability | Abilities | Who holds it | What it unlocks |
|---|---|---|---|
OwnerCap | key, store | The treasury owner | Every owner function of one treasury. |
AgentCap | key | The agent; cannot be transferred on | Spending, posting offers and sealed-room consent within limits; borrowing through the desk. |
LoanDeed | key, store | The borrower | Repay, refinance, claim a loan's leftover. |
LenderClaim | key, store | The lender's treasury | Collect a default. |
PoolShare | key, store | A pool depositor | Redeem from the pool. |
MarketAdminCap | key, store | The publisher | Create markets and propose parameter changes (see above). |
Conventions#
Cis the collateral coin type andLthe loan coin type; intreasuryandoffer,Tis the treasury's coin.- Rates and ratios are in basis points: 10,000 = 100%.
- Times are milliseconds from the Sui
Clock, except interest, which accrues per whole second. public(package)functions are not callable from outside the package and are listed only where they explain a check.- Error codes are each module's own abort codes.