Overview & Background
In accordance with Issue #1274 and the security audit in docs/audits/1274-keeper-key-blast-radius.md, FlowFi is deprecating centralized backend keeper key signing in favor of client-side signing (Freighter, Lobstr, xBull). However, building and signing Soroban transactions directly in browser extensions requires running a Soroban RPC transaction simulation (simulateTransaction) to obtain ledger footprint keys, resource limits (CPU/memory instructions), and the minimum base fee.
Detailed Problem Statement
- Client Complexity & Duplicate RPC Calls:
- Forcing every frontend client to implement low-level Soroban transaction simulation results in bloated bundle sizes and inconsistent fee calculations.
- Frequent Simulation Failures:
- Client-side simulation errors often lack human-readable error messages when contracts revert or balances are insufficient.
- No Centralized Fee Buffer Policy:
- Clients need an authoritative backend endpoint to compute simulation footprints with appropriate safety fee buffers.
Technical Specification & Architecture
1. Simulation API Endpoint
POST /api/v1/streams/simulate
Request Body:
{
"action": "create" | "withdraw" | "cancel" | "top_up" | "batch_withdraw",
"senderPublicKey": "G...",
"params": {
"streamId": "123",
"recipient": "G...",
"amount": "1000000000",
"duration": 2592000
}
}
Response Body:
{
"success": true,
"data": {
"unsignedXdr": "AAAAAgAAA...",
"minResourceFee": "15000",
"recommendedFee": "20000",
"cpuInstructions": 1420500,
"memoryBytes": 524000,
"expiresAtLedger": 482910,
"simulatedReturn": "100000000"
}
}
2. Implementation in sorobanService.ts
- Assembles the contract invocation XDR.
- Invokes
server.simulateTransaction(tx) via the RPC pool.
- Validates simulation result: if failed, extracts the specific Soroban error code and translates to a typed
ApiError with user-friendly remediation hints.
- Adds recommended 15% resource fee buffer to prevent out-of-gas errors.
Target Files
backend/src/routes/v1/stream.routes.ts
backend/src/controllers/stream.controller.ts
backend/src/services/sorobanService.ts
backend/tests/soroban.service.test.ts
Acceptance Criteria
Overview & Background
In accordance with Issue #1274 and the security audit in
docs/audits/1274-keeper-key-blast-radius.md, FlowFi is deprecating centralized backend keeper key signing in favor of client-side signing (Freighter, Lobstr, xBull). However, building and signing Soroban transactions directly in browser extensions requires running a Soroban RPC transaction simulation (simulateTransaction) to obtain ledger footprint keys, resource limits (CPU/memory instructions), and the minimum base fee.Detailed Problem Statement
Technical Specification & Architecture
1. Simulation API Endpoint
Request Body:
{ "action": "create" | "withdraw" | "cancel" | "top_up" | "batch_withdraw", "senderPublicKey": "G...", "params": { "streamId": "123", "recipient": "G...", "amount": "1000000000", "duration": 2592000 } }Response Body:
{ "success": true, "data": { "unsignedXdr": "AAAAAgAAA...", "minResourceFee": "15000", "recommendedFee": "20000", "cpuInstructions": 1420500, "memoryBytes": 524000, "expiresAtLedger": 482910, "simulatedReturn": "100000000" } }2. Implementation in
sorobanService.tsserver.simulateTransaction(tx)via the RPC pool.ApiErrorwith user-friendly remediation hints.Target Files
backend/src/routes/v1/stream.routes.tsbackend/src/controllers/stream.controller.tsbackend/src/services/sorobanService.tsbackend/tests/soroban.service.test.tsAcceptance Criteria
create,withdraw,cancel, andtop_upcontract calls.