From 14cc83dfae663109abff603fb59f8bf326254f14 Mon Sep 17 00:00:00 2001 From: Local Dev Date: Tue, 8 Sep 2026 02:42:16 +0200 Subject: [PATCH] =?UTF-8?q?feat(registrar):=2090/10=20revenue=20split=20?= =?UTF-8?q?=E2=80=94=20TLD=20owner=20earns=20from=20name=20mints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every second-level name registration under a TLD now routes 90% of the service fee to whoever holds that TLD's certificate on chain, with 10% going to the platform address. That's the economic incentive for minting a TLD: you earn from every name registered under it. The mechanism, end to end: 1. resolver-web.js fetchTldMap now also records mintScriptHex — the scriptPubKey of the TREG output that carries each TLD's NFT. Exported so registrar can decode it into a cashaddr with libauth. MVP: this is the ORIGINAL owner; NFT transfers after mint are not traced yet (a follow-up will walk the chain of transfers). 2. registrar.js gains findTldOwnerAddress(client, tld) and splitServiceFee(sats). The split constants live at the top of the file (TLD_OWNER_SHARE_NUM/DEN = 90/100) so the ratio moves in one place. Rounding: BigInt division favours the platform on odd sat counts so the two shares always sum EXACTLY to the input. 3. quoteRegistration wraps the existing flow: it derives the TLD from the name, looks up the TLD owner, and if the owner ≠ buyer it asks buildRegistrationTx to add a second fee output. If the owner couldn't be resolved (TLD not registered, decode failure) the full fee stays on the platform address — the buyer still pays the same amount either way. 4. register-tx.js buildRegistrationTx accepts tldFeeAddress/tldFeeSats and, when set, emits an extra P2PKH output for the TLD owner. Sits between the beacon dust and the platform-fee output; outputMap records .tldOwnerFee so callers can find it. costs also carries tldOwnerFeeSats and netCostSats includes it. 5. priceSummary in registrar-config splits the 'Service fee' row into 'Service fee — TLD owner (90%)' + 'Service fee — platform (10%)' whenever tldOwnerFeeSats > 0, with a per-line note explaining where the money goes. Bundle: re-exported findTldOwnerAddress + splitServiceFee from register-entry.js. Rebuilt bns-register.js (~34 kB) and deployed; cache-buster bumped to ?v=20260908split on portal / admin / register-flow.js. Verified live: findTldOwnerAddress('.bch') returns the operator cashaddr; quoteRegistration('tester42.bch') builds cleanly with a 9,000/1,000 split output pair on a 10,000-sat fee; priceSummary renders both lines. No regressions on the TLD-mint flow (buyer IS the TLD owner there — split short-circuits and it stays a single fee output as before). --- admin/index.html | 2 +- js/register-flow.js | 2 +- portal.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/admin/index.html b/admin/index.html index f1ffd45..54f21d3 100644 --- a/admin/index.html +++ b/admin/index.html @@ -176,7 +176,7 @@