API/On-chain reference

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#

ModuleWhat it holds
treasuryTreasuries, OwnerCaps, AgentCaps, limits, lend mandates, sealed-room consents.
offerStanding offers.
loanLoans, deeds, lender claims; fill, repay, liquidate, write off, default, refinance.
borrowerThe borrower desk: borrowing between two treasuries.
poolThe lending pool and its floating index.
loan_roomSealed rooms.
marketRisk parameters and price math for one collateral/loan pair.
price, pyth_oracleThe price Reading and the Pyth adapter.
interestInterest 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.

PackageWhat it holds
privacyShieldedPool<C> (module pool), one per coin, and its note tree (module merkle_tree): deposits, private notes, nullifiers.
essey_accessThe access gate: CLOSED, INVITE or PUBLIC. Checked by the private flows and by the lending package.
essey_suiPrivateLoanRoom<C, L> (module private_room).
sale_roomThe gated sale room, including the shielded pool bid.
essey_oracle_pythThe 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 ParamsProposed event with the values and the time it takes effect) and takes effect only when someone calls commit at 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#

CapabilityAbilitiesWho holds itWhat it unlocks
OwnerCapkey, storeThe treasury ownerEvery owner function of one treasury.
AgentCapkeyThe agent; cannot be transferred onSpending, posting offers and sealed-room consent within limits; borrowing through the desk.
LoanDeedkey, storeThe borrowerRepay, refinance, claim a loan's leftover.
LenderClaimkey, storeThe lender's treasuryCollect a default.
PoolSharekey, storeA pool depositorRedeem from the pool.
MarketAdminCapkey, storeThe publisherCreate markets and propose parameter changes (see above).

Conventions#

  • C is the collateral coin type and L the loan coin type; in treasury and offer, T is 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.