@axis-markets/client 0.4.0 → 0.7.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.
package/src/index.d.ts CHANGED
@@ -1,521 +1,1446 @@
1
- /** Trading order type - instructions to contract how to execute the trade */
2
- export enum OrderKind {
3
- Limit = 1,
4
- Fill = 2,
5
- FillOrKill = 3,
6
- }
7
-
8
- /** Trade direction instructions */
9
- export enum TradeDirection {
10
- Sell = 1,
11
- Buy = 2,
12
- }
13
-
14
- /** Order properties, stored on-chain */
15
- export interface Order {
16
- /** Amount left to sell/buy */
17
- amount: bigint;
18
- /** Buying token address */
19
- buying: string;
20
- /** expiration timestamp */
21
- expires: bigint;
22
- /** Unique order identifier */
23
- id: bigint;
24
- /** Order type */
25
- kind: OrderKind;
26
- /** Maker address */
27
- owner: string;
28
- /** Order price */
29
- price: bigint;
30
- /** Initial selling/buying amount */
31
- quote: bigint;
32
- /** Selling token address */
33
- selling: string;
34
- }
35
-
36
- /** Orderbook trade event */
37
- export interface TradeContractEvent {
38
- /** Bought tokens amount */
39
- bought: bigint;
40
- /** Bought asset address */
41
- buying: string;
42
- /** Unique trade id */
43
- id: bigint;
44
- /** Seller account address */
45
- maker: string;
46
- /** Order id */
47
- order: bigint;
48
- /** Sold asset address */
49
- selling: string;
50
- /** Sold tokens amount */
51
- sold: bigint;
52
- /** Trader account address */
53
- taker: string;
54
- }
55
-
56
- /** Orderbook swap event */
57
- export interface SwapContractEvent {
58
- /** Unique swap id (last trade id assigned while settling the swap legs) */
59
- id: bigint;
60
- /** Trader account address */
61
- trader: string;
62
- /** Sold asset address */
63
- selling: string;
64
- /** Bought asset address */
65
- buying: string;
66
- /** Amount of `selling` tokens sold */
67
- sold: bigint;
68
- /** Amount of `buying` tokens received */
69
- bought: bigint;
70
- }
71
-
72
- /** A trade step in a multi-market swap path. */
73
- export interface TradeStep {
74
- /** Asset to buy at this step */
75
- asset: string;
76
- /** Maker order IDs to match */
77
- orders: Array<bigint>;
78
- }
79
-
80
- /** Standard contract errors */
81
- export declare const ContractErrors: {
82
- 701: {message: "NotAuthorized"};
83
- 702: {message: "InsufficientBalance"};
84
- 703: {message: "OrderNotFound"};
85
- 704: {message: "Overflow"};
86
- 705: {message: "InvalidMatch"};
87
- 706: {message: "InvalidPrice"};
88
- }
89
-
90
- export interface ClientInitializationParams {
91
- /** Public key of the account that will interact with the contract */
92
- publicKey: string;
93
- /** Callback for signing transactions generated by the client */
94
- signTransaction: SignTransactionCallback;
95
- /** URL of the RPC server */
96
- rpcUrl: string;
97
- /** DEX contract ID */
98
- contractId: string;
99
- /** Network passphrase (Pubnet passphrase by default) */
100
- networkPassphrase?: string;
101
- /** Transaction fee (0.1 XLM by default) */
102
- fee?: string;
103
- }
104
-
105
- export type SignTransactionCallback = (
106
- tx: string,
107
- context: {network: string; networkPassphrase: string; accountToSign: string}
108
- ) => Promise<{signedTxXdr: string; signerAddress?: string}>;
109
-
110
- export interface TradeArguments {
111
- /** Trading order behavior */
112
- kind: OrderKind,
113
- /** Trader address */
114
- trader: string;
115
- /** Tokens amount */
116
- amount: bigint;
117
- /** Selling token address */
118
- selling: string;
119
- /** Buying token address */
120
- buying: string;
121
- /** Price a trader willing to accept */
122
- price: bigint;
123
- /** List of order IDs to match before creating the order on-chain */
124
- orders: Array<bigint>;
125
- }
126
-
127
- export interface SellTradeArguments extends TradeArguments {
128
- /** Amount of `selling` tokens to sell */
129
- amount: bigint;
130
- /** Price a trader willing to accept, minimum `buying` tokens per 1 `selling` */
131
- price: bigint;
132
- }
133
-
134
- export interface BuyTradeArguments extends TradeArguments {
135
- /** Amount of `buying` tokens to acquire */
136
- amount: bigint;
137
- /** Price a trader willing to accept, maximum `selling` tokens per 1 `buying` */
138
- price: bigint;
139
- }
140
-
141
- export interface SwapArguments {
142
- /** Trade direction: `Sell` or `Buy` */
143
- direction: TradeDirection,
144
- /** Trader address */
145
- trader: string,
146
- /** Token address sent by the trader */
147
- selling: string,
148
- /** Maximum amount of selling tokens to send */
149
- sellingAmount: bigint,
150
- /** Minimum amount of buying tokens to receive */
151
- buyingAmount: bigint,
152
- /** Ordered list of the trade route steps */
153
- path: Array<TradeStep>
154
- }
155
-
156
- export declare class AxisContractClient {
157
- constructor(params: ClientInitializationParams);
158
-
159
- /**
160
- * Retrieve last order id
161
- * @returns Last created order id
162
- */
163
- last(): Promise<bigint>;
164
-
165
- /**
166
- * Fetch existing order
167
- * @param id - ID of the order to fetch
168
- * @returns Order fetched from the storage
169
- */
170
- order(id: bigint): Promise<Order>;
171
-
172
- /**
173
- * Cancel existing order
174
- * @param ids - ID of the order to cancel
175
- * @param trader - Trader address
176
- */
177
- cancel(ids: Array<bigint>, trader: string): Promise<void>;
178
-
179
- /**
180
- * Fill existing orders using another matching order from the orderbook
181
- * @param trader - Trader address
182
- * @param takerOrderId - ID of the order that serves as a taker
183
- * @param orders - List of order IDs to match
184
- * @returns Amount of sold and bought tokens
185
- */
186
- fill_order(trader: string, takerOrderId: bigint, orders: Array<bigint>): Promise<[bigint, bigint]>;
187
-
188
- /**
189
- * Trade with DEX and create buy limit order if quote not executed in full
190
- * @param params - Trade parameters
191
- * @returns Amount of sold tokens, bought tokens, and ID of the newly created order if any
192
- */
193
- buy(params: BuyTradeArguments): Promise<[bigint, bigint, bigint]>;
194
-
195
- /**
196
- * Trade with DEX and create sell limit order if quote not executed in full
197
- * @param params - Trade parameters
198
- * @returns Amount of sold tokens, bought tokens, and ID of the newly created order if any
199
- */
200
- sell(params: SellTradeArguments): Promise<[bigint, bigint, bigint]>;
201
-
202
- /**
203
- * Swap tokens across several markets.
204
- * @param params - Trade parameters
205
- * @returns Amount of sold tokens and bought tokens
206
- */
207
- swap(params: SwapArguments): Promise<[bigint, bigint]>;
208
- }
209
-
210
- /** Error thrown when the Aggregator API responds with a non-success HTTP status */
211
- export declare class AxisApiError extends Error {
212
- constructor(message: string, status: number);
213
-
214
- /** HTTP status code associated with the error */
215
- readonly status: number;
216
- }
217
-
218
- export interface QuoteParams {
219
- /** Asset to sell (`XLM` | `CODE:Issuer` | `CODE-Issuer` | contractId) */
220
- sellingAsset: string;
221
- /** Asset to buy (same format as `sellingAsset`) */
222
- buyingAsset: string;
223
- /** Trade amount in stroops (1 unit = 10,000,000 stroops) */
224
- amount: string | number;
225
- /** Restrict to the direct market only (no intermediate-asset routes) */
226
- direct?: boolean;
227
- }
228
-
229
- export interface QuotePathStep {
230
- /** Selling asset contract id at this hop */
231
- selling: string;
232
- /** Buying asset contract id at this hop */
233
- buying: string;
234
- /** Maker order IDs matched at this hop */
235
- orders: string[];
236
- }
237
-
238
- export interface QuotePath {
239
- /** Amount sold, in stroops */
240
- sold: string;
241
- /** Amount bought, in stroops */
242
- bought: string;
243
- /** Ordered list of hops in the route */
244
- path: QuotePathStep[];
245
- }
246
-
247
- export interface QuoteResult {
248
- /** Base58-encoded quote id */
249
- id: string;
250
- /** Quote status */
251
- status: 'success' | 'unfeasible' | 'rejected';
252
- /** Trade direction */
253
- direction: 'strict_send' | 'strict_receive';
254
- /** Selling asset contract id */
255
- sellingAsset: string;
256
- /** Buying asset contract id */
257
- buyingAsset: string;
258
- /** Ledger sequence the quote was computed for */
259
- ledger: number;
260
- /** Candidate routes ranked by profitability (up to 10) */
261
- paths: QuotePath[];
262
- /** Error message (present only if status is not `success`) */
263
- error?: string;
264
- }
265
-
266
- export interface DepthParams {
267
- /** Market identifier `BASE/QUOTE` */
268
- market: string;
269
- /** Percentage band (±) around the center price (0 < depth ≤ 100, default 20) */
270
- depth?: number;
271
- }
272
-
273
- export interface OrderbookDepth {
274
- /** Ledger sequence */
275
- ledger: number;
276
- /** UNIX timestamp (seconds) */
277
- timestamp: number;
278
- /** `[price, quantity]` pairs sorted descending by price */
279
- bids: Array<[string, string]>;
280
- /** `[price, quantity]` pairs sorted ascending by price */
281
- asks: Array<[string, string]>;
282
- }
283
-
284
- export interface CandlesParams {
285
- /** Market identifier `BASE/QUOTE` */
286
- market: string;
287
- /** Lower boundary (UNIX seconds, default 0) */
288
- from?: number;
289
- /** Upper boundary (UNIX seconds, defaults to `from + resolution * 200`) */
290
- to?: number;
291
- /** Resolution in seconds or alias (`5m`,`15m`,`30m`,`1h`,`2h`,`4h`,`12h`,`1d`,`3d`,`1w`,`2w`, default `auto`) */
292
- resolution?: number | string;
293
- /** Sort order (default `desc`) */
294
- order?: 'asc' | 'desc';
295
- }
296
-
297
- /** OHLCVT candle row: `[timestamp, open, high, low, close, baseVolume, quoteVolume, tradeCount]` */
298
- export type Candle = [number, string, string, string, string, string, string, number];
299
-
300
- export interface TickerEntry {
301
- /** Market symbol `BASE/QUOTE` */
302
- symbol: string;
303
- /** Opening price 24h ago */
304
- openPrice: string;
305
- /** Highest price in the 24h window */
306
- highPrice: string;
307
- /** Lowest price in the 24h window */
308
- lowPrice: string;
309
- /** Most recent trade price */
310
- lastPrice: string;
311
- /** 24h base asset volume */
312
- volume: string;
313
- /** 24h quote asset volume */
314
- quoteVolume: string;
315
- /** 24h price change (percent) */
316
- change: number;
317
- /** Volume-weighted average price */
318
- avgPrice: string;
319
- /** 24h trade count */
320
- trades: number;
321
- }
322
-
323
- export interface Ticker24hResult {
324
- /** Ledger sequence */
325
- ledger: number;
326
- /** UNIX timestamp (seconds) */
327
- timestamp: number;
328
- /** Per-market 24h stats, sorted by trade count descending */
329
- ticker: TickerEntry[];
330
- }
331
-
332
- export interface MarketsParams {
333
- /** Pagination cursor (`baseAsset-quoteAsset`) */
334
- cursor?: string;
335
- /** Max markets to return */
336
- limit?: number | string;
337
- }
338
-
339
- export interface MarketInfo {
340
- /** Base asset contract id */
341
- baseAsset: string;
342
- /** Quote asset contract id */
343
- quoteAsset: string;
344
- /** Pagination cursor for this market */
345
- cursor: string;
346
- /** Supported order types */
347
- orderTypes: string[];
348
- }
349
-
350
- export interface OrdersParams {
351
- /** Filter by order owner address */
352
- owner?: string;
353
- /** Filter by asset(s) - matches orders selling or buying any of them */
354
- asset?: string | string[];
355
- /** Pagination cursor (order id) */
356
- cursor?: string | bigint;
357
- /** Max orders to return */
358
- limit?: number | string;
359
- }
360
-
361
- export interface OrderHistoryParams {
362
- /** Filter by order owner address */
363
- owner?: string;
364
- /** Asset pair `[base, quote]` (contract ids) */
365
- pair?: string[];
366
- /** Pagination cursor (order id) */
367
- cursor?: string | bigint;
368
- /** Max orders to return */
369
- limit?: number | string;
370
- }
371
-
372
- export interface TradesParams {
373
- /** Filter by trader address */
374
- trader?: string;
375
- /** Asset pair `[base, quote]` (contract ids) */
376
- pair?: string[];
377
- /** Pagination cursor (trade id) */
378
- cursor?: string | bigint;
379
- /** Max trades to return */
380
- limit?: number | string;
381
- }
382
-
383
- /** Serialized order returned by the API */
384
- export interface ApiOrder {
385
- /** Order ID */
386
- id: string;
387
- /** Order status (`ACTIVE`|`FILLED`|`CANCELED`) */
388
- status: string;
389
- /** Order kind (`LIMIT`) */
390
- kind: string;
391
- /** Buying asset contract id */
392
- buying: string;
393
- /** Selling asset contract id */
394
- selling: string;
395
- /** Order price */
396
- price: string;
397
- /** Rational price representation */
398
- rprice: string;
399
- /** Total quote amount */
400
- quote: string;
401
- /** Amount left to sell/buy */
402
- amount: string;
403
- /** Maker address */
404
- owner: string;
405
- /** Expiration timestamp (UTC) */
406
- expires?: string;
407
- /** Iceberg amount */
408
- iceberg?: string;
409
- /** Stop price */
410
- stop?: string;
411
- /** Creation timestamp (UTC) */
412
- created?: string;
413
- /** Last update timestamp (UTC) */
414
- updated?: string;
415
- /** Pagination cursor */
416
- cursor?: string;
417
- }
418
-
419
- /** Serialized trade returned by the API */
420
- export interface ApiTrade {
421
- /** Trade ID */
422
- id: string;
423
- /** Matched order ID */
424
- order: string;
425
- /** Taker account address */
426
- taker: string;
427
- /** Maker account address */
428
- maker: string;
429
- /** Sold asset contract id */
430
- soldAsset: string;
431
- /** Bought asset contract id */
432
- boughtAsset: string;
433
- /** Sold tokens amount */
434
- sold: string;
435
- /** Bought tokens amount */
436
- bought: string;
437
- /** Approximate trade price */
438
- price: string;
439
- /** Pagination cursor */
440
- cursor?: string;
441
- /** Trade timestamp (UTC) */
442
- timestamp: string;
443
- }
444
-
445
- /** HTTP client for the AXIS Aggregator REST API */
446
- export declare class AxisApiClient {
447
- /** @param serverUrl - Base URL of the Aggregator server */
448
- constructor(serverUrl: string);
449
-
450
- /** Base URL of the Aggregator server */
451
- readonly serverUrl: string;
452
-
453
- /**
454
- * Price quote and candidate trade routes for selling a fixed amount of the source asset
455
- * @param params - Quote request parameters
456
- * @returns Best routes ranked by profitability
457
- */
458
- quoteSell(params: QuoteParams): Promise<QuoteResult>;
459
-
460
- /**
461
- * Price quote and candidate trade routes for buying a fixed amount of the destination asset
462
- * @param params - Quote request parameters
463
- * @returns Best routes ranked by profitability
464
- */
465
- quoteBuy(params: QuoteParams): Promise<QuoteResult>;
466
-
467
- /**
468
- * Order book depth aggregated into price buckets around the mid price
469
- * @param params - Depth request parameters
470
- * @returns Aggregated bids and asks
471
- */
472
- getDepth(params: DepthParams): Promise<OrderbookDepth>;
473
-
474
- /**
475
- * OHLCVT candlestick data (open, high, low, close, base volume, quote volume, trade count)
476
- * @param params - Candles request parameters
477
- * @returns Time-bucketed candles, max 200 per response
478
- */
479
- getCandles(params: CandlesParams): Promise<Candle[]>;
480
-
481
- /**
482
- * 24-hour ticker statistics for every available market
483
- * @returns Aggregated 24h stats per market
484
- */
485
- getTicker24h(): Promise<Ticker24hResult>;
486
-
487
- /**
488
- * List all active markets with pagination
489
- * @param params - Pagination parameters
490
- * @returns Active markets
491
- */
492
- getMarkets(params?: MarketsParams): Promise<MarketInfo[]>;
493
-
494
- /**
495
- * Retrieve active orders, filterable by owner or asset
496
- * @param params - Filter parameters
497
- * @returns Active orders matching the filter
498
- */
499
- getOrders(params?: OrdersParams): Promise<ApiOrder[]>;
500
-
501
- /**
502
- * Retrieve a single order by ID
503
- * @param id - Order ID
504
- * @returns Order, or null if not found
505
- */
506
- getOrder(id: bigint | string | number): Promise<ApiOrder | null>;
507
-
508
- /**
509
- * Retrieve archived/historical orders
510
- * @param params - Filter parameters
511
- * @returns Archived orders matching the filter
512
- */
513
- getOrderHistory(params?: OrderHistoryParams): Promise<ApiOrder[]>;
514
-
515
- /**
516
- * Retrieve recent trades
517
- * @param params - Filter parameters
518
- * @returns Recent trades matching the filter
519
- */
520
- getTrades(params?: TradesParams): Promise<ApiTrade[]>;
521
- }
1
+ import type {rpc} from "@stellar/stellar-sdk";
2
+
3
+ /** Trading order type */
4
+ export enum OrderKind {
5
+ /** Execute trade, create a limit order if not executed in full */
6
+ Limit = 1,
7
+ /** Execute trade without creating a limit order */
8
+ Fill = 2,
9
+ /** Execute trade, cancel if was not executed in full */
10
+ FillOrKill = 3,
11
+ }
12
+
13
+ /** Trade direction instructions */
14
+ export enum TradeDirection {
15
+ Sell = 1,
16
+ Buy = 2,
17
+ }
18
+
19
+ /** Order properties, stored on-chain */
20
+ export interface Order {
21
+ /** Amount left to sell */
22
+ amount: bigint;
23
+ /** Buying token address */
24
+ buying: string;
25
+ /** Expiration timestamp (0 = no expiration) */
26
+ expires: bigint;
27
+ /** Unique order identifier, derived from the owner and the client nonce */
28
+ id: bigint;
29
+ /** Maker address */
30
+ owner: string;
31
+ /** Order price (`buying` per 1 `selling`, 18 decimals) */
32
+ price: bigint;
33
+ /** Selling token address */
34
+ selling: string;
35
+ }
36
+
37
+ /** Token allowance granted to the contract as part of the call */
38
+ export interface Approval {
39
+ /** Token the allowance is granted on: defaults to `selling` for `buy`, `sell` and `swap`, required in `update` approvals */
40
+ asset?: string;
41
+ /** Absolute allowance amount (0 revokes the approval) */
42
+ amount: bigint;
43
+ /** Ledger sequence the allowance lives until */
44
+ liveUntil: number;
45
+ }
46
+
47
+ /** New amount, price and expiration for an existing order */
48
+ export interface OrderUpdate {
49
+ /** Order id */
50
+ id: bigint;
51
+ /** New amount to sell, 0 removes the order */
52
+ amount: bigint;
53
+ /** New order price (ignored for a removal) */
54
+ price: bigint;
55
+ /** New expiration UNIX timestamp (in seconds), 0 or omitted = no expiration */
56
+ expires?: bigint | number;
57
+ }
58
+
59
+ /** Contract configuration */
60
+ export interface Config {
61
+ /** Oracle contract address */
62
+ oracle: string;
63
+ /** Amount of oracle tokens burned by the market creator to provision the oracle price feeds (always the oracle daily fee x 90) */
64
+ market_listing_fee: bigint;
65
+ /** Address of the account allowed to freeze the contract, change the minimum trade size and replace the oracle */
66
+ safety_admin: string;
67
+ /** Minimum trade value in USD, with 7 decimals precision (0 disables the limit) */
68
+ min_trade_size: bigint;
69
+ }
70
+
71
+ /** Market asset descriptor */
72
+ export interface MarketSide {
73
+ /** Token contract address */
74
+ asset: string;
75
+ /** Whether the asset is quoted by the oracle */
76
+ listed: boolean;
77
+ /** Token decimals (fetched only for listed assets) */
78
+ decimals: number;
79
+ }
80
+
81
+ /** Market record, stored on-chain */
82
+ export interface Market {
83
+ /** First asset (canonical order) */
84
+ a: MarketSide;
85
+ /** Second asset (canonical order) */
86
+ b: MarketSide;
87
+ /** Creation timestamp */
88
+ created: bigint;
89
+ }
90
+
91
+ /** Orderbook `trade` event, one per fill (topics: `trade`, `selling`, `buying`) */
92
+ export interface TradeContractEvent {
93
+ /** Asset sold by the taker (topic) */
94
+ selling: string;
95
+ /** Asset bought by the taker (topic) */
96
+ buying: string;
97
+ /** Maker order id */
98
+ order: bigint;
99
+ /** Trader account address */
100
+ taker: string;
101
+ /** Seller account address */
102
+ maker: string;
103
+ /** Sold tokens amount */
104
+ sold: bigint;
105
+ /** Bought tokens amount */
106
+ bought: bigint;
107
+ /** Order amount left after the fill (0 = removed) */
108
+ left: bigint;
109
+ }
110
+
111
+ /** Orderbook `swap` event, one per call (topics: `swap`, `selling`, `buying`) */
112
+ export interface SwapContractEvent {
113
+ /** Asset sold by the trader (topic) */
114
+ selling: string;
115
+ /** Asset received by the trader (topic) */
116
+ buying: string;
117
+ /** Trader account address */
118
+ trader: string;
119
+ /** Amount of `selling` tokens sold */
120
+ sold: bigint;
121
+ /** Amount of `buying` tokens received */
122
+ bought: bigint;
123
+ }
124
+
125
+ /** Orderbook `new` event, an order created (topics: `new`, `selling`, `buying`) */
126
+ export interface OrderCreatedContractEvent {
127
+ /** Selling asset address (topic) */
128
+ selling: string;
129
+ /** Buying asset address (topic) */
130
+ buying: string;
131
+ /** Unique order identifier */
132
+ id: bigint;
133
+ /** Maker address */
134
+ owner: string;
135
+ /** Order price */
136
+ price: bigint;
137
+ /** Current amount */
138
+ amount: bigint;
139
+ /** Expiration timestamp (0 = no expiration) */
140
+ expires: bigint;
141
+ }
142
+
143
+ /** Orderbook `mod` event, an order changed outside a fill (topics: `mod`) */
144
+ export interface OrderUpdatedContractEvent {
145
+ /** Unique order identifier */
146
+ id: bigint;
147
+ /** Order price */
148
+ price: bigint;
149
+ /** Current amount (0 = removed) */
150
+ amount: bigint;
151
+ /** Expiration timestamp (0 = no expiration) */
152
+ expires: bigint;
153
+ }
154
+
155
+ /**
156
+ * Orderbook `skip` event, a listed order its maker could not settle (backing short of the fill, cannot receive the
157
+ * taker's asset, or the transfer failed); the order is left unchanged (topics: `skip`)
158
+ */
159
+ export interface OrderSkippedContractEvent {
160
+ /** Order id */
161
+ order: bigint;
162
+ }
163
+
164
+ /** Orderbook `refresh` event, a market checked against the oracle (topics: `refresh`, `a`, `b`; no data) */
165
+ export interface MarketRefreshContractEvent {
166
+ /** First market asset (canonical order, topic) */
167
+ a: string;
168
+ /** Second market asset (canonical order, topic) */
169
+ b: string;
170
+ }
171
+
172
+ /** `freeze` event (topics: `freeze`) */
173
+ export interface FreezeContractEvent {
174
+ /** Whether trading is blocked after the call */
175
+ frozen: boolean;
176
+ }
177
+
178
+ /** `config` update notification event, emitted by the constructor, `delegate`, `set_oracle` or `set_floor` (topics: `config`) */
179
+ export interface ConfigChangedContractEvent {
180
+ /** Contract configuration after the call */
181
+ config: Config;
182
+ }
183
+
184
+ /** A trade step in a multi-market swap path. */
185
+ export interface TradeStep {
186
+ /** Asset to buy at this step */
187
+ asset: string;
188
+ /** Maker order IDs to match */
189
+ orders: Array<bigint>;
190
+ }
191
+
192
+ /** Standard contract errors */
193
+ export declare const ContractErrors: {
194
+ 701: {message: "NotAuthorized"};
195
+ 702: {message: "InsufficientBalance"};
196
+ 703: {message: "InsufficientAllowance"};
197
+ 704: {message: "InvalidMatch"};
198
+ 705: {message: "InvalidPrice"};
199
+ 706: {message: "InvalidAmount"};
200
+ 707: {message: "InvalidExpiration"};
201
+ 708: {message: "CannotReceive"};
202
+ 709: {message: "NotFilled"};
203
+ 710: {message: "OrderNotFound"};
204
+ 711: {message: "OrderExists"};
205
+ 720: {message: "OrderSizeTooSmall"};
206
+ 721: {message: "AssetsNotVerifiedByOracle"};
207
+ 722: {message: "AssetPriceOracleFetchFailed"};
208
+ 723: {message: "InvalidOracleConfig"};
209
+ 730: {message: "Frozen"};
210
+ 740: {message: "Overflow"};
211
+ }
212
+
213
+ /**
214
+ * Compute the id of the order `owner` creates with `nonce`
215
+ * (first 16 bytes of `sha256(xdr([owner, nonce]))` as a big-endian u128)
216
+ * @param owner - Order owner address
217
+ * @param nonce - u64 nonce the order was created with
218
+ */
219
+ export declare function orderId(owner: string, nonce: bigint | number | string): bigint;
220
+
221
+ export interface ClientInitializationParams {
222
+ /** Public key of the account that will interact with the contract */
223
+ publicKey: string;
224
+ /** Callback for signing transactions generated by the client */
225
+ signTransaction: SignTransactionCallback;
226
+ /** URL of the RPC server */
227
+ rpcUrl: string;
228
+ /** DEX contract ID */
229
+ contractId: string;
230
+ /** Network passphrase (Pubnet passphrase by default) */
231
+ networkPassphrase?: string;
232
+ /** Transaction fee (0.1 XLM by default) */
233
+ fee?: string;
234
+ /** Declare every supplied order id, and the balances and allowances of the makers behind them, in the read-write footprint of trading transactions (enabled by default) */
235
+ autoFootprint?: boolean;
236
+ }
237
+
238
+ export type SignTransactionCallback = (
239
+ tx: string,
240
+ context: {network: string; networkPassphrase: string; accountToSign: string}
241
+ ) => Promise<{signedTxXdr: string; signerAddress?: string}>;
242
+
243
+ export interface TradeArguments {
244
+ /** Trading order behavior */
245
+ kind: OrderKind,
246
+ /** Trader address */
247
+ trader: string;
248
+ /** Tokens amount */
249
+ amount: bigint;
250
+ /** Selling token address */
251
+ selling: string;
252
+ /** Buying token address */
253
+ buying: string;
254
+ /** Price a trader willing to accept */
255
+ price: bigint;
256
+ /** List of order IDs to match before creating the order on-chain */
257
+ orders?: Array<bigint>;
258
+ /** Expiration UNIX timestamp (in seconds) of the order created for a `Limit` remainder, 0 or omitted = no expiration */
259
+ expires?: bigint | number;
260
+ /** Optional allowance granted to the contract before trading (on `selling` unless `asset` is set) */
261
+ approve?: Approval;
262
+ }
263
+
264
+ export interface SellTradeArguments extends TradeArguments {
265
+ /** Amount of `selling` tokens to sell */
266
+ amount: bigint;
267
+ /** Price a trader willing to accept, minimum `buying` tokens per 1 `selling` */
268
+ price: bigint;
269
+ }
270
+
271
+ export interface BuyTradeArguments extends TradeArguments {
272
+ /** Amount of `buying` tokens to acquire */
273
+ amount: bigint;
274
+ /** Price a trader willing to accept, maximum `selling` tokens per 1 `buying` */
275
+ price: bigint;
276
+ }
277
+
278
+ export interface SwapArguments {
279
+ /** Trade direction: `Sell` or `Buy` */
280
+ direction: TradeDirection,
281
+ /** Trader address */
282
+ trader: string,
283
+ /** Token address sent by the trader */
284
+ selling: string,
285
+ /** Amount of selling tokens to send (`Sell`) or the maximum to spend (`Buy`) */
286
+ sellingAmount: bigint,
287
+ /** Minimum amount of buying tokens to receive (`Sell`) or the exact amount (`Buy`) */
288
+ buyingAmount: bigint,
289
+ /** Ordered list of the trade route steps */
290
+ path: Array<TradeStep>,
291
+ /** Optional allowance granted to the contract before trading (on `selling` unless `asset` is set) */
292
+ approve?: Approval
293
+ }
294
+
295
+ export interface UpdateArguments {
296
+ /** Orders owner */
297
+ trader: string;
298
+ /** New amount, price and expiration per order */
299
+ updates: Array<OrderUpdate>;
300
+ /** Allowances granted before the backing check, each naming its `asset`; an asset without an approval keeps its current allowance */
301
+ approvals?: Array<Approval & {asset: string}>;
302
+ }
303
+
304
+ export interface SubsidizeArguments {
305
+ /** Address paying for the oracle feeds (and the listing fee of a new market) */
306
+ sponsor: string;
307
+ /** First market asset */
308
+ selling: string;
309
+ /** Second market asset (either order opens the same market) */
310
+ buying: string;
311
+ /** Amount of XRF fee tokens to burn, at least `Config.market_listing_fee` to open a market */
312
+ amount: bigint;
313
+ }
314
+
315
+ export declare class AxisContractClient {
316
+ constructor(params: ClientInitializationParams);
317
+
318
+ /** Account that signs and pays for the transactions */
319
+ readonly publicKey: string;
320
+
321
+ /**
322
+ * Fetch existing order
323
+ * @param id - ID of the order to fetch
324
+ * @returns Order fetched from the storage, undefined if not found or expired
325
+ */
326
+ order(id: bigint): Promise<Order | undefined>;
327
+
328
+ /** Fetch contract configuration */
329
+ loadConfig(): Promise<Config>;
330
+
331
+ /**
332
+ * Check whether the contract is frozen
333
+ * @returns `true` if contract is frozen (trading and order management operations blocked)
334
+ */
335
+ isFrozen(): Promise<boolean>;
336
+
337
+ /**
338
+ * Fetch market for the given asset pair
339
+ * @param selling - First market asset
340
+ * @param buying - Second market asset
341
+ * @returns Market record if the market exists
342
+ */
343
+ getMarket(selling: string, buying: string): Promise<Market | undefined>;
344
+
345
+ /**
346
+ * Cancel existing orders, expired ones included: `update` with a zero amount per order (the contract has no
347
+ * `cancel`). A transaction can process up to 100 orders in one batch
348
+ * @param trader - Trader address
349
+ * @param ids - IDs of the orders to cancel (non-existent orders are ignored)
350
+ * @throws If trader is not the owner of any existing order in `ids` or if the contract is frozen
351
+ */
352
+ cancel(trader: string, ids: Array<bigint>): Promise<void>;
353
+
354
+ /**
355
+ * Update the amount, price, or expiration of several orders in place, or remove them.
356
+ * Orders that no longer exist are skipped; expired orders revived with the new expiration.
357
+ * A zero amount removes the order, expired ones included. An updated order's entry lifetime is extended to cover
358
+ * its expiration +1 day. Approvals and removals work in a frozen contract. A transaction can process up to 100
359
+ * orders in one batch
360
+ * @param params - Update parameters
361
+ * @returns IDs of the orders to update
362
+ * @throws If the trader does not own an updated order, if order parameters are invalid, if an order is below the
363
+ * minimum value, if the new amounts are not backed by the trader's balance and allowance, if the contract is frozen
364
+ */
365
+ update(params: UpdateArguments): Promise<Array<bigint>>;
366
+
367
+ /**
368
+ * Fill an existing order against matching orders from the orderbook. Profits from inefficiencies go to the trader
369
+ * @param trader - Trader address
370
+ * @param takerOrderId - ID of the order that serves as a taker
371
+ * @param orders - List of order IDs to match against
372
+ * @returns Amount the taker order sold, amount the taker received, surplus paid to the trader
373
+ * @throws If the taker order does not exist or has expired, if any of the orders provided do not match
374
+ * selling/buying asset, if the taker order's owner or the trader cannot receive the bought asset, if the contract is
375
+ * frozen
376
+ */
377
+ crossfill(trader: string, takerOrderId: bigint, orders: Array<bigint>): Promise<[bigint, bigint, bigint]>;
378
+
379
+ /**
380
+ * Trade with DEX and create a buy limit order if the quote not executed in full
381
+ * @param params - Trade parameters
382
+ * @returns Amount of sold and bought tokens, ID of the newly created order if any
383
+ * @throws If the trader has insufficient balance or allowance, invalid `expires` field specified, a `Limit` trade
384
+ * targets a pair without a market, no reference price is available, any of the counter orders provided do not match
385
+ * selling/buying asset, or a live order with the same id exists
386
+ */
387
+ buy(params: BuyTradeArguments): Promise<[bigint, bigint, bigint | undefined]>;
388
+
389
+ /**
390
+ * Trade with DEX and create a sell limit order if the quote not executed in full
391
+ * @param params - Trade parameters
392
+ * @returns Amount of sold and bought tokens, ID of the newly created order if any
393
+ * @throws If the trader has insufficient balance or allowance, invalid `expires` field specified, a `Limit` trade
394
+ * targets a pair without a market, no reference price is available, any of the counter orders provided do not match
395
+ * selling/buying asset, or a live order with the same id exists
396
+ */
397
+ sell(params: SellTradeArguments): Promise<[bigint, bigint, bigint | undefined]>;
398
+
399
+ /**
400
+ * Swap tokens across several markets. The contract holds the intermediate hop proceeds only within the call
401
+ * @param params - Swap path and settings
402
+ * @returns Amount of sold and bought tokens
403
+ * @throws If the route cannot satisfy the selling/buying amount, if `path` is empty or an amount is invalid, if any
404
+ * of the orders provided do not match trade step selling/buying asset, if the trader cannot pay for the fills or
405
+ * receive tokens, if the contract is frozen
406
+ */
407
+ swap(params: SwapArguments): Promise<[bigint, bigint]>;
408
+
409
+ /** Extend the contract instance and code lifetime */
410
+ keepalive(): Promise<void>;
411
+
412
+ /**
413
+ * Re-check both market assets against the price oracle and cache oracle prices.
414
+ * A cached price is valid for up to 72 hours. A market without quoted assets stops accepting new limit orders; its
415
+ * outstanding orders stay cancellable and fillable. The record and the cached prices are rewritten only when they
416
+ * change. When the simulation writes nothing (the market and the cached prices are current, or the oracle has no
417
+ * newer price), the simulated result is returned and no transaction is submitted
418
+ * @param selling - First market asset
419
+ * @param buying - Second market asset
420
+ * @returns Updated market record, undefined if the market does not exist
421
+ * @throws If the contract is frozen
422
+ */
423
+ requote(selling: string, buying: string): Promise<Market | undefined>;
424
+
425
+ /**
426
+ * Extend oracle price feeds access for a market, creating the market if it does not exist yet
427
+ * @param params - Subsidy parameters
428
+ * @returns New access expiration UNIX timestamps (in seconds) per oracle-listed asset
429
+ * @throws If `amount` is invalid, if the market does not exist and the amount is below the market listing fee, if
430
+ * neither market asset is quoted by the oracle, if the contract is frozen
431
+ */
432
+ subsidize(params: SubsidizeArguments): Promise<Array<bigint>>;
433
+ }
434
+
435
+ /** Error thrown when the Aggregator API responds with a non-success HTTP status */
436
+ export declare class AxisApiError extends Error {
437
+ constructor(message: string, status: number);
438
+
439
+ /** HTTP status code associated with the error */
440
+ readonly status: number;
441
+ }
442
+
443
+ export interface QuoteParams {
444
+ /** Asset to sell (`XLM` | `CODE:Issuer` | `CODE-Issuer` | contractId) */
445
+ sellingAsset: string;
446
+ /** Asset to buy (same format as `sellingAsset`) */
447
+ buyingAsset: string;
448
+ /** Trade amount in stroops (1 unit = 10,000,000 stroops) */
449
+ amount: string | number;
450
+ /** Restrict to the direct market only (no intermediate-asset routes) */
451
+ direct?: boolean;
452
+ }
453
+
454
+ export interface QuotePathStep {
455
+ /** Selling asset contract id at this hop */
456
+ selling: string;
457
+ /** Buying asset contract id at this hop */
458
+ buying: string;
459
+ /** Maker order IDs matched at this hop */
460
+ orders: string[];
461
+ /** Highest price among the matched orders (maker `buying` per `selling`, 18 decimals): a trade limit at this price crosses every listed order */
462
+ worstPrice?: string;
463
+ }
464
+
465
+ export interface QuotePath {
466
+ /** Amount sold, in stroops */
467
+ sold: string;
468
+ /** Amount bought, in stroops */
469
+ bought: string;
470
+ /** Ordered list of hops in the route */
471
+ path: QuotePathStep[];
472
+ }
473
+
474
+ export interface QuoteResult {
475
+ /** Base58-encoded quote id */
476
+ id: string;
477
+ /** Quote status */
478
+ status: 'success' | 'unfeasible' | 'rejected';
479
+ /** Trade direction */
480
+ direction: 'strict_send' | 'strict_receive';
481
+ /** Selling asset contract id */
482
+ sellingAsset: string;
483
+ /** Buying asset contract id */
484
+ buyingAsset: string;
485
+ /** Ledger sequence the quote was computed for */
486
+ ledger: number;
487
+ /** Candidate routes ranked by profitability (up to 10) */
488
+ paths: QuotePath[];
489
+ /** Error message (present only if status is not `success`) */
490
+ error?: string;
491
+ }
492
+
493
+ export interface DepthParams {
494
+ /** Market identifier `BASE/QUOTE` */
495
+ market: string;
496
+ /** Percentage band (±) around the center price (0 < depth ≤ 100, default 20) */
497
+ depth?: number;
498
+ /** Price step of the levels, a decimal such as `"0.0005"` (5 significant digits of the mid price by default) */
499
+ step?: string;
500
+ /** Price levels per side (default 100, max 500) */
501
+ limit?: number;
502
+ }
503
+
504
+ export interface OrderbookDepth {
505
+ /** Ledger sequence */
506
+ ledger: number;
507
+ /** UNIX timestamp (seconds) */
508
+ timestamp: number;
509
+ /** Price step of the levels (null for an empty book) */
510
+ step: string | null;
511
+ /** Exact best bid price, before the rounding to levels */
512
+ bestBid: string | null;
513
+ /** Exact best ask price, before the rounding to levels */
514
+ bestAsk: string | null;
515
+ /** `[price, quantity]` pairs sorted descending by price */
516
+ bids: Array<[string, string]>;
517
+ /** `[price, quantity]` pairs sorted ascending by price */
518
+ asks: Array<[string, string]>;
519
+ }
520
+
521
+ export interface CandlesParams {
522
+ /** Market identifier `BASE/QUOTE` */
523
+ market: string;
524
+ /** Lower boundary (UNIX seconds, default 0) */
525
+ from?: number;
526
+ /** Upper boundary (UNIX seconds, defaults to `from + resolution * 200`) */
527
+ to?: number;
528
+ /** Resolution in seconds or alias (`5m`,`15m`,`30m`,`1h`,`2h`,`4h`,`12h`,`1d`,`3d`,`1w`,`2w`, default `auto`) */
529
+ resolution?: number | string;
530
+ /** Sort order (default `desc`) */
531
+ order?: 'asc' | 'desc';
532
+ }
533
+
534
+ /** OHLCVT candle row: `[timestamp, open, high, low, close, baseVolume, quoteVolume, tradeCount]` */
535
+ export type Candle = [number, string, string, string, string, string, string, number];
536
+
537
+ export interface TickerEntry {
538
+ /** Market symbol `BASE/QUOTE` */
539
+ symbol: string;
540
+ /** Opening price 24h ago */
541
+ openPrice: string;
542
+ /** Highest price in the 24h window */
543
+ highPrice: string;
544
+ /** Lowest price in the 24h window */
545
+ lowPrice: string;
546
+ /** Most recent trade price */
547
+ lastPrice: string;
548
+ /** 24h base asset volume */
549
+ volume: string;
550
+ /** 24h quote asset volume */
551
+ quoteVolume: string;
552
+ /** 24h price change (percent) */
553
+ change: number;
554
+ /** Volume-weighted average price */
555
+ avgPrice: string;
556
+ /** 24h trade count */
557
+ trades: number;
558
+ }
559
+
560
+ export interface Ticker24hResult {
561
+ /** Ledger sequence */
562
+ ledger: number;
563
+ /** UNIX timestamp (seconds) */
564
+ timestamp: number;
565
+ /** Per-market 24h stats, sorted by trade count descending */
566
+ ticker: TickerEntry[];
567
+ }
568
+
569
+ export interface MarketsParams {
570
+ /** Pagination cursor (`baseAsset-quoteAsset`) */
571
+ cursor?: string;
572
+ /** Max markets to return */
573
+ limit?: number | string;
574
+ }
575
+
576
+ export interface MarketInfo {
577
+ /** Base asset contract id */
578
+ baseAsset: string;
579
+ /** Quote asset contract id */
580
+ quoteAsset: string;
581
+ /** Pagination cursor for this market */
582
+ cursor: string;
583
+ /** Supported order types */
584
+ orderTypes: string[];
585
+ }
586
+
587
+ /** Contract configuration tracked by the indexer */
588
+ export interface ContractInfoConfig {
589
+ /** Safety admin address */
590
+ safetyAdmin: string;
591
+ /** Price oracle contract address */
592
+ oracle: string;
593
+ /** Fee token amount burned to open a market */
594
+ marketListingFee: string;
595
+ /** Minimum trade value in USD with 7 decimals (0 = disabled) */
596
+ minTradeSize: string;
597
+ }
598
+
599
+ /** Market tracked by the indexer */
600
+ export interface ContractInfoMarket {
601
+ /** First market asset */
602
+ a: string;
603
+ /** Second market asset */
604
+ b: string;
605
+ /** Creation timestamp (UTC) */
606
+ created: string;
607
+ /** Last oracle check timestamp (UTC) */
608
+ refreshed: string;
609
+ }
610
+
611
+ /** Contract state tracked by the indexer */
612
+ export interface ContractInfo {
613
+ /** Whether trading is blocked by the safety admin */
614
+ frozen: boolean;
615
+ /** Contract configuration */
616
+ config?: ContractInfoConfig;
617
+ /** Markets opened by `subsidize` */
618
+ markets: ContractInfoMarket[];
619
+ }
620
+
621
+ export interface OrdersParams {
622
+ /** Filter by order owner address */
623
+ owner?: string;
624
+ /** Filter by asset(s) - every listed asset must be one of the order assets (two assets select a pair) */
625
+ asset?: string | string[];
626
+ /** Pagination cursor (order id) */
627
+ cursor?: string | bigint;
628
+ /** Max orders to return */
629
+ limit?: number | string;
630
+ }
631
+
632
+ export interface OrderHistoryParams {
633
+ /** Filter by order owner address */
634
+ owner?: string;
635
+ /** Asset pair `[base, quote]` (contract ids) */
636
+ pair?: string[];
637
+ /** Pagination cursor (order id) */
638
+ cursor?: string | bigint;
639
+ /** Max orders to return */
640
+ limit?: number | string;
641
+ }
642
+
643
+ export interface TradesParams {
644
+ /** Filter by trader address */
645
+ trader?: string;
646
+ /** Asset pair `[base, quote]` (contract ids) */
647
+ pair?: string[];
648
+ /** Pagination cursor (trade id) */
649
+ cursor?: string | bigint;
650
+ /** Max trades to return */
651
+ limit?: number | string;
652
+ }
653
+
654
+ /** Maker backing in the order's selling asset */
655
+ export interface ApiOrderBacking {
656
+ /** Token balance */
657
+ balance: string;
658
+ /** Allowance granted to the AXIS contract */
659
+ allowance: string;
660
+ /** Ledger sequence the allowance lives until */
661
+ liveUntil: number;
662
+ /** Whether the maker can send and receive the token */
663
+ authorized: boolean;
664
+ /** Last load timestamp (UTC) */
665
+ updated?: string;
666
+ /** A reload confirming the latest event is still due: the values may predate it */
667
+ pending?: boolean;
668
+ }
669
+
670
+ /** Tracked backing of an account in a token */
671
+ export interface ApiBacking {
672
+ /** Account address */
673
+ owner: string;
674
+ /** Token contract id */
675
+ asset: string;
676
+ /** Token balance */
677
+ balance: string;
678
+ /** Allowance granted to the AXIS contract */
679
+ allowance: string;
680
+ /** Ledger sequence the allowance lives until */
681
+ liveUntil: number;
682
+ /** Whether the account can send and receive the token */
683
+ authorized: boolean;
684
+ /** Effective budget, min(balance, allowance), 0 when unauthorized or expired */
685
+ budget: string;
686
+ /** Last load timestamp (UTC) */
687
+ updated?: string;
688
+ /** Last `skip` event of an order selling the token (UTC) */
689
+ skipped?: string;
690
+ /** A reload confirming the latest event is still due */
691
+ pending?: boolean;
692
+ }
693
+
694
+ /** Account state: every live order and the backing per traded asset */
695
+ export interface ApiAccount {
696
+ /** Trader address */
697
+ address: string;
698
+ /** Last processed ledger */
699
+ ledger: number;
700
+ /** Live orders, oldest first */
701
+ orders: ApiOrder[];
702
+ /** Backing by token contract id */
703
+ backing: Record<string, ApiBacking>;
704
+ }
705
+
706
+ /** Serialized order returned by the API */
707
+ export interface ApiOrder {
708
+ /** Order ID (decimal u128) */
709
+ id: string;
710
+ /** Order status: `ACTIVE`, `FILLED`, `CANCELED` (removed by the owner) or `EXPIRED` (archived once past `expires`) */
711
+ status: 'ACTIVE' | 'FILLED' | 'CANCELED' | 'EXPIRED';
712
+ /** Buying asset contract id */
713
+ buying: string;
714
+ /** Selling asset contract id */
715
+ selling: string;
716
+ /** Order price */
717
+ price: string;
718
+ /** Rational price representation */
719
+ rprice: string;
720
+ /** Selling amount at creation */
721
+ quote: string;
722
+ /** Amount left to sell */
723
+ amount: string;
724
+ /** Amount the maker can actually deliver, when the indexer tracks backing */
725
+ backed?: string;
726
+ /** Maker backing details, when the indexer tracks backing */
727
+ backing?: ApiOrderBacking;
728
+ /** Maker address */
729
+ owner: string;
730
+ /** Expiration timestamp (UTC) */
731
+ expires?: string;
732
+ /** Creation timestamp (UTC) */
733
+ created?: string;
734
+ /** Last update timestamp (UTC) */
735
+ updated?: string;
736
+ /** Pagination cursor */
737
+ cursor?: string;
738
+ }
739
+
740
+ /** Serialized trade returned by the API */
741
+ export interface ApiTrade {
742
+ /** Record type */
743
+ type: 'trade';
744
+ /** Trade ID */
745
+ id: string;
746
+ /** Matched order ID */
747
+ order: string;
748
+ /** Taker account address */
749
+ taker: string;
750
+ /** Maker account address */
751
+ maker: string;
752
+ /** Sold asset contract id */
753
+ soldAsset: string;
754
+ /** Bought asset contract id */
755
+ boughtAsset: string;
756
+ /** Sold tokens amount */
757
+ sold: string;
758
+ /** Bought tokens amount */
759
+ bought: string;
760
+ /** Order amount left after the fill */
761
+ left?: string;
762
+ /** Approximate trade price */
763
+ price: string;
764
+ /** Pagination cursor */
765
+ cursor?: string;
766
+ /** Trade timestamp (UTC) */
767
+ timestamp: string;
768
+ }
769
+
770
+ /** HTTP client for the AXIS Aggregator REST API */
771
+ export declare class AxisApiClient {
772
+ /** @param serverUrl - Base URL of the Aggregator server */
773
+ constructor(serverUrl: string);
774
+
775
+ /** Base URL of the Aggregator server */
776
+ readonly serverUrl: string;
777
+
778
+ /**
779
+ * Price quote and candidate trade routes for selling a fixed amount of the source asset
780
+ * @param params - Quote request parameters
781
+ * @returns Best routes ranked by profitability
782
+ * @throws {AxisApiError} If the server is not ready or there is not enough liquidity
783
+ */
784
+ quoteSell(params: QuoteParams): Promise<QuoteResult>;
785
+
786
+ /**
787
+ * Price quote and candidate trade routes for buying a fixed amount of the destination asset
788
+ * @param params - Quote request parameters
789
+ * @returns Best routes ranked by profitability
790
+ * @throws {AxisApiError} If the server is not ready or there is not enough liquidity
791
+ */
792
+ quoteBuy(params: QuoteParams): Promise<QuoteResult>;
793
+
794
+ /**
795
+ * Order book depth around the mid price, aggregated into price levels on multiples of `step` (bids rounded down,
796
+ * asks up, so a level price crosses every order in it)
797
+ * @param params - Depth request parameters
798
+ * @returns Aggregated bids and asks
799
+ */
800
+ getDepth(params: DepthParams): Promise<OrderbookDepth>;
801
+
802
+ /**
803
+ * OHLCVT candlestick data (open, high, low, close, base volume, quote volume, trade count)
804
+ * @param params - Candles request parameters
805
+ * @returns Time-bucketed candles, max 200 per response
806
+ */
807
+ getCandles(params: CandlesParams): Promise<Candle[]>;
808
+
809
+ /**
810
+ * 24-hour ticker statistics for every available market
811
+ * @returns Aggregated 24h stats per market
812
+ */
813
+ getTicker24h(): Promise<Ticker24hResult>;
814
+
815
+ /**
816
+ * List all active markets with pagination
817
+ * @param params - Pagination parameters
818
+ * @returns Active markets
819
+ */
820
+ getMarkets(params?: MarketsParams): Promise<MarketInfo[]>;
821
+
822
+ /**
823
+ * Contract state tracked by the indexer: frozen switch, configuration and active markets
824
+ * @returns Contract state
825
+ */
826
+ getContract(): Promise<ContractInfo>;
827
+
828
+ /**
829
+ * Retrieve active orders, filterable by owner or asset
830
+ * @param params - Filter parameters
831
+ * @returns Active orders matching the filter
832
+ */
833
+ getOrders(params?: OrdersParams): Promise<ApiOrder[]>;
834
+
835
+ /**
836
+ * Account state tracked by the indexer: every live order of the trader (not paginated) and their backing in each
837
+ * asset they trade
838
+ * @param address - Trader address
839
+ */
840
+ getAccount(address: string): Promise<ApiAccount>;
841
+
842
+ /**
843
+ * Retrieve a single order by ID
844
+ * @param id - Order ID
845
+ * @returns Order (throws `AxisApiError` with status 404 if not found)
846
+ */
847
+ getOrder(id: bigint | string | number): Promise<ApiOrder>;
848
+
849
+ /**
850
+ * Retrieve archived/historical orders
851
+ * @param params - Filter parameters
852
+ * @returns Archived orders matching the filter
853
+ */
854
+ getOrderHistory(params?: OrderHistoryParams): Promise<ApiOrder[]>;
855
+
856
+ /**
857
+ * Retrieve recent trades
858
+ * @param params - Filter parameters
859
+ * @returns Recent trades matching the filter
860
+ */
861
+ getTrades(params?: TradesParams): Promise<ApiTrade[]>;
862
+ }
863
+
864
+ /** Price scale of the contract (18 decimals) */
865
+ export declare const PRICE_SCALE: bigint;
866
+
867
+ /**
868
+ * Compare two assets in the contract canonical order
869
+ * @param a - Token contract address
870
+ * @param b - Token contract address
871
+ * @returns Negative if `a` first, positive if `b` first, 0 if equal
872
+ */
873
+ export declare function compareAssets(a: string, b: string): number;
874
+
875
+ /**
876
+ * Reorder an asset pair the way the contract stores markets
877
+ * @param x - Token contract address
878
+ * @param y - Token contract address
879
+ * @returns `[a, b]`: `a` is the base, `b` the quote of the canonical market symbol
880
+ */
881
+ export declare function canonicalPair(x: string, y: string): [string, string];
882
+
883
+ /**
884
+ * Canonical market key `a/b`
885
+ * @param a - Token contract address
886
+ * @param b - Token contract address
887
+ */
888
+ export declare function pairKey(a: string, b: string): string;
889
+
890
+ /**
891
+ * Calculate inverted price, rounded down: `floor(10^36 / price)`
892
+ * @param price - Price in the contract scale
893
+ */
894
+ export declare function invertPrice(price: bigint): bigint;
895
+
896
+ /**
897
+ * 24h ticker entry of the market seen in the inverted orientation (`b/a`)
898
+ * @param entry - Standard ticker entry
899
+ */
900
+ export declare function invertTicker(entry: TickerEntry): TickerEntry;
901
+
902
+ /**
903
+ * Parse an Aggregator API timestamp (`YYYY-MM-DD HH:mm:ss` UTC)
904
+ * @returns UNIX milliseconds, 0 when missing or invalid
905
+ */
906
+ export declare function parseApiDate(value: string | number | undefined): number;
907
+
908
+ /** Allowance lifetime granted with a trade, in ledgers: ~30 days at 5s per ledger (the maximum entry TTL ~180 days) */
909
+ export declare const APPROVAL_TTL_LEDGERS: number;
910
+ /** An allowance expiring within this number of ledgers is renewed with the next trade (~1 day) */
911
+ export declare const APPROVAL_RENEW_LEDGERS: number;
912
+
913
+ export interface ApprovalPlanParams {
914
+ /** Max amount of the selling asset the call may spend */
915
+ required: bigint;
916
+ /** Remaining amount of orders in the book selling the asset */
917
+ committed: bigint;
918
+ /** Current allowance (0 once expired) */
919
+ allowance: bigint;
920
+ /** Current ledger sequence */
921
+ ledger: number;
922
+ /** Ledger the current allowance lives until (0 or omitted when unknown) */
923
+ liveUntil?: number;
924
+ }
925
+
926
+ /**
927
+ * Decide whether a call needs an in-call approval and adjust it. The approval amount is absolute and one allowance
928
+ * backs every order selling the token across all markets, so it has to cover this call plus every order selling the
929
+ * same asset
930
+ * @returns Approval to pass with the call, undefined when the current allowance already covers it
931
+ */
932
+ export declare function planApproval(params: ApprovalPlanParams): {amount: bigint, liveUntil: number} | undefined;
933
+
934
+ /**
935
+ * Max amount of `selling` tokens a buy trade may cost: `ceil(amount × price / 10^18)`
936
+ * @param amount - Amount of `buying` tokens to acquire
937
+ * @param price - Limit price (`selling` per 1 `buying`, with AXIS standard price decimals)
938
+ */
939
+ export declare function maxQuoteSpend(amount: bigint, price: bigint): bigint;
940
+
941
+ /** Minimal event emitter that works in browsers and Node */
942
+ export declare class Emitter {
943
+ /**
944
+ * Subscribe to an event
945
+ * @returns Unsubscribe function
946
+ */
947
+ on(event: string, listener: (...args: any[]) => void): () => void;
948
+ /**
949
+ * Subscribe to the next occurrence of an event
950
+ * @returns Unsubscribe function
951
+ */
952
+ once(event: string, listener: (...args: any[]) => void): () => void;
953
+ /** Unsubscribe from an event */
954
+ off(event: string, listener: (...args: any[]) => void): void;
955
+ }
956
+
957
+ /** Server message; `type` names the payload, `topic` the subscription it belongs to */
958
+ export interface StreamMessage {
959
+ type: string;
960
+ topic?: string;
961
+ /** Echoed request id (snapshots and errors) */
962
+ id?: number;
963
+ [key: string]: any;
964
+ }
965
+
966
+ export interface StreamClientOptions {
967
+ /** WebSocket implementation (the global one by default) */
968
+ WebSocket?: typeof WebSocket;
969
+ /** Application-level ping period, in milliseconds (20 s by default) */
970
+ pingInterval?: number;
971
+ /** First reconnect delay, doubled after each failure (1 s by default) */
972
+ minReconnectDelay?: number;
973
+ /** Reconnect delay cap (30 s by default) */
974
+ maxReconnectDelay?: number;
975
+ }
976
+
977
+ /**
978
+ * WebSocket client of the Aggregator push API.
979
+ * Emits `open`, `close` and `error` (server errors not tied to a subscription).
980
+ */
981
+ export declare class AxisStreamClient extends Emitter {
982
+ /** @param url - WebSocket endpoint, e.g. `wss://api.axis.markets/ws` */
983
+ constructor(url: string, options?: StreamClientOptions);
984
+
985
+ /** WebSocket endpoint */
986
+ readonly url: string;
987
+ /** Whether the connection is open */
988
+ readonly connected: boolean;
989
+
990
+ /**
991
+ * Subscribe to a channel; connects on the first subscription
992
+ * @param channel - Channel name
993
+ * @param params - Channel parameters
994
+ * @param handler - Receives the snapshot (again after every reconnect), the changes, and `{type: 'error'}` if the
995
+ * server rejects the subscription
996
+ * @returns Unsubscribe function
997
+ */
998
+ subscribe(channel: 'contract' | 'ticker' | 'account' | 'trades' | 'depth' | 'candles', params: {address?: string, market?: string, depth?: number, step?: string, resolution?: number | string, limit?: number}, handler: (message: StreamMessage) => void): () => void;
999
+
1000
+ /** Close the connection and drop every subscription */
1001
+ close(): void;
1002
+ }
1003
+
1004
+ /** Token state for allowance calculation, token balances, and current ledger */
1005
+ export declare class TokenBalance {
1006
+ /** @param options - `spender` is the AXIS contract */
1007
+ constructor(options: {rpcUrl: string, networkPassphrase: string, spender: string, server?: rpc.Server});
1008
+
1009
+ /**
1010
+ * Allowance `owner` granted to the AXIS contract on a token, 0 when expired
1011
+ * @param token - Token contract address
1012
+ * @param owner - Token holder address
1013
+ * @throws If the simulation fails
1014
+ */
1015
+ getAllowance(token: string, owner: string): Promise<bigint>;
1016
+ /**
1017
+ * Token balance of an account
1018
+ * @param token - Token contract address
1019
+ * @param owner - Token holder address
1020
+ * @returns 0 if the account holds no balance entry
1021
+ */
1022
+ getBalance(token: string, owner: string): Promise<bigint>;
1023
+ /** Latest closed ledger sequence */
1024
+ getLatestLedger(): Promise<number>;
1025
+ }
1026
+
1027
+ /** Account signing contract calls */
1028
+ export interface Signer {
1029
+ /** Transaction source account */
1030
+ publicKey: string;
1031
+ signTransaction: SignTransactionCallback;
1032
+ }
1033
+
1034
+ export interface AxisOptions {
1035
+ /** Aggregator REST API URL */
1036
+ apiUrl: string;
1037
+ /** AXIS contract address */
1038
+ contractId: string;
1039
+ /** Aggregator push API URL (`<apiUrl>/ws` with the `ws(s)` scheme by default) */
1040
+ wsUrl?: string;
1041
+ /** Stellar RPC URL, required to trade; also reads allowances and the ledger when the push API does not provide them */
1042
+ rpcUrl?: string;
1043
+ /** Network passphrase (Pubnet by default) */
1044
+ networkPassphrase?: string;
1045
+ /** Transaction fee */
1046
+ fee?: string;
1047
+ /** Default signer settings for contract operations (`keepalive`, `requote`, `subsidize`) */
1048
+ signer?: Signer;
1049
+ /** REST polling period while the push connection is down, in milliseconds (15 s by default) */
1050
+ fallbackPollInterval?: number;
1051
+ /** WebSocket implementation (the global one by default) */
1052
+ WebSocket?: typeof WebSocket;
1053
+ }
1054
+
1055
+ /**
1056
+ * High-level AXIS DEX state.
1057
+ * Emits:
1058
+ * - `change` - anything in the contract state changed
1059
+ * - `frozen` `boolean` - the frozen state toggled
1060
+ * - `config` {@link ContractInfoConfig} - contract configuration changed
1061
+ * - `market` `{market: AxisMarket, created: boolean}` - a market was opened or updated
1062
+ * - `connection` `boolean` - WebSocket push connection opened or dropped
1063
+ * - `ledger` `number` - new ledger processed by the indexer
1064
+ */
1065
+ export declare class Axis extends Emitter {
1066
+ constructor(options: AxisOptions);
1067
+
1068
+ /** Aggregator REST client */
1069
+ readonly api: AxisApiClient;
1070
+ /** Aggregator WebSocket API client */
1071
+ readonly stream: AxisStreamClient;
1072
+ /** Token balance wrappers; undefined without `rpcUrl` */
1073
+ readonly tokenBalances: TokenBalance | undefined;
1074
+ /** Contract address of the native XLM token */
1075
+ readonly nativeAsset: string;
1076
+ /** Last known ledger (0 until pushed) */
1077
+ readonly ledger: number;
1078
+ /** When `ledger` was last updated, UNIX milliseconds */
1079
+ readonly ledgerTime: number;
1080
+ /** Whether trading is suspended */
1081
+ readonly frozen: boolean;
1082
+ /** Contract configuration, undefined until loaded */
1083
+ readonly config: ContractInfoConfig | undefined;
1084
+ /** Available AXIS markets, by the canonical key `a/b` */
1085
+ readonly markets: Map<string, AxisMarket>;
1086
+ /** 24h ticker entries by the canonical key, filled while `subscribeTicker` runs */
1087
+ readonly tickers: Map<string, TickerEntry>;
1088
+ /** Whether the contract state loaded */
1089
+ readonly loaded: boolean;
1090
+
1091
+ /** Load the contract state and track its changes */
1092
+ connect(): Promise<Axis>;
1093
+ /** Current ledger sequence: the pushed one while connected and fresh, otherwise read over RPC */
1094
+ getLedger(): Promise<number>;
1095
+ /**
1096
+ * Get market of the asset pair, in either order
1097
+ * @param asset1 - Token contract address
1098
+ * @param asset2 - Token contract address
1099
+ */
1100
+ getMarket(asset1: string, asset2: string): AxisMarket | undefined;
1101
+ /**
1102
+ * Get live order by id, from a tracked account or the Aggregator
1103
+ * @returns Undefined if not found (filled, removed, expired)
1104
+ */
1105
+ getOrder(id: bigint | string): Promise<AccountOrder | undefined>;
1106
+ /**
1107
+ * Trader wrapper tracking the orders and allowances for an account (one instance per account address)
1108
+ * @param address - Trader address
1109
+ * @param options - Transaction signing callback
1110
+ */
1111
+ account(address: string, options?: {signTransaction?: SignTransactionCallback}): AxisAccount;
1112
+ /**
1113
+ * Stream the 24h ticker of every market (canonical orientation).
1114
+ * Sends a full snapshot, then updates caused by trades
1115
+ * @returns Unsubscribe function
1116
+ */
1117
+ subscribeTicker(callback?: (ticker: Ticker24hResult) => void): () => void;
1118
+ /**
1119
+ * Extend the contract instance and code lifetime
1120
+ * @param signer - Transaction source, the default signer by default
1121
+ */
1122
+ keepalive(signer?: Signer): Promise<void>;
1123
+ /** Stop following the contract state and tracked accounts */
1124
+ close(): void;
1125
+ }
1126
+
1127
+ /** Derive the push API endpoint from the REST API URL */
1128
+ export declare function toWsUrl(apiUrl: string): string;
1129
+
1130
+ /** DEX Market; assets in the contract canonical order */
1131
+ export declare class AxisMarket {
1132
+ /** Base asset */
1133
+ readonly a: string;
1134
+ /** Quote asset */
1135
+ readonly b: string;
1136
+ /** Canonical market key `a/b` */
1137
+ readonly key: string;
1138
+ /** Base asset (`a`) */
1139
+ readonly base: string;
1140
+ /** Quote asset (`b`) */
1141
+ readonly quote: string;
1142
+ /** Creation timestamp (first oracle check) (UNIX milliseconds) */
1143
+ readonly created: number;
1144
+ /** Last oracle check (UNIX milliseconds) */
1145
+ readonly refreshed: number;
1146
+ /** Last 24h ticker entry of the market, available while {@link Axis.subscribeTicker} runs */
1147
+ readonly ticker: TickerEntry | undefined;
1148
+
1149
+ /** Check whether the asset is one of the market assets */
1150
+ has(asset: string): boolean;
1151
+ /**
1152
+ * The other market asset
1153
+ * @param asset - One of the market assets
1154
+ * @throws If the asset does not belong to the market
1155
+ */
1156
+ counter(asset: string): string;
1157
+ /**
1158
+ * Re-check both market assets against the price oracle and cache oracle prices
1159
+ * @param signer - Transaction source, the {@link Axis} signer by default
1160
+ */
1161
+ requote(signer?: Signer): Promise<Market | undefined>;
1162
+ /**
1163
+ * Extend oracle price feeds access for the market
1164
+ * @param params - `amount` of fee tokens to burn
1165
+ * @returns New access expiration UNIX timestamps (in seconds) for each oracle-listed asset
1166
+ */
1167
+ subsidize(params: {amount: bigint, sponsor?: string, signer?: Signer}): Promise<bigint[]>;
1168
+ /**
1169
+ * Orderbook depth data with given precision
1170
+ * @param params - `base` is the base asset (`a` by default), `step` the price step (automatic by default)
1171
+ */
1172
+ getDepth(params?: {base?: string, depth?: number, step?: string, limit?: number}): Promise<OrderbookDepth>;
1173
+ /**
1174
+ * Stream the orderbook depth.
1175
+ * Returns a snapshot, then updates on book changes
1176
+ * @returns Unsubscribe function
1177
+ */
1178
+ subscribeDepth(params: {base?: string, depth?: number, step?: string, limit?: number}, callback: (depth: OrderbookDepth) => void): () => void;
1179
+ /**
1180
+ * Stream the market trades.
1181
+ * Returns a snapshot, then updates on trades
1182
+ * @param callback - Trades and whether they are the snapshot
1183
+ * @returns Unsubscribe function
1184
+ */
1185
+ subscribeTrades(callback: (trades: ApiTrade[], snapshot: boolean) => void): () => void;
1186
+ /**
1187
+ * Stream the market candles.
1188
+ * Returns a snapshot, then updates on trades
1189
+ * @param params - `base` is the base asset of the view, `resolution` in seconds or an alias (`5m`, `1h`, …), `limit`
1190
+ * the candles in the snapshot (200 by default, at most 200)
1191
+ * @param callback - Candles and whether they are the snapshot
1192
+ * @returns Unsubscribe function
1193
+ */
1194
+ subscribeCandles(params: {base?: string, resolution: number | string, limit?: number}, callback: (candles: Candle[], snapshot: boolean) => void): () => void;
1195
+ }
1196
+
1197
+ /** Open order of a tracked account */
1198
+ export interface AccountOrder {
1199
+ /** Order id (decimal u128) */
1200
+ id: string;
1201
+ /** Maker address */
1202
+ owner: string;
1203
+ /** Sold token */
1204
+ selling: string;
1205
+ /** Bought token */
1206
+ buying: string;
1207
+ /** Market key (canonical `a/b`) */
1208
+ market: string;
1209
+ /** Current status */
1210
+ status: 'ACTIVE' | 'FILLED' | 'CANCELED' | 'EXPIRED';
1211
+ /** `buying` per 1 `selling`, contract scale (18 decimals) */
1212
+ price: bigint;
1213
+ /** Amount of `selling` left */
1214
+ amount: bigint;
1215
+ /** Amount of `selling` at creation */
1216
+ quote: bigint;
1217
+ /** Expiration UNIX timestamp in seconds, 0 = none */
1218
+ expires: number;
1219
+ /** Creation time, UNIX milliseconds */
1220
+ created: number;
1221
+ /** Last change, UNIX milliseconds */
1222
+ updated: number;
1223
+ /** Paging cursor (undefined for unconfirmed local orders) */
1224
+ cursor?: bigint;
1225
+ /** Share of the account budget in `selling` that backs the order; null when unknown */
1226
+ backed: bigint | null;
1227
+ /** `backed / amount` (0..1), null when unknown */
1228
+ backedPct: number | null;
1229
+ /** The backing is not confirmed yet */
1230
+ backingPending: boolean;
1231
+ /** Filled share of the initial amount (0..1) */
1232
+ filledPct: number;
1233
+ /** Created by this client, not reported by the indexer yet */
1234
+ pending: boolean;
1235
+ }
1236
+
1237
+ /** Balance and allowance of the account in a token, as tracked by the indexer */
1238
+ export interface AccountBacking {
1239
+ asset: string;
1240
+ /** Spendable amount (balance minus reserve and liabilities) */
1241
+ balance: bigint;
1242
+ /** Allowance granted to the AXIS contract */
1243
+ allowance: bigint;
1244
+ /** Ledger sequence the allowance lives until */
1245
+ liveUntil: number;
1246
+ /** Whether the account can send and receive the token */
1247
+ authorized: boolean;
1248
+ /** min(balance, allowance), 0 when unauthorized or expired */
1249
+ budget: bigint;
1250
+ /** Last load, UNIX milliseconds (0 = not loaded) */
1251
+ updated: number;
1252
+ /** Last skipped fill of an order selling the token, UNIX milliseconds (0 = none) */
1253
+ skipped: number;
1254
+ /** A reload confirming the latest change is due */
1255
+ pending: boolean;
1256
+ }
1257
+
1258
+ export interface AccountAllowance {
1259
+ asset: string;
1260
+ /** Whether the backing is tracked and loaded */
1261
+ known: boolean;
1262
+ balance?: bigint;
1263
+ allowance?: bigint;
1264
+ liveUntil?: number;
1265
+ authorized?: boolean;
1266
+ pending?: boolean;
1267
+ /** min(balance, allowance) */
1268
+ available?: bigint;
1269
+ /** Remaining amount of the open orders selling the token */
1270
+ committed: bigint;
1271
+ }
1272
+
1273
+ export interface AccountFill {
1274
+ /** Order after the fill */
1275
+ order: AccountOrder;
1276
+ /** Amount of `selling` delivered */
1277
+ sold: bigint;
1278
+ /** Amount of `buying` received */
1279
+ bought: bigint;
1280
+ /** Taker address */
1281
+ taker: string;
1282
+ /** Trade id */
1283
+ trade: string;
1284
+ /** Trade time, UNIX milliseconds */
1285
+ ts: number;
1286
+ /** Whether the order is still open */
1287
+ partial: boolean;
1288
+ }
1289
+
1290
+ export interface AccountTradeParams {
1291
+ /** Token sent */
1292
+ selling: string;
1293
+ /** Token received */
1294
+ buying: string;
1295
+ /** `selling` amount of a sell, `buying` amount of a buy (raw units) */
1296
+ amount: bigint | string;
1297
+ /** Limit price, contract scale; omitted for a market order */
1298
+ price?: bigint | string;
1299
+ /** `Limit` by default, `Fill` for a market order */
1300
+ kind?: OrderKind;
1301
+ /** Expiration UNIX timestamp (seconds) of the resting remainder */
1302
+ expires?: number;
1303
+ /** Counter orders to cross, looked up automatically when omitted */
1304
+ orders?: Array<bigint | string>;
1305
+ /** Explicit approval (`null` for none), planned automatically when omitted */
1306
+ approve?: Approval | null;
1307
+ }
1308
+
1309
+ export interface AccountTradeResult {
1310
+ /** Amount of `selling` sent */
1311
+ sold: bigint;
1312
+ /** Amount of `buying` received */
1313
+ bought: bigint;
1314
+ /** ID of the order created for a limit remainder */
1315
+ orderId?: string;
1316
+ /** The created order (unconfirmed until the indexer reports it) */
1317
+ order?: AccountOrder;
1318
+ /** Approval granted with the trade */
1319
+ approve?: Approval;
1320
+ }
1321
+
1322
+ export interface AccountSwapParams {
1323
+ /** Token sent */
1324
+ selling: string;
1325
+ /** Token received */
1326
+ buying: string;
1327
+ /** `selling` amount of a sell, `buying` amount of a buy (raw units) */
1328
+ amount: bigint | string;
1329
+ /** `Sell` by default */
1330
+ direction?: TradeDirection;
1331
+ /** Price tolerance as a fraction (0.005 = 0.5%), 0 by default */
1332
+ slippage?: number;
1333
+ }
1334
+
1335
+ /** Market filter: a market key `x/y`, an {@link AxisMarket} or a pair of assets, in any order */
1336
+ export type AccountMarketFilter = string | {a: string, b: string} | string[];
1337
+
1338
+ /**
1339
+ * Trader wrapper that tracks every open order of an account across all markets and the account backing.
1340
+ * Create it with {@link Axis.account}.
1341
+ * Emits:
1342
+ * - `ready` - the account state was loaded
1343
+ * - `new` {@link AccountOrder} - an order was created (confirmed by the indexer)
1344
+ * - `pending` {@link AccountOrder} - an order created by this client, not reported by the indexer yet
1345
+ * - `fill` {@link AccountFill} - an order was partially filled
1346
+ * - `filled` {@link AccountFill} - an order was filled in full
1347
+ * - `update` {@link AccountOrder} - an order changed (amount, price, expiration, revived)
1348
+ * - `cancel` {@link AccountOrder} - an order was removed by the owner
1349
+ * - `expire` {@link AccountOrder} - an order expired
1350
+ * - `remove` {@link AccountOrder} - an order left the open orders (after `filled`, `cancel`, `expire`)
1351
+ * - `order` `{action, order, fill?}` - any order change
1352
+ * - `backing` `{asset, backing}` - the balance, allowance or the backing split of the orders selling a token changed
1353
+ * - `approve` `{asset, amount, liveUntil}` - a trading call is about to grant an allowance
1354
+ * - `trade` {@link ApiTrade} - the account performed a trade
1355
+ * - `swap` - the account performed a swap
1356
+ * - `change` - the open orders or the backing changed
1357
+ * - `error` `Error` - the push API rejected the account subscription
1358
+ */
1359
+ export declare class AxisAccount extends Emitter {
1360
+ /** Trader address */
1361
+ readonly address: string;
1362
+ /** Wallet signing callback, required to trade */
1363
+ signTransaction?: SignTransactionCallback;
1364
+ /** Open orders by id */
1365
+ readonly orders: Map<string, AccountOrder>;
1366
+ /** Account backing by token contract id */
1367
+ readonly backing: Map<string, AccountBacking>;
1368
+ /** Resolves once the account state has been loaded */
1369
+ readonly ready: Promise<void>;
1370
+ /** Whether the account state has been loaded */
1371
+ readonly loaded: boolean;
1372
+ /** Spendable balances in every tracked token by token contract id */
1373
+ readonly balances: Map<string, bigint>;
1374
+ /** Whether the account exists on the ledger; undefined until its XLM backing is known */
1375
+ readonly funded: boolean | undefined;
1376
+
1377
+ /**
1378
+ * Get spendable balance of the account in a token
1379
+ * @param asset - Token contract id
1380
+ * @returns Undefined if not tracked
1381
+ */
1382
+ getBalance(asset: string): bigint | undefined;
1383
+ /**
1384
+ * Retrieve open orders, newest first, including unconfirmed ones created by this client
1385
+ * @param filter - `market` is an {@link AxisMarket}, a market key or a pair of assets in any order
1386
+ */
1387
+ getOrders(filter?: {market?: AccountMarketFilter, selling?: string, buying?: string}): AccountOrder[];
1388
+ /** Get open order by id */
1389
+ getOrder(id: bigint | string): AccountOrder | undefined;
1390
+ /**
1391
+ * Calculate the remaining amount of the open orders selling the token across every market (what the allowance must
1392
+ * cover)
1393
+ * @param asset - Token contract id
1394
+ */
1395
+ committed(asset: string): bigint;
1396
+ /**
1397
+ * Get balance, allowance and commitments of the account in a token
1398
+ * @param asset - Token contract id
1399
+ */
1400
+ getAllowance(asset: string): AccountAllowance;
1401
+ /**
1402
+ * Sell tokens creating a limit remainder order if not executed in full (market order without `price`)
1403
+ * @param params - `amount` of `selling` to sell; `price` is the minimum `buying` per 1 `selling`
1404
+ */
1405
+ sell(params: AccountTradeParams): Promise<AccountTradeResult>;
1406
+ /**
1407
+ * Buy tokens creating a limit remainder order if not executed in full (market order without `price`)
1408
+ * @param params - `amount` of `buying` to acquire; `price` is the maximum `selling` per 1 `buying`
1409
+ */
1410
+ buy(params: AccountTradeParams): Promise<AccountTradeResult>;
1411
+ /**
1412
+ * Change the amount, price or expiration of open orders (omitted fields keep their current values); the allowance
1413
+ * is raised as needed
1414
+ * @returns Updated order ids
1415
+ */
1416
+ update(updates: Array<{id: bigint | string, amount?: bigint, price?: bigint, expires?: number}>): Promise<bigint[]>;
1417
+ /** Cancel open orders */
1418
+ cancel(ids: Array<bigint | string>): Promise<void>;
1419
+ /**
1420
+ * Cancel all open orders, optionally of one market
1421
+ * @returns Canceled order ids
1422
+ */
1423
+ cancelAll(filter?: {market?: AccountMarketFilter}): Promise<string[]>;
1424
+ /**
1425
+ * Fill an open order against the book while keeping profits from price inefficiencies
1426
+ * @param takerOrderId - Order acting as the taker
1427
+ * @param orders - Counter orders, looked up automatically when omitted
1428
+ */
1429
+ crossfill(takerOrderId: bigint | string, orders?: Array<bigint | string>): Promise<{sold: bigint, bought: bigint, surplus: bigint}>;
1430
+ /** Swap across one or several markets along the best route found by the Aggregator */
1431
+ swap(params: AccountSwapParams): Promise<{sold: bigint, bought: bigint, approve?: Approval}>;
1432
+ /**
1433
+ * Compute approval for a call
1434
+ * @param asset - Token contract id
1435
+ * @param required - Max amount the call may spend
1436
+ * @returns Undefined when the current allowance covers the call
1437
+ */
1438
+ planApproval(asset: string, required: bigint): Promise<{amount: bigint, liveUntil: number} | undefined>;
1439
+ /** Reload current account state from the REST API */
1440
+ refresh(): Promise<void>;
1441
+ /** Stop tracking this account */
1442
+ close(): void;
1443
+ }
1444
+
1445
+ /** Convert an API order to the client form (bigint amounts and prices, numeric timestamps) */
1446
+ export declare function parseApiOrder(raw: ApiOrder): AccountOrder;