@axis-markets/client 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +169 -100
- package/lib/axis-client.cjs +1 -1
- package/lib/axis-client.cjs.map +1 -1
- package/lib/footprint.cjs +1 -1
- package/lib/footprint.cjs.map +1 -1
- package/package.json +1 -1
- package/src/api-client.js +490 -423
- package/src/api-dates.js +1 -1
- package/src/axis-account.js +1009 -970
- package/src/axis-market.js +181 -197
- package/src/axis.js +409 -408
- package/src/contract-client.js +65 -63
- package/src/errors.js +131 -62
- package/src/footprint.d.ts +129 -102
- package/src/footprint.js +469 -419
- package/src/index.d.ts +347 -167
- package/src/index.js +249 -54
- package/src/order-id.js +47 -47
- package/src/stream-client.js +2 -2
package/src/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface Order {
|
|
|
22
22
|
amount: bigint;
|
|
23
23
|
/** Buying token address */
|
|
24
24
|
buying: string;
|
|
25
|
-
/** Expiration timestamp (0 = no expiration) */
|
|
25
|
+
/** Expiration UNIX timestamp in seconds (0 = no expiration) */
|
|
26
26
|
expires: bigint;
|
|
27
27
|
/** Unique order identifier, derived from the owner and the client nonce */
|
|
28
28
|
id: bigint;
|
|
@@ -36,7 +36,7 @@ export interface Order {
|
|
|
36
36
|
|
|
37
37
|
/** Token allowance granted to the contract as part of the call */
|
|
38
38
|
export interface Approval {
|
|
39
|
-
/** Token the allowance is granted on
|
|
39
|
+
/** Token the allowance is granted on */
|
|
40
40
|
asset?: string;
|
|
41
41
|
/** Absolute allowance amount (0 revokes the approval) */
|
|
42
42
|
amount: bigint;
|
|
@@ -58,21 +58,25 @@ export interface OrderUpdate {
|
|
|
58
58
|
|
|
59
59
|
/** Contract configuration */
|
|
60
60
|
export interface Config {
|
|
61
|
+
/** Address of the account allowed to freeze the contract and change the configuration */
|
|
62
|
+
safety_admin: string;
|
|
61
63
|
/** Oracle contract address */
|
|
62
64
|
oracle: string;
|
|
63
|
-
/**
|
|
65
|
+
/** Days of price feeds a new market must buy (0 opens markets without a fee) */
|
|
66
|
+
listing_min_days: number;
|
|
67
|
+
/** Amount of oracle fee tokens paid by the market creator to provision the oracle price feeds (the oracle daily fee x `listing_min_days`) */
|
|
64
68
|
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
69
|
/** Minimum trade value in USD, with 7 decimals precision (0 disables the limit) */
|
|
68
70
|
min_trade_size: bigint;
|
|
71
|
+
/** Expected average ledger close time in seconds, used to convert entry lifetimes into ledgers */
|
|
72
|
+
ledger_time: number;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
/** Market asset descriptor */
|
|
72
76
|
export interface MarketSide {
|
|
73
77
|
/** Token contract address */
|
|
74
78
|
asset: string;
|
|
75
|
-
/** Whether the asset is quoted by the oracle */
|
|
79
|
+
/** Whether the asset is quoted by the oracle (with token decimals the valuation can handle) */
|
|
76
80
|
listed: boolean;
|
|
77
81
|
/** Token decimals (fetched only for listed assets) */
|
|
78
82
|
decimals: number;
|
|
@@ -80,15 +84,15 @@ export interface MarketSide {
|
|
|
80
84
|
|
|
81
85
|
/** Market record, stored on-chain */
|
|
82
86
|
export interface Market {
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
/** Creation timestamp */
|
|
87
|
+
/** Base asset, the first of the pair in canonical order */
|
|
88
|
+
base: MarketSide;
|
|
89
|
+
/** Quote asset, the second of the pair in canonical order */
|
|
90
|
+
quote: MarketSide;
|
|
91
|
+
/** Creation UNIX timestamp in seconds */
|
|
88
92
|
created: bigint;
|
|
89
93
|
}
|
|
90
94
|
|
|
91
|
-
/** Orderbook `trade` event, one per fill
|
|
95
|
+
/** Orderbook `trade` event, one per fill */
|
|
92
96
|
export interface TradeContractEvent {
|
|
93
97
|
/** Asset sold by the taker (topic) */
|
|
94
98
|
selling: string;
|
|
@@ -108,7 +112,7 @@ export interface TradeContractEvent {
|
|
|
108
112
|
left: bigint;
|
|
109
113
|
}
|
|
110
114
|
|
|
111
|
-
/** Orderbook `swap` event, one per call
|
|
115
|
+
/** Orderbook `swap` event, one per call */
|
|
112
116
|
export interface SwapContractEvent {
|
|
113
117
|
/** Asset sold by the trader (topic) */
|
|
114
118
|
selling: string;
|
|
@@ -122,7 +126,7 @@ export interface SwapContractEvent {
|
|
|
122
126
|
bought: bigint;
|
|
123
127
|
}
|
|
124
128
|
|
|
125
|
-
/** Orderbook `new` event, an order created
|
|
129
|
+
/** Orderbook `new` event, an order created */
|
|
126
130
|
export interface OrderCreatedContractEvent {
|
|
127
131
|
/** Selling asset address (topic) */
|
|
128
132
|
selling: string;
|
|
@@ -136,11 +140,11 @@ export interface OrderCreatedContractEvent {
|
|
|
136
140
|
price: bigint;
|
|
137
141
|
/** Current amount */
|
|
138
142
|
amount: bigint;
|
|
139
|
-
/** Expiration timestamp (0 = no expiration) */
|
|
143
|
+
/** Expiration UNIX timestamp in seconds (0 = no expiration) */
|
|
140
144
|
expires: bigint;
|
|
141
145
|
}
|
|
142
146
|
|
|
143
|
-
/** Orderbook `mod` event, an order changed outside a fill
|
|
147
|
+
/** Orderbook `mod` event, an order changed outside a fill */
|
|
144
148
|
export interface OrderUpdatedContractEvent {
|
|
145
149
|
/** Unique order identifier */
|
|
146
150
|
id: bigint;
|
|
@@ -148,40 +152,44 @@ export interface OrderUpdatedContractEvent {
|
|
|
148
152
|
price: bigint;
|
|
149
153
|
/** Current amount (0 = removed) */
|
|
150
154
|
amount: bigint;
|
|
151
|
-
/** Expiration timestamp (0 = no expiration) */
|
|
155
|
+
/** Expiration UNIX timestamp in seconds (0 = no expiration) */
|
|
152
156
|
expires: bigint;
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
/**
|
|
156
|
-
* Orderbook `skip` event, a listed order its maker could not settle
|
|
157
|
-
* taker's asset, or the
|
|
160
|
+
* Orderbook `skip` event, a listed order its maker could not settle: backing short of the fill, a missing or
|
|
161
|
+
* deauthorized trustline for the taker's asset, or the maker's asset could not be collected. The order is left
|
|
162
|
+
* unchanged. For `crossfill` it also flags a taker order its owner cannot back or be paid for
|
|
158
163
|
*/
|
|
159
164
|
export interface OrderSkippedContractEvent {
|
|
160
165
|
/** Order id */
|
|
161
166
|
order: bigint;
|
|
162
167
|
}
|
|
163
168
|
|
|
164
|
-
/** Orderbook `refresh` event, a market checked against the oracle (topics: `refresh`, `
|
|
169
|
+
/** Orderbook `refresh` event, a market checked against the oracle (topics: `refresh`, `base`, `quote`, no data) */
|
|
165
170
|
export interface MarketRefreshContractEvent {
|
|
166
|
-
/**
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
|
|
171
|
+
/** Base market asset (canonical order, topic) */
|
|
172
|
+
base: string;
|
|
173
|
+
/** Quote market asset (canonical order, topic) */
|
|
174
|
+
quote: string;
|
|
170
175
|
}
|
|
171
176
|
|
|
172
|
-
/** `freeze` event
|
|
177
|
+
/** `freeze` event */
|
|
173
178
|
export interface FreezeContractEvent {
|
|
174
179
|
/** Whether trading is blocked after the call */
|
|
175
180
|
frozen: boolean;
|
|
176
181
|
}
|
|
177
182
|
|
|
178
|
-
/**
|
|
183
|
+
/**
|
|
184
|
+
* `config` update notification event (constructor, `delegate`, `set_oracle`, `set_floor`, `set_listing_min_days`,
|
|
185
|
+
* `set_ledger_time`)
|
|
186
|
+
*/
|
|
179
187
|
export interface ConfigChangedContractEvent {
|
|
180
188
|
/** Contract configuration after the call */
|
|
181
189
|
config: Config;
|
|
182
190
|
}
|
|
183
191
|
|
|
184
|
-
/** A trade step in a multi-market swap path
|
|
192
|
+
/** A trade step in a multi-market swap path */
|
|
185
193
|
export interface TradeStep {
|
|
186
194
|
/** Asset to buy at this step */
|
|
187
195
|
asset: string;
|
|
@@ -202,6 +210,7 @@ export declare const ContractErrors: {
|
|
|
202
210
|
709: {message: "NotFilled"};
|
|
203
211
|
710: {message: "OrderNotFound"};
|
|
204
212
|
711: {message: "OrderExists"};
|
|
213
|
+
712: {message: "IntermediaryCannotReceive"};
|
|
205
214
|
720: {message: "OrderSizeTooSmall"};
|
|
206
215
|
721: {message: "AssetsNotVerifiedByOracle"};
|
|
207
216
|
722: {message: "AssetPriceOracleFetchFailed"};
|
|
@@ -210,11 +219,30 @@ export declare const ContractErrors: {
|
|
|
210
219
|
740: {message: "Overflow"};
|
|
211
220
|
}
|
|
212
221
|
|
|
222
|
+
/** Errors of the Stellar Asset Contract, raised by the token transfers a trading call settles with */
|
|
223
|
+
export declare const TokenErrors: {
|
|
224
|
+
1: {message: "InternalError"};
|
|
225
|
+
2: {message: "OperationNotSupportedError"};
|
|
226
|
+
3: {message: "AlreadyInitializedError"};
|
|
227
|
+
4: {message: "UnauthorizedError"};
|
|
228
|
+
5: {message: "AuthenticationError"};
|
|
229
|
+
6: {message: "AccountMissingError"};
|
|
230
|
+
7: {message: "AccountIsNotClassic"};
|
|
231
|
+
8: {message: "NegativeAmountError"};
|
|
232
|
+
9: {message: "AllowanceError"};
|
|
233
|
+
10: {message: "BalanceError"};
|
|
234
|
+
11: {message: "BalanceDeauthorizedError"};
|
|
235
|
+
12: {message: "OverflowError"};
|
|
236
|
+
13: {message: "TrustlineMissingError"};
|
|
237
|
+
}
|
|
238
|
+
|
|
213
239
|
/**
|
|
214
|
-
* Compute the id of the order `owner` creates with `nonce
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* @param
|
|
240
|
+
* Compute the id of the order `owner` creates with `nonce`.
|
|
241
|
+
* Mirrors the contract: the first 16 bytes of `sha256(xdr(ScVec[owner: Address, nonce: u64]))`
|
|
242
|
+
* interpreted as a big-endian `u128` (the full 128 bits, no mask).
|
|
243
|
+
* @param owner - Order owner address (account or contract)
|
|
244
|
+
* @param nonce - Client-chosen u64 nonce
|
|
245
|
+
* @returns u128 order id
|
|
218
246
|
*/
|
|
219
247
|
export declare function orderId(owner: string, nonce: bigint | number | string): bigint;
|
|
220
248
|
|
|
@@ -229,16 +257,22 @@ export interface ClientInitializationParams {
|
|
|
229
257
|
contractId: string;
|
|
230
258
|
/** Network passphrase (Pubnet passphrase by default) */
|
|
231
259
|
networkPassphrase?: string;
|
|
232
|
-
/**
|
|
260
|
+
/** Inclusion fee bid in stroops (100,000 = 0.01 XLM by default), the simulated resource fee is added on top */
|
|
233
261
|
fee?: string;
|
|
234
262
|
/** 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
263
|
autoFootprint?: boolean;
|
|
236
264
|
}
|
|
237
265
|
|
|
266
|
+
/**
|
|
267
|
+
* Callback for signing transactions generated by the client (`@stellar/stellar-sdk` 17 contract client shape)
|
|
268
|
+
* @param xdr - Transaction XDR to sign
|
|
269
|
+
* @param opts - Signing options passed by the SDK
|
|
270
|
+
* @returns Signed transaction response
|
|
271
|
+
*/
|
|
238
272
|
export type SignTransactionCallback = (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
) => Promise<{signedTxXdr: string; signerAddress?: string}>;
|
|
273
|
+
xdr: string,
|
|
274
|
+
opts?: {networkPassphrase?: string; address?: string; submit?: boolean; submitUrl?: string}
|
|
275
|
+
) => Promise<{signedTxXdr: string; signerAddress?: string; error?: unknown}>;
|
|
242
276
|
|
|
243
277
|
export interface TradeArguments {
|
|
244
278
|
/** Trading order behavior */
|
|
@@ -275,6 +309,23 @@ export interface BuyTradeArguments extends TradeArguments {
|
|
|
275
309
|
price: bigint;
|
|
276
310
|
}
|
|
277
311
|
|
|
312
|
+
/** Simulated trade, nothing signed or submitted */
|
|
313
|
+
export interface TradeEstimate {
|
|
314
|
+
/** Maximum total network fee of the transaction, in stroops (inclusion fee bid plus resource fee) */
|
|
315
|
+
fee: bigint;
|
|
316
|
+
/** Inclusion fee bid, in stroops (the network charges the market rate up to it) */
|
|
317
|
+
inclusionFee: bigint;
|
|
318
|
+
/** Resource fee, in stroops, including the rent of an order created for the remainder */
|
|
319
|
+
resourceFee: bigint;
|
|
320
|
+
/** Expected amount of sold tokens */
|
|
321
|
+
sold: bigint;
|
|
322
|
+
/** Expected amount of bought tokens */
|
|
323
|
+
bought: bigint;
|
|
324
|
+
/** ID of the order the remainder would create */
|
|
325
|
+
orderId?: bigint;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** Swap path and settings */
|
|
278
329
|
export interface SwapArguments {
|
|
279
330
|
/** Trade direction: `Sell` or `Buy` */
|
|
280
331
|
direction: TradeDirection,
|
|
@@ -312,6 +363,7 @@ export interface SubsidizeArguments {
|
|
|
312
363
|
amount: bigint;
|
|
313
364
|
}
|
|
314
365
|
|
|
366
|
+
/** Smart contract client for trading with AXIS DEX */
|
|
315
367
|
export declare class AxisContractClient {
|
|
316
368
|
constructor(params: ClientInitializationParams);
|
|
317
369
|
|
|
@@ -319,23 +371,23 @@ export declare class AxisContractClient {
|
|
|
319
371
|
readonly publicKey: string;
|
|
320
372
|
|
|
321
373
|
/**
|
|
322
|
-
* Fetch existing order
|
|
374
|
+
* Fetch existing order.
|
|
323
375
|
* @param id - ID of the order to fetch
|
|
324
376
|
* @returns Order fetched from the storage, undefined if not found or expired
|
|
325
377
|
*/
|
|
326
378
|
order(id: bigint): Promise<Order | undefined>;
|
|
327
379
|
|
|
328
|
-
/** Fetch contract configuration */
|
|
380
|
+
/** Fetch contract configuration. */
|
|
329
381
|
loadConfig(): Promise<Config>;
|
|
330
382
|
|
|
331
383
|
/**
|
|
332
|
-
* Check whether the contract is frozen
|
|
384
|
+
* Check whether the contract is frozen.
|
|
333
385
|
* @returns `true` if contract is frozen (trading and order management operations blocked)
|
|
334
386
|
*/
|
|
335
387
|
isFrozen(): Promise<boolean>;
|
|
336
388
|
|
|
337
389
|
/**
|
|
338
|
-
* Fetch market for the given asset pair
|
|
390
|
+
* Fetch market for the given asset pair.
|
|
339
391
|
* @param selling - First market asset
|
|
340
392
|
* @param buying - Second market asset
|
|
341
393
|
* @returns Market record if the market exists
|
|
@@ -343,78 +395,90 @@ export declare class AxisContractClient {
|
|
|
343
395
|
getMarket(selling: string, buying: string): Promise<Market | undefined>;
|
|
344
396
|
|
|
345
397
|
/**
|
|
346
|
-
* Cancel existing orders, expired ones included
|
|
347
|
-
* `cancel`). A transaction can process up to 100 orders in one batch
|
|
398
|
+
* Cancel existing orders, expired ones included. A transaction can process up to 90 orders in one batch.
|
|
348
399
|
* @param trader - Trader address
|
|
349
400
|
* @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`
|
|
401
|
+
* @throws If trader is not the owner of any existing order in `ids` (works while the contract is frozen)
|
|
351
402
|
*/
|
|
352
403
|
cancel(trader: string, ids: Array<bigint>): Promise<void>;
|
|
353
404
|
|
|
354
405
|
/**
|
|
355
406
|
* Update the amount, price, or expiration of several orders in place, or remove them.
|
|
356
407
|
* 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
|
-
*
|
|
359
|
-
* orders in one batch
|
|
360
|
-
* @param params - Update parameters
|
|
408
|
+
* A zero amount removes the order, expired ones included. An updated order's entry lifetime is extended to cover its expiration +1 day.
|
|
409
|
+
* Approvals and removals work in a frozen contract and on a market without quoted assets.
|
|
410
|
+
* A transaction can process up to 90 orders in one batch.
|
|
361
411
|
* @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
|
-
*
|
|
412
|
+
* @throws If the trader does not own an updated order, if order parameters are invalid, if an order is below the minimum value,
|
|
413
|
+
* if the new amounts are not backed by the trader's balance and allowance, an update changes an order on the frozen or not-quoted market
|
|
364
414
|
*/
|
|
365
415
|
update(params: UpdateArguments): Promise<Array<bigint>>;
|
|
366
416
|
|
|
367
417
|
/**
|
|
368
|
-
* Fill an existing order against matching orders from the orderbook. Profits from inefficiencies go to the trader
|
|
418
|
+
* Fill an existing order against matching orders from the orderbook. Profits from inefficiencies go to the trader.
|
|
369
419
|
* @param trader - Trader address
|
|
370
420
|
* @param takerOrderId - ID of the order that serves as a taker
|
|
371
421
|
* @param orders - List of order IDs to match against
|
|
372
|
-
* @returns Amount the taker order sold, amount the
|
|
373
|
-
* @throws If the taker order does not exist or has expired, if
|
|
374
|
-
*
|
|
375
|
-
* frozen
|
|
422
|
+
* @returns Amount the taker order sold, amount the makers delivered, surplus paid to the trader.
|
|
423
|
+
* @throws If the taker order does not exist or has expired, if the trader cannot receive the bought asset, if the
|
|
424
|
+
* contract cannot hold the bought asset, if the contract is frozen.
|
|
376
425
|
*/
|
|
377
426
|
crossfill(trader: string, takerOrderId: bigint, orders: Array<bigint>): Promise<[bigint, bigint, bigint]>;
|
|
378
427
|
|
|
379
428
|
/**
|
|
380
|
-
* Trade with DEX and create a buy limit order if the quote not executed in full
|
|
381
|
-
* @param params - Trade parameters
|
|
429
|
+
* Trade with DEX and create a buy limit order if the quote not executed in full.
|
|
382
430
|
* @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
|
-
*
|
|
385
|
-
*
|
|
431
|
+
* @throws If the trader has insufficient balance or allowance, invalid `expires` field specified, a `Limit` trade targets a pair without a market,
|
|
432
|
+
* no reference price is available, a live order with the same id exists, the trader cannot receive `buying` (`CannotReceive`), or the contract
|
|
433
|
+
* cannot hold `buying` until its issuer authorizes it (`IntermediaryCannotReceive`).
|
|
386
434
|
*/
|
|
387
435
|
buy(params: BuyTradeArguments): Promise<[bigint, bigint, bigint | undefined]>;
|
|
388
436
|
|
|
389
437
|
/**
|
|
390
|
-
* Trade with DEX and create a sell limit order if the quote not executed in full
|
|
391
|
-
* @param params - Trade parameters
|
|
438
|
+
* Trade with DEX and create a sell limit order if the quote not executed in full.
|
|
392
439
|
* @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
|
-
*
|
|
395
|
-
*
|
|
440
|
+
* @throws If the trader has insufficient balance or allowance, invalid `expires` field specified, a `Limit` trade targets a pair without a market,
|
|
441
|
+
* no reference price is available, a live order with the same id exists, the trader cannot receive `buying` (`CannotReceive`), or the contract
|
|
442
|
+
* cannot hold `buying` until its issuer authorizes it (`IntermediaryCannotReceive`).
|
|
396
443
|
*/
|
|
397
444
|
sell(params: SellTradeArguments): Promise<[bigint, bigint, bigint | undefined]>;
|
|
398
445
|
|
|
399
446
|
/**
|
|
400
|
-
*
|
|
401
|
-
* @
|
|
447
|
+
* Simulate a buy trade without signing or submitting it, to show the network fee before the trade.
|
|
448
|
+
* @throws If the simulation fails, for the same reasons as `buy`
|
|
449
|
+
*/
|
|
450
|
+
estimateBuy(params: BuyTradeArguments): Promise<TradeEstimate>;
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Simulate a sell trade without signing or submitting it, to show the network fee before the trade.
|
|
454
|
+
* @throws If the simulation fails, for the same reasons as `sell`
|
|
455
|
+
*/
|
|
456
|
+
estimateSell(params: SellTradeArguments): Promise<TradeEstimate>;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Swap tokens across several markets. The contract holds the intermediate hop proceeds only within the call.
|
|
402
460
|
* @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,
|
|
404
|
-
*
|
|
405
|
-
* receive tokens, if the contract is frozen
|
|
461
|
+
* @throws If the route cannot satisfy the selling/buying amount, if `path` is empty or an amount is invalid,
|
|
462
|
+
* if the contract cannot hold an asset of the path, if the contract is frozen.
|
|
406
463
|
*/
|
|
407
464
|
swap(params: SwapArguments): Promise<[bigint, bigint]>;
|
|
408
465
|
|
|
409
|
-
/**
|
|
410
|
-
|
|
466
|
+
/**
|
|
467
|
+
* Extend the contract instance and code lifetime with an `ExtendFootprintTTL` operation, restoring the archived
|
|
468
|
+
* ones first with a `RestoreFootprint` transaction.
|
|
469
|
+
* @param days - Lifetime in days, 30 by default, at most the network maximum (180 days on mainnet)
|
|
470
|
+
* @returns Ledger sequence both entries live at least until
|
|
471
|
+
* @throws If `days` is invalid, if the instance is not found, if a simulation or a transaction fails
|
|
472
|
+
*/
|
|
473
|
+
keepalive(days?: number): Promise<number>;
|
|
411
474
|
|
|
412
475
|
/**
|
|
413
476
|
* 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
|
|
415
|
-
* outstanding orders stay cancellable and fillable. The record and the
|
|
416
|
-
* change. When the simulation writes nothing (the market and the
|
|
417
|
-
* newer price), the simulated result is
|
|
477
|
+
* A cached price is valid for up to 72 hours. A market without quoted assets stops accepting
|
|
478
|
+
* new limit orders; its outstanding orders stay cancellable and fillable. The record and the
|
|
479
|
+
* cached prices are rewritten only when they change. When the simulation writes nothing (the market and the
|
|
480
|
+
* cached prices are current, or the oracle has no newer price), the simulated result is
|
|
481
|
+
* returned and no transaction is submitted.
|
|
418
482
|
* @param selling - First market asset
|
|
419
483
|
* @param buying - Second market asset
|
|
420
484
|
* @returns Updated market record, undefined if the market does not exist
|
|
@@ -423,17 +487,20 @@ export declare class AxisContractClient {
|
|
|
423
487
|
requote(selling: string, buying: string): Promise<Market | undefined>;
|
|
424
488
|
|
|
425
489
|
/**
|
|
426
|
-
* Extend oracle price feeds access for a market, creating the market if it does not exist yet
|
|
427
|
-
* @param params - Subsidy parameters
|
|
490
|
+
* Extend oracle price feeds access for a market, creating the market if it does not exist yet.
|
|
428
491
|
* @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
|
|
430
|
-
* neither market asset is quoted by the oracle, if the contract is frozen
|
|
492
|
+
* @throws If `amount` is invalid, if `selling` equals `buying`, if the market does not exist and the amount is below
|
|
493
|
+
* the market listing fee, if neither market asset is quoted by the oracle, if the contract is frozen
|
|
431
494
|
*/
|
|
432
495
|
subsidize(params: SubsidizeArguments): Promise<Array<bigint>>;
|
|
433
496
|
}
|
|
434
497
|
|
|
435
|
-
/** Error thrown when the
|
|
498
|
+
/** Error thrown when the AXIS API responds with a non-success HTTP status */
|
|
436
499
|
export declare class AxisApiError extends Error {
|
|
500
|
+
/**
|
|
501
|
+
* @param message - Error message returned by the API
|
|
502
|
+
* @param status - HTTP status code
|
|
503
|
+
*/
|
|
437
504
|
constructor(message: string, status: number);
|
|
438
505
|
|
|
439
506
|
/** HTTP status code associated with the error */
|
|
@@ -449,6 +516,12 @@ export interface QuoteParams {
|
|
|
449
516
|
amount: string | number;
|
|
450
517
|
/** Restrict to the direct market only (no intermediate-asset routes) */
|
|
451
518
|
direct?: boolean;
|
|
519
|
+
/**
|
|
520
|
+
* Highest maker price to cross (requires `direct`), in the units of a hop `worstPrice`: `sellingAsset` per unit of
|
|
521
|
+
* `buyingAsset`, scaled by 10^18. Quotes the crossing of a limit order: orders priced above it are left out and the
|
|
522
|
+
* route may trade less than `amount`
|
|
523
|
+
*/
|
|
524
|
+
maxPrice?: bigint | string;
|
|
452
525
|
}
|
|
453
526
|
|
|
454
527
|
export interface QuotePathStep {
|
|
@@ -584,24 +657,26 @@ export interface MarketInfo {
|
|
|
584
657
|
orderTypes: string[];
|
|
585
658
|
}
|
|
586
659
|
|
|
587
|
-
/** Contract configuration tracked by the indexer */
|
|
588
660
|
export interface ContractInfoConfig {
|
|
589
661
|
/** Safety admin address */
|
|
590
662
|
safetyAdmin: string;
|
|
591
663
|
/** Price oracle contract address */
|
|
592
664
|
oracle: string;
|
|
593
|
-
/**
|
|
665
|
+
/** Days of price feeds a new market must buy (0 opens markets without a fee) */
|
|
666
|
+
listingMinDays?: number;
|
|
667
|
+
/** Oracle fee tokens a market creator pays to provision the price feeds */
|
|
594
668
|
marketListingFee: string;
|
|
595
669
|
/** Minimum trade value in USD with 7 decimals (0 = disabled) */
|
|
596
670
|
minTradeSize: string;
|
|
671
|
+
/** Expected ledger close time in seconds */
|
|
672
|
+
ledgerTime?: number;
|
|
597
673
|
}
|
|
598
674
|
|
|
599
|
-
/** Market tracked by the indexer */
|
|
600
675
|
export interface ContractInfoMarket {
|
|
601
|
-
/**
|
|
602
|
-
|
|
603
|
-
/**
|
|
604
|
-
|
|
676
|
+
/** Base market asset, the first of the pair in canonical order */
|
|
677
|
+
base: string;
|
|
678
|
+
/** Quote market asset, the second of the pair in canonical order */
|
|
679
|
+
quote: string;
|
|
605
680
|
/** Creation timestamp (UTC) */
|
|
606
681
|
created: string;
|
|
607
682
|
/** Last oracle check timestamp (UTC) */
|
|
@@ -623,7 +698,7 @@ export interface OrdersParams {
|
|
|
623
698
|
owner?: string;
|
|
624
699
|
/** Filter by asset(s) - every listed asset must be one of the order assets (two assets select a pair) */
|
|
625
700
|
asset?: string | string[];
|
|
626
|
-
/**
|
|
701
|
+
/** `cursor` of the last order received (its creation position, not the order id) */
|
|
627
702
|
cursor?: string | bigint;
|
|
628
703
|
/** Max orders to return */
|
|
629
704
|
limit?: number | string;
|
|
@@ -634,7 +709,7 @@ export interface OrderHistoryParams {
|
|
|
634
709
|
owner?: string;
|
|
635
710
|
/** Asset pair `[base, quote]` (contract ids) */
|
|
636
711
|
pair?: string[];
|
|
637
|
-
/**
|
|
712
|
+
/** `cursor` of the last order received (its creation position, not the order id) */
|
|
638
713
|
cursor?: string | bigint;
|
|
639
714
|
/** Max orders to return */
|
|
640
715
|
limit?: number | string;
|
|
@@ -645,7 +720,7 @@ export interface TradesParams {
|
|
|
645
720
|
trader?: string;
|
|
646
721
|
/** Asset pair `[base, quote]` (contract ids) */
|
|
647
722
|
pair?: string[];
|
|
648
|
-
/**
|
|
723
|
+
/** `cursor` of the last record received (the trade or swap id) */
|
|
649
724
|
cursor?: string | bigint;
|
|
650
725
|
/** Max trades to return */
|
|
651
726
|
limit?: number | string;
|
|
@@ -683,6 +758,11 @@ export interface ApiBacking {
|
|
|
683
758
|
authorized: boolean;
|
|
684
759
|
/** Effective budget, min(balance, allowance), 0 when unauthorized or expired */
|
|
685
760
|
budget: string;
|
|
761
|
+
/**
|
|
762
|
+
* Amount the account can still receive (trustline limit minus balance and buying
|
|
763
|
+
* liabilities), omitted when unlimited or unknown
|
|
764
|
+
*/
|
|
765
|
+
headroom?: string;
|
|
686
766
|
/** Last load timestamp (UTC) */
|
|
687
767
|
updated?: string;
|
|
688
768
|
/** Last `skip` event of an order selling the token (UTC) */
|
|
@@ -737,6 +817,30 @@ export interface ApiOrder {
|
|
|
737
817
|
cursor?: string;
|
|
738
818
|
}
|
|
739
819
|
|
|
820
|
+
/** Serialized swap returned by the API, one per `swap` call */
|
|
821
|
+
export interface ApiSwap {
|
|
822
|
+
/** Record type */
|
|
823
|
+
type: 'swap';
|
|
824
|
+
/** Swap ID */
|
|
825
|
+
id: string;
|
|
826
|
+
/** Trader address */
|
|
827
|
+
trader: string;
|
|
828
|
+
/** Sold asset contract id */
|
|
829
|
+
soldAsset: string;
|
|
830
|
+
/** Bought asset contract id */
|
|
831
|
+
boughtAsset: string;
|
|
832
|
+
/** Sold tokens amount */
|
|
833
|
+
sold: string;
|
|
834
|
+
/** Bought tokens amount */
|
|
835
|
+
bought: string;
|
|
836
|
+
/** Approximate swap price */
|
|
837
|
+
price: string;
|
|
838
|
+
/** Pagination cursor */
|
|
839
|
+
cursor: string;
|
|
840
|
+
/** Swap timestamp (UTC) */
|
|
841
|
+
timestamp: string;
|
|
842
|
+
}
|
|
843
|
+
|
|
740
844
|
/** Serialized trade returned by the API */
|
|
741
845
|
export interface ApiTrade {
|
|
742
846
|
/** Record type */
|
|
@@ -759,6 +863,11 @@ export interface ApiTrade {
|
|
|
759
863
|
bought: string;
|
|
760
864
|
/** Order amount left after the fill */
|
|
761
865
|
left?: string;
|
|
866
|
+
/**
|
|
867
|
+
* The fill of a `crossfill` taker order: `taker` is the caller, paid the surplus, and the amounts mirror the makers'
|
|
868
|
+
* fills of the same call (left out of candles and volume)
|
|
869
|
+
*/
|
|
870
|
+
crossfill?: boolean;
|
|
762
871
|
/** Approximate trade price */
|
|
763
872
|
price: string;
|
|
764
873
|
/** Pagination cursor */
|
|
@@ -767,19 +876,74 @@ export interface ApiTrade {
|
|
|
767
876
|
timestamp: string;
|
|
768
877
|
}
|
|
769
878
|
|
|
770
|
-
|
|
879
|
+
export interface FailuresParams {
|
|
880
|
+
/** Caller of the failed transaction, or a party of the failed transfer */
|
|
881
|
+
account?: string;
|
|
882
|
+
/** Contract function (`trade`, `swap`, `crossfill`, `update`, ...) */
|
|
883
|
+
fn?: string;
|
|
884
|
+
/** `cursor` of the last record received */
|
|
885
|
+
cursor?: string | bigint;
|
|
886
|
+
/** Max records to return (20 by default, at most 500) */
|
|
887
|
+
limit?: number | string;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Failed AXIS call (made by the transaction or through another contract, the transaction failed
|
|
892
|
+
* or a calling contract caught the failure). It changes no state and blames no party:
|
|
893
|
+
* a token error on a settlement transfer does not tell the payer who could not pay from the recipient who could not be
|
|
894
|
+
* credited (e.g. a full trustline), and in a `crossfill` the makers are paid by the taker order owner, not the caller
|
|
895
|
+
*/
|
|
896
|
+
export interface ApiFailure {
|
|
897
|
+
/** Record type */
|
|
898
|
+
type: 'failure';
|
|
899
|
+
/** Record id (position of the transaction plus the index of the failed call) */
|
|
900
|
+
id: string;
|
|
901
|
+
/** Transaction hash */
|
|
902
|
+
txHash: string;
|
|
903
|
+
/** Ledger sequence */
|
|
904
|
+
ledger: number;
|
|
905
|
+
/** Ledger close time (UTC) */
|
|
906
|
+
timestamp: string;
|
|
907
|
+
/** Contract function called */
|
|
908
|
+
fn: string;
|
|
909
|
+
/** The `trader` or `sponsor` argument, the transaction source for other functions */
|
|
910
|
+
caller: string;
|
|
911
|
+
/** Maker order ids listed by the call */
|
|
912
|
+
orders: string[];
|
|
913
|
+
/** Taker order id of a `crossfill` */
|
|
914
|
+
takerOrder?: string;
|
|
915
|
+
/** Operation result code */
|
|
916
|
+
result: string;
|
|
917
|
+
/** The transaction succeeded: a calling contract caught the failed AXIS call */
|
|
918
|
+
caught?: boolean;
|
|
919
|
+
/**
|
|
920
|
+
* `contract`: a contract error (`error`), `transfer`: a token transfer failed (`transfer`, either side may be at
|
|
921
|
+
* fault), `resources`: a resource limit, the refundable fee or an archived entry, `auth`: an authorization failure,
|
|
922
|
+
* `unknown`: no diagnostic events
|
|
923
|
+
*/
|
|
924
|
+
reason: 'contract' | 'transfer' | 'resources' | 'auth' | 'unknown';
|
|
925
|
+
/** Contract error that failed the call */
|
|
926
|
+
error?: {contract: string | null, code: number, name?: string};
|
|
927
|
+
/** Token transfer that failed */
|
|
928
|
+
transfer?: {token: string, fn: string, from: string, to: string, amount: string};
|
|
929
|
+
/** Pagination cursor */
|
|
930
|
+
cursor: string;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/** HTTP client for the AXIS REST API */
|
|
771
934
|
export declare class AxisApiClient {
|
|
772
|
-
/** @param serverUrl - Base URL of the
|
|
935
|
+
/** @param serverUrl - Base URL of the AXIS API server */
|
|
773
936
|
constructor(serverUrl: string);
|
|
774
937
|
|
|
775
|
-
/** Base URL of the
|
|
938
|
+
/** Base URL of the AXIS API server */
|
|
776
939
|
readonly serverUrl: string;
|
|
777
940
|
|
|
778
941
|
/**
|
|
779
942
|
* Price quote and candidate trade routes for selling a fixed amount of the source asset
|
|
780
943
|
* @param params - Quote request parameters
|
|
781
944
|
* @returns Best routes ranked by profitability
|
|
782
|
-
* @throws {AxisApiError}
|
|
945
|
+
* @throws {AxisApiError} 409 if the server is not ready or routing fails, 400 on invalid parameters. Not enough
|
|
946
|
+
* liquidity resolves with `status: 'unfeasible'`, a frozen contract with `status: 'rejected'`
|
|
783
947
|
*/
|
|
784
948
|
quoteSell(params: QuoteParams): Promise<QuoteResult>;
|
|
785
949
|
|
|
@@ -787,7 +951,8 @@ export declare class AxisApiClient {
|
|
|
787
951
|
* Price quote and candidate trade routes for buying a fixed amount of the destination asset
|
|
788
952
|
* @param params - Quote request parameters
|
|
789
953
|
* @returns Best routes ranked by profitability
|
|
790
|
-
* @throws {AxisApiError}
|
|
954
|
+
* @throws {AxisApiError} 409 if the server is not ready or routing fails, 400 on invalid parameters. Not enough
|
|
955
|
+
* liquidity resolves with `status: 'unfeasible'`, a frozen contract with `status: 'rejected'`
|
|
791
956
|
*/
|
|
792
957
|
quoteBuy(params: QuoteParams): Promise<QuoteResult>;
|
|
793
958
|
|
|
@@ -842,7 +1007,7 @@ export declare class AxisApiClient {
|
|
|
842
1007
|
/**
|
|
843
1008
|
* Retrieve a single order by ID
|
|
844
1009
|
* @param id - Order ID
|
|
845
|
-
* @returns Order (throws
|
|
1010
|
+
* @returns Order (throws AxisApiError with status 404 if not found)
|
|
846
1011
|
*/
|
|
847
1012
|
getOrder(id: bigint | string | number): Promise<ApiOrder>;
|
|
848
1013
|
|
|
@@ -854,11 +1019,18 @@ export declare class AxisApiClient {
|
|
|
854
1019
|
getOrderHistory(params?: OrderHistoryParams): Promise<ApiOrder[]>;
|
|
855
1020
|
|
|
856
1021
|
/**
|
|
857
|
-
* Retrieve recent trades
|
|
1022
|
+
* Retrieve recent trades and swaps, newest first
|
|
1023
|
+
* @param params - Filter parameters
|
|
1024
|
+
* @returns Recent trades and swaps matching the filter (told apart by `type`)
|
|
1025
|
+
*/
|
|
1026
|
+
getTrades(params?: TradesParams): Promise<Array<ApiTrade | ApiSwap>>;
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* Failed AXIS calls, newest first (diagnostics: a failure changes no state, and a record never blames a party, see
|
|
1030
|
+
* {@link ApiFailure})
|
|
858
1031
|
* @param params - Filter parameters
|
|
859
|
-
* @returns Recent trades matching the filter
|
|
860
1032
|
*/
|
|
861
|
-
|
|
1033
|
+
getFailures(params?: FailuresParams): Promise<ApiFailure[]>;
|
|
862
1034
|
}
|
|
863
1035
|
|
|
864
1036
|
/** Price scale of the contract (18 decimals) */
|
|
@@ -900,7 +1072,7 @@ export declare function invertPrice(price: bigint): bigint;
|
|
|
900
1072
|
export declare function invertTicker(entry: TickerEntry): TickerEntry;
|
|
901
1073
|
|
|
902
1074
|
/**
|
|
903
|
-
* Parse an
|
|
1075
|
+
* Parse an AXIS API timestamp (`YYYY-MM-DD HH:mm:ss` UTC)
|
|
904
1076
|
* @returns UNIX milliseconds, 0 when missing or invalid
|
|
905
1077
|
*/
|
|
906
1078
|
export declare function parseApiDate(value: string | number | undefined): number;
|
|
@@ -958,7 +1130,6 @@ export declare class Emitter {
|
|
|
958
1130
|
export interface StreamMessage {
|
|
959
1131
|
type: string;
|
|
960
1132
|
topic?: string;
|
|
961
|
-
/** Echoed request id (snapshots and errors) */
|
|
962
1133
|
id?: number;
|
|
963
1134
|
[key: string]: any;
|
|
964
1135
|
}
|
|
@@ -975,11 +1146,12 @@ export interface StreamClientOptions {
|
|
|
975
1146
|
}
|
|
976
1147
|
|
|
977
1148
|
/**
|
|
978
|
-
* WebSocket client of the
|
|
1149
|
+
* WebSocket client of the AXIS API push channel
|
|
1150
|
+
*
|
|
979
1151
|
* Emits `open`, `close` and `error` (server errors not tied to a subscription).
|
|
980
1152
|
*/
|
|
981
1153
|
export declare class AxisStreamClient extends Emitter {
|
|
982
|
-
/** @param url - WebSocket endpoint, e.g. `wss://api.axis.markets/ws` */
|
|
1154
|
+
/** @param url - WebSocket endpoint, e.g. `wss://demo-api.axis.markets/ws` (testnet) */
|
|
983
1155
|
constructor(url: string, options?: StreamClientOptions);
|
|
984
1156
|
|
|
985
1157
|
/** WebSocket endpoint */
|
|
@@ -989,10 +1161,10 @@ export declare class AxisStreamClient extends Emitter {
|
|
|
989
1161
|
|
|
990
1162
|
/**
|
|
991
1163
|
* Subscribe to a channel; connects on the first subscription
|
|
992
|
-
* @param
|
|
993
|
-
*
|
|
994
|
-
* @param handler - Receives the snapshot (again after every reconnect), the
|
|
995
|
-
* server rejects the subscription
|
|
1164
|
+
* @param params -
|
|
1165
|
+
* Channel parameters
|
|
1166
|
+
* @param handler - Receives the snapshot (again after every reconnect), the
|
|
1167
|
+
* changes, and `{type: 'error'}` if the server rejects the subscription
|
|
996
1168
|
* @returns Unsubscribe function
|
|
997
1169
|
*/
|
|
998
1170
|
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;
|
|
@@ -1032,32 +1204,33 @@ export interface Signer {
|
|
|
1032
1204
|
}
|
|
1033
1205
|
|
|
1034
1206
|
export interface AxisOptions {
|
|
1035
|
-
/**
|
|
1207
|
+
/** AXIS REST API URL */
|
|
1036
1208
|
apiUrl: string;
|
|
1037
1209
|
/** AXIS contract address */
|
|
1038
1210
|
contractId: string;
|
|
1039
|
-
/**
|
|
1211
|
+
/** AXIS API push channel URL (`<apiUrl>/ws` with the `ws(s)` scheme by default) */
|
|
1040
1212
|
wsUrl?: string;
|
|
1041
|
-
/** Stellar RPC URL
|
|
1213
|
+
/** Stellar RPC URL */
|
|
1042
1214
|
rpcUrl?: string;
|
|
1043
1215
|
/** Network passphrase (Pubnet by default) */
|
|
1044
1216
|
networkPassphrase?: string;
|
|
1045
1217
|
/** Transaction fee */
|
|
1046
1218
|
fee?: string;
|
|
1047
|
-
/** Default signer settings for contract operations
|
|
1219
|
+
/** Default signer settings for contract operations */
|
|
1048
1220
|
signer?: Signer;
|
|
1049
|
-
/** REST polling period while the push connection is down, in milliseconds
|
|
1221
|
+
/** REST polling period while the push connection is down, in milliseconds */
|
|
1050
1222
|
fallbackPollInterval?: number;
|
|
1051
|
-
/** WebSocket implementation
|
|
1223
|
+
/** WebSocket implementation */
|
|
1052
1224
|
WebSocket?: typeof WebSocket;
|
|
1053
1225
|
}
|
|
1054
1226
|
|
|
1055
1227
|
/**
|
|
1056
|
-
* High-level AXIS DEX state
|
|
1228
|
+
* High-level AXIS DEX state
|
|
1229
|
+
*
|
|
1057
1230
|
* Emits:
|
|
1058
1231
|
* - `change` - anything in the contract state changed
|
|
1059
1232
|
* - `frozen` `boolean` - the frozen state toggled
|
|
1060
|
-
* - `config` {
|
|
1233
|
+
* - `config` {ContractInfoConfig} - contract configuration changed
|
|
1061
1234
|
* - `market` `{market: AxisMarket, created: boolean}` - a market was opened or updated
|
|
1062
1235
|
* - `connection` `boolean` - WebSocket push connection opened or dropped
|
|
1063
1236
|
* - `ledger` `number` - new ledger processed by the indexer
|
|
@@ -1065,41 +1238,42 @@ export interface AxisOptions {
|
|
|
1065
1238
|
export declare class Axis extends Emitter {
|
|
1066
1239
|
constructor(options: AxisOptions);
|
|
1067
1240
|
|
|
1068
|
-
/**
|
|
1241
|
+
/** AXIS REST API client */
|
|
1069
1242
|
readonly api: AxisApiClient;
|
|
1070
|
-
/**
|
|
1243
|
+
/** AXIS API WebSocket client */
|
|
1071
1244
|
readonly stream: AxisStreamClient;
|
|
1072
|
-
/** Token balance wrappers
|
|
1245
|
+
/** Token balance wrappers */
|
|
1073
1246
|
readonly tokenBalances: TokenBalance | undefined;
|
|
1074
1247
|
/** Contract address of the native XLM token */
|
|
1075
1248
|
readonly nativeAsset: string;
|
|
1076
|
-
/** Last known ledger
|
|
1249
|
+
/** Last known ledger */
|
|
1077
1250
|
readonly ledger: number;
|
|
1078
|
-
/**
|
|
1251
|
+
/** Last updated UNIX milliseconds */
|
|
1079
1252
|
readonly ledgerTime: number;
|
|
1080
1253
|
/** Whether trading is suspended */
|
|
1081
1254
|
readonly frozen: boolean;
|
|
1082
|
-
/** Contract configuration
|
|
1255
|
+
/** Contract configuration */
|
|
1083
1256
|
readonly config: ContractInfoConfig | undefined;
|
|
1084
|
-
/** Available AXIS markets
|
|
1257
|
+
/** Available AXIS markets */
|
|
1085
1258
|
readonly markets: Map<string, AxisMarket>;
|
|
1086
|
-
/** 24h ticker entries
|
|
1259
|
+
/** 24h ticker entries */
|
|
1087
1260
|
readonly tickers: Map<string, TickerEntry>;
|
|
1088
1261
|
/** Whether the contract state loaded */
|
|
1089
1262
|
readonly loaded: boolean;
|
|
1090
1263
|
|
|
1091
1264
|
/** Load the contract state and track its changes */
|
|
1092
1265
|
connect(): Promise<Axis>;
|
|
1093
|
-
/** Current ledger sequence
|
|
1266
|
+
/** Current ledger sequence */
|
|
1094
1267
|
getLedger(): Promise<number>;
|
|
1095
1268
|
/**
|
|
1096
|
-
* Get market of the asset pair
|
|
1269
|
+
* Get market of the asset pair
|
|
1097
1270
|
* @param asset1 - Token contract address
|
|
1098
1271
|
* @param asset2 - Token contract address
|
|
1099
1272
|
*/
|
|
1100
1273
|
getMarket(asset1: string, asset2: string): AxisMarket | undefined;
|
|
1101
1274
|
/**
|
|
1102
|
-
* Get live order by id
|
|
1275
|
+
* Get live order by id
|
|
1276
|
+
* @param id - Order id
|
|
1103
1277
|
* @returns Undefined if not found (filled, removed, expired)
|
|
1104
1278
|
*/
|
|
1105
1279
|
getOrder(id: bigint | string): Promise<AccountOrder | undefined>;
|
|
@@ -1110,16 +1284,17 @@ export declare class Axis extends Emitter {
|
|
|
1110
1284
|
*/
|
|
1111
1285
|
account(address: string, options?: {signTransaction?: SignTransactionCallback}): AxisAccount;
|
|
1112
1286
|
/**
|
|
1113
|
-
* Stream the 24h ticker of every market
|
|
1287
|
+
* Stream the 24h ticker of every market
|
|
1114
1288
|
* Sends a full snapshot, then updates caused by trades
|
|
1115
1289
|
* @returns Unsubscribe function
|
|
1116
1290
|
*/
|
|
1117
1291
|
subscribeTicker(callback?: (ticker: Ticker24hResult) => void): () => void;
|
|
1118
1292
|
/**
|
|
1119
|
-
* Extend the contract instance and code lifetime
|
|
1120
|
-
* @param
|
|
1293
|
+
* Extend the contract instance and code lifetime with an `ExtendFootprintTTL` operation, restoring them first if archived
|
|
1294
|
+
* @param params - Lifetime in days (30 by default) and the transaction source (the default signer by default)
|
|
1295
|
+
* @returns Ledger sequence both entries live until, at least
|
|
1121
1296
|
*/
|
|
1122
|
-
keepalive(signer?: Signer): Promise<
|
|
1297
|
+
keepalive(params?: {days?: number; signer?: Signer}): Promise<number>;
|
|
1123
1298
|
/** Stop following the contract state and tracked accounts */
|
|
1124
1299
|
close(): void;
|
|
1125
1300
|
}
|
|
@@ -1127,23 +1302,19 @@ export declare class Axis extends Emitter {
|
|
|
1127
1302
|
/** Derive the push API endpoint from the REST API URL */
|
|
1128
1303
|
export declare function toWsUrl(apiUrl: string): string;
|
|
1129
1304
|
|
|
1130
|
-
/** DEX Market
|
|
1305
|
+
/** DEX Market */
|
|
1131
1306
|
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`) */
|
|
1307
|
+
/** Base asset, the first of the pair in the contract canonical order */
|
|
1139
1308
|
readonly base: string;
|
|
1140
|
-
/** Quote asset
|
|
1309
|
+
/** Quote asset, the second of the pair in the contract canonical order */
|
|
1141
1310
|
readonly quote: string;
|
|
1311
|
+
/** Canonical market key `base/quote` */
|
|
1312
|
+
readonly key: string;
|
|
1142
1313
|
/** Creation timestamp (first oracle check) (UNIX milliseconds) */
|
|
1143
1314
|
readonly created: number;
|
|
1144
1315
|
/** Last oracle check (UNIX milliseconds) */
|
|
1145
1316
|
readonly refreshed: number;
|
|
1146
|
-
/** Last 24h ticker entry of the market, available while {@link Axis
|
|
1317
|
+
/** Last 24h ticker entry of the market, available while {@link Axis#subscribeTicker} runs */
|
|
1147
1318
|
readonly ticker: TickerEntry | undefined;
|
|
1148
1319
|
|
|
1149
1320
|
/** Check whether the asset is one of the market assets */
|
|
@@ -1151,7 +1322,6 @@ export declare class AxisMarket {
|
|
|
1151
1322
|
/**
|
|
1152
1323
|
* The other market asset
|
|
1153
1324
|
* @param asset - One of the market assets
|
|
1154
|
-
* @throws If the asset does not belong to the market
|
|
1155
1325
|
*/
|
|
1156
1326
|
counter(asset: string): string;
|
|
1157
1327
|
/**
|
|
@@ -1167,28 +1337,27 @@ export declare class AxisMarket {
|
|
|
1167
1337
|
subsidize(params: {amount: bigint, sponsor?: string, signer?: Signer}): Promise<bigint[]>;
|
|
1168
1338
|
/**
|
|
1169
1339
|
* Orderbook depth data with given precision
|
|
1170
|
-
* @param params - `base` is the base asset
|
|
1340
|
+
* @param params - `base` is the base asset, `step` the price step (automatic by default)
|
|
1171
1341
|
*/
|
|
1172
1342
|
getDepth(params?: {base?: string, depth?: number, step?: string, limit?: number}): Promise<OrderbookDepth>;
|
|
1173
1343
|
/**
|
|
1174
|
-
* Stream the orderbook depth
|
|
1344
|
+
* Stream the orderbook depth
|
|
1175
1345
|
* Returns a snapshot, then updates on book changes
|
|
1176
1346
|
* @returns Unsubscribe function
|
|
1177
1347
|
*/
|
|
1178
1348
|
subscribeDepth(params: {base?: string, depth?: number, step?: string, limit?: number}, callback: (depth: OrderbookDepth) => void): () => void;
|
|
1179
1349
|
/**
|
|
1180
|
-
* Stream the market trades
|
|
1350
|
+
* Stream the market trades
|
|
1181
1351
|
* Returns a snapshot, then updates on trades
|
|
1182
1352
|
* @param callback - Trades and whether they are the snapshot
|
|
1183
1353
|
* @returns Unsubscribe function
|
|
1184
1354
|
*/
|
|
1185
1355
|
subscribeTrades(callback: (trades: ApiTrade[], snapshot: boolean) => void): () => void;
|
|
1186
1356
|
/**
|
|
1187
|
-
* Stream the market candles
|
|
1357
|
+
* Stream the market candles
|
|
1188
1358
|
* 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
|
-
*
|
|
1191
|
-
* @param callback - Candles and whether they are the snapshot
|
|
1359
|
+
* @param params - `base` is the base asset of the view, `resolution` in seconds or an alias (`5m`, `1h`, …), `limit` the candles in the snapshot (200 by default, at most 200)
|
|
1360
|
+
* @param callback - Candles
|
|
1192
1361
|
* @returns Unsubscribe function
|
|
1193
1362
|
*/
|
|
1194
1363
|
subscribeCandles(params: {base?: string, resolution: number | string, limit?: number}, callback: (candles: Candle[], snapshot: boolean) => void): () => void;
|
|
@@ -1204,7 +1373,7 @@ export interface AccountOrder {
|
|
|
1204
1373
|
selling: string;
|
|
1205
1374
|
/** Bought token */
|
|
1206
1375
|
buying: string;
|
|
1207
|
-
/** Market key
|
|
1376
|
+
/** Market key */
|
|
1208
1377
|
market: string;
|
|
1209
1378
|
/** Current status */
|
|
1210
1379
|
status: 'ACTIVE' | 'FILLED' | 'CANCELED' | 'EXPIRED';
|
|
@@ -1222,7 +1391,7 @@ export interface AccountOrder {
|
|
|
1222
1391
|
updated: number;
|
|
1223
1392
|
/** Paging cursor (undefined for unconfirmed local orders) */
|
|
1224
1393
|
cursor?: bigint;
|
|
1225
|
-
/** Share of the account budget in `selling` that backs the order
|
|
1394
|
+
/** Share of the account budget in `selling` that backs the order */
|
|
1226
1395
|
backed: bigint | null;
|
|
1227
1396
|
/** `backed / amount` (0..1), null when unknown */
|
|
1228
1397
|
backedPct: number | null;
|
|
@@ -1296,13 +1465,13 @@ export interface AccountTradeParams {
|
|
|
1296
1465
|
amount: bigint | string;
|
|
1297
1466
|
/** Limit price, contract scale; omitted for a market order */
|
|
1298
1467
|
price?: bigint | string;
|
|
1299
|
-
/** `Limit` by default, `Fill` for a market order */
|
|
1468
|
+
/** {@link OrderKind}: `Limit` by default, `Fill` for a market order */
|
|
1300
1469
|
kind?: OrderKind;
|
|
1301
1470
|
/** Expiration UNIX timestamp (seconds) of the resting remainder */
|
|
1302
1471
|
expires?: number;
|
|
1303
1472
|
/** Counter orders to cross, looked up automatically when omitted */
|
|
1304
1473
|
orders?: Array<bigint | string>;
|
|
1305
|
-
/** Explicit approval (`null` for none)
|
|
1474
|
+
/** Explicit approval (`null` for none) */
|
|
1306
1475
|
approve?: Approval | null;
|
|
1307
1476
|
}
|
|
1308
1477
|
|
|
@@ -1326,18 +1495,19 @@ export interface AccountSwapParams {
|
|
|
1326
1495
|
buying: string;
|
|
1327
1496
|
/** `selling` amount of a sell, `buying` amount of a buy (raw units) */
|
|
1328
1497
|
amount: bigint | string;
|
|
1329
|
-
/** `Sell` by default */
|
|
1498
|
+
/** {@link TradeDirection}, `Sell` by default */
|
|
1330
1499
|
direction?: TradeDirection;
|
|
1331
1500
|
/** Price tolerance as a fraction (0.005 = 0.5%), 0 by default */
|
|
1332
1501
|
slippage?: number;
|
|
1333
1502
|
}
|
|
1334
1503
|
|
|
1335
1504
|
/** Market filter: a market key `x/y`, an {@link AxisMarket} or a pair of assets, in any order */
|
|
1336
|
-
export type AccountMarketFilter = string | {
|
|
1505
|
+
export type AccountMarketFilter = string | {base: string, quote: string} | string[];
|
|
1337
1506
|
|
|
1338
1507
|
/**
|
|
1339
1508
|
* Trader wrapper that tracks every open order of an account across all markets and the account backing.
|
|
1340
|
-
* Create it with {@link Axis
|
|
1509
|
+
* Create it with {@link import('./axis.js').Axis#account}.
|
|
1510
|
+
*
|
|
1341
1511
|
* Emits:
|
|
1342
1512
|
* - `ready` - the account state was loaded
|
|
1343
1513
|
* - `new` {@link AccountOrder} - an order was created (confirmed by the indexer)
|
|
@@ -1351,8 +1521,8 @@ export type AccountMarketFilter = string | {a: string, b: string} | string[];
|
|
|
1351
1521
|
* - `order` `{action, order, fill?}` - any order change
|
|
1352
1522
|
* - `backing` `{asset, backing}` - the balance, allowance or the backing split of the orders selling a token changed
|
|
1353
1523
|
* - `approve` `{asset, amount, liveUntil}` - a trading call is about to grant an allowance
|
|
1354
|
-
* - `trade` {
|
|
1355
|
-
* - `swap` - the account performed a swap
|
|
1524
|
+
* - `trade` {ApiTrade} - the account performed a trade
|
|
1525
|
+
* - `swap` {ApiSwap} - the account performed a swap
|
|
1356
1526
|
* - `change` - the open orders or the backing changed
|
|
1357
1527
|
* - `error` `Error` - the push API rejected the account subscription
|
|
1358
1528
|
*/
|
|
@@ -1369,9 +1539,9 @@ export declare class AxisAccount extends Emitter {
|
|
|
1369
1539
|
readonly ready: Promise<void>;
|
|
1370
1540
|
/** Whether the account state has been loaded */
|
|
1371
1541
|
readonly loaded: boolean;
|
|
1372
|
-
/**
|
|
1542
|
+
/** Get spendable balances in every tracked token by token contract id */
|
|
1373
1543
|
readonly balances: Map<string, bigint>;
|
|
1374
|
-
/** Whether the account exists on the ledger
|
|
1544
|
+
/** Whether the account exists on the ledger */
|
|
1375
1545
|
readonly funded: boolean | undefined;
|
|
1376
1546
|
|
|
1377
1547
|
/**
|
|
@@ -1381,8 +1551,8 @@ export declare class AxisAccount extends Emitter {
|
|
|
1381
1551
|
*/
|
|
1382
1552
|
getBalance(asset: string): bigint | undefined;
|
|
1383
1553
|
/**
|
|
1384
|
-
* Retrieve open orders, newest first
|
|
1385
|
-
* @param filter - `market` is an {
|
|
1554
|
+
* Retrieve open orders, newest first
|
|
1555
|
+
* @param filter - `market` is an {AxisMarket} or a pair of assets in any order
|
|
1386
1556
|
*/
|
|
1387
1557
|
getOrders(filter?: {market?: AccountMarketFilter, selling?: string, buying?: string}): AccountOrder[];
|
|
1388
1558
|
/** Get open order by id */
|
|
@@ -1399,25 +1569,36 @@ export declare class AxisAccount extends Emitter {
|
|
|
1399
1569
|
*/
|
|
1400
1570
|
getAllowance(asset: string): AccountAllowance;
|
|
1401
1571
|
/**
|
|
1402
|
-
* Sell tokens creating a limit remainder order if not executed in full
|
|
1572
|
+
* Sell tokens creating a limit remainder order if not executed in full
|
|
1403
1573
|
* @param params - `amount` of `selling` to sell; `price` is the minimum `buying` per 1 `selling`
|
|
1404
1574
|
*/
|
|
1405
1575
|
sell(params: AccountTradeParams): Promise<AccountTradeResult>;
|
|
1406
1576
|
/**
|
|
1407
|
-
* Buy tokens creating a limit remainder order if not executed in full
|
|
1577
|
+
* Buy tokens creating a limit remainder order if not executed in full
|
|
1408
1578
|
* @param params - `amount` of `buying` to acquire; `price` is the maximum `selling` per 1 `buying`
|
|
1409
1579
|
*/
|
|
1410
1580
|
buy(params: AccountTradeParams): Promise<AccountTradeResult>;
|
|
1411
1581
|
/**
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1582
|
+
* Simulate a sell with the same crossing and approval as `sell`, without signing or submitting it
|
|
1583
|
+
* @param params - Same as `sell`
|
|
1584
|
+
* @returns Network fee and expected result
|
|
1585
|
+
*/
|
|
1586
|
+
estimateSell(params: AccountTradeParams): Promise<TradeEstimate>;
|
|
1587
|
+
/**
|
|
1588
|
+
* Simulate a buy with the same crossing and approval as `buy`, without signing or submitting it
|
|
1589
|
+
* @param params - Same as `buy`
|
|
1590
|
+
* @returns Network fee and expected result
|
|
1591
|
+
*/
|
|
1592
|
+
estimateBuy(params: AccountTradeParams): Promise<TradeEstimate>;
|
|
1593
|
+
/**
|
|
1594
|
+
* Change the amount, price or expiration of open orders (omitted fields keep their current values)
|
|
1414
1595
|
* @returns Updated order ids
|
|
1415
1596
|
*/
|
|
1416
1597
|
update(updates: Array<{id: bigint | string, amount?: bigint, price?: bigint, expires?: number}>): Promise<bigint[]>;
|
|
1417
1598
|
/** Cancel open orders */
|
|
1418
1599
|
cancel(ids: Array<bigint | string>): Promise<void>;
|
|
1419
1600
|
/**
|
|
1420
|
-
* Cancel all open orders
|
|
1601
|
+
* Cancel all open orders
|
|
1421
1602
|
* @returns Canceled order ids
|
|
1422
1603
|
*/
|
|
1423
1604
|
cancelAll(filter?: {market?: AccountMarketFilter}): Promise<string[]>;
|
|
@@ -1427,13 +1608,12 @@ export declare class AxisAccount extends Emitter {
|
|
|
1427
1608
|
* @param orders - Counter orders, looked up automatically when omitted
|
|
1428
1609
|
*/
|
|
1429
1610
|
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
|
|
1611
|
+
/** Swap across one or several markets along the best route found by the AXIS API */
|
|
1431
1612
|
swap(params: AccountSwapParams): Promise<{sold: bigint, bought: bigint, approve?: Approval}>;
|
|
1432
1613
|
/**
|
|
1433
1614
|
* Compute approval for a call
|
|
1434
1615
|
* @param asset - Token contract id
|
|
1435
1616
|
* @param required - Max amount the call may spend
|
|
1436
|
-
* @returns Undefined when the current allowance covers the call
|
|
1437
1617
|
*/
|
|
1438
1618
|
planApproval(asset: string, required: bigint): Promise<{amount: bigint, liveUntil: number} | undefined>;
|
|
1439
1619
|
/** Reload current account state from the REST API */
|