@drift-labs/sdk 2.45.0-beta.5 → 2.45.0-beta.6

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.
package/README.md CHANGED
@@ -57,7 +57,7 @@ The Drift SDK uses some common precisions, which are available as constants to i
57
57
 
58
58
  **Important Note for BigNum division**
59
59
 
60
- Because BN only supports integers, you need to be conscious of the numbers you are using when dividing. BN will return the floor when using the regular division function; if you want to get the exact divison, you need to add the modulus of the two numbers as well. There is a helper function `convertToNumber` in the SDK which will do this for you.
60
+ Because BN only supports integers, you need to be conscious of the numbers you are using when dividing. BN will return the floor when using the regular division function; if you want to get the exact division, you need to add the modulus of the two numbers as well. There is a helper function `convertToNumber` in the SDK which will do this for you.
61
61
 
62
62
  ```typescript
63
63
  import {convertToNumber} from @drift-labs/sdk
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.45.0-beta.5
1
+ 2.45.0-beta.6
@@ -36,6 +36,7 @@ export declare class AdminClient extends DriftClient {
36
36
  updateLiquidationMarginBufferRatio(updateLiquidationMarginBufferRatio: number): Promise<TransactionSignature>;
37
37
  updateOracleGuardRails(oracleGuardRails: OracleGuardRails): Promise<TransactionSignature>;
38
38
  updateStateSettlementDuration(settlementDuration: number): Promise<TransactionSignature>;
39
+ updateStateMaxNumberOfSubAccounts(maxNumberOfSubAccounts: number): Promise<TransactionSignature>;
39
40
  updateWithdrawGuardThreshold(spotMarketIndex: number, withdrawGuardThreshold: BN): Promise<TransactionSignature>;
40
41
  updateSpotMarketIfFactor(spotMarketIndex: number, userIfFactor: BN, totalIfFactor: BN): Promise<TransactionSignature>;
41
42
  updateSpotMarketRevenueSettlePeriod(spotMarketIndex: number, revenueSettlePeriod: BN): Promise<TransactionSignature>;
@@ -447,6 +447,14 @@ class AdminClient extends driftClient_1.DriftClient {
447
447
  },
448
448
  });
449
449
  }
450
+ async updateStateMaxNumberOfSubAccounts(maxNumberOfSubAccounts) {
451
+ return await this.program.rpc.updateStateMaxNumberOfSubAccounts(maxNumberOfSubAccounts, {
452
+ accounts: {
453
+ admin: this.wallet.publicKey,
454
+ state: await this.getStatePublicKey(),
455
+ },
456
+ });
457
+ }
450
458
  async updateWithdrawGuardThreshold(spotMarketIndex, withdrawGuardThreshold) {
451
459
  const tx = await this.program.transaction.updateWithdrawGuardThreshold(withdrawGuardThreshold, {
452
460
  accounts: {
@@ -4163,6 +4163,27 @@
4163
4163
  }
4164
4164
  ]
4165
4165
  },
4166
+ {
4167
+ "name": "updateStateMaxNumberOfSubAccounts",
4168
+ "accounts": [
4169
+ {
4170
+ "name": "admin",
4171
+ "isMut": false,
4172
+ "isSigner": true
4173
+ },
4174
+ {
4175
+ "name": "state",
4176
+ "isMut": true,
4177
+ "isSigner": false
4178
+ }
4179
+ ],
4180
+ "args": [
4181
+ {
4182
+ "name": "maxNumberOfSubAccounts",
4183
+ "type": "u16"
4184
+ }
4185
+ ]
4186
+ },
4166
4187
  {
4167
4188
  "name": "updatePerpMarketOracle",
4168
4189
  "accounts": [
@@ -5722,12 +5743,16 @@
5722
5743
  "name": "initialPctToLiquidate",
5723
5744
  "type": "u16"
5724
5745
  },
5746
+ {
5747
+ "name": "maxNumberOfSubAccounts",
5748
+ "type": "u16"
5749
+ },
5725
5750
  {
5726
5751
  "name": "padding",
5727
5752
  "type": {
5728
5753
  "array": [
5729
5754
  "u8",
5730
- 14
5755
+ 12
5731
5756
  ]
5732
5757
  }
5733
5758
  }
@@ -10898,7 +10923,7 @@
10898
10923
  {
10899
10924
  "code": 6221,
10900
10925
  "name": "SpotFulfillmentConfigDisabled",
10901
- "msg": "Spot Fulfullment Config Disabled"
10926
+ "msg": "Spot Fulfillment Config Disabled"
10902
10927
  },
10903
10928
  {
10904
10929
  "code": 6222,
@@ -204,7 +204,21 @@ function isTriggered(order) {
204
204
  }
205
205
  exports.isTriggered = isTriggered;
206
206
  function isRestingLimitOrder(order, slot) {
207
- return (isLimitOrder(order) && (order.postOnly || (0, auction_1.isAuctionComplete)(order, slot)));
207
+ if (!isLimitOrder(order)) {
208
+ return false;
209
+ }
210
+ if ((0, types_1.isVariant)(order.orderType, 'triggerLimit')) {
211
+ if ((0, types_1.isVariant)(order.direction, 'long') &&
212
+ order.triggerPrice.lt(order.price)) {
213
+ return false;
214
+ }
215
+ else if ((0, types_1.isVariant)(order.direction, 'short') &&
216
+ order.triggerPrice.gt(order.price)) {
217
+ return false;
218
+ }
219
+ return (0, auction_1.isAuctionComplete)(order, slot);
220
+ }
221
+ return order.postOnly || (0, auction_1.isAuctionComplete)(order, slot);
208
222
  }
209
223
  exports.isRestingLimitOrder = isRestingLimitOrder;
210
224
  function isTakingOrder(order, slot) {
package/lib/types.d.ts CHANGED
@@ -620,6 +620,7 @@ export type StateAccount = {
620
620
  defaultSpotAuctionDuration: number;
621
621
  liquidationMarginBufferRatio: number;
622
622
  settlementDuration: number;
623
+ maxNumberOfSubAccounts: number;
623
624
  signer: PublicKey;
624
625
  signerNonce: number;
625
626
  srmVault: PublicKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.45.0-beta.5",
3
+ "version": "2.45.0-beta.6",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -832,6 +832,20 @@ export class AdminClient extends DriftClient {
832
832
  );
833
833
  }
834
834
 
835
+ public async updateStateMaxNumberOfSubAccounts(
836
+ maxNumberOfSubAccounts: number
837
+ ): Promise<TransactionSignature> {
838
+ return await this.program.rpc.updateStateMaxNumberOfSubAccounts(
839
+ maxNumberOfSubAccounts,
840
+ {
841
+ accounts: {
842
+ admin: this.wallet.publicKey,
843
+ state: await this.getStatePublicKey(),
844
+ },
845
+ }
846
+ );
847
+ }
848
+
835
849
  public async updateWithdrawGuardThreshold(
836
850
  spotMarketIndex: number,
837
851
  withdrawGuardThreshold: BN
@@ -4163,6 +4163,27 @@
4163
4163
  }
4164
4164
  ]
4165
4165
  },
4166
+ {
4167
+ "name": "updateStateMaxNumberOfSubAccounts",
4168
+ "accounts": [
4169
+ {
4170
+ "name": "admin",
4171
+ "isMut": false,
4172
+ "isSigner": true
4173
+ },
4174
+ {
4175
+ "name": "state",
4176
+ "isMut": true,
4177
+ "isSigner": false
4178
+ }
4179
+ ],
4180
+ "args": [
4181
+ {
4182
+ "name": "maxNumberOfSubAccounts",
4183
+ "type": "u16"
4184
+ }
4185
+ ]
4186
+ },
4166
4187
  {
4167
4188
  "name": "updatePerpMarketOracle",
4168
4189
  "accounts": [
@@ -5722,12 +5743,16 @@
5722
5743
  "name": "initialPctToLiquidate",
5723
5744
  "type": "u16"
5724
5745
  },
5746
+ {
5747
+ "name": "maxNumberOfSubAccounts",
5748
+ "type": "u16"
5749
+ },
5725
5750
  {
5726
5751
  "name": "padding",
5727
5752
  "type": {
5728
5753
  "array": [
5729
5754
  "u8",
5730
- 14
5755
+ 12
5731
5756
  ]
5732
5757
  }
5733
5758
  }
@@ -10898,7 +10923,7 @@
10898
10923
  {
10899
10924
  "code": 6221,
10900
10925
  "name": "SpotFulfillmentConfigDisabled",
10901
- "msg": "Spot Fulfullment Config Disabled"
10926
+ "msg": "Spot Fulfillment Config Disabled"
10902
10927
  },
10903
10928
  {
10904
10929
  "code": 6222,
@@ -11071,4 +11096,4 @@
11071
11096
  "msg": "InvalidMarginCalculation"
11072
11097
  }
11073
11098
  ]
11074
- }
11099
+ }
@@ -322,9 +322,27 @@ export function isTriggered(order: Order): boolean {
322
322
  }
323
323
 
324
324
  export function isRestingLimitOrder(order: Order, slot: number): boolean {
325
- return (
326
- isLimitOrder(order) && (order.postOnly || isAuctionComplete(order, slot))
327
- );
325
+ if (!isLimitOrder(order)) {
326
+ return false;
327
+ }
328
+
329
+ if (isVariant(order.orderType, 'triggerLimit')) {
330
+ if (
331
+ isVariant(order.direction, 'long') &&
332
+ order.triggerPrice.lt(order.price)
333
+ ) {
334
+ return false;
335
+ } else if (
336
+ isVariant(order.direction, 'short') &&
337
+ order.triggerPrice.gt(order.price)
338
+ ) {
339
+ return false;
340
+ }
341
+
342
+ return isAuctionComplete(order, slot);
343
+ }
344
+
345
+ return order.postOnly || isAuctionComplete(order, slot);
328
346
  }
329
347
 
330
348
  export function isTakingOrder(order: Order, slot: number): boolean {
package/src/types.ts CHANGED
@@ -543,6 +543,7 @@ export type StateAccount = {
543
543
  defaultSpotAuctionDuration: number;
544
544
  liquidationMarginBufferRatio: number;
545
545
  settlementDuration: number;
546
+ maxNumberOfSubAccounts: number;
546
547
  signer: PublicKey;
547
548
  signerNonce: number;
548
549
  srmVault: PublicKey;
@@ -584,6 +584,7 @@ export const mockStateAccount: StateAccount = {
584
584
  },
585
585
  srmVault: PublicKey.default,
586
586
  whitelistMint: PublicKey.default,
587
+ maxNumberOfSubAccounts: 0,
587
588
  };
588
589
 
589
590
  export class MockUserMap implements UserMapInterface {
@@ -27,6 +27,7 @@ import {
27
27
 
28
28
  import { mockPerpMarkets, mockSpotMarkets, mockStateAccount } from './helpers';
29
29
  import { DLOBOrdersCoder } from '../../src/dlob/DLOBOrders';
30
+ import {isAuctionComplete, isRestingLimitOrder} from "../../lib";
30
31
 
31
32
  function insertOrderToDLOB(
32
33
  dlob: DLOB,
@@ -2504,6 +2505,52 @@ describe('DLOB Perp Tests', () => {
2504
2505
  }
2505
2506
  });
2506
2507
 
2508
+ it('Test trigger limit isnt maker', () => {
2509
+ const vAsk = new BN(15);
2510
+ const vBid = new BN(8);
2511
+
2512
+ const user0 = Keypair.generate();
2513
+
2514
+ const dlob = new DLOB();
2515
+ const marketIndex = 0;
2516
+
2517
+ const slot = 20;
2518
+ const oracle = {
2519
+ price: vBid.add(vAsk).div(new BN(2)),
2520
+ slot: new BN(slot),
2521
+ confidence: new BN(1),
2522
+ hasSufficientNumberOfDataPoints: true,
2523
+ };
2524
+
2525
+ // should trigger limit buy with above condition
2526
+ insertTriggerOrderToDLOB(
2527
+ dlob,
2528
+ user0.publicKey,
2529
+ OrderType.TRIGGER_LIMIT,
2530
+ MarketType.PERP,
2531
+ 1, //orderId
2532
+ marketIndex, // marketIndex
2533
+ oracle.price.add(new BN(1)), // price
2534
+ BASE_PRECISION, // baseAssetAmount: BN,
2535
+ PositionDirection.LONG,
2536
+ oracle.price.sub(new BN(1)), // triggerPrice: BN,
2537
+ OrderTriggerCondition.TRIGGERED_ABOVE, // triggerCondition: OrderTriggerCondition,
2538
+ vBid,
2539
+ vAsk,
2540
+ new BN(1), // slot
2541
+ );
2542
+
2543
+ const restingLimitBids = Array.from(dlob.getRestingLimitBids(marketIndex, slot, MarketType.PERP, oracle));
2544
+ expect(restingLimitBids.length).to.equal(0);
2545
+
2546
+ const takingBids = Array.from(dlob.getTakingBids(marketIndex, MarketType.PERP, slot, oracle));
2547
+ expect(takingBids.length).to.equal(1);
2548
+ const triggerLimitBid = takingBids[0];
2549
+ expect(isAuctionComplete(triggerLimitBid.order, slot)).to.equal(true);
2550
+ expect(isRestingLimitOrder(triggerLimitBid.order, slot)).to.equal(false);
2551
+
2552
+ });
2553
+
2507
2554
  it('Test will return expired market orders to fill', () => {
2508
2555
  const vAsk = new BN(15);
2509
2556
  const vBid = new BN(8);