DIM · Dagon Inference Marketplace

On-chain accounts

The settlement program im-channels holds buyer funds in a Vault, lets an owner delegate bounded spending to an agent with a Mandate, and pays one seller through a Channel. Every account is a program-derived address, starts with Anchor's 8-byte discriminator and then version: u8, and is Borsh-encoded little-endian. Clients read the tracked IDL at programs/idl/im_channels.json, never a build output (A23).

Constant Value
Program id 2grG8aUKE1HRjE8FqG4h5C2tmfAUG7PLsS8yL4nKrjdW
IDL im_channels 0.1.0 (spec 0.1.0)
MAX_SELLERS 8
MAX_ANCESTORS 3
ACCOUNT_VERSION 2
MAX_GRACE_SECS 2,592,000
Voucher length accepted by redeem 168

<sub>Generated from programs/idl/im_channels.json, programs/programs/im-channels/src/state.rs, programs/programs/im-channels/src/lib.rs.</sub>

Addresses

Account Address Created by
Vault PDA ["vault", owner, mint] init_vault
Mandate PDA ["mandate", vault, args.agent_key, args.nonce (u64 LE)] create_mandate
Channel PDA ["channel", vault, args.seller_settler, args.channel_epoch (u64 LE)] open_channel
Vault token account PDA [vault, token_program, mint] of the Associated Token Account program init_vault

<sub>Generated from programs/idl/im_channels.json.</sub>

u64 seeds are their 8 little-endian bytes. String seeds are their ASCII bytes.

Account Discriminator (sha256("account:<Name>")[..8])
Channel 31 9f 63 6a dc 57 db 58
Mandate 71 d8 62 9f b9 3f 37 12
Vault d3 08 e8 2b 02 98 75 77

<sub>Generated from programs/idl/im_channels.json.</sub>

Vault

One per owner and mint. It holds the owner's USDC in its associated token account and tracks two balances: free, which the owner can withdraw or commit, and reserved, the unspent budgets of open and closing channels. After every token movement, and on a no-op redeem, the program checks that the token account holds at least free + reserved (InsolventVault). Tokens sent straight to the token account are surplus: they are never credited to free and cannot be withdrawn.

Allocated: 130 bytes (8-byte discriminator + 122), rent-exempt minimum 1,795,680 lamports. Encoded length: 130 bytes; the unused tail is zero.

Offset Size Field Type Meaning
0 8 discriminator [u8; 8] sha256("account:Vault")[..8] = d3 08 e8 2b 02 98 75 77
8 1 version u8 Account layout version; every instruction requires ACCOUNT_VERSION.
9 32 owner pubkey Signs deposits, withdrawals and root Mandates.
41 32 mint pubkey Must equal the compiled MINT.
73 32 token_account pubkey The vault's associated token account; custody paths check it by address.
105 8 free u64 Unreserved balance, in micro-USDC.
113 8 reserved u64 Sum of budget − redeemed over open and closing channels.
121 8 last_channel_epoch u64 Epoch of the most recent channel opened in this vault (0 before the first). A31: a new channel must use exactly last_channel_epoch + 1, so a closed Channel PDA can never be re-created, old vouchers (bound to the channel address and epoch) never replay, and no opener can exhaust the epoch space.
129 1 bump u8 PDA bump.

<sub>Generated from programs/idl/im_channels.json, programs/programs/im-channels/src/state.rs.</sub>

A vault cannot be closed. Recreating it would reset last_channel_epoch to 0 and make old channel addresses, and their vouchers, reusable.

Mandate

A Mandate lets agent_key open channels from the vault within a per-period budget, a per-request cap, an allowlist of sellers and an expiry. A child Mandate (with parent) may only narrow its parent: its period budget fits in the parent's remaining period budget, its cap, grace and expiry are no larger than the parent's, and its sellers are ones the parent allows. A Mandate has at most MAX_ANCESTORS ancestors.

Allocated: 792 bytes (8-byte discriminator + 784), rent-exempt minimum 6,403,200 lamports. Encoded length: 248 + 32p + 64n bytes; the unused tail is zero.

Offset Size Field Type Meaning
0 8 discriminator [u8; 8] sha256("account:Mandate")[..8] = 71 d8 62 9f b9 3f 37 12
8 1 version u8 Account layout version.
9 32 owner pubkey Copied from the vault.
41 32 vault pubkey The vault this Mandate spends from.
73 32 agent_key pubkey The agent this Mandate authorizes.
105 8 nonce u64 PDA seed; lets one agent hold several Mandates (A8).
113 32 rent_payer pubkey Paid the account rent; the only possible recipient when it is closed.
145 1 + 32p parent Option<pubkey> Parent Mandate for a delegated (narrowed) Mandate; None for a root.
146 + 32p 8 budget_per_period u64 Most that channels opened in one period may commit, in micro-USDC.
154 + 32p 8 period_secs u64 Period length in seconds; nonzero.
162 + 32p 8 period_start i64 Unix seconds; rolled forward by whole periods before any use (A9).
170 + 32p 8 committed_in_period u64 Gross budgets of channels opened in the current period (A9). finalize never lowers it.
178 + 32p 8 reserved u64 Outstanding budget of channels opened under this Mandate or a descendant.
186 + 32p 8 spent_total u64 Lifetime redeemed amount; informational, and saturates at u64::MAX instead of failing.
194 + 32p 8 per_request_cap u64 Per-request limit the gateway applies to Holds on these channels.
202 + 32p 8 max_grace_secs u64 Largest grace G a channel may use (A21); 1 to MAX_GRACE_SECS.
210 + 32p 8 live_channels u64 Channels opened under this Mandate or a descendant and not yet finalized.
218 + 32p 8 children u64 Child Mandates that still exist (created and not yet closed).
226 + 32p 4 + 64n sellers Vec<SellerPair> Allowlisted (seller_settler, seller_payout_token) pairs (A20), at most MAX_SELLERS.
230 + 32p + 64n 1 any_seller bool Always false: create_mandate rejects true (SellerNotAllowed), and such a Mandate could not open channels.
231 + 32p + 64n 8 expiry i64 Unix seconds; the Mandate is inactive from this time.
239 + 32p + 64n 8 revoked_slot u64 Slot of revocation; 0 means live.
247 + 32p + 64n 1 bump u8 PDA bump.

Offsets after a variable-length field move: p = 1 when parent is Some, else 0; n = sellers.len(). An Option is a one-byte tag (0 None, 1 Some) followed by the value only when present; a Vec is a u32 length followed by its elements.

<sub>Generated from programs/idl/im_channels.json, programs/programs/im-channels/src/state.rs.</sub>

Because offsets after parent move, filter Mandates with getProgramAccounts only on the fixed prefix (discriminator through rent_payer).

Periods (A9). Before any instruction uses a Mandate, it rolls period_start forward by whole periods once now ≥ period_start + period_secs and resets committed_in_period to 0. Opening a channel adds its full budget to committed_in_period of the Mandate and every ancestor; finalizing never gives period capacity back.

Liveness (A10). A Mandate is live only while it and every ancestor are unrevoked (revoked_slot == 0) and unexpired (now < expiry).

SellerPair

64 bytes, embedded without a discriminator.

Offset Size Field Type Meaning
0 32 seller_settler pubkey Seller settlement key.
32 32 seller_payout_token pubkey Seller payout token account.

<sub>Generated from programs/idl/im_channels.json.</sub>

Channel

One payment relationship between a vault and one seller, at one epoch. session_key signs the buyer's Holds and vouchers; redeem pays the seller's seller_payout_token.

Allocated: 252 bytes (8-byte discriminator + 244), rent-exempt minimum 2,644,800 lamports. Encoded length: 220 + 32m bytes; the unused tail is zero.

Offset Size Field Type Meaning
0 8 discriminator [u8; 8] sha256("account:Channel")[..8] = 31 9f 63 6a dc 57 db 58
8 1 version u8 Account layout version.
9 32 vault pubkey The funding vault.
41 32 rent_payer pubkey Paid the account rent; finalize closes the channel to this account only.
73 1 + 32m mandate Option<pubkey> Mandate the channel was opened under, if any.
74 + 32m 32 seller_payout_token pubkey Token account that receives redemptions.
106 + 32m 32 seller_settler pubkey Seller settlement key; a PDA seed, and may begin closing.
138 + 32m 32 session_key pubkey Ed25519 key that signs Holds and vouchers.
170 + 32m 8 channel_epoch u64 Vault-wide epoch; a PDA seed and part of every voucher.
178 + 32m 8 budget u64 Most this channel can pay out, in micro-USDC.
186 + 32m 8 redeemed u64 Highest settled_total paid so far.
194 + 32m 8 service_end_unix i64 T: service end, Unix seconds.
202 + 32m 8 grace_secs u64 G: redemption grace after closing begins.
210 + 32m 8 close_deadline_unix i64 D = min(T, now) + G; 0 until closing begins.
218 + 32m 1 status ChannelStatus (u8 variant index) Open or Closing. A finalized channel no longer exists.
219 + 32m 1 bump u8 PDA bump.

Offsets after a variable-length field move: m = 1 when mandate is Some, else 0. An Option is a one-byte tag (0 None, 1 Some) followed by the value only when present; a Vec is a u32 length followed by its elements.

<sub>Generated from programs/idl/im_channels.json, programs/programs/im-channels/src/state.rs.</sub>

ChannelStatus

One byte: the Borsh variant index. A finalized channel has no status: finalize closes the account.

Value Variant
0 Open
1 Closing

<sub>Generated from programs/idl/im_channels.json, programs/programs/im-channels/src/state.rs.</sub>

Epochs (A31). channel_epoch is counted per vault across all sellers, starting at 1. open_channel accepts only vault.last_channel_epoch + 1, so a finalized channel's address is never recreated and its vouchers can never be replayed. Two opens built from the same vault snapshot race; the loser fails with EpochNotIncreasing and retries with the next epoch.

Rent

Rent is a deposit. A Channel is closed by finalize and a Mandate by close_mandate; both send all the account's lamports to the rent_payer stored when it was created, never to the caller. Naming any other refund account fails with Anchor's ConstraintHasOne (2001). Both closes are permissionless.