@axis-markets/client 0.7.0 → 0.8.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.
@@ -1,102 +1,129 @@
1
- import type {xdr, Asset, rpc} from "@stellar/stellar-sdk";
2
-
3
- /** Upper bound of a serialized `Order` ledger entry in bytes */
4
- export declare const ORDER_ENTRY_SIZE: number;
5
- /** CPU instructions added to the declared budget per order not matched at simulation time */
6
- export declare const ORDER_INSTRUCTIONS: number;
7
- /** Resource fee (stroops) added per order not matched at simulation time */
8
- export declare const ORDER_RESOURCE_FEE: bigint;
9
- /** Upper bound of a maker balance or allowance ledger entry in bytes */
10
- export declare const MAKER_ENTRY_SIZE: number;
11
- /** Resource fee (stroops) added per maker entry declared read-write */
12
- export declare const MAKER_ENTRY_RESOURCE_FEE: bigint;
13
- /** CPU instructions added per maker whose entries were declared */
14
- export declare const MAKER_INSTRUCTIONS: number;
15
- /** Resource fee (stroops) added per maker whose entries were declared */
16
- export declare const MAKER_RESOURCE_FEE: bigint;
17
-
18
- /**
19
- * Flatten and deduplicate order ids from several lists, coercing them to bigint
20
- * @param idLists - Lists of order ids
21
- * @return Unique order ids in the order of first appearance
22
- */
23
- export declare function collectOrderIds(...idLists: Array<Array<bigint | number | string> | undefined | null>): bigint[];
24
-
25
- /**
26
- * Build the persistent contract data ledger key of an order (the key is the raw u128 order id)
27
- * @param contractId - DEX contract address
28
- * @param orderId - Order id
29
- */
30
- export declare function orderLedgerKey(contractId: string, orderId: bigint | number | string): xdr.LedgerKey;
31
-
32
- /**
33
- * Build the ledger key of a contract instance entry
34
- * @param contractId - Contract address
35
- */
36
- export declare function instanceLedgerKey(contractId: string): xdr.LedgerKey;
37
-
38
- /**
39
- * Build the ledger key holding the balance of `owner` in a Stellar Asset Contract token
40
- * @param owner - Account or contract address
41
- * @param token - Token contract address
42
- * @param asset - Classic asset behind the token, `null` for a token that is not a Stellar Asset Contract
43
- * @return `null` when the balance has no ledger entry of its own (issuer) or the token storage layout is unknown
44
- */
45
- export declare function balanceLedgerKey(owner: string, token: string, asset: Asset | null): xdr.LedgerKey | null;
46
-
47
- /**
48
- * Build the ledger key of the allowance `owner` granted to `spender` in a Stellar Asset Contract token
49
- * @param owner - Account or contract address granting the allowance
50
- * @param token - Token contract address
51
- * @param spender - Spender address (the DEX contract)
52
- */
53
- export declare function allowanceLedgerKey(owner: string, token: string, spender: string): xdr.LedgerKey;
54
-
55
- /**
56
- * Decode a stored order entry value: a positional vector `[owner, selling, buying, amount, price, expires?]`
57
- * @param val - Contract data value of the order entry
58
- */
59
- export declare function decodeStoredOrder(val: xdr.ScVal): {owner: string, selling: string, buying: string};
60
-
61
- /**
62
- * Resolve the classic asset behind a token from its contract instance entry
63
- * @param val - Contract data value of the token instance entry
64
- * @return `null` for a token that is not a Stellar Asset Contract
65
- */
66
- export declare function decodeSacAsset(val: xdr.ScVal): Asset | null;
67
-
68
- /**
69
- * Make sure every supplied order id is declared in the read-write footprint of a simulated transaction.
70
- * Patches the simulation data (footprint, resources, resource fee) in place and rebuilds `tx.built`.
71
- * @param tx - Simulated `AssembledTransaction` from `@stellar/stellar-sdk/contract`
72
- * @param contractId - DEX contract address
73
- * @param orderIds - Order ids passed to the contract call
74
- * @return Number of order entries added to the read-write footprint
75
- */
76
- export declare function ensureOrdersFootprint(tx: any, contractId: string, orderIds: Array<bigint | number | string>): number;
77
-
78
- export interface FootprintOptions {
79
- /** RPC server used to load the listed orders and the token instances */
80
- server: rpc.Server;
81
- /** Tokens the call trades, resolved together with the orders */
82
- tokens?: string[];
83
- /** Classic assets of resolved tokens (`null` for other tokens), reused between calls */
84
- assetCache?: Map<string, Asset | null>;
85
- }
86
-
87
- /**
88
- * Complete the footprint of a simulated trading transaction so it still applies when the book moves between simulation
89
- * and execution (an order repriced back into range, a maker's backing restored, an earlier order shrunk): every listed
90
- * order entry, and for every maker behind them the balance of the asset they sell, their allowance on it to the DEX
91
- * contract and the balance of the asset they receive, are declared read-write (orders first, in list order, while the
92
- * footprint limits allow). Makers of tokens that are not Stellar Asset Contracts keep what the simulation recorded
93
- * (their storage layout is unknown).
94
- * Patches the simulation data (footprint, resources including disk read bytes, resource fee) in place and rebuilds
95
- * `tx.built`.
96
- * @param tx - Simulated `AssembledTransaction` from `@stellar/stellar-sdk/contract`
97
- * @param contractId - DEX contract address
98
- * @param orderIds - Order ids passed to the contract call
99
- * @param options - RPC server, traded tokens and the asset cache
100
- * @return Number of order and maker entries added to the read-write footprint
101
- */
102
- export declare function completeFootprint(tx: any, contractId: string, orderIds: Array<bigint | number | string>, options: FootprintOptions): Promise<{orders: number, makerEntries: number}>;
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}>;