stableflow-ai-sdk 1.0.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.
@@ -0,0 +1,549 @@
1
+ type ApiRequestOptions = {
2
+ readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
3
+ readonly url: string;
4
+ readonly path?: Record<string, any>;
5
+ readonly cookies?: Record<string, any>;
6
+ readonly headers?: Record<string, any>;
7
+ readonly query?: Record<string, any>;
8
+ readonly formData?: Record<string, any>;
9
+ readonly body?: any;
10
+ readonly mediaType?: string;
11
+ readonly responseHeader?: string;
12
+ readonly errors?: Record<number, string>;
13
+ };
14
+
15
+ type ApiResult = {
16
+ readonly url: string;
17
+ readonly ok: boolean;
18
+ readonly status: number;
19
+ readonly statusText: string;
20
+ readonly body: any;
21
+ };
22
+
23
+ declare class ApiError extends Error {
24
+ readonly url: string;
25
+ readonly status: number;
26
+ readonly statusText: string;
27
+ readonly body: any;
28
+ readonly request: ApiRequestOptions;
29
+ constructor(request: ApiRequestOptions, response: ApiResult, message: string);
30
+ }
31
+
32
+ declare class CancelError extends Error {
33
+ constructor(message: string);
34
+ get isCancelled(): boolean;
35
+ }
36
+ interface OnCancel {
37
+ readonly isResolved: boolean;
38
+ readonly isRejected: boolean;
39
+ readonly isCancelled: boolean;
40
+ (cancelHandler: () => void): void;
41
+ }
42
+ declare class CancelablePromise<T> implements Promise<T> {
43
+ #private;
44
+ constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void, onCancel: OnCancel) => void);
45
+ get [Symbol.toStringTag](): string;
46
+ then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
47
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
48
+ finally(onFinally?: (() => void) | null): Promise<T>;
49
+ cancel(): void;
50
+ get isCancelled(): boolean;
51
+ }
52
+
53
+ type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
54
+ type Headers = Record<string, string>;
55
+ type OpenAPIConfig = {
56
+ BASE: string;
57
+ VERSION: string;
58
+ WITH_CREDENTIALS: boolean;
59
+ CREDENTIALS: 'include' | 'omit' | 'same-origin';
60
+ TOKEN?: string | Resolver<string> | undefined;
61
+ USERNAME?: string | Resolver<string> | undefined;
62
+ PASSWORD?: string | Resolver<string> | undefined;
63
+ HEADERS?: Headers | Resolver<Headers> | undefined;
64
+ ENCODE_PATH?: ((path: string) => string) | undefined;
65
+ };
66
+ declare const OpenAPI: OpenAPIConfig;
67
+
68
+ type AppFee = {
69
+ /**
70
+ * Account ID within Intents to which this fee will be transferred
71
+ */
72
+ recipient: string;
73
+ /**
74
+ * Fee for this recipient as part of amountIn in basis points (1/100th of a percent), e.g. 100 for 1% fee
75
+ */
76
+ fee: number;
77
+ };
78
+
79
+ type BadRequestResponse = {
80
+ message: string;
81
+ };
82
+
83
+ type Quote = {
84
+ /**
85
+ * The deposit address on the chain of `originAsset` when `depositType` is `ORIGIN_CHAIN`.
86
+ *
87
+ * The deposit address inside NEAR Intents (the verifier smart contract) when `depositType` is `INTENTS`.
88
+ */
89
+ depositAddress?: string;
90
+ /**
91
+ * Some of the deposit addresses **REQUIRE** to also include the `memo` for the deposit to be processed
92
+ */
93
+ depositMemo?: string;
94
+ /**
95
+ * Amount of the origin asset
96
+ */
97
+ amountIn: string;
98
+ /**
99
+ * Amount of the origin asset in readable format
100
+ */
101
+ amountInFormatted: string;
102
+ /**
103
+ * Amount of the origin assets equivalent in USD
104
+ */
105
+ amountInUsd: string;
106
+ /**
107
+ * Minimum amount of the origin asset that will be used for the swap
108
+ */
109
+ minAmountIn: string;
110
+ /**
111
+ * Amount of the destination asset
112
+ */
113
+ amountOut: string;
114
+ /**
115
+ * Amount of the destination asset in readable format
116
+ */
117
+ amountOutFormatted: string;
118
+ /**
119
+ * Amount of the destination asset equivalent in USD
120
+ */
121
+ amountOutUsd: string;
122
+ /**
123
+ * Minimum output amount after slippage is applied
124
+ */
125
+ minAmountOut: string;
126
+ /**
127
+ * Time when the deposit address becomes inactive and funds may be lost
128
+ */
129
+ deadline?: string;
130
+ /**
131
+ * Time when the deposit address becomes cold, causing swap processing to take longer
132
+ */
133
+ timeWhenInactive?: string;
134
+ /**
135
+ * Estimated time in seconds for the swap to be executed after the deposit transaction is confirmed
136
+ */
137
+ timeEstimate: number;
138
+ /**
139
+ * EVM address of a transfer recipient in a virtual chain
140
+ */
141
+ virtualChainRecipient?: string;
142
+ /**
143
+ * EVM address of a refund recipient in a virtual chain
144
+ */
145
+ virtualChainRefundRecipient?: string;
146
+ };
147
+
148
+ type QuoteRequest = {
149
+ /**
150
+ * Flag indicating whether this is a dry run request.
151
+ * If `true`, the response will **NOT** contain the following fields:
152
+ * - `depositAddress`
153
+ * - `timeWhenInactive`
154
+ * - `deadline`
155
+ */
156
+ dry: boolean;
157
+ /**
158
+ * What deposit address mode you will get in the response, most chain supports only `SIMPLE` and some(for example `stellar`) only `MEMO`:
159
+ * - `SIMPLE` - usual deposit with only deposit address.
160
+ * - `MEMO` - some chains will **REQUIRE** the `memo` together with `depositAddress` for swap to work.
161
+ */
162
+ depositMode?: QuoteRequest.depositMode;
163
+ /**
164
+ * How to interpret `amount` when performing the swap:
165
+ * - `EXACT_INPUT` - requests the output amount for an exact input.
166
+ * - `EXACT_OUTPUT` - requests the input amount for an exact output. The `refundTo` address always receives any excess tokens after the swap is complete.
167
+ * - `FLEX_INPUT` - a flexible input amount that allows for partial deposits and variable amounts.
168
+ */
169
+ swapType: QuoteRequest.swapType;
170
+ /**
171
+ * Slippage tolerance for the swap. This value is in basis points (1/100th of a percent), e.g. 100 for 1% slippage.
172
+ */
173
+ slippageTolerance: number;
174
+ /**
175
+ * ID of the origin asset.
176
+ */
177
+ originAsset: string;
178
+ /**
179
+ * Type of deposit address:
180
+ * - `ORIGIN_CHAIN` - deposit address on the origin chain.
181
+ * - `INTENTS` - the account ID within NEAR Intents to which you should transfer assets.
182
+ */
183
+ depositType: QuoteRequest.depositType;
184
+ /**
185
+ * ID of the destination asset.
186
+ */
187
+ destinationAsset: string;
188
+ /**
189
+ * Amount to swap as the base amount. It is interpreted as the input or output amount based on the `swapType` flag and is specified in the smallest unit of the currency (e.g., wei for ETH).
190
+ */
191
+ amount: string;
192
+ /**
193
+ * Address used for refunds.
194
+ */
195
+ refundTo: string;
196
+ /**
197
+ * Type of refund address:
198
+ * - `ORIGIN_CHAIN` - assets are refunded to the `refundTo` address on the origin chain.
199
+ * - `INTENTS` - assets are refunded to the `refundTo` Intents account.
200
+ */
201
+ refundType: QuoteRequest.refundType;
202
+ /**
203
+ * Recipient address. The format must match `recipientType`.
204
+ */
205
+ recipient: string;
206
+ /**
207
+ * EVM address of a transfer recipient in a virtual chain
208
+ */
209
+ virtualChainRecipient?: string;
210
+ /**
211
+ * EVM address of a refund recipient in a virtual chain
212
+ */
213
+ virtualChainRefundRecipient?: string;
214
+ /**
215
+ * Type of recipient address:
216
+ * - `DESTINATION_CHAIN` - assets are transferred to the chain of `destinationAsset`.
217
+ * - `INTENTS` - assets are transferred to an account inside Intents
218
+ */
219
+ recipientType: QuoteRequest.recipientType;
220
+ /**
221
+ * Timestamp in ISO format that identifies when the user refund begins if the swap isn't completed by then. It must exceed the time required for the deposit transaction to be mined. For example, Bitcoin may require around one hour depending on the fees paid.
222
+ */
223
+ deadline: string;
224
+ /**
225
+ * Referral identifier (lowercase only). It will be reflected in the on-chain data and displayed on public analytics platforms.
226
+ */
227
+ referral?: string;
228
+ /**
229
+ * Time in milliseconds the user is willing to wait for a quote from the relay.
230
+ */
231
+ quoteWaitingTimeMs?: number;
232
+ /**
233
+ * List of recipients and their fees
234
+ */
235
+ appFees?: Array<AppFee>;
236
+ };
237
+ declare namespace QuoteRequest {
238
+ /**
239
+ * What deposit address mode you will get in the response, most chain supports only `SIMPLE` and some(for example `stellar`) only `MEMO`:
240
+ * - `SIMPLE` - usual deposit with only deposit address.
241
+ * - `MEMO` - some chains will **REQUIRE** the `memo` together with `depositAddress` for swap to work.
242
+ */
243
+ enum depositMode {
244
+ SIMPLE = "SIMPLE",
245
+ MEMO = "MEMO"
246
+ }
247
+ /**
248
+ * How to interpret `amount` when performing the swap:
249
+ * - `EXACT_INPUT` - requests the output amount for an exact input.
250
+ * - `EXACT_OUTPUT` - requests the input amount for an exact output. The `refundTo` address always receives any excess tokens after the swap is complete.
251
+ * - `FLEX_INPUT` - a flexible input amount that allows for partial deposits and variable amounts.
252
+ */
253
+ enum swapType {
254
+ EXACT_INPUT = "EXACT_INPUT",
255
+ EXACT_OUTPUT = "EXACT_OUTPUT",
256
+ FLEX_INPUT = "FLEX_INPUT"
257
+ }
258
+ /**
259
+ * Type of deposit address:
260
+ * - `ORIGIN_CHAIN` - deposit address on the origin chain.
261
+ * - `INTENTS` - the account ID within NEAR Intents to which you should transfer assets.
262
+ */
263
+ enum depositType {
264
+ ORIGIN_CHAIN = "ORIGIN_CHAIN",
265
+ INTENTS = "INTENTS"
266
+ }
267
+ /**
268
+ * Type of refund address:
269
+ * - `ORIGIN_CHAIN` - assets are refunded to the `refundTo` address on the origin chain.
270
+ * - `INTENTS` - assets are refunded to the `refundTo` Intents account.
271
+ */
272
+ enum refundType {
273
+ ORIGIN_CHAIN = "ORIGIN_CHAIN",
274
+ INTENTS = "INTENTS"
275
+ }
276
+ /**
277
+ * Type of recipient address:
278
+ * - `DESTINATION_CHAIN` - assets are transferred to the chain of `destinationAsset`.
279
+ * - `INTENTS` - assets are transferred to an account inside Intents
280
+ */
281
+ enum recipientType {
282
+ DESTINATION_CHAIN = "DESTINATION_CHAIN",
283
+ INTENTS = "INTENTS"
284
+ }
285
+ }
286
+
287
+ type QuoteResponse = {
288
+ /**
289
+ * Timestamp in ISO format that was used to derive the deposit address
290
+ */
291
+ timestamp: string;
292
+ /**
293
+ * Signature of the StableFlow service confirming the quote for the specific deposit address. Must be saved on the client side (along with the whole quote) in order to resolve any disputes or mistakes.
294
+ */
295
+ signature: string;
296
+ /**
297
+ * User request
298
+ */
299
+ quoteRequest: QuoteRequest;
300
+ /**
301
+ * Response containing the deposit address for sending the `amount` of `originAsset` and the expected output amount.
302
+ */
303
+ quote: Quote;
304
+ };
305
+
306
+ type TransactionDetails = {
307
+ /**
308
+ * Transaction hash
309
+ */
310
+ hash: string;
311
+ /**
312
+ * Explorer URL for the transaction
313
+ */
314
+ explorerUrl: string;
315
+ };
316
+
317
+ type SwapDetails = {
318
+ /**
319
+ * All intent hashes that took part in this swap
320
+ */
321
+ intentHashes: Array<string>;
322
+ /**
323
+ * All NEAR transactions executed for this swap
324
+ */
325
+ nearTxHashes: Array<string>;
326
+ /**
327
+ * Exact amount of `originToken` after the trade was settled
328
+ */
329
+ amountIn?: string;
330
+ /**
331
+ * Exact amount of `originToken` in readable format after the trade was settled
332
+ */
333
+ amountInFormatted?: string;
334
+ /**
335
+ * Exact amount of `originToken` equivalent in USD
336
+ */
337
+ amountInUsd?: string;
338
+ /**
339
+ * Exact amount of `destinationToken` after the trade was settled
340
+ */
341
+ amountOut?: string;
342
+ /**
343
+ * Exact amount of `destinationToken` in readable format after the trade was settled
344
+ */
345
+ amountOutFormatted?: string;
346
+ /**
347
+ * Exact amount of `destinationToken` equivalent in USD
348
+ */
349
+ amountOutUsd?: string;
350
+ /**
351
+ * Actual slippage
352
+ */
353
+ slippage?: number;
354
+ /**
355
+ * Hashes and explorer URLs for all transactions on the origin chain
356
+ */
357
+ originChainTxHashes: Array<TransactionDetails>;
358
+ /**
359
+ * Hashes and explorer URLs for all transactions on the destination chain
360
+ */
361
+ destinationChainTxHashes: Array<TransactionDetails>;
362
+ /**
363
+ * Amount of `originAsset` transferred to `refundTo`
364
+ */
365
+ refundedAmount?: string;
366
+ /**
367
+ * Refunded amount in readable format
368
+ */
369
+ refundedAmountFormatted?: string;
370
+ /**
371
+ * Refunded amount equivalent in USD
372
+ */
373
+ refundedAmountUsd?: string;
374
+ };
375
+
376
+ type GetExecutionStatusResponse = {
377
+ /**
378
+ * Quote response from the original request
379
+ */
380
+ quoteResponse: QuoteResponse;
381
+ status: GetExecutionStatusResponse.status;
382
+ /**
383
+ * Last time the state was updated
384
+ */
385
+ updatedAt: string;
386
+ /**
387
+ * Details of actual swaps and withdrawals
388
+ */
389
+ swapDetails: SwapDetails;
390
+ };
391
+ declare namespace GetExecutionStatusResponse {
392
+ enum status {
393
+ KNOWN_DEPOSIT_TX = "KNOWN_DEPOSIT_TX",
394
+ PENDING_DEPOSIT = "PENDING_DEPOSIT",
395
+ INCOMPLETE_DEPOSIT = "INCOMPLETE_DEPOSIT",
396
+ PROCESSING = "PROCESSING",
397
+ SUCCESS = "SUCCESS",
398
+ REFUNDED = "REFUNDED",
399
+ FAILED = "FAILED"
400
+ }
401
+ }
402
+
403
+ type SubmitDepositTxRequest = {
404
+ /**
405
+ * Transaction hash of your deposit
406
+ */
407
+ txHash: string;
408
+ /**
409
+ * Deposit address for the quote
410
+ */
411
+ depositAddress: string;
412
+ };
413
+
414
+ type SubmitDepositTxResponse = {
415
+ /**
416
+ * Quote response from the original request
417
+ */
418
+ quoteResponse: QuoteResponse;
419
+ status: SubmitDepositTxResponse.status;
420
+ /**
421
+ * Last time the state was updated
422
+ */
423
+ updatedAt: string;
424
+ /**
425
+ * Details of actual swaps and withdrawals
426
+ */
427
+ swapDetails: SwapDetails;
428
+ };
429
+ declare namespace SubmitDepositTxResponse {
430
+ enum status {
431
+ KNOWN_DEPOSIT_TX = "KNOWN_DEPOSIT_TX",
432
+ PENDING_DEPOSIT = "PENDING_DEPOSIT",
433
+ INCOMPLETE_DEPOSIT = "INCOMPLETE_DEPOSIT",
434
+ PROCESSING = "PROCESSING",
435
+ SUCCESS = "SUCCESS",
436
+ REFUNDED = "REFUNDED",
437
+ FAILED = "FAILED"
438
+ }
439
+ }
440
+
441
+ type TokenResponse = {
442
+ /**
443
+ * Unique asset identifier
444
+ */
445
+ assetId: string;
446
+ /**
447
+ * Number of decimals for the token
448
+ */
449
+ decimals: number;
450
+ /**
451
+ * Blockchain associated with the token
452
+ */
453
+ blockchain: TokenResponse.blockchain;
454
+ /**
455
+ * Token symbol (e.g. BTC, ETH)
456
+ */
457
+ symbol: string;
458
+ /**
459
+ * Current price of the token in USD
460
+ */
461
+ price: number;
462
+ /**
463
+ * Date when the token price was last updated
464
+ */
465
+ priceUpdatedAt: string;
466
+ /**
467
+ * Contract address of the token
468
+ */
469
+ contractAddress?: string;
470
+ };
471
+ declare namespace TokenResponse {
472
+ /**
473
+ * Blockchain associated with the token
474
+ */
475
+ enum blockchain {
476
+ NEAR = "near",
477
+ ETH = "eth",
478
+ BASE = "base",
479
+ ARB = "arb",
480
+ BTC = "btc",
481
+ SOL = "sol",
482
+ TON = "ton",
483
+ DOGE = "doge",
484
+ XRP = "xrp",
485
+ ZEC = "zec",
486
+ GNOSIS = "gnosis",
487
+ BERA = "bera",
488
+ BSC = "bsc",
489
+ POL = "pol",
490
+ TRON = "tron",
491
+ SUI = "sui",
492
+ OP = "op",
493
+ AVAX = "avax",
494
+ CARDANO = "cardano"
495
+ }
496
+ }
497
+
498
+ /**
499
+ * StableFlow AI Service
500
+ * Main service class for interacting with the StableFlow AI API
501
+ */
502
+ declare class SFA {
503
+ /**
504
+ * Get supported tokens
505
+ * Retrieves a list of tokens currently supported by the StableFlow AI API for asset swaps.
506
+ *
507
+ * Each token entry includes its blockchain, contract address (if available), price in USD, and other metadata such as symbol and decimals.
508
+ * @returns TokenResponse
509
+ * @throws ApiError
510
+ */
511
+ static getTokens(): CancelablePromise<Array<TokenResponse>>;
512
+ /**
513
+ * Request a swap quote
514
+ * Generates a swap quote based on input parameters such as the assets, amount, slippage tolerance, and recipient/refund information.
515
+ *
516
+ * Returns pricing details, estimated time, and a unique **deposit address** to which tokens must be transferred to initiate the swap.
517
+ *
518
+ * You can set the `dry` parameter to `true` to simulate the quote request **without generating a deposit address** or initiating the swap process. This is useful for previewing swap parameters or validating input data without committing to an actual swap.
519
+ *
520
+ * This endpoint is the first required step in the swap process.
521
+ * @param requestBody
522
+ * @returns QuoteResponse
523
+ * @throws ApiError
524
+ */
525
+ static getQuote(requestBody: QuoteRequest): CancelablePromise<QuoteResponse>;
526
+ /**
527
+ * Check swap execution status
528
+ * Retrieves the current status of a swap using the unique deposit address from the quote, if quote response included deposit memo, it is required as well.
529
+ *
530
+ * The response includes the state of the swap (e.g., pending, processing, success, refunded) and any associated swap and transaction details.
531
+ * @param depositAddress
532
+ * @param depositMemo
533
+ * @returns GetExecutionStatusResponse
534
+ * @throws ApiError
535
+ */
536
+ static getExecutionStatus(depositAddress: string, depositMemo?: string): CancelablePromise<GetExecutionStatusResponse>;
537
+ /**
538
+ * Submit deposit transaction hash
539
+ * Optionally notifies the StableFlow AI service that a deposit has been sent to the specified address, using the blockchain transaction hash.
540
+ *
541
+ * This step can speed up swap processing by allowing the system to preemptively verify the deposit.
542
+ * @param requestBody
543
+ * @returns SubmitDepositTxResponse
544
+ * @throws ApiError
545
+ */
546
+ static submitDepositTx(requestBody: SubmitDepositTxRequest): CancelablePromise<SubmitDepositTxResponse>;
547
+ }
548
+
549
+ export { ApiError, type AppFee, type BadRequestResponse, CancelError, CancelablePromise, GetExecutionStatusResponse, OpenAPI, type OpenAPIConfig, type Quote, QuoteRequest, type QuoteResponse, SFA, type SubmitDepositTxRequest, SubmitDepositTxResponse, type SwapDetails, TokenResponse, type TransactionDetails };