23 lines
1.4 KiB
TypeScript
Executable File
23 lines
1.4 KiB
TypeScript
Executable File
import { ADDITIONAL_MARKET_FEE } from '../../shared/market.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' {
|
|
const mode = env.WIKIDECK_PAYMENT_MODE ?? 'mock';
|
|
if (mode !== 'mock') throw new Error('Real payments are launch-gated. Only WIKIDECK_PAYMENT_MODE=mock is supported until production settlement review.');
|
|
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')}`;
|
|
}
|
|
/** 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;
|
|
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),
|
|
additionalFee: { ...ADDITIONAL_MARKET_FEE, amountXmr: xmrString(additionalFee), payout: 'not-started' as const } };
|
|
}
|