@drift-labs/sdk 2.61.0-beta.1 → 2.61.0-beta.3

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.61.0-beta.1
1
+ 2.61.0-beta.3
@@ -7,15 +7,29 @@ function exchangePaused(state) {
7
7
  }
8
8
  exports.exchangePaused = exchangePaused;
9
9
  function fillPaused(state, market) {
10
- return ((state.exchangeStatus & types_1.ExchangeStatus.FILL_PAUSED) ===
11
- types_1.ExchangeStatus.FILL_PAUSED ||
12
- (0, types_1.isOneOfVariant)(market.status, ['paused', 'fillPaused']));
10
+ if ((state.exchangeStatus & types_1.ExchangeStatus.FILL_PAUSED) ===
11
+ types_1.ExchangeStatus.FILL_PAUSED) {
12
+ return true;
13
+ }
14
+ if (market.hasOwnProperty('amm')) {
15
+ return isOperationPaused(market.pausedOperations, types_1.PerpOperation.FILL);
16
+ }
17
+ else {
18
+ return isOperationPaused(market.pausedOperations, types_1.SpotOperation.FILL);
19
+ }
13
20
  }
14
21
  exports.fillPaused = fillPaused;
15
22
  function ammPaused(state, market) {
16
- return ((state.exchangeStatus & types_1.ExchangeStatus.AMM_PAUSED) ===
17
- types_1.ExchangeStatus.AMM_PAUSED ||
18
- (0, types_1.isOneOfVariant)(market.status, ['paused', 'ammPaused']));
23
+ if ((state.exchangeStatus & types_1.ExchangeStatus.AMM_PAUSED) ===
24
+ types_1.ExchangeStatus.AMM_PAUSED) {
25
+ return true;
26
+ }
27
+ if (market.hasOwnProperty('amm')) {
28
+ return isOperationPaused(market.pausedOperations, types_1.PerpOperation.AMM_FILL);
29
+ }
30
+ else {
31
+ return false;
32
+ }
19
33
  }
20
34
  exports.ammPaused = ammPaused;
21
35
  function isOperationPaused(pausedOperations, operation) {
@@ -207,17 +207,6 @@ function isRestingLimitOrder(order, slot) {
207
207
  if (!isLimitOrder(order)) {
208
208
  return false;
209
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
210
  return order.postOnly || (0, auction_1.isAuctionComplete)(order, slot);
222
211
  }
223
212
  exports.isRestingLimitOrder = isRestingLimitOrder;
@@ -17,6 +17,7 @@ class PythClient {
17
17
  getOraclePriceDataFromBuffer(buffer) {
18
18
  const priceData = (0, client_1.parsePriceData)(buffer);
19
19
  const confidence = convertPythPrice(priceData.confidence, priceData.exponent, this.multiple);
20
+ const minPublishers = Math.min(priceData.numComponentPrices, 3);
20
21
  let price = convertPythPrice(priceData.aggregate.price, priceData.exponent, this.multiple);
21
22
  if (this.stableCoin) {
22
23
  price = getStableCoinPrice(price, confidence);
@@ -27,7 +28,7 @@ class PythClient {
27
28
  confidence,
28
29
  twap: convertPythPrice(priceData.twap.value, priceData.exponent, this.multiple),
29
30
  twapConfidence: convertPythPrice(priceData.twac.value, priceData.exponent, this.multiple),
30
- hasSufficientNumberOfDataPoints: true,
31
+ hasSufficientNumberOfDataPoints: priceData.numQuoters >= minPublishers,
31
32
  };
32
33
  }
33
34
  }
package/lib/types.d.ts CHANGED
@@ -689,6 +689,7 @@ export type PerpMarketAccount = {
689
689
  };
690
690
  quoteSpotMarketIndex: number;
691
691
  feeAdjustment: number;
692
+ pausedOperations: number;
692
693
  };
693
694
  export type HistoricalOracleData = {
694
695
  lastOraclePrice: BN;
@@ -766,6 +767,7 @@ export type SpotMarketAccount = {
766
767
  flashLoanAmount: BN;
767
768
  flashLoanInitialTokenAmount: BN;
768
769
  ordersEnabled: boolean;
770
+ pausedOperations: number;
769
771
  };
770
772
  export type PoolBalance = {
771
773
  scaledBalance: BN;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.61.0-beta.1",
3
+ "version": "2.61.0-beta.3",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  ExchangeStatus,
3
- isOneOfVariant,
4
3
  PerpMarketAccount,
5
4
  PerpOperation,
6
5
  SpotMarketAccount,
@@ -16,22 +15,36 @@ export function fillPaused(
16
15
  state: StateAccount,
17
16
  market: PerpMarketAccount | SpotMarketAccount
18
17
  ): boolean {
19
- return (
18
+ if (
20
19
  (state.exchangeStatus & ExchangeStatus.FILL_PAUSED) ===
21
- ExchangeStatus.FILL_PAUSED ||
22
- isOneOfVariant(market.status, ['paused', 'fillPaused'])
23
- );
20
+ ExchangeStatus.FILL_PAUSED
21
+ ) {
22
+ return true;
23
+ }
24
+
25
+ if (market.hasOwnProperty('amm')) {
26
+ return isOperationPaused(market.pausedOperations, PerpOperation.FILL);
27
+ } else {
28
+ return isOperationPaused(market.pausedOperations, SpotOperation.FILL);
29
+ }
24
30
  }
25
31
 
26
32
  export function ammPaused(
27
33
  state: StateAccount,
28
34
  market: PerpMarketAccount | SpotMarketAccount
29
35
  ): boolean {
30
- return (
36
+ if (
31
37
  (state.exchangeStatus & ExchangeStatus.AMM_PAUSED) ===
32
- ExchangeStatus.AMM_PAUSED ||
33
- isOneOfVariant(market.status, ['paused', 'ammPaused'])
34
- );
38
+ ExchangeStatus.AMM_PAUSED
39
+ ) {
40
+ return true;
41
+ }
42
+
43
+ if (market.hasOwnProperty('amm')) {
44
+ return isOperationPaused(market.pausedOperations, PerpOperation.AMM_FILL);
45
+ } else {
46
+ return false;
47
+ }
35
48
  }
36
49
 
37
50
  export function isOperationPaused(
@@ -331,22 +331,6 @@ export function isRestingLimitOrder(order: Order, slot: number): boolean {
331
331
  return false;
332
332
  }
333
333
 
334
- if (isVariant(order.orderType, 'triggerLimit')) {
335
- if (
336
- isVariant(order.direction, 'long') &&
337
- order.triggerPrice.lt(order.price)
338
- ) {
339
- return false;
340
- } else if (
341
- isVariant(order.direction, 'short') &&
342
- order.triggerPrice.gt(order.price)
343
- ) {
344
- return false;
345
- }
346
-
347
- return isAuctionComplete(order, slot);
348
- }
349
-
350
334
  return order.postOnly || isAuctionComplete(order, slot);
351
335
  }
352
336
 
@@ -38,6 +38,7 @@ export class PythClient implements OracleClient {
38
38
  priceData.exponent,
39
39
  this.multiple
40
40
  );
41
+ const minPublishers = Math.min(priceData.numComponentPrices, 3);
41
42
  let price = convertPythPrice(
42
43
  priceData.aggregate.price,
43
44
  priceData.exponent,
@@ -61,7 +62,7 @@ export class PythClient implements OracleClient {
61
62
  priceData.exponent,
62
63
  this.multiple
63
64
  ),
64
- hasSufficientNumberOfDataPoints: true,
65
+ hasSufficientNumberOfDataPoints: priceData.numQuoters >= minPublishers,
65
66
  };
66
67
  }
67
68
  }
package/src/types.ts CHANGED
@@ -609,6 +609,7 @@ export type PerpMarketAccount = {
609
609
  };
610
610
  quoteSpotMarketIndex: number;
611
611
  feeAdjustment: number;
612
+ pausedOperations: number;
612
613
  };
613
614
 
614
615
  export type HistoricalOracleData = {
@@ -700,6 +701,8 @@ export type SpotMarketAccount = {
700
701
  flashLoanInitialTokenAmount: BN;
701
702
 
702
703
  ordersEnabled: boolean;
704
+
705
+ pausedOperations: number;
703
706
  };
704
707
 
705
708
  export type PoolBalance = {
@@ -28,7 +28,6 @@ import {
28
28
 
29
29
  import { mockPerpMarkets, mockSpotMarkets, mockStateAccount } from './helpers';
30
30
  import { DLOBOrdersCoder } from '../../src/dlob/DLOBOrders';
31
- import { isAuctionComplete, isRestingLimitOrder } from '../../lib';
32
31
 
33
32
  function insertOrderToDLOB(
34
33
  dlob: DLOB,
@@ -2698,60 +2697,6 @@ describe('DLOB Perp Tests', () => {
2698
2697
  }
2699
2698
  });
2700
2699
 
2701
- it('Test trigger limit isnt maker', () => {
2702
- const vAsk = new BN(15);
2703
- const vBid = new BN(8);
2704
-
2705
- const user0 = Keypair.generate();
2706
-
2707
- const dlob = new DLOB();
2708
- const marketIndex = 0;
2709
-
2710
- const slot = 20;
2711
- const oracle = {
2712
- price: vBid.add(vAsk).div(new BN(2)),
2713
- slot: new BN(slot),
2714
- confidence: new BN(1),
2715
- hasSufficientNumberOfDataPoints: true,
2716
- };
2717
-
2718
- // should trigger limit buy with above condition
2719
- insertTriggerOrderToDLOB(
2720
- dlob,
2721
- user0.publicKey,
2722
- OrderType.TRIGGER_LIMIT,
2723
- MarketType.PERP,
2724
- 1, //orderId
2725
- marketIndex, // marketIndex
2726
- oracle.price.add(new BN(1)), // price
2727
- BASE_PRECISION, // baseAssetAmount: BN,
2728
- PositionDirection.LONG,
2729
- oracle.price.sub(new BN(1)), // triggerPrice: BN,
2730
- OrderTriggerCondition.TRIGGERED_ABOVE, // triggerCondition: OrderTriggerCondition,
2731
- vBid,
2732
- vAsk,
2733
- new BN(1) // slot
2734
- );
2735
-
2736
- const restingLimitBids = Array.from(
2737
- dlob.getRestingLimitBids(marketIndex, slot, MarketType.PERP, oracle)
2738
- );
2739
- expect(restingLimitBids.length).to.equal(0);
2740
-
2741
- const takingBids = Array.from(
2742
- dlob.getTakingBids(marketIndex, MarketType.PERP, slot, oracle)
2743
- );
2744
- expect(takingBids.length).to.equal(1);
2745
- const triggerLimitBid = takingBids[0];
2746
- expect(triggerLimitBid !== undefined);
2747
- expect(isAuctionComplete(triggerLimitBid.order as Order, slot)).to.equal(
2748
- true
2749
- );
2750
- expect(isRestingLimitOrder(triggerLimitBid.order as Order, slot)).to.equal(
2751
- false
2752
- );
2753
- });
2754
-
2755
2700
  it('Test will return expired market orders to fill', () => {
2756
2701
  const vAsk = new BN(15);
2757
2702
  const vBid = new BN(8);