@stellar-broker/client 0.6.14 → 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.
package/src/index.d.ts CHANGED
@@ -1,277 +1,294 @@
1
- import {Asset, TransactionI} from "@stellar/stellar-sdk";
2
-
3
- /**
4
- * Client for StellarBroker service
5
- */
6
- export class StellarBrokerClient {
7
- /**
8
- * @param {ClientInitializationParams} params
9
- */
10
- constructor(params: ClientInitializationParams);
11
-
12
- /**
13
- * Trader account public key
14
- * @type {string}
15
- */
16
- readonly trader: string;
17
- /**
18
- * Stellar network passphrase
19
- * @type {string}
20
- */
21
- readonly network: string;
22
- /**
23
- * @type {ClientSessionStatus}
24
- */
25
- readonly status: ClientSessionStatus;
26
-
27
- /**
28
- * Connect to the StellarBroker server
29
- * @return {Promise<StellarBrokerClient>}
30
- */
31
- connect(): Promise<StellarBrokerClient>;
32
-
33
- /**
34
- * Request swap quote
35
- * @param {QuoteParams} params - Quote parameters
36
- */
37
- quote(params: QuoteParams): void;
38
-
39
- /**
40
- * Stop quotation/trading
41
- */
42
- stop(): void;
43
-
44
- /**
45
- * Confirm current quote and start trading
46
- * @param {string} [account] - Trader account address (overrides value provided in the constructor)
47
- * @param {ClientAuthorizationParams} [authorization] - Authorization params (overrides value provided in the constructor)
48
- */
49
- confirmQuote(account?: string, authorization?: ClientAuthorizationParams): void;
50
-
51
- /**
52
- * Add event listener
53
- * @param {StellarBrokerClientEvent} type
54
- * @param {function} callback
55
- */
56
- on(type: StellarBrokerClientEvent, callback: Function): void;
57
-
58
- /**
59
- * Add event listener that will be executed once
60
- * @param {StellarBrokerClientEvent} type
61
- * @param {function} callback
62
- */
63
- once(type: StellarBrokerClientEvent, callback: Function): void;
64
-
65
- /**
66
- * Remove event listener
67
- * @param {StellarBrokerClientEvent} type
68
- * @param {function} callback
69
- */
70
- off(type: StellarBrokerClientEvent, callback: Function): void;
71
-
72
- /**
73
- * Close underlying connection and finalize the client
74
- */
75
- close(): void;
76
- }
77
-
78
- /**
79
- * Request single swap quote estimate without trading
80
- */
81
- export function estimateSwap(params: QuoteParams): Promise<QuoteResult>;
82
-
83
- /**
84
- * Quote request parameters provided by the client
85
- */
86
- export interface QuoteParams {
87
- /**
88
- * Asset to sell
89
- */
90
- sellingAsset: string
91
- /**
92
- * Asset to buy
93
- */
94
- buyingAsset: string
95
- /**
96
- * Amount of selling asset
97
- */
98
- sellingAmount?: string
99
- /**
100
- * Swap slippage tolerance (0.02 by default - 2%)
101
- */
102
- slippageTolerance?: number
103
- }
104
-
105
- export interface ClientInitializationParams {
106
- /**
107
- * Partner key
108
- */
109
- partnerKey?: string;
110
- /**
111
- * Trader account address
112
- */
113
- account?: string;
114
- /**
115
- * Authorization method, either account secret key or an authorization callback
116
- */
117
- authorization?: ClientAuthorizationParams;
118
- }
119
-
120
- /**
121
- * Current client session status
122
- */
123
- export type ClientSessionStatus = "disconnected" | "ready" | "quote" | "trade";
124
-
125
- /**
126
- * Event type generated by the client
127
- */
128
- export type StellarBrokerClientEvent = "quote" | "progress" | "paused" | "finished" | "error";
129
-
130
- /**
131
- * Result status code returned by the server
132
- */
133
- export type QuoteResultStatus = "unfeasible" | "rejected" | "success";
134
-
135
- /**
136
- * Quote received from the server
137
- */
138
- export interface QuoteResult {
139
- /**
140
- * Quote timestamp
141
- */
142
- readonly ts: Date,
143
- /**
144
- * Quote status code
145
- */
146
- readonly status: QuoteResultStatus;
147
- /**
148
- * Asset to sell
149
- */
150
- readonly sellingAsset: string;
151
- /**
152
- * Asset to buy
153
- */
154
- readonly buyingAsset: string;
155
- /**
156
- * Swap slippage tolerance
157
- */
158
- readonly slippageTolerance: number;
159
- /**
160
- * Amount of the selling asset
161
- */
162
- readonly sellingAmount: string;
163
- /**
164
- * Estimated amount of buyingAsset to receive
165
- */
166
- readonly estimatedBuyingAmount?: string;
167
- /**
168
- * Equivalent direct path_payment trade estimate
169
- */
170
- readonly directTrade?: QuoteDirectTradeResult;
171
- /**
172
- * Difference between quoted price and estimated direct trade
173
- */
174
- readonly profit: string;
175
- /**
176
- * Error details from the server (for failed quotes)
177
- */
178
- readonly error?: string;
179
- }
180
-
181
- /**
182
- * Emulated single `path_payment` trades result corresponding to the quote
183
- */
184
- export interface QuoteDirectTradeResult {
185
- /**
186
- * Estimated amount to sell
187
- */
188
- selling: string;
189
- /**
190
- * Estimated amount to buy
191
- */
192
- buying: string;
193
- /**
194
- * Conversion path
195
- */
196
- path: string[];
197
- }
198
-
199
- export class StellarBrokerError extends Error {
200
- /**
201
- * Numeric error code
202
- * @type {number}
203
- * @readonly
204
- */
205
- readonly code: number;
206
- }
207
-
208
- /**
209
- * Async authorization callback for transactions and simulated auth entries
210
- */
211
- export type ClientAuthorizationCallback = (txOrAuthEntry: TransactionI | Buffer) => Promise<TransactionI | Buffer>;
212
-
213
- /**
214
- * Authorization method, either account secret key or an authorization callback
215
- */
216
- export type ClientAuthorizationParams = string | ClientAuthorizationCallback;
217
-
218
- /**
219
- * Trader mediator account wrapper
220
- */
221
- export class Mediator {
222
- /**
223
- * Create a trader mediator account instance for a given source account
224
- * @param source - Source account
225
- * @param sellingAsset - Asset to sell
226
- * @param buyingAsset - Asset to buy
227
- * @param sellingAmount - Amount to sell
228
- * @param authorization - Authorization callback or secret key
229
- * @param [reserveFeeAmount] - Amount reserved to cover tx fees (all unused funds will be refunded)
230
- */
231
- constructor(source: string, sellingAsset: string | Asset, buyingAsset: string | Asset, sellingAmount: string, authorization: ClientAuthorizationParams, reserveFeeAmount?: number)
232
-
233
- readonly source: string;
234
-
235
- readonly sellingAsset: Asset;
236
-
237
- readonly buyingAsset: Asset;
238
-
239
- readonly sellingAmount: bigint;
240
-
241
- readonly mediatorAddress: string;
242
-
243
- /**
244
- * Check if there are any non-disposed mediators that belong to lost swap sessions
245
- */
246
- get hasObsoleteMediators(): boolean;
247
-
248
- /**
249
- * Check if there are any non-disposed mediators that belong to lost swap sessions
250
- * @param source - Initiator account that created a mediator
251
- * @param [storagePrefix] - Local storage key prefix
252
- */
253
- static hasObsoleteMediators(source: string, storagePrefix?: string): boolean
254
-
255
- /**
256
- * Retrieve funds from mediator accounts that belong to lost swap sessions
257
- */
258
- disposeObsoleteMediators(): Promise<void>;
259
-
260
- /**
261
- * Retrieve funds from mediator accounts that belong to lost swap sessions
262
- * @param source - Initiator account that created a mediator
263
- * @param authorization - Authorization callback or secret key
264
- * @param [storagePrefix] - Local storage key prefix
265
- */
266
- static disposeObsoleteMediators(source: string, authorization: ClientAuthorizationParams, storagePrefix?: string): Promise<void>;
267
-
268
- /**
269
- * Create mediator account and deposit tokens to sell
270
- */
271
- init(): Promise<string>;
272
-
273
- /**
274
- * Dispose mediator account
275
- */
276
- dispose(address?: string): Promise<void>;
277
- }
1
+ import {Asset, TransactionI} from "@stellar/stellar-sdk";
2
+
3
+ /**
4
+ * Client for StellarBroker service
5
+ */
6
+ export class StellarBrokerClient {
7
+ /**
8
+ * @param {ClientInitializationParams} params
9
+ */
10
+ constructor(params: ClientInitializationParams);
11
+
12
+ /**
13
+ * Trader account public key
14
+ * @type {string}
15
+ */
16
+ readonly trader: string;
17
+ /**
18
+ * Stellar network passphrase
19
+ * @type {string}
20
+ */
21
+ readonly network: string;
22
+ /**
23
+ * @type {ClientSessionStatus}
24
+ */
25
+ readonly status: ClientSessionStatus;
26
+
27
+ /**
28
+ * Connect to the StellarBroker server
29
+ * @return {Promise<StellarBrokerClient>}
30
+ */
31
+ connect(): Promise<StellarBrokerClient>;
32
+
33
+ /**
34
+ * Request swap quote
35
+ * @param {QuoteParams} params - Quote parameters
36
+ */
37
+ quote(params: QuoteParams): void;
38
+
39
+ /**
40
+ * Stop quotation/trading
41
+ */
42
+ stop(): void;
43
+
44
+ /**
45
+ * Confirm current quote and start trading
46
+ * @param {string} [account] - Trader account address (overrides value provided in the constructor)
47
+ * @param {ClientAuthorizationParams} [authorization] - Authorization params (overrides value provided in the constructor)
48
+ */
49
+ confirmQuote(account?: string, authorization?: ClientAuthorizationParams): void;
50
+
51
+ /**
52
+ * Add event listener
53
+ * @param {StellarBrokerClientEvent} type
54
+ * @param {function} callback
55
+ */
56
+ on(type: StellarBrokerClientEvent, callback: Function): void;
57
+
58
+ /**
59
+ * Add event listener that will be executed once
60
+ * @param {StellarBrokerClientEvent} type
61
+ * @param {function} callback
62
+ */
63
+ once(type: StellarBrokerClientEvent, callback: Function): void;
64
+
65
+ /**
66
+ * Remove event listener
67
+ * @param {StellarBrokerClientEvent} type
68
+ * @param {function} callback
69
+ */
70
+ off(type: StellarBrokerClientEvent, callback: Function): void;
71
+
72
+ /**
73
+ * Close underlying connection and finalize the client
74
+ */
75
+ close(): void;
76
+ }
77
+
78
+ /**
79
+ * Request single swap quote estimate without trading
80
+ */
81
+ export function estimateSwap(params: QuoteParams): Promise<QuoteResult>;
82
+
83
+ /**
84
+ * Quote request parameters provided by the client
85
+ */
86
+ export interface QuoteParams {
87
+ /**
88
+ * Asset to sell
89
+ */
90
+ sellingAsset: string
91
+ /**
92
+ * Asset to buy
93
+ */
94
+ buyingAsset: string
95
+ /**
96
+ * Amount of selling asset
97
+ */
98
+ sellingAmount?: string
99
+ /**
100
+ * Swap slippage tolerance (0.02 by default - 2%)
101
+ */
102
+ slippageTolerance?: number
103
+ }
104
+
105
+ export interface ClientInitializationParams {
106
+ /**
107
+ * Partner key
108
+ */
109
+ partnerKey?: string;
110
+ /**
111
+ * Trader account address
112
+ */
113
+ account?: string;
114
+ /**
115
+ * Authorization method, either account secret key or an authorization callback
116
+ */
117
+ authorization?: ClientAuthorizationParams;
118
+ /**
119
+ * Stellar network passphrase (pubnet by default)
120
+ */
121
+ network?: string;
122
+ /**
123
+ * StellarBroker server origin (https://api.stellar.broker by default)
124
+ */
125
+ origin?: string;
126
+ }
127
+
128
+ /**
129
+ * Current client session status
130
+ */
131
+ export type ClientSessionStatus = "disconnected" | "ready" | "quote" | "trade";
132
+
133
+ /**
134
+ * Event type generated by the client
135
+ */
136
+ export type StellarBrokerClientEvent = "quote" | "progress" | "paused" | "finished" | "error";
137
+
138
+ /**
139
+ * Result status code returned by the server
140
+ */
141
+ export type QuoteResultStatus = "unfeasible" | "rejected" | "success";
142
+
143
+ /**
144
+ * Quote received from the server
145
+ */
146
+ export interface QuoteResult {
147
+ /**
148
+ * Quote timestamp
149
+ */
150
+ readonly ts: Date,
151
+ /**
152
+ * Quote status code
153
+ */
154
+ readonly status: QuoteResultStatus;
155
+ /**
156
+ * Asset to sell
157
+ */
158
+ readonly sellingAsset: string;
159
+ /**
160
+ * Asset to buy
161
+ */
162
+ readonly buyingAsset: string;
163
+ /**
164
+ * Swap slippage tolerance
165
+ */
166
+ readonly slippageTolerance: number;
167
+ /**
168
+ * Amount of the selling asset
169
+ */
170
+ readonly sellingAmount: string;
171
+ /**
172
+ * Estimated amount of buyingAsset to receive
173
+ */
174
+ readonly estimatedBuyingAmount?: string;
175
+ /**
176
+ * Equivalent direct path_payment trade estimate
177
+ */
178
+ readonly directTrade?: QuoteDirectTradeResult;
179
+ /**
180
+ * Difference between quoted price and estimated direct trade
181
+ */
182
+ readonly profit: string;
183
+ /**
184
+ * Error details from the server (for failed quotes)
185
+ */
186
+ readonly error?: string;
187
+ }
188
+
189
+ /**
190
+ * Emulated single `path_payment` trades result corresponding to the quote
191
+ */
192
+ export interface QuoteDirectTradeResult {
193
+ /**
194
+ * Estimated amount to sell
195
+ */
196
+ selling: string;
197
+ /**
198
+ * Estimated amount to buy
199
+ */
200
+ buying: string;
201
+ /**
202
+ * Conversion path
203
+ */
204
+ path: string[];
205
+ }
206
+
207
+ export class StellarBrokerError extends Error {
208
+ /**
209
+ * Numeric error code
210
+ * @type {number}
211
+ * @readonly
212
+ */
213
+ readonly code: number;
214
+ }
215
+
216
+ /**
217
+ * Async authorization callback for transactions and simulated auth entries
218
+ */
219
+ export type ClientAuthorizationCallback = (txOrAuthEntry: TransactionI | Uint8Array) => Promise<TransactionI | Uint8Array>;
220
+
221
+ /**
222
+ * Authorization method, either account secret key or an authorization callback
223
+ */
224
+ export type ClientAuthorizationParams = string | ClientAuthorizationCallback;
225
+
226
+ /**
227
+ * Trader mediator account wrapper
228
+ */
229
+ export class Mediator {
230
+ /**
231
+ * Create a trader mediator account instance for a given source account
232
+ * @param source - Source account
233
+ * @param sellingAsset - Asset to sell
234
+ * @param buyingAsset - Asset to buy
235
+ * @param sellingAmount - Amount to sell
236
+ * @param authorization - Authorization callback or secret key
237
+ * @param [reserveFeeAmount] - Amount reserved to cover tx fees (all unused funds will be refunded)
238
+ */
239
+ constructor(source: string, sellingAsset: string | Asset, buyingAsset: string | Asset, sellingAmount: string, authorization: ClientAuthorizationParams, reserveFeeAmount?: number)
240
+
241
+ /**
242
+ * Stellar network passphrase used by mediator accounts (pubnet by default)
243
+ */
244
+ static network: string;
245
+ /**
246
+ * Horizon server used by mediator accounts (https://horizon.stellar.org by default)
247
+ */
248
+ static horizonUrl: string;
249
+
250
+ readonly source: string;
251
+
252
+ readonly sellingAsset: Asset;
253
+
254
+ readonly buyingAsset: Asset;
255
+
256
+ readonly sellingAmount: bigint;
257
+
258
+ readonly mediatorAddress: string;
259
+
260
+ /**
261
+ * Check if there are any non-disposed mediators that belong to lost swap sessions
262
+ */
263
+ get hasObsoleteMediators(): boolean;
264
+
265
+ /**
266
+ * Check if there are any non-disposed mediators that belong to lost swap sessions
267
+ * @param source - Initiator account that created a mediator
268
+ * @param [storagePrefix] - Local storage key prefix
269
+ */
270
+ static hasObsoleteMediators(source: string, storagePrefix?: string): boolean
271
+
272
+ /**
273
+ * Retrieve funds from mediator accounts that belong to lost swap sessions
274
+ */
275
+ disposeObsoleteMediators(): Promise<void>;
276
+
277
+ /**
278
+ * Retrieve funds from mediator accounts that belong to lost swap sessions
279
+ * @param source - Initiator account that created a mediator
280
+ * @param authorization - Authorization callback or secret key
281
+ * @param [storagePrefix] - Local storage key prefix
282
+ */
283
+ static disposeObsoleteMediators(source: string, authorization: ClientAuthorizationParams, storagePrefix?: string): Promise<void>;
284
+
285
+ /**
286
+ * Create mediator account and deposit tokens to sell
287
+ */
288
+ init(): Promise<string>;
289
+
290
+ /**
291
+ * Dispose mediator account
292
+ */
293
+ dispose(address?: string): Promise<void>;
294
+ }