From fb1336c1168b42667afd975dd165b76954767e46 Mon Sep 17 00:00:00 2001 From: Forte11Cuba Date: Fri, 16 Jan 2026 12:54:44 -0600 Subject: [PATCH] Fix onchain fee calculation to support fractional cents - Changed onChainUsdTxFee to use FractionalCentAmount instead of CentAmount - Removed Math.round() that was losing decimal precision from Ibex API - Updated both main and quickstart GraphQL schemas - Aligns with existing pattern used in LnNoAmountUsdInvoiceFeeProbe --- quickstart/graphql/public/schema.graphql | 4 ++-- .../public/root/query/on-chain-usd-tx-fee-query.ts | 13 ++++--------- src/graphql/public/schema.graphql | 4 ++-- .../public/types/object/onchain-usd-tx-fee.ts | 4 ++-- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/quickstart/graphql/public/schema.graphql b/quickstart/graphql/public/schema.graphql index 89629a281..9356377a9 100644 --- a/quickstart/graphql/public/schema.graphql +++ b/quickstart/graphql/public/schema.graphql @@ -856,7 +856,7 @@ input OnChainUsdPaymentSendInput { } type OnChainUsdTxFee { - amount: CentAmount! + amount: FractionalCentAmount! } type OneDayAccountLimit implements AccountLimit { @@ -1009,7 +1009,7 @@ type Query { me: User mobileVersions: [MobileVersions] onChainTxFee(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainTxFee! - onChainUsdTxFee(address: OnChainAddress!, amount: CentAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainUsdTxFee! + onChainUsdTxFee(address: OnChainAddress!, amount: FractionalCentAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainUsdTxFee! onChainUsdTxFeeAsBtcDenominated(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainUsdTxFee! quizQuestions: [QuizQuestion] @deprecated(reason: "TODO: remove. we don't need a non authenticated version of this query. the users can only do the query while authenticated") diff --git a/src/graphql/public/root/query/on-chain-usd-tx-fee-query.ts b/src/graphql/public/root/query/on-chain-usd-tx-fee-query.ts index 1ba124ec6..90b96e51d 100644 --- a/src/graphql/public/root/query/on-chain-usd-tx-fee-query.ts +++ b/src/graphql/public/root/query/on-chain-usd-tx-fee-query.ts @@ -6,7 +6,7 @@ import { paymentAmountFromNumber, USDAmount, ValidationError, WalletCurrency } f import { GT } from "@graphql/index" import { mapError } from "@graphql/error-map" -import CentAmount from "@graphql/public/types/scalar/cent-amount" +import FractionalCentAmount from "@graphql/public/types/scalar/cent-amount-fraction" import OnChainAddress from "@graphql/shared/types/scalar/on-chain-address" import PayoutSpeed from "@graphql/public/types/scalar/payout-speed" import WalletId from "@graphql/shared/types/scalar/wallet-id" @@ -25,7 +25,7 @@ const OnChainUsdTxFeeQuery = GT.Field({ args: { walletId: { type: GT.NonNull(WalletId) }, address: { type: GT.NonNull(OnChainAddress) }, - amount: { type: GT.NonNull(CentAmount) }, + amount: { type: GT.NonNull(FractionalCentAmount) }, speed: { type: PayoutSpeed, defaultValue: DomainPayoutSpeed.Fast, @@ -46,20 +46,15 @@ const OnChainUsdTxFeeQuery = GT.Field({ // speed, // }) - const send = USDAmount.cents(amount) + const send = USDAmount.cents(amount.toString()) if (send instanceof Error) return send const resp = await Ibex.estimateOnchainFee(send, address) if (resp instanceof IbexError) return resp if (resp.fee === undefined) return new UnexpectedIbexResponse("Missing fee field") - const fee: PaymentAmount = { - amount: BigInt(Math.round(resp.fee * 100)), - currency: WalletCurrency.Usd, - } - return { - amount: normalizePaymentAmount(fee).amount, + amount: resp.fee, } }, }) diff --git a/src/graphql/public/schema.graphql b/src/graphql/public/schema.graphql index 75a710c07..333a5d2e0 100644 --- a/src/graphql/public/schema.graphql +++ b/src/graphql/public/schema.graphql @@ -979,7 +979,7 @@ input OnChainUsdPaymentSendInput { } type OnChainUsdTxFee { - amount: CentAmount! + amount: FractionalCentAmount! } type OneDayAccountLimit implements AccountLimit { @@ -1134,7 +1134,7 @@ type Query { mobileVersions: [MobileVersions] npubByUsername(username: Username!): npubByUsername onChainTxFee(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainTxFee! - onChainUsdTxFee(address: OnChainAddress!, amount: CentAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainUsdTxFee! + onChainUsdTxFee(address: OnChainAddress!, amount: FractionalCentAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainUsdTxFee! onChainUsdTxFeeAsBtcDenominated(address: OnChainAddress!, amount: SatAmount!, speed: PayoutSpeed = FAST, walletId: WalletId!): OnChainUsdTxFee! quizQuestions: [QuizQuestion] @deprecated(reason: "TODO: remove. we don't need a non authenticated version of this query. the users can only do the query while authenticated") diff --git a/src/graphql/public/types/object/onchain-usd-tx-fee.ts b/src/graphql/public/types/object/onchain-usd-tx-fee.ts index 11d894a19..1c611f74b 100644 --- a/src/graphql/public/types/object/onchain-usd-tx-fee.ts +++ b/src/graphql/public/types/object/onchain-usd-tx-fee.ts @@ -1,11 +1,11 @@ import { GT } from "@graphql/index" -import CentAmount from "../scalar/cent-amount" +import FractionalCentAmount from "../scalar/cent-amount-fraction" const OnChainUsdTxFee = GT.Object({ name: "OnChainUsdTxFee", fields: () => ({ - amount: { type: GT.NonNull(CentAmount) }, + amount: { type: GT.NonNull(FractionalCentAmount) }, }), })