From d18ad032bc2e97bbf0aa2903dca0734dc32e2093 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 16 Apr 2025 20:53:47 -0700 Subject: per-type fees --- lib/payments.ts | 11 +++++++---- routes/payments.ts | 5 +---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/payments.ts b/lib/payments.ts index 24eed057..2a2176e6 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -116,7 +116,7 @@ export const debit = async ({ PaymentType.liquid, PaymentType.lightning, ].includes(type) - ? Math.round((amount + fee + tip) * config.fee) + ? Math.round((amount + fee + tip) * config.fee[creditType]) : 0; if (aid) ourfee = 0; @@ -267,7 +267,10 @@ export const credit = async ({ creditType, ) ) - m.incrBy(`credit:${creditType}:${uid}`, Math.round(amount * config.fee)); + m.incrBy( + `credit:${creditType}:${uid}`, + Math.round(amount * config.fee[creditType]), + ); m.set(`invoice:${inv.id}`, JSON.stringify(inv)) .set(`payment:${p.id}`, JSON.stringify(p)) @@ -688,7 +691,7 @@ export const build = async ({ } const balance = await g(`balance:${aid}`); - let ourfee = Math.round(amount * config.fee); + let ourfee = Math.round(amount * config.fee[type]); const credit = await g(`credit:${type}:${aid}`); const covered = Math.min(credit, ourfee); ourfee -= covered; @@ -879,7 +882,7 @@ const reverse = async (p) => { const total = Math.abs(p.amount) + p.fee + p.ourfee; const ourfee = p.ourfee || 0; - const credit = Math.round(total * config.fee) - ourfee; + const credit = Math.round(total * config.fee[PaymentType.lightning]) - ourfee; l("reversing", p.id, p.amount, p.fee, total, ourfee, credit); diff --git a/routes/payments.ts b/routes/payments.ts index dd41b730..71f29da4 100644 --- a/routes/payments.ts +++ b/routes/payments.ts @@ -28,11 +28,8 @@ import { import rpc from "@coinos/rpc"; import got from "got"; import { v4 } from "uuid"; - import { PaymentType } from "$lib/types"; - import ln from "$lib/ln"; -const { URL } = process.env; export default { async info(_, res) { @@ -212,7 +209,7 @@ export default { const alias = node ? node.alias : payee.substr(0, 12); const amount = Math.round(amount_msat / 1000); - let ourfee = Math.round(amount * config.fee); + let ourfee = Math.round(amount * config.fee[PaymentType.lightning]); const credit = await g(`credit:lightning:${user.id}`); const covered = Math.min(credit, ourfee) || 0; ourfee -= covered; -- cgit v1.2.3