Mandates
A Mandate is an on-chain spending rule that a vault owner gives to one agent key: a budget per period, a cap per request, a list of allowed sellers and an expiry. The owner can revoke it at any time. The Solana program checks the Mandate every time the agent opens a channel, and the seller's gateway checks the per-request cap on every hold, so an agent cannot spend outside it even if its code is wrong or compromised.
The rules a Mandate holds
| Field | Plain meaning |
|---|---|
agent_key |
The public key allowed to act under this Mandate. |
budget_per_period, period_secs |
The most the agent may commit to new channels in each period, in micro-USDC. |
per_request_cap |
The largest cap any single request may carry. |
sellers |
Up to 8 allowed {seller_settler, seller_payout_token} pairs. |
any_seller |
Accepted when narrowing, but in the MVP a Mandate with any_seller cannot open channels. |
expiry |
Unix time after which the Mandate is dead. |
max_grace_secs |
The longest closing grace period a channel opened under it may use. |
parent |
Set for a sub-agent's Mandate; see narrowing below. |
revoked_slot |
0 while live; set by revocation. |
Mandate accounts live at ["mandate", vault, agent_key, nonce], so one agent can hold several Mandates with different nonces.
Budget per period
The period budget limits channel budgets committed, not tokens consumed. When the agent opens a channel, the program adds the channel's full budget to committed_in_period and requires committed_in_period + budget ≤ budget_per_period. Money a channel later returns to the vault does not give period capacity back. When a period ends, the next instruction that touches the Mandate rolls period_start forward by whole periods and resets the committed amount to zero.
Example: with a budget of 10 USDC per day, an agent can open five 2 USDC channels today. If two of them close early with money left over, it still cannot open a sixth until tomorrow.
Per-request cap
Every request carries a cap: the most it may cost. Under a Mandate, the gateway refuses a hold whose cap is above per_request_cap with 402 cap_exceeds_limit, and the SDK refuses to sign it in the first place. A receipt's charge can never exceed its hold's cap, so the cap is a hard ceiling per request.
Sellers and expiry
An agent can only open channels whose (seller_settler, seller_payout_token) pair is on the list, so it cannot send money to an arbitrary account. A channel's service end must be at or before the Mandate's expiry, its grace must be at most max_grace_secs, and service end plus grace must be at most expiry + max_grace_secs.
Revocation
The owner, or the agent of any ancestor Mandate, can call revoke_mandate. From then on:
- the Mandate and all its descendants count as dead, because a Mandate is live only if it and every ancestor are unrevoked and unexpired;
- the agent can no longer open channels under it;
- anyone can call
close_on_revokedon its channels, which starts the normal close countdown. When the grace period ends,finalizereturns each channel's unspent budget to the vault.
The SDK marks a Mandate revoked locally before it submits the revocation, so it stops signing new holds immediately.
Sub-agents: narrowing
An agent can give a sub-agent its own Mandate by signing create_mandate with its Mandate as parent. The child must be narrower in every way: its period budget fits in what the parent has left this period, its per-request cap, expiry and grace are no larger, and its seller list is a subset. Anything wider fails with NotNarrowed (6010). Chains go at most three ancestors deep. Opening a channel under a child also counts against every ancestor's period budget.
import { ChannelWallet, type Mandate } from "@im/sdk";
declare const wallet: ChannelWallet; // owner's wallet, SolanaChannelBackend signed by the owner
declare const agentKey: string; // base58 public key of the agent
declare const seller: { settler: string; payoutToken: string };
const now = Math.floor(Date.now() / 1000);
const mandate: Mandate = await wallet.createMandate({
agentKey,
nonce: 1n,
budgetPerPeriod: 10_000_000n, // 10 USDC per period
periodSeconds: 86_400, // one day
perRequestCap: 50_000n, // at most 0.05 USDC per request
maxGraceSeconds: 3_600,
sellers: [{ seller_settler: seller.settler, seller_payout_token: seller.payoutToken }],
expiry: now + 30 * 86_400,
});
console.log("Mandate address:", mandate.address);
Closing a Mandate
A revoked or expired Mandate with no live channels, no reservation and no remaining children can be closed with close_mandate, which refunds its rent to whoever created it. Close children before parents. The SDK exposes this as wallet.closeMandate(address).