From d5a25736577f37adbe759119f2c3c4b9a2c4ec71 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Fri, 8 Aug 2025 18:05:33 +0200 Subject: [PATCH] Add proxy fee to minSendable of lnurl-pay (#2404) --- api/paidAction/receive.js | 4 ++-- lib/constants.js | 1 + pages/api/lnurlp/[username]/index.js | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/api/paidAction/receive.js b/api/paidAction/receive.js index c2400138..9abbe36a 100644 --- a/api/paidAction/receive.js +++ b/api/paidAction/receive.js @@ -1,4 +1,4 @@ -import { PAID_ACTION_PAYMENT_METHODS } from '@/lib/constants' +import { PAID_ACTION_PAYMENT_METHODS, PROXY_RECEIVE_FEE_PERCENT } from '@/lib/constants' import { toPositiveBigInt, numWithUnits, msatsToSats } from '@/lib/format' import { notifyDeposit } from '@/lib/webPush' import { getInvoiceableWallets } from '@/wallets/server' @@ -29,7 +29,7 @@ export async function getInvoiceablePeer (_, { me, models, cost, paymentMethod } } export async function getSybilFeePercent () { - return 10n + return PROXY_RECEIVE_FEE_PERCENT } export async function perform ({ diff --git a/lib/constants.js b/lib/constants.js index 76bdf5ca..f1a92ae7 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -92,6 +92,7 @@ export const MAX_INVOICE_DESCRIPTION_LENGTH = 640 export const RESERVED_MAX_USER_ID = 615 export const GLOBAL_SEED = USER_ID.k00b export const FREEBIE_BASE_COST_THRESHOLD = 10 +export const PROXY_RECEIVE_FEE_PERCENT = 10n export const SANCTIONED_COUNTRY_CODES = process.env.SANCTIONED_COUNTRY_CODES?.split(',') || [] diff --git a/pages/api/lnurlp/[username]/index.js b/pages/api/lnurlp/[username]/index.js index bc8be79c..68626eb0 100644 --- a/pages/api/lnurlp/[username]/index.js +++ b/pages/api/lnurlp/[username]/index.js @@ -1,7 +1,7 @@ import { getPublicKey } from 'nostr' import models from '@/api/models' import { lnurlPayMetadataString } from '@/lib/lnurl' -import { LNURLP_COMMENT_MAX_LENGTH } from '@/lib/constants' +import { LNURLP_COMMENT_MAX_LENGTH, PROXY_RECEIVE_FEE_PERCENT } from '@/lib/constants' export default async ({ query: { username } }, res) => { const user = await models.user.findUnique({ where: { name: username } }) @@ -9,10 +9,15 @@ export default async ({ query: { username } }, res) => { return res.status(400).json({ status: 'ERROR', reason: `user @${username} does not exist` }) } + let minSendable = 1000n + if (user.proxyReceive) { + minSendable += minSendable * PROXY_RECEIVE_FEE_PERCENT / 100n + } + const url = process.env.NODE_ENV === 'development' ? process.env.SELF_URL : process.env.NEXT_PUBLIC_URL return res.status(200).json({ callback: `${url}/api/lnurlp/${username}/pay`, // The URL from LN SERVICE which will accept the pay request parameters - minSendable: 1000, // Min amount LN SERVICE is willing to receive, can not be less than 1 or more than `maxSendable` + minSendable: Number(minSendable), // Min amount LN SERVICE is willing to receive, can not be less than 1 or more than `maxSendable` maxSendable: 1000000000, metadata: lnurlPayMetadataString(username), // Metadata json which must be presented as raw string here, this is required to pass signature verification at a later step commentAllowed: LNURLP_COMMENT_MAX_LENGTH, // LUD-12 Comments for payRequests https://github.com/lnurl/luds/blob/luds/12.md