Add proxy fee to minSendable of lnurl-pay (#2404)

This commit is contained in:
ekzyis 2025-08-08 18:05:33 +02:00 committed by GitHub
parent 0e842e9915
commit d5a2573657
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 4 deletions

View File

@ -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 { toPositiveBigInt, numWithUnits, msatsToSats } from '@/lib/format'
import { notifyDeposit } from '@/lib/webPush' import { notifyDeposit } from '@/lib/webPush'
import { getInvoiceableWallets } from '@/wallets/server' import { getInvoiceableWallets } from '@/wallets/server'
@ -29,7 +29,7 @@ export async function getInvoiceablePeer (_, { me, models, cost, paymentMethod }
} }
export async function getSybilFeePercent () { export async function getSybilFeePercent () {
return 10n return PROXY_RECEIVE_FEE_PERCENT
} }
export async function perform ({ export async function perform ({

View File

@ -92,6 +92,7 @@ export const MAX_INVOICE_DESCRIPTION_LENGTH = 640
export const RESERVED_MAX_USER_ID = 615 export const RESERVED_MAX_USER_ID = 615
export const GLOBAL_SEED = USER_ID.k00b export const GLOBAL_SEED = USER_ID.k00b
export const FREEBIE_BASE_COST_THRESHOLD = 10 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(',') || [] export const SANCTIONED_COUNTRY_CODES = process.env.SANCTIONED_COUNTRY_CODES?.split(',') || []

View File

@ -1,7 +1,7 @@
import { getPublicKey } from 'nostr' import { getPublicKey } from 'nostr'
import models from '@/api/models' import models from '@/api/models'
import { lnurlPayMetadataString } from '@/lib/lnurl' 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) => { export default async ({ query: { username } }, res) => {
const user = await models.user.findUnique({ where: { name: username } }) 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` }) 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 const url = process.env.NODE_ENV === 'development' ? process.env.SELF_URL : process.env.NEXT_PUBLIC_URL
return res.status(200).json({ return res.status(200).json({
callback: `${url}/api/lnurlp/${username}/pay`, // The URL from LN SERVICE which will accept the pay request parameters 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, 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 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 commentAllowed: LNURLP_COMMENT_MAX_LENGTH, // LUD-12 Comments for payRequests https://github.com/lnurl/luds/blob/luds/12.md