@lendasat/lendaswap-sdk 0.1.0 → 0.1.3
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 +260 -37
- package/dist/api.d.ts +100 -28
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +139 -21
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/price-feed.d.ts +10 -10
- package/dist/price-feed.d.ts.map +1 -1
- package/dist/storage/dexieSwapStorage.d.ts +2 -2
- package/dist/storage/dexieSwapStorage.js +2 -2
- package/dist/storage/dexieWalletStorage.d.ts +2 -2
- package/dist/storage/dexieWalletStorage.js +2 -2
- package/dist/usd-price.d.ts +83 -0
- package/dist/usd-price.d.ts.map +1 -0
- package/dist/usd-price.js +157 -0
- package/dist/usd-price.js.map +1 -0
- package/package.json +15 -16
- package/dist/storage/indexedDB.d.ts +0 -30
- package/dist/storage/indexedDB.d.ts.map +0 -1
- package/dist/storage/indexedDB.js +0 -108
- package/dist/storage/indexedDB.js.map +0 -1
- package/dist/storage/localStorage.d.ts +0 -32
- package/dist/storage/localStorage.d.ts.map +0 -1
- package/dist/storage/localStorage.js +0 -58
- package/dist/storage/localStorage.js.map +0 -1
- package/dist/storage/memory.d.ts +0 -35
- package/dist/storage/memory.d.ts.map +0 -1
- package/dist/storage/memory.js +0 -50
- package/dist/storage/memory.js.map +0 -1
- package/dist/wallet.d.ts +0 -108
- package/dist/wallet.d.ts.map +0 -1
- package/dist/wallet.js +0 -188
- package/dist/wallet.js.map +0 -1
package/dist/api.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* API client for easier use in TypeScript/JavaScript applications.
|
|
6
6
|
*/
|
|
7
7
|
// Import WASM types for internal use
|
|
8
|
-
import init, { JsSwapStorageProvider, JsWalletStorageProvider, Client as WasmClient, } from "../wasm/lendaswap_wasm_sdk.js";
|
|
8
|
+
import init, { JsSwapStorageProvider, JsWalletStorageProvider, Chain as WasmChain, Client as WasmClient, getLogLevel as wasmGetLogLevel, setLogLevel as wasmSetLogLevel, } from "../wasm/lendaswap_wasm_sdk.js";
|
|
9
9
|
// Cached initialization promise
|
|
10
10
|
let initPromise = null;
|
|
11
11
|
/**
|
|
@@ -52,26 +52,45 @@ export async function initWasm(wasmPath) {
|
|
|
52
52
|
return initPromise;
|
|
53
53
|
}
|
|
54
54
|
// Re-export WASM types directly
|
|
55
|
-
export { QuoteResponse, TokenId, Version, VhtlcAmounts, } from "../wasm/lendaswap_wasm_sdk.js";
|
|
55
|
+
export { CreateVtxoSwapResult, EstimateVtxoSwapResponse, QuoteResponse, SwapParams as VtxoSwapParams, TokenId, Version, VhtlcAmounts, VtxoSwapResponse, } from "../wasm/lendaswap_wasm_sdk.js";
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
57
|
+
* Map WASM Chain enum to our Chain type.
|
|
58
|
+
*/
|
|
59
|
+
function mapChain(wasmChain) {
|
|
60
|
+
switch (wasmChain) {
|
|
61
|
+
case WasmChain.Arkade:
|
|
62
|
+
return "Arkade";
|
|
63
|
+
case WasmChain.Lightning:
|
|
64
|
+
return "Lightning";
|
|
65
|
+
case WasmChain.Polygon:
|
|
66
|
+
return "Polygon";
|
|
67
|
+
case WasmChain.Ethereum:
|
|
68
|
+
return "Ethereum";
|
|
69
|
+
default:
|
|
70
|
+
return String(wasmChain);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Map WASM TokenInfo to our typed TokenInfo.
|
|
75
|
+
*/
|
|
76
|
+
function mapTokenInfo(wasmToken) {
|
|
77
|
+
return {
|
|
78
|
+
tokenId: wasmToken.tokenId,
|
|
79
|
+
symbol: wasmToken.symbol,
|
|
80
|
+
chain: mapChain(wasmToken.chain),
|
|
81
|
+
name: wasmToken.name,
|
|
82
|
+
decimals: wasmToken.decimals,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Map WASM AssetPair to our typed AssetPair.
|
|
74
87
|
*/
|
|
88
|
+
function mapAssetPair(wasmPair) {
|
|
89
|
+
return {
|
|
90
|
+
source: mapTokenInfo(wasmPair.source),
|
|
91
|
+
target: mapTokenInfo(wasmPair.target),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
75
94
|
/**
|
|
76
95
|
* Convert a value from WASM (which may be a Map) to a plain object.
|
|
77
96
|
* serde_wasm_bindgen serializes structs as Maps by default.
|
|
@@ -123,7 +142,7 @@ export class Client {
|
|
|
123
142
|
* };
|
|
124
143
|
*
|
|
125
144
|
* const client = await Client.create(
|
|
126
|
-
* 'https://
|
|
145
|
+
* 'https://apilendaswap.lendasat.com',
|
|
127
146
|
* walletStorage,
|
|
128
147
|
* swapStorage,
|
|
129
148
|
* 'bitcoin',
|
|
@@ -183,7 +202,12 @@ export class Client {
|
|
|
183
202
|
return { ...obj, direction: "evm_to_btc" };
|
|
184
203
|
}
|
|
185
204
|
async getAssetPairs() {
|
|
186
|
-
|
|
205
|
+
const wasmPairs = await this.client.getAssetPairs();
|
|
206
|
+
return wasmPairs.map(mapAssetPair);
|
|
207
|
+
}
|
|
208
|
+
async getTokens() {
|
|
209
|
+
const wasmTokens = await this.client.getTokens();
|
|
210
|
+
return wasmTokens.map(mapTokenInfo);
|
|
187
211
|
}
|
|
188
212
|
/**
|
|
189
213
|
* Get a quote for a swap.
|
|
@@ -302,5 +326,99 @@ export class Client {
|
|
|
302
326
|
async deleteSwap(id) {
|
|
303
327
|
return await this.client.deleteSwap(id);
|
|
304
328
|
}
|
|
329
|
+
// =========================================================================
|
|
330
|
+
// VTXO Swap Methods
|
|
331
|
+
// =========================================================================
|
|
332
|
+
/**
|
|
333
|
+
* Estimate the fee for a VTXO swap.
|
|
334
|
+
*
|
|
335
|
+
* @param vtxos - List of VTXO outpoints to refresh ("txid:vout" format)
|
|
336
|
+
* @returns Estimate response with fee and output amounts
|
|
337
|
+
*/
|
|
338
|
+
async estimateVtxoSwap(vtxos) {
|
|
339
|
+
return await this.client.estimateVtxoSwap(vtxos);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Create a VTXO swap for refreshing VTXOs.
|
|
343
|
+
*
|
|
344
|
+
* This creates a swap where the client will fund their VHTLC first,
|
|
345
|
+
* then the server funds their VHTLC, and the client claims the server's
|
|
346
|
+
* VHTLC to complete the swap.
|
|
347
|
+
*
|
|
348
|
+
* @param vtxos - List of VTXO outpoints to refresh ("txid:vout" format)
|
|
349
|
+
* @returns The swap response and swap parameters
|
|
350
|
+
*/
|
|
351
|
+
async createVtxoSwap(vtxos) {
|
|
352
|
+
return await this.client.createVtxoSwap(vtxos);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Get VTXO swap details by ID.
|
|
356
|
+
*
|
|
357
|
+
* @param id - The swap ID
|
|
358
|
+
* @returns The VTXO swap response
|
|
359
|
+
*/
|
|
360
|
+
async getVtxoSwap(id) {
|
|
361
|
+
return await this.client.getVtxoSwap(id);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Claim the server's VHTLC in a VTXO swap.
|
|
365
|
+
*
|
|
366
|
+
* This should be called after the server has funded their VHTLC.
|
|
367
|
+
* The client reveals the preimage to claim the fresh VTXOs.
|
|
368
|
+
*
|
|
369
|
+
* @param swap - The VTXO swap response
|
|
370
|
+
* @param swapParams - The client's swap parameters (containing preimage)
|
|
371
|
+
* @param claimAddress - The Arkade address to receive the claimed funds
|
|
372
|
+
* @returns The claim transaction ID
|
|
373
|
+
*/
|
|
374
|
+
async claimVtxoSwap(swap, swapParams, claimAddress) {
|
|
375
|
+
return await this.client.claimVtxoSwap(swap, swapParams, claimAddress);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Refund the client's VHTLC in a VTXO swap.
|
|
379
|
+
*
|
|
380
|
+
* This can be called if the swap fails (e.g., server doesn't fund)
|
|
381
|
+
* and the client's locktime has expired.
|
|
382
|
+
*
|
|
383
|
+
* @param swap - The VTXO swap response
|
|
384
|
+
* @param swapParams - The client's swap parameters
|
|
385
|
+
* @param refundAddress - The Arkade address to receive the refunded funds
|
|
386
|
+
* @returns The refund transaction ID
|
|
387
|
+
*/
|
|
388
|
+
async refundVtxoSwap(swap, swapParams, refundAddress) {
|
|
389
|
+
return await this.client.refundVtxoSwap(swap, swapParams, refundAddress);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Set the SDK log level.
|
|
394
|
+
*
|
|
395
|
+
* This configures the log level for all Rust/WASM code in the SDK.
|
|
396
|
+
* The level is persisted in localStorage under key "lendaswap_log_level",
|
|
397
|
+
* so it will be used on page reload.
|
|
398
|
+
*
|
|
399
|
+
* @param level - Log level: "trace", "debug", "info", "warn", "error"
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* ```typescript
|
|
403
|
+
* import { setLogLevel } from '@lendasat/lendaswap-sdk';
|
|
404
|
+
*
|
|
405
|
+
* // Enable debug logging
|
|
406
|
+
* setLogLevel('debug');
|
|
407
|
+
*
|
|
408
|
+
* // Or set via localStorage directly (for debugging in browser console)
|
|
409
|
+
* localStorage.setItem('lendaswap_log_level', 'debug');
|
|
410
|
+
* // Then reload the page
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
export function setLogLevel(level) {
|
|
414
|
+
wasmSetLogLevel(level);
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Get the current SDK log level.
|
|
418
|
+
*
|
|
419
|
+
* @returns Current log level
|
|
420
|
+
*/
|
|
421
|
+
export function getLogLevel() {
|
|
422
|
+
return wasmGetLogLevel();
|
|
305
423
|
}
|
|
306
424
|
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qCAAqC;AACrC,OAAO,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qCAAqC;AACrC,OAAO,IAAI,EAAE,EAGX,qBAAqB,EACrB,uBAAuB,EAIvB,KAAK,IAAI,SAAS,EAClB,MAAM,IAAI,UAAU,EAEpB,WAAW,IAAI,eAAe,EAC9B,WAAW,IAAI,eAAe,GAC/B,MAAM,+BAA+B,CAAC;AAGvC,gCAAgC;AAChC,IAAI,WAAW,GAAyB,IAAI,CAAC;AAE7C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,QAAiB;IAC9C,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC;IACrB,CAAC;IAED,WAAW,GAAG,CAAC,KAAK,IAAI,EAAE;QACxB,4BAA4B;QAC5B,MAAM,MAAM,GACV,OAAO,OAAO,KAAK,WAAW;YAC9B,OAAO,CAAC,QAAQ,IAAI,IAAI;YACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC;QAEhC,IAAI,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;YACxB,iDAAiD;YACjD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;YACjD,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC;YAC9C,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;YAE/C,0CAA0C;YAC1C,MAAM,UAAU,GAAG,aA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B,EACtB,UAAsB,EACtB,YAAoB;QAEpB,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;IACzE,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,cAAc,CAClB,IAAsB,EACtB,UAAsB,EACtB,aAAqB;QAErB,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;IAC3E,CAAC;CACF;AAOD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,WAAW,CAAC,KAAe;IACzC,eAAe,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,eAAe,EAAc,CAAC;AACvC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
* // Create client
|
|
20
20
|
* const client = await Client.create(
|
|
21
|
-
* 'https://
|
|
21
|
+
* 'https://apilendaswap.lendasat.com',
|
|
22
22
|
* walletStorage,
|
|
23
23
|
* swapStorage,
|
|
24
24
|
* 'bitcoin',
|
|
@@ -35,8 +35,9 @@
|
|
|
35
35
|
* @packageDocumentation
|
|
36
36
|
*/
|
|
37
37
|
export type { QuoteResponse, QuoteResponseInfo, SwapStorageProvider, TokenInfo, Version, VersionInfo, WalletStorageProvider, } from "./api.js";
|
|
38
|
-
export { type AssetPair, type BtcToEvmSwapResponse, type Chain, Client, type EvmToArkadeSwapRequest, type EvmToBtcSwapResponse, type EvmToLightningSwapRequest, type ExtendedSwapStorageData, type GelatoSubmitRequest, type GelatoSubmitResponse, type GetSwapResponse, type QuoteRequest, type RecoveredSwap, type RecoverSwapsResponse, type SwapCommonFields, type SwapRequest, type SwapStatus, TokenId, type TokenIdString, } from "./api.js";
|
|
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 SwapCommonFields, type SwapRequest, type SwapStatus, setLogLevel, TokenId, type TokenIdString, VtxoSwapParams, VtxoSwapResponse, type VtxoSwapStatus, } from "./api.js";
|
|
39
39
|
export { PriceFeedService, type PriceTiers, type PriceUpdateCallback, type PriceUpdateMessage, type TradingPairPrices, } from "./price-feed.js";
|
|
40
40
|
export { createDexieSwapStorage, createDexieWalletStorage, DexieSwapStorageProvider, DexieWalletStorageProvider, STORAGE_KEYS, } from "./storage/index.js";
|
|
41
41
|
export type { Network, SwapData, SwapParams, VhtlcAmounts } from "./types.js";
|
|
42
|
+
export { type GetUsdPriceOptions, getCoinGeckoId, getSupportedTokensForUsdPrice, getUsdPrice, getUsdPrices, type UsdPriceResult, } from "./usd-price.js";
|
|
42
43
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAIH,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,OAAO,EACP,WAAW,EACX,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,KAAK,EACV,MAAM,EACN,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,OAAO,EACP,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAIH,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,OAAO,EACP,WAAW,EACX,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,KAAK,EACV,MAAM,EACN,oBAAoB,EACpB,wBAAwB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,WAAW,EACX,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,WAAW,EACX,OAAO,EACP,KAAK,aAAa,EAClB,cAAc,EACd,gBAAgB,EAChB,KAAK,cAAc,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,0BAA0B,EAC1B,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EACL,KAAK,kBAAkB,EACvB,cAAc,EACd,6BAA6B,EAC7B,WAAW,EACX,YAAY,EACZ,KAAK,cAAc,GACpB,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
* // Create client
|
|
20
20
|
* const client = await Client.create(
|
|
21
|
-
* 'https://
|
|
21
|
+
* 'https://apilendaswap.lendasat.com',
|
|
22
22
|
* walletStorage,
|
|
23
23
|
* swapStorage,
|
|
24
24
|
* 'bitcoin',
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
* @packageDocumentation
|
|
36
36
|
*/
|
|
37
37
|
// API client
|
|
38
|
-
export { Client, TokenId, } from "./api.js";
|
|
39
|
-
// Price feed
|
|
38
|
+
export { Client, CreateVtxoSwapResult, EstimateVtxoSwapResponse, getLogLevel, setLogLevel, TokenId, VtxoSwapParams, VtxoSwapResponse, } from "./api.js";
|
|
40
39
|
export { PriceFeedService, } from "./price-feed.js";
|
|
41
40
|
// Storage (wallet data)
|
|
42
41
|
// Swap storage (typed swap data using Dexie/IndexedDB)
|
|
43
42
|
// Wallet storage (typed wallet data using Dexie/IndexedDB)
|
|
44
43
|
export { createDexieSwapStorage, createDexieWalletStorage, DexieSwapStorageProvider, DexieWalletStorageProvider, STORAGE_KEYS, } from "./storage/index.js";
|
|
44
|
+
export { getCoinGeckoId, getSupportedTokensForUsdPrice, getUsdPrice, getUsdPrices, } from "./usd-price.js";
|
|
45
45
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAaH,aAAa;AACb,OAAO,EAIL,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAaH,aAAa;AACb,OAAO,EAIL,MAAM,EACN,oBAAoB,EACpB,wBAAwB,EAQxB,WAAW,EAQX,WAAW,EACX,OAAO,EAEP,cAAc,EACd,gBAAgB,GAEjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,GAKjB,MAAM,iBAAiB,CAAC;AACzB,wBAAwB;AACxB,uDAAuD;AACvD,2DAA2D;AAC3D,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,0BAA0B,EAC1B,YAAY,GACb,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEL,cAAc,EACd,6BAA6B,EAC7B,WAAW,EACX,YAAY,GAEb,MAAM,gBAAgB,CAAC"}
|
package/dist/price-feed.d.ts
CHANGED
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
/**
|
|
23
|
-
* Price tiers for different
|
|
24
|
-
* Different rates apply based on swap volume.
|
|
23
|
+
* Price tiers for different quote asset amounts.
|
|
24
|
+
* Different rates apply based on swap volume (in units of the quote asset).
|
|
25
25
|
*/
|
|
26
26
|
export interface PriceTiers {
|
|
27
|
-
/** Rate
|
|
28
|
-
|
|
29
|
-
/** Rate
|
|
30
|
-
|
|
31
|
-
/** Rate
|
|
32
|
-
|
|
33
|
-
/** Rate
|
|
34
|
-
|
|
27
|
+
/** Rate when swapping 1 unit of the quote asset */
|
|
28
|
+
tier_1: number;
|
|
29
|
+
/** Rate when swapping 100 units of the quote asset */
|
|
30
|
+
tier_100: number;
|
|
31
|
+
/** Rate when swapping 1,000 units of the quote asset */
|
|
32
|
+
tier_1000: number;
|
|
33
|
+
/** Rate when swapping 5,000 units of the quote asset */
|
|
34
|
+
tier_5000: number;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Trading pair prices with volume-based tiers.
|
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,
|
|
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,MAAM,CAAC;IACb,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"}
|
|
@@ -27,7 +27,7 @@ interface SwapRecord extends ExtendedSwapStorageData {
|
|
|
27
27
|
*
|
|
28
28
|
* // Use with the Client
|
|
29
29
|
* const client = await Client.create(
|
|
30
|
-
* 'https://
|
|
30
|
+
* 'https://apilendaswap.lendasat.com',
|
|
31
31
|
* walletStorage,
|
|
32
32
|
* swapStorage,
|
|
33
33
|
* 'bitcoin',
|
|
@@ -98,7 +98,7 @@ export declare class DexieSwapStorageProvider {
|
|
|
98
98
|
*
|
|
99
99
|
* const swapStorage = createDexieSwapStorage();
|
|
100
100
|
* const client = await Client.create(
|
|
101
|
-
* 'https://
|
|
101
|
+
* 'https://apilendaswap.lendasat.com',
|
|
102
102
|
* walletStorage,
|
|
103
103
|
* swapStorage,
|
|
104
104
|
* 'bitcoin',
|
|
@@ -32,7 +32,7 @@ class LendaswapDatabase extends Dexie {
|
|
|
32
32
|
*
|
|
33
33
|
* // Use with the Client
|
|
34
34
|
* const client = await Client.create(
|
|
35
|
-
* 'https://
|
|
35
|
+
* 'https://apilendaswap.lendasat.com',
|
|
36
36
|
* walletStorage,
|
|
37
37
|
* swapStorage,
|
|
38
38
|
* 'bitcoin',
|
|
@@ -125,7 +125,7 @@ export class DexieSwapStorageProvider {
|
|
|
125
125
|
*
|
|
126
126
|
* const swapStorage = createDexieSwapStorage();
|
|
127
127
|
* const client = await Client.create(
|
|
128
|
-
* 'https://
|
|
128
|
+
* 'https://apilendaswap.lendasat.com',
|
|
129
129
|
* walletStorage,
|
|
130
130
|
* swapStorage,
|
|
131
131
|
* 'bitcoin',
|
|
@@ -21,7 +21,7 @@ import type { WalletStorageProvider } from "../api.js";
|
|
|
21
21
|
*
|
|
22
22
|
* // Use with the Client
|
|
23
23
|
* const client = await Client.create(
|
|
24
|
-
* 'https://
|
|
24
|
+
* 'https://apilendaswap.lendasat.com',
|
|
25
25
|
* walletStorage,
|
|
26
26
|
* swapStorage,
|
|
27
27
|
* 'bitcoin',
|
|
@@ -87,7 +87,7 @@ export declare class DexieWalletStorageProvider implements WalletStorageProvider
|
|
|
87
87
|
* const swapStorage = createDexieSwapStorage();
|
|
88
88
|
*
|
|
89
89
|
* const client = await Client.create(
|
|
90
|
-
* 'https://
|
|
90
|
+
* 'https://apilendaswap.lendasat.com',
|
|
91
91
|
* walletStorage,
|
|
92
92
|
* swapStorage,
|
|
93
93
|
* 'bitcoin',
|
|
@@ -33,7 +33,7 @@ class WalletDatabase extends Dexie {
|
|
|
33
33
|
*
|
|
34
34
|
* // Use with the Client
|
|
35
35
|
* const client = await Client.create(
|
|
36
|
-
* 'https://
|
|
36
|
+
* 'https://apilendaswap.lendasat.com',
|
|
37
37
|
* walletStorage,
|
|
38
38
|
* swapStorage,
|
|
39
39
|
* 'bitcoin',
|
|
@@ -125,7 +125,7 @@ export class DexieWalletStorageProvider {
|
|
|
125
125
|
* const swapStorage = createDexieSwapStorage();
|
|
126
126
|
*
|
|
127
127
|
* const client = await Client.create(
|
|
128
|
-
* 'https://
|
|
128
|
+
* 'https://apilendaswap.lendasat.com',
|
|
129
129
|
* walletStorage,
|
|
130
130
|
* swapStorage,
|
|
131
131
|
* 'bitcoin',
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* USD price fetching utilities using CoinGecko API.
|
|
3
|
+
*
|
|
4
|
+
* Provides functions to fetch current USD prices for tokens supported by the SDK.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { getUsdPrice, getUsdPrices, TokenId } from '@lendaswap/sdk';
|
|
9
|
+
*
|
|
10
|
+
* // Get single token price
|
|
11
|
+
* const btcPrice = await getUsdPrice('btc_lightning');
|
|
12
|
+
* console.log('BTC price:', btcPrice);
|
|
13
|
+
*
|
|
14
|
+
* // Get multiple token prices
|
|
15
|
+
* const prices = await getUsdPrices(['btc_lightning', 'usdc_pol', 'pol_pol']);
|
|
16
|
+
* console.log('Prices:', prices);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import type { TokenIdString } from "./api.js";
|
|
20
|
+
/**
|
|
21
|
+
* USD price result for a token
|
|
22
|
+
*/
|
|
23
|
+
export interface UsdPriceResult {
|
|
24
|
+
/** Token ID */
|
|
25
|
+
tokenId: TokenIdString;
|
|
26
|
+
/** USD price (null if not found) */
|
|
27
|
+
usdPrice: number | null;
|
|
28
|
+
/** 24h change percentage (optional) */
|
|
29
|
+
change24h?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Options for price fetching
|
|
33
|
+
*/
|
|
34
|
+
export interface GetUsdPriceOptions {
|
|
35
|
+
/** Include 24h price change. Default: false */
|
|
36
|
+
include24hChange?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the CoinGecko ID for a given TokenId.
|
|
40
|
+
*
|
|
41
|
+
* @param tokenId - The SDK token ID
|
|
42
|
+
* @returns CoinGecko coin ID or null if not supported
|
|
43
|
+
*/
|
|
44
|
+
export declare function getCoinGeckoId(tokenId: TokenIdString): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* Fetch the current USD price for a single token.
|
|
47
|
+
*
|
|
48
|
+
* @param tokenId - Token ID (e.g., 'btc_lightning', 'usdc_pol', 'pol_pol')
|
|
49
|
+
* @param options - Optional settings
|
|
50
|
+
* @returns USD price or null if not found/error
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const btcPrice = await getUsdPrice('btc_lightning');
|
|
55
|
+
* if (btcPrice) {
|
|
56
|
+
* console.log(`BTC: $${btcPrice.toFixed(2)}`);
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function getUsdPrice(tokenId: TokenIdString, options?: GetUsdPriceOptions): Promise<number | null>;
|
|
61
|
+
/**
|
|
62
|
+
* Fetch current USD prices for multiple tokens in a single request.
|
|
63
|
+
*
|
|
64
|
+
* @param tokenIds - Array of token IDs
|
|
65
|
+
* @param options - Optional settings
|
|
66
|
+
* @returns Array of price results (same order as input)
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const prices = await getUsdPrices(['btc_lightning', 'pol_pol', 'usdc_pol']);
|
|
71
|
+
* for (const p of prices) {
|
|
72
|
+
* console.log(`${p.tokenId}: $${p.usdPrice?.toFixed(2) ?? 'N/A'}`);
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function getUsdPrices(tokenIds: TokenIdString[], options?: GetUsdPriceOptions): Promise<UsdPriceResult[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Get all supported token IDs that have USD price mappings.
|
|
79
|
+
*
|
|
80
|
+
* @returns Array of supported token IDs
|
|
81
|
+
*/
|
|
82
|
+
export declare function getSupportedTokensForUsdPrice(): TokenIdString[];
|
|
83
|
+
//# sourceMappingURL=usd-price.d.ts.map
|
|
@@ -0,0 +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;AA0C9C;;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"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* USD price fetching utilities using CoinGecko API.
|
|
3
|
+
*
|
|
4
|
+
* Provides functions to fetch current USD prices for tokens supported by the SDK.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { getUsdPrice, getUsdPrices, TokenId } from '@lendaswap/sdk';
|
|
9
|
+
*
|
|
10
|
+
* // Get single token price
|
|
11
|
+
* const btcPrice = await getUsdPrice('btc_lightning');
|
|
12
|
+
* console.log('BTC price:', btcPrice);
|
|
13
|
+
*
|
|
14
|
+
* // Get multiple token prices
|
|
15
|
+
* const prices = await getUsdPrices(['btc_lightning', 'usdc_pol', 'pol_pol']);
|
|
16
|
+
* console.log('Prices:', prices);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* CoinGecko API base URL
|
|
21
|
+
*/
|
|
22
|
+
const COINGECKO_API = "https://api.coingecko.com/api/v3";
|
|
23
|
+
/**
|
|
24
|
+
* Mapping from SDK TokenId to CoinGecko coin ID.
|
|
25
|
+
* CoinGecko uses lowercase slugs as identifiers.
|
|
26
|
+
*/
|
|
27
|
+
const TOKEN_TO_COINGECKO = {
|
|
28
|
+
// Bitcoin variants
|
|
29
|
+
btc_lightning: "bitcoin",
|
|
30
|
+
btc_arkade: "bitcoin",
|
|
31
|
+
// Stablecoins on Polygon
|
|
32
|
+
usdc_pol: "usd-coin",
|
|
33
|
+
usdt0_pol: "tether",
|
|
34
|
+
// Stablecoins on Ethereum
|
|
35
|
+
usdc_eth: "usd-coin",
|
|
36
|
+
usdt_eth: "tether",
|
|
37
|
+
// Gold token
|
|
38
|
+
xaut_eth: "tether-gold",
|
|
39
|
+
// Native tokens
|
|
40
|
+
pol_pol: "matic-network", // POL (formerly MATIC)
|
|
41
|
+
eth_eth: "ethereum",
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Get the CoinGecko ID for a given TokenId.
|
|
45
|
+
*
|
|
46
|
+
* @param tokenId - The SDK token ID
|
|
47
|
+
* @returns CoinGecko coin ID or null if not supported
|
|
48
|
+
*/
|
|
49
|
+
export function getCoinGeckoId(tokenId) {
|
|
50
|
+
return TOKEN_TO_COINGECKO[tokenId.toLowerCase()] ?? null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Fetch the current USD price for a single token.
|
|
54
|
+
*
|
|
55
|
+
* @param tokenId - Token ID (e.g., 'btc_lightning', 'usdc_pol', 'pol_pol')
|
|
56
|
+
* @param options - Optional settings
|
|
57
|
+
* @returns USD price or null if not found/error
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const btcPrice = await getUsdPrice('btc_lightning');
|
|
62
|
+
* if (btcPrice) {
|
|
63
|
+
* console.log(`BTC: $${btcPrice.toFixed(2)}`);
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export async function getUsdPrice(tokenId, options) {
|
|
68
|
+
const result = await getUsdPrices([tokenId], options);
|
|
69
|
+
return result[0]?.usdPrice ?? null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Fetch current USD prices for multiple tokens in a single request.
|
|
73
|
+
*
|
|
74
|
+
* @param tokenIds - Array of token IDs
|
|
75
|
+
* @param options - Optional settings
|
|
76
|
+
* @returns Array of price results (same order as input)
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const prices = await getUsdPrices(['btc_lightning', 'pol_pol', 'usdc_pol']);
|
|
81
|
+
* for (const p of prices) {
|
|
82
|
+
* console.log(`${p.tokenId}: $${p.usdPrice?.toFixed(2) ?? 'N/A'}`);
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export async function getUsdPrices(tokenIds, options) {
|
|
87
|
+
// Map token IDs to CoinGecko IDs, filtering out unsupported tokens
|
|
88
|
+
const tokenToCoinGecko = new Map();
|
|
89
|
+
for (const tokenId of tokenIds) {
|
|
90
|
+
const coinGeckoId = getCoinGeckoId(tokenId);
|
|
91
|
+
if (coinGeckoId) {
|
|
92
|
+
tokenToCoinGecko.set(tokenId.toLowerCase(), coinGeckoId);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Get unique CoinGecko IDs
|
|
96
|
+
const uniqueCoinGeckoIds = [...new Set(tokenToCoinGecko.values())];
|
|
97
|
+
if (uniqueCoinGeckoIds.length === 0) {
|
|
98
|
+
// No supported tokens, return null prices for all
|
|
99
|
+
return tokenIds.map((tokenId) => ({
|
|
100
|
+
tokenId,
|
|
101
|
+
usdPrice: null,
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
// Build request URL
|
|
105
|
+
const include24hChange = options?.include24hChange ?? false;
|
|
106
|
+
const params = new URLSearchParams({
|
|
107
|
+
ids: uniqueCoinGeckoIds.join(","),
|
|
108
|
+
vs_currencies: "usd",
|
|
109
|
+
...(include24hChange && { include_24hr_change: "true" }),
|
|
110
|
+
});
|
|
111
|
+
try {
|
|
112
|
+
const response = await fetch(`${COINGECKO_API}/simple/price?${params}`);
|
|
113
|
+
if (!response.ok) {
|
|
114
|
+
console.error(`CoinGecko API error: ${response.status} ${response.statusText}`);
|
|
115
|
+
return tokenIds.map((tokenId) => ({
|
|
116
|
+
tokenId,
|
|
117
|
+
usdPrice: null,
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
const data = await response.json();
|
|
121
|
+
// Map results back to token IDs
|
|
122
|
+
return tokenIds.map((tokenId) => {
|
|
123
|
+
const coinGeckoId = tokenToCoinGecko.get(tokenId.toLowerCase());
|
|
124
|
+
if (!coinGeckoId) {
|
|
125
|
+
return { tokenId, usdPrice: null };
|
|
126
|
+
}
|
|
127
|
+
const priceData = data[coinGeckoId];
|
|
128
|
+
if (!priceData) {
|
|
129
|
+
return { tokenId, usdPrice: null };
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
tokenId,
|
|
133
|
+
usdPrice: priceData.usd,
|
|
134
|
+
...(include24hChange &&
|
|
135
|
+
priceData.usd_24h_change !== undefined && {
|
|
136
|
+
change24h: priceData.usd_24h_change,
|
|
137
|
+
}),
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.error("Failed to fetch USD prices from CoinGecko:", error);
|
|
143
|
+
return tokenIds.map((tokenId) => ({
|
|
144
|
+
tokenId,
|
|
145
|
+
usdPrice: null,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get all supported token IDs that have USD price mappings.
|
|
151
|
+
*
|
|
152
|
+
* @returns Array of supported token IDs
|
|
153
|
+
*/
|
|
154
|
+
export function getSupportedTokensForUsdPrice() {
|
|
155
|
+
return Object.keys(TOKEN_TO_COINGECKO);
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=usd-price.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usd-price.js","sourceRoot":"","sources":["../src/usd-price.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;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