forked from davedumto/LancePay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-fee-quote.js
More file actions
96 lines (78 loc) · 2.73 KB
/
Copy pathtest-fee-quote.js
File metadata and controls
96 lines (78 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Simple test script for the fee-quote API logic
* Run with: node test-fee-quote.js
*/
const FEE_CONFIG = {
onRamp: {
percentageFee: 0.035, // 3.5%
fixedFee: 0.50,
},
offRamp: {
percentageFee: 0.015, // 1.5%
fixedFee: 0.25,
},
};
function calculateFees(usdAmount, exchangeRate, stellarBaseFee = 0.00001) {
// Step 1: Calculate on-ramp fee
const onRampFee = (usdAmount * FEE_CONFIG.onRamp.percentageFee) + FEE_CONFIG.onRamp.fixedFee;
// Step 2: Network fee (Stellar)
const networkFee = stellarBaseFee;
// Step 3: Calculate net USDC after on-ramp and network fees
const netUsdc = usdAmount - onRampFee - networkFee;
// Step 4: Calculate off-ramp fee
const offRampFee = (netUsdc * FEE_CONFIG.offRamp.percentageFee) + FEE_CONFIG.offRamp.fixedFee;
// Step 5: Final USDC after all fees
const finalUsdc = netUsdc - offRampFee;
// Step 6: Convert to NGN
const finalNgnValue = finalUsdc * exchangeRate;
// Step 7: Calculate effective rate
const effectiveRate = finalNgnValue / usdAmount;
return {
netUsdcValue: parseFloat(finalUsdc.toFixed(2)),
finalNgnValue: parseFloat(finalNgnValue.toFixed(2)),
feeBreakdown: {
onRamp: parseFloat(onRampFee.toFixed(2)),
network: parseFloat(networkFee.toFixed(2)),
offRamp: parseFloat(offRampFee.toFixed(2)),
},
effectiveRate: parseFloat(effectiveRate.toFixed(2)),
};
}
// Test scenarios
console.log("=== Fee Quote Calculator Tests ===\n");
// Test 1: Basic Quote for $100
console.log("Test 1: $100 USD");
const test1 = calculateFees(100, 1600);
console.log(JSON.stringify({
usdAmount: 100.00,
...test1,
timestamp: new Date().toISOString()
}, null, 2));
console.log(`\nVerification: ${test1.netUsdcValue} + ${test1.feeBreakdown.onRamp} + ${test1.feeBreakdown.network} + ${test1.feeBreakdown.offRamp} ≈ 100.00`);
const total = test1.netUsdcValue + test1.feeBreakdown.onRamp + test1.feeBreakdown.network + test1.feeBreakdown.offRamp;
console.log(`Total: ${total.toFixed(2)}\n`);
// Test 2: Large amount $10,000
console.log("\nTest 2: $10,000 USD");
const test2 = calculateFees(10000, 1600);
console.log(JSON.stringify({
usdAmount: 10000.00,
...test2,
timestamp: new Date().toISOString()
}, null, 2));
// Test 3: Small amount $10
console.log("\nTest 3: $10 USD (small amount)");
const test3 = calculateFees(10, 1600);
console.log(JSON.stringify({
usdAmount: 10.00,
...test3,
timestamp: new Date().toISOString()
}, null, 2));
// Test 4: Different exchange rate
console.log("\nTest 4: $100 USD with different exchange rate (1700 NGN/USD)");
const test4 = calculateFees(100, 1700);
console.log(JSON.stringify({
usdAmount: 100.00,
...test4,
timestamp: new Date().toISOString()
}, null, 2));
console.log("\n=== All Tests Complete ===");