@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,208 +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.PollingUserStatsAccountSubscriber = void 0;
40
- var types_1 = require("./types");
41
- var events_1 = require("events");
42
- var utils_1 = require("./utils");
43
- var PollingUserStatsAccountSubscriber = /** @class */ (function () {
44
- function PollingUserStatsAccountSubscriber(program, userStatsAccountPublicKey, accountLoader) {
45
- this.accountsToPoll = new Map();
46
- this.isSubscribed = false;
47
- this.program = program;
48
- this.accountLoader = accountLoader;
49
- this.eventEmitter = new events_1.EventEmitter();
50
- this.userStatsAccountPublicKey = userStatsAccountPublicKey;
51
- }
52
- PollingUserStatsAccountSubscriber.prototype.subscribe = function () {
53
- return __awaiter(this, void 0, void 0, function () {
54
- var subscriptionSucceeded, retries;
55
- return __generator(this, function (_a) {
56
- switch (_a.label) {
57
- case 0:
58
- if (this.isSubscribed) {
59
- return [2 /*return*/, true];
60
- }
61
- return [4 /*yield*/, this.addToAccountLoader()];
62
- case 1:
63
- _a.sent();
64
- subscriptionSucceeded = false;
65
- retries = 0;
66
- _a.label = 2;
67
- case 2:
68
- if (!(!subscriptionSucceeded && retries < 5)) return [3 /*break*/, 4];
69
- return [4 /*yield*/, this.fetchIfUnloaded()];
70
- case 3:
71
- _a.sent();
72
- subscriptionSucceeded = this.didSubscriptionSucceed();
73
- retries++;
74
- return [3 /*break*/, 2];
75
- case 4:
76
- if (subscriptionSucceeded) {
77
- this.eventEmitter.emit('update');
78
- }
79
- this.isSubscribed = subscriptionSucceeded;
80
- return [2 /*return*/, subscriptionSucceeded];
81
- }
82
- });
83
- });
84
- };
85
- PollingUserStatsAccountSubscriber.prototype.addToAccountLoader = function () {
86
- return __awaiter(this, void 0, void 0, function () {
87
- var _loop_1, this_1, _i, _a, _b, _1, accountToPoll;
88
- var _this = this;
89
- return __generator(this, function (_c) {
90
- if (this.accountsToPoll.size > 0) {
91
- return [2 /*return*/];
92
- }
93
- this.accountsToPoll.set(this.userStatsAccountPublicKey.toString(), {
94
- key: 'userStats',
95
- publicKey: this.userStatsAccountPublicKey,
96
- eventType: 'userStatsAccountUpdate'
97
- });
98
- _loop_1 = function (_1, accountToPoll) {
99
- accountToPoll.callbackId = this_1.accountLoader.addAccount(accountToPoll.publicKey, function (buffer, slot) {
100
- if (!buffer) {
101
- return;
102
- }
103
- var account = _this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
104
- _this[accountToPoll.key] = { data: account, slot: slot };
105
- // @ts-ignore
106
- _this.eventEmitter.emit(accountToPoll.eventType, account);
107
- _this.eventEmitter.emit('update');
108
- });
109
- };
110
- this_1 = this;
111
- for (_i = 0, _a = this.accountsToPoll; _i < _a.length; _i++) {
112
- _b = _a[_i], _1 = _b[0], accountToPoll = _b[1];
113
- _loop_1(_1, accountToPoll);
114
- }
115
- this.errorCallbackId = this.accountLoader.addErrorCallbacks(function (error) {
116
- _this.eventEmitter.emit('error', error);
117
- });
118
- return [2 /*return*/];
119
- });
120
- });
121
- };
122
- PollingUserStatsAccountSubscriber.prototype.fetchIfUnloaded = function () {
123
- return __awaiter(this, void 0, void 0, function () {
124
- var shouldFetch, _i, _a, _b, _2, accountToPoll;
125
- return __generator(this, function (_c) {
126
- switch (_c.label) {
127
- case 0:
128
- shouldFetch = false;
129
- for (_i = 0, _a = this.accountsToPoll; _i < _a.length; _i++) {
130
- _b = _a[_i], _2 = _b[0], accountToPoll = _b[1];
131
- if (this[accountToPoll.key] === undefined) {
132
- shouldFetch = true;
133
- break;
134
- }
135
- }
136
- if (!shouldFetch) return [3 /*break*/, 2];
137
- return [4 /*yield*/, this.fetch()];
138
- case 1:
139
- _c.sent();
140
- _c.label = 2;
141
- case 2: return [2 /*return*/];
142
- }
143
- });
144
- });
145
- };
146
- PollingUserStatsAccountSubscriber.prototype.fetch = function () {
147
- return __awaiter(this, void 0, void 0, function () {
148
- var _i, _a, _b, _3, accountToPoll, _c, buffer, slot, account;
149
- return __generator(this, function (_d) {
150
- switch (_d.label) {
151
- case 0: return [4 /*yield*/, this.accountLoader.load()];
152
- case 1:
153
- _d.sent();
154
- for (_i = 0, _a = this.accountsToPoll; _i < _a.length; _i++) {
155
- _b = _a[_i], _3 = _b[0], accountToPoll = _b[1];
156
- _c = this.accountLoader.getBufferAndSlot(accountToPoll.publicKey), buffer = _c.buffer, slot = _c.slot;
157
- if (buffer) {
158
- account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
159
- this[accountToPoll.key] = { data: account, slot: slot };
160
- }
161
- }
162
- return [2 /*return*/];
163
- }
164
- });
165
- });
166
- };
167
- PollingUserStatsAccountSubscriber.prototype.didSubscriptionSucceed = function () {
168
- var success = true;
169
- for (var _i = 0, _a = this.accountsToPoll; _i < _a.length; _i++) {
170
- var _b = _a[_i], _4 = _b[0], accountToPoll = _b[1];
171
- if (!this[accountToPoll.key]) {
172
- success = false;
173
- break;
174
- }
175
- }
176
- return success;
177
- };
178
- PollingUserStatsAccountSubscriber.prototype.unsubscribe = function () {
179
- return __awaiter(this, void 0, void 0, function () {
180
- var _i, _a, _b, _5, accountToPoll;
181
- return __generator(this, function (_c) {
182
- if (!this.isSubscribed) {
183
- return [2 /*return*/];
184
- }
185
- for (_i = 0, _a = this.accountsToPoll; _i < _a.length; _i++) {
186
- _b = _a[_i], _5 = _b[0], accountToPoll = _b[1];
187
- this.accountLoader.removeAccount(accountToPoll.publicKey, accountToPoll.callbackId);
188
- }
189
- this.accountLoader.removeErrorCallbacks(this.errorCallbackId);
190
- this.errorCallbackId = undefined;
191
- this.accountsToPoll.clear();
192
- this.isSubscribed = false;
193
- return [2 /*return*/];
194
- });
195
- });
196
- };
197
- PollingUserStatsAccountSubscriber.prototype.assertIsSubscribed = function () {
198
- if (!this.isSubscribed) {
199
- throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
200
- }
201
- };
202
- PollingUserStatsAccountSubscriber.prototype.getUserStatsAccountAndSlot = function () {
203
- this.assertIsSubscribed();
204
- return this.userStats;
205
- };
206
- return PollingUserStatsAccountSubscriber;
207
- }());
208
- exports.PollingUserStatsAccountSubscriber = PollingUserStatsAccountSubscriber;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- exports.__esModule = true;
18
- exports.NotSubscribedError = void 0;
19
- var NotSubscribedError = /** @class */ (function (_super) {
20
- __extends(NotSubscribedError, _super);
21
- function NotSubscribedError() {
22
- var _this = _super !== null && _super.apply(this, arguments) || this;
23
- _this.name = 'NotSubscribedError';
24
- return _this;
25
- }
26
- return NotSubscribedError;
27
- }(Error));
28
- exports.NotSubscribedError = NotSubscribedError;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.capitalize = void 0;
4
- function capitalize(value) {
5
- return value[0].toUpperCase() + value.slice(1);
6
- }
7
- exports.capitalize = capitalize;
@@ -1,138 +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.WebSocketAccountSubscriber = void 0;
40
- var utils_1 = require("./utils");
41
- var WebSocketAccountSubscriber = /** @class */ (function () {
42
- function WebSocketAccountSubscriber(accountName, program, accountPublicKey, decodeBuffer) {
43
- this.accountName = accountName;
44
- this.program = program;
45
- this.accountPublicKey = accountPublicKey;
46
- this.decodeBufferFn = decodeBuffer;
47
- }
48
- WebSocketAccountSubscriber.prototype.subscribe = function (onChange) {
49
- return __awaiter(this, void 0, void 0, function () {
50
- var _this = this;
51
- return __generator(this, function (_a) {
52
- switch (_a.label) {
53
- case 0:
54
- if (this.listenerId) {
55
- return [2 /*return*/];
56
- }
57
- this.onChange = onChange;
58
- return [4 /*yield*/, this.fetch()];
59
- case 1:
60
- _a.sent();
61
- this.listenerId = this.program.provider.connection.onAccountChange(this.accountPublicKey, function (accountInfo, context) {
62
- _this.handleRpcResponse(context, accountInfo);
63
- }, this.program.provider.opts.commitment);
64
- return [2 /*return*/];
65
- }
66
- });
67
- });
68
- };
69
- WebSocketAccountSubscriber.prototype.fetch = function () {
70
- return __awaiter(this, void 0, void 0, function () {
71
- var rpcResponse;
72
- return __generator(this, function (_a) {
73
- switch (_a.label) {
74
- case 0: return [4 /*yield*/, this.program.provider.connection.getAccountInfoAndContext(this.accountPublicKey, this.program.provider.opts.commitment)];
75
- case 1:
76
- rpcResponse = _a.sent();
77
- this.handleRpcResponse(rpcResponse.context, rpcResponse === null || rpcResponse === void 0 ? void 0 : rpcResponse.value);
78
- return [2 /*return*/];
79
- }
80
- });
81
- });
82
- };
83
- WebSocketAccountSubscriber.prototype.handleRpcResponse = function (context, accountInfo) {
84
- var newSlot = context.slot;
85
- var newBuffer = undefined;
86
- if (accountInfo) {
87
- newBuffer = accountInfo.data;
88
- }
89
- if (!this.bufferAndSlot) {
90
- this.bufferAndSlot = {
91
- buffer: newBuffer,
92
- slot: newSlot
93
- };
94
- if (newBuffer) {
95
- var account = this.decodeBuffer(newBuffer);
96
- this.dataAndSlot = {
97
- data: account,
98
- slot: newSlot
99
- };
100
- this.onChange(account);
101
- }
102
- return;
103
- }
104
- if (newSlot <= this.bufferAndSlot.slot) {
105
- return;
106
- }
107
- var oldBuffer = this.bufferAndSlot.buffer;
108
- if (newBuffer && (!oldBuffer || !newBuffer.equals(oldBuffer))) {
109
- this.bufferAndSlot = {
110
- buffer: newBuffer,
111
- slot: newSlot
112
- };
113
- var account = this.decodeBuffer(newBuffer);
114
- this.dataAndSlot = {
115
- data: account,
116
- slot: newSlot
117
- };
118
- this.onChange(account);
119
- }
120
- };
121
- WebSocketAccountSubscriber.prototype.decodeBuffer = function (buffer) {
122
- if (this.decodeBufferFn) {
123
- return this.decodeBufferFn(buffer);
124
- }
125
- else {
126
- return this.program.account[this.accountName].coder.accounts.decode((0, utils_1.capitalize)(this.accountName), buffer);
127
- }
128
- };
129
- WebSocketAccountSubscriber.prototype.unsubscribe = function () {
130
- if (this.listenerId) {
131
- var promise = this.program.provider.connection.removeAccountChangeListener(this.listenerId);
132
- this.listenerId = undefined;
133
- return promise;
134
- }
135
- };
136
- return WebSocketAccountSubscriber;
137
- }());
138
- exports.WebSocketAccountSubscriber = WebSocketAccountSubscriber;