@1inch/fusion-sdk 0.1.10 → 0.1.12

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.
Files changed (77) hide show
  1. package/api/fusion-api.d.ts +2 -0
  2. package/api/fusion-api.js +3 -0
  3. package/api/fusion-api.js.map +1 -1
  4. package/api/quoter/index.d.ts +1 -0
  5. package/api/quoter/index.js +1 -0
  6. package/api/quoter/index.js.map +1 -1
  7. package/api/quoter/quote/quote.d.ts +6 -1
  8. package/api/quoter/quote/quote.js +4 -1
  9. package/api/quoter/quote/quote.js.map +1 -1
  10. package/api/quoter/quoter-custom-preset.request.d.ts +10 -0
  11. package/api/quoter/quoter-custom-preset.request.js +66 -0
  12. package/api/quoter/quoter-custom-preset.request.js.map +1 -0
  13. package/api/quoter/quoter.api.d.ts +2 -0
  14. package/api/quoter/quoter.api.js +17 -0
  15. package/api/quoter/quoter.api.js.map +1 -1
  16. package/api/quoter/types.d.ts +16 -1
  17. package/api/quoter/types.js +1 -0
  18. package/api/quoter/types.js.map +1 -1
  19. package/constants.d.ts +2 -1
  20. package/constants.js +7 -3
  21. package/constants.js.map +1 -1
  22. package/package.json +2 -2
  23. package/sdk/sdk.d.ts +3 -1
  24. package/sdk/sdk.js +41 -8
  25. package/sdk/sdk.js.map +1 -1
  26. package/sdk/types.d.ts +5 -1
  27. package/api/orders/order-api.spec.d.ts +0 -1
  28. package/api/orders/order-api.spec.js +0 -431
  29. package/api/orders/order-api.spec.js.map +0 -1
  30. package/api/pagination.spec.d.ts +0 -1
  31. package/api/pagination.spec.js +0 -28
  32. package/api/pagination.spec.js.map +0 -1
  33. package/api/quoter/quoter.api.spec.d.ts +0 -1
  34. package/api/quoter/quoter.api.spec.js +0 -141
  35. package/api/quoter/quoter.api.spec.js.map +0 -1
  36. package/api/relayer/relayer.api.spec.d.ts +0 -1
  37. package/api/relayer/relayer.api.spec.js +0 -85
  38. package/api/relayer/relayer.api.spec.js.map +0 -1
  39. package/auction-calculator/auction-calculator.spec.d.ts +0 -1
  40. package/auction-calculator/auction-calculator.spec.js +0 -35
  41. package/auction-calculator/auction-calculator.spec.js.map +0 -1
  42. package/auction-salt/auction.salt.spec.d.ts +0 -1
  43. package/auction-salt/auction.salt.spec.js +0 -59
  44. package/auction-salt/auction.salt.spec.js.map +0 -1
  45. package/auction-suffix/auction-suffix.spec.d.ts +0 -1
  46. package/auction-suffix/auction-suffix.spec.js +0 -73
  47. package/auction-suffix/auction-suffix.spec.js.map +0 -1
  48. package/connector/blockchain/private-key-provider.connector.spec.d.ts +0 -1
  49. package/connector/blockchain/private-key-provider.connector.spec.js +0 -48
  50. package/connector/blockchain/private-key-provider.connector.spec.js.map +0 -1
  51. package/connector/blockchain/web3-provider.connector.spec.d.ts +0 -1
  52. package/connector/blockchain/web3-provider.connector.spec.js +0 -51
  53. package/connector/blockchain/web3-provider.connector.spec.js.map +0 -1
  54. package/connector/http/axios-provider.connector.spec.d.ts +0 -1
  55. package/connector/http/axios-provider.connector.spec.js +0 -37
  56. package/connector/http/axios-provider.connector.spec.js.map +0 -1
  57. package/fusion-order/fusion-order.spec.d.ts +0 -1
  58. package/fusion-order/fusion-order.spec.js +0 -54
  59. package/fusion-order/fusion-order.spec.js.map +0 -1
  60. package/limit-order/limit-order.spec.d.ts +0 -1
  61. package/limit-order/limit-order.spec.js +0 -196
  62. package/limit-order/limit-order.spec.js.map +0 -1
  63. package/limit-order/predicate-factory.spec.d.ts +0 -1
  64. package/limit-order/predicate-factory.spec.js +0 -35
  65. package/limit-order/predicate-factory.spec.js.map +0 -1
  66. package/nonce-manager/nonce-manager.spec.d.ts +0 -1
  67. package/nonce-manager/nonce-manager.spec.js +0 -20
  68. package/nonce-manager/nonce-manager.spec.js.map +0 -1
  69. package/sdk/sdk.spec.d.ts +0 -1
  70. package/sdk/sdk.spec.js +0 -85
  71. package/sdk/sdk.spec.js.map +0 -1
  72. package/settlement/settlement.spec.d.ts +0 -1
  73. package/settlement/settlement.spec.js +0 -67
  74. package/settlement/settlement.spec.js.map +0 -1
  75. package/ws-api/ws.spec.d.ts +0 -1
  76. package/ws-api/ws.spec.js +0 -644
  77. package/ws-api/ws.spec.js.map +0 -1
package/ws-api/ws.spec.js DELETED
@@ -1,644 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /* eslint-disable max-lines-per-function */
4
- const ws_api_1 = require("./ws-api");
5
- const ws_1 = require("ws");
6
- const constants_1 = require("../constants");
7
- const url_1 = require("./url");
8
- const connector_1 = require("../connector");
9
- jest.setTimeout(5 * 60 * 1000);
10
- describe(__filename, () => {
11
- describe('base', () => {
12
- it('should be possible to subscribe to message', (done) => {
13
- const message = { id: 1 };
14
- const { wss, url } = createWebsocketServerMock([message]);
15
- const wsSdk = new ws_api_1.WebSocketApi({
16
- url,
17
- network: constants_1.NetworkEnum.ETHEREUM,
18
- authKey: ''
19
- });
20
- wsSdk.onMessage((data) => {
21
- expect(data).toEqual(message);
22
- wsSdk.close();
23
- wss.close();
24
- done();
25
- });
26
- });
27
- it('should be possible to subscribe to open connection', (done) => {
28
- const message = { id: 1 };
29
- const { wss, url } = createWebsocketServerMock([message]);
30
- const wsSdk = new ws_api_1.WebSocketApi({
31
- url,
32
- network: constants_1.NetworkEnum.ETHEREUM,
33
- authKey: ''
34
- });
35
- wsSdk.onOpen(() => {
36
- wsSdk.close();
37
- wss.close();
38
- done();
39
- });
40
- });
41
- it('this is pointed to underlying websocket', (done) => {
42
- const message = { id: 1 };
43
- const { wss, url } = createWebsocketServerMock([message]);
44
- const wsSdk = new ws_api_1.WebSocketApi({
45
- url,
46
- network: constants_1.NetworkEnum.ETHEREUM,
47
- authKey: ''
48
- });
49
- wsSdk.on('open', function () {
50
- expect(this).toBeInstanceOf(ws_1.WebSocket);
51
- this.close();
52
- wss.close();
53
- done();
54
- });
55
- });
56
- it('should be possible to subscribe to error', (done) => {
57
- const wsSdk = new ws_api_1.WebSocketApi({
58
- url: 'ws://localhost:1234',
59
- network: constants_1.NetworkEnum.ETHEREUM,
60
- authKey: ''
61
- });
62
- wsSdk.on('error', (error) => {
63
- expect(error.message).toContain('ECONNREFUSED');
64
- done();
65
- });
66
- });
67
- it('should be possible to initialize in lazy mode', (done) => {
68
- const message = { id: 1 };
69
- const port = 8080;
70
- const url = `ws://localhost:${port}/ws`;
71
- const wss = new ws_1.WebSocketServer({ port, path: '/ws/v1.0/1' });
72
- wss.on('connection', (ws) => {
73
- for (const m of [message]) {
74
- ws.send(JSON.stringify(m));
75
- }
76
- });
77
- const wsSdk = new ws_api_1.WebSocketApi({
78
- url,
79
- network: constants_1.NetworkEnum.ETHEREUM,
80
- lazyInit: true,
81
- authKey: ''
82
- });
83
- expect(wsSdk.provider).toMatchObject({ initialized: false });
84
- wsSdk.init();
85
- expect(wsSdk.provider).toMatchObject({ initialized: true });
86
- wsSdk.onMessage((data) => {
87
- expect(data).toEqual(message);
88
- wsSdk.close();
89
- wss.close();
90
- done();
91
- });
92
- });
93
- it('should be safe to call methods on uninitialized ws', () => {
94
- const wsSdk = new ws_api_1.WebSocketApi({
95
- url: 'random',
96
- network: constants_1.NetworkEnum.ETHEREUM,
97
- lazyInit: true
98
- });
99
- expect(() => wsSdk.send({ id: 1 })).toThrowError();
100
- });
101
- it('should be possible to initialize not in lazy mode', (done) => {
102
- const message = { id: 1 };
103
- const port = 8080;
104
- const url = `ws://localhost:${port}/ws`;
105
- const wss = new ws_1.WebSocketServer({ port, path: '/ws/v1.0/1' });
106
- wss.on('connection', (ws) => {
107
- for (const m of [message]) {
108
- ws.send(JSON.stringify(m));
109
- }
110
- });
111
- const wsSdk = new ws_api_1.WebSocketApi({
112
- url,
113
- network: constants_1.NetworkEnum.ETHEREUM,
114
- lazyInit: false
115
- });
116
- expect(wsSdk).toBeDefined();
117
- wsSdk.onMessage((data) => {
118
- expect(data).toEqual(message);
119
- wsSdk.close();
120
- wss.close();
121
- done();
122
- });
123
- });
124
- it('should be possible to pass provider instead of config', (done) => {
125
- const message = { id: 1 };
126
- const port = 8080;
127
- const url = `ws://localhost:${port}/ws`;
128
- const wss = new ws_1.WebSocketServer({ port, path: '/ws/v1.0/1' });
129
- wss.on('connection', (ws) => {
130
- for (const m of [message]) {
131
- ws.send(JSON.stringify(m));
132
- }
133
- });
134
- const castedUrl = (0, url_1.castUrl)(url);
135
- const urlWithNetwork = `${castedUrl}/v1.0/1`;
136
- const provider = new connector_1.WebsocketClient({ url: urlWithNetwork });
137
- const wsSdk = new ws_api_1.WebSocketApi(provider);
138
- expect(wsSdk.rpc).toBeDefined();
139
- expect(wsSdk.order).toBeDefined();
140
- expect(wsSdk).toBeDefined();
141
- wsSdk.onMessage((data) => {
142
- expect(data).toEqual(message);
143
- wsSdk.close();
144
- wss.close();
145
- done();
146
- });
147
- });
148
- it('should be possible to initialize with new method', (done) => {
149
- const message = { id: 1 };
150
- const port = 8080;
151
- const url = `ws://localhost:${port}/ws`;
152
- const wss = new ws_1.WebSocketServer({ port, path: '/ws/v1.0/1' });
153
- wss.on('connection', (ws) => {
154
- for (const m of [message]) {
155
- ws.send(JSON.stringify(m));
156
- }
157
- });
158
- const castedUrl = (0, url_1.castUrl)(url);
159
- const urlWithNetwork = `${castedUrl}/v1.0/1`;
160
- const provider = new connector_1.WebsocketClient({
161
- url: urlWithNetwork,
162
- authKey: ''
163
- });
164
- const wsSdk = ws_api_1.WebSocketApi.new(provider);
165
- expect(wsSdk.rpc).toBeDefined();
166
- expect(wsSdk.order).toBeDefined();
167
- expect(wsSdk).toBeDefined();
168
- wsSdk.onMessage((data) => {
169
- expect(data).toEqual(message);
170
- wsSdk.close();
171
- wss.close();
172
- done();
173
- });
174
- });
175
- it('connection can be closed and you can listen to close event', (done) => {
176
- const message = { id: 1 };
177
- const { wss, url } = createWebsocketServerMock([message]);
178
- const wsSdk = new ws_api_1.WebSocketApi({
179
- url,
180
- network: constants_1.NetworkEnum.ETHEREUM,
181
- authKey: ''
182
- });
183
- wsSdk.onClose(() => {
184
- wss.close();
185
- done();
186
- });
187
- wsSdk.onOpen(() => {
188
- wsSdk.close();
189
- });
190
- });
191
- });
192
- describe('rpc', () => {
193
- it('can ping pong ', (done) => {
194
- const response = { method: 'ping', result: 'pong' };
195
- const { url, wss } = createWebsocketRpcServerMock((ws, data) => {
196
- const parsedData = JSON.parse(data);
197
- if (parsedData.method === 'ping') {
198
- ws.send(JSON.stringify(response));
199
- }
200
- });
201
- const wsSdk = new ws_api_1.WebSocketApi({
202
- url,
203
- network: constants_1.NetworkEnum.ETHEREUM,
204
- authKey: ''
205
- });
206
- wsSdk.onOpen(() => {
207
- wsSdk.rpc.ping();
208
- });
209
- wsSdk.rpc.onPong((data) => {
210
- expect(data).toEqual(response.result);
211
- wsSdk.close();
212
- wss.close();
213
- done();
214
- });
215
- });
216
- it('can retrieve allowed rpc methods ', (done) => {
217
- const response = {
218
- method: 'getAllowedMethods',
219
- result: ['ping', 'getAllowedMethods']
220
- };
221
- const { url, wss } = createWebsocketRpcServerMock((ws, data) => {
222
- const parsedData = JSON.parse(data);
223
- if (parsedData.method === 'getAllowedMethods') {
224
- ws.send(JSON.stringify(response));
225
- }
226
- });
227
- const wsSdk = new ws_api_1.WebSocketApi({
228
- url,
229
- network: constants_1.NetworkEnum.ETHEREUM,
230
- authKey: ''
231
- });
232
- wsSdk.onOpen(() => {
233
- wsSdk.rpc.getAllowedMethods();
234
- });
235
- wsSdk.rpc.onGetAllowedMethods((data) => {
236
- expect(data).toEqual(response.result);
237
- wsSdk.close();
238
- wss.close();
239
- done();
240
- });
241
- });
242
- it('getActiveOrders success', (done) => {
243
- const response = {
244
- method: 'getActiveOrders',
245
- result: {
246
- items: [],
247
- meta: {
248
- totalItems: 0,
249
- totalPages: 0,
250
- itemsPerPage: 0,
251
- currentPage: 0
252
- }
253
- }
254
- };
255
- const { url, wss } = createWebsocketRpcServerMock((ws, data) => {
256
- const parsedData = JSON.parse(data);
257
- if (parsedData.method === 'getActiveOrders') {
258
- ws.send(JSON.stringify(response));
259
- }
260
- });
261
- const wsSdk = new ws_api_1.WebSocketApi({
262
- url,
263
- network: constants_1.NetworkEnum.ETHEREUM,
264
- authKey: ''
265
- });
266
- wsSdk.onOpen(() => {
267
- wsSdk.rpc.getActiveOrders();
268
- });
269
- wsSdk.rpc.onGetActiveOrders((data) => {
270
- expect(data).toEqual(response.result);
271
- wsSdk.close();
272
- wss.close();
273
- done();
274
- });
275
- });
276
- it('getActiveOrders throws error', (done) => {
277
- const response = {
278
- method: 'getActiveOrders',
279
- result: {
280
- items: [],
281
- meta: {
282
- totalItems: 0,
283
- totalPages: 0,
284
- itemsPerPage: 0,
285
- currentPage: 0
286
- }
287
- }
288
- };
289
- const { url, wss } = createWebsocketRpcServerMock((ws, data) => {
290
- const parsedData = JSON.parse(data);
291
- if (parsedData.method === 'getActiveOrders') {
292
- ws.send(JSON.stringify(response));
293
- }
294
- });
295
- const wsSdk = new ws_api_1.WebSocketApi({
296
- url,
297
- network: constants_1.NetworkEnum.ETHEREUM,
298
- authKey: ''
299
- });
300
- wsSdk.onOpen(() => {
301
- try {
302
- wsSdk.rpc.getActiveOrders({ page: -1 });
303
- }
304
- catch (error) {
305
- wsSdk.close();
306
- wss.close();
307
- done();
308
- }
309
- });
310
- });
311
- });
312
- describe('order', () => {
313
- it('can subscribe to order events', (done) => {
314
- const message1 = {
315
- event: 'order_created',
316
- result: {
317
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4',
318
- order: {
319
- salt: '45144194282371711345892930501725766861375817078109214409479816083205610767025',
320
- maker: '0x6f250c769001617aff9bdf4b9fd878062e94af83',
321
- offsets: '970558080243398695134547109586957793750899628853613079895592438595584',
322
- receiver: '0x0000000000000000000000000000000000000000',
323
- makerAsset: '0x6eb15148d0ea88433dd8088a3acc515d27e36c1b',
324
- takerAsset: '0xdac17f958d2ee523a2206206994597c13d831ec7',
325
- interactions: '0x2cc2878d000063ceb60f0000000000006f250c769001617aff9bdf4b9fd878062e94af83006c00c2fe001800c44c0000000084d99aa569d93a9ca187d83734c8c4a519c4e9b1ffffffff0a',
326
- makingAmount: '2246481050155000',
327
- takingAmount: '349837736598',
328
- allowedSender: '0xa88800cd213da5ae406ce248380802bd53b47647'
329
- },
330
- signature: '0x21ef770f9bedbb97542033bd3b1a2ad611917567102545c93ce66668b8524b7c609bead7829113e104be41fbbd14fea027c85bc4668214b81d52f02c2f9010551b',
331
- deadline: '2023-01-31T11:01:02.000Z',
332
- auctionStartDate: '2023-01-31T10:58:02.000Z',
333
- auctionEndDate: '2023-01-31T11:01:02.000Z',
334
- remainingMakerAmount: '57684207067582695'
335
- }
336
- };
337
- const message2 = {
338
- event: 'order_invalid',
339
- result: {
340
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4'
341
- }
342
- };
343
- const messages = [message1, message1, message2];
344
- const { url, wss } = createWebsocketServerMock(messages);
345
- const wsSdk = new ws_api_1.WebSocketApi({
346
- url,
347
- network: constants_1.NetworkEnum.ETHEREUM,
348
- authKey: ''
349
- });
350
- const resArray = [];
351
- wsSdk.order.onOrder((data) => {
352
- resArray.push(data);
353
- });
354
- wsSdk.onMessage(() => {
355
- if (resArray.length === 3) {
356
- expect(resArray).toEqual(messages);
357
- wsSdk.close();
358
- wss.close();
359
- done();
360
- }
361
- });
362
- });
363
- it('can subscribe to order created events', (done) => {
364
- const message1 = {
365
- event: 'order_created',
366
- result: {
367
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4',
368
- order: {
369
- salt: '45144194282371711345892930501725766861375817078109214409479816083205610767025',
370
- maker: '0x6f250c769001617aff9bdf4b9fd878062e94af83',
371
- offsets: '970558080243398695134547109586957793750899628853613079895592438595584',
372
- receiver: '0x0000000000000000000000000000000000000000',
373
- makerAsset: '0x6eb15148d0ea88433dd8088a3acc515d27e36c1b',
374
- takerAsset: '0xdac17f958d2ee523a2206206994597c13d831ec7',
375
- interactions: '0x2cc2878d000063ceb60f0000000000006f250c769001617aff9bdf4b9fd878062e94af83006c00c2fe001800c44c0000000084d99aa569d93a9ca187d83734c8c4a519c4e9b1ffffffff0a',
376
- makingAmount: '2246481050155000',
377
- takingAmount: '349837736598',
378
- allowedSender: '0xa88800cd213da5ae406ce248380802bd53b47647'
379
- },
380
- signature: '0x21ef770f9bedbb97542033bd3b1a2ad611917567102545c93ce66668b8524b7c609bead7829113e104be41fbbd14fea027c85bc4668214b81d52f02c2f9010551b',
381
- deadline: '2023-01-31T11:01:02.000Z',
382
- auctionStartDate: '2023-01-31T10:58:02.000Z',
383
- auctionEndDate: '2023-01-31T11:01:02.000Z',
384
- remainingMakerAmount: '57684207067582695'
385
- }
386
- };
387
- const message2 = {
388
- event: 'order_invalid',
389
- result: {
390
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4'
391
- }
392
- };
393
- const messages = [message2, message1, message1];
394
- const expectedMessages = [message1, message1];
395
- const { url, wss } = createWebsocketServerMock(messages);
396
- const wsSdk = new ws_api_1.WebSocketApi({
397
- url,
398
- network: constants_1.NetworkEnum.ETHEREUM,
399
- authKey: ''
400
- });
401
- const resArray = [];
402
- wsSdk.order.onOrderCreated((data) => {
403
- resArray.push(data);
404
- });
405
- wsSdk.onMessage(() => {
406
- if (resArray.length === 2) {
407
- expect(resArray).toEqual(expectedMessages);
408
- wsSdk.close();
409
- wss.close();
410
- done();
411
- }
412
- });
413
- });
414
- it('can subscribe to order invalid events', (done) => {
415
- const message1 = {
416
- event: 'order_created',
417
- result: {
418
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4',
419
- order: {
420
- salt: '45144194282371711345892930501725766861375817078109214409479816083205610767025',
421
- maker: '0x6f250c769001617aff9bdf4b9fd878062e94af83',
422
- offsets: '970558080243398695134547109586957793750899628853613079895592438595584',
423
- receiver: '0x0000000000000000000000000000000000000000',
424
- makerAsset: '0x6eb15148d0ea88433dd8088a3acc515d27e36c1b',
425
- takerAsset: '0xdac17f958d2ee523a2206206994597c13d831ec7',
426
- interactions: '0x2cc2878d000063ceb60f0000000000006f250c769001617aff9bdf4b9fd878062e94af83006c00c2fe001800c44c0000000084d99aa569d93a9ca187d83734c8c4a519c4e9b1ffffffff0a',
427
- makingAmount: '2246481050155000',
428
- takingAmount: '349837736598',
429
- allowedSender: '0xa88800cd213da5ae406ce248380802bd53b47647'
430
- },
431
- signature: '0x21ef770f9bedbb97542033bd3b1a2ad611917567102545c93ce66668b8524b7c609bead7829113e104be41fbbd14fea027c85bc4668214b81d52f02c2f9010551b',
432
- deadline: '2023-01-31T11:01:02.000Z',
433
- auctionStartDate: '2023-01-31T10:58:02.000Z',
434
- auctionEndDate: '2023-01-31T11:01:02.000Z',
435
- remainingMakerAmount: '57684207067582695'
436
- }
437
- };
438
- const message2 = {
439
- event: 'order_invalid',
440
- result: {
441
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4'
442
- }
443
- };
444
- const messages = [message1, message1, message2];
445
- const expectedMessages = [message2];
446
- const { url, wss } = createWebsocketServerMock(messages);
447
- const wsSdk = new ws_api_1.WebSocketApi({
448
- url,
449
- network: constants_1.NetworkEnum.ETHEREUM,
450
- authKey: ''
451
- });
452
- const resArray = [];
453
- wsSdk.order.onOrderInvalid((data) => {
454
- resArray.push(data);
455
- });
456
- wsSdk.onMessage(() => {
457
- if (resArray.length === 1) {
458
- expect(resArray).toEqual(expectedMessages);
459
- wsSdk.close();
460
- wss.close();
461
- done();
462
- }
463
- });
464
- });
465
- it('can subscribe to order_balance_or_allowance_change events', (done) => {
466
- const message1 = {
467
- event: 'order_created',
468
- result: {
469
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4',
470
- order: {
471
- salt: '45144194282371711345892930501725766861375817078109214409479816083205610767025',
472
- maker: '0x6f250c769001617aff9bdf4b9fd878062e94af83',
473
- offsets: '970558080243398695134547109586957793750899628853613079895592438595584',
474
- receiver: '0x0000000000000000000000000000000000000000',
475
- makerAsset: '0x6eb15148d0ea88433dd8088a3acc515d27e36c1b',
476
- takerAsset: '0xdac17f958d2ee523a2206206994597c13d831ec7',
477
- interactions: '0x2cc2878d000063ceb60f0000000000006f250c769001617aff9bdf4b9fd878062e94af83006c00c2fe001800c44c0000000084d99aa569d93a9ca187d83734c8c4a519c4e9b1ffffffff0a',
478
- makingAmount: '2246481050155000',
479
- takingAmount: '349837736598',
480
- allowedSender: '0xa88800cd213da5ae406ce248380802bd53b47647'
481
- },
482
- signature: '0x21ef770f9bedbb97542033bd3b1a2ad611917567102545c93ce66668b8524b7c609bead7829113e104be41fbbd14fea027c85bc4668214b81d52f02c2f9010551b',
483
- deadline: '2023-01-31T11:01:02.000Z',
484
- auctionStartDate: '2023-01-31T10:58:02.000Z',
485
- auctionEndDate: '2023-01-31T11:01:02.000Z',
486
- remainingMakerAmount: '57684207067582695'
487
- }
488
- };
489
- const message2 = {
490
- event: 'order_balance_or_allowance_change',
491
- result: {
492
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4',
493
- remainingMakerAmount: '57684207067582695',
494
- balance: '57684207067582695',
495
- allowance: '0'
496
- }
497
- };
498
- const messages = [message1, message1, message2];
499
- const expectedMessages = [message2];
500
- const { url, wss } = createWebsocketServerMock(messages);
501
- const wsSdk = new ws_api_1.WebSocketApi({
502
- url,
503
- network: constants_1.NetworkEnum.ETHEREUM,
504
- authKey: ''
505
- });
506
- const resArray = [];
507
- wsSdk.order.onOrderBalanceOrAllowanceChange((data) => {
508
- resArray.push(data);
509
- });
510
- wsSdk.onMessage(() => {
511
- if (resArray.length === 1) {
512
- expect(resArray).toEqual(expectedMessages);
513
- wsSdk.close();
514
- wss.close();
515
- done();
516
- }
517
- });
518
- });
519
- it('can subscribe to order filled events', (done) => {
520
- const message1 = {
521
- event: 'order_created',
522
- result: {
523
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4',
524
- order: {
525
- salt: '45144194282371711345892930501725766861375817078109214409479816083205610767025',
526
- maker: '0x6f250c769001617aff9bdf4b9fd878062e94af83',
527
- offsets: '970558080243398695134547109586957793750899628853613079895592438595584',
528
- receiver: '0x0000000000000000000000000000000000000000',
529
- makerAsset: '0x6eb15148d0ea88433dd8088a3acc515d27e36c1b',
530
- takerAsset: '0xdac17f958d2ee523a2206206994597c13d831ec7',
531
- interactions: '0x2cc2878d000063ceb60f0000000000006f250c769001617aff9bdf4b9fd878062e94af83006c00c2fe001800c44c0000000084d99aa569d93a9ca187d83734c8c4a519c4e9b1ffffffff0a',
532
- makingAmount: '2246481050155000',
533
- takingAmount: '349837736598',
534
- allowedSender: '0xa88800cd213da5ae406ce248380802bd53b47647'
535
- },
536
- signature: '0x21ef770f9bedbb97542033bd3b1a2ad611917567102545c93ce66668b8524b7c609bead7829113e104be41fbbd14fea027c85bc4668214b81d52f02c2f9010551b',
537
- deadline: '2023-01-31T11:01:02.000Z',
538
- auctionStartDate: '2023-01-31T10:58:02.000Z',
539
- auctionEndDate: '2023-01-31T11:01:02.000Z',
540
- remainingMakerAmount: '57684207067582695'
541
- }
542
- };
543
- const message2 = {
544
- event: 'order_filled',
545
- result: {
546
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4'
547
- }
548
- };
549
- const messages = [message1, message1, message2];
550
- const expectedMessages = [message2];
551
- const { url, wss } = createWebsocketServerMock(messages);
552
- const wsSdk = new ws_api_1.WebSocketApi({
553
- url,
554
- network: constants_1.NetworkEnum.ETHEREUM,
555
- authKey: ''
556
- });
557
- const resArray = [];
558
- wsSdk.order.onOrderFilled((data) => {
559
- resArray.push(data);
560
- });
561
- wsSdk.onMessage(() => {
562
- if (resArray.length === 1) {
563
- expect(resArray).toEqual(expectedMessages);
564
- wsSdk.close();
565
- wss.close();
566
- done();
567
- }
568
- });
569
- });
570
- it('can subscribe to order filled partially events', (done) => {
571
- const message1 = {
572
- event: 'order_created',
573
- result: {
574
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4',
575
- order: {
576
- salt: '45144194282371711345892930501725766861375817078109214409479816083205610767025',
577
- maker: '0x6f250c769001617aff9bdf4b9fd878062e94af83',
578
- offsets: '970558080243398695134547109586957793750899628853613079895592438595584',
579
- receiver: '0x0000000000000000000000000000000000000000',
580
- makerAsset: '0x6eb15148d0ea88433dd8088a3acc515d27e36c1b',
581
- takerAsset: '0xdac17f958d2ee523a2206206994597c13d831ec7',
582
- interactions: '0x2cc2878d000063ceb60f0000000000006f250c769001617aff9bdf4b9fd878062e94af83006c00c2fe001800c44c0000000084d99aa569d93a9ca187d83734c8c4a519c4e9b1ffffffff0a',
583
- makingAmount: '2246481050155000',
584
- takingAmount: '349837736598',
585
- allowedSender: '0xa88800cd213da5ae406ce248380802bd53b47647'
586
- },
587
- signature: '0x21ef770f9bedbb97542033bd3b1a2ad611917567102545c93ce66668b8524b7c609bead7829113e104be41fbbd14fea027c85bc4668214b81d52f02c2f9010551b',
588
- deadline: '2023-01-31T11:01:02.000Z',
589
- auctionStartDate: '2023-01-31T10:58:02.000Z',
590
- auctionEndDate: '2023-01-31T11:01:02.000Z',
591
- remainingMakerAmount: '57684207067582695'
592
- }
593
- };
594
- const message2 = {
595
- event: 'order_filled_partially',
596
- result: {
597
- orderHash: '0x1beee023ab933cf5446c298eaddb61c0-5705f2156ef5b2db36c160b36f31ce4',
598
- remainingMakerAmount: '57684207067582695'
599
- }
600
- };
601
- const messages = [message1, message1, message2];
602
- const expectedMessages = [message2];
603
- const { url, wss } = createWebsocketServerMock(messages);
604
- const wsSdk = new ws_api_1.WebSocketApi({
605
- url,
606
- network: constants_1.NetworkEnum.ETHEREUM,
607
- authKey: ''
608
- });
609
- const resArray = [];
610
- wsSdk.order.onOrderFilledPartially((data) => {
611
- resArray.push(data);
612
- });
613
- wsSdk.onMessage(() => {
614
- if (resArray.length === 1) {
615
- expect(resArray).toEqual(expectedMessages);
616
- wsSdk.close();
617
- wss.close();
618
- done();
619
- }
620
- });
621
- });
622
- });
623
- });
624
- function createWebsocketRpcServerMock(cb) {
625
- const port = 8080;
626
- const returnUrl = `ws://localhost:${port}/ws`;
627
- const wss = new ws_1.WebSocketServer({ port, path: '/ws/v1.0/1' });
628
- wss.on('connection', (ws) => {
629
- ws.on('message', (data) => cb(ws, data));
630
- });
631
- return { url: returnUrl, wss };
632
- }
633
- function createWebsocketServerMock(messages) {
634
- const port = 8080;
635
- const returnUrl = `ws://localhost:${port}/ws`;
636
- const wss = new ws_1.WebSocketServer({ port, path: '/ws/v1.0/1' });
637
- wss.on('connection', (ws) => {
638
- for (const message of messages) {
639
- ws.send(JSON.stringify(message));
640
- }
641
- });
642
- return { url: returnUrl, wss };
643
- }
644
- //# sourceMappingURL=ws.spec.js.map