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

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 (184) hide show
  1. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +13 -13
  2. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +27 -27
  3. package/lib/accounts/types.d.ts +8 -9
  4. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +14 -14
  5. package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +35 -34
  6. package/lib/addresses/pda.d.ts +7 -6
  7. package/lib/addresses/pda.js +31 -27
  8. package/lib/admin.d.ts +9 -6
  9. package/lib/admin.js +83 -42
  10. package/lib/clearingHouse.d.ts +69 -42
  11. package/lib/clearingHouse.js +753 -277
  12. package/lib/clearingHouseConfig.d.ts +2 -2
  13. package/lib/clearingHouseUser.d.ts +16 -16
  14. package/lib/clearingHouseUser.js +139 -119
  15. package/lib/config.d.ts +7 -7
  16. package/lib/config.js +20 -20
  17. package/lib/constants/numericConstants.d.ts +12 -12
  18. package/lib/constants/numericConstants.js +13 -13
  19. package/lib/constants/{markets.d.ts → perpMarkets.d.ts} +5 -5
  20. package/{src/constants/markets.js → lib/constants/perpMarkets.js} +4 -4
  21. package/lib/constants/{banks.d.ts → spotMarkets.d.ts} +6 -6
  22. package/lib/constants/{banks.js → spotMarkets.js} +16 -16
  23. package/lib/events/types.d.ts +2 -1
  24. package/lib/events/types.js +1 -0
  25. package/lib/examples/makeTradeExample.js +7 -7
  26. package/lib/idl/clearing_house.json +1008 -279
  27. package/lib/index.d.ts +5 -3
  28. package/lib/index.js +5 -3
  29. package/lib/math/amm.d.ts +2 -2
  30. package/lib/math/amm.js +1 -1
  31. package/lib/math/funding.d.ts +6 -6
  32. package/lib/math/funding.js +2 -1
  33. package/lib/math/margin.d.ts +4 -4
  34. package/lib/math/margin.js +18 -11
  35. package/lib/math/market.d.ts +10 -9
  36. package/lib/math/market.js +29 -6
  37. package/lib/math/oracles.d.ts +2 -1
  38. package/lib/math/oracles.js +11 -1
  39. package/lib/math/orders.d.ts +5 -5
  40. package/lib/math/position.d.ts +13 -13
  41. package/lib/math/position.js +19 -19
  42. package/lib/math/spotBalance.d.ts +19 -0
  43. package/lib/math/spotBalance.js +176 -0
  44. package/lib/math/spotMarket.d.ts +4 -0
  45. package/lib/math/spotMarket.js +8 -0
  46. package/lib/math/spotPosition.d.ts +2 -0
  47. package/lib/math/spotPosition.js +8 -0
  48. package/lib/math/state.js +2 -2
  49. package/lib/math/trade.d.ts +4 -4
  50. package/lib/orderParams.d.ts +4 -4
  51. package/lib/orderParams.js +12 -4
  52. package/lib/serum/serumSubscriber.d.ts +23 -0
  53. package/lib/serum/serumSubscriber.js +41 -0
  54. package/lib/serum/types.d.ts +11 -0
  55. package/lib/serum/types.js +2 -0
  56. package/lib/tx/retryTxSender.d.ts +1 -1
  57. package/lib/tx/retryTxSender.js +4 -2
  58. package/lib/tx/types.d.ts +1 -1
  59. package/lib/types.d.ts +123 -33
  60. package/lib/types.js +31 -9
  61. package/my-script/.env +7 -0
  62. package/my-script/getUserStats.ts +106 -0
  63. package/my-script/multiConnections.ts +119 -0
  64. package/my-script/test-regex.ts +11 -0
  65. package/my-script/utils.ts +52 -0
  66. package/package.json +1 -1
  67. package/src/accounts/bulkAccountLoader.js +249 -0
  68. package/src/accounts/bulkUserStatsSubscription.js +75 -0
  69. package/src/accounts/bulkUserSubscription.js +75 -0
  70. package/src/accounts/fetch.js +92 -0
  71. package/src/accounts/pollingClearingHouseAccountSubscriber.js +465 -0
  72. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +38 -38
  73. package/src/accounts/pollingOracleSubscriber.js +156 -0
  74. package/src/accounts/pollingTokenAccountSubscriber.js +141 -0
  75. package/src/accounts/pollingUserAccountSubscriber.js +208 -0
  76. package/src/accounts/pollingUserStatsAccountSubscriber.js +208 -0
  77. package/src/accounts/types.js +28 -0
  78. package/src/accounts/types.ts +11 -9
  79. package/src/accounts/utils.js +7 -0
  80. package/src/accounts/webSocketAccountSubscriber.js +138 -0
  81. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +433 -0
  82. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +59 -52
  83. package/src/accounts/webSocketUserAccountSubscriber.js +113 -0
  84. package/src/accounts/webSocketUserStatsAccountSubsriber.js +113 -0
  85. package/src/addresses/pda.js +186 -0
  86. package/src/addresses/pda.ts +49 -44
  87. package/src/admin.js +1284 -0
  88. package/src/admin.ts +140 -47
  89. package/src/assert/assert.js +1 -1
  90. package/src/clearingHouse.js +3433 -0
  91. package/src/clearingHouse.ts +1083 -378
  92. package/src/clearingHouseConfig.js +2 -0
  93. package/src/clearingHouseConfig.ts +2 -2
  94. package/src/clearingHouseUser.js +874 -0
  95. package/src/clearingHouseUser.ts +232 -168
  96. package/src/clearingHouseUserConfig.js +2 -0
  97. package/src/clearingHouseUserStats.js +115 -0
  98. package/src/clearingHouseUserStatsConfig.js +2 -0
  99. package/src/config.js +80 -0
  100. package/src/config.ts +29 -29
  101. package/src/constants/numericConstants.js +18 -11
  102. package/src/constants/numericConstants.ts +17 -15
  103. package/{lib/constants/markets.js → src/constants/perpMarkets.js} +11 -11
  104. package/src/constants/{markets.ts → perpMarkets.ts} +5 -5
  105. package/src/constants/spotMarkets.js +51 -0
  106. package/src/constants/{banks.ts → spotMarkets.ts} +19 -19
  107. package/src/events/eventList.js +66 -23
  108. package/src/events/eventSubscriber.js +202 -0
  109. package/src/events/fetchLogs.js +117 -0
  110. package/src/events/pollingLogProvider.js +113 -0
  111. package/src/events/sort.js +41 -0
  112. package/src/events/txEventCache.js +22 -19
  113. package/src/events/types.js +25 -0
  114. package/src/events/types.ts +3 -0
  115. package/src/events/webSocketLogProvider.js +76 -0
  116. package/src/examples/makeTradeExample.ts +10 -8
  117. package/src/factory/bigNum.js +183 -180
  118. package/src/factory/oracleClient.js +9 -9
  119. package/src/idl/clearing_house.json +1008 -279
  120. package/src/index.js +75 -0
  121. package/src/index.ts +5 -3
  122. package/src/math/amm.js +422 -0
  123. package/src/math/amm.ts +6 -3
  124. package/src/math/auction.js +10 -10
  125. package/src/math/conversion.js +4 -3
  126. package/src/math/funding.js +223 -175
  127. package/src/math/funding.ts +7 -7
  128. package/src/math/insurance.js +27 -0
  129. package/src/math/margin.js +77 -0
  130. package/src/math/margin.ts +34 -23
  131. package/src/math/market.js +105 -0
  132. package/src/math/market.ts +71 -19
  133. package/src/math/oracles.js +40 -10
  134. package/src/math/oracles.ts +18 -1
  135. package/src/math/orders.js +153 -0
  136. package/src/math/orders.ts +5 -5
  137. package/src/math/position.js +172 -0
  138. package/src/math/position.ts +31 -31
  139. package/src/math/repeg.js +40 -40
  140. package/src/math/spotBalance.js +176 -0
  141. package/src/math/spotBalance.ts +290 -0
  142. package/src/math/spotMarket.js +8 -0
  143. package/src/math/spotMarket.ts +9 -0
  144. package/src/math/spotPosition.js +8 -0
  145. package/src/math/spotPosition.ts +6 -0
  146. package/src/math/state.ts +2 -2
  147. package/src/math/trade.js +81 -74
  148. package/src/math/trade.ts +4 -4
  149. package/src/math/utils.js +8 -7
  150. package/src/oracles/oracleClientCache.js +10 -9
  151. package/src/oracles/pythClient.js +52 -17
  152. package/src/oracles/quoteAssetOracleClient.js +44 -13
  153. package/src/oracles/switchboardClient.js +69 -37
  154. package/src/oracles/types.js +1 -1
  155. package/src/orderParams.js +14 -6
  156. package/src/orderParams.ts +16 -8
  157. package/src/serum/serumSubscriber.js +102 -0
  158. package/src/serum/serumSubscriber.ts +80 -0
  159. package/src/serum/types.js +2 -0
  160. package/src/serum/types.ts +13 -0
  161. package/src/slot/SlotSubscriber.js +67 -20
  162. package/src/token/index.js +4 -4
  163. package/src/tokenFaucet.js +288 -154
  164. package/src/tx/retryTxSender.js +280 -0
  165. package/src/tx/retryTxSender.ts +5 -2
  166. package/src/tx/types.js +1 -1
  167. package/src/tx/types.ts +2 -1
  168. package/src/tx/utils.js +7 -6
  169. package/src/types.js +216 -0
  170. package/src/types.ts +110 -33
  171. package/src/userName.js +5 -5
  172. package/src/util/computeUnits.js +46 -11
  173. package/src/util/promiseTimeout.js +5 -5
  174. package/src/util/tps.js +46 -12
  175. package/src/wallet.js +55 -18
  176. package/lib/math/bankBalance.d.ts +0 -15
  177. package/lib/math/bankBalance.js +0 -150
  178. package/src/addresses/marketAddresses.js +0 -26
  179. package/src/constants/banks.js +0 -42
  180. package/src/examples/makeTradeExample.js +0 -80
  181. package/src/math/bankBalance.ts +0 -258
  182. package/src/math/state.js +0 -15
  183. package/src/math/utils.js.map +0 -1
  184. package/src/util/getTokenAddress.js +0 -9
@@ -0,0 +1,280 @@
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;
@@ -42,7 +42,8 @@ export class RetryTxSender implements TxSender {
42
42
  async send(
43
43
  tx: Transaction,
44
44
  additionalSigners?: Array<Signer>,
45
- opts?: ConfirmOptions
45
+ opts?: ConfirmOptions,
46
+ preSigned?: boolean
46
47
  ): Promise<TxSigAndSlot> {
47
48
  if (additionalSigners === undefined) {
48
49
  additionalSigners = [];
@@ -51,7 +52,9 @@ export class RetryTxSender implements TxSender {
51
52
  opts = this.provider.opts;
52
53
  }
53
54
 
54
- await this.prepareTx(tx, additionalSigners, opts);
55
+ if (!preSigned) {
56
+ await this.prepareTx(tx, additionalSigners, opts);
57
+ }
55
58
 
56
59
  const rawTransaction = tx.serialize();
57
60
  const startTime = this.getTimestamp();
package/src/tx/types.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.__esModule = true;
package/src/tx/types.ts CHANGED
@@ -17,6 +17,7 @@ export interface TxSender {
17
17
  send(
18
18
  tx: Transaction,
19
19
  additionalSigners?: Array<Signer>,
20
- opts?: ConfirmOptions
20
+ opts?: ConfirmOptions,
21
+ preSigned?: boolean
21
22
  ): Promise<TxSigAndSlot>;
22
23
  }
package/src/tx/utils.js CHANGED
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.__esModule = true;
3
3
  exports.wrapInTx = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- const COMPUTE_UNITS_DEFAULT = 200000;
6
- function wrapInTx(instruction, computeUnits = 600000 // TODO, requires less code change
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
7
  ) {
8
- const tx = new web3_js_1.Transaction();
8
+ if (computeUnits === void 0) { computeUnits = 600000; }
9
+ var tx = new web3_js_1.Transaction();
9
10
  if (computeUnits != COMPUTE_UNITS_DEFAULT) {
10
11
  tx.add(web3_js_1.ComputeBudgetProgram.requestUnits({
11
12
  units: computeUnits,
12
- additionalFee: 0,
13
+ additionalFee: 0
13
14
  }));
14
15
  }
15
16
  return tx.add(instruction);
package/src/types.js ADDED
@@ -0,0 +1,216 @@
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
+ };