API/Endpoints

Borrow

Routes for borrowing from your own wallet: you sign every transaction yourself, and loans open in your address's name. All need a session. To have an agent borrow for you instead, create a borrower agent: see Agents.

Quote#

POST/v1/borrow/quote

— what each route would give, before anything is signed.

FieldType
collateraldecimal string, SUI
amountdecimal string, USDC
JSON
{
  "ok": true,
  "price": { "spot": "0.93592165", "ema": "0.93672012", "publishMs": 1792901005000 },
  "market": { "ltvBps": 5000, "liqBps": 7500, "bonusBps": 500 },
  "health": { "valueAtBorrow": "…", "ltvBps": 3200, "liqBps": 7500, "underwater": false, "liquidationPrice": "…" },
  "routes": {
    "offer": { "offerId": "0x…", "rateBps": 800, "termMs": 86400000 },
    "pool": { "rateBps": 520, "floating": true, "available": "…" },
    "room": { "rateBps": null, "note": "lenders bid blind; you see the rates only after close" }
  },
  "warnings": []
}

Values are illustrative.

routes.offer and routes.pool are null when that route does not qualify. The null has no reason field of its own. The reason that the server attaches is a top-level warnings entry.

  • routes.offer is the cheapest listed offer that is still open, lasts at least 6 hours, fits amount inside its min and max fill and its remaining size, and whose LTV ceiling and lend rules accept this borrower. It is null when none qualify. It is also null while the offer index is loading.
  • routes.pool is null when there is no pool, the pool quote could not be read, or the pool holds less than amount. A missing pool is not itself a warning.
  • routes.room is always present and its rateBps is always null: lenders bid blind, and the rates are unknown until close.
  • Quote warnings codes:
    • OFFERS_LOADING — "the offer list is still loading from the chain: try again in a moment". routes.offer is null in that case.
    • LTV_TOO_HIGH — "over the market's borrow limit: add SUI or borrow less". The quote still returns ok: true. This warning does not by itself null a route: an offer whose own LTV ceiling allows the loan can still be routes.offer, and the pool route does not apply the market LTV.

Other warning codes, on loans and rooms rather than on the quote:

CodeWhere
LIQUIDATABLEA loan, over the safety line at both prices.
LTV_NEAR_LINEA loan, within 10 points of that line.
MATURITY_SOONA loan, due within the hour.
PAST_MATURITYA loan, past due.
REFINANCE_CHEAPERA loan; carries offerId.
PRICE_STALEA loan list, when the SUI price is stale.
ROOM_CLOSINGA room, bidding ends within a minute.
SETTLE_WINDOW_CLOSINGA room, within five minutes of the end of the settle window.
ROOM_NO_BIDSA room, no bid.
ROOM_REFUNDABLEA room, the settle window has passed.

Errors: BAD_COLLATERAL 400, BAD_AMOUNT 400, PRICE_STALE 409.

Preview a borrower agent's rules#

POST/v1/borrow/preview

With { form } → { ok, sentence, chain } or 400 BAD_FORM with errors. The form is described in Agent transactions. chain holds suiBudget, cashFloat, cashBudget, capExpiresAtMs, repayByMs, maxOwed, and borrow — the borrow rules { maxRateBps, minTermMs, latestMaturityMs, poolId, allowance } the deposit will write on chain; poolId is the deployment's pool for a switcher and null otherwise, and allowance (a string in USDC base units) is the form's amount plus 0.001 USDC per refinance for a switcher.

Rooms#

GET/v1/borrow/rooms→ { ok, nowMs, rooms }

The sealed rooms you opened.

GET/v1/borrow/rooms/:roomId→ { ok, nowMs, room, offers, seal }
FieldWhat it is
roomThe room's terms and state, plus phase and warnings.
offersEach sealed bid: {index, lender, commitment, ciphertext}, ciphertext in base64.
sealWhat your browser needs to open the bids: {pkg, loanCoin, identity, keyServers, threshold}.

phase is bidding, open-bids, refundable, settled, declined or refunded. Room warnings: ROOM_CLOSING (bidding ends within a minute), SETTLE_WINDOW_CLOSING (within five minutes), ROOM_NO_BIDS, ROOM_REFUNDABLE.

Errors: BAD_ROOM_ID 400, NO_SUCH_ROOM 404 (also for a room that is not yours).

Loans#

GET/v1/borrow/loans→ { ok, nowMs, priceStale, offersLoading, more, loans }

The newest 50 loans your address opened whose deed it still holds; more is true when older ones were not read, offersLoading while the offer list is still loading (no cheaper-offer hints until it has).

FieldNotes
loanId, deedId, state, principal, collateral, lenderKind, maturityMsmaturityMs is 0 for a pool loan.
rateBps, floatingA pool loan's rate is the pool's this second, and floating is true.
owedNowWhat it owes this second.
health{valueAtBorrow, ltvBps, liqBps, underwater, liquidationPrice}, or null when the price is stale or the loan is closed.
warningsSee below.
WarningMeaning
LIQUIDATABLEOver the line at both prices; anyone can close it now.
LTV_NEAR_LINEWithin 10 points of the line.
MATURITY_SOONDue within the hour.
PAST_MATURITYPast due; after the grace period the lender can collect.
REFINANCE_CHEAPERA cheaper offer you can move to is open; carries offerId.
PRICE_STALEThe SUI price is over five minutes old.

History#

GET/v1/borrow/history→ { ok, more, loans }

Newest first: every loan your address opened and everything that happened to it since.

FieldNotes
loanId, lenderKind, lenderId, principal, rateBps, collateralAtOpen
openedAtMs, openDigest, closedAtMs, closeDigest
outcomeopen, repaid, refinanced, liquidated, written-off, defaulted or claimed.
refinancedIntoThe new loan's id after a refinance.
stepsEach event: {kind, atMs, digest, data}.

The history covers the newest 50 loans your address opened; more is true when older ones were not read.