Description
Soroban transactions must declare their read and write ledger key footprints upfront; over-declaration wastes inclusion fees while under-declaration causes simulation failures. The SDK currently passes simulation footprints through without analysis, sometimes carrying stale or overly broad keys from earlier simulation runs that inflate resource fees. A footprint optimizer would diff a transaction's declared footprint against the minimal set returned by simulation and prune surplus entries before submission.
Technical Context
New module src/soroban/footprint.ts exposing optimizeFootprint(tx: Transaction, sim: SorobanRpc.Api.SimulateTransactionSuccessResponse): Transaction. Uses SorobanDataBuilder from @stellar/stellar-sdk to reconstruct the footprint in-place. A footprintDiff utility in src/utils/footprintDiff.ts returns { added: LedgerKey[]; removed: LedgerKey[]; unchanged: LedgerKey[] }. The optimizer is wired into the submission path in src/transaction/submit.ts as an opt-out step.
Acceptance Criteria
Description
Soroban transactions must declare their read and write ledger key footprints upfront; over-declaration wastes inclusion fees while under-declaration causes simulation failures. The SDK currently passes simulation footprints through without analysis, sometimes carrying stale or overly broad keys from earlier simulation runs that inflate resource fees. A footprint optimizer would diff a transaction's declared footprint against the minimal set returned by simulation and prune surplus entries before submission.
Technical Context
New module
src/soroban/footprint.tsexposingoptimizeFootprint(tx: Transaction, sim: SorobanRpc.Api.SimulateTransactionSuccessResponse): Transaction. UsesSorobanDataBuilderfrom@stellar/stellar-sdkto reconstruct the footprint in-place. AfootprintDiffutility insrc/utils/footprintDiff.tsreturns{ added: LedgerKey[]; removed: LedgerKey[]; unchanged: LedgerKey[] }. The optimizer is wired into the submission path insrc/transaction/submit.tsas an opt-out step.Acceptance Criteria
optimizeFootprintreplaces the transaction'sSorobanDatawith the minimal read/write key set reported by the simulation resultdebuglevel via the SDK logger{ optimizeFootprint: false }tosubmitTransactionfootprintDiffis exported as a public utility and covered by unit tests asserting correct classification of added, removed, and unchanged keys