add pub fee to quote

This commit is contained in:
boufni95 2025-11-11 20:05:06 +00:00
parent c1e698a3af
commit 9b5d5e4105
5 changed files with 31 additions and 9 deletions

View file

@ -1570,6 +1570,8 @@ The nostr server will send back a message response, and inside the body there wi
### TransactionSwapQuote
- __chain_fee_sats__: _number_
- __invoice_amount_sats__: _number_
- __routing_fee_reserve_sats__: _number_
- __service_fee_sats__: _number_
- __swap_fee_sats__: _number_
- __swap_operation_id__: _string_
- __transaction_amount_sats__: _number_

View file

@ -641,11 +641,13 @@ type SingleMetricReq struct {
Request_id int64 `json:"request_id"`
}
type TransactionSwapQuote struct {
Chain_fee_sats int64 `json:"chain_fee_sats"`
Invoice_amount_sats int64 `json:"invoice_amount_sats"`
Swap_fee_sats int64 `json:"swap_fee_sats"`
Swap_operation_id string `json:"swap_operation_id"`
Transaction_amount_sats int64 `json:"transaction_amount_sats"`
Chain_fee_sats int64 `json:"chain_fee_sats"`
Invoice_amount_sats int64 `json:"invoice_amount_sats"`
Routing_fee_reserve_sats int64 `json:"routing_fee_reserve_sats"`
Service_fee_sats int64 `json:"service_fee_sats"`
Swap_fee_sats int64 `json:"swap_fee_sats"`
Swap_operation_id string `json:"swap_operation_id"`
Transaction_amount_sats int64 `json:"transaction_amount_sats"`
}
type TransactionSwapRequest struct {
Transaction_amount_sats int64 `json:"transaction_amount_sats"`

View file

@ -3757,6 +3757,8 @@ export const SingleMetricReqValidate = (o?: SingleMetricReq, opts: SingleMetricR
export type TransactionSwapQuote = {
chain_fee_sats: number
invoice_amount_sats: number
routing_fee_reserve_sats: number
service_fee_sats: number
swap_fee_sats: number
swap_operation_id: string
transaction_amount_sats: number
@ -3766,6 +3768,8 @@ export type TransactionSwapQuoteOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
chain_fee_sats_CustomCheck?: (v: number) => boolean
invoice_amount_sats_CustomCheck?: (v: number) => boolean
routing_fee_reserve_sats_CustomCheck?: (v: number) => boolean
service_fee_sats_CustomCheck?: (v: number) => boolean
swap_fee_sats_CustomCheck?: (v: number) => boolean
swap_operation_id_CustomCheck?: (v: string) => boolean
transaction_amount_sats_CustomCheck?: (v: number) => boolean
@ -3780,6 +3784,12 @@ export const TransactionSwapQuoteValidate = (o?: TransactionSwapQuote, opts: Tra
if (typeof o.invoice_amount_sats !== 'number') return new Error(`${path}.invoice_amount_sats: is not a number`)
if (opts.invoice_amount_sats_CustomCheck && !opts.invoice_amount_sats_CustomCheck(o.invoice_amount_sats)) return new Error(`${path}.invoice_amount_sats: custom check failed`)
if (typeof o.routing_fee_reserve_sats !== 'number') return new Error(`${path}.routing_fee_reserve_sats: is not a number`)
if (opts.routing_fee_reserve_sats_CustomCheck && !opts.routing_fee_reserve_sats_CustomCheck(o.routing_fee_reserve_sats)) return new Error(`${path}.routing_fee_reserve_sats: custom check failed`)
if (typeof o.service_fee_sats !== 'number') return new Error(`${path}.service_fee_sats: is not a number`)
if (opts.service_fee_sats_CustomCheck && !opts.service_fee_sats_CustomCheck(o.service_fee_sats)) return new Error(`${path}.service_fee_sats: custom check failed`)
if (typeof o.swap_fee_sats !== 'number') return new Error(`${path}.swap_fee_sats: is not a number`)
if (opts.swap_fee_sats_CustomCheck && !opts.swap_fee_sats_CustomCheck(o.swap_fee_sats)) return new Error(`${path}.swap_fee_sats: custom check failed`)

View file

@ -832,8 +832,11 @@ message TransactionSwapRequest {
message TransactionSwapQuote {
string swap_operation_id = 1;
int64 swap_fee_sats = 2;
int64 invoice_amount_sats = 3;
int64 transaction_amount_sats = 4;
int64 invoice_amount_sats = 2;
int64 transaction_amount_sats = 3;
int64 swap_fee_sats = 4;
int64 chain_fee_sats = 5;
int64 routing_fee_reserve_sats = 6;
int64 service_fee_sats = 7;
}

View file

@ -373,7 +373,10 @@ export default class {
}
const decoded = await this.lnd.DecodeInvoice(res.createdResponse.invoice)
const swapFee = decoded.numSatoshis - chainTotal
const app = await this.storage.applicationStorage.GetApplication(ctx.app_id)
const isAppUserPayment = ctx.user_id !== app.owner.user_id
const serviceFee = this.getServiceFee(Types.UserOperationType.OUTGOING_INVOICE, decoded.numSatoshis, isAppUserPayment)
const routingFeeLimit = this.lnd.GetFeeLimitAmount(decoded.numSatoshis)
const newSwap = await this.storage.paymentStorage.AddTransactionSwap({
app_user_id: ctx.app_user_id,
swap_quote_id: res.createdResponse.id,
@ -396,6 +399,8 @@ export default class {
invoice_amount_sats: decoded.numSatoshis,
transaction_amount_sats: req.transaction_amount_sats,
chain_fee_sats: minerFee,
service_fee_sats: serviceFee,
routing_fee_reserve_sats: routingFeeLimit
}
}