@atomiqlabs/sdk 8.8.3 → 8.9.0

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.
Files changed (130) hide show
  1. package/api/index.d.ts +1 -0
  2. package/api/index.js +3 -0
  3. package/dist/ApiList.d.ts +37 -0
  4. package/dist/ApiList.js +30 -0
  5. package/dist/api/ApiEndpoints.d.ts +393 -0
  6. package/dist/api/ApiEndpoints.js +2 -0
  7. package/dist/api/ApiParser.d.ts +10 -0
  8. package/dist/api/ApiParser.js +134 -0
  9. package/dist/api/ApiTypes.d.ts +157 -0
  10. package/dist/api/ApiTypes.js +75 -0
  11. package/dist/api/SerializedAction.d.ts +40 -0
  12. package/dist/api/SerializedAction.js +59 -0
  13. package/dist/api/SwapperApi.d.ts +50 -0
  14. package/dist/api/SwapperApi.js +431 -0
  15. package/dist/api/index.d.ts +5 -0
  16. package/dist/api/index.js +24 -0
  17. package/dist/events/UnifiedSwapEventListener.d.ts +4 -3
  18. package/dist/events/UnifiedSwapEventListener.js +8 -2
  19. package/dist/http/HttpUtils.d.ts +4 -2
  20. package/dist/http/HttpUtils.js +10 -4
  21. package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +2 -1
  22. package/dist/http/paramcoders/client/StreamingFetchPromise.js +3 -2
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/intermediaries/IntermediaryDiscovery.d.ts +7 -2
  26. package/dist/intermediaries/IntermediaryDiscovery.js +4 -4
  27. package/dist/intermediaries/apis/IntermediaryAPI.d.ts +171 -14
  28. package/dist/intermediaries/apis/IntermediaryAPI.js +174 -28
  29. package/dist/intermediaries/auth/SignedKeyBasedAuth.d.ts +14 -0
  30. package/dist/intermediaries/auth/SignedKeyBasedAuth.js +68 -0
  31. package/dist/storage/IUnifiedStorage.d.ts +45 -3
  32. package/dist/storage/UnifiedSwapStorage.d.ts +8 -2
  33. package/dist/storage/UnifiedSwapStorage.js +46 -8
  34. package/dist/swapper/Swapper.d.ts +36 -3
  35. package/dist/swapper/Swapper.js +54 -18
  36. package/dist/swapper/SwapperUtils.d.ts +18 -2
  37. package/dist/swapper/SwapperUtils.js +39 -1
  38. package/dist/swaps/ISwap.d.ts +70 -9
  39. package/dist/swaps/ISwap.js +28 -6
  40. package/dist/swaps/ISwapWrapper.d.ts +11 -1
  41. package/dist/swaps/ISwapWrapper.js +23 -3
  42. package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +1 -1
  43. package/dist/swaps/escrow_swaps/IEscrowSwap.js +4 -2
  44. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +2 -1
  45. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +2 -2
  46. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +3 -1
  47. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +3 -2
  48. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +47 -31
  49. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +201 -67
  50. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +3 -1
  51. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +6 -6
  52. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +82 -15
  53. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +304 -98
  54. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +3 -1
  55. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +6 -6
  56. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +75 -42
  57. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +424 -87
  58. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +3 -1
  59. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +7 -7
  60. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +54 -11
  61. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +214 -41
  62. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +2 -1
  63. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +7 -8
  64. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +3 -1
  65. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +5 -5
  66. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +76 -19
  67. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +290 -51
  68. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +3 -1
  69. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +5 -5
  70. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +53 -12
  71. package/dist/swaps/trusted/ln/LnForGasSwap.js +163 -49
  72. package/dist/swaps/trusted/ln/LnForGasWrapper.js +1 -2
  73. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +14 -13
  74. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +30 -47
  75. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +3 -1
  76. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +4 -4
  77. package/dist/types/SwapExecutionAction.d.ts +141 -34
  78. package/dist/types/SwapExecutionAction.js +104 -0
  79. package/dist/types/SwapExecutionStep.d.ts +144 -0
  80. package/dist/types/SwapExecutionStep.js +87 -0
  81. package/dist/types/TokenAmount.d.ts +6 -0
  82. package/dist/types/TokenAmount.js +26 -1
  83. package/dist/utils/BitcoinUtils.d.ts +2 -0
  84. package/dist/utils/BitcoinUtils.js +34 -1
  85. package/dist/utils/Utils.d.ts +3 -1
  86. package/dist/utils/Utils.js +7 -1
  87. package/package.json +7 -4
  88. package/src/api/ApiEndpoints.ts +427 -0
  89. package/src/api/ApiParser.ts +138 -0
  90. package/src/api/ApiTypes.ts +229 -0
  91. package/src/api/SerializedAction.ts +97 -0
  92. package/src/api/SwapperApi.ts +545 -0
  93. package/src/api/index.ts +5 -0
  94. package/src/events/UnifiedSwapEventListener.ts +11 -3
  95. package/src/http/HttpUtils.ts +10 -4
  96. package/src/http/paramcoders/client/StreamingFetchPromise.ts +4 -2
  97. package/src/index.ts +1 -0
  98. package/src/intermediaries/IntermediaryDiscovery.ts +9 -2
  99. package/src/intermediaries/apis/IntermediaryAPI.ts +314 -30
  100. package/src/intermediaries/auth/SignedKeyBasedAuth.ts +69 -0
  101. package/src/storage/IUnifiedStorage.ts +45 -4
  102. package/src/storage/UnifiedSwapStorage.ts +42 -8
  103. package/src/swapper/Swapper.ts +87 -18
  104. package/src/swapper/SwapperUtils.ts +42 -2
  105. package/src/swaps/ISwap.ts +88 -16
  106. package/src/swaps/ISwapWrapper.ts +28 -3
  107. package/src/swaps/escrow_swaps/IEscrowSwap.ts +5 -3
  108. package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +3 -1
  109. package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +4 -1
  110. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +264 -67
  111. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +6 -4
  112. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +390 -89
  113. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +6 -4
  114. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +548 -94
  115. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +7 -5
  116. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +276 -45
  117. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +7 -6
  118. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +5 -3
  119. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +393 -57
  120. package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +5 -3
  121. package/src/swaps/trusted/ln/LnForGasSwap.ts +211 -47
  122. package/src/swaps/trusted/ln/LnForGasWrapper.ts +1 -2
  123. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +32 -51
  124. package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +5 -3
  125. package/src/types/SwapExecutionAction.ts +266 -43
  126. package/src/types/SwapExecutionStep.ts +224 -0
  127. package/src/types/TokenAmount.ts +36 -2
  128. package/src/utils/BitcoinUtils.ts +32 -0
  129. package/src/utils/Utils.ts +10 -1
  130. package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +0 -258
package/api/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "../dist/api";
package/api/index.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ module.exports = require("../dist/api");
@@ -0,0 +1,37 @@
1
+ declare const apiFunctionDict: {
2
+ createSwap: {
3
+ type: string;
4
+ callback: (requestBody: any, queryParams: any) => void;
5
+ inputSchema: {
6
+ inputToken: {
7
+ type: string;
8
+ description: string;
9
+ };
10
+ outputToken: string;
11
+ amount: string;
12
+ };
13
+ };
14
+ status: {
15
+ type: string;
16
+ callback: (requestBody: any, queryParams: any) => {
17
+ new (executor: (resolve: (value: any) => void, reject: (reason?: any) => void) => void): Promise<any>;
18
+ all<T>(values: Iterable<T | PromiseLike<T>>): Promise<Awaited<T>[]>;
19
+ all<T_1 extends [] | readonly unknown[]>(values: T_1): Promise<{ -readonly [P in keyof T_1]: Awaited<T_1[P]>; }>;
20
+ race<T_2>(values: Iterable<T_2 | PromiseLike<T_2>>): Promise<Awaited<T_2>>;
21
+ race<T_3 extends [] | readonly unknown[]>(values: T_3): Promise<Awaited<T_3[number]>>;
22
+ readonly prototype: Promise<any>;
23
+ reject<T_4 = never>(reason?: any): Promise<T_4>;
24
+ resolve(): Promise<void>;
25
+ resolve<T_5>(value: T_5): Promise<Awaited<T_5>>;
26
+ resolve<T_6>(value: T_6 | PromiseLike<T_6>): Promise<Awaited<T_6>>;
27
+ allSettled<T_7 extends [] | readonly unknown[]>(values: T_7): Promise<{ -readonly [P_1 in keyof T_7]: PromiseSettledResult<Awaited<T_7[P_1]>>; }>;
28
+ allSettled<T_8>(values: Iterable<T_8 | PromiseLike<T_8>>): Promise<PromiseSettledResult<Awaited<T_8>>[]>;
29
+ any<T_9 extends [] | readonly unknown[]>(values: T_9): Promise<Awaited<T_9[number]>>;
30
+ any<T_10>(values: Iterable<T_10 | PromiseLike<T_10>>): Promise<Awaited<T_10>>;
31
+ readonly [Symbol.species]: PromiseConstructor;
32
+ };
33
+ inputSchema: {
34
+ id: string;
35
+ };
36
+ };
37
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ // Example structure of the API dict, convert this to class with swapper instance & functions to init the SDK, run sync with _syncSwaps()
3
+ const apiFunctionDict = {
4
+ createSwap: {
5
+ type: "POST",
6
+ callback: (requestBody, queryParams) => {
7
+ // ...
8
+ },
9
+ inputSchema: {
10
+ inputToken: {
11
+ type: "string",
12
+ description: "Input token ticker or address"
13
+ },
14
+ outputToken: "string",
15
+ amount: "string",
16
+ // ...
17
+ }
18
+ },
19
+ status: {
20
+ type: "GET",
21
+ callback: (requestBody, queryParams) => Promise,
22
+ inputSchema: {
23
+ id: "string"
24
+ }
25
+ }
26
+ };
27
+ // Example boilerplate
28
+ for (let key in apiFunctionDict) {
29
+ // app.post("/"+key, (req, res) => apiFunctionDict[key].callback(req.body, req.query).then(response => res.json(response)));
30
+ }
@@ -0,0 +1,393 @@
1
+ import { SwapExecutionStep } from "../types/SwapExecutionStep";
2
+ import { SerializedAction } from "./SerializedAction";
3
+ import { SwapExecutionAction } from "../types/SwapExecutionAction";
4
+ import { ApiAmount, ApiLNURL, ApiToken } from "./ApiTypes";
5
+ import { LNURLDecodedSuccessAction } from "../types/lnurl/LNURLPay";
6
+ /**
7
+ * Base serialized swap data returned by API endpoints that expose swap details.
8
+ *
9
+ * @category API
10
+ */
11
+ export type SwapOutputBase = {
12
+ /** Unique identifier of the swap. */
13
+ swapId: string;
14
+ /** Swap type name, for example `FROM_BTC`, `TO_BTCLN`, or `FROM_BTCLN`. */
15
+ swapType: string;
16
+ /** Current swap state information. This varies for every swap type */
17
+ state: {
18
+ /** Numeric state representation of the state. */
19
+ number: number;
20
+ /** Human-readable state name. */
21
+ name: string;
22
+ /** Human-readable description of the current state. */
23
+ description: string;
24
+ };
25
+ /** Quote data captured when the swap was created. */
26
+ quote: {
27
+ /** Input source amount that will be paid by the user (including fees, but excluding source network fees). */
28
+ inputAmount: ApiAmount;
29
+ /** Output destination amount that will be paid out to the user. */
30
+ outputAmount: ApiAmount;
31
+ /** Fee breakdown included in the quote. */
32
+ fees: {
33
+ /** Swap service fee (charged in source token). */
34
+ swap: ApiAmount;
35
+ /** Swap fee to cover the transaction network fees on the destination side (charged in source token). */
36
+ networkOutput?: ApiAmount;
37
+ };
38
+ /** Quote expiration timestamp in milliseconds since Unix epoch. */
39
+ expiry: number;
40
+ /** Output address of the swap, the destination tokens will be sent here. */
41
+ outputAddress: string;
42
+ };
43
+ /** Swap creation timestamp in milliseconds since Unix epoch. */
44
+ createdAt: number;
45
+ /** Swap execution steps. */
46
+ steps: SwapExecutionStep[];
47
+ /** LNURL metadata attached to Lightning-based swaps when applicable. */
48
+ lnurl?: {
49
+ /** LNURL-withdraw link for Lightning to smart-chain flows. */
50
+ withdraw?: string;
51
+ /** LNURL-pay link for smart-chain to Lightning flows. */
52
+ pay?: string;
53
+ /** LNURL success action returned after a successful payment via LNURL-pay link, if specified in the LNURL. */
54
+ successAction?: LNURLDecodedSuccessAction;
55
+ };
56
+ };
57
+ /**
58
+ * Input for creating a new swap
59
+ *
60
+ * @category API
61
+ */
62
+ export type CreateSwapInput = {
63
+ /** Input source token identifier, always in the format of <network>-<tiker>, e.g. `BITCOIN-BTC`, `LIGHTNING-BTC`, or `STARKNET-STRK`. */
64
+ srcToken: string;
65
+ /** Output destination token identifier, always in the format of <network>-<tiker>, e.g. `BITCOIN-BTC`, `LIGHTNING-BTC`, or `STARKNET-STRK`. */
66
+ dstToken: string;
67
+ /** Swap amount in base units */
68
+ amount: bigint;
69
+ /** Whether the provided amount represents the exact input or exact output side of the quote. */
70
+ amountType: "EXACT_IN" | "EXACT_OUT";
71
+ /** Source address for flows that require it, mainly smart-chain to Bitcoin or Lightning swaps. */
72
+ srcAddress?: string;
73
+ /** Destination address, invoice, or recipient identifier for the swap output. */
74
+ dstAddress: string;
75
+ /**
76
+ * Only for smart chain to Lighting/Bitcoin swaps.
77
+ *
78
+ * Optional gas-drop amount (additional native token) to receive on the destination smart chain, in base units.
79
+ */
80
+ gasAmount?: bigint;
81
+ /**
82
+ * Only for Lightning to smart chain swaps.
83
+ *
84
+ * Optional custom swap payment hash encoded as a hexadecimal string, for when you want to generate the preimage
85
+ * and payment hash pair outside the API. When used, you need to provide the `secret` argument to the `getSwapStatus`
86
+ * endpoint when the swap HTLC is ready to be claimed (indicated by the `requiresSecretReveal` param in the
87
+ * `getSwapStatus` response)
88
+ */
89
+ paymentHash?: string;
90
+ /**
91
+ * Only for Lightning to smart chain swaps.
92
+ *
93
+ * Optional description to add to the generated Lightning network BOLT11 invoice.
94
+ */
95
+ lightningInvoiceDescription?: string;
96
+ /**
97
+ * Only for Lightning to smart chain swaps.
98
+ *
99
+ * Optional description to add to the generated Lightning network BOLT11 invoice.
100
+ */
101
+ lightningInvoiceDescriptionHash?: string;
102
+ /**
103
+ * Only for smart chain to Lightning swaps.
104
+ *
105
+ * Optional override for the HTLC timeout in seconds (default is 5 days), longer timeouts allow more lightning
106
+ * network hops to be considered when routing the destination lightning network payment, but might lead to longer
107
+ * funds lockup in case of non-cooperative LP.
108
+ */
109
+ lightningPaymentHTLCTimeout?: number;
110
+ };
111
+ /**
112
+ * Output from create swap endpoint
113
+ *
114
+ * @category API
115
+ */
116
+ export type CreateSwapOutput = SwapOutputBase;
117
+ /**
118
+ * Input for getting swap status
119
+ *
120
+ * @category API
121
+ */
122
+ export type GetSwapStatusInput = {
123
+ /** Unique identifier of the swap to query. */
124
+ swapId: string;
125
+ /**
126
+ * Swap secret pre-image revealed after the destination chain HTLC is created for Lightning to smart chain swaps,
127
+ * encoded as a hexadecimal string.
128
+ */
129
+ secret?: string;
130
+ /**
131
+ * For Bitcoin to smart chain swaps.
132
+ *
133
+ * Bitcoin address used to request a pre-funded PSBT with populated input UTXOs ready for signing and execution
134
+ */
135
+ bitcoinAddress?: string;
136
+ /**
137
+ * For Bitcoin to smart chain swaps.
138
+ *
139
+ * Bitcoin public key used together with `bitcoinAddress` to request a pre-funded PSBT with populated input UTXOs
140
+ * ready for signing and execution
141
+ */
142
+ bitcoinPublicKey?: string;
143
+ /**
144
+ * For Bitcoin to smart chain swaps.
145
+ *
146
+ * Bitcoin fee rate override used when building a pre-funded PSBT, otherwise the current economical fee rate is used.
147
+ */
148
+ bitcoinFeeRate?: number;
149
+ /** Alternative smart-chain signer to use for claim, refund, or manual settlement transactions. */
150
+ signer?: string;
151
+ };
152
+ /**
153
+ * Output from swap status getter
154
+ *
155
+ * @category API
156
+ */
157
+ export type ListSwapOutput = SwapOutputBase & {
158
+ /** Whether the swap reached a terminal state. */
159
+ isFinished: boolean;
160
+ /** Whether the swap finished successfully. */
161
+ isSuccess: boolean;
162
+ /** Whether the swap finished in a failed state. */
163
+ isFailed: boolean;
164
+ /** Whether the quote expired before completion. */
165
+ isExpired: boolean;
166
+ };
167
+ /**
168
+ * Output from swap status getter
169
+ *
170
+ * @category API
171
+ */
172
+ export type GetSwapStatusOutput = ListSwapOutput & {
173
+ /** Current actionable instruction for the client, or `null` when no action is required. */
174
+ currentAction: SerializedAction<SwapExecutionAction> | null;
175
+ /**
176
+ * For Lightning to smart chain swaps.
177
+ *
178
+ * Whether the client should provide the Lightning secret pre-image to continue execution. Returned when the HTLC
179
+ * on the destination chain is created and is ready to be claimed by the user.
180
+ */
181
+ requiresSecretReveal?: boolean;
182
+ /**
183
+ * Escrow-specific data for escrow contract based swaps (all except the non-legacy Bitcoin to smart chain swaps)
184
+ */
185
+ escrow?: {
186
+ /** Serialized escrow data. */
187
+ data: any;
188
+ /** A transaction which created the escrow, if the escrow is already created on-chain. */
189
+ initTxId?: string;
190
+ };
191
+ };
192
+ /**
193
+ * Input for listing swaps
194
+ *
195
+ * @category API
196
+ */
197
+ export type ListSwapsInput = {
198
+ /** Smart-chain signer address used to filter swaps. */
199
+ signer: string;
200
+ /** Optional smart-chain identifier used to narrow the result set, e.g. SOLANA, STARKNET, CITREA */
201
+ chainId?: string;
202
+ };
203
+ /**
204
+ * Output from swap list endpoint
205
+ *
206
+ * @category API
207
+ */
208
+ export type ListSwapsOutput = ListSwapOutput[];
209
+ /**
210
+ * Input for listing pending swaps
211
+ *
212
+ * @category API
213
+ */
214
+ export type ListPendingSwapsInput = ListSwapsInput;
215
+ /**
216
+ * Output from pending swap list endpoint
217
+ *
218
+ * @category API
219
+ */
220
+ export type ListPendingSwapsOutput = ListSwapsOutput;
221
+ /**
222
+ * Input for listing supported tokens
223
+ *
224
+ * @category API
225
+ */
226
+ export type GetSupportedTokensInput = {
227
+ /** Whether to list source-side (`INPUT`) or destination-side (`OUTPUT`) tokens. */
228
+ side: "INPUT" | "OUTPUT";
229
+ };
230
+ /**
231
+ * Output from supported token list endpoint
232
+ *
233
+ * @category API
234
+ */
235
+ export type GetSupportedTokensOutput = ApiToken[];
236
+ /**
237
+ * Input for listing swap counter-tokens for a given token
238
+ *
239
+ * @category API
240
+ */
241
+ export type GetSwapCounterTokensInput = {
242
+ /** Token identifier to find compatible counter-tokens for, e.g. BITCOIN-BTC, LIGHTNING-BTC or STARKNET-STRK */
243
+ token: string;
244
+ /** Whether the provided token should be treated as the input or output side of the swap. */
245
+ side: "INPUT" | "OUTPUT";
246
+ };
247
+ /**
248
+ * Output from swap counter-token list endpoint
249
+ *
250
+ * @category API
251
+ */
252
+ export type GetSwapCounterTokensOutput = ApiToken[];
253
+ /**
254
+ * Input for querying swap limits between two tokens
255
+ *
256
+ * @category API
257
+ */
258
+ export type GetSwapLimitsInput = {
259
+ /** Source token identifier, e.g. BITCOIN-BTC, LIGHTNING-BTC or STARKNET-STRK */
260
+ srcToken: string;
261
+ /** Destination token identifier, e.g. BITCOIN-BTC, LIGHTNING-BTC or STARKNET-STRK */
262
+ dstToken: string;
263
+ };
264
+ /**
265
+ * Output from swap limits endpoint
266
+ *
267
+ * @category API
268
+ */
269
+ export type GetSwapLimitsOutput = {
270
+ /** Limits expressed on the input side of the swap. */
271
+ input: {
272
+ /** Minimum supported input amount. */
273
+ min: ApiAmount;
274
+ /** Maximum supported input amount when bounded. */
275
+ max?: ApiAmount;
276
+ };
277
+ /** Limits expressed on the output side of the swap. */
278
+ output: {
279
+ /** Minimum supported output amount. */
280
+ min: ApiAmount;
281
+ /** Maximum supported output amount when bounded. */
282
+ max?: ApiAmount;
283
+ };
284
+ };
285
+ /**
286
+ * Input for parsing an address-like string supported by the SDK
287
+ *
288
+ * @category API
289
+ */
290
+ export type ParseAddressInput = {
291
+ /** Address-like string to parse, such as a wallet address, lightning invoice, LNURL, or URI. */
292
+ address: string;
293
+ };
294
+ /**
295
+ * Output from address parser endpoint
296
+ *
297
+ * @category API
298
+ */
299
+ export type ParseAddressOutput = {
300
+ /** Canonical parsed address or recipient identifier. */
301
+ address: string;
302
+ /** Parsed address type, e.g. BITCOIN, LIGHTNING, SOLANA, STARKNET or CITREA */
303
+ type: string;
304
+ /** Parsed LNURL metadata when the input resolves to LNURL content. */
305
+ lnurl?: ApiLNURL;
306
+ /** Minimum supported amount advertised by the parsed target, when available. */
307
+ min?: ApiAmount;
308
+ /** Maximum supported amount advertised by the parsed target, when available. */
309
+ max?: ApiAmount;
310
+ /** Amount embedded directly in the parsed target, when present. */
311
+ amount?: ApiAmount;
312
+ };
313
+ /**
314
+ * Input for querying spendable wallet balance
315
+ *
316
+ * @category API
317
+ */
318
+ export type GetSpendableBalanceInput = {
319
+ /** Wallet address to inspect. */
320
+ wallet: string;
321
+ /** Token identifier to get the balance for, e.g. BITCOIN-BTC, SOLANA-SOL or STARKNET-STRK */
322
+ token: string;
323
+ /**
324
+ * Target smart chain identifier when estimating spendable bitcoin balance. Automatically adjusts based on
325
+ * available swaps between Bitcoin and the provided chain
326
+ */
327
+ targetChain?: string;
328
+ /**
329
+ * Whether gas-drop transaction size overhead should be included for Bitcoin to smart chain swaps.
330
+ */
331
+ gasDrop?: boolean;
332
+ /**
333
+ * Manual fee-rate override used for spendable balance estimation.
334
+ */
335
+ feeRate?: string;
336
+ /** Minimum Bitcoin fee rate to enforce during estimation. */
337
+ minBitcoinFeeRate?: number;
338
+ /**
339
+ * Multiplier applied to fetched economical network fee.
340
+ */
341
+ feeMultiplier?: number;
342
+ };
343
+ /**
344
+ * Output from spendable balance endpoint
345
+ *
346
+ * @category API
347
+ */
348
+ export type GetSpendableBalanceOutput = {
349
+ /** Spendable balance after deducting estimated swap execution costs. */
350
+ balance: ApiAmount;
351
+ /** Fee rate used during estimation. Only when estimating BTC balances on Bitcoin */
352
+ feeRate?: number;
353
+ };
354
+ /**
355
+ * Input for submitting signed transactions
356
+ *
357
+ * @category API
358
+ */
359
+ export type SubmitTransactionInput = {
360
+ /** Unique identifier of the swap the transactions belong to. */
361
+ swapId: string;
362
+ /** Serialized signed transactions to submit in execution order. */
363
+ signedTxs: string[];
364
+ };
365
+ /**
366
+ * Output from submitting transactions
367
+ *
368
+ * @category API
369
+ */
370
+ export type SubmitTransactionOutput = {
371
+ /** Transaction hashes returned after successful submission. */
372
+ txHashes: string[];
373
+ };
374
+ /**
375
+ * Input for triggering an LNURL-withdraw based settlement for Lightning -> Smart chain swaps
376
+ *
377
+ * @category API
378
+ */
379
+ export type SettleWithLnurlInput = {
380
+ /** Unique identifier of the Lightning to smart-chain swap to settle. */
381
+ swapId: string;
382
+ /** LNURL-withdraw link to use when the swap was not already created with one. */
383
+ lnurlWithdraw?: string;
384
+ };
385
+ /**
386
+ * Output for triggering an LNURL-withdraw based settlement for Lightning -> Smart chain swaps
387
+ *
388
+ * @category API
389
+ */
390
+ export type SettleWithLnurlOutput = {
391
+ /** Payment hash of the Lightning payment paid by the LNURL-withdraw link, encoded as a hexadecimal string. */
392
+ paymentHash: string;
393
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { InputSchema } from "./ApiTypes";
2
+ /**
3
+ * Parses raw input values according to the endpoint schema.
4
+ *
5
+ * This accepts untyped transport input such as HTTP query params, JSON request bodies,
6
+ * or CLI arguments and returns the normalized callback input type.
7
+ *
8
+ * @category API
9
+ */
10
+ export declare function parseApiInput<TInput>(inputSchema: InputSchema<TInput>, rawInput: unknown): TInput;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseApiInput = void 0;
4
+ // Errors
5
+ function invalidInput(path, expected, value) {
6
+ const actualType = value == null ? String(value) : Array.isArray(value) ? "array" : typeof (value);
7
+ return new Error(`Invalid input "${path}", expected ${expected}, got ${actualType}`);
8
+ }
9
+ function missingInput(path) {
10
+ return new Error(`Missing required input "${path}"`);
11
+ }
12
+ function invalidAllowedValue(path, allowedValues, value) {
13
+ return new Error(`Invalid input "${path}", expected one of: ${allowedValues.map(val => val.toString()).join(", ")}, got ${value.toString()}`);
14
+ }
15
+ // Parsers
16
+ function parseNumber(path, value) {
17
+ let result;
18
+ if (typeof (value) === "number") {
19
+ result = value;
20
+ }
21
+ else if (typeof (value) === "string") {
22
+ const trimmedValue = value.trim();
23
+ if (trimmedValue === "")
24
+ throw invalidInput(path, "finite number", value);
25
+ result = Number(trimmedValue);
26
+ }
27
+ else
28
+ throw invalidInput(path, "finite number", value);
29
+ if (!Number.isFinite(result))
30
+ throw invalidInput(path, "finite number", value);
31
+ return result;
32
+ }
33
+ function parseBigInt(path, value) {
34
+ if (typeof (value) === "bigint")
35
+ return value;
36
+ if (typeof (value) === "number") {
37
+ if (!Number.isSafeInteger(value))
38
+ throw invalidInput(path, "safe integer", value);
39
+ return BigInt(value);
40
+ }
41
+ if (typeof (value) === "string") {
42
+ const trimmedValue = value.trim();
43
+ if (!/^[+-]?\d+$/.test(trimmedValue))
44
+ throw invalidInput(path, "integer", value);
45
+ return BigInt(trimmedValue);
46
+ }
47
+ throw invalidInput(path, "integer", value);
48
+ }
49
+ function parseBoolean(path, value) {
50
+ Boolean(value);
51
+ if (typeof (value) === "boolean")
52
+ return value;
53
+ if (value === "true")
54
+ return true;
55
+ if (value === "false")
56
+ return false;
57
+ throw invalidInput(path, "boolean", value);
58
+ }
59
+ // Object type check
60
+ function isObject(value) {
61
+ return value != null && typeof (value) === "object" && !Array.isArray(value);
62
+ }
63
+ // Allowed values for enums
64
+ function applyAllowedValues(path, value, allowedValues) {
65
+ if (allowedValues != null && !allowedValues.includes(value)) {
66
+ throw invalidAllowedValue(path, allowedValues, value);
67
+ }
68
+ return value;
69
+ }
70
+ function parseField(field, value, path) {
71
+ switch (field.type) {
72
+ case "string": {
73
+ if (typeof (value) !== "string")
74
+ throw invalidInput(path, "string", value);
75
+ return applyAllowedValues(path, value, field.allowedValues);
76
+ }
77
+ case "number": {
78
+ const parsedValue = parseNumber(path, value);
79
+ return applyAllowedValues(path, parsedValue, field.allowedValues);
80
+ }
81
+ case "bigint": {
82
+ const parsedValue = parseBigInt(path, value);
83
+ return applyAllowedValues(path, parsedValue, field.allowedValues);
84
+ }
85
+ case "boolean":
86
+ return parseBoolean(path, value);
87
+ case "array": {
88
+ if (!Array.isArray(value))
89
+ throw invalidInput(path, "array", value);
90
+ if (field.items == null)
91
+ return [...value];
92
+ return value.map((item, index) => parseField(field.items, item, `${path}[${index}]`));
93
+ }
94
+ case "object": {
95
+ if (!isObject(value))
96
+ throw invalidInput(path, "object", value);
97
+ if (field.properties == null)
98
+ return { ...value };
99
+ return _parseApiInput(field.properties, value, path);
100
+ }
101
+ default:
102
+ throw new Error(`Unsupported input schema type for "${path}": ${field.type}`);
103
+ }
104
+ }
105
+ function _parseApiInput(inputSchema, rawInput, parentPath = "") {
106
+ if (!isObject(rawInput)) {
107
+ throw invalidInput(parentPath || "input", "object", rawInput);
108
+ }
109
+ const parsedInput = {};
110
+ for (const key in inputSchema) {
111
+ const field = inputSchema[key];
112
+ const value = rawInput[key];
113
+ const path = parentPath === "" ? key : `${parentPath}.${key}`;
114
+ if (value == null) {
115
+ if (field.required)
116
+ throw missingInput(path);
117
+ continue;
118
+ }
119
+ parsedInput[key] = parseField(field, value, path);
120
+ }
121
+ return parsedInput;
122
+ }
123
+ /**
124
+ * Parses raw input values according to the endpoint schema.
125
+ *
126
+ * This accepts untyped transport input such as HTTP query params, JSON request bodies,
127
+ * or CLI arguments and returns the normalized callback input type.
128
+ *
129
+ * @category API
130
+ */
131
+ function parseApiInput(inputSchema, rawInput) {
132
+ return _parseApiInput(inputSchema, rawInput);
133
+ }
134
+ exports.parseApiInput = parseApiInput;