@flashnet/sdk 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1786,6 +1786,489 @@ class FlashnetClient {
1786
1786
  throw new Error(errorMessage);
1787
1787
  }
1788
1788
  }
1789
+ // ===== Lightning Payment with Token =====
1790
+ /**
1791
+ * Get a quote for paying a Lightning invoice with a token.
1792
+ * This calculates the optimal pool and token amount needed.
1793
+ *
1794
+ * @param invoice - BOLT11-encoded Lightning invoice
1795
+ * @param tokenAddress - Token identifier to use for payment
1796
+ * @param options - Optional configuration (slippage, integrator fees, etc.)
1797
+ * @returns Quote with pricing details
1798
+ * @throws Error if invoice amount or token amount is below Flashnet minimums
1799
+ */
1800
+ async getPayLightningWithTokenQuote(invoice, tokenAddress, options) {
1801
+ await this.ensureInitialized();
1802
+ // Decode the invoice to get the amount
1803
+ const invoiceAmountSats = await this.decodeInvoiceAmount(invoice);
1804
+ if (!invoiceAmountSats || invoiceAmountSats <= 0) {
1805
+ throw new Error("Unable to decode invoice amount. Zero-amount invoices are not supported for token payments.");
1806
+ }
1807
+ // Get Lightning fee estimate
1808
+ const lightningFeeEstimate = await this.getLightningFeeEstimate(invoice);
1809
+ // Total BTC needed = invoice amount + lightning fee
1810
+ const baseBtcNeeded = BigInt(invoiceAmountSats) + BigInt(lightningFeeEstimate);
1811
+ // Round up to next multiple of 64 (2^6) to account for BTC variable fee bit masking.
1812
+ // The AMM zeroes the lowest 6 bits of BTC output, so we need to request enough
1813
+ // that after masking we still have the required amount.
1814
+ // Example: 5014 -> masked to 4992, but if we request 5056, masked stays 5056
1815
+ const BTC_VARIABLE_FEE_BITS = 6n;
1816
+ const BTC_VARIABLE_FEE_MASK = 1n << BTC_VARIABLE_FEE_BITS; // 64
1817
+ const totalBtcNeeded = ((baseBtcNeeded + BTC_VARIABLE_FEE_MASK - 1n) / BTC_VARIABLE_FEE_MASK) *
1818
+ BTC_VARIABLE_FEE_MASK;
1819
+ // Check Flashnet minimum amounts early to provide clear error messages
1820
+ const minAmounts = await this.getEnabledMinAmountsMap();
1821
+ // Check BTC minimum (output from swap)
1822
+ const btcMinAmount = minAmounts.get(BTC_ASSET_PUBKEY.toLowerCase());
1823
+ if (btcMinAmount && totalBtcNeeded < btcMinAmount) {
1824
+ throw new Error(`Invoice amount too small. Flashnet minimum BTC output is ${btcMinAmount} sats, ` +
1825
+ `but invoice + lightning fee totals only ${totalBtcNeeded} sats. ` +
1826
+ `Please use an invoice of at least ${btcMinAmount} sats.`);
1827
+ }
1828
+ // Find the best pool to swap token -> BTC
1829
+ const poolQuote = await this.findBestPoolForTokenToBtc(tokenAddress, totalBtcNeeded.toString(), options?.integratorFeeRateBps);
1830
+ // Check token minimum (input to swap)
1831
+ const tokenHex = this.toHexTokenIdentifier(tokenAddress).toLowerCase();
1832
+ const tokenMinAmount = minAmounts.get(tokenHex);
1833
+ if (tokenMinAmount &&
1834
+ BigInt(poolQuote.tokenAmountRequired) < tokenMinAmount) {
1835
+ throw new Error(`Token amount too small. Flashnet minimum input is ${tokenMinAmount} units, ` +
1836
+ `but calculated amount is only ${poolQuote.tokenAmountRequired} units. ` +
1837
+ `Please use a larger invoice amount.`);
1838
+ }
1839
+ // Calculate the BTC variable fee adjustment (how much extra we're requesting)
1840
+ const btcVariableFeeAdjustment = Number(totalBtcNeeded - baseBtcNeeded);
1841
+ return {
1842
+ poolId: poolQuote.poolId,
1843
+ tokenAddress: this.toHexTokenIdentifier(tokenAddress),
1844
+ tokenAmountRequired: poolQuote.tokenAmountRequired,
1845
+ btcAmountRequired: totalBtcNeeded.toString(),
1846
+ invoiceAmountSats: invoiceAmountSats,
1847
+ estimatedAmmFee: poolQuote.estimatedAmmFee,
1848
+ estimatedLightningFee: lightningFeeEstimate,
1849
+ btcVariableFeeAdjustment,
1850
+ executionPrice: poolQuote.executionPrice,
1851
+ priceImpactPct: poolQuote.priceImpactPct,
1852
+ tokenIsAssetA: poolQuote.tokenIsAssetA,
1853
+ poolReserves: poolQuote.poolReserves,
1854
+ warningMessage: poolQuote.warningMessage,
1855
+ };
1856
+ }
1857
+ /**
1858
+ * Pay a Lightning invoice using a token.
1859
+ * This swaps the token to BTC on Flashnet and uses the BTC to pay the invoice.
1860
+ *
1861
+ * @param options - Payment options including invoice and token address
1862
+ * @returns Payment result with transaction details
1863
+ */
1864
+ async payLightningWithToken(options) {
1865
+ await this.ensureInitialized();
1866
+ const { invoice, tokenAddress, maxSlippageBps = 100, // 1% default
1867
+ maxLightningFeeSats, preferSpark = true, integratorFeeRateBps, integratorPublicKey, transferTimeoutMs = 10000, } = options;
1868
+ try {
1869
+ // Step 1: Get a quote for the payment
1870
+ const quote = await this.getPayLightningWithTokenQuote(invoice, tokenAddress, {
1871
+ maxSlippageBps,
1872
+ integratorFeeRateBps,
1873
+ });
1874
+ // Step 2: Check balance
1875
+ await this.checkBalance({
1876
+ balancesToCheck: [
1877
+ {
1878
+ assetAddress: tokenAddress,
1879
+ amount: quote.tokenAmountRequired,
1880
+ },
1881
+ ],
1882
+ errorPrefix: "Insufficient token balance for Lightning payment: ",
1883
+ });
1884
+ // Step 3: Get pool details
1885
+ const pool = await this.getPool(quote.poolId);
1886
+ // Step 4: Determine swap direction and execute
1887
+ const assetInAddress = quote.tokenIsAssetA
1888
+ ? pool.assetAAddress
1889
+ : pool.assetBAddress;
1890
+ const assetOutAddress = quote.tokenIsAssetA
1891
+ ? pool.assetBAddress
1892
+ : pool.assetAAddress;
1893
+ // Calculate min amount out with slippage protection
1894
+ const minBtcOut = this.calculateMinAmountOut(quote.btcAmountRequired, maxSlippageBps);
1895
+ // Execute the swap
1896
+ const swapResponse = await this.executeSwap({
1897
+ poolId: quote.poolId,
1898
+ assetInAddress,
1899
+ assetOutAddress,
1900
+ amountIn: quote.tokenAmountRequired,
1901
+ maxSlippageBps,
1902
+ minAmountOut: minBtcOut,
1903
+ integratorFeeRateBps,
1904
+ integratorPublicKey,
1905
+ });
1906
+ if (!swapResponse.accepted || !swapResponse.outboundTransferId) {
1907
+ return {
1908
+ success: false,
1909
+ poolId: quote.poolId,
1910
+ tokenAmountSpent: quote.tokenAmountRequired,
1911
+ btcAmountReceived: "0",
1912
+ swapTransferId: swapResponse.outboundTransferId || "",
1913
+ ammFeePaid: quote.estimatedAmmFee,
1914
+ error: swapResponse.error || "Swap was not accepted",
1915
+ };
1916
+ }
1917
+ // Step 5: Wait for the transfer to complete
1918
+ const transferComplete = await this.waitForTransferCompletion(swapResponse.outboundTransferId, transferTimeoutMs);
1919
+ if (!transferComplete) {
1920
+ return {
1921
+ success: false,
1922
+ poolId: quote.poolId,
1923
+ tokenAmountSpent: quote.tokenAmountRequired,
1924
+ btcAmountReceived: swapResponse.amountOut || "0",
1925
+ swapTransferId: swapResponse.outboundTransferId,
1926
+ ammFeePaid: quote.estimatedAmmFee,
1927
+ error: "Transfer did not complete within timeout",
1928
+ };
1929
+ }
1930
+ // Step 6: Calculate Lightning fee limit
1931
+ const invoiceAmountSats = await this.decodeInvoiceAmount(invoice);
1932
+ const effectiveMaxLightningFee = maxLightningFeeSats ??
1933
+ Math.max(5, Math.ceil(invoiceAmountSats * 0.0017)); // 17 bps or 5 sats minimum
1934
+ // Step 7: Pay the Lightning invoice
1935
+ const lightningPayment = await this._wallet.payLightningInvoice({
1936
+ invoice,
1937
+ maxFeeSats: effectiveMaxLightningFee,
1938
+ preferSpark,
1939
+ });
1940
+ return {
1941
+ success: true,
1942
+ poolId: quote.poolId,
1943
+ tokenAmountSpent: quote.tokenAmountRequired,
1944
+ btcAmountReceived: swapResponse.amountOut || quote.btcAmountRequired,
1945
+ swapTransferId: swapResponse.outboundTransferId,
1946
+ lightningPaymentId: lightningPayment.id,
1947
+ ammFeePaid: quote.estimatedAmmFee,
1948
+ lightningFeePaid: effectiveMaxLightningFee,
1949
+ };
1950
+ }
1951
+ catch (error) {
1952
+ const errorMessage = error instanceof Error ? error.message : String(error);
1953
+ return {
1954
+ success: false,
1955
+ poolId: "",
1956
+ tokenAmountSpent: "0",
1957
+ btcAmountReceived: "0",
1958
+ swapTransferId: "",
1959
+ ammFeePaid: "0",
1960
+ error: errorMessage,
1961
+ };
1962
+ }
1963
+ }
1964
+ /**
1965
+ * Find the best pool for swapping a token to BTC
1966
+ * @private
1967
+ */
1968
+ async findBestPoolForTokenToBtc(tokenAddress, btcAmountNeeded, integratorFeeRateBps) {
1969
+ const tokenHex = this.toHexTokenIdentifier(tokenAddress);
1970
+ const btcHex = BTC_ASSET_PUBKEY;
1971
+ // Find all pools that have this token paired with BTC
1972
+ const poolsWithTokenAsA = await this.listPools({
1973
+ assetAAddress: tokenHex,
1974
+ assetBAddress: btcHex,
1975
+ });
1976
+ const poolsWithTokenAsB = await this.listPools({
1977
+ assetAAddress: btcHex,
1978
+ assetBAddress: tokenHex,
1979
+ });
1980
+ const allPools = [
1981
+ ...poolsWithTokenAsA.pools.map((p) => ({ ...p, tokenIsAssetA: true })),
1982
+ ...poolsWithTokenAsB.pools.map((p) => ({ ...p, tokenIsAssetA: false })),
1983
+ ];
1984
+ if (allPools.length === 0) {
1985
+ throw new Error(`No liquidity pool found for token ${tokenAddress} paired with BTC`);
1986
+ }
1987
+ // Find the best pool (lowest token cost for the required BTC)
1988
+ let bestPool = null;
1989
+ let bestTokenAmount = BigInt(Number.MAX_SAFE_INTEGER);
1990
+ let bestSimulation = null;
1991
+ for (const pool of allPools) {
1992
+ try {
1993
+ // Get pool details for reserves
1994
+ const poolDetails = await this.getPool(pool.lpPublicKey);
1995
+ // Calculate the token amount needed using AMM math
1996
+ const calculation = this.calculateTokenAmountForBtcOutput(btcAmountNeeded, poolDetails.assetAReserve, poolDetails.assetBReserve, poolDetails.lpFeeBps, poolDetails.hostFeeBps, pool.tokenIsAssetA, integratorFeeRateBps);
1997
+ const tokenAmount = BigInt(calculation.amountIn);
1998
+ // Check if this is better than our current best
1999
+ if (tokenAmount < bestTokenAmount) {
2000
+ // Verify with simulation
2001
+ const simulation = await this.simulateSwap({
2002
+ poolId: pool.lpPublicKey,
2003
+ assetInAddress: pool.tokenIsAssetA
2004
+ ? poolDetails.assetAAddress
2005
+ : poolDetails.assetBAddress,
2006
+ assetOutAddress: pool.tokenIsAssetA
2007
+ ? poolDetails.assetBAddress
2008
+ : poolDetails.assetAAddress,
2009
+ amountIn: calculation.amountIn,
2010
+ integratorBps: integratorFeeRateBps,
2011
+ });
2012
+ // Verify the output is sufficient
2013
+ if (BigInt(simulation.amountOut) >= BigInt(btcAmountNeeded)) {
2014
+ bestPool = pool;
2015
+ bestTokenAmount = tokenAmount;
2016
+ bestSimulation = {
2017
+ amountIn: calculation.amountIn,
2018
+ fee: calculation.totalFee,
2019
+ executionPrice: simulation.executionPrice || "0",
2020
+ priceImpactPct: simulation.priceImpactPct || "0",
2021
+ warningMessage: simulation.warningMessage,
2022
+ };
2023
+ }
2024
+ }
2025
+ }
2026
+ catch { }
2027
+ }
2028
+ if (!bestPool || !bestSimulation) {
2029
+ throw new Error(`No pool has sufficient liquidity for ${btcAmountNeeded} sats`);
2030
+ }
2031
+ const poolDetails = await this.getPool(bestPool.lpPublicKey);
2032
+ return {
2033
+ poolId: bestPool.lpPublicKey,
2034
+ tokenAmountRequired: bestSimulation.amountIn,
2035
+ estimatedAmmFee: bestSimulation.fee,
2036
+ executionPrice: bestSimulation.executionPrice,
2037
+ priceImpactPct: bestSimulation.priceImpactPct,
2038
+ tokenIsAssetA: bestPool.tokenIsAssetA,
2039
+ poolReserves: {
2040
+ assetAReserve: poolDetails.assetAReserve,
2041
+ assetBReserve: poolDetails.assetBReserve,
2042
+ },
2043
+ warningMessage: bestSimulation.warningMessage,
2044
+ };
2045
+ }
2046
+ /**
2047
+ * Calculate the token amount needed to get a specific BTC output.
2048
+ * Implements the AMM fee-inclusive model.
2049
+ * @private
2050
+ */
2051
+ calculateTokenAmountForBtcOutput(btcAmountOut, reserveA, reserveB, lpFeeBps, hostFeeBps, tokenIsAssetA, integratorFeeBps) {
2052
+ const amountOut = BigInt(btcAmountOut);
2053
+ const resA = BigInt(reserveA);
2054
+ const resB = BigInt(reserveB);
2055
+ const totalFeeBps = lpFeeBps + hostFeeBps + (integratorFeeBps || 0);
2056
+ const feeRate = Number(totalFeeBps) / 10000; // Convert bps to decimal
2057
+ // Token is the input asset
2058
+ // BTC is the output asset
2059
+ if (tokenIsAssetA) {
2060
+ // Token is asset A, BTC is asset B
2061
+ // A → B swap: we want BTC out (asset B)
2062
+ // reserve_in = reserveA (token), reserve_out = reserveB (BTC)
2063
+ // Constant product formula for amount_in given amount_out:
2064
+ // amount_in_effective = (reserve_in * amount_out) / (reserve_out - amount_out)
2065
+ const reserveIn = resA;
2066
+ const reserveOut = resB;
2067
+ if (amountOut >= reserveOut) {
2068
+ throw new Error("Insufficient liquidity: requested BTC amount exceeds reserve");
2069
+ }
2070
+ // Calculate effective amount in (before fees)
2071
+ const amountInEffective = (reserveIn * amountOut) / (reserveOut - amountOut) + 1n; // +1 for rounding up
2072
+ // A→B swap: LP fee deducted from input A, integrator fee from output B
2073
+ // amount_in = amount_in_effective * (1 + lp_fee_rate)
2074
+ // Then integrator fee is deducted from output, so we need slightly more input
2075
+ const lpFeeRate = Number(lpFeeBps) / 10000;
2076
+ const integratorFeeRate = Number(integratorFeeBps || 0) / 10000;
2077
+ // Account for LP fee on input
2078
+ const amountInWithLpFee = BigInt(Math.ceil(Number(amountInEffective) * (1 + lpFeeRate)));
2079
+ // Account for integrator fee on output (need more input to get same output after fee)
2080
+ const amountIn = integratorFeeRate > 0
2081
+ ? BigInt(Math.ceil(Number(amountInWithLpFee) * (1 + integratorFeeRate)))
2082
+ : amountInWithLpFee;
2083
+ const totalFee = amountIn - amountInEffective;
2084
+ return {
2085
+ amountIn: amountIn.toString(),
2086
+ totalFee: totalFee.toString(),
2087
+ };
2088
+ }
2089
+ else {
2090
+ // Token is asset B, BTC is asset A
2091
+ // B → A swap: we want BTC out (asset A)
2092
+ // reserve_in = reserveB (token), reserve_out = reserveA (BTC)
2093
+ const reserveIn = resB;
2094
+ const reserveOut = resA;
2095
+ if (amountOut >= reserveOut) {
2096
+ throw new Error("Insufficient liquidity: requested BTC amount exceeds reserve");
2097
+ }
2098
+ // Calculate effective amount in (before fees)
2099
+ const amountInEffective = (reserveIn * amountOut) / (reserveOut - amountOut) + 1n; // +1 for rounding up
2100
+ // B→A swap: ALL fees (LP + integrator) deducted from input B
2101
+ // amount_in = amount_in_effective * (1 + total_fee_rate)
2102
+ const amountIn = BigInt(Math.ceil(Number(amountInEffective) * (1 + feeRate)));
2103
+ // Fee calculation: fee = amount_in * fee_rate / (1 + fee_rate)
2104
+ const totalFee = BigInt(Math.ceil((Number(amountIn) * feeRate) / (1 + feeRate)));
2105
+ return {
2106
+ amountIn: amountIn.toString(),
2107
+ totalFee: totalFee.toString(),
2108
+ };
2109
+ }
2110
+ }
2111
+ /**
2112
+ * Calculate minimum amount out with slippage protection
2113
+ * @private
2114
+ */
2115
+ calculateMinAmountOut(expectedAmount, slippageBps) {
2116
+ const amount = BigInt(expectedAmount);
2117
+ const slippageFactor = BigInt(10000 - slippageBps);
2118
+ const minAmount = (amount * slippageFactor) / 10000n;
2119
+ return minAmount.toString();
2120
+ }
2121
+ /**
2122
+ * Wait for a transfer to be claimed using wallet events.
2123
+ * This is more efficient than polling as it uses the wallet's event stream.
2124
+ * @private
2125
+ */
2126
+ async waitForTransferCompletion(transferId, timeoutMs) {
2127
+ return new Promise((resolve) => {
2128
+ const timeout = setTimeout(() => {
2129
+ // Remove listener on timeout
2130
+ try {
2131
+ this._wallet.removeListener?.("transfer:claimed", handler);
2132
+ }
2133
+ catch {
2134
+ // Ignore if removeListener doesn't exist
2135
+ }
2136
+ resolve(false);
2137
+ }, timeoutMs);
2138
+ const handler = (claimedTransferId, _balance) => {
2139
+ if (claimedTransferId === transferId) {
2140
+ clearTimeout(timeout);
2141
+ try {
2142
+ this._wallet.removeListener?.("transfer:claimed", handler);
2143
+ }
2144
+ catch {
2145
+ // Ignore if removeListener doesn't exist
2146
+ }
2147
+ resolve(true);
2148
+ }
2149
+ };
2150
+ // Subscribe to transfer claimed events
2151
+ // The wallet's RPC stream will automatically claim incoming transfers
2152
+ try {
2153
+ this._wallet.on?.("transfer:claimed", handler);
2154
+ }
2155
+ catch {
2156
+ // If event subscription fails, fall back to polling
2157
+ clearTimeout(timeout);
2158
+ this.pollForTransferCompletion(transferId, timeoutMs).then(resolve);
2159
+ }
2160
+ });
2161
+ }
2162
+ /**
2163
+ * Fallback polling method for transfer completion
2164
+ * @private
2165
+ */
2166
+ async pollForTransferCompletion(transferId, timeoutMs) {
2167
+ const startTime = Date.now();
2168
+ const pollIntervalMs = 500;
2169
+ while (Date.now() - startTime < timeoutMs) {
2170
+ try {
2171
+ const transfer = await this._wallet.getTransfer(transferId);
2172
+ if (transfer) {
2173
+ if (transfer.status === "TRANSFER_STATUS_COMPLETED") {
2174
+ return true;
2175
+ }
2176
+ }
2177
+ }
2178
+ catch {
2179
+ // Ignore errors and continue polling
2180
+ }
2181
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
2182
+ }
2183
+ return false;
2184
+ }
2185
+ /**
2186
+ * Get Lightning fee estimate for an invoice
2187
+ * @private
2188
+ */
2189
+ async getLightningFeeEstimate(invoice) {
2190
+ try {
2191
+ const feeEstimate = await this._wallet.getLightningSendFeeEstimate({
2192
+ encodedInvoice: invoice,
2193
+ });
2194
+ // The fee estimate might be returned as a number or an object
2195
+ if (typeof feeEstimate === "number") {
2196
+ return feeEstimate;
2197
+ }
2198
+ if (feeEstimate?.fee || feeEstimate?.feeEstimate) {
2199
+ return Number(feeEstimate.fee || feeEstimate.feeEstimate);
2200
+ }
2201
+ // Fallback to invoice amount-based estimate
2202
+ const invoiceAmount = await this.decodeInvoiceAmount(invoice);
2203
+ return Math.max(5, Math.ceil(invoiceAmount * 0.0017)); // 17 bps or 5 sats minimum
2204
+ }
2205
+ catch {
2206
+ // Fallback to invoice amount-based estimate
2207
+ const invoiceAmount = await this.decodeInvoiceAmount(invoice);
2208
+ return Math.max(5, Math.ceil(invoiceAmount * 0.0017));
2209
+ }
2210
+ }
2211
+ /**
2212
+ * Decode the amount from a Lightning invoice (in sats)
2213
+ * @private
2214
+ */
2215
+ async decodeInvoiceAmount(invoice) {
2216
+ // Extract amount from BOLT11 invoice
2217
+ // Format: ln[network][amount][multiplier]...
2218
+ // Amount multipliers: m = milli (0.001), u = micro (0.000001), n = nano, p = pico
2219
+ const lowerInvoice = invoice.toLowerCase();
2220
+ // Find where the amount starts (after network prefix)
2221
+ let amountStart = 0;
2222
+ if (lowerInvoice.startsWith("lnbc")) {
2223
+ amountStart = 4;
2224
+ }
2225
+ else if (lowerInvoice.startsWith("lntb")) {
2226
+ amountStart = 4;
2227
+ }
2228
+ else if (lowerInvoice.startsWith("lnbcrt")) {
2229
+ amountStart = 6;
2230
+ }
2231
+ else if (lowerInvoice.startsWith("lntbs")) {
2232
+ amountStart = 5;
2233
+ }
2234
+ else {
2235
+ // Unknown format, try to find amount
2236
+ const match = lowerInvoice.match(/^ln[a-z]+/);
2237
+ if (match) {
2238
+ amountStart = match[0].length;
2239
+ }
2240
+ }
2241
+ // Extract amount and multiplier
2242
+ const afterPrefix = lowerInvoice.substring(amountStart);
2243
+ const amountMatch = afterPrefix.match(/^(\d+)([munp]?)/);
2244
+ if (!amountMatch || !amountMatch[1]) {
2245
+ return 0; // Zero-amount invoice
2246
+ }
2247
+ const amount = parseInt(amountMatch[1], 10);
2248
+ const multiplier = amountMatch[2] ?? "";
2249
+ // Convert to satoshis (1 BTC = 100,000,000 sats)
2250
+ // Invoice amounts are in BTC by default
2251
+ let btcAmount;
2252
+ switch (multiplier) {
2253
+ case "m": // milli-BTC (0.001 BTC)
2254
+ btcAmount = amount * 0.001;
2255
+ break;
2256
+ case "u": // micro-BTC (0.000001 BTC)
2257
+ btcAmount = amount * 0.000001;
2258
+ break;
2259
+ case "n": // nano-BTC (0.000000001 BTC)
2260
+ btcAmount = amount * 0.000000001;
2261
+ break;
2262
+ case "p": // pico-BTC (0.000000000001 BTC)
2263
+ btcAmount = amount * 0.000000000001;
2264
+ break;
2265
+ default: // BTC
2266
+ btcAmount = amount;
2267
+ break;
2268
+ }
2269
+ // Convert BTC to sats
2270
+ return Math.round(btcAmount * 100000000);
2271
+ }
1789
2272
  /**
1790
2273
  * Clean up wallet connections
1791
2274
  */