@axis-markets/client 0.5.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/README.md +351 -77
- 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 +2 -2
- package/src/allowance.js +46 -0
- package/src/api-client.js +95 -12
- package/src/api-dates.js +17 -0
- package/src/asset-pair.js +104 -0
- package/src/axis-account.js +970 -0
- package/src/axis-market.js +197 -0
- package/src/axis.js +408 -0
- package/src/constants.js +15 -0
- package/src/contract-client.js +47 -20
- package/src/emitter.js +71 -0
- package/src/errors.js +62 -29
- package/src/footprint.d.ts +72 -2
- package/src/footprint.js +326 -30
- package/src/index.d.ts +998 -75
- package/src/index.js +522 -265
- package/src/order-id.js +47 -0
- package/src/stream-client.js +327 -0
- package/src/token-balance.js +81 -0
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import type {rpc} from "@stellar/stellar-sdk";
|
|
2
|
+
|
|
3
|
+
/** Trading order type */
|
|
2
4
|
export enum OrderKind {
|
|
5
|
+
/** Execute trade, create a limit order if not executed in full */
|
|
3
6
|
Limit = 1,
|
|
7
|
+
/** Execute trade without creating a limit order */
|
|
4
8
|
Fill = 2,
|
|
9
|
+
/** Execute trade, cancel if was not executed in full */
|
|
5
10
|
FillOrKill = 3,
|
|
6
11
|
}
|
|
7
12
|
|
|
@@ -13,62 +18,169 @@ export enum TradeDirection {
|
|
|
13
18
|
|
|
14
19
|
/** Order properties, stored on-chain */
|
|
15
20
|
export interface Order {
|
|
16
|
-
/** Amount left to sell
|
|
21
|
+
/** Amount left to sell */
|
|
17
22
|
amount: bigint;
|
|
18
23
|
/** Buying token address */
|
|
19
24
|
buying: string;
|
|
20
|
-
/**
|
|
25
|
+
/** Expiration timestamp (0 = no expiration) */
|
|
21
26
|
expires: bigint;
|
|
22
|
-
/** Unique order identifier */
|
|
27
|
+
/** Unique order identifier, derived from the owner and the client nonce */
|
|
23
28
|
id: bigint;
|
|
24
|
-
/** Order type */
|
|
25
|
-
kind: OrderKind;
|
|
26
29
|
/** Maker address */
|
|
27
30
|
owner: string;
|
|
28
|
-
/** Order price */
|
|
31
|
+
/** Order price (`buying` per 1 `selling`, 18 decimals) */
|
|
29
32
|
price: bigint;
|
|
30
|
-
/** Initial selling/buying amount */
|
|
31
|
-
quote: bigint;
|
|
32
33
|
/** Selling token address */
|
|
33
34
|
selling: string;
|
|
34
35
|
}
|
|
35
36
|
|
|
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`) */
|
|
37
92
|
export interface TradeContractEvent {
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
/**
|
|
93
|
+
/** Asset sold by the taker (topic) */
|
|
94
|
+
selling: string;
|
|
95
|
+
/** Asset bought by the taker (topic) */
|
|
41
96
|
buying: string;
|
|
42
|
-
/**
|
|
43
|
-
|
|
97
|
+
/** Maker order id */
|
|
98
|
+
order: bigint;
|
|
99
|
+
/** Trader account address */
|
|
100
|
+
taker: string;
|
|
44
101
|
/** Seller account address */
|
|
45
102
|
maker: string;
|
|
46
|
-
/** Order id */
|
|
47
|
-
order: bigint;
|
|
48
|
-
/** Sold asset address */
|
|
49
|
-
selling: string;
|
|
50
103
|
/** Sold tokens amount */
|
|
51
104
|
sold: bigint;
|
|
52
|
-
/**
|
|
53
|
-
|
|
105
|
+
/** Bought tokens amount */
|
|
106
|
+
bought: bigint;
|
|
107
|
+
/** Order amount left after the fill (0 = removed) */
|
|
108
|
+
left: bigint;
|
|
54
109
|
}
|
|
55
110
|
|
|
56
|
-
/** Orderbook swap event */
|
|
111
|
+
/** Orderbook `swap` event, one per call (topics: `swap`, `selling`, `buying`) */
|
|
57
112
|
export interface SwapContractEvent {
|
|
58
|
-
/**
|
|
59
|
-
id: bigint;
|
|
60
|
-
/** Trader account address */
|
|
61
|
-
trader: string;
|
|
62
|
-
/** Sold asset address */
|
|
113
|
+
/** Asset sold by the trader (topic) */
|
|
63
114
|
selling: string;
|
|
64
|
-
/**
|
|
115
|
+
/** Asset received by the trader (topic) */
|
|
65
116
|
buying: string;
|
|
117
|
+
/** Trader account address */
|
|
118
|
+
trader: string;
|
|
66
119
|
/** Amount of `selling` tokens sold */
|
|
67
120
|
sold: bigint;
|
|
68
121
|
/** Amount of `buying` tokens received */
|
|
69
122
|
bought: bigint;
|
|
70
123
|
}
|
|
71
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
|
+
|
|
72
184
|
/** A trade step in a multi-market swap path. */
|
|
73
185
|
export interface TradeStep {
|
|
74
186
|
/** Asset to buy at this step */
|
|
@@ -81,12 +193,31 @@ export interface TradeStep {
|
|
|
81
193
|
export declare const ContractErrors: {
|
|
82
194
|
701: {message: "NotAuthorized"};
|
|
83
195
|
702: {message: "InsufficientBalance"};
|
|
84
|
-
703: {message: "
|
|
85
|
-
704: {message: "
|
|
86
|
-
705: {message: "
|
|
87
|
-
706: {message: "
|
|
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"};
|
|
88
211
|
}
|
|
89
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
|
+
|
|
90
221
|
export interface ClientInitializationParams {
|
|
91
222
|
/** Public key of the account that will interact with the contract */
|
|
92
223
|
publicKey: string;
|
|
@@ -100,7 +231,7 @@ export interface ClientInitializationParams {
|
|
|
100
231
|
networkPassphrase?: string;
|
|
101
232
|
/** Transaction fee (0.1 XLM by default) */
|
|
102
233
|
fee?: string;
|
|
103
|
-
/** Declare every supplied order id in the read-write footprint of trading transactions (enabled by default) */
|
|
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) */
|
|
104
235
|
autoFootprint?: boolean;
|
|
105
236
|
}
|
|
106
237
|
|
|
@@ -123,7 +254,11 @@ export interface TradeArguments {
|
|
|
123
254
|
/** Price a trader willing to accept */
|
|
124
255
|
price: bigint;
|
|
125
256
|
/** List of order IDs to match before creating the order on-chain */
|
|
126
|
-
orders
|
|
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;
|
|
127
262
|
}
|
|
128
263
|
|
|
129
264
|
export interface SellTradeArguments extends TradeArguments {
|
|
@@ -147,66 +282,154 @@ export interface SwapArguments {
|
|
|
147
282
|
trader: string,
|
|
148
283
|
/** Token address sent by the trader */
|
|
149
284
|
selling: string,
|
|
150
|
-
/**
|
|
285
|
+
/** Amount of selling tokens to send (`Sell`) or the maximum to spend (`Buy`) */
|
|
151
286
|
sellingAmount: bigint,
|
|
152
|
-
/** Minimum amount of buying tokens to receive */
|
|
287
|
+
/** Minimum amount of buying tokens to receive (`Sell`) or the exact amount (`Buy`) */
|
|
153
288
|
buyingAmount: bigint,
|
|
154
289
|
/** Ordered list of the trade route steps */
|
|
155
|
-
path: Array<TradeStep
|
|
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;
|
|
156
313
|
}
|
|
157
314
|
|
|
158
315
|
export declare class AxisContractClient {
|
|
159
316
|
constructor(params: ClientInitializationParams);
|
|
160
317
|
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
* @returns Last created order id
|
|
164
|
-
*/
|
|
165
|
-
last(): Promise<bigint>;
|
|
318
|
+
/** Account that signs and pays for the transactions */
|
|
319
|
+
readonly publicKey: string;
|
|
166
320
|
|
|
167
321
|
/**
|
|
168
322
|
* Fetch existing order
|
|
169
323
|
* @param id - ID of the order to fetch
|
|
170
|
-
* @returns Order fetched from the storage
|
|
324
|
+
* @returns Order fetched from the storage, undefined if not found or expired
|
|
171
325
|
*/
|
|
172
|
-
order(id: bigint): Promise<Order>;
|
|
326
|
+
order(id: bigint): Promise<Order | undefined>;
|
|
327
|
+
|
|
328
|
+
/** Fetch contract configuration */
|
|
329
|
+
loadConfig(): Promise<Config>;
|
|
173
330
|
|
|
174
331
|
/**
|
|
175
|
-
*
|
|
176
|
-
* @
|
|
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
|
|
177
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
|
|
178
364
|
*/
|
|
179
|
-
|
|
365
|
+
update(params: UpdateArguments): Promise<Array<bigint>>;
|
|
180
366
|
|
|
181
367
|
/**
|
|
182
|
-
* Fill existing orders
|
|
368
|
+
* Fill an existing order against matching orders from the orderbook. Profits from inefficiencies go to the trader
|
|
183
369
|
* @param trader - Trader address
|
|
184
370
|
* @param takerOrderId - ID of the order that serves as a taker
|
|
185
|
-
* @param orders - List of order IDs to match
|
|
186
|
-
* @returns Amount
|
|
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
|
|
187
376
|
*/
|
|
188
|
-
|
|
377
|
+
crossfill(trader: string, takerOrderId: bigint, orders: Array<bigint>): Promise<[bigint, bigint, bigint]>;
|
|
189
378
|
|
|
190
379
|
/**
|
|
191
|
-
* Trade with DEX and create buy limit order if quote not executed in full
|
|
380
|
+
* Trade with DEX and create a buy limit order if the quote not executed in full
|
|
192
381
|
* @param params - Trade parameters
|
|
193
|
-
* @returns Amount of sold
|
|
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
|
|
194
386
|
*/
|
|
195
|
-
buy(params: BuyTradeArguments): Promise<[bigint, bigint, bigint]>;
|
|
387
|
+
buy(params: BuyTradeArguments): Promise<[bigint, bigint, bigint | undefined]>;
|
|
196
388
|
|
|
197
389
|
/**
|
|
198
|
-
* Trade with DEX and create sell limit order if quote not executed in full
|
|
390
|
+
* Trade with DEX and create a sell limit order if the quote not executed in full
|
|
199
391
|
* @param params - Trade parameters
|
|
200
|
-
* @returns Amount of sold
|
|
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
|
|
201
396
|
*/
|
|
202
|
-
sell(params: SellTradeArguments): Promise<[bigint, bigint, bigint]>;
|
|
397
|
+
sell(params: SellTradeArguments): Promise<[bigint, bigint, bigint | undefined]>;
|
|
203
398
|
|
|
204
399
|
/**
|
|
205
|
-
* Swap tokens across several markets.
|
|
206
|
-
* @param params -
|
|
207
|
-
* @returns Amount of sold
|
|
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
|
|
208
406
|
*/
|
|
209
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>>;
|
|
210
433
|
}
|
|
211
434
|
|
|
212
435
|
/** Error thrown when the Aggregator API responds with a non-success HTTP status */
|
|
@@ -235,6 +458,8 @@ export interface QuotePathStep {
|
|
|
235
458
|
buying: string;
|
|
236
459
|
/** Maker order IDs matched at this hop */
|
|
237
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;
|
|
238
463
|
}
|
|
239
464
|
|
|
240
465
|
export interface QuotePath {
|
|
@@ -270,6 +495,10 @@ export interface DepthParams {
|
|
|
270
495
|
market: string;
|
|
271
496
|
/** Percentage band (±) around the center price (0 < depth ≤ 100, default 20) */
|
|
272
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;
|
|
273
502
|
}
|
|
274
503
|
|
|
275
504
|
export interface OrderbookDepth {
|
|
@@ -277,6 +506,12 @@ export interface OrderbookDepth {
|
|
|
277
506
|
ledger: number;
|
|
278
507
|
/** UNIX timestamp (seconds) */
|
|
279
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;
|
|
280
515
|
/** `[price, quantity]` pairs sorted descending by price */
|
|
281
516
|
bids: Array<[string, string]>;
|
|
282
517
|
/** `[price, quantity]` pairs sorted ascending by price */
|
|
@@ -349,10 +584,44 @@ export interface MarketInfo {
|
|
|
349
584
|
orderTypes: string[];
|
|
350
585
|
}
|
|
351
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
|
+
|
|
352
621
|
export interface OrdersParams {
|
|
353
622
|
/** Filter by order owner address */
|
|
354
623
|
owner?: string;
|
|
355
|
-
/** Filter by asset(s) -
|
|
624
|
+
/** Filter by asset(s) - every listed asset must be one of the order assets (two assets select a pair) */
|
|
356
625
|
asset?: string | string[];
|
|
357
626
|
/** Pagination cursor (order id) */
|
|
358
627
|
cursor?: string | bigint;
|
|
@@ -382,14 +651,64 @@ export interface TradesParams {
|
|
|
382
651
|
limit?: number | string;
|
|
383
652
|
}
|
|
384
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
|
+
|
|
385
706
|
/** Serialized order returned by the API */
|
|
386
707
|
export interface ApiOrder {
|
|
387
|
-
/** Order ID */
|
|
708
|
+
/** Order ID (decimal u128) */
|
|
388
709
|
id: string;
|
|
389
|
-
/** Order status
|
|
390
|
-
status:
|
|
391
|
-
/** Order kind (`LIMIT`) */
|
|
392
|
-
kind: string;
|
|
710
|
+
/** Order status: `ACTIVE`, `FILLED`, `CANCELED` (removed by the owner) or `EXPIRED` (archived once past `expires`) */
|
|
711
|
+
status: 'ACTIVE' | 'FILLED' | 'CANCELED' | 'EXPIRED';
|
|
393
712
|
/** Buying asset contract id */
|
|
394
713
|
buying: string;
|
|
395
714
|
/** Selling asset contract id */
|
|
@@ -398,18 +717,18 @@ export interface ApiOrder {
|
|
|
398
717
|
price: string;
|
|
399
718
|
/** Rational price representation */
|
|
400
719
|
rprice: string;
|
|
401
|
-
/**
|
|
720
|
+
/** Selling amount at creation */
|
|
402
721
|
quote: string;
|
|
403
|
-
/** Amount left to sell
|
|
722
|
+
/** Amount left to sell */
|
|
404
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;
|
|
405
728
|
/** Maker address */
|
|
406
729
|
owner: string;
|
|
407
730
|
/** Expiration timestamp (UTC) */
|
|
408
731
|
expires?: string;
|
|
409
|
-
/** Iceberg amount */
|
|
410
|
-
iceberg?: string;
|
|
411
|
-
/** Stop price */
|
|
412
|
-
stop?: string;
|
|
413
732
|
/** Creation timestamp (UTC) */
|
|
414
733
|
created?: string;
|
|
415
734
|
/** Last update timestamp (UTC) */
|
|
@@ -420,6 +739,8 @@ export interface ApiOrder {
|
|
|
420
739
|
|
|
421
740
|
/** Serialized trade returned by the API */
|
|
422
741
|
export interface ApiTrade {
|
|
742
|
+
/** Record type */
|
|
743
|
+
type: 'trade';
|
|
423
744
|
/** Trade ID */
|
|
424
745
|
id: string;
|
|
425
746
|
/** Matched order ID */
|
|
@@ -436,6 +757,8 @@ export interface ApiTrade {
|
|
|
436
757
|
sold: string;
|
|
437
758
|
/** Bought tokens amount */
|
|
438
759
|
bought: string;
|
|
760
|
+
/** Order amount left after the fill */
|
|
761
|
+
left?: string;
|
|
439
762
|
/** Approximate trade price */
|
|
440
763
|
price: string;
|
|
441
764
|
/** Pagination cursor */
|
|
@@ -456,6 +779,7 @@ export declare class AxisApiClient {
|
|
|
456
779
|
* Price quote and candidate trade routes for selling a fixed amount of the source asset
|
|
457
780
|
* @param params - Quote request parameters
|
|
458
781
|
* @returns Best routes ranked by profitability
|
|
782
|
+
* @throws {AxisApiError} If the server is not ready or there is not enough liquidity
|
|
459
783
|
*/
|
|
460
784
|
quoteSell(params: QuoteParams): Promise<QuoteResult>;
|
|
461
785
|
|
|
@@ -463,11 +787,13 @@ export declare class AxisApiClient {
|
|
|
463
787
|
* Price quote and candidate trade routes for buying a fixed amount of the destination asset
|
|
464
788
|
* @param params - Quote request parameters
|
|
465
789
|
* @returns Best routes ranked by profitability
|
|
790
|
+
* @throws {AxisApiError} If the server is not ready or there is not enough liquidity
|
|
466
791
|
*/
|
|
467
792
|
quoteBuy(params: QuoteParams): Promise<QuoteResult>;
|
|
468
793
|
|
|
469
794
|
/**
|
|
470
|
-
* Order book depth aggregated into price
|
|
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)
|
|
471
797
|
* @param params - Depth request parameters
|
|
472
798
|
* @returns Aggregated bids and asks
|
|
473
799
|
*/
|
|
@@ -493,6 +819,12 @@ export declare class AxisApiClient {
|
|
|
493
819
|
*/
|
|
494
820
|
getMarkets(params?: MarketsParams): Promise<MarketInfo[]>;
|
|
495
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
|
+
|
|
496
828
|
/**
|
|
497
829
|
* Retrieve active orders, filterable by owner or asset
|
|
498
830
|
* @param params - Filter parameters
|
|
@@ -500,12 +832,19 @@ export declare class AxisApiClient {
|
|
|
500
832
|
*/
|
|
501
833
|
getOrders(params?: OrdersParams): Promise<ApiOrder[]>;
|
|
502
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
|
+
|
|
503
842
|
/**
|
|
504
843
|
* Retrieve a single order by ID
|
|
505
844
|
* @param id - Order ID
|
|
506
|
-
* @returns Order
|
|
845
|
+
* @returns Order (throws `AxisApiError` with status 404 if not found)
|
|
507
846
|
*/
|
|
508
|
-
getOrder(id: bigint | string | number): Promise<ApiOrder
|
|
847
|
+
getOrder(id: bigint | string | number): Promise<ApiOrder>;
|
|
509
848
|
|
|
510
849
|
/**
|
|
511
850
|
* Retrieve archived/historical orders
|
|
@@ -521,3 +860,587 @@ export declare class AxisApiClient {
|
|
|
521
860
|
*/
|
|
522
861
|
getTrades(params?: TradesParams): Promise<ApiTrade[]>;
|
|
523
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;
|