diff --git a/src/lib/registrar.js b/src/lib/registrar.js index 844af12..80a3cbd 100644 --- a/src/lib/registrar.js +++ b/src/lib/registrar.js @@ -70,8 +70,17 @@ export async function findTldOwnerAddress(client, tld, prefix = REGISTRAR.addres */ export function splitServiceFee(serviceFeeSats) { const total = BigInt(serviceFeeSats ?? 0n); - const tldOwner = (total * TLD_OWNER_SHARE_NUM) / TLD_OWNER_SHARE_DEN; - const platform = total - tldOwner; + let tldOwner = (total * TLD_OWNER_SHARE_NUM) / TLD_OWNER_SHARE_DEN; + let platform = total - tldOwner; + // An output below the dust limit is rejected by the network, so a cheap + // name's split would make its registration unmineable. The small share + // then goes with the big one: the TLD owner keeps all of a fee whose + // platform share is dust, and the platform keeps all of a fee that is + // too small to split at all. + const DUST = 546n; + if (platform > 0n && platform < DUST) { tldOwner = total; platform = 0n; } + if (tldOwner > 0n && tldOwner < DUST) { platform = total; tldOwner = 0n; } + if (platform < DUST) platform = 0n; // a fee below the dust limit cannot be paid at all return { tldOwnerFeeSats: tldOwner, platformFeeSats: platform }; }