@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,280 +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
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
- exports.__esModule = true;
48
- exports.RetryTxSender = void 0;
49
- var assert_1 = require("assert");
50
- var bs58_1 = require("bs58");
51
- var DEFAULT_TIMEOUT = 35000;
52
- var DEFAULT_RETRY = 8000;
53
- var RetryTxSender = /** @class */ (function () {
54
- function RetryTxSender(provider, timeout, retrySleep, additionalConnections) {
55
- if (additionalConnections === void 0) { additionalConnections = new Array(); }
56
- this.provider = provider;
57
- this.timeout = timeout !== null && timeout !== void 0 ? timeout : DEFAULT_TIMEOUT;
58
- this.retrySleep = retrySleep !== null && retrySleep !== void 0 ? retrySleep : DEFAULT_RETRY;
59
- this.additionalConnections = additionalConnections;
60
- }
61
- RetryTxSender.prototype.send = function (tx, additionalSigners, opts, preSigned) {
62
- return __awaiter(this, void 0, void 0, function () {
63
- var rawTransaction, startTime, txid, e_1, done, resolveReference, stopWaiting, slot, result, e_2;
64
- var _this = this;
65
- return __generator(this, function (_a) {
66
- switch (_a.label) {
67
- case 0:
68
- if (additionalSigners === undefined) {
69
- additionalSigners = [];
70
- }
71
- if (opts === undefined) {
72
- opts = this.provider.opts;
73
- }
74
- if (!!preSigned) return [3 /*break*/, 2];
75
- return [4 /*yield*/, this.prepareTx(tx, additionalSigners, opts)];
76
- case 1:
77
- _a.sent();
78
- _a.label = 2;
79
- case 2:
80
- rawTransaction = tx.serialize();
81
- startTime = this.getTimestamp();
82
- _a.label = 3;
83
- case 3:
84
- _a.trys.push([3, 5, , 6]);
85
- return [4 /*yield*/, this.provider.connection.sendRawTransaction(rawTransaction, opts)];
86
- case 4:
87
- txid = _a.sent();
88
- this.sendToAdditionalConnections(rawTransaction, opts);
89
- return [3 /*break*/, 6];
90
- case 5:
91
- e_1 = _a.sent();
92
- console.error(e_1);
93
- throw e_1;
94
- case 6:
95
- done = false;
96
- resolveReference = {
97
- resolve: undefined
98
- };
99
- stopWaiting = function () {
100
- done = true;
101
- if (resolveReference.resolve) {
102
- resolveReference.resolve();
103
- }
104
- };
105
- (function () { return __awaiter(_this, void 0, void 0, function () {
106
- return __generator(this, function (_a) {
107
- switch (_a.label) {
108
- case 0:
109
- if (!(!done && this.getTimestamp() - startTime < this.timeout)) return [3 /*break*/, 2];
110
- return [4 /*yield*/, this.sleep(resolveReference)];
111
- case 1:
112
- _a.sent();
113
- if (!done) {
114
- this.provider.connection
115
- .sendRawTransaction(rawTransaction, opts)["catch"](function (e) {
116
- console.error(e);
117
- stopWaiting();
118
- });
119
- this.sendToAdditionalConnections(rawTransaction, opts);
120
- }
121
- return [3 /*break*/, 0];
122
- case 2: return [2 /*return*/];
123
- }
124
- });
125
- }); })();
126
- _a.label = 7;
127
- case 7:
128
- _a.trys.push([7, 9, 10, 11]);
129
- return [4 /*yield*/, this.confirmTransaction(txid, opts.commitment)];
130
- case 8:
131
- result = _a.sent();
132
- slot = result.context.slot;
133
- return [3 /*break*/, 11];
134
- case 9:
135
- e_2 = _a.sent();
136
- console.error(e_2);
137
- throw e_2;
138
- case 10:
139
- stopWaiting();
140
- return [7 /*endfinally*/];
141
- case 11: return [2 /*return*/, { txSig: txid, slot: slot }];
142
- }
143
- });
144
- });
145
- };
146
- RetryTxSender.prototype.prepareTx = function (tx, additionalSigners, opts) {
147
- return __awaiter(this, void 0, void 0, function () {
148
- var _a;
149
- return __generator(this, function (_b) {
150
- switch (_b.label) {
151
- case 0:
152
- tx.feePayer = this.provider.wallet.publicKey;
153
- _a = tx;
154
- return [4 /*yield*/, this.provider.connection.getRecentBlockhash(opts.preflightCommitment)];
155
- case 1:
156
- _a.recentBlockhash = (_b.sent()).blockhash;
157
- return [4 /*yield*/, this.provider.wallet.signTransaction(tx)];
158
- case 2:
159
- _b.sent();
160
- additionalSigners
161
- .filter(function (s) { return s !== undefined; })
162
- .forEach(function (kp) {
163
- tx.partialSign(kp);
164
- });
165
- return [2 /*return*/, tx];
166
- }
167
- });
168
- });
169
- };
170
- RetryTxSender.prototype.confirmTransaction = function (signature, commitment) {
171
- return __awaiter(this, void 0, void 0, function () {
172
- var decodedSignature, start, subscriptionCommitment, subscriptionIds, connections, response, promises, _i, _a, _b, i, subscriptionId, duration;
173
- return __generator(this, function (_c) {
174
- switch (_c.label) {
175
- case 0:
176
- try {
177
- decodedSignature = bs58_1["default"].decode(signature);
178
- }
179
- catch (err) {
180
- throw new Error('signature must be base58 encoded: ' + signature);
181
- }
182
- (0, assert_1["default"])(decodedSignature.length === 64, 'signature has invalid length');
183
- start = Date.now();
184
- subscriptionCommitment = commitment || this.provider.opts.commitment;
185
- subscriptionIds = new Array();
186
- connections = __spreadArray([
187
- this.provider.connection
188
- ], this.additionalConnections, true);
189
- response = null;
190
- promises = connections.map(function (connection, i) {
191
- var subscriptionId;
192
- var confirmPromise = new Promise(function (resolve, reject) {
193
- try {
194
- subscriptionId = connection.onSignature(signature, function (result, context) {
195
- subscriptionIds[i] = undefined;
196
- response = {
197
- context: context,
198
- value: result
199
- };
200
- resolve(null);
201
- }, subscriptionCommitment);
202
- }
203
- catch (err) {
204
- reject(err);
205
- }
206
- });
207
- subscriptionIds.push(subscriptionId);
208
- return confirmPromise;
209
- });
210
- _c.label = 1;
211
- case 1:
212
- _c.trys.push([1, , 3, 4]);
213
- return [4 /*yield*/, this.promiseTimeout(promises, this.timeout)];
214
- case 2:
215
- _c.sent();
216
- return [3 /*break*/, 4];
217
- case 3:
218
- for (_i = 0, _a = subscriptionIds.entries(); _i < _a.length; _i++) {
219
- _b = _a[_i], i = _b[0], subscriptionId = _b[1];
220
- if (subscriptionId) {
221
- connections[i].removeSignatureListener(subscriptionId);
222
- }
223
- }
224
- return [7 /*endfinally*/];
225
- case 4:
226
- if (response === null) {
227
- duration = (Date.now() - start) / 1000;
228
- throw new Error("Transaction was not confirmed in ".concat(duration.toFixed(2), " seconds. It is unknown if it succeeded or failed. Check signature ").concat(signature, " using the Solana Explorer or CLI tools."));
229
- }
230
- return [2 /*return*/, response];
231
- }
232
- });
233
- });
234
- };
235
- RetryTxSender.prototype.getTimestamp = function () {
236
- return new Date().getTime();
237
- };
238
- RetryTxSender.prototype.sleep = function (reference) {
239
- return __awaiter(this, void 0, void 0, function () {
240
- var _this = this;
241
- return __generator(this, function (_a) {
242
- return [2 /*return*/, new Promise(function (resolve) {
243
- reference.resolve = resolve;
244
- setTimeout(resolve, _this.retrySleep);
245
- })];
246
- });
247
- });
248
- };
249
- RetryTxSender.prototype.promiseTimeout = function (promises, timeoutMs) {
250
- var timeoutId;
251
- var timeoutPromise = new Promise(function (resolve) {
252
- timeoutId = setTimeout(function () { return resolve(null); }, timeoutMs);
253
- });
254
- return Promise.race(__spreadArray(__spreadArray([], promises, true), [timeoutPromise], false)).then(function (result) {
255
- clearTimeout(timeoutId);
256
- return result;
257
- });
258
- };
259
- RetryTxSender.prototype.sendToAdditionalConnections = function (rawTx, opts) {
260
- this.additionalConnections.map(function (connection) {
261
- connection.sendRawTransaction(rawTx, opts)["catch"](function (e) {
262
- console.error(
263
- // @ts-ignore
264
- "error sending tx to additional connection ".concat(connection._rpcEndpoint));
265
- console.error(e);
266
- });
267
- });
268
- };
269
- RetryTxSender.prototype.addAdditionalConnection = function (newConnection) {
270
- var alreadyUsingConnection = this.additionalConnections.filter(function (connection) {
271
- // @ts-ignore
272
- return connection._rpcEndpoint === newConnection.rpcEndpoint;
273
- }).length > 0;
274
- if (!alreadyUsingConnection) {
275
- this.additionalConnections.push(newConnection);
276
- }
277
- };
278
- return RetryTxSender;
279
- }());
280
- exports.RetryTxSender = RetryTxSender;
package/src/tx/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
package/src/tx/utils.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.wrapInTx = void 0;
4
- var web3_js_1 = require("@solana/web3.js");
5
- var COMPUTE_UNITS_DEFAULT = 200000;
6
- function wrapInTx(instruction, computeUnits // TODO, requires less code change
7
- ) {
8
- if (computeUnits === void 0) { computeUnits = 600000; }
9
- var tx = new web3_js_1.Transaction();
10
- if (computeUnits != COMPUTE_UNITS_DEFAULT) {
11
- tx.add(web3_js_1.ComputeBudgetProgram.requestUnits({
12
- units: computeUnits,
13
- additionalFee: 0
14
- }));
15
- }
16
- return tx.add(instruction);
17
- }
18
- exports.wrapInTx = wrapInTx;
package/src/types.js DELETED
@@ -1,216 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.DefaultOrderParams = exports.LiquidationType = exports.LPAction = exports.TradeSide = exports.isOneOfVariant = exports.isVariant = exports.SpotFulfillmentStatus = exports.SpotFulfillmentType = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderDiscountTier = exports.OrderStatus = exports.MarketType = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.SpotBalanceType = exports.SwapDirection = exports.ContractType = exports.MarketStatus = void 0;
4
- var _1 = require(".");
5
- // # Utility Types / Enums / Constants
6
- var MarketStatus = /** @class */ (function () {
7
- function MarketStatus() {
8
- }
9
- MarketStatus.INITIALIZED = { initialized: {} };
10
- MarketStatus.REDUCEONLY = { reduceonly: {} };
11
- MarketStatus.SETTLEMENT = { settlement: {} };
12
- return MarketStatus;
13
- }());
14
- exports.MarketStatus = MarketStatus;
15
- var ContractType = /** @class */ (function () {
16
- function ContractType() {
17
- }
18
- ContractType.PERPETUAL = { perpetual: {} };
19
- ContractType.FUTURE = { future: {} };
20
- return ContractType;
21
- }());
22
- exports.ContractType = ContractType;
23
- var SwapDirection = /** @class */ (function () {
24
- function SwapDirection() {
25
- }
26
- SwapDirection.ADD = { add: {} };
27
- SwapDirection.REMOVE = { remove: {} };
28
- return SwapDirection;
29
- }());
30
- exports.SwapDirection = SwapDirection;
31
- var SpotBalanceType = /** @class */ (function () {
32
- function SpotBalanceType() {
33
- }
34
- SpotBalanceType.DEPOSIT = { deposit: {} };
35
- SpotBalanceType.BORROW = { borrow: {} };
36
- return SpotBalanceType;
37
- }());
38
- exports.SpotBalanceType = SpotBalanceType;
39
- var PositionDirection = /** @class */ (function () {
40
- function PositionDirection() {
41
- }
42
- PositionDirection.LONG = { long: {} };
43
- PositionDirection.SHORT = { short: {} };
44
- return PositionDirection;
45
- }());
46
- exports.PositionDirection = PositionDirection;
47
- var DepositDirection = /** @class */ (function () {
48
- function DepositDirection() {
49
- }
50
- DepositDirection.DEPOSIT = { deposit: {} };
51
- DepositDirection.WITHDRAW = { withdraw: {} };
52
- return DepositDirection;
53
- }());
54
- exports.DepositDirection = DepositDirection;
55
- var OracleSource = /** @class */ (function () {
56
- function OracleSource() {
57
- }
58
- OracleSource.PYTH = { pyth: {} };
59
- OracleSource.SWITCHBOARD = { switchboard: {} };
60
- OracleSource.QUOTE_ASSET = { quoteAsset: {} };
61
- return OracleSource;
62
- }());
63
- exports.OracleSource = OracleSource;
64
- var OrderType = /** @class */ (function () {
65
- function OrderType() {
66
- }
67
- OrderType.LIMIT = { limit: {} };
68
- OrderType.TRIGGER_MARKET = { triggerMarket: {} };
69
- OrderType.TRIGGER_LIMIT = { triggerLimit: {} };
70
- OrderType.MARKET = { market: {} };
71
- return OrderType;
72
- }());
73
- exports.OrderType = OrderType;
74
- var MarketType = /** @class */ (function () {
75
- function MarketType() {
76
- }
77
- MarketType.SPOT = { spot: {} };
78
- MarketType.PERP = { perp: {} };
79
- return MarketType;
80
- }());
81
- exports.MarketType = MarketType;
82
- var OrderStatus = /** @class */ (function () {
83
- function OrderStatus() {
84
- }
85
- OrderStatus.INIT = { init: {} };
86
- OrderStatus.OPEN = { open: {} };
87
- return OrderStatus;
88
- }());
89
- exports.OrderStatus = OrderStatus;
90
- var OrderDiscountTier = /** @class */ (function () {
91
- function OrderDiscountTier() {
92
- }
93
- OrderDiscountTier.NONE = { none: {} };
94
- OrderDiscountTier.FIRST = { first: {} };
95
- OrderDiscountTier.SECOND = { second: {} };
96
- OrderDiscountTier.THIRD = { third: {} };
97
- OrderDiscountTier.FOURTH = { fourth: {} };
98
- return OrderDiscountTier;
99
- }());
100
- exports.OrderDiscountTier = OrderDiscountTier;
101
- var OrderAction = /** @class */ (function () {
102
- function OrderAction() {
103
- }
104
- OrderAction.PLACE = { place: {} };
105
- OrderAction.CANCEL = { cancel: {} };
106
- OrderAction.EXPIRE = { expire: {} };
107
- OrderAction.FILL = { fill: {} };
108
- OrderAction.TRIGGER = { trigger: {} };
109
- return OrderAction;
110
- }());
111
- exports.OrderAction = OrderAction;
112
- var OrderActionExplanation = /** @class */ (function () {
113
- function OrderActionExplanation() {
114
- }
115
- OrderActionExplanation.NONE = { none: {} };
116
- OrderActionExplanation.ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
117
- oraclePriceBreachedLimitPrice: {}
118
- };
119
- OrderActionExplanation.MARKET_ORDER_FILLED_TO_LIMIT_PRICE = {
120
- marketOrderFilledToLimitPrice: {}
121
- };
122
- OrderActionExplanation.CANCELED_FOR_LIQUIDATION = {
123
- canceledForLiquidation: {}
124
- };
125
- OrderActionExplanation.MARKET_ORDER_AUCTION_EXPIRED = {
126
- marketOrderAuctionExpired: {}
127
- };
128
- return OrderActionExplanation;
129
- }());
130
- exports.OrderActionExplanation = OrderActionExplanation;
131
- var OrderTriggerCondition = /** @class */ (function () {
132
- function OrderTriggerCondition() {
133
- }
134
- OrderTriggerCondition.ABOVE = { above: {} };
135
- OrderTriggerCondition.BELOW = { below: {} };
136
- return OrderTriggerCondition;
137
- }());
138
- exports.OrderTriggerCondition = OrderTriggerCondition;
139
- var SpotFulfillmentType = /** @class */ (function () {
140
- function SpotFulfillmentType() {
141
- }
142
- SpotFulfillmentType.SERUM_v3 = { serumV3: {} };
143
- return SpotFulfillmentType;
144
- }());
145
- exports.SpotFulfillmentType = SpotFulfillmentType;
146
- var SpotFulfillmentStatus = /** @class */ (function () {
147
- function SpotFulfillmentStatus() {
148
- }
149
- SpotFulfillmentStatus.ENABLED = { enabled: {} };
150
- SpotFulfillmentStatus.DISABLED = { disabled: {} };
151
- return SpotFulfillmentStatus;
152
- }());
153
- exports.SpotFulfillmentStatus = SpotFulfillmentStatus;
154
- function isVariant(object, type) {
155
- return object.hasOwnProperty(type);
156
- }
157
- exports.isVariant = isVariant;
158
- function isOneOfVariant(object, types) {
159
- return types.reduce(function (result, type) {
160
- return result || object.hasOwnProperty(type);
161
- }, false);
162
- }
163
- exports.isOneOfVariant = isOneOfVariant;
164
- var TradeSide;
165
- (function (TradeSide) {
166
- TradeSide[TradeSide["None"] = 0] = "None";
167
- TradeSide[TradeSide["Buy"] = 1] = "Buy";
168
- TradeSide[TradeSide["Sell"] = 2] = "Sell";
169
- })(TradeSide = exports.TradeSide || (exports.TradeSide = {}));
170
- var LPAction = /** @class */ (function () {
171
- function LPAction() {
172
- }
173
- LPAction.ADD_LIQUIDITY = { addLiquidity: {} };
174
- LPAction.REMOVE_LIQUIDITY = { removeLiquidity: {} };
175
- LPAction.SETTLE_LIQUIDITY = { settleLiquidity: {} };
176
- return LPAction;
177
- }());
178
- exports.LPAction = LPAction;
179
- var LiquidationType = /** @class */ (function () {
180
- function LiquidationType() {
181
- }
182
- LiquidationType.LIQUIDATE_PERP = { liquidatePerp: {} };
183
- LiquidationType.LIQUIDATE_BORROW = { liquidateBorrow: {} };
184
- LiquidationType.LIQUIDATE_BORROW_FOR_PERP_PNL = {
185
- liquidateBorrowForPerpPnl: {}
186
- };
187
- LiquidationType.LIQUIDATE_PERP_PNL_FOR_DEPOSIT = {
188
- liquidatePerpPnlForDeposit: {}
189
- };
190
- LiquidationType.PERP_BANKRUPTCY = {
191
- perpBankruptcy: {}
192
- };
193
- LiquidationType.BORROW_BANKRUPTCY = {
194
- borrowBankruptcy: {}
195
- };
196
- return LiquidationType;
197
- }());
198
- exports.LiquidationType = LiquidationType;
199
- exports.DefaultOrderParams = {
200
- orderType: OrderType.MARKET,
201
- marketType: MarketType.PERP,
202
- userOrderId: 0,
203
- direction: PositionDirection.LONG,
204
- baseAssetAmount: _1.ZERO,
205
- price: _1.ZERO,
206
- marketIndex: _1.ZERO,
207
- reduceOnly: false,
208
- postOnly: false,
209
- immediateOrCancel: false,
210
- triggerPrice: _1.ZERO,
211
- triggerCondition: OrderTriggerCondition.ABOVE,
212
- positionLimit: _1.ZERO,
213
- oraclePriceOffset: _1.ZERO,
214
- padding0: _1.ZERO,
215
- padding1: _1.ZERO
216
- };
package/src/userName.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.decodeName = exports.encodeName = exports.DEFAULT_USER_NAME = exports.MAX_NAME_LENGTH = void 0;
4
- exports.MAX_NAME_LENGTH = 32;
5
- exports.DEFAULT_USER_NAME = 'Main Account';
6
- function encodeName(name) {
7
- if (name.length > exports.MAX_NAME_LENGTH) {
8
- throw Error("User name (".concat(name, ") longer than 32 characters"));
9
- }
10
- var buffer = Buffer.alloc(32);
11
- buffer.fill(name);
12
- buffer.fill(' ', name.length);
13
- return Array.apply(void 0, buffer);
14
- }
15
- exports.encodeName = encodeName;
16
- function decodeName(bytes) {
17
- var buffer = Buffer.from(bytes);
18
- return buffer.toString('utf8').trim();
19
- }
20
- exports.decodeName = decodeName;
@@ -1,62 +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.findComputeUnitConsumption = void 0;
40
- function findComputeUnitConsumption(programId, connection, txSignature, commitment) {
41
- if (commitment === void 0) { commitment = 'confirmed'; }
42
- return __awaiter(this, void 0, void 0, function () {
43
- var tx, computeUnits, regex;
44
- return __generator(this, function (_a) {
45
- switch (_a.label) {
46
- case 0: return [4 /*yield*/, connection.getTransaction(txSignature, { commitment: commitment })];
47
- case 1:
48
- tx = _a.sent();
49
- computeUnits = [];
50
- regex = new RegExp("Program ".concat(programId.toString(), " consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units"));
51
- tx.meta.logMessages.forEach(function (logMessage) {
52
- var match = logMessage.match(regex);
53
- if (match && match[1]) {
54
- computeUnits.push(match[1]);
55
- }
56
- });
57
- return [2 /*return*/, computeUnits];
58
- }
59
- });
60
- });
61
- }
62
- exports.findComputeUnitConsumption = findComputeUnitConsumption;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- exports.promiseTimeout = void 0;
4
- function promiseTimeout(promise, timeoutMs) {
5
- var timeoutId;
6
- var timeoutPromise = new Promise(function (resolve) {
7
- timeoutId = setTimeout(function () { return resolve(null); }, timeoutMs);
8
- });
9
- return Promise.race([promise, timeoutPromise]).then(function (result) {
10
- clearTimeout(timeoutId);
11
- return result;
12
- });
13
- }
14
- exports.promiseTimeout = promiseTimeout;
package/src/util/tps.js DELETED
@@ -1,61 +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.estimateTps = void 0;
40
- function estimateTps(programId, connection, failed) {
41
- return __awaiter(this, void 0, void 0, function () {
42
- var signatures, numberOfSignatures;
43
- return __generator(this, function (_a) {
44
- switch (_a.label) {
45
- case 0: return [4 /*yield*/, connection.getSignaturesForAddress(programId, undefined, 'finalized')];
46
- case 1:
47
- signatures = _a.sent();
48
- if (failed) {
49
- signatures = signatures.filter(function (signature) { return signature.err; });
50
- }
51
- numberOfSignatures = signatures.length;
52
- if (numberOfSignatures === 0) {
53
- return [2 /*return*/, 0];
54
- }
55
- return [2 /*return*/, (numberOfSignatures /
56
- (signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime))];
57
- }
58
- });
59
- });
60
- }
61
- exports.estimateTps = estimateTps;