diff --git a/proto/autogenerated/client.md b/proto/autogenerated/client.md index 17dcc2de..a5dfc69f 100644 --- a/proto/autogenerated/client.md +++ b/proto/autogenerated/client.md @@ -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_ diff --git a/proto/autogenerated/go/types.go b/proto/autogenerated/go/types.go index 2c85c8c0..2623e357 100644 --- a/proto/autogenerated/go/types.go +++ b/proto/autogenerated/go/types.go @@ -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"` diff --git a/proto/autogenerated/ts/types.ts b/proto/autogenerated/ts/types.ts index 71ad89fc..1afad70e 100644 --- a/proto/autogenerated/ts/types.ts +++ b/proto/autogenerated/ts/types.ts @@ -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`) diff --git a/proto/service/structs.proto b/proto/service/structs.proto index 65771361..c1b5011e 100644 --- a/proto/service/structs.proto +++ b/proto/service/structs.proto @@ -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; } \ No newline at end of file diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index 918dc72e..78d780ba 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -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 } }