Skip to main content
These functions read state directly from chain. No backend dependency: the policy object and the audit events are the source of truth.

readPolicyObject

readPolicyObject(client, policyId): Promise<PolicyObject>
Reads the live multi-asset policy — the authoritative caps, allowed actions, scope, expiry, and state.
type PolicyObject = {
  caps: { coinType: string; perTxCap: string; perDayCap: string; spentToday: string }[];
  actions: number[];
  allowedPackages: string[];
  expiresAtMs: string;
  revoked: boolean;
  paused: boolean;
};
readPolicy(client, policyId) returns a flatter PolicySnapshot (single budget asset) with agentId, perTxCap, perDayCap, spentToday, allowedPackages, expiresAtMs, revoked, paused, version.

vaultBalances

vaultBalances(client, vaultId): Promise<{ coinType: string; amount: string }[]>
Every coin balance the multi-asset vault holds. Balances live in dynamic fields keyed by coin type; this enumerates them and reads each amount. Returns [] if the vault has no assets.

readAuditLog

readAuditLog(client, corePkg, limit = 50): Promise<AuditEvent[]>
The on-chain activity log: AllowedAction, WithdrawalAttested, PolicyRevoked, PolicyUpdated events emitted by corePkg, in descending order.
type AuditEvent = { type: string; txDigest: string; timestampMs: string | null; data: unknown };

decodePolicyAbort

decodePolicyAbort(err): { code: number; reason_code: string; message: string } | null
Extracts a policy MoveAbort from a thrown error or a devInspect failure status, and maps the abort code to a stable reason. Only aborts raised by the policy module are decoded; returns null for any other failure (so you can tell a policy denial apart from a liquidity or gas failure).
try {
  await agent.swap(2_000_000_000n);
} catch (e) {
  const ab = decodePolicyAbort(e);
  if (ab) console.log(ab.reason_code, ab.message); // "over_per_tx_cap", "over per-tx cap"
  else throw e;                                    // not a policy decision
}
Codereason_code
1policy_revoked
2policy_expired
3agent_paused
4over_per_tx_cap
5over_per_day_cap
6package_not_allowed
7wrong_policy
8action_not_allowed
9action_config_missing
10asset_not_allowed

guardedSubmit

Dry-run, record a denial without spending gas, and submit only when allowed.