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

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 +1 -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 +2 -0
  9. package/lib/clearingHouse.js +14 -1
  10. package/lib/clearingHouseUser.d.ts +11 -9
  11. package/lib/clearingHouseUser.js +182 -106
  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 +122 -202
  20. package/lib/index.d.ts +5 -0
  21. package/lib/index.js +5 -0
  22. package/lib/math/market.d.ts +1 -1
  23. package/lib/math/market.js +1 -1
  24. package/lib/math/orders.d.ts +3 -3
  25. package/lib/math/orders.js +31 -16
  26. package/lib/math/spotBalance.d.ts +3 -0
  27. package/lib/math/spotBalance.js +18 -1
  28. package/lib/math/spotPosition.d.ts +5 -1
  29. package/lib/math/spotPosition.js +16 -1
  30. package/lib/types.d.ts +24 -23
  31. package/lib/types.js +9 -3
  32. package/lib/userMap/userMap.d.ts +25 -0
  33. package/lib/userMap/userMap.js +73 -0
  34. package/lib/userMap/userStatsMap.d.ts +19 -0
  35. package/lib/userMap/userStatsMap.js +68 -0
  36. package/package.json +6 -3
  37. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +4 -0
  38. package/src/accounts/types.ts +1 -0
  39. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +6 -0
  40. package/src/addresses/marketAddresses.js +26 -0
  41. package/src/admin.ts +50 -8
  42. package/src/assert/assert.js +1 -1
  43. package/src/clearingHouse.ts +23 -1
  44. package/src/clearingHouseUser.ts +364 -165
  45. package/src/config.ts +1 -1
  46. package/src/constants/banks.js +42 -0
  47. package/src/constants/{perpMarkets.js → markets.js} +11 -11
  48. package/src/dlob/DLOB.ts +884 -0
  49. package/src/dlob/DLOBNode.ts +163 -0
  50. package/src/dlob/NodeList.ts +185 -0
  51. package/src/events/eventList.js +23 -66
  52. package/src/events/txEventCache.js +19 -22
  53. package/src/examples/makeTradeExample.js +157 -0
  54. package/src/factory/bigNum.js +180 -183
  55. package/src/factory/oracleClient.js +9 -9
  56. package/src/idl/clearing_house.json +122 -202
  57. package/src/index.ts +5 -0
  58. package/src/math/auction.js +10 -10
  59. package/src/math/conversion.js +3 -4
  60. package/src/math/funding.js +175 -223
  61. package/src/math/market.ts +1 -1
  62. package/src/math/orders.ts +29 -21
  63. package/src/math/repeg.js +40 -40
  64. package/src/math/spotBalance.ts +26 -0
  65. package/src/math/spotPosition.ts +42 -1
  66. package/src/math/trade.js +74 -81
  67. package/src/math/utils.js +7 -8
  68. package/src/math/utils.js.map +1 -0
  69. package/src/oracles/oracleClientCache.js +9 -10
  70. package/src/oracles/pythClient.js +17 -52
  71. package/src/oracles/quoteAssetOracleClient.js +13 -44
  72. package/src/oracles/switchboardClient.js +37 -69
  73. package/src/oracles/types.js +1 -1
  74. package/src/token/index.js +4 -4
  75. package/src/tx/types.js +1 -1
  76. package/src/tx/utils.js +6 -7
  77. package/src/types.ts +25 -23
  78. package/src/userMap/userMap.ts +100 -0
  79. package/src/userMap/userStatsMap.ts +110 -0
  80. package/src/userName.js +5 -5
  81. package/src/util/computeUnits.js +11 -46
  82. package/src/util/getTokenAddress.js +9 -0
  83. package/src/util/promiseTimeout.js +5 -5
  84. package/src/util/tps.js +12 -46
  85. package/src/wallet.js +18 -55
  86. package/tests/bn/test.ts +2 -3
  87. package/tests/dlob/helpers.ts +322 -0
  88. package/tests/dlob/test.ts +2865 -0
  89. package/my-script/.env +0 -7
  90. package/my-script/getUserStats.ts +0 -106
  91. package/my-script/multiConnections.ts +0 -119
  92. package/my-script/test-regex.ts +0 -11
  93. package/my-script/utils.ts +0 -52
  94. package/src/accounts/bulkAccountLoader.js +0 -249
  95. package/src/accounts/bulkUserStatsSubscription.js +0 -75
  96. package/src/accounts/bulkUserSubscription.js +0 -75
  97. package/src/accounts/fetch.js +0 -92
  98. package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -465
  99. package/src/accounts/pollingOracleSubscriber.js +0 -156
  100. package/src/accounts/pollingTokenAccountSubscriber.js +0 -141
  101. package/src/accounts/pollingUserAccountSubscriber.js +0 -208
  102. package/src/accounts/pollingUserStatsAccountSubscriber.js +0 -208
  103. package/src/accounts/types.js +0 -28
  104. package/src/accounts/utils.js +0 -7
  105. package/src/accounts/webSocketAccountSubscriber.js +0 -138
  106. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -433
  107. package/src/accounts/webSocketUserAccountSubscriber.js +0 -113
  108. package/src/accounts/webSocketUserStatsAccountSubsriber.js +0 -113
  109. package/src/addresses/pda.js +0 -186
  110. package/src/admin.js +0 -1284
  111. package/src/clearingHouse.js +0 -3433
  112. package/src/clearingHouseConfig.js +0 -2
  113. package/src/clearingHouseUser.js +0 -874
  114. package/src/clearingHouseUserConfig.js +0 -2
  115. package/src/clearingHouseUserStats.js +0 -115
  116. package/src/clearingHouseUserStatsConfig.js +0 -2
  117. package/src/config.js +0 -80
  118. package/src/constants/numericConstants.js +0 -48
  119. package/src/constants/spotMarkets.js +0 -51
  120. package/src/events/eventSubscriber.js +0 -202
  121. package/src/events/fetchLogs.js +0 -117
  122. package/src/events/pollingLogProvider.js +0 -113
  123. package/src/events/sort.js +0 -41
  124. package/src/events/types.js +0 -25
  125. package/src/events/webSocketLogProvider.js +0 -76
  126. package/src/index.js +0 -75
  127. package/src/math/amm.js +0 -422
  128. package/src/math/insurance.js +0 -27
  129. package/src/math/margin.js +0 -77
  130. package/src/math/market.js +0 -105
  131. package/src/math/oracles.js +0 -56
  132. package/src/math/orders.js +0 -153
  133. package/src/math/position.js +0 -172
  134. package/src/math/spotBalance.js +0 -176
  135. package/src/math/spotMarket.js +0 -8
  136. package/src/math/spotPosition.js +0 -8
  137. package/src/orderParams.js +0 -28
  138. package/src/serum/serumSubscriber.js +0 -102
  139. package/src/serum/types.js +0 -2
  140. package/src/slot/SlotSubscriber.js +0 -86
  141. package/src/tokenFaucet.js +0 -323
  142. package/src/tx/retryTxSender.js +0 -280
  143. package/src/types.js +0 -216
@@ -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/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
- };