Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions __tests__/lib/fee-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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,
);
});
Expand Down
7 changes: 6 additions & 1 deletion lib/fee-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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" },
Expand Down
Loading