EsseyAgent
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#
| Method | Signs | Returns | Throws (before signing) |
|---|---|---|---|
EsseyAgent.start(options) | no | EsseyAgent | NETWORK_REFUSED (deployment for another chain), any key-separation code |
execute(tx) | yes | Landed | NOT_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, cancelOffer | yes | Landed | as 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, claim | yes, through the borrower desk | Landed | as 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, once | Landed | NOT_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, separation | no | reads | NOT_FOUND (offer, loan) |
allowance() | no | bigint 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.
export type AgentAccount = {
treasuryId: string;
agentCapId: string;
cash?: { treasuryId: string; capId: string };
};AgentOptions#
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#
export type Warning = {
kind: "cap-expiring" | "cap-gone" | "underwater" | "repay-due";
id: string;
text: string;
};EsseyAgent#
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.
static async start(o: AgentOptions): Promise<EsseyAgent>EsseyAgent.account
get account(): AgentAccount | nullEsseyAgent.separation
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.
async execute(tx: Transaction): Promise<Landed>EsseyAgent.offer
async offer(offerId: string): Promise<OfferView>EsseyAgent.loan
async loan(loanId: string): Promise<LoanView>EsseyAgent.myLoans
Borrower: loans whose deed its SUI treasury holds. Lender: loans its treasury funded.
async myLoans(): Promise<LoanView[]>EsseyAgent.postOffer
async postOffer(terms: OfferTerms): Promise<Landed>EsseyAgent.cancelOffer
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.
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.
borrowFromPool(collateral: bigint, amount: bigint): Promise<Landed>EsseyAgent.repay
async repay(loanId: string): Promise<Landed>EsseyAgent.refinance
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
addCollateral(loanId: string, amount: bigint): Promise<Landed>EsseyAgent.claim
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.
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.
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).
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.
| Field | Meaning |
|---|---|
| perTx | The most one spend may move. A spend of this size passes. One base unit more aborts EOverPerTx (code 4) in treasury::charge. |
| perDay | The 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). |
| spent24h | That window's sum so far, the fourth value limits_of returns. |
| expiresAtMs | When 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).
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.
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.
capSides(): { coinType: string; treasuryId: string; capId: string }[]EsseyAgent.warnings
async warnings(withinMs = 3 * DAY_MS): Promise<Warning[]>