@drift-labs/sdk 0.1.23-master.0 → 0.1.23-master.2

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.
@@ -23,7 +23,7 @@ class BulkAccountLoader {
23
23
  }
24
24
  addAccount(publicKey, callback) {
25
25
  const existingSize = this.accountsToLoad.size;
26
- const callbackId = uuid_1.v4();
26
+ const callbackId = (0, uuid_1.v4)();
27
27
  const existingAccountToLoad = this.accountsToLoad.get(publicKey.toString());
28
28
  if (existingAccountToLoad) {
29
29
  existingAccountToLoad.callbacks.set(callbackId, callback);
@@ -57,7 +57,7 @@ class BulkAccountLoader {
57
57
  }
58
58
  }
59
59
  addErrorCallbacks(callback) {
60
- const callbackId = uuid_1.v4();
60
+ const callbackId = (0, uuid_1.v4)();
61
61
  this.errorCallbacks.set(callbackId, callback);
62
62
  return callbackId;
63
63
  }
@@ -54,7 +54,7 @@ class PollingClearingHouseAccountSubscriber {
54
54
  if (this.accountsToPoll.size > 0) {
55
55
  return;
56
56
  }
57
- const statePublicKey = yield addresses_1.getClearingHouseStateAccountPublicKey(this.program.programId);
57
+ const statePublicKey = yield (0, addresses_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
58
58
  const state = (yield this.program.account.state.fetch(statePublicKey));
59
59
  this.accountsToPoll.set(statePublicKey.toString(), {
60
60
  key: 'state',
@@ -127,7 +127,7 @@ class PollingClearingHouseAccountSubscriber {
127
127
  return __awaiter(this, void 0, void 0, function* () {
128
128
  for (const [_, accountToPoll] of this.accountsToPoll) {
129
129
  accountToPoll.callbackId = this.accountLoader.addAccount(accountToPoll.publicKey, (buffer) => {
130
- const account = this.program.account[accountToPoll.key].coder.accounts.decode(utils_1.capitalize(accountToPoll.key), buffer);
130
+ const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
131
131
  this[accountToPoll.key] = account;
132
132
  // @ts-ignore
133
133
  this.eventEmitter.emit(accountToPoll.eventType, account);
@@ -145,7 +145,7 @@ class PollingClearingHouseAccountSubscriber {
145
145
  for (const [_, accountToPoll] of this.accountsToPoll) {
146
146
  const buffer = this.accountLoader.getAccountData(accountToPoll.publicKey);
147
147
  if (buffer) {
148
- this[accountToPoll.key] = this.program.account[accountToPoll.key].coder.accounts.decode(utils_1.capitalize(accountToPoll.key), buffer);
148
+ this[accountToPoll.key] = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
149
149
  }
150
150
  }
151
151
  });
@@ -37,7 +37,7 @@ class PollingTokenAccountSubscriber {
37
37
  return;
38
38
  }
39
39
  this.callbackId = this.accountLoader.addAccount(this.publicKey, (buffer) => {
40
- const tokenAccount = token_1.parseTokenAccount(buffer);
40
+ const tokenAccount = (0, token_1.parseTokenAccount)(buffer);
41
41
  this.tokenAccount = tokenAccount;
42
42
  // @ts-ignore
43
43
  this.eventEmitter.emit('tokenAccountUpdate', tokenAccount);
@@ -51,7 +51,7 @@ class PollingTokenAccountSubscriber {
51
51
  return __awaiter(this, void 0, void 0, function* () {
52
52
  yield this.accountLoader.load();
53
53
  const buffer = this.accountLoader.getAccountData(this.publicKey);
54
- this.tokenAccount = token_1.parseTokenAccount(buffer);
54
+ this.tokenAccount = (0, token_1.parseTokenAccount)(buffer);
55
55
  });
56
56
  }
57
57
  unsubscribe() {
@@ -42,7 +42,7 @@ class PollingUserAccountSubscriber {
42
42
  return;
43
43
  }
44
44
  if (!userPublicKeys) {
45
- const userPublicKey = yield addresses_1.getUserAccountPublicKey(this.program.programId, this.authority);
45
+ const userPublicKey = yield (0, addresses_1.getUserAccountPublicKey)(this.program.programId, this.authority);
46
46
  const userAccount = (yield this.program.account.user.fetch(userPublicKey));
47
47
  this.accountsToPoll.set(userPublicKey.toString(), {
48
48
  key: 'user',
@@ -54,7 +54,7 @@ class PollingUserAccountSubscriber {
54
54
  publicKey: userAccount.positions,
55
55
  eventType: 'userPositionsData',
56
56
  });
57
- const userOrdersPublicKey = yield addresses_1.getUserOrdersAccountPublicKey(this.program.programId, userPublicKey);
57
+ const userOrdersPublicKey = yield (0, addresses_1.getUserOrdersAccountPublicKey)(this.program.programId, userPublicKey);
58
58
  this.accountsToPoll.set(userOrdersPublicKey.toString(), {
59
59
  key: 'userOrders',
60
60
  publicKey: userOrdersPublicKey,
@@ -85,7 +85,7 @@ class PollingUserAccountSubscriber {
85
85
  if (!buffer) {
86
86
  return;
87
87
  }
88
- const account = this.program.account[accountToPoll.key].coder.accounts.decode(utils_1.capitalize(accountToPoll.key), buffer);
88
+ const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
89
89
  this[accountToPoll.key] = account;
90
90
  // @ts-ignore
91
91
  this.eventEmitter.emit(accountToPoll.eventType, account);
@@ -117,7 +117,7 @@ class PollingUserAccountSubscriber {
117
117
  for (const [_, accountToPoll] of this.accountsToPoll) {
118
118
  const buffer = this.accountLoader.getAccountData(accountToPoll.publicKey);
119
119
  if (buffer) {
120
- this[accountToPoll.key] = this.program.account[accountToPoll.key].coder.accounts.decode(utils_1.capitalize(accountToPoll.key), buffer);
120
+ this[accountToPoll.key] = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
121
121
  }
122
122
  }
123
123
  });
@@ -47,7 +47,7 @@ class WebSocketAccountSubscriber {
47
47
  slot: newSlot,
48
48
  };
49
49
  if (newBuffer) {
50
- this.data = this.program.account[this.accountName].coder.accounts.decode(utils_1.capitalize(this.accountName), newBuffer);
50
+ this.data = this.program.account[this.accountName].coder.accounts.decode((0, utils_1.capitalize)(this.accountName), newBuffer);
51
51
  this.onChange(this.data);
52
52
  }
53
53
  return;
@@ -61,7 +61,7 @@ class WebSocketAccountSubscriber {
61
61
  buffer: newBuffer,
62
62
  slot: newSlot,
63
63
  };
64
- this.data = this.program.account[this.accountName].coder.accounts.decode(utils_1.capitalize(this.accountName), newBuffer);
64
+ this.data = this.program.account[this.accountName].coder.accounts.decode((0, utils_1.capitalize)(this.accountName), newBuffer);
65
65
  this.onChange(this.data);
66
66
  }
67
67
  }
@@ -35,7 +35,7 @@ class WebSocketClearingHouseAccountSubscriber {
35
35
  this.subscriptionPromise = new Promise((res) => {
36
36
  this.subscriptionPromiseResolver = res;
37
37
  });
38
- const statePublicKey = yield addresses_1.getClearingHouseStateAccountPublicKey(this.program.programId);
38
+ const statePublicKey = yield (0, addresses_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
39
39
  // create and activate main state account subscription
40
40
  this.stateAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('state', this.program, statePublicKey);
41
41
  yield this.stateAccountSubscriber.subscribe((data) => {
@@ -27,7 +27,7 @@ class WebSocketUserAccountSubscriber {
27
27
  if (this.isSubscribed) {
28
28
  return true;
29
29
  }
30
- const userPublicKey = yield addresses_1.getUserAccountPublicKey(this.program.programId, this.authority);
30
+ const userPublicKey = yield (0, addresses_1.getUserAccountPublicKey)(this.program.programId, this.authority);
31
31
  this.userDataAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('user', this.program, userPublicKey);
32
32
  yield this.userDataAccountSubscriber.subscribe((data) => {
33
33
  this.eventEmitter.emit('userAccountData', data);
@@ -39,7 +39,7 @@ class WebSocketUserAccountSubscriber {
39
39
  this.eventEmitter.emit('userPositionsData', data);
40
40
  this.eventEmitter.emit('update');
41
41
  });
42
- const userOrdersPublicKey = yield addresses_1.getUserOrdersAccountPublicKey(this.program.programId, userPublicKey);
42
+ const userOrdersPublicKey = yield (0, addresses_1.getUserOrdersAccountPublicKey)(this.program.programId, userPublicKey);
43
43
  this.userOrdersAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userOrders', this.program, userOrdersPublicKey);
44
44
  yield this.userOrdersAccountSubscriber.subscribe((data) => {
45
45
  this.eventEmitter.emit('userOrdersData', data);
package/lib/admin.js CHANGED
@@ -41,8 +41,8 @@ const amm_1 = require("./math/amm");
41
41
  const clearingHouse_2 = require("./factory/clearingHouse");
42
42
  class Admin extends clearingHouse_1.ClearingHouse {
43
43
  static from(connection, wallet, clearingHouseProgramId, opts = anchor_1.Provider.defaultOptions()) {
44
- const config = clearingHouse_2.getWebSocketClearingHouseConfig(connection, wallet, clearingHouseProgramId, opts);
45
- return clearingHouse_2.getAdmin(config);
44
+ const config = (0, clearingHouse_2.getWebSocketClearingHouseConfig)(connection, wallet, clearingHouseProgramId, opts);
45
+ return (0, clearingHouse_2.getAdmin)(config);
46
46
  }
47
47
  initialize(usdcMint, adminControlsPrices) {
48
48
  return __awaiter(this, void 0, void 0, function* () {
@@ -61,7 +61,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
61
61
  const tradeHistory = anchor.web3.Keypair.generate();
62
62
  const liquidationHistory = anchor.web3.Keypair.generate();
63
63
  const curveHistory = anchor.web3.Keypair.generate();
64
- const [clearingHouseStatePublicKey, clearingHouseNonce] = yield addresses_1.getClearingHouseStateAccountPublicKeyAndNonce(this.program.programId);
64
+ const [clearingHouseStatePublicKey, clearingHouseNonce] = yield (0, addresses_1.getClearingHouseStateAccountPublicKeyAndNonce)(this.program.programId);
65
65
  const initializeTx = yield this.program.transaction.initialize(clearingHouseNonce, collateralVaultNonce, insuranceVaultNonce, adminControlsPrices, {
66
66
  accounts: {
67
67
  admin: this.wallet.publicKey,
@@ -118,8 +118,8 @@ class Admin extends clearingHouse_1.ClearingHouse {
118
118
  initializeOrderState() {
119
119
  return __awaiter(this, void 0, void 0, function* () {
120
120
  const orderHistory = anchor.web3.Keypair.generate();
121
- const [orderStatePublicKey, orderStateNonce] = yield addresses_1.getOrderStateAccountPublicKeyAndNonce(this.program.programId);
122
- const clearingHouseStatePublicKey = yield addresses_1.getClearingHouseStateAccountPublicKey(this.program.programId);
121
+ const [orderStatePublicKey, orderStateNonce] = yield (0, addresses_1.getOrderStateAccountPublicKeyAndNonce)(this.program.programId);
122
+ const clearingHouseStatePublicKey = yield (0, addresses_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
123
123
  const initializeOrderStateTx = yield this.program.transaction.initializeOrderState(orderStateNonce, {
124
124
  accounts: {
125
125
  admin: this.wallet.publicKey,
@@ -202,8 +202,8 @@ class Admin extends clearingHouse_1.ClearingHouse {
202
202
  moveAmmToPrice(marketIndex, targetPrice) {
203
203
  return __awaiter(this, void 0, void 0, function* () {
204
204
  const market = this.getMarket(marketIndex);
205
- const [direction, tradeSize, _] = trade_1.calculateTargetPriceTrade(market, targetPrice);
206
- const [newQuoteAssetAmount, newBaseAssetAmount] = amm_1.calculateAmmReservesAfterSwap(market.amm, 'quote', tradeSize, amm_1.getSwapDirection('quote', direction));
205
+ const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(market, targetPrice);
206
+ const [newQuoteAssetAmount, newBaseAssetAmount] = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction));
207
207
  const state = this.getStateAccount();
208
208
  return yield this.program.rpc.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, marketIndex, {
209
209
  accounts: {
@@ -38,7 +38,6 @@ const anchor = __importStar(require("@project-serum/anchor"));
38
38
  const clearing_house_json_1 = __importDefault(require("./idl/clearing_house.json"));
39
39
  const web3_js_1 = require("@solana/web3.js");
40
40
  const addresses_1 = require("./addresses");
41
- const defaultTxSender_1 = require("./tx/defaultTxSender");
42
41
  const utils_1 = require("./tx/utils");
43
42
  const clearingHouse_1 = require("./factory/clearingHouse");
44
43
  /**
@@ -74,8 +73,8 @@ class ClearingHouse {
74
73
  * @returns
75
74
  */
76
75
  static from(connection, wallet, clearingHouseProgramId, opts = anchor_1.Provider.defaultOptions()) {
77
- const config = clearingHouse_1.getWebSocketClearingHouseConfig(connection, wallet, clearingHouseProgramId, opts);
78
- return clearingHouse_1.getClearingHouse(config);
76
+ const config = (0, clearingHouse_1.getWebSocketClearingHouseConfig)(connection, wallet, clearingHouseProgramId, opts);
77
+ return (0, clearingHouse_1.getClearingHouse)(config);
79
78
  }
80
79
  /**
81
80
  *
@@ -127,7 +126,7 @@ class ClearingHouse {
127
126
  if (this.statePublicKey) {
128
127
  return this.statePublicKey;
129
128
  }
130
- this.statePublicKey = yield addresses_1.getClearingHouseStateAccountPublicKey(this.program.programId);
129
+ this.statePublicKey = yield (0, addresses_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
131
130
  return this.statePublicKey;
132
131
  });
133
132
  }
@@ -169,7 +168,7 @@ class ClearingHouse {
169
168
  if (this.orderStatePublicKey) {
170
169
  return this.orderStatePublicKey;
171
170
  }
172
- this.orderStatePublicKey = yield addresses_1.getOrderStateAccountPublicKey(this.program.programId);
171
+ this.orderStatePublicKey = yield (0, addresses_1.getOrderStateAccountPublicKey)(this.program.programId);
173
172
  return this.orderStatePublicKey;
174
173
  });
175
174
  }
@@ -183,11 +182,11 @@ class ClearingHouse {
183
182
  updateWallet(newWallet) {
184
183
  const newProvider = new anchor_1.Provider(this.connection, newWallet, this.opts);
185
184
  const newProgram = new anchor_1.Program(clearing_house_json_1.default, this.program.programId, newProvider);
186
- const newTxSender = new defaultTxSender_1.DefaultTxSender(newProvider);
185
+ // Update provider for txSender with new wallet details
186
+ this.txSender.provider = newProvider;
187
187
  this.wallet = newWallet;
188
188
  this.provider = newProvider;
189
189
  this.program = newProgram;
190
- this.txSender = newTxSender;
191
190
  this.userAccountPublicKey = undefined;
192
191
  this.userAccount = undefined;
193
192
  }
@@ -203,7 +202,7 @@ class ClearingHouse {
203
202
  }
204
203
  getInitializeUserInstructions() {
205
204
  return __awaiter(this, void 0, void 0, function* () {
206
- const [userAccountPublicKey, userAccountNonce] = yield addresses_1.getUserAccountPublicKeyAndNonce(this.program.programId, this.wallet.publicKey);
205
+ const [userAccountPublicKey, userAccountNonce] = yield (0, addresses_1.getUserAccountPublicKeyAndNonce)(this.program.programId, this.wallet.publicKey);
207
206
  const remainingAccounts = [];
208
207
  const optionalAccounts = {
209
208
  whitelistToken: false,
@@ -244,7 +243,7 @@ class ClearingHouse {
244
243
  if (!userAccountPublicKey) {
245
244
  userAccountPublicKey = yield this.getUserAccountPublicKey();
246
245
  }
247
- const [userOrdersAccountPublicKey, userOrdersAccountNonce] = yield addresses_1.getUserOrdersAccountPublicKeyAndNonce(this.program.programId, userAccountPublicKey);
246
+ const [userOrdersAccountPublicKey, userOrdersAccountNonce] = yield (0, addresses_1.getUserOrdersAccountPublicKeyAndNonce)(this.program.programId, userAccountPublicKey);
248
247
  return yield this.program.instruction.initializeUserOrders(userOrdersAccountNonce, {
249
248
  accounts: {
250
249
  user: userAccountPublicKey,
@@ -266,7 +265,7 @@ class ClearingHouse {
266
265
  if (this.userAccountPublicKey) {
267
266
  return this.userAccountPublicKey;
268
267
  }
269
- this.userAccountPublicKey = yield addresses_1.getUserAccountPublicKey(this.program.programId, this.wallet.publicKey);
268
+ this.userAccountPublicKey = yield (0, addresses_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey);
270
269
  return this.userAccountPublicKey;
271
270
  });
272
271
  }
@@ -288,7 +287,7 @@ class ClearingHouse {
288
287
  if (this.userOrdersAccountPublicKey) {
289
288
  return this.userOrdersAccountPublicKey;
290
289
  }
291
- this.userOrdersAccountPublicKey = yield addresses_1.getUserOrdersAccountPublicKey(this.program.programId, yield this.getUserAccountPublicKey());
290
+ this.userOrdersAccountPublicKey = yield (0, addresses_1.getUserOrdersAccountPublicKey)(this.program.programId, yield this.getUserAccountPublicKey());
292
291
  return this.userOrdersAccountPublicKey;
293
292
  });
294
293
  }
@@ -381,7 +380,7 @@ class ClearingHouse {
381
380
  }
382
381
  withdrawCollateral(amount, collateralAccountPublicKey) {
383
382
  return __awaiter(this, void 0, void 0, function* () {
384
- return this.txSender.send(utils_1.wrapInTx(yield this.getWithdrawCollateralIx(amount, collateralAccountPublicKey)), [], this.opts);
383
+ return this.txSender.send((0, utils_1.wrapInTx)(yield this.getWithdrawCollateralIx(amount, collateralAccountPublicKey)), [], this.opts);
385
384
  });
386
385
  }
387
386
  getWithdrawCollateralIx(amount, collateralAccountPublicKey) {
@@ -410,7 +409,7 @@ class ClearingHouse {
410
409
  }
411
410
  openPosition(direction, amount, marketIndex, limitPrice, discountToken, referrer) {
412
411
  return __awaiter(this, void 0, void 0, function* () {
413
- return yield this.txSender.send(utils_1.wrapInTx(yield this.getOpenPositionIx(direction, amount, marketIndex, limitPrice, discountToken, referrer)), [], this.opts);
412
+ return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getOpenPositionIx(direction, amount, marketIndex, limitPrice, discountToken, referrer)), [], this.opts);
414
413
  });
415
414
  }
416
415
  getOpenPositionIx(direction, amount, marketIndex, limitPrice, discountToken, referrer) {
@@ -476,7 +475,7 @@ class ClearingHouse {
476
475
  }
477
476
  placeOrder(orderParams, discountToken, referrer) {
478
477
  return __awaiter(this, void 0, void 0, function* () {
479
- return yield this.txSender.send(utils_1.wrapInTx(yield this.getPlaceOrderIx(orderParams, discountToken, referrer)), [], this.opts);
478
+ return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getPlaceOrderIx(orderParams, discountToken, referrer)), [], this.opts);
480
479
  });
481
480
  }
482
481
  getPlaceOrderIx(orderParams, discountToken, referrer) {
@@ -528,7 +527,7 @@ class ClearingHouse {
528
527
  }
529
528
  cancelOrder(orderId) {
530
529
  return __awaiter(this, void 0, void 0, function* () {
531
- return yield this.txSender.send(utils_1.wrapInTx(yield this.getCancelOrderIx(orderId)), [], this.opts);
530
+ return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getCancelOrderIx(orderId)), [], this.opts);
532
531
  });
533
532
  }
534
533
  getCancelOrderIx(orderId) {
@@ -555,7 +554,7 @@ class ClearingHouse {
555
554
  }
556
555
  cancelOrderByUserId(userOrderId) {
557
556
  return __awaiter(this, void 0, void 0, function* () {
558
- return yield this.txSender.send(utils_1.wrapInTx(yield this.getCancelOrderByUserIdIx(userOrderId)), [], this.opts);
557
+ return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getCancelOrderByUserIdIx(userOrderId)), [], this.opts);
559
558
  });
560
559
  }
561
560
  getCancelOrderByUserIdIx(userOrderId) {
@@ -582,7 +581,7 @@ class ClearingHouse {
582
581
  }
583
582
  fillOrder(userAccountPublicKey, userOrdersAccountPublicKey, order) {
584
583
  return __awaiter(this, void 0, void 0, function* () {
585
- return yield this.txSender.send(utils_1.wrapInTx(yield this.getFillOrderIx(userAccountPublicKey, userOrdersAccountPublicKey, order)), [], this.opts);
584
+ return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getFillOrderIx(userAccountPublicKey, userOrdersAccountPublicKey, order)), [], this.opts);
586
585
  });
587
586
  }
588
587
  getFillOrderIx(userAccountPublicKey, userOrdersAccountPublicKey, order) {
@@ -640,7 +639,7 @@ class ClearingHouse {
640
639
  }
641
640
  placeAndFillOrder(orderParams, discountToken, referrer) {
642
641
  return __awaiter(this, void 0, void 0, function* () {
643
- return yield this.txSender.send(utils_1.wrapInTx(yield this.getPlaceAndFillOrderIx(orderParams, discountToken, referrer)), [], this.opts);
642
+ return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getPlaceAndFillOrderIx(orderParams, discountToken, referrer)), [], this.opts);
644
643
  });
645
644
  }
646
645
  getPlaceAndFillOrderIx(orderParams, discountToken, referrer) {
@@ -701,7 +700,7 @@ class ClearingHouse {
701
700
  */
702
701
  closePosition(marketIndex, discountToken, referrer) {
703
702
  return __awaiter(this, void 0, void 0, function* () {
704
- return yield this.txSender.send(utils_1.wrapInTx(yield this.getClosePositionIx(marketIndex, discountToken, referrer)), [], this.opts);
703
+ return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getClosePositionIx(marketIndex, discountToken, referrer)), [], this.opts);
705
704
  });
706
705
  }
707
706
  getClosePositionIx(marketIndex, discountToken, referrer) {
@@ -749,7 +748,7 @@ class ClearingHouse {
749
748
  }
750
749
  liquidate(liquidateeUserAccountPublicKey) {
751
750
  return __awaiter(this, void 0, void 0, function* () {
752
- return this.txSender.send(utils_1.wrapInTx(yield this.getLiquidateIx(liquidateeUserAccountPublicKey)), [], this.opts);
751
+ return this.txSender.send((0, utils_1.wrapInTx)(yield this.getLiquidateIx(liquidateeUserAccountPublicKey)), [], this.opts);
753
752
  });
754
753
  }
755
754
  getLiquidateIx(liquidateeUserAccountPublicKey) {
@@ -793,7 +792,7 @@ class ClearingHouse {
793
792
  }
794
793
  updateFundingRate(oracle, marketIndex) {
795
794
  return __awaiter(this, void 0, void 0, function* () {
796
- return this.txSender.send(utils_1.wrapInTx(yield this.getUpdateFundingRateIx(oracle, marketIndex)), [], this.opts);
795
+ return this.txSender.send((0, utils_1.wrapInTx)(yield this.getUpdateFundingRateIx(oracle, marketIndex)), [], this.opts);
797
796
  });
798
797
  }
799
798
  getUpdateFundingRateIx(oracle, marketIndex) {
@@ -811,7 +810,7 @@ class ClearingHouse {
811
810
  }
812
811
  settleFundingPayment(userAccount, userPositionsAccount) {
813
812
  return __awaiter(this, void 0, void 0, function* () {
814
- return this.txSender.send(utils_1.wrapInTx(yield this.getSettleFundingPaymentIx(userAccount, userPositionsAccount)), [], this.opts);
813
+ return this.txSender.send((0, utils_1.wrapInTx)(yield this.getSettleFundingPaymentIx(userAccount, userPositionsAccount)), [], this.opts);
815
814
  });
816
815
  }
817
816
  getSettleFundingPaymentIx(userAccount, userPositionsAccount) {
@@ -38,8 +38,8 @@ class ClearingHouseUser {
38
38
  static from(clearingHouse, authority) {
39
39
  if (clearingHouse.accountSubscriber.type !== 'websocket')
40
40
  throw 'This method only works for clearing houses with a websocket account listener. Try using the getClearingHouseUser factory method to initialize a ClearingHouseUser instead';
41
- const config = clearingHouseUser_1.getWebSocketClearingHouseUserConfig(clearingHouse, authority);
42
- return clearingHouseUser_1.getClearingHouseUser(config);
41
+ const config = (0, clearingHouseUser_1.getWebSocketClearingHouseUserConfig)(clearingHouse, authority);
42
+ return (0, clearingHouseUser_1.getClearingHouseUser)(config);
43
43
  }
44
44
  /**
45
45
  * Subscribe to ClearingHouseUser state accounts
@@ -112,7 +112,7 @@ class ClearingHouseUser {
112
112
  if (this.userAccountPublicKey) {
113
113
  return this.userAccountPublicKey;
114
114
  }
115
- this.userAccountPublicKey = yield addresses_1.getUserAccountPublicKey(this.clearingHouse.program.programId, this.authority);
115
+ this.userAccountPublicKey = yield (0, addresses_1.getUserAccountPublicKey)(this.clearingHouse.program.programId, this.authority);
116
116
  return this.userAccountPublicKey;
117
117
  });
118
118
  }
@@ -121,7 +121,7 @@ class ClearingHouseUser {
121
121
  if (this.userOrdersAccountPublicKey) {
122
122
  return this.userOrdersAccountPublicKey;
123
123
  }
124
- this.userOrdersAccountPublicKey = yield _1.getUserOrdersAccountPublicKey(this.clearingHouse.program.programId, yield this.getUserAccountPublicKey());
124
+ this.userOrdersAccountPublicKey = yield (0, _1.getUserOrdersAccountPublicKey)(this.clearingHouse.program.programId, yield this.getUserAccountPublicKey());
125
125
  return this.userOrdersAccountPublicKey;
126
126
  });
127
127
  }
@@ -159,7 +159,7 @@ class ClearingHouseUser {
159
159
  .positions.filter((pos) => marketIndex ? pos.marketIndex === marketIndex : true)
160
160
  .reduce((pnl, marketPosition) => {
161
161
  const market = this.clearingHouse.getMarket(marketPosition.marketIndex);
162
- return pnl.add(_1.calculatePositionPNL(market, marketPosition, withFunding));
162
+ return pnl.add((0, _1.calculatePositionPNL)(market, marketPosition, withFunding));
163
163
  }, numericConstants_1.ZERO);
164
164
  }
165
165
  /**
@@ -171,7 +171,7 @@ class ClearingHouseUser {
171
171
  .positions.filter((pos) => marketIndex ? pos.marketIndex === marketIndex : true)
172
172
  .reduce((pnl, marketPosition) => {
173
173
  const market = this.clearingHouse.getMarket(marketPosition.marketIndex);
174
- return pnl.add(_1.calculatePositionFundingPNL(market, marketPosition));
174
+ return pnl.add((0, _1.calculatePositionFundingPNL)(market, marketPosition));
175
175
  }, numericConstants_1.ZERO);
176
176
  }
177
177
  /**
@@ -189,7 +189,7 @@ class ClearingHouseUser {
189
189
  getTotalPositionValue() {
190
190
  return this.getUserPositionsAccount().positions.reduce((positionValue, marketPosition) => {
191
191
  const market = this.clearingHouse.getMarket(marketPosition.marketIndex);
192
- return positionValue.add(_1.calculateBaseAssetValue(market, marketPosition));
192
+ return positionValue.add((0, _1.calculateBaseAssetValue)(market, marketPosition));
193
193
  }, numericConstants_1.ZERO);
194
194
  }
195
195
  /**
@@ -199,7 +199,7 @@ class ClearingHouseUser {
199
199
  getPositionValue(marketIndex) {
200
200
  const userPosition = this.getUserPosition(marketIndex) || this.getEmptyPosition(marketIndex);
201
201
  const market = this.clearingHouse.getMarket(userPosition.marketIndex);
202
- return _1.calculateBaseAssetValue(market, userPosition);
202
+ return (0, _1.calculateBaseAssetValue)(market, userPosition);
203
203
  }
204
204
  getPositionSide(currentPosition) {
205
205
  if (currentPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
@@ -218,10 +218,10 @@ class ClearingHouseUser {
218
218
  */
219
219
  getPositionEstimatedExitPriceAndPnl(position, amountToClose) {
220
220
  const market = this.clearingHouse.getMarket(position.marketIndex);
221
- const entryPrice = position_1.calculateEntryPrice(position);
221
+ const entryPrice = (0, position_1.calculateEntryPrice)(position);
222
222
  if (amountToClose) {
223
223
  if (amountToClose.eq(numericConstants_1.ZERO)) {
224
- return [_1.calculateMarkPrice(market), numericConstants_1.ZERO];
224
+ return [(0, _1.calculateMarkPrice)(market), numericConstants_1.ZERO];
225
225
  }
226
226
  position = {
227
227
  baseAssetAmount: amountToClose,
@@ -230,7 +230,7 @@ class ClearingHouseUser {
230
230
  quoteAssetAmount: position.quoteAssetAmount,
231
231
  };
232
232
  }
233
- const baseAssetValue = _1.calculateBaseAssetValue(market, position);
233
+ const baseAssetValue = (0, _1.calculateBaseAssetValue)(market, position);
234
234
  if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
235
235
  return [numericConstants_1.ZERO, numericConstants_1.ZERO];
236
236
  }
@@ -337,7 +337,7 @@ class ClearingHouseUser {
337
337
 
338
338
  for 10x long, BTC down $400:
339
339
  3. (10k - 4k) / (100k - 4k) = 6k/96k => .0625 */
340
- const currentPrice = _1.calculateMarkPrice(this.clearingHouse.getMarket(targetMarket.marketIndex));
340
+ const currentPrice = (0, _1.calculateMarkPrice)(this.clearingHouse.getMarket(targetMarket.marketIndex));
341
341
  const totalCollateralUSDC = this.getTotalCollateral();
342
342
  // calculate the total position value ignoring any value from the target market of the trade
343
343
  const totalCurrentPositionValueIgnoringTargetUSDC = this.getTotalPositionValueExcludingMarket(targetMarket.marketIndex);
@@ -353,7 +353,7 @@ class ClearingHouseUser {
353
353
  openOrders: new _1.BN(0),
354
354
  };
355
355
  const market = this.clearingHouse.getMarket(proposedMarketPosition.marketIndex);
356
- const proposedMarketPositionValueUSDC = _1.calculateBaseAssetValue(market, proposedMarketPosition);
356
+ const proposedMarketPositionValueUSDC = (0, _1.calculateBaseAssetValue)(market, proposedMarketPosition);
357
357
  // total position value after trade
358
358
  const targetTotalPositionValueUSDC = totalCurrentPositionValueIgnoringTargetUSDC.add(proposedMarketPositionValueUSDC);
359
359
  let totalFreeCollateralUSDC = this.getTotalCollateral().sub(this.getTotalPositionValue()
@@ -439,7 +439,7 @@ class ClearingHouseUser {
439
439
  openOrders: new _1.BN(0),
440
440
  };
441
441
  const market = this.clearingHouse.getMarket(proposedMarketPosition.marketIndex);
442
- const proposedMarketPositionValueUSDC = _1.calculateBaseAssetValue(market, proposedMarketPosition);
442
+ const proposedMarketPositionValueUSDC = (0, _1.calculateBaseAssetValue)(market, proposedMarketPosition);
443
443
  // total position value after trade
444
444
  const targetTotalPositionValueUSDC = totalCurrentPositionValueIgnoringTargetUSDC.add(proposedMarketPositionValueUSDC);
445
445
  let totalFreeCollateralUSDC = tc.sub(totalCurrentPositionValueIgnoringTargetUSDC
@@ -467,13 +467,13 @@ class ClearingHouseUser {
467
467
  }
468
468
  let currentPrice;
469
469
  if (positionBaseSizeChange.eq(numericConstants_1.ZERO)) {
470
- currentPrice = _1.calculateMarkPrice(this.clearingHouse.getMarket(targetMarket.marketIndex));
470
+ currentPrice = (0, _1.calculateMarkPrice)(this.clearingHouse.getMarket(targetMarket.marketIndex));
471
471
  }
472
472
  else {
473
473
  const direction = positionBaseSizeChange.gt(numericConstants_1.ZERO)
474
474
  ? _1.PositionDirection.LONG
475
475
  : _1.PositionDirection.SHORT;
476
- currentPrice = _1.calculateTradeSlippage(direction, positionBaseSizeChange.abs(), this.clearingHouse.getMarket(targetMarket.marketIndex), 'base')[3]; // newPrice after swap
476
+ currentPrice = (0, _1.calculateTradeSlippage)(direction, positionBaseSizeChange.abs(), this.clearingHouse.getMarket(targetMarket.marketIndex), 'base')[3]; // newPrice after swap
477
477
  }
478
478
  // if the position value after the trade is less than total collateral, there is no liq price
479
479
  if (targetTotalPositionValueUSDC.lte(totalFreeCollateralUSDC) &&
@@ -664,10 +664,10 @@ class ClearingHouseUser {
664
664
  const userPositionsAccount = this.getUserPositionsAccount();
665
665
  const userPosition = this.getUserPosition(order.marketIndex);
666
666
  const market = this.clearingHouse.getMarket(order.marketIndex);
667
- if (position_1.isEmptyPosition(userPosition)) {
667
+ if ((0, position_1.isEmptyPosition)(userPosition)) {
668
668
  return false;
669
669
  }
670
- const newState = _1.calculateNewStateAfterOrder(userAccount, userPosition, market, order);
670
+ const newState = (0, _1.calculateNewStateAfterOrder)(userAccount, userPosition, market, order);
671
671
  if (newState === null) {
672
672
  return false;
673
673
  }
@@ -678,20 +678,20 @@ class ClearingHouseUser {
678
678
  market = marketAfter;
679
679
  marketPosition = userPositionAfter;
680
680
  }
681
- return positionValue.add(_1.calculateBaseAssetValue(market, marketPosition));
681
+ return positionValue.add((0, _1.calculateBaseAssetValue)(market, marketPosition));
682
682
  }, numericConstants_1.ZERO);
683
683
  if (totalPositionValue.eq(numericConstants_1.ZERO)) {
684
684
  return true;
685
685
  }
686
686
  const unrealizedPnL = userPositionsAccount.positions.reduce((pnl, marketPosition) => {
687
687
  let market = this.clearingHouse.getMarket(marketPosition.marketIndex);
688
- pnl = pnl.add(_1.calculatePositionFundingPNL(market, marketPosition).div(numericConstants_1.PRICE_TO_QUOTE_PRECISION));
688
+ pnl = pnl.add((0, _1.calculatePositionFundingPNL)(market, marketPosition).div(numericConstants_1.PRICE_TO_QUOTE_PRECISION));
689
689
  if (marketPosition.marketIndex.eq(order.marketIndex)) {
690
690
  market = marketAfter;
691
691
  marketPosition = userPositionAfter;
692
692
  }
693
693
  // update
694
- return pnl.add(_1.calculatePositionPNL(market, marketPosition, false));
694
+ return pnl.add((0, _1.calculatePositionPNL)(market, marketPosition, false));
695
695
  }, numericConstants_1.ZERO);
696
696
  const totalCollateral = userAccountAfter.collateral.add(unrealizedPnL);
697
697
  const marginRatioAfter = totalCollateral
@@ -21,7 +21,7 @@ const getTokenAddress = (mintAddress, userPubKey) => {
21
21
  exports.getTokenAddress = getTokenAddress;
22
22
  const main = () => __awaiter(void 0, void 0, void 0, function* () {
23
23
  // Initialize Drift SDK
24
- const sdkConfig = __2.initialize({ env: 'devnet' });
24
+ const sdkConfig = (0, __2.initialize)({ env: 'devnet' });
25
25
  // Set up the Wallet and Provider
26
26
  const privateKey = process.env.BOT_PRIVATE_KEY; // stored as an array string
27
27
  const keypair = web3_js_1.Keypair.fromSecretKey(Uint8Array.from(JSON.parse(privateKey)));
@@ -35,7 +35,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
35
35
  const lamportsBalance = yield connection.getBalance(wallet.publicKey);
36
36
  console.log('SOL balance:', lamportsBalance / Math.pow(10, 9));
37
37
  // Misc. other things to set up
38
- const usdcTokenAddress = yield exports.getTokenAddress(sdkConfig.USDC_MINT_ADDRESS, wallet.publicKey.toString());
38
+ const usdcTokenAddress = yield (0, exports.getTokenAddress)(sdkConfig.USDC_MINT_ADDRESS, wallet.publicKey.toString());
39
39
  // Set up the Drift Clearing House
40
40
  const clearingHousePublicKey = new web3_js_1.PublicKey(sdkConfig.CLEARING_HOUSE_PROGRAM_ID);
41
41
  const clearingHouse = __2.ClearingHouse.from(connection, provider.wallet, clearingHousePublicKey);
@@ -47,18 +47,18 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
47
47
  if (!userAccountExists) {
48
48
  //// Create a Clearing House account by Depositing some USDC ($10,000 in this case)
49
49
  const depositAmount = new anchor_1.BN(10000).mul(__2.QUOTE_PRECISION);
50
- yield clearingHouse.initializeUserAccountAndDepositCollateral(depositAmount, yield exports.getTokenAddress(usdcTokenAddress.toString(), wallet.publicKey.toString()));
50
+ yield clearingHouse.initializeUserAccountAndDepositCollateral(depositAmount, yield (0, exports.getTokenAddress)(usdcTokenAddress.toString(), wallet.publicKey.toString()));
51
51
  }
52
52
  yield user.subscribe();
53
53
  // Get current price
54
54
  const solMarketInfo = __2.Markets.find((market) => market.baseAssetSymbol === 'SOL');
55
- const currentMarketPrice = __2.calculateMarkPrice(clearingHouse.getMarket(solMarketInfo.marketIndex));
56
- const formattedPrice = __2.convertToNumber(currentMarketPrice, __2.MARK_PRICE_PRECISION);
55
+ const currentMarketPrice = (0, __2.calculateMarkPrice)(clearingHouse.getMarket(solMarketInfo.marketIndex));
56
+ const formattedPrice = (0, __2.convertToNumber)(currentMarketPrice, __2.MARK_PRICE_PRECISION);
57
57
  console.log(`Current Market Price is $${formattedPrice}`);
58
58
  // Estimate the slippage for a $5000 LONG trade
59
59
  const solMarketAccount = clearingHouse.getMarket(solMarketInfo.marketIndex);
60
60
  const longAmount = new anchor_1.BN(5000).mul(__2.QUOTE_PRECISION);
61
- const slippage = __2.convertToNumber(__2.calculateTradeSlippage(__2.PositionDirection.LONG, longAmount, solMarketAccount)[0], __2.MARK_PRICE_PRECISION);
61
+ const slippage = (0, __2.convertToNumber)((0, __2.calculateTradeSlippage)(__2.PositionDirection.LONG, longAmount, solMarketAccount)[0], __2.MARK_PRICE_PRECISION);
62
62
  console.log(`Slippage for a $5000 LONG on the SOL market would be $${slippage}`);
63
63
  // Make a $5000 LONG trade
64
64
  yield clearingHouse.openPosition(__2.PositionDirection.LONG, longAmount, solMarketInfo.marketIndex);