XMR native

This commit is contained in:
2026-10-20 12:09:58 -04:00
parent 558427545f
commit a1de67ea14
9 changed files with 341 additions and 12 deletions
+6 -5
View File
@@ -1,4 +1,6 @@
import { ADDITIONAL_MARKET_FEE } from '../../shared/market.ts';
import { formatXmr, XMR_ATOMIC_UNITS } from '../../shared/xmr-amount.ts';
import { allocateXmrSale } from '../../shared/xmr-pricing.ts';
/** No live payment adapter is reachable in this release. Never return a payable mock address. */
export function paymentMode(env: NodeJS.ProcessEnv = process.env): 'mock' {
@@ -7,16 +9,15 @@ export function paymentMode(env: NodeJS.ProcessEnv = process.env): 'mock' {
return mode;
}
export function xmrString(atomic: bigint): string {
return `${atomic / 1_000_000_000_000n}.${(atomic % 1_000_000_000_000n).toString().padStart(12, '0')}`;
return formatXmr(atomic);
}
/** Deterministic simulation ONLY. Round gross up and both independent seller fees down. */
export function mockQuote(priceCents: number, feeBps: number, usdCentsPerXmr: number) {
const rate = BigInt(usdCentsPerXmr);
const gross = (BigInt(priceCents) * 1_000_000_000_000n + rate - 1n) / rate;
const fee = gross * BigInt(feeBps) / 10_000n;
const additionalFee = gross * BigInt(ADDITIONAL_MARKET_FEE.bps) / 10_000n;
const gross = (BigInt(priceCents) * XMR_ATOMIC_UNITS + rate - 1n) / rate;
const { hosting: fee, author: additionalFee, sellerBeforeNetworkCosts } = allocateXmrSale(gross, feeBps);
return { invoice: { provider: 'mock' as const, amountXmr: xmrString(gross), address: null,
label: 'SIMULATION ONLY — no Monero payment address. Never send real XMR.' },
feeXmr: xmrString(fee), sellerNetXmr: xmrString(gross - fee - additionalFee),
feeXmr: xmrString(fee), sellerNetXmr: xmrString(sellerBeforeNetworkCosts),
additionalFee: { ...ADDITIONAL_MARKET_FEE, amountXmr: xmrString(additionalFee), payout: 'not-started' as const } };
}