Overview
The invoice struct stores several redundant or padded fields that inflate storage costs. Refactor the on-chain representation to use compact types and remove redundant fields without breaking the external API.
Acceptance Criteria
- Audit all invoice struct fields; identify and remove computed fields (e.g.
funded_percentage derivable from funded_amount / target_amount)
- Replace
String status field with a u8 enum to save XDR bytes
- Replace
u64 timestamps with u32 ledger sequences where wall-clock time is not needed
- Measure before/after storage bytes per invoice using
soroban-sdk storage().has() size inspection
- Target: ≥ 20% reduction in bytes per invoice in persistent storage
get_invoice view function still returns the full external struct (status as string, etc.) — remapped from compact storage
- Migration: a one-time
compact_migrate(invoice_id) helper for upgrading stored invoices
- Integration tests verify stored and returned data is identical before/after migration
Overview
The invoice struct stores several redundant or padded fields that inflate storage costs. Refactor the on-chain representation to use compact types and remove redundant fields without breaking the external API.
Acceptance Criteria
funded_percentagederivable fromfunded_amount / target_amount)Stringstatus field with au8enum to save XDR bytesu64timestamps withu32ledger sequences where wall-clock time is not neededsoroban-sdkstorage().has()size inspectionget_invoiceview function still returns the full external struct (status as string, etc.) — remapped from compact storagecompact_migrate(invoice_id)helper for upgrading stored invoices