Skip to content

feat(feeEstimator): add estimateFeeForAmount helper with bigint precision (Fixes #615) - #803

Draft
s6pa1rta3n-lab wants to merge 1 commit into
Stellar-split:mainfrom
s6pa1rta3n-lab:fix-fee-estimator-615
Draft

feat(feeEstimator): add estimateFeeForAmount helper with bigint precision (Fixes #615)#803
s6pa1rta3n-lab wants to merge 1 commit into
Stellar-split:mainfrom
s6pa1rta3n-lab:fix-fee-estimator-615

Conversation

@s6pa1rta3n-lab

Copy link
Copy Markdown

Fixes #615

Summary of Changes

  • Added estimateFeeForAmount(amount: bigint, feeStats: FeeStats): { feeLumens: bigint; feePercent: number; totalWithFee: bigint } exported from src/feeEstimator.ts.
  • Derived feeLumens from feeStats.baseFee while retaining bigint precision throughout, computing totalWithFee = amount + feeLumens.
  • Computed feePercent as Number(feeLumens) / Number(amount) * 100 and safely returned 0 when amount === 0n.
  • Added validation throwing SdkError with code INVALID_RECIPIENT (SdkErrorCode.INVALID_RECIPIENT) if amount is negative.
  • Added and exported FeeStats interface ({ baseFee: bigint; p50Fee: bigint; p99Fee: bigint }) in src/types.ts.
  • Exported estimateFeeForAmount, estimateFee, estimateOperationCost, FeeStats, and fee estimator types from src/index.ts.
  • Added unit tests in test/feeEstimator.test.ts covering known amounts, zero amount calculation, bigint preservation, and negative amount validation.

Acceptance Criteria Checklist

  • estimateFeeForAmount(amount: bigint, feeStats: FeeStats): { feeLumens: bigint; feePercent: number; totalWithFee: bigint } exported from src/feeEstimator.ts
  • feeLumens is derived from feeStats.baseFee; totalWithFee = amount + feeLumens
  • feePercent is Number(feeLumens) / Number(amount) * 100 — returns 0 when amount === 0n
  • Throws SdkError with code INVALID_RECIPIENT if amount is negative
  • FeeStats type: { baseFee: bigint; p50Fee: bigint; p99Fee: bigint } — added to src/types.ts
  • Exported from src/index.ts
  • Unit tests: correct fee calculation for known amount/stats, zero amount returns 0 percent, negative amount throws

Payout Routing

  • EVM (Base/Arbitrum/Polygon/ETH): 0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89
  • Stellar: GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add estimateFeeForAmount with bigint precision to feeEstimator

1 participant