diff --git a/__tests__/lib/fee-utils.test.ts b/__tests__/lib/fee-utils.test.ts index 20596ee..1ab38a8 100644 --- a/__tests__/lib/fee-utils.test.ts +++ b/__tests__/lib/fee-utils.test.ts @@ -5,12 +5,19 @@ import { formatFee, calculateBatchFees, TYPICAL_FEES, + FEE_BUFFER_MULTIPLIER, } from "@/lib/fee-utils"; +describe("FEE_BUFFER_MULTIPLIER", () => { + it("exports expected 15% safety buffer multiplier", () => { + expect(FEE_BUFFER_MULTIPLIER).toBe(1.15); + }); +}); + describe("calculateFeeBreakdown", () => { it("applies 15% buffer to minResourceFee", () => { const result = calculateFeeBreakdown(100_000); - expect(result.totalEstimated).toBe(Math.ceil(100_000 * 1.15)); + expect(result.totalEstimated).toBe(Math.ceil(100_000 * FEE_BUFFER_MULTIPLIER)); }); it("minFee plus bufferFee equals total", () => { @@ -26,7 +33,7 @@ describe("calculateFeeBreakdown", () => { it("calculates estimatedUsd with custom xlmPrice", () => { const result = calculateFeeBreakdown(10_000_000, 0.5); // 1 XLM at $0.50 expect(result.estimatedUsd).toBeCloseTo( - (0.5 * Math.ceil(10_000_000 * 1.15)) / 1e7, + (0.5 * Math.ceil(10_000_000 * FEE_BUFFER_MULTIPLIER)) / 1e7, 5, ); }); diff --git a/lib/fee-utils.ts b/lib/fee-utils.ts index f778815..f2bd7a6 100644 --- a/lib/fee-utils.ts +++ b/lib/fee-utils.ts @@ -18,7 +18,7 @@ export function calculateFeeBreakdown( xlmPrice: number = XLM_PRICE, ): FeeBreakdown { // Apply 15% buffer to ensure inclusion - const bufferMultiplier = 1.15; + const bufferMultiplier = FEE_BUFFER_MULTIPLIER; const totalFee = Math.ceil(minResourceFee * bufferMultiplier); const bufferFee = totalFee - minResourceFee; @@ -36,6 +36,11 @@ export function calculateFeeBreakdown( /** * Estimate typical fees for common operations */ +/** + * Default safety buffer multiplier (15%) applied to resource fees to ensure inclusion. + */ +export const FEE_BUFFER_MULTIPLIER = 1.15; + export const TYPICAL_FEES = { createStream: { min: 50000, typical: 80000, unit: "stroops" }, withdraw: { min: 30000, typical: 50000, unit: "stroops" },