Owner actions
Everything only the owner may do is built by the SDK as an unsigned transaction. The bytes go to the owner's own device — a wallet, or the passkey on their phone — which signs and submits them. The agent never signs these.
From builder to bytes#
- Build the transaction with
ownerTx(a lender),borrowerOwnerTx(a borrower) orrenewTx(any agent). - Turn it into bytes with
unsignedTx(client, tx, ownerAddress). - The owner's device signs
txBytesand submits it.
import { ownerTx, unsignedTx } from "@esseyonsui/sui-sdk";
const tx = ownerTx("deposit", refs, { amount: 20_000_000n }); // 20 USDC
const u = await unsignedTx(chain.client, tx, refs.owner);
// u = { kind: "unsigned", sender, txBytes, kindBytes } -> to the owner's devicetxBytes is the full transaction, with gas paid by the owner; kindBytes is the transaction without gas, for a sponsor or an owner page. If the full transaction cannot be built — for example the owner has no gas yet — txBytes is null and txError says why; if even the kind cannot be built, unsignedTx throws INVALID_ARGUMENT.
In the localnet run the MCP server built a renewal this way and a separate owner key signed it, standing in for the owner's phone.
Lender: ownerTx(action, refs, params)#
| Action | Params | On chain |
|---|---|---|
create | capExpiresAtMs, optional mandate, optional amount | treasury::new_with_cap, then set_mandate and set_collateral if mandate is given, a deposit if amount is given, then treasury::share; the OwnerCap to the owner. Without the options it opens the account only. |
set-mandate | mandate, optional capExpiresAtMs, optional amount | set_limits (if a new expiry), set_mandate, set_collateral, then a deposit if amount is given. |
deposit | amount | treasury::deposit. |
revoke | — | treasury::revoke. |
withdraw | amount | treasury::withdraw to the owner. |
claim-default | claim (the LenderClaim's object ref), loanId | Receives the claim out of the treasury and collects the overdue loan's collateral to the owner. |
A lender's cap gets a spending limit of one unit, payable only to the owner: it funds loans through the mandate, never by spending.
Borrower: borrowerOwnerTx(action, refs, params)#
| Action | Params | On chain |
|---|---|---|
create | limits, optional borrow, collateral (needs borrow), cashFloat | Two new_with_cap calls (a SUI treasury and a cash treasury, each cap paying only the owner), the SUI cap's set_borrow_mandate pinned to the new cash treasury (owner_treasury), the deposits, then two share calls. Without the options it opens the accounts only. Deposit coins never come from the gas coin. |
deposit | collateral and/or cashFloat; with collateral, also limits and borrow | Re-sets both caps' limits and the SUI cap's borrow rules (set_borrow_mandate), then deposits. |
revoke | — | Revokes both caps. |
withdraw | withdraw: { sui, cash } | Withdraws either or both to the owner. |
repay | loan, amount | Withdraws amount from cash, repays through the desk with the OwnerCap, returns the change to cash. |
claim | loan | borrower::owner_claim. |
add-collateral | loan, amount (SUI) | borrower::owner_add_collateral. |
The borrow rules are { maxRateBps, minTermMs, latestMaturityMs, poolId, allowance }, and the SDK adds the borrower's own cash treasury as the one place a new loan's proceeds may land; it takes that id from the treasury pair in refs, never from other input. A desk borrow whose proceeds would go anywhere else aborts 28. A desk loan that opens above the rate, an offer loan with a shorter term or maturing after the latest maturity, any loan opened after the latest maturity, and a borrow from any pool but poolId (null refuses every pool) abort on chain; with no rules set, desk loans abort.
allowance is what the desk may still borrow, in the loan coin's smallest unit. Each borrow uses it up (a refinance only its new principal over the old debt), repaying does not restore it, and a borrow past it aborts 29. The allowance is checked after the collateral draw: a desk borrow first takes its collateral from the SUI treasury through treasury::charge, so a borrow whose collateral would pass the SUI cap's per-transaction or per-day limit aborts there (4 EOverPerTx, 5 EOverPerDay) before abort 29 is reached; with the hosted form, whose SUI cap per-day limit is the collateral plus the spare SUI, a second borrow in the same 24 hours meets abort 5 first. Signing a deposit with collateral and rules again sets a fresh one; EsseyAgent.allowance() reads what is left. In the localnet run the owner re-set the rules after an abort 29 and the same borrow then landed.
Testnet. Borrow rules set by an SDK-built deposit were exercised on testnet in one run against the earlier package 0x628b…6579, before the allowance existed. The live package 0x6786…61b4 takes the allowance as the last argument of set_borrow_mandate. The allowance is proven on localnet.
Renew: renewTx(pkg, sides, expiresAtMs)#
One set_limits call per cap, with the new expiry and every other limit as it is.