@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/footprint.d.ts
CHANGED
|
@@ -1,102 +1,129 @@
|
|
|
1
|
-
import type {xdr, Asset, rpc} from "@stellar/stellar-sdk";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare const
|
|
9
|
-
/**
|
|
10
|
-
export declare const
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
export declare
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* @param
|
|
41
|
-
* @
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
* @
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* @param
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
1
|
+
import type {xdr, Asset, rpc} from "@stellar/stellar-sdk";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Upper bound of a serialized `Order` ledger entry in bytes.
|
|
5
|
+
* (positional vector of three addresses, i128 amount and price, optional u64 expires = at most 188-byte value,
|
|
6
|
+
* about 264-byte ledger entry, rounded up to 320).
|
|
7
|
+
*/
|
|
8
|
+
export declare const ORDER_ENTRY_SIZE: number;
|
|
9
|
+
/** CPU instructions added to the declared budget for every order that was not matched at simulation time. */
|
|
10
|
+
export declare const ORDER_INSTRUCTIONS: number;
|
|
11
|
+
/**
|
|
12
|
+
* Resource fee (stroops) added for every order that was not matched at simulation time.
|
|
13
|
+
* (write entry ~10k, read entry ~6k, writes ~12k, 2M instructions ~5k, trade/order events ~10k).
|
|
14
|
+
*/
|
|
15
|
+
export declare const ORDER_RESOURCE_FEE: bigint;
|
|
16
|
+
/** Upper bound of a maker balance (account, trustline or token balance) or allowance ledger entry in bytes. */
|
|
17
|
+
export declare const MAKER_ENTRY_SIZE: number;
|
|
18
|
+
/** Resource fee (stroops) added for every maker entry declared read-write (write entry ~10k, its bytes charged as written ~6k). */
|
|
19
|
+
export declare const MAKER_ENTRY_RESOURCE_FEE: bigint;
|
|
20
|
+
/** CPU instructions added for every maker whose entries were declared (two token transfers, backing and receive checks). */
|
|
21
|
+
export declare const MAKER_INSTRUCTIONS: number;
|
|
22
|
+
/**
|
|
23
|
+
* Resource fee (stroops) added for every maker whose entries were declared (instructions ~8k, two transfer events and
|
|
24
|
+
* a `skip` event ~4k, rounded up).
|
|
25
|
+
*/
|
|
26
|
+
export declare const MAKER_RESOURCE_FEE: bigint;
|
|
27
|
+
/**
|
|
28
|
+
* CPU instructions added when the settlement entries of the call were declared: the transfer forwarding what the makers
|
|
29
|
+
* delivered from the DEX contract to the receiver, and the receive checks before it.
|
|
30
|
+
*/
|
|
31
|
+
export declare const FORWARD_INSTRUCTIONS: number;
|
|
32
|
+
/**
|
|
33
|
+
* Resource fee (stroops) added when the settlement entries of the call were declared (instructions ~5k, the forwarding
|
|
34
|
+
* `transfer` event ~2k, rounded up).
|
|
35
|
+
*/
|
|
36
|
+
export declare const FORWARD_RESOURCE_FEE: bigint;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Flatten and deduplicate order ids from several lists, coercing them to bigint.
|
|
40
|
+
* @param idLists - Lists of order ids
|
|
41
|
+
* @returns Unique order ids in the order of first appearance
|
|
42
|
+
*/
|
|
43
|
+
export declare function collectOrderIds(...idLists: Array<Array<bigint | number | string> | undefined | null>): bigint[];
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Build persistent contract data ledger key of an order (the key is the raw u128 order id).
|
|
47
|
+
* @param contractId - DEX contract address
|
|
48
|
+
* @param orderId - Order id
|
|
49
|
+
*/
|
|
50
|
+
export declare function orderLedgerKey(contractId: string, orderId: bigint | number | string): xdr.LedgerKey;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Build the ledger key of a contract instance entry.
|
|
54
|
+
* @param contractId - Contract address
|
|
55
|
+
*/
|
|
56
|
+
export declare function instanceLedgerKey(contractId: string): xdr.LedgerKey;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Build the ledger key holding the balance of `owner` in a Stellar Asset Contract token.
|
|
60
|
+
* @param owner - Account or contract address
|
|
61
|
+
* @param token - Token contract address
|
|
62
|
+
* @param asset - Classic asset behind the token, `null` for a token that is not a Stellar Asset Contract
|
|
63
|
+
* @returns `null` when the balance has no ledger entry of its own (issuer) or the token storage layout is unknown
|
|
64
|
+
*/
|
|
65
|
+
export declare function balanceLedgerKey(owner: string, token: string, asset: Asset | null): xdr.LedgerKey | null;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Build the ledger key of the allowance `owner` granted to `spender` in a Stellar Asset Contract token.
|
|
69
|
+
* @param owner - Account or contract address granting the allowance
|
|
70
|
+
* @param token - Token contract address
|
|
71
|
+
* @param spender - Spender address (the DEX contract)
|
|
72
|
+
*/
|
|
73
|
+
export declare function allowanceLedgerKey(owner: string, token: string, spender: string): xdr.LedgerKey;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Decode a stored order entry value: a positional vector `[owner, selling, buying, amount, price, expires?]`.
|
|
77
|
+
* @param val - Contract data value of the order entry
|
|
78
|
+
*/
|
|
79
|
+
export declare function decodeStoredOrder(val: xdr.ScVal): {owner: string, selling: string, buying: string};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Resolve the classic asset behind a token from its contract instance entry.
|
|
83
|
+
* @param val - Contract data value of the token instance entry
|
|
84
|
+
* @returns `null` for a token that is not a Stellar Asset Contract
|
|
85
|
+
*/
|
|
86
|
+
export declare function decodeSacAsset(val: xdr.ScVal): Asset | null;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Make sure every supplied order id declared in the read-write footprint of a simulated transaction.
|
|
90
|
+
* @param tx - Simulated transaction
|
|
91
|
+
* @param contractId - DEX contract address
|
|
92
|
+
* @param orderIds - Order ids passed to the contract call
|
|
93
|
+
* @returns Number of order entries added to the read-write footprint
|
|
94
|
+
*/
|
|
95
|
+
export declare function ensureOrdersFootprint(tx: any, contractId: string, orderIds: Array<bigint | number | string>): number;
|
|
96
|
+
|
|
97
|
+
export interface FootprintOptions {
|
|
98
|
+
/** RPC server used to load the listed orders and the token instances */
|
|
99
|
+
server: rpc.Server;
|
|
100
|
+
/** Tokens the call trades, resolved together with the orders */
|
|
101
|
+
tokens?: string[];
|
|
102
|
+
/** Classic assets of resolved tokens (`null` for other tokens), reused between calls */
|
|
103
|
+
assetCache?: Map<string, Asset | null>;
|
|
104
|
+
/** Tokens the call moves through the DEX contract's own balance: the bought asset of a trade, every hop asset of a swap */
|
|
105
|
+
passThrough?: string[];
|
|
106
|
+
/** Account the bought asset is forwarded to (the trader, or the crossfill caller paid the surplus) */
|
|
107
|
+
receiver?: string;
|
|
108
|
+
/** Token the receiver gets (the taker order's `buying` by default for a crossfill) */
|
|
109
|
+
bought?: string;
|
|
110
|
+
/** Taker order of a crossfill: the asset it buys passes through the contract */
|
|
111
|
+
takerOrder?: bigint | number | string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Complete the footprint of a simulated trading transaction, so it still applies when the book moves between simulation
|
|
116
|
+
* and execution (an order repriced back into range, a maker's backing restored, an earlier order shrunk). Every listed
|
|
117
|
+
* order entry is declared read-write, then the entries the settlement writes for the call itself: the DEX contract's own
|
|
118
|
+
* balance of every asset passing through it (makers deliver to the contract, which forwards to the receiver) and the
|
|
119
|
+
* receiver's balance of the bought asset. Then, for every order's maker, the balance of the asset the maker sells, the
|
|
120
|
+
* allowance on it granted to the DEX contract, and the balance of the asset the maker receives. Tokens that are not
|
|
121
|
+
* Stellar Asset Contracts keep what the simulation recorded (their storage layout is unknown). Entries are added in that
|
|
122
|
+
* order while the footprint limits allow.
|
|
123
|
+
* @param tx - Simulated transaction
|
|
124
|
+
* @param contractId - DEX contract address
|
|
125
|
+
* @param orderIds - Order ids passed to the contract call
|
|
126
|
+
* @returns Number of order, settlement and
|
|
127
|
+
* maker entries added to the read-write footprint
|
|
128
|
+
*/
|
|
129
|
+
export declare function completeFootprint(tx: any, contractId: string, orderIds: Array<bigint | number | string>, options: FootprintOptions): Promise<{orders: number, settlementEntries: number, makerEntries: number}>;
|