Transaction Lifecycle
Every transaction in Agentic Wallet follows a deterministic state machine with clear failure points and recovery paths.Transaction States
Full Transaction Flow (Spend-Capable)
Step-by-Step Execution
1. Request Ingestion
1. Request Ingestion
Entry Point: Actions:
POST /api/v1/transactions- API Gateway validates API key and rate limits
- Gateway proxies to transaction-engine
- Transaction-engine validates schema with Zod
- Creates transaction record with
pendingstatus - Enqueues to durable outbox
2. Pre-Balance Snapshot
2. Pre-Balance Snapshot
Actions:
- Fetch current wallet balance from wallet-engine
- Store
preBalanceLamportsin transaction record - Update portfolio risk tracker with current balance
3. Transaction Building
3. Transaction Building
For
transfer_sol (built locally):- Fetch wallet public key from wallet-engine
- Check if destination account exists
- Validate amount meets rent-exemption minimum if unfunded
- Build
SystemProgram.transfer()instruction - Apply adaptive compute budget and priority fee
- Set recent blockhash
- Call
POST /api/v1/buildwith intent - Protocol adapter constructs protocol-specific instructions
- Returns unsigned transaction or instruction list
simulating4. Simulation
4. Simulation
Actions:
- Serialize unsigned transaction
- Call
connection.simulateTransaction()with failover - Retry with exponential backoff on RPC failures
- Simulation returns
ok: true - Logs stored for proof generation
- Proceeds to policy evaluation
- Simulation returns error
- Transaction marked as
failedwith simulation error - Failure proof generated
- Execution stops
5. Protocol Risk Evaluation
5. Protocol Risk Evaluation
Risk Checks (executed in transaction-engine):✓ Slippage Check:✓ Pool Allowlist:✓ Program Allowlist:✓ Pool Concentration:✓ Quote Staleness:✓ Oracle Deviation:✓ Portfolio Risk:
- Token exposure limits
- Protocol exposure limits
- Daily loss limits
- Max drawdown limits
policy_eval6. Policy Evaluation
6. Policy Evaluation
Actions:Fail-Secure:
- Call
POST ${policyEngineUrl}/api/v1/evaluate - Fetch active policies for wallet
- Execute all policy rules
- Aggregate results
allow: Proceed to signingdeny: Stop execution, mark as failedrequire_approval: Pause at approval gate- If policy-engine is unreachable → return
deny - If evaluation throws error → return
deny
7. Approval Gate (Conditional)
7. Approval Gate (Conditional)
Triggered When:
- Policy returns
require_approval - Protocol risk returns
require_approval requireApprovalOnDemandflag is set
- Set status to
approval_gate - Store in pending approvals table with 24h expiry
- Return
202 AcceptedwithawaitingApproval: true - Execution pauses here
POST /api/v1/transactions/:txId/approve- Proceeds to signing
POST /api/v1/transactions/:txId/reject- Marks as
failedwith rejection reason
8. Signing
8. Signing
Actions:
- Set status to
signing - Call
POST ${walletEngineUrl}/api/v1/wallets/:walletId/sign - Wallet-engine loads private key from key provider
- Signs transaction
- Returns signed transaction and signature
- Only wallet-engine can read private keys
- Transaction-engine never sees key material
- Signed transaction stored in durable outbox
- Signing fails → mark as
failed - Generate failure proof
9. Submission
9. Submission
Actions:Gasless Path (via Kora RPC):Failover:
- Set status to
submitting
- RPC pool rotates to healthy endpoint on failure
- Exponential backoff retry
- Durable outbox ensures recovery on restart
10. Post-Balance Verification
10. Post-Balance Verification
Actions:Purpose: Detect silent execution failures or sandwich attacks
- Fetch
postBalanceLamportsfrom wallet-engine - Calculate actual lamport delta:
postBalance - preBalance - Calculate expected delta based on transaction type
11. Position Indexing
11. Position Indexing
Actions:Lend Supply/Borrow:Escrow:
- Index DeFi positions based on transaction type
12. Execution Proof Generation
12. Execution Proof Generation
Actions:Storage:
- Generate deterministic proof with SHA-256 hashes
- Store proof in transaction record
- Store proof in separate proof table for quick lookup
- Emit audit event with proof hashes
13. Status Finalization
13. Status Finalization
Actions:
- Set status to
confirmed - Set
confirmedAttimestamp - Emit audit event:
tx_statuswith statusconfirmed - Increment metrics:
tx.confirmed,tx.confirmation_latency_ms_total - Return success response
Read-Only Transaction Flow
Transaction Types:query_balance, query_positions
These bypass the full pipeline:
Execute Query
For
query_balance:- Fetch balance from wallet-engine
- Fetch tokens from wallet-engine
query_positions:- Fetch positions from transaction-engine
- Fetch escrows from transaction-engine
- Fetch recent transactions
Escrow Lifecycle
Escrow operations are backed by a real Anchor program deployed to Solana devnet.Escrow State Machine
Escrow Operations
create_escrow
create_escrow
Intent:On-Chain Instruction:
- Calls
create_escrowon Anchor program - Creates escrow PDA with funds locked
- Emits
EscrowCreatedevent
- Creates escrow record with state
create_escrow
accept_escrow
accept_escrow
Intent:On-Chain Instruction:
- Counterparty calls
accept_escrow - Marks escrow as accepted
- Emits
EscrowAcceptedevent
- Updates escrow record state to
accept_escrow
release_escrow
release_escrow
Intent:On-Chain Instruction:
- Creator or arbiter releases funds to counterparty
- Transfers lamports minus fee
- Closes escrow account
- Emits
EscrowReleasedevent
- Updates escrow record state to
release_escrow
refund_escrow
refund_escrow
Conditions:
- Deadline passed and counterparty hasn’t accepted
- OR arbiter decides to refund
- Refunds lamports to creator
- Closes escrow account
- Emits
EscrowRefundedevent
- Updates escrow record state to
refund_escrow
dispute_escrow
dispute_escrow
Conditions:
- Counterparty or creator raises dispute
- Marks escrow as disputed
- Arbiter notified
- Emits
EscrowDisputedevent
- Updates escrow record state to
dispute_escrow
resolve_dispute
resolve_dispute
Conditions:On-Chain Instruction:
- Only arbiter can call
- Arbiter decides release or refund
- Executes corresponding action
- Emits
DisputeResolvedevent
- Updates escrow record state to
resolve_dispute
Milestone Escrow
Milestone Escrow
create_milestone_escrow:
- Creates multi-milestone escrow
- Each milestone has separate release conditions
- Releases individual milestone
- Remaining milestones stay locked
X402 Payment
X402 Payment
x402_pay:
- HTTP 402 payment protocol integration
- Pay-per-use resource access
- Micropayment escrow
Escrow Query Endpoints
Agent Execution Flow
Supervised Mode
Agent waits for external API calls:Capability Check
- Check
allowedIntentsincludes type - Check
allowedProtocolsincludes protocol - Verify capability manifest (if required)
Autonomous Mode
Agent runs on scheduler with built-in decision engine:Scheduler Tick
Every
AGENT_LOOP_INTERVAL_MS (default 5000ms):- Fetch wallet context (balance, positions, transactions)
- Build autonomy context
Decision Engine
For each strategy:
- Evaluate conditions
- Check cadence/cooldown/rate caps
- If conditions met → generate decision
Auto-Execute
- Execute intent via internal API call
- Mark decision as executed with timestamp
- Update decision state (last execution time, rate counters)
Durable Outbox Pattern
Problem
Transactions must survive:- Process crashes
- RPC timeouts
- Network failures
- Transient errors
Solution: Durable Outbox Queue
Claim
Outbox worker claims next pending job:
- Set
leaseId = uuid - Set
leaseExpiresAt = now + 30s - Increment
attempts - Return job
Mark Failed
On failure:
- If
retryableandattempts < maxAttempts:- Reset lease, job becomes pending again
- Else:
- Mark as permanently failed
Lease Expiry
If worker crashes mid-execution:- Lease expires after 30s
- Job becomes available for retry
- Another worker can claim it
RPC Failover Flow
Problem
Single RPC endpoint can:- Go down
- Rate limit
- Return stale data
- Time out
Solution: Health-Scored Pool
Adaptive Execution Tuning
Problem
Solana transactions need:- Appropriate compute budget
- Competitive priority fee
- Both vary by network conditions
Solution: Adaptive Tuning
Next Steps
Trust Boundaries
Deep dive into security model and control boundaries
Services
Detailed service-by-service architecture reference