SDK/Reference

EsseyAgent

PREVIEW

The agent: reads through book, builds through ptb, and signs only through execute, which re-runs the key-separation check every time and refuses anything outside the agent lane (NOT_AGENT_CALL). A loan room is not an agent method: a borrower runs it from their own wallet. A sale-room bid is, when the agent is started with saleRoom: bidSaleRoom signs membership::from_proof and room::bid of that package and nothing else of it. See Key separation.

At a glance#

MethodSignsReturnsThrows (before signing)
EsseyAgent.start(options)noEsseyAgentNETWORK_REFUSED (deployment for another chain), any key-separation code
execute(tx)yesLandedNOT_SET_UP, any key-separation code, NOT_AGENT_CALL (a call outside the agent lane), NO_COINS (coin gas), NETWORK_REFUSED (chain changed), WOULD_ABORT (the simulation before signing says the transaction would abort)
postOffer, cancelOfferyesLandedas execute; postOffer also NOT_SET_UP (the mandate is gone), OVER_MANDATE_CAP (size over what the cap has left), LENDER_SHORT (funds under the smallest fill)
borrowFromOffer, borrowFromPool, repay, refinance, addCollateral, claimyes, through the borrower deskLandedas execute; NOT_FOUND for an unknown offer or loan; NO_CASH_TREASURY, NO_POOL from the builders
bidSealed(roomId, rateBps, seal)yes, twice (consent, then bid){ consent, placed, opening }NOT_SET_UP, as execute
bidSaleRoom(roomId, price, pass, seal?)yes, onceLandedNOT_SET_UP (no saleRoom), NOT_FOUND (not a SaleRoom of that package, or its PassKey is not), SELLER_CANNOT_BID (the agent opened the room), INVALID_ARGUMENT (a credential the chain would refuse: another holder, expired, another issuer key or epoch than the PassKey holds, a non-canonical tag; a shielded-only, ended, closed or full room; a second bid; a price out of range; a ciphertext the room would refuse), as execute
offer, loan, myLoans, limits, recipients, capSides, warnings, separationnoreadsNOT_FOUND (offer, loan)
allowance()nobigint or null: what the borrower desk may still borrow (treasury::borrow_allowance_of); null without a cash treasury or borrow rules—

Amounts are bigint in the coin's smallest unit: MIST for SUI, and the loan coin's own unit (1 USDC = 1_000_000n).

A chain refusal is not thrown: the method returns Landed with ok: false and an abort.

Signatures below are copied from the source; descriptions are the source's own doc comments.

From agent.ts#

Exported by index.ts.

AgentAccount#

The agent's caps. A lender has one treasury in the loan coin; a borrower has its SUI (collateral) treasury here and its loan-coin treasury as cash, and borrows only through the borrower desk, so funds never pass its address.

TypeScript
export type AgentAccount = {
  treasuryId: string;
  agentCapId: string;
  cash?: { treasuryId: string; capId: string };
};

AgentOptions#

TypeScript
export type AgentOptions = {
  chain: EsseyChain;
  deployment: EsseyDeployment;
  /** The agent's own key. There is no second key: owner actions are built unsigned (owner.ts, unsigned.ts). */
  signer: Signer;
  /** null before the owner has created the account: reads work, nothing signs. */
  account: AgentAccount | null;
  gas?: GasMode;
  /** The sale-room package the agent may bid in (saleRoomOf); without it, execute refuses every sale-room call. */
  saleRoom?: SaleRoomConfig;
};

Warning#

TypeScript
export type Warning = {
  kind: "cap-expiring" | "cap-gone" | "underwater" | "repay-due";
  id: string;
  text: string;
};

EsseyAgent#

TypeScript
export class EsseyAgent
  • field readonly address: string
  • field readonly book: Book
  • field readonly ptb: Ptb | null

EsseyAgent.start

Connects and runs the key-separation check; throws its EsseyError instead of returning an agent that would sign.

TypeScript
static async start(o: AgentOptions): Promise<EsseyAgent>

EsseyAgent.account

TypeScript
get account(): AgentAccount | null

EsseyAgent.separation

TypeScript
separation(): Promise<Separation>

EsseyAgent.execute

The one signing path: the separation check runs again first, every time, and the built transaction must stay in the agent lane (lane.ts), so whatever the agent signs keeps its loans inside its treasury. The calls already in the PTB are checked before the build too: resolving a coin intent can fail on the agent's balance first.

TypeScript
async execute(tx: Transaction): Promise<Landed>

EsseyAgent.offer

TypeScript
async offer(offerId: string): Promise<OfferView>

EsseyAgent.loan

TypeScript
async loan(loanId: string): Promise<LoanView>

EsseyAgent.myLoans

Borrower: loans whose deed its SUI treasury holds. Lender: loans its treasury funded.

TypeScript
async myLoans(): Promise<LoanView[]>

EsseyAgent.postOffer

TypeScript
async postOffer(terms: OfferTerms): Promise<Landed>

EsseyAgent.cancelOffer

TypeScript
cancelOffer(offerId: string): Promise<Landed>

EsseyAgent.borrowFromOffer

Collateral is a base-unit SUI amount taken from the agent's SUI treasury. amount is base units of the loan coin. The proceeds land in the cash treasury (account.cash). The deed stays in the SUI treasury. Throws NO_CASH_TREASURY when account has no cash.

TypeScript
async borrowFromOffer(offerId: string, collateral: bigint, amount: bigint): Promise<Landed>

EsseyAgent.borrowFromPool

Same treasuries as borrowFromOffer: SUI out of the SUI treasury, loan coin into the cash treasury. Throws NO_POOL when the deployment has no pool, and NO_CASH_TREASURY without a cash treasury.

TypeScript
borrowFromPool(collateral: bigint, amount: bigint): Promise<Landed>

EsseyAgent.repay

TypeScript
async repay(loanId: string): Promise<Landed>

EsseyAgent.refinance

TypeScript
async refinance(loanId: string, offerId: string, amount: bigint): Promise<Landed>

Known limit: an offer refinanced into another offer of the same lender treasury hits CommandArgumentError at argument 5, because deskRefinance passes that treasury as both the old lender and the new offer's treasury. Pool to offer, and offer to a different lender, work.

EsseyAgent.addCollateral

TypeScript
addCollateral(loanId: string, amount: bigint): Promise<Landed>

EsseyAgent.claim

TypeScript
claim(loanId: string): Promise<Landed>

EsseyAgent.bidSealed

Lender: consents on chain to its own opening, then places it sealed. seal encrypts it (loan-room.ts encryptOffer with the testnet key servers); the opening is returned so the lender can audit what it bid.

TypeScript
async bidSealed(
  roomId: string,
  rateBps: bigint,
  seal: (o: SealedOpening) => Promise<Uint8Array>,
): Promise<{ consent: Landed; placed: Landed | null; opening: SealedOpening }>

EsseyAgent.bidSaleRoom

A sealed bid in a sale room with the agent's own SUI: the pass (a ProvedPass from provedPassFor) becomes a membership and room::bid takes it with a max_price deposit, in one transaction. Refused before signing when the chain would refuse the pass (checked against the on-chain PassKey), the room, a second bid, the price or the ciphertext.

TypeScript
async bidSaleRoom(
  roomId: string,
  price: bigint,
  pass: ProvedPass,
  seal?: Pick<SealClient, "encrypt">,
): Promise<Landed>

EsseyAgent.limits

treasury::limits_of for any of the agent's treasuries (Book.capLimits reads only loan-coin treasuries). Returns null when the simulation fails, which is what a revoked or unknown cap does (ECapRevoked).

TypeScript
async limits(coinType: string, treasuryId: string, capId: string): Promise<CapLimits | null>

CapLimits is { perTx, perDay, expiresAtMs, spent24h }. These are coin amounts in base units of coinType (MIST for 0x2::sui::SUI, 10⁻⁶ USDC for the hosted loan coin). They are not counts of transactions.

FieldMeaning
perTxThe most one spend may move. A spend of this size passes. One base unit more aborts EOverPerTx (code 4) in treasury::charge.
perDayThe most the rolling window may sum to. The window is the current hour and the 23 hours before it, so a spend stops counting 23–24 hours after it. One base unit over the sum aborts EOverPerDay (code 5).
spent24hThat window's sum so far, the fourth value limits_of returns.
expiresAtMsWhen the cap stops. A later spend aborts ECapExpired.

perTx is at least 1 and never above perDay; a zero perTx is refused when the cap is minted.

EsseyAgent.recipients

treasury::recipients_of: who the cap may pay (the owner, for every cap the owner setup makes).

TypeScript
async recipients(coinType: string, treasuryId: string, capId: string): Promise<string[] | null>

EsseyAgent.allowance

treasury::borrow_allowance_of on the SUI cap: what the desk may still borrow; null with no borrow rules set.

TypeScript
async allowance(): Promise<bigint | null>

EsseyAgent.capSides

The agent's caps with their coin type: loan coin for a lender, SUI then loan coin for a borrower.

TypeScript
capSides(): { coinType: string; treasuryId: string; capId: string }[]

EsseyAgent.warnings

TypeScript
async warnings(withinMs = 3 * DAY_MS): Promise<Warning[]>