@drift-labs/sdk 2.28.0-beta.1 → 2.28.0-beta.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.
@@ -203,6 +203,11 @@ export declare class DriftClient {
203
203
  getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
204
204
  cancelOrders(marketType?: MarketType, marketIndex?: number, direction?: PositionDirection, txParams?: TxParams): Promise<TransactionSignature>;
205
205
  getCancelOrdersIx(marketType: MarketType | null, marketIndex: number | null, direction: PositionDirection | null): Promise<TransactionInstruction>;
206
+ cancelAndPlaceOrders(cancelOrderParams: {
207
+ marketType?: MarketType;
208
+ marketIndex?: number;
209
+ direction?: PositionDirection;
210
+ }, placeOrderParams: OrderParams[], txParams?: TxParams): Promise<TransactionSignature>;
206
211
  fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<TransactionSignature>;
207
212
  getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
208
213
  getRevertFillIx(): Promise<TransactionInstruction>;
@@ -1525,6 +1525,25 @@ class DriftClient {
1525
1525
  remainingAccounts,
1526
1526
  });
1527
1527
  }
1528
+ async cancelAndPlaceOrders(cancelOrderParams, placeOrderParams, txParams) {
1529
+ const tx = (0, utils_1.wrapInTx)(await this.getCancelOrdersIx(cancelOrderParams.marketType, cancelOrderParams.marketIndex, cancelOrderParams.direction), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice);
1530
+ for (const placeOrderParam of placeOrderParams) {
1531
+ const marketType = placeOrderParam.marketType;
1532
+ if (!marketType) {
1533
+ throw new Error('marketType must be set on placeOrderParams');
1534
+ }
1535
+ let ix;
1536
+ if ((0, types_1.isVariant)(marketType, 'perp')) {
1537
+ ix = this.getPlacePerpOrderIx(placeOrderParam);
1538
+ }
1539
+ else {
1540
+ ix = this.getPlaceSpotOrderIx(placeOrderParam);
1541
+ }
1542
+ tx.add(ix);
1543
+ }
1544
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1545
+ return txSig;
1546
+ }
1528
1547
  async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo, txParams) {
1529
1548
  const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
1530
1549
  return txSig;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.28.0-beta.1",
2
+ "version": "2.28.0-beta.2",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -29,8 +29,8 @@ export declare class PhoenixSubscriber implements L2OrderBookGenerator {
29
29
  lastUnixTimestamp: number;
30
30
  constructor(config: PhoenixMarketSubscriberConfig);
31
31
  subscribe(): Promise<void>;
32
- getBestBid(): BN;
33
- getBestAsk(): BN;
32
+ getBestBid(): BN | undefined;
33
+ getBestAsk(): BN | undefined;
34
34
  getL2Bids(): Generator<L2Level>;
35
35
  getL2Asks(): Generator<L2Level>;
36
36
  getL2Levels(side: 'bids' | 'asks'): Generator<L2Level>;
@@ -54,11 +54,19 @@ class PhoenixSubscriber {
54
54
  }
55
55
  getBestBid() {
56
56
  const ladder = (0, phoenix_sdk_1.getMarketUiLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 1);
57
- return new anchor_1.BN(Math.floor(ladder.bids[0][0] * numericConstants_1.PRICE_PRECISION.toNumber()));
57
+ const bestBid = ladder.bids[0];
58
+ if (!bestBid) {
59
+ return undefined;
60
+ }
61
+ return new anchor_1.BN(Math.floor(bestBid[0] * numericConstants_1.PRICE_PRECISION.toNumber()));
58
62
  }
59
63
  getBestAsk() {
60
64
  const ladder = (0, phoenix_sdk_1.getMarketUiLadder)(this.market, this.lastSlot, this.lastUnixTimestamp, 1);
61
- return new anchor_1.BN(Math.floor(ladder.asks[0][0] * numericConstants_1.PRICE_PRECISION.toNumber()));
65
+ const bestAsk = ladder.asks[0];
66
+ if (!bestAsk) {
67
+ return undefined;
68
+ }
69
+ return new anchor_1.BN(Math.floor(bestAsk[0] * numericConstants_1.PRICE_PRECISION.toNumber()));
62
70
  }
63
71
  getL2Bids() {
64
72
  return this.getL2Levels('bids');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.28.0-beta.1",
3
+ "version": "2.28.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -2664,6 +2664,43 @@ export class DriftClient {
2664
2664
  );
2665
2665
  }
2666
2666
 
2667
+ public async cancelAndPlaceOrders(
2668
+ cancelOrderParams: {
2669
+ marketType?: MarketType;
2670
+ marketIndex?: number;
2671
+ direction?: PositionDirection;
2672
+ },
2673
+ placeOrderParams: OrderParams[],
2674
+ txParams?: TxParams
2675
+ ): Promise<TransactionSignature> {
2676
+ const tx = wrapInTx(
2677
+ await this.getCancelOrdersIx(
2678
+ cancelOrderParams.marketType,
2679
+ cancelOrderParams.marketIndex,
2680
+ cancelOrderParams.direction
2681
+ ),
2682
+ txParams?.computeUnits,
2683
+ txParams?.computeUnitsPrice
2684
+ );
2685
+
2686
+ for (const placeOrderParam of placeOrderParams) {
2687
+ const marketType = placeOrderParam.marketType;
2688
+ if (!marketType) {
2689
+ throw new Error('marketType must be set on placeOrderParams');
2690
+ }
2691
+ let ix;
2692
+ if (isVariant(marketType, 'perp')) {
2693
+ ix = this.getPlacePerpOrderIx(placeOrderParam);
2694
+ } else {
2695
+ ix = this.getPlaceSpotOrderIx(placeOrderParam);
2696
+ }
2697
+ tx.add(ix);
2698
+ }
2699
+
2700
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2701
+ return txSig;
2702
+ }
2703
+
2667
2704
  public async fillPerpOrder(
2668
2705
  userAccountPublicKey: PublicKey,
2669
2706
  user: UserAccount,
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.28.0-beta.1",
2
+ "version": "2.28.0-beta.2",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -108,24 +108,33 @@ export class PhoenixSubscriber implements L2OrderBookGenerator {
108
108
  this.subscribed = true;
109
109
  }
110
110
 
111
- public getBestBid(): BN {
111
+ public getBestBid(): BN | undefined {
112
112
  const ladder = getMarketUiLadder(
113
113
  this.market,
114
114
  this.lastSlot,
115
115
  this.lastUnixTimestamp,
116
116
  1
117
117
  );
118
- return new BN(Math.floor(ladder.bids[0][0] * PRICE_PRECISION.toNumber()));
118
+ const bestBid = ladder.bids[0];
119
+ if (!bestBid) {
120
+ return undefined;
121
+ }
122
+ return new BN(Math.floor(bestBid[0] * PRICE_PRECISION.toNumber()));
119
123
  }
120
124
 
121
- public getBestAsk(): BN {
125
+ public getBestAsk(): BN | undefined {
122
126
  const ladder = getMarketUiLadder(
123
127
  this.market,
124
128
  this.lastSlot,
125
129
  this.lastUnixTimestamp,
126
130
  1
127
131
  );
128
- return new BN(Math.floor(ladder.asks[0][0] * PRICE_PRECISION.toNumber()));
132
+
133
+ const bestAsk = ladder.asks[0];
134
+ if (!bestAsk) {
135
+ return undefined;
136
+ }
137
+ return new BN(Math.floor(bestAsk[0] * PRICE_PRECISION.toNumber()));
129
138
  }
130
139
 
131
140
  public getL2Bids(): Generator<L2Level> {