@drift-labs/sdk 0.2.0-master.26 → 0.2.0-master.28

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 (143) hide show
  1. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +1 -0
  2. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +3 -0
  3. package/lib/accounts/types.d.ts +2 -0
  4. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +1 -0
  5. package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +3 -0
  6. package/lib/admin.d.ts +5 -2
  7. package/lib/admin.js +30 -4
  8. package/lib/clearingHouse.d.ts +3 -0
  9. package/lib/clearingHouse.js +19 -1
  10. package/lib/clearingHouseUser.d.ts +11 -9
  11. package/lib/clearingHouseUser.js +184 -108
  12. package/lib/config.js +1 -1
  13. package/lib/dlob/DLOB.d.ts +73 -0
  14. package/lib/dlob/DLOB.js +557 -0
  15. package/lib/dlob/DLOBNode.d.ts +52 -0
  16. package/lib/dlob/DLOBNode.js +82 -0
  17. package/lib/dlob/NodeList.d.ts +26 -0
  18. package/lib/dlob/NodeList.js +138 -0
  19. package/lib/idl/clearing_house.json +123 -203
  20. package/lib/index.d.ts +5 -0
  21. package/lib/index.js +5 -0
  22. package/lib/math/market.d.ts +3 -2
  23. package/lib/math/market.js +17 -12
  24. package/lib/math/orders.d.ts +3 -3
  25. package/lib/math/orders.js +31 -16
  26. package/lib/math/position.d.ts +3 -3
  27. package/lib/math/position.js +23 -16
  28. package/lib/math/repeg.js +8 -0
  29. package/lib/math/spotBalance.d.ts +3 -0
  30. package/lib/math/spotBalance.js +18 -1
  31. package/lib/math/spotPosition.d.ts +5 -1
  32. package/lib/math/spotPosition.js +16 -1
  33. package/lib/types.d.ts +25 -24
  34. package/lib/types.js +9 -3
  35. package/lib/userMap/userMap.d.ts +25 -0
  36. package/lib/userMap/userMap.js +73 -0
  37. package/lib/userMap/userStatsMap.d.ts +19 -0
  38. package/lib/userMap/userStatsMap.js +68 -0
  39. package/package.json +6 -3
  40. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +4 -0
  41. package/src/accounts/types.ts +1 -0
  42. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +6 -0
  43. package/src/admin.ts +50 -8
  44. package/src/clearingHouse.ts +30 -1
  45. package/src/clearingHouseUser.ts +366 -167
  46. package/src/config.ts +1 -1
  47. package/src/dlob/DLOB.ts +884 -0
  48. package/src/dlob/DLOBNode.ts +163 -0
  49. package/src/dlob/NodeList.ts +185 -0
  50. package/src/idl/clearing_house.json +123 -203
  51. package/src/index.ts +5 -0
  52. package/src/math/market.ts +22 -13
  53. package/src/math/orders.ts +29 -21
  54. package/src/math/position.ts +36 -22
  55. package/src/math/repeg.ts +9 -0
  56. package/src/math/spotBalance.ts +26 -0
  57. package/src/math/spotPosition.ts +42 -1
  58. package/src/types.ts +26 -24
  59. package/src/userMap/userMap.ts +100 -0
  60. package/src/userMap/userStatsMap.ts +110 -0
  61. package/tests/bn/test.ts +2 -3
  62. package/tests/dlob/helpers.ts +322 -0
  63. package/tests/dlob/test.ts +2865 -0
  64. package/my-script/.env +0 -7
  65. package/my-script/getUserStats.ts +0 -106
  66. package/my-script/multiConnections.ts +0 -119
  67. package/my-script/test-regex.ts +0 -11
  68. package/my-script/utils.ts +0 -52
  69. package/src/accounts/bulkAccountLoader.js +0 -249
  70. package/src/accounts/bulkUserStatsSubscription.js +0 -75
  71. package/src/accounts/bulkUserSubscription.js +0 -75
  72. package/src/accounts/fetch.js +0 -92
  73. package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -465
  74. package/src/accounts/pollingOracleSubscriber.js +0 -156
  75. package/src/accounts/pollingTokenAccountSubscriber.js +0 -141
  76. package/src/accounts/pollingUserAccountSubscriber.js +0 -208
  77. package/src/accounts/pollingUserStatsAccountSubscriber.js +0 -208
  78. package/src/accounts/types.js +0 -28
  79. package/src/accounts/utils.js +0 -7
  80. package/src/accounts/webSocketAccountSubscriber.js +0 -138
  81. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -433
  82. package/src/accounts/webSocketUserAccountSubscriber.js +0 -113
  83. package/src/accounts/webSocketUserStatsAccountSubsriber.js +0 -113
  84. package/src/addresses/pda.js +0 -186
  85. package/src/admin.js +0 -1284
  86. package/src/assert/assert.js +0 -9
  87. package/src/clearingHouse.js +0 -3433
  88. package/src/clearingHouseConfig.js +0 -2
  89. package/src/clearingHouseUser.js +0 -874
  90. package/src/clearingHouseUserConfig.js +0 -2
  91. package/src/clearingHouseUserStats.js +0 -115
  92. package/src/clearingHouseUserStatsConfig.js +0 -2
  93. package/src/config.js +0 -80
  94. package/src/constants/numericConstants.js +0 -48
  95. package/src/constants/perpMarkets.js +0 -42
  96. package/src/constants/spotMarkets.js +0 -51
  97. package/src/events/eventList.js +0 -120
  98. package/src/events/eventSubscriber.js +0 -202
  99. package/src/events/fetchLogs.js +0 -117
  100. package/src/events/pollingLogProvider.js +0 -113
  101. package/src/events/sort.js +0 -41
  102. package/src/events/txEventCache.js +0 -74
  103. package/src/events/types.js +0 -25
  104. package/src/events/webSocketLogProvider.js +0 -76
  105. package/src/factory/bigNum.js +0 -393
  106. package/src/factory/oracleClient.js +0 -20
  107. package/src/index.js +0 -75
  108. package/src/math/amm.js +0 -422
  109. package/src/math/auction.js +0 -42
  110. package/src/math/conversion.js +0 -12
  111. package/src/math/funding.js +0 -296
  112. package/src/math/insurance.js +0 -27
  113. package/src/math/margin.js +0 -77
  114. package/src/math/market.js +0 -105
  115. package/src/math/oracles.js +0 -56
  116. package/src/math/orders.js +0 -153
  117. package/src/math/position.js +0 -172
  118. package/src/math/repeg.js +0 -128
  119. package/src/math/spotBalance.js +0 -176
  120. package/src/math/spotMarket.js +0 -8
  121. package/src/math/spotPosition.js +0 -8
  122. package/src/math/trade.js +0 -260
  123. package/src/math/utils.js +0 -27
  124. package/src/oracles/oracleClientCache.js +0 -20
  125. package/src/oracles/pythClient.js +0 -81
  126. package/src/oracles/quoteAssetOracleClient.js +0 -63
  127. package/src/oracles/switchboardClient.js +0 -101
  128. package/src/oracles/types.js +0 -2
  129. package/src/orderParams.js +0 -28
  130. package/src/serum/serumSubscriber.js +0 -102
  131. package/src/serum/types.js +0 -2
  132. package/src/slot/SlotSubscriber.js +0 -86
  133. package/src/token/index.js +0 -38
  134. package/src/tokenFaucet.js +0 -323
  135. package/src/tx/retryTxSender.js +0 -280
  136. package/src/tx/types.js +0 -2
  137. package/src/tx/utils.js +0 -18
  138. package/src/types.js +0 -216
  139. package/src/userName.js +0 -20
  140. package/src/util/computeUnits.js +0 -62
  141. package/src/util/promiseTimeout.js +0 -14
  142. package/src/util/tps.js +0 -61
  143. package/src/wallet.js +0 -72
@@ -1,117 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- exports.__esModule = true;
39
- exports.LogParser = exports.fetchLogs = void 0;
40
- function fetchLogs(connection, programId, finality, beforeTx, untilTx, limit) {
41
- return __awaiter(this, void 0, void 0, function () {
42
- var signatures, sortedSignatures, filteredSignatures, chunkedSignatures, transactionLogs, earliest, mostRecent;
43
- var _this = this;
44
- return __generator(this, function (_a) {
45
- switch (_a.label) {
46
- case 0: return [4 /*yield*/, connection.getSignaturesForAddress(programId, {
47
- before: beforeTx,
48
- until: untilTx,
49
- limit: limit
50
- }, finality)];
51
- case 1:
52
- signatures = _a.sent();
53
- sortedSignatures = signatures.sort(function (a, b) {
54
- return a.slot === b.slot ? 0 : a.slot < b.slot ? -1 : 1;
55
- });
56
- filteredSignatures = sortedSignatures.filter(function (signature) { return !signature.err; });
57
- if (filteredSignatures.length === 0) {
58
- return [2 /*return*/, undefined];
59
- }
60
- chunkedSignatures = chunk(filteredSignatures, 100);
61
- return [4 /*yield*/, Promise.all(chunkedSignatures.map(function (chunk) { return __awaiter(_this, void 0, void 0, function () {
62
- var transactions;
63
- return __generator(this, function (_a) {
64
- switch (_a.label) {
65
- case 0: return [4 /*yield*/, connection.getTransactions(chunk.map(function (confirmedSignature) { return confirmedSignature.signature; }), finality)];
66
- case 1:
67
- transactions = _a.sent();
68
- return [2 /*return*/, transactions.map(function (transaction) {
69
- return {
70
- txSig: transaction.transaction.signatures[0],
71
- slot: transaction.slot,
72
- logs: transaction.meta.logMessages
73
- };
74
- })];
75
- }
76
- });
77
- }); }))];
78
- case 2:
79
- transactionLogs = (_a.sent()).flat();
80
- earliest = filteredSignatures[0];
81
- mostRecent = filteredSignatures[filteredSignatures.length - 1];
82
- return [2 /*return*/, {
83
- transactionLogs: transactionLogs,
84
- earliestTx: earliest.signature,
85
- mostRecentTx: mostRecent.signature,
86
- earliestSlot: earliest.slot,
87
- mostRecentSlot: mostRecent.slot
88
- }];
89
- }
90
- });
91
- });
92
- }
93
- exports.fetchLogs = fetchLogs;
94
- function chunk(array, size) {
95
- return new Array(Math.ceil(array.length / size))
96
- .fill(null)
97
- .map(function (_, index) { return index * size; })
98
- .map(function (begin) { return array.slice(begin, begin + size); });
99
- }
100
- var LogParser = /** @class */ (function () {
101
- function LogParser(program) {
102
- this.program = program;
103
- }
104
- LogParser.prototype.parseEventsFromLogs = function (event) {
105
- var records = [];
106
- // @ts-ignore
107
- this.program._events._eventParser.parseLogs(event.logs, function (eventLog) {
108
- eventLog.data.txSig = event.txSig;
109
- eventLog.data.slot = event.slot;
110
- eventLog.data.eventType = eventLog.name;
111
- records.push(eventLog.data);
112
- });
113
- return records;
114
- };
115
- return LogParser;
116
- }());
117
- exports.LogParser = LogParser;
@@ -1,113 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- exports.__esModule = true;
39
- exports.PollingLogProvider = void 0;
40
- var fetchLogs_1 = require("./fetchLogs");
41
- var PollingLogProvider = /** @class */ (function () {
42
- function PollingLogProvider(connection, programId, commitment, frequency) {
43
- if (frequency === void 0) { frequency = 15 * 1000; }
44
- this.connection = connection;
45
- this.programId = programId;
46
- this.frequency = frequency;
47
- this.firstFetch = true;
48
- this.finality = commitment === 'finalized' ? 'finalized' : 'confirmed';
49
- }
50
- PollingLogProvider.prototype.subscribe = function (callback, skipHistory) {
51
- var _this = this;
52
- if (this.intervalId) {
53
- return true;
54
- }
55
- this.intervalId = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
56
- var response, mostRecentTx, transactionLogs, _i, transactionLogs_1, _a, txSig, slot, logs, e_1;
57
- return __generator(this, function (_b) {
58
- switch (_b.label) {
59
- case 0:
60
- if (this.mutex === 1) {
61
- return [2 /*return*/];
62
- }
63
- this.mutex = 1;
64
- _b.label = 1;
65
- case 1:
66
- _b.trys.push([1, 3, 4, 5]);
67
- return [4 /*yield*/, (0, fetchLogs_1.fetchLogs)(this.connection, this.programId, this.finality, undefined, this.mostRecentSeenTx,
68
- // If skipping history, only fetch one log back, not the maximum amount available
69
- skipHistory && this.firstFetch ? 1 : undefined)];
70
- case 2:
71
- response = _b.sent();
72
- this.firstFetch = false;
73
- if (response === undefined) {
74
- return [2 /*return*/];
75
- }
76
- mostRecentTx = response.mostRecentTx, transactionLogs = response.transactionLogs;
77
- for (_i = 0, transactionLogs_1 = transactionLogs; _i < transactionLogs_1.length; _i++) {
78
- _a = transactionLogs_1[_i], txSig = _a.txSig, slot = _a.slot, logs = _a.logs;
79
- callback(txSig, slot, logs);
80
- }
81
- this.mostRecentSeenTx = mostRecentTx;
82
- return [3 /*break*/, 5];
83
- case 3:
84
- e_1 = _b.sent();
85
- console.error('PollingLogProvider threw an Error');
86
- console.error(e_1);
87
- return [3 /*break*/, 5];
88
- case 4:
89
- this.mutex = 0;
90
- return [7 /*endfinally*/];
91
- case 5: return [2 /*return*/];
92
- }
93
- });
94
- }); }, this.frequency);
95
- return true;
96
- };
97
- PollingLogProvider.prototype.isSubscribed = function () {
98
- return this.intervalId !== undefined;
99
- };
100
- PollingLogProvider.prototype.unsubscribe = function () {
101
- return __awaiter(this, void 0, void 0, function () {
102
- return __generator(this, function (_a) {
103
- if (this.intervalId !== undefined) {
104
- clearInterval(this.intervalId);
105
- this.intervalId = undefined;
106
- }
107
- return [2 /*return*/, true];
108
- });
109
- });
110
- };
111
- return PollingLogProvider;
112
- }());
113
- exports.PollingLogProvider = PollingLogProvider;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.getSortFn = void 0;
4
- var index_1 = require("../index");
5
- function clientSortAscFn() {
6
- return 'less than';
7
- }
8
- function clientSortDescFn() {
9
- return 'greater than';
10
- }
11
- function defaultBlockchainSortFn(currentEvent, newEvent) {
12
- return currentEvent.slot <= newEvent.slot ? 'less than' : 'greater than';
13
- }
14
- function orderActionRecordSortFn(currentEvent, newEvent) {
15
- var _a, _b;
16
- var currentEventMarketIndex = currentEvent.marketIndex;
17
- var newEventMarketIndex = newEvent.marketIndex;
18
- if (!currentEventMarketIndex.eq(newEventMarketIndex)) {
19
- return currentEvent.ts.lte(newEvent.ts) ? 'less than' : 'greater than';
20
- }
21
- if (((_a = currentEvent.fillRecordId) === null || _a === void 0 ? void 0 : _a.gt(index_1.ZERO)) && ((_b = newEvent.fillRecordId) === null || _b === void 0 ? void 0 : _b.gt(index_1.ZERO))) {
22
- return currentEvent.fillRecordId.lte(newEvent.fillRecordId)
23
- ? 'less than'
24
- : 'greater than';
25
- }
26
- else {
27
- return currentEvent.ts.lte(newEvent.ts) ? 'less than' : 'greater than';
28
- }
29
- }
30
- function getSortFn(orderBy, orderDir, eventType) {
31
- if (orderBy === 'client') {
32
- return orderDir === 'asc' ? clientSortAscFn : clientSortDescFn;
33
- }
34
- switch (eventType) {
35
- case 'OrderActionRecord':
36
- return orderActionRecordSortFn;
37
- default:
38
- return defaultBlockchainSortFn;
39
- }
40
- }
41
- exports.getSortFn = getSortFn;
@@ -1,74 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.TxEventCache = void 0;
4
- var Node = /** @class */ (function () {
5
- function Node(key, value, next, prev) {
6
- this.key = key;
7
- this.value = value;
8
- this.next = next;
9
- this.prev = prev;
10
- }
11
- return Node;
12
- }());
13
- // lru cache
14
- var TxEventCache = /** @class */ (function () {
15
- function TxEventCache(maxTx) {
16
- if (maxTx === void 0) { maxTx = 1024; }
17
- this.maxTx = maxTx;
18
- this.size = 0;
19
- this.cacheMap = {};
20
- }
21
- TxEventCache.prototype.add = function (key, events) {
22
- var existingNode = this.cacheMap[key];
23
- if (existingNode) {
24
- this.detach(existingNode);
25
- this.size--;
26
- }
27
- else if (this.size === this.maxTx) {
28
- delete this.cacheMap[this.tail.key];
29
- this.detach(this.tail);
30
- this.size--;
31
- }
32
- // Write to head of LinkedList
33
- if (!this.head) {
34
- this.head = this.tail = new Node(key, events);
35
- }
36
- else {
37
- var node = new Node(key, events, this.head);
38
- this.head.prev = node;
39
- this.head = node;
40
- }
41
- // update cacheMap with LinkedList key and Node reference
42
- this.cacheMap[key] = this.head;
43
- this.size++;
44
- };
45
- TxEventCache.prototype.has = function (key) {
46
- return this.cacheMap.hasOwnProperty(key);
47
- };
48
- TxEventCache.prototype.get = function (key) {
49
- var _a;
50
- return (_a = this.cacheMap[key]) === null || _a === void 0 ? void 0 : _a.value;
51
- };
52
- TxEventCache.prototype.detach = function (node) {
53
- if (node.prev !== undefined) {
54
- node.prev.next = node.next;
55
- }
56
- else {
57
- this.head = node.next;
58
- }
59
- if (node.next !== undefined) {
60
- node.next.prev = node.prev;
61
- }
62
- else {
63
- this.tail = node.prev;
64
- }
65
- };
66
- TxEventCache.prototype.clear = function () {
67
- this.head = undefined;
68
- this.tail = undefined;
69
- this.size = 0;
70
- this.cacheMap = {};
71
- };
72
- return TxEventCache;
73
- }());
74
- exports.TxEventCache = TxEventCache;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.DefaultEventSubscriptionOptions = void 0;
4
- exports.DefaultEventSubscriptionOptions = {
5
- eventTypes: [
6
- 'DepositRecord',
7
- 'FundingPaymentRecord',
8
- 'LiquidationRecord',
9
- 'OrderRecord',
10
- 'OrderActionRecord',
11
- 'FundingRateRecord',
12
- 'NewUserRecord',
13
- 'SettlePnlRecord',
14
- 'LPRecord',
15
- 'InsuranceFundRecord',
16
- ],
17
- maxEventsPerType: 4096,
18
- orderBy: 'blockchain',
19
- orderDir: 'asc',
20
- commitment: 'confirmed',
21
- maxTx: 4096,
22
- logProviderConfig: {
23
- type: 'websocket'
24
- }
25
- };
@@ -1,76 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- exports.__esModule = true;
39
- exports.WebSocketLogProvider = void 0;
40
- var WebSocketLogProvider = /** @class */ (function () {
41
- function WebSocketLogProvider(connection, programId, commitment) {
42
- this.connection = connection;
43
- this.programId = programId;
44
- this.commitment = commitment;
45
- }
46
- WebSocketLogProvider.prototype.subscribe = function (callback) {
47
- if (this.subscriptionId) {
48
- return true;
49
- }
50
- this.subscriptionId = this.connection.onLogs(this.programId, function (logs, ctx) {
51
- callback(logs.signature, ctx.slot, logs.logs);
52
- }, this.commitment);
53
- return true;
54
- };
55
- WebSocketLogProvider.prototype.isSubscribed = function () {
56
- return this.subscriptionId !== undefined;
57
- };
58
- WebSocketLogProvider.prototype.unsubscribe = function () {
59
- return __awaiter(this, void 0, void 0, function () {
60
- return __generator(this, function (_a) {
61
- switch (_a.label) {
62
- case 0:
63
- if (!(this.subscriptionId !== undefined)) return [3 /*break*/, 2];
64
- return [4 /*yield*/, this.connection.removeOnLogsListener(this.subscriptionId)];
65
- case 1:
66
- _a.sent();
67
- this.subscriptionId = undefined;
68
- _a.label = 2;
69
- case 2: return [2 /*return*/, true];
70
- }
71
- });
72
- });
73
- };
74
- return WebSocketLogProvider;
75
- }());
76
- exports.WebSocketLogProvider = WebSocketLogProvider;