Delegation PDA
Seeds:[b"delegation", delegator.as_ref(), delegate.as_ref(), delegation_id.to_le_bytes()]
Permission flags
Seven boolean flags control what a delegate can do:Constraints
Constraints limit what a delegate can do even when they have the right permission:Delegation depth
Delegations support up to 3 levels of chaining:
When creating a sub-delegation, the program enforces that the child’s constraints are a subset of the parent’s:
max_spend_totalcannot exceed the parent’s remaining budget (parent.max_spend_total - parent.spent_total).expires_atcannot be later than the parent’s expiry.allowed_tokensmust be a subset of the parent’s allowed tokens.allowed_programsmust be a subset of the parent’s allowed programs.- Permissions must be a subset of the parent’s permissions.
Cascading invalidation via owner_version
When an agent NFT is transferred andclaim_agent is called, the owner_version on the AgentIdentity increments. Every delegation stores the owner_version at creation time. At use time, the program checks:
owner_version check.
DelegationBuilder fluent API
The SDK provides a builder pattern for constructing delegations:Permission methods
Constraint methods
x402 budget integration
Delegations power budget-based x402 payments. Instead of signing every payment transaction, a user sets up a spending budget once and the x84 facilitator auto-debits within the budget constraints.1
Create delegation and SPL approve in one transaction
The user signs a single transaction containing two instructions:
spl_token::approve— authorizes the x84 facilitator wallet as delegate on the user’s token account (ATA), with an amount matchingmax_spend_total.x84::create_delegation— creates the on-chain delegation withcan_transact = trueand desired constraints.
2
Facilitator auto-debits on each request
When the user calls an x402-gated agent endpoint, the x402 gate reads the
X-DELEGATION header, loads the Delegation PDA, verifies all constraints, and uses the SPL Token delegate authority to transfer tokens from the user’s ATA. No per-request signature is needed.3
Spent tracking
Each delegated settlement updates
delegation.spent_total on-chain, providing a full audit trail of cumulative spending per delegation.Revocation
active status during verification.
Delegation verification checks (full list)
Delegation verification checks (full list)
When a delegate attempts to use their delegation, the program runs these checks in order:
delegation.active == truedelegation.delegate == callerdelegation.nft_mint == agent.nft_mintdelegation.owner_version == agent.owner_version- Expiry:
delegation.expires_at == 0ordelegation.expires_at > now - Uses:
delegation.uses_remaining == 0ordelegation.uses_remaining > 0 - Required permission flag is set
- If spending:
amount <= max_spend_per_txandspent_total + amount <= max_spend_total - If token specified:
allowed_tokensis empty or contains the token mint - If program specified:
allowed_programsis empty or contains the program ID - If
parent_delegationis set: recursively verify the parent (max depth ensures termination)