Skip to content

Sponsorship Reserve Verifier #502

Description

@Kingsman-99

Description

The SDK's sponsorship feature (via src/sponsorship.ts) builds BeginSponsoringFutureReserves / EndSponsoringFutureReserves operation pairs but does not verify in advance that the sponsoring account has sufficient XLM reserve to cover the new ledger entries it will sponsor. This causes submission failures that are cryptic to callers. A pre-submission reserve verifier should calculate the required reserve increase and check the sponsor's available balance.

Technical Context

Extend src/sponsorship.ts and src/preflightChecker.ts. Uses @stellar/stellar-sdk Server.loadAccount() to read subentry_count and num_sponsored, and the Stellar network's BASE_RESERVE constant. Reference SponsorshipConfig from src/types.ts. Add InsufficientSponsorReserveError to src/errors.ts. Expose the check as a method callable before the sponsorship transaction is built in src/txBuilder.ts.

Acceptance Criteria

  • verifySponsorReserve(sponsorId: string, newEntries: number): Promise<ReserveCheckResult> calculates required XLM and compares with available balance
  • Returns { sufficient: boolean, required: string, available: string, shortfall?: string } typed in src/types.ts
  • Throws InsufficientSponsorReserveError with the shortfall amount when the check fails and throwOnInsufficient: true
  • src/sponsorship.ts calls verifySponsorReserve() before building the sponsorship operation pair
  • Unit tests mock loadAccount() responses and assert correct reserve arithmetic for 0, 1, and 10 new entries
  • All CI checks (npm test, npm run build, ESLint/TypeScript) pass and the branch has no merge conflicts

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions