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
+3 -2
View File
@@ -3,6 +3,7 @@ import { mkdir,open,unlink,chmod } from 'node:fs/promises';
import { join } from 'node:path';
import { z } from 'zod';
import { ADDITIONAL_MARKET_FEE } from '../../shared/market.ts';
import { allocateXmrSale } from '../../shared/xmr-pricing.ts';
import { NETWORK } from '../../shared/network.ts';
import { CHAIN_ID,sha256,verifySignature,transactionId } from '../testnet/consensus.ts';
import { atomicXmr,fiatCents,validateXmrAddress } from './xmr.ts';
@@ -107,9 +108,9 @@ export class SettlementLab {
s.quote=await this.processor.createInvoice(id,s.terms.priceCents);
await validateXmrAddress(s.quote.address);const gross=atomicXmr(s.quote.amountXmr);
if(!s.quote.id||gross<=0n)throw new Error('Invalid quote');
const hosting=gross*BigInt(s.terms.feeBps)/10000n,fee=gross*100n/10000n;
const {hosting,author:fee,sellerBeforeNetworkCosts}=allocateXmrSale(gross,s.terms.feeBps);
s.hostingXmr=xmrString(hosting);
s.seller={amount:xmrString(gross-hosting-fee),destination:s.terms.sellerXmr,state:'ready'};
s.seller={amount:xmrString(sellerBeforeNetworkCosts),destination:s.terms.sellerXmr,state:'ready'};
s.fee={amount:xmrString(fee),destination:ADDITIONAL_MARKET_FEE.address,state:fee===0n?'skipped':'ready'};
s.quoteDigest=sha256(buyerInvoiceMessage(s));s.status='quote';this.save(s);return s;
}catch{return this.hold(s,'invoice-create-ambiguous-or-invalid');}