@lendasat/lendaswap-sdk 0.1.8 → 0.1.67
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.
- package/README.md +200 -126
- package/dist/api.d.ts +206 -192
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +292 -132
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +23 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -21
- package/dist/index.js.map +1 -1
- package/dist/price-calculations.d.ts +135 -0
- package/dist/price-calculations.d.ts.map +1 -0
- package/dist/price-calculations.js +171 -0
- package/dist/price-calculations.js.map +1 -0
- package/dist/price-feed.d.ts +3 -0
- package/dist/price-feed.d.ts.map +1 -1
- package/dist/price-feed.js.map +1 -1
- package/dist/usd-price.d.ts.map +1 -1
- package/dist/usd-price.js +1 -0
- package/dist/usd-price.js.map +1 -1
- package/package.json +14 -15
- package/wasm/lendaswap_wasm_sdk.d.ts +442 -114
- package/wasm/lendaswap_wasm_sdk_bg.js +2946 -630
- package/wasm/lendaswap_wasm_sdk_bg.wasm +0 -0
- package/wasm/lendaswap_wasm_sdk_bg.wasm.d.ts +268 -64
- package/dist/storage/dexieSwapStorage.d.ts +0 -111
- package/dist/storage/dexieSwapStorage.d.ts.map +0 -1
- package/dist/storage/dexieSwapStorage.js +0 -139
- package/dist/storage/dexieSwapStorage.js.map +0 -1
- package/dist/storage/dexieWalletStorage.d.ts +0 -99
- package/dist/storage/dexieWalletStorage.d.ts.map +0 -1
- package/dist/storage/dexieWalletStorage.js +0 -139
- package/dist/storage/dexieWalletStorage.js.map +0 -1
- package/dist/storage/index.d.ts +0 -18
- package/dist/storage/index.d.ts.map +0 -1
- package/dist/storage/index.js +0 -20
- package/dist/storage/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,23 +6,27 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* import {
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
9
|
+
* import { Client, ClientBuilder, openIdbDatabase } from '@lendasat/lendaswap-sdk';
|
|
10
|
+
*
|
|
11
|
+
* // Open the IndexedDB database
|
|
12
|
+
* const storage = await openIdbDatabase();
|
|
13
|
+
*
|
|
14
|
+
* // Create client using builder (recommended)
|
|
15
|
+
* const client = Client.builder()
|
|
16
|
+
* .url('https://apilendaswap.lendasat.com')
|
|
17
|
+
* .storage(storage)
|
|
18
|
+
* .network('bitcoin')
|
|
19
|
+
* .arkadeUrl('https://arkade.computer')
|
|
20
|
+
* .esploraUrl('https://mempool.space/api')
|
|
21
|
+
* .build();
|
|
22
|
+
*
|
|
23
|
+
* // Or use the static create method
|
|
24
|
+
* const client2 = await Client.create(
|
|
21
25
|
* 'https://apilendaswap.lendasat.com',
|
|
22
|
-
*
|
|
23
|
-
* swapStorage,
|
|
26
|
+
* storage,
|
|
24
27
|
* 'bitcoin',
|
|
25
|
-
* 'https://arkade.computer'
|
|
28
|
+
* 'https://arkade.computer',
|
|
29
|
+
* 'https://mempool.space/api'
|
|
26
30
|
* );
|
|
27
31
|
*
|
|
28
32
|
* // Initialize wallet (generates mnemonic if needed)
|
|
@@ -34,10 +38,10 @@
|
|
|
34
38
|
*
|
|
35
39
|
* @packageDocumentation
|
|
36
40
|
*/
|
|
37
|
-
export type {
|
|
38
|
-
export { type AssetPair, type BtcToEvmSwapResponse, type Chain, Client, CreateVtxoSwapResult, EstimateVtxoSwapResponse, type EvmToArkadeSwapRequest, type EvmToBtcSwapResponse, type EvmToLightningSwapRequest, type ExtendedSwapStorageData, type GelatoSubmitRequest, type GelatoSubmitResponse, type GetSwapResponse, getLogLevel, type LogLevel, type QuoteRequest, type RecoveredSwap, type RecoverSwapsResponse, type
|
|
41
|
+
export type { NetworkInput } from "./api.js";
|
|
42
|
+
export { type AssetPair, type BtcToArkadeSwapRequest, type BtcToArkadeSwapResponse, type BtcToEvmSwapResponse, type Chain, Client, ClientBuilder, CreateVtxoSwapResult, EstimateVtxoSwapResponse, type EvmToArkadeSwapRequest, type EvmToBtcSwapResponse, type EvmToLightningSwapRequest, type ExtendedSwapStorageData, type ExtendedSwapStorageDataWasm, ExtendedVtxoSwapStorageData, type GelatoSubmitRequest, type GelatoSubmitResponse, type GetSwapResponse, getLogLevel, type IdbStorageHandle, type LogLevel, type Network, openIdbDatabase, type QuoteRequest, QuoteResponse, type RecoveredSwap, type RecoverSwapsResponse, type SwapRequest, SwapStatus, swapStatusToString, type SwapType, setLogLevel, TokenId, type TokenIdString, type TokenInfo, Version, VhtlcAmounts, VtxoSwapParams, VtxoSwapResponse, } from "./api.js";
|
|
39
43
|
export { PriceFeedService, type PriceTiers, type PriceUpdateCallback, type PriceUpdateMessage, type TradingPairPrices, } from "./price-feed.js";
|
|
40
|
-
export {
|
|
41
|
-
export type {
|
|
44
|
+
export { calculateSourceAmount, calculateTargetAmount, computeExchangeRate, selectTierRate, } from "./price-calculations.js";
|
|
45
|
+
export type { SwapData, SwapParams } from "./types.js";
|
|
42
46
|
export { type GetUsdPriceOptions, getCoinGeckoId, getSupportedTokensForUsdPrice, getUsdPrice, getUsdPrices, type UsdPriceResult, } from "./usd-price.js";
|
|
43
47
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,EACL,KAAK,SAAS,EAC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|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
9
|
+
* import { Client, ClientBuilder, openIdbDatabase } from '@lendasat/lendaswap-sdk';
|
|
10
|
+
*
|
|
11
|
+
* // Open the IndexedDB database
|
|
12
|
+
* const storage = await openIdbDatabase();
|
|
13
|
+
*
|
|
14
|
+
* // Create client using builder (recommended)
|
|
15
|
+
* const client = Client.builder()
|
|
16
|
+
* .url('https://apilendaswap.lendasat.com')
|
|
17
|
+
* .storage(storage)
|
|
18
|
+
* .network('bitcoin')
|
|
19
|
+
* .arkadeUrl('https://arkade.computer')
|
|
20
|
+
* .esploraUrl('https://mempool.space/api')
|
|
21
|
+
* .build();
|
|
22
|
+
*
|
|
23
|
+
* // Or use the static create method
|
|
24
|
+
* const client2 = await Client.create(
|
|
21
25
|
* 'https://apilendaswap.lendasat.com',
|
|
22
|
-
*
|
|
23
|
-
* swapStorage,
|
|
26
|
+
* storage,
|
|
24
27
|
* 'bitcoin',
|
|
25
|
-
* 'https://arkade.computer'
|
|
28
|
+
* 'https://arkade.computer',
|
|
29
|
+
* 'https://mempool.space/api'
|
|
26
30
|
* );
|
|
27
31
|
*
|
|
28
32
|
* // Initialize wallet (generates mnemonic if needed)
|
|
@@ -34,12 +38,9 @@
|
|
|
34
38
|
*
|
|
35
39
|
* @packageDocumentation
|
|
36
40
|
*/
|
|
37
|
-
// API
|
|
38
|
-
export { Client, CreateVtxoSwapResult, EstimateVtxoSwapResponse, getLogLevel, setLogLevel, TokenId, VtxoSwapParams, VtxoSwapResponse, } from "./api.js";
|
|
41
|
+
// Re-export WASM types and API types
|
|
42
|
+
export { Client, ClientBuilder, CreateVtxoSwapResult, EstimateVtxoSwapResponse, ExtendedVtxoSwapStorageData, getLogLevel, openIdbDatabase, QuoteResponse, SwapStatus, swapStatusToString, setLogLevel, TokenId, Version, VhtlcAmounts, VtxoSwapParams, VtxoSwapResponse, } from "./api.js";
|
|
39
43
|
export { PriceFeedService, } from "./price-feed.js";
|
|
40
|
-
|
|
41
|
-
// Swap storage (typed swap data using Dexie/IndexedDB)
|
|
42
|
-
// Wallet storage (typed wallet data using Dexie/IndexedDB)
|
|
43
|
-
export { createDexieSwapStorage, createDexieWalletStorage, DexieSwapStorageProvider, DexieWalletStorageProvider, STORAGE_KEYS, } from "./storage/index.js";
|
|
44
|
+
export { calculateSourceAmount, calculateTargetAmount, computeExchangeRate, selectTierRate, } from "./price-calculations.js";
|
|
44
45
|
export { getCoinGeckoId, getSupportedTokensForUsdPrice, getUsdPrice, getUsdPrices, } from "./usd-price.js";
|
|
45
46
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,qCAAqC;AACrC,OAAO,EAML,MAAM,EACN,aAAa,EACb,oBAAoB,EACpB,wBAAwB,EAMxB,2BAA2B,EAI3B,WAAW,EAIX,eAAe,EAEf,aAAa,EAIb,UAAU,EACV,kBAAkB,EAElB,WAAW,EACX,OAAO,EAGP,OAAO,EACP,YAAY,EACZ,cAAc,EACd,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,GAKjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,GACf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAEL,cAAc,EACd,6BAA6B,EAC7B,WAAW,EACX,YAAY,GAEb,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Price calculation utilities for swap amount conversions.
|
|
3
|
+
*
|
|
4
|
+
* This module provides functions to calculate swap amounts using exchange rates
|
|
5
|
+
* from the price feed. It handles:
|
|
6
|
+
* - Tier-based rate selection based on swap volume
|
|
7
|
+
* - Exchange rate inversion for BTC ↔ EVM token swaps
|
|
8
|
+
* - Forward and reverse amount calculations with fee handling
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import {
|
|
13
|
+
* selectTierRate,
|
|
14
|
+
* computeExchangeRate,
|
|
15
|
+
* calculateTargetAmount,
|
|
16
|
+
* calculateSourceAmount,
|
|
17
|
+
* type PriceTiers,
|
|
18
|
+
* } from '@lendasat/lendaswap-sdk';
|
|
19
|
+
*
|
|
20
|
+
* // Select tier based on amount
|
|
21
|
+
* const rate = selectTierRate(priceTiers, 1000); // Gets tier_1000 rate
|
|
22
|
+
*
|
|
23
|
+
* // Compute exchange rate with proper inversion
|
|
24
|
+
* const exchangeRate = computeExchangeRate(rate, isSourceBtc, isTargetEvm);
|
|
25
|
+
*
|
|
26
|
+
* // Calculate target amount from source
|
|
27
|
+
* const targetAmount = calculateTargetAmount(100, exchangeRate, 0.0001, false, true);
|
|
28
|
+
*
|
|
29
|
+
* // Calculate source amount needed for target
|
|
30
|
+
* const sourceAmount = calculateSourceAmount(0.01, exchangeRate, 0.0001, false, true);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
import type { PriceTiers } from "./price-feed.js";
|
|
34
|
+
/**
|
|
35
|
+
* Select the appropriate tier rate based on the asset amount.
|
|
36
|
+
* Higher amounts get better rates (lower spread).
|
|
37
|
+
*
|
|
38
|
+
* @param tiers - The price tiers from the price feed
|
|
39
|
+
* @param assetAmount - The swap amount in quote asset units
|
|
40
|
+
* @returns The rate for the appropriate tier
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const tiers = { tier_1: 0.000010773, tier_100: 0.0000107787, tier_1000: 0.0000107740, tier_5000: 0.0000107524 };
|
|
45
|
+
*
|
|
46
|
+
* selectTierRate(tiers, 50); // Returns tier_1 (0.000010773)
|
|
47
|
+
* selectTierRate(tiers, 500); // Returns tier_100 (0.0000107787)
|
|
48
|
+
* selectTierRate(tiers, 2000); // Returns tier_1000 (0.0000107740)
|
|
49
|
+
* selectTierRate(tiers, 10000); // Returns tier_5000 (0.0000107524)
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function selectTierRate(tiers: PriceTiers, assetAmount: number): number;
|
|
53
|
+
/**
|
|
54
|
+
* Compute the exchange rate with proper inversion handling.
|
|
55
|
+
*
|
|
56
|
+
* The backend sends rates in the format "BTC per 1 stablecoin" for ALL pairs.
|
|
57
|
+
* When the source is BTC and target is a stablecoin/EVM token, we need to
|
|
58
|
+
* invert the rate to get "stablecoin per 1 BTC".
|
|
59
|
+
*
|
|
60
|
+
* @param rate - The raw rate from the backend (BTC per 1 stablecoin)
|
|
61
|
+
* @param isSourceBtc - Whether the source token is BTC (Lightning, Arkade, or Onchain)
|
|
62
|
+
* @param isTargetEvmToken - Whether the target token is an EVM token (stablecoins, etc.)
|
|
63
|
+
* @returns The exchange rate as "1 source = X target"
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const btcPerUsdc = 0.000010773; // ~1 BTC = 92,828 USDC
|
|
68
|
+
*
|
|
69
|
+
* // USDC -> BTC: rate stays as-is (BTC per USDC)
|
|
70
|
+
* computeExchangeRate(btcPerUsdc, false, false); // 0.000010773
|
|
71
|
+
*
|
|
72
|
+
* // BTC -> USDC: rate is inverted (USDC per BTC)
|
|
73
|
+
* computeExchangeRate(btcPerUsdc, true, true); // ~92,828
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function computeExchangeRate(rate: number, isSourceBtc: boolean, isTargetEvmToken: boolean): number;
|
|
77
|
+
/**
|
|
78
|
+
* Calculate the target amount given a source amount.
|
|
79
|
+
* Uses the exchange rate semantics: 1 source = exchangeRate target
|
|
80
|
+
*
|
|
81
|
+
* Fee handling:
|
|
82
|
+
* - If source is BTC: fee is deducted from source before conversion
|
|
83
|
+
* - If target is BTC: fee is deducted from target after conversion
|
|
84
|
+
*
|
|
85
|
+
* @param sourceAmount - Amount of source asset
|
|
86
|
+
* @param exchangeRate - Rate where 1 source = exchangeRate target
|
|
87
|
+
* @param networkFeeInBtc - Network fee in BTC
|
|
88
|
+
* @param isSourceBtc - Whether source is BTC (fee deducted from source before conversion)
|
|
89
|
+
* @param isTargetBtc - Whether target is BTC (fee deducted from target after conversion)
|
|
90
|
+
* @returns Target amount after fees
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const networkFee = 0.0001; // 10,000 sats
|
|
95
|
+
*
|
|
96
|
+
* // USDC -> BTC: 1000 USDC at rate 0.000010773
|
|
97
|
+
* // Target = 1000 * 0.000010773 - 0.0001 = 0.010673 BTC
|
|
98
|
+
* calculateTargetAmount(1000, 0.000010773, networkFee, false, true);
|
|
99
|
+
*
|
|
100
|
+
* // BTC -> USDC: 0.01 BTC at rate 92,824
|
|
101
|
+
* // Target = (0.01 - 0.0001) * 92824 = 918.96 USDC
|
|
102
|
+
* calculateTargetAmount(0.01, 92824, networkFee, true, false);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function calculateTargetAmount(sourceAmount: number, exchangeRate: number, networkFeeInBtc: number, isSourceBtc: boolean, isTargetBtc: boolean): number;
|
|
106
|
+
/**
|
|
107
|
+
* Calculate the source amount needed to receive a target amount.
|
|
108
|
+
* Uses the exchange rate semantics: 1 source = exchangeRate target
|
|
109
|
+
*
|
|
110
|
+
* Fee handling (reverse of calculateTargetAmount):
|
|
111
|
+
* - If target is BTC: fee is added to target before reverse conversion
|
|
112
|
+
* - If source is BTC: fee is added to source after reverse conversion
|
|
113
|
+
*
|
|
114
|
+
* @param targetAmount - Desired amount of target asset
|
|
115
|
+
* @param exchangeRate - Rate where 1 source = exchangeRate target
|
|
116
|
+
* @param networkFeeInBtc - Network fee in BTC
|
|
117
|
+
* @param isSourceBtc - Whether source is BTC (fee added to required source)
|
|
118
|
+
* @param isTargetBtc - Whether target is BTC (fee added to target before reverse calc)
|
|
119
|
+
* @returns Source amount needed (including fees)
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const networkFee = 0.0001; // 10,000 sats
|
|
124
|
+
*
|
|
125
|
+
* // Want 0.01 BTC, paying with USDC at rate 0.000010773
|
|
126
|
+
* // Source = (0.01 + 0.0001) / 0.000010773 = 937.26 USDC
|
|
127
|
+
* calculateSourceAmount(0.01, 0.000010773, networkFee, false, true);
|
|
128
|
+
*
|
|
129
|
+
* // Want 1000 USDC, paying with BTC at rate 92,824
|
|
130
|
+
* // Source = 1000 / 92824 + 0.0001 = 0.01088 BTC
|
|
131
|
+
* calculateSourceAmount(1000, 92824, networkFee, true, false);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare function calculateSourceAmount(targetAmount: number, exchangeRate: number, networkFeeInBtc: number, isSourceBtc: boolean, isTargetBtc: boolean): number;
|
|
135
|
+
//# sourceMappingURL=price-calculations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"price-calculations.d.ts","sourceRoot":"","sources":["../src/price-calculations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAW7E;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,OAAO,EACpB,gBAAgB,EAAE,OAAO,GACxB,MAAM,CAQR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,OAAO,EACpB,WAAW,EAAE,OAAO,GACnB,MAAM,CASR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,OAAO,EACpB,WAAW,EAAE,OAAO,GACnB,MAAM,CASR"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Price calculation utilities for swap amount conversions.
|
|
3
|
+
*
|
|
4
|
+
* This module provides functions to calculate swap amounts using exchange rates
|
|
5
|
+
* from the price feed. It handles:
|
|
6
|
+
* - Tier-based rate selection based on swap volume
|
|
7
|
+
* - Exchange rate inversion for BTC ↔ EVM token swaps
|
|
8
|
+
* - Forward and reverse amount calculations with fee handling
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import {
|
|
13
|
+
* selectTierRate,
|
|
14
|
+
* computeExchangeRate,
|
|
15
|
+
* calculateTargetAmount,
|
|
16
|
+
* calculateSourceAmount,
|
|
17
|
+
* type PriceTiers,
|
|
18
|
+
* } from '@lendasat/lendaswap-sdk';
|
|
19
|
+
*
|
|
20
|
+
* // Select tier based on amount
|
|
21
|
+
* const rate = selectTierRate(priceTiers, 1000); // Gets tier_1000 rate
|
|
22
|
+
*
|
|
23
|
+
* // Compute exchange rate with proper inversion
|
|
24
|
+
* const exchangeRate = computeExchangeRate(rate, isSourceBtc, isTargetEvm);
|
|
25
|
+
*
|
|
26
|
+
* // Calculate target amount from source
|
|
27
|
+
* const targetAmount = calculateTargetAmount(100, exchangeRate, 0.0001, false, true);
|
|
28
|
+
*
|
|
29
|
+
* // Calculate source amount needed for target
|
|
30
|
+
* const sourceAmount = calculateSourceAmount(0.01, exchangeRate, 0.0001, false, true);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Select the appropriate tier rate based on the asset amount.
|
|
35
|
+
* Higher amounts get better rates (lower spread).
|
|
36
|
+
*
|
|
37
|
+
* @param tiers - The price tiers from the price feed
|
|
38
|
+
* @param assetAmount - The swap amount in quote asset units
|
|
39
|
+
* @returns The rate for the appropriate tier
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const tiers = { tier_1: 0.000010773, tier_100: 0.0000107787, tier_1000: 0.0000107740, tier_5000: 0.0000107524 };
|
|
44
|
+
*
|
|
45
|
+
* selectTierRate(tiers, 50); // Returns tier_1 (0.000010773)
|
|
46
|
+
* selectTierRate(tiers, 500); // Returns tier_100 (0.0000107787)
|
|
47
|
+
* selectTierRate(tiers, 2000); // Returns tier_1000 (0.0000107740)
|
|
48
|
+
* selectTierRate(tiers, 10000); // Returns tier_5000 (0.0000107524)
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function selectTierRate(tiers, assetAmount) {
|
|
52
|
+
if (assetAmount >= 5000) {
|
|
53
|
+
return tiers.tier_5000;
|
|
54
|
+
}
|
|
55
|
+
if (assetAmount >= 1000) {
|
|
56
|
+
return tiers.tier_1000;
|
|
57
|
+
}
|
|
58
|
+
if (assetAmount >= 100) {
|
|
59
|
+
return tiers.tier_100;
|
|
60
|
+
}
|
|
61
|
+
return tiers.tier_1;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Compute the exchange rate with proper inversion handling.
|
|
65
|
+
*
|
|
66
|
+
* The backend sends rates in the format "BTC per 1 stablecoin" for ALL pairs.
|
|
67
|
+
* When the source is BTC and target is a stablecoin/EVM token, we need to
|
|
68
|
+
* invert the rate to get "stablecoin per 1 BTC".
|
|
69
|
+
*
|
|
70
|
+
* @param rate - The raw rate from the backend (BTC per 1 stablecoin)
|
|
71
|
+
* @param isSourceBtc - Whether the source token is BTC (Lightning, Arkade, or Onchain)
|
|
72
|
+
* @param isTargetEvmToken - Whether the target token is an EVM token (stablecoins, etc.)
|
|
73
|
+
* @returns The exchange rate as "1 source = X target"
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const btcPerUsdc = 0.000010773; // ~1 BTC = 92,828 USDC
|
|
78
|
+
*
|
|
79
|
+
* // USDC -> BTC: rate stays as-is (BTC per USDC)
|
|
80
|
+
* computeExchangeRate(btcPerUsdc, false, false); // 0.000010773
|
|
81
|
+
*
|
|
82
|
+
* // BTC -> USDC: rate is inverted (USDC per BTC)
|
|
83
|
+
* computeExchangeRate(btcPerUsdc, true, true); // ~92,828
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export function computeExchangeRate(rate, isSourceBtc, isTargetEvmToken) {
|
|
87
|
+
// Backend sends same rate for both directions (BTC per stablecoin).
|
|
88
|
+
// When source is BTC and target is EVM token, invert to get "EVM per BTC"
|
|
89
|
+
const needsInversion = isSourceBtc && isTargetEvmToken;
|
|
90
|
+
if (needsInversion) {
|
|
91
|
+
return 1 / rate;
|
|
92
|
+
}
|
|
93
|
+
return rate;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Calculate the target amount given a source amount.
|
|
97
|
+
* Uses the exchange rate semantics: 1 source = exchangeRate target
|
|
98
|
+
*
|
|
99
|
+
* Fee handling:
|
|
100
|
+
* - If source is BTC: fee is deducted from source before conversion
|
|
101
|
+
* - If target is BTC: fee is deducted from target after conversion
|
|
102
|
+
*
|
|
103
|
+
* @param sourceAmount - Amount of source asset
|
|
104
|
+
* @param exchangeRate - Rate where 1 source = exchangeRate target
|
|
105
|
+
* @param networkFeeInBtc - Network fee in BTC
|
|
106
|
+
* @param isSourceBtc - Whether source is BTC (fee deducted from source before conversion)
|
|
107
|
+
* @param isTargetBtc - Whether target is BTC (fee deducted from target after conversion)
|
|
108
|
+
* @returns Target amount after fees
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const networkFee = 0.0001; // 10,000 sats
|
|
113
|
+
*
|
|
114
|
+
* // USDC -> BTC: 1000 USDC at rate 0.000010773
|
|
115
|
+
* // Target = 1000 * 0.000010773 - 0.0001 = 0.010673 BTC
|
|
116
|
+
* calculateTargetAmount(1000, 0.000010773, networkFee, false, true);
|
|
117
|
+
*
|
|
118
|
+
* // BTC -> USDC: 0.01 BTC at rate 92,824
|
|
119
|
+
* // Target = (0.01 - 0.0001) * 92824 = 918.96 USDC
|
|
120
|
+
* calculateTargetAmount(0.01, 92824, networkFee, true, false);
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export function calculateTargetAmount(sourceAmount, exchangeRate, networkFeeInBtc, isSourceBtc, isTargetBtc) {
|
|
124
|
+
if (isSourceBtc) {
|
|
125
|
+
// Source is BTC: deduct fee from source, then convert
|
|
126
|
+
const sourceAfterFee = sourceAmount - networkFeeInBtc;
|
|
127
|
+
return sourceAfterFee * exchangeRate;
|
|
128
|
+
}
|
|
129
|
+
// Target is BTC: convert first, then deduct fee
|
|
130
|
+
const targetBeforeFee = sourceAmount * exchangeRate;
|
|
131
|
+
return isTargetBtc ? targetBeforeFee - networkFeeInBtc : targetBeforeFee;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Calculate the source amount needed to receive a target amount.
|
|
135
|
+
* Uses the exchange rate semantics: 1 source = exchangeRate target
|
|
136
|
+
*
|
|
137
|
+
* Fee handling (reverse of calculateTargetAmount):
|
|
138
|
+
* - If target is BTC: fee is added to target before reverse conversion
|
|
139
|
+
* - If source is BTC: fee is added to source after reverse conversion
|
|
140
|
+
*
|
|
141
|
+
* @param targetAmount - Desired amount of target asset
|
|
142
|
+
* @param exchangeRate - Rate where 1 source = exchangeRate target
|
|
143
|
+
* @param networkFeeInBtc - Network fee in BTC
|
|
144
|
+
* @param isSourceBtc - Whether source is BTC (fee added to required source)
|
|
145
|
+
* @param isTargetBtc - Whether target is BTC (fee added to target before reverse calc)
|
|
146
|
+
* @returns Source amount needed (including fees)
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const networkFee = 0.0001; // 10,000 sats
|
|
151
|
+
*
|
|
152
|
+
* // Want 0.01 BTC, paying with USDC at rate 0.000010773
|
|
153
|
+
* // Source = (0.01 + 0.0001) / 0.000010773 = 937.26 USDC
|
|
154
|
+
* calculateSourceAmount(0.01, 0.000010773, networkFee, false, true);
|
|
155
|
+
*
|
|
156
|
+
* // Want 1000 USDC, paying with BTC at rate 92,824
|
|
157
|
+
* // Source = 1000 / 92824 + 0.0001 = 0.01088 BTC
|
|
158
|
+
* calculateSourceAmount(1000, 92824, networkFee, true, false);
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export function calculateSourceAmount(targetAmount, exchangeRate, networkFeeInBtc, isSourceBtc, isTargetBtc) {
|
|
162
|
+
if (isTargetBtc) {
|
|
163
|
+
// Target is BTC: add fee to target, then reverse convert
|
|
164
|
+
const targetPlusFee = targetAmount + networkFeeInBtc;
|
|
165
|
+
return targetPlusFee / exchangeRate;
|
|
166
|
+
}
|
|
167
|
+
// Source is BTC: reverse convert first, then add fee
|
|
168
|
+
const sourceBeforeFee = targetAmount / exchangeRate;
|
|
169
|
+
return isSourceBtc ? sourceBeforeFee + networkFeeInBtc : sourceBeforeFee;
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=price-calculations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"price-calculations.js","sourceRoot":"","sources":["../src/price-calculations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAIH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,cAAc,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E,CAAC;QAChB,yDAAyD;QACzD,MAAM,aAAa,GAAG,YAAY,GAAG,eAAe,CAAC;QACrD,OAAO,aAAa,GAAG,YAAY,CAAC;IACtC,CAAC;IACD,qDAAqD;IACrD,MAAM,eAAe,GAAG,YAAY,GAAG,YAAY,CAAC;IACpD,OAAO,WAAW,CAAC,CAAC,CAAC,eAAe,GAAG,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC;AAC3E,CAAC"}
|
package/dist/price-feed.d.ts
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* unsubscribe();
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
+
import type { TokenIdString } from "./api";
|
|
22
23
|
/**
|
|
23
24
|
* Price tiers for different quote asset amounts.
|
|
24
25
|
* Different rates apply based on swap volume (in units of the quote asset).
|
|
@@ -39,6 +40,8 @@ export interface PriceTiers {
|
|
|
39
40
|
export interface TradingPairPrices {
|
|
40
41
|
/** Trading pair identifier, e.g., "USDC_POL-BTC" or "USDT0_POL-BTC" */
|
|
41
42
|
pair: string;
|
|
43
|
+
source: TokenIdString;
|
|
44
|
+
target: TokenIdString;
|
|
42
45
|
/** Price tiers for this pair */
|
|
43
46
|
tiers: PriceTiers;
|
|
44
47
|
}
|
package/dist/price-feed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price-feed.d.ts","sourceRoot":"","sources":["../src/price-feed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,QAAQ,EAAE,MAAM,CAAC;IACjB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uEAAuE;IACvE,IAAI,EAAE,M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AwD;IACxD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,aAAa,CAAC;IACtB,MAAM,EAAE,aAAa,CAAC;IACtB,gCAAgC;IAChC,KAAK,EAAE,UAAU,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,KAAK,EAAE,iBAAiB,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,SAAS,CAAuC;IACxD,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,aAAa,CAAS;IAE9B;;;;;OAKG;gBACS,OAAO,EAAE,MAAM;IAS3B;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,mBAAmB,GAAG,MAAM,IAAI;IAkBpD;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,aAAa,IAAI,MAAM;IAIvB;;OAEG;IACH,OAAO,CAAC,OAAO;IAqDf;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAiBzB;;OAEG;IACH,KAAK,IAAI,IAAI;CAad"}
|
package/dist/price-feed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price-feed.js","sourceRoot":"","sources":["../src/price-feed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;
|
|
1
|
+
{"version":3,"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AE,IAAI,CAAC,cAAc,CAAC,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAE1B,IAAI,IAAI,CAAC,cAAc,KAAK,IAAI,EAAE,CAAC;YACjC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7B,CAAC;QAED,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YACZ,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;QACjB,CAAC;IACH,CAAC;CACF"}
|
package/dist/usd-price.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usd-price.d.ts","sourceRoot":"","sources":["../src/usd-price.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"usd-price.d.ts","sourceRoot":"","sources":["../src/usd-price.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AA2C9C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,eAAe;IACf,OAAO,EAAE,aAAa,CAAC;IACvB,oCAAoC;IACpC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,+CAA+C;IAC/C,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAEpE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGxB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,aAAa,EAAE,EACzB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,cAAc,EAAE,CAAC,CAwE3B;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,IAAI,aAAa,EAAE,CAE/D"}
|
package/dist/usd-price.js
CHANGED
package/dist/usd-price.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usd-price.js","sourceRoot":"","sources":["../src/usd-price.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH;;GAEG;AACH,MAAM,aAAa,GAAG,kCAAkC,CAAC;AAEzD;;;GAGG;AACH,MAAM,kBAAkB,GAA2B;IACjD,mBAAmB;IACnB,aAAa,EAAE,SAAS;IACxB,UAAU,EAAE,SAAS;
|
|
1
|
+
{"version":3,"file":"usd-price.js","sourceRoot":"","sources":["../src/usd-price.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH;;GAEG;AACH,MAAM,aAAa,GAAG,kCAAkC,CAAC;AAEzD;;;GAGG;AACH,MAAM,kBAAkB,GAA2B;IACjD,mBAAmB;IACnB,aAAa,EAAE,SAAS;IACxB,UAAU,EAAE,SAAS;IACrB,WAAW,EAAE,SAAS;IAEtB,yBAAyB;IACzB,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,QAAQ;IAEnB,0BAA0B;IAC1B,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,QAAQ;IAElB,aAAa;IACb,QAAQ,EAAE,aAAa;IAEvB,gBAAgB;IAChB,OAAO,EAAE,eAAe,EAAE,uBAAuB;IACjD,OAAO,EAAE,UAAU;CACpB,CAAC;AAgCF;;;;;G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c;iBACpC,CAAC;aACL,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,KAAK,CAAC,CAAC;QACnE,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAChC,OAAO;YACP,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC,CAAC;IACN,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,6BAA6B;IAC3C,OAAO,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAoB,CAAC;AAC5D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lendasat/lendaswap-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.67",
|
|
4
4
|
"description": "Lendaswap Client SDK for TypeScript/JavaScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,9 +16,19 @@
|
|
|
16
16
|
"dist",
|
|
17
17
|
"wasm"
|
|
18
18
|
],
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build:wasm": "cd ../wasm-sdk && wasm-pack build --target bundler --out-dir ../ts-sdk/wasm && echo '# Allow npm to publish wasm files' > ../ts-sdk/wasm/.gitignore",
|
|
21
|
+
"build:wasm:release": "cd ../wasm-sdk && wasm-pack build --target bundler --release --out-dir ../ts-sdk/wasm && echo '# Allow npm to publish wasm files' > ../ts-sdk/wasm/.gitignore",
|
|
22
|
+
"build:ts": "tsc",
|
|
23
|
+
"build": "pnpm run build:wasm && pnpm run build:ts",
|
|
24
|
+
"build:release": "pnpm run build:wasm:release && pnpm run build:ts",
|
|
25
|
+
"test": "vitest",
|
|
26
|
+
"clean": "rm -rf dist wasm",
|
|
27
|
+
"prepublishOnly": "pnpm run build:release",
|
|
28
|
+
"publish:npm": "pnpm run build:release && pnpm publish --access public",
|
|
29
|
+
"publish:npm:dry-run": "pnpm run build:release && pnpm publish --access public --dry-run"
|
|
21
30
|
},
|
|
31
|
+
"dependencies": {},
|
|
22
32
|
"devDependencies": {
|
|
23
33
|
"@biomejs/biome": "2.3.7",
|
|
24
34
|
"@types/node": "^20.0.0",
|
|
@@ -42,16 +52,5 @@
|
|
|
42
52
|
},
|
|
43
53
|
"publishConfig": {
|
|
44
54
|
"access": "public"
|
|
45
|
-
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build:wasm": "cd ../wasm-sdk && wasm-pack build --target bundler --out-dir ../ts-sdk/wasm && echo '# Allow npm to publish wasm files' > ../ts-sdk/wasm/.gitignore",
|
|
48
|
-
"build:wasm:release": "cd ../wasm-sdk && wasm-pack build --target bundler --release --out-dir ../ts-sdk/wasm && echo '# Allow npm to publish wasm files' > ../ts-sdk/wasm/.gitignore",
|
|
49
|
-
"build:ts": "tsc",
|
|
50
|
-
"build": "pnpm run build:wasm && pnpm run build:ts",
|
|
51
|
-
"build:release": "pnpm run build:wasm:release && pnpm run build:ts",
|
|
52
|
-
"test": "vitest",
|
|
53
|
-
"clean": "rm -rf dist wasm",
|
|
54
|
-
"publish:npm": "pnpm run build:release && pnpm publish --access public",
|
|
55
|
-
"publish:npm:dry-run": "pnpm run build:release && pnpm publish --access public --dry-run"
|
|
56
55
|
}
|
|
57
|
-
}
|
|
56
|
+
}
|