@drift-labs/sdk 2.100.0-beta.1 → 2.100.0-beta.11

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 (39) hide show
  1. package/VERSION +1 -1
  2. package/lib/browser/constants/perpMarkets.js +10 -0
  3. package/lib/browser/constants/spotMarkets.js +11 -0
  4. package/lib/browser/dlob/DLOB.d.ts +18 -0
  5. package/lib/browser/dlob/DLOB.js +28 -32
  6. package/lib/browser/driftClient.d.ts +4 -4
  7. package/lib/browser/driftClient.js +25 -24
  8. package/lib/browser/idl/drift.json +72 -8
  9. package/lib/browser/index.d.ts +1 -0
  10. package/lib/browser/index.js +1 -0
  11. package/lib/browser/math/oracles.js +1 -1
  12. package/lib/browser/types.d.ts +2 -1
  13. package/lib/browser/types.js +2 -1
  14. package/lib/browser/userMap/referrerMap.d.ts +11 -11
  15. package/lib/browser/userMap/referrerMap.js +44 -43
  16. package/lib/node/constants/perpMarkets.js +10 -0
  17. package/lib/node/constants/spotMarkets.js +11 -0
  18. package/lib/node/dlob/DLOB.d.ts +18 -0
  19. package/lib/node/dlob/DLOB.js +28 -32
  20. package/lib/node/driftClient.d.ts +4 -4
  21. package/lib/node/driftClient.js +25 -24
  22. package/lib/node/idl/drift.json +72 -8
  23. package/lib/node/index.d.ts +1 -0
  24. package/lib/node/index.js +1 -0
  25. package/lib/node/math/oracles.js +1 -1
  26. package/lib/node/types.d.ts +2 -1
  27. package/lib/node/types.js +2 -1
  28. package/lib/node/userMap/referrerMap.d.ts +11 -11
  29. package/lib/node/userMap/referrerMap.js +44 -43
  30. package/package.json +1 -1
  31. package/src/constants/perpMarkets.ts +10 -0
  32. package/src/constants/spotMarkets.ts +14 -0
  33. package/src/dlob/DLOB.ts +32 -39
  34. package/src/driftClient.ts +48 -40
  35. package/src/idl/drift.json +72 -8
  36. package/src/index.ts +1 -0
  37. package/src/math/oracles.ts +1 -1
  38. package/src/types.ts +2 -1
  39. package/src/userMap/referrerMap.ts +58 -74
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.100.0-beta.1
1
+ 2.100.0-beta.11
@@ -310,6 +310,16 @@ exports.DevnetPerpMarkets = [
310
310
  launchTs: 1722214583000,
311
311
  oracleSource: __1.OracleSource.Prelaunch,
312
312
  },
313
+ {
314
+ fullName: 'RANDOM-2024',
315
+ category: ['Prediction'],
316
+ symbol: 'RANDOM-2024-PREDICT',
317
+ baseAssetSymbol: 'RANDOM-2024',
318
+ marketIndex: 28,
319
+ oracle: new web3_js_1.PublicKey('sDAQaZQJQ4RXAxH3x526mbEXyQZT15ktkL84d7hmk7M'),
320
+ launchTs: 1729622442000,
321
+ oracleSource: __1.OracleSource.Prelaunch,
322
+ },
313
323
  ];
314
324
  exports.MainnetPerpMarkets = [
315
325
  {
@@ -106,6 +106,7 @@ exports.MainnetSpotMarkets = [
106
106
  precisionExp: numericConstants_1.EIGHT,
107
107
  serumMarket: new web3_js_1.PublicKey('BbJgE7HZMaDp5NTYvRh5jZSkQPVDTU8ubPFtpogUkEj4'),
108
108
  phoenixMarket: new web3_js_1.PublicKey('Ew3vFDdtdGrknJAVVfraxCA37uNJtimXYPY4QjnfhFHH'),
109
+ openbookMarket: new web3_js_1.PublicKey('AT1R2jUNb9iTo4EaRfKSTPiNTX4Jb64KSwnVmig6Hu4t'),
109
110
  pythFeedId: '0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
110
111
  },
111
112
  {
@@ -354,6 +355,16 @@ exports.MainnetSpotMarkets = [
354
355
  precisionExp: numericConstants_1.SIX,
355
356
  pythFeedId: '0x62742a997d01f7524f791fdb2dd43aaf0e567d765ebf8fd0406a994239e874d4',
356
357
  },
358
+ {
359
+ symbol: 'cbBTC',
360
+ marketIndex: 27,
361
+ oracle: new web3_js_1.PublicKey('486kr3pmFPfTsS4aZgcsQ7kS4i9rjMsYYZup6HQNSTT4'),
362
+ oracleSource: __1.OracleSource.PYTH_PULL,
363
+ mint: new web3_js_1.PublicKey('cbbtcf3aa214zXHbiAZQwf4122FBYbraNdFqgw4iMij'),
364
+ precision: new __1.BN(10).pow(numericConstants_1.EIGHT),
365
+ precisionExp: numericConstants_1.EIGHT,
366
+ pythFeedId: '0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
367
+ },
357
368
  ];
358
369
  exports.SpotMarkets = {
359
370
  devnet: exports.DevnetSpotMarkets,
@@ -84,7 +84,25 @@ export declare class DLOB {
84
84
  protected getBestNode(generatorList: Array<Generator<DLOBNode>>, oraclePriceData: OraclePriceData, slot: number, compareFcn: (bestDLOBNode: DLOBNode, currentDLOBNode: DLOBNode, slot: number, oraclePriceData: OraclePriceData) => boolean, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
85
85
  getRestingLimitAsks(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
86
86
  getRestingLimitBids(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
87
+ /**
88
+ * This will look at both the taking and resting limit asks
89
+ * @param marketIndex
90
+ * @param fallbackAsk
91
+ * @param slot
92
+ * @param marketType
93
+ * @param oraclePriceData
94
+ * @param filterFcn
95
+ */
87
96
  getAsks(marketIndex: number, fallbackAsk: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
97
+ /**
98
+ * This will look at both the taking and resting limit bids
99
+ * @param marketIndex
100
+ * @param fallbackBid
101
+ * @param slot
102
+ * @param marketType
103
+ * @param oraclePriceData
104
+ * @param filterFcn
105
+ */
88
106
  getBids(marketIndex: number, fallbackBid: BN | undefined, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, filterFcn?: DLOBFilterFcn): Generator<DLOBNode>;
89
107
  findCrossingRestingLimitOrders(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData): NodeToFill[];
90
108
  determineMakerAndTaker(askNode: DLOBNode, bidNode: DLOBNode): {
@@ -675,6 +675,15 @@ class DLOB {
675
675
  .gt(currentNode.getPrice(oraclePriceData, slot));
676
676
  }, filterFcn);
677
677
  }
678
+ /**
679
+ * This will look at both the taking and resting limit asks
680
+ * @param marketIndex
681
+ * @param fallbackAsk
682
+ * @param slot
683
+ * @param marketType
684
+ * @param oraclePriceData
685
+ * @param filterFcn
686
+ */
678
687
  *getAsks(marketIndex, fallbackAsk, slot, marketType, oraclePriceData, filterFcn) {
679
688
  if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
680
689
  throw new Error('Must provide OraclePriceData to get spot asks');
@@ -688,26 +697,24 @@ class DLOB {
688
697
  generatorList.push((0, NodeList_1.getVammNodeGenerator)(fallbackAsk));
689
698
  }
690
699
  yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
691
- const bestNodeTaking = bestNode.order
692
- ? (0, __1.isTakingOrder)(bestNode.order, slot)
693
- : false;
694
- const currentNodeTaking = currentNode.order
695
- ? (0, __1.isTakingOrder)(currentNode.order, slot)
696
- : false;
697
- if (bestNodeTaking && currentNodeTaking) {
700
+ var _a, _b;
701
+ const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot)) !== null && _a !== void 0 ? _a : __1.ZERO;
702
+ const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot)) !== null && _b !== void 0 ? _b : __1.ZERO;
703
+ if (bestNodePrice.eq(currentNodePrice)) {
698
704
  return bestNode.order.slot.lt(currentNode.order.slot);
699
705
  }
700
- if (bestNodeTaking) {
701
- return true;
702
- }
703
- if (currentNodeTaking) {
704
- return false;
705
- }
706
- return bestNode
707
- .getPrice(oraclePriceData, slot)
708
- .lt(currentNode.getPrice(oraclePriceData, slot));
706
+ return bestNodePrice.lt(currentNodePrice);
709
707
  }, filterFcn);
710
708
  }
709
+ /**
710
+ * This will look at both the taking and resting limit bids
711
+ * @param marketIndex
712
+ * @param fallbackBid
713
+ * @param slot
714
+ * @param marketType
715
+ * @param oraclePriceData
716
+ * @param filterFcn
717
+ */
711
718
  *getBids(marketIndex, fallbackBid, slot, marketType, oraclePriceData, filterFcn) {
712
719
  if ((0, __1.isVariant)(marketType, 'spot') && !oraclePriceData) {
713
720
  throw new Error('Must provide OraclePriceData to get spot bids');
@@ -721,24 +728,13 @@ class DLOB {
721
728
  generatorList.push((0, NodeList_1.getVammNodeGenerator)(fallbackBid));
722
729
  }
723
730
  yield* this.getBestNode(generatorList, oraclePriceData, slot, (bestNode, currentNode, slot, oraclePriceData) => {
724
- const bestNodeTaking = bestNode.order
725
- ? (0, __1.isTakingOrder)(bestNode.order, slot)
726
- : false;
727
- const currentNodeTaking = currentNode.order
728
- ? (0, __1.isTakingOrder)(currentNode.order, slot)
729
- : false;
730
- if (bestNodeTaking && currentNodeTaking) {
731
+ var _a, _b;
732
+ const bestNodePrice = (_a = bestNode.getPrice(oraclePriceData, slot)) !== null && _a !== void 0 ? _a : __1.BN_MAX;
733
+ const currentNodePrice = (_b = currentNode.getPrice(oraclePriceData, slot)) !== null && _b !== void 0 ? _b : __1.BN_MAX;
734
+ if (bestNodePrice.eq(currentNodePrice)) {
731
735
  return bestNode.order.slot.lt(currentNode.order.slot);
732
736
  }
733
- if (bestNodeTaking) {
734
- return true;
735
- }
736
- if (currentNodeTaking) {
737
- return false;
738
- }
739
- return bestNode
740
- .getPrice(oraclePriceData, slot)
741
- .gt(currentNode.getPrice(oraclePriceData, slot));
737
+ return bestNodePrice.gt(currentNodePrice);
742
738
  }, filterFcn);
743
739
  }
744
740
  findCrossingRestingLimitOrders(marketIndex, slot, marketType, oraclePriceData) {
@@ -141,8 +141,10 @@ export declare class DriftClient {
141
141
  getInitializeUserStatsIx(): Promise<TransactionInstruction>;
142
142
  initializeRFQUser(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
143
143
  getInitializeRFQUserInstruction(userAccountPublicKey: PublicKey): Promise<[PublicKey, TransactionInstruction]>;
144
- initializeSwiftUserOrdersAccount(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
145
- getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey: PublicKey): Promise<[PublicKey, TransactionInstruction]>;
144
+ initializeSwiftUserOrders(userAccountPublicKey: PublicKey, numOrders: number, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
145
+ getInitializeSwiftUserOrdersAccountIx(userAccountPublicKey: PublicKey, numOrders: number): Promise<[PublicKey, TransactionInstruction]>;
146
+ resizeSwiftUserOrders(userAccountPublicKey: PublicKey, numOrders: number, txParams?: TxParams): Promise<TransactionSignature>;
147
+ getResizeSwiftUserOrdersInstruction(userAccountPublicKey: PublicKey, numOrders: number): Promise<TransactionInstruction>;
146
148
  getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
147
149
  getNextSubAccountId(): Promise<number>;
148
150
  initializeReferrerName(name: string): Promise<TransactionSignature>;
@@ -503,8 +505,6 @@ export declare class DriftClient {
503
505
  getUpdateUserFuelBonusIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, userAuthority: PublicKey): Promise<TransactionInstruction>;
504
506
  updateUserStatsReferrerStatus(userAuthority: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
505
507
  getUpdateUserStatsReferrerStatusIx(userAuthority: PublicKey): Promise<TransactionInstruction>;
506
- updateUserStatsReferrerInfo(userStatsAccountPublicKey: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
507
- getUpdateUserStatsReferrerInfoIx(userStatsAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
508
508
  updateUserOpenOrdersCount(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams, fillerPublicKey?: PublicKey): Promise<TransactionSignature>;
509
509
  getUpdateUserOpenOrdersCountIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
510
510
  placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
@@ -600,17 +600,17 @@ class DriftClient {
600
600
  });
601
601
  return [rfqUserAccountPublicKey, initializeUserAccountIx];
602
602
  }
603
- async initializeSwiftUserOrdersAccount(userAccountPublicKey, txParams) {
603
+ async initializeSwiftUserOrders(userAccountPublicKey, numOrders, txParams) {
604
604
  const initializeIxs = [];
605
- const [swiftUserAccountPublicKey, initializeUserAccountIx] = await this.getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey);
605
+ const [swiftUserAccountPublicKey, initializeUserAccountIx] = await this.getInitializeSwiftUserOrdersAccountIx(userAccountPublicKey, numOrders);
606
606
  initializeIxs.push(initializeUserAccountIx);
607
607
  const tx = await this.buildTransaction(initializeIxs, txParams);
608
608
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
609
609
  return [txSig, swiftUserAccountPublicKey];
610
610
  }
611
- async getInitializeSwiftUserOrdersAccountInstruction(userAccountPublicKey) {
611
+ async getInitializeSwiftUserOrdersAccountIx(userAccountPublicKey, numOrders) {
612
612
  const swiftUserAccountPublicKey = (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, userAccountPublicKey);
613
- const initializeUserAccountIx = await this.program.instruction.initializeSwiftUserOrders({
613
+ const initializeUserAccountIx = await this.program.instruction.initializeSwiftUserOrders(numOrders, {
614
614
  accounts: {
615
615
  swiftUserOrders: swiftUserAccountPublicKey,
616
616
  authority: this.wallet.publicKey,
@@ -622,6 +622,24 @@ class DriftClient {
622
622
  });
623
623
  return [swiftUserAccountPublicKey, initializeUserAccountIx];
624
624
  }
625
+ async resizeSwiftUserOrders(userAccountPublicKey, numOrders, txParams) {
626
+ const resizeUserAccountIx = await this.getResizeSwiftUserOrdersInstruction(userAccountPublicKey, numOrders);
627
+ const tx = await this.buildTransaction([resizeUserAccountIx], txParams);
628
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
629
+ return txSig;
630
+ }
631
+ async getResizeSwiftUserOrdersInstruction(userAccountPublicKey, numOrders) {
632
+ const swiftUserAccountPublicKey = (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, userAccountPublicKey);
633
+ const resizeUserAccountIx = await this.program.instruction.resizeSwiftUserOrders(numOrders, {
634
+ accounts: {
635
+ swiftUserOrders: swiftUserAccountPublicKey,
636
+ authority: this.wallet.publicKey,
637
+ user: userAccountPublicKey,
638
+ systemProgram: anchor.web3.SystemProgram.programId,
639
+ },
640
+ });
641
+ return resizeUserAccountIx;
642
+ }
625
643
  async getInitializeUserInstructions(subAccountId = 0, name, referrerInfo) {
626
644
  const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, subAccountId);
627
645
  const remainingAccounts = new Array();
@@ -2824,20 +2842,7 @@ class DriftClient {
2824
2842
  }
2825
2843
  async getUpdateUserStatsReferrerStatusIx(userAuthority) {
2826
2844
  const userStatsAccountPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAuthority);
2827
- return await this.program.instruction.updateStatsReferrerStatus({
2828
- accounts: {
2829
- state: await this.getStatePublicKey(),
2830
- userStats: userStatsAccountPublicKey,
2831
- authority: this.wallet.publicKey,
2832
- },
2833
- });
2834
- }
2835
- async updateUserStatsReferrerInfo(userStatsAccountPublicKey, txParams) {
2836
- const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateUserStatsReferrerInfoIx(userStatsAccountPublicKey), txParams), [], this.opts);
2837
- return txSig;
2838
- }
2839
- async getUpdateUserStatsReferrerInfoIx(userStatsAccountPublicKey) {
2840
- return await this.program.instruction.updateUserStatsReferrerInfo({
2845
+ return await this.program.instruction.updateUserStatsReferrerStatus({
2841
2846
  accounts: {
2842
2847
  state: await this.getStatePublicKey(),
2843
2848
  userStats: userStatsAccountPublicKey,
@@ -4219,14 +4224,10 @@ class DriftClient {
4219
4224
  else {
4220
4225
  marketAccount = this.getSpotMarketAccount(marketIndex);
4221
4226
  }
4222
- let takeFeeAdjustment;
4227
+ takerFee += (takerFee * marketAccount.feeAdjustment) / 100;
4223
4228
  if (user && user.isHighLeverageMode()) {
4224
- takeFeeAdjustment = 100;
4225
- }
4226
- else {
4227
- takeFeeAdjustment = marketAccount.feeAdjustment;
4229
+ takerFee *= 2;
4228
4230
  }
4229
- takerFee += (takerFee * takeFeeAdjustment) / 100;
4230
4231
  makerFee += (makerFee * marketAccount.feeAdjustment) / 100;
4231
4232
  }
4232
4233
  return {
@@ -144,7 +144,7 @@
144
144
  },
145
145
  {
146
146
  "name": "user",
147
- "isMut": true,
147
+ "isMut": false,
148
148
  "isSigner": false
149
149
  },
150
150
  {
@@ -163,7 +163,43 @@
163
163
  "isSigner": false
164
164
  }
165
165
  ],
166
- "args": []
166
+ "args": [
167
+ {
168
+ "name": "numOrders",
169
+ "type": "u16"
170
+ }
171
+ ]
172
+ },
173
+ {
174
+ "name": "resizeSwiftUserOrders",
175
+ "accounts": [
176
+ {
177
+ "name": "swiftUserOrders",
178
+ "isMut": true,
179
+ "isSigner": false
180
+ },
181
+ {
182
+ "name": "authority",
183
+ "isMut": true,
184
+ "isSigner": true
185
+ },
186
+ {
187
+ "name": "user",
188
+ "isMut": false,
189
+ "isSigner": false
190
+ },
191
+ {
192
+ "name": "systemProgram",
193
+ "isMut": false,
194
+ "isSigner": false
195
+ }
196
+ ],
197
+ "args": [
198
+ {
199
+ "name": "numOrders",
200
+ "type": "u16"
201
+ }
202
+ ]
167
203
  },
168
204
  {
169
205
  "name": "initializeReferrerName",
@@ -7615,6 +7651,9 @@
7615
7651
  },
7616
7652
  {
7617
7653
  "name": "SwiftUserOrders",
7654
+ "docs": [
7655
+ "* This struct is a duplicate of SwiftUserOrdersZeroCopy\n * It is used to give anchor an struct to generate the idl for clients\n * The struct SwiftUserOrdersZeroCopy is used to load the data in efficiently"
7656
+ ],
7618
7657
  "type": {
7619
7658
  "kind": "struct",
7620
7659
  "fields": [
@@ -7622,15 +7661,16 @@
7622
7661
  "name": "userPubkey",
7623
7662
  "type": "publicKey"
7624
7663
  },
7664
+ {
7665
+ "name": "padding",
7666
+ "type": "u32"
7667
+ },
7625
7668
  {
7626
7669
  "name": "swiftOrderData",
7627
7670
  "type": {
7628
- "array": [
7629
- {
7630
- "defined": "SwiftOrderId"
7631
- },
7632
- 32
7633
- ]
7671
+ "vec": {
7672
+ "defined": "SwiftOrderId"
7673
+ }
7634
7674
  }
7635
7675
  }
7636
7676
  ]
@@ -9836,6 +9876,30 @@
9836
9876
  {
9837
9877
  "name": "orderId",
9838
9878
  "type": "u32"
9879
+ },
9880
+ {
9881
+ "name": "padding",
9882
+ "type": "u32"
9883
+ }
9884
+ ]
9885
+ }
9886
+ },
9887
+ {
9888
+ "name": "SwiftUserOrdersFixed",
9889
+ "type": {
9890
+ "kind": "struct",
9891
+ "fields": [
9892
+ {
9893
+ "name": "userPubkey",
9894
+ "type": "publicKey"
9895
+ },
9896
+ {
9897
+ "name": "padding",
9898
+ "type": "u32"
9899
+ },
9900
+ {
9901
+ "name": "len",
9902
+ "type": "u32"
9839
9903
  }
9840
9904
  ]
9841
9905
  }
@@ -92,6 +92,7 @@ export * from './tx/forwardOnlyTxSender';
92
92
  export * from './tx/types';
93
93
  export * from './tx/txHandler';
94
94
  export * from './util/computeUnits';
95
+ export * from './util/digest';
95
96
  export * from './util/tps';
96
97
  export * from './util/promiseTimeout';
97
98
  export * from './util/pythPullOracleUtils';
@@ -115,6 +115,7 @@ __exportStar(require("./tx/forwardOnlyTxSender"), exports);
115
115
  __exportStar(require("./tx/types"), exports);
116
116
  __exportStar(require("./tx/txHandler"), exports);
117
117
  __exportStar(require("./util/computeUnits"), exports);
118
+ __exportStar(require("./util/digest"), exports);
118
119
  __exportStar(require("./util/tps"), exports);
119
120
  __exportStar(require("./util/promiseTimeout"), exports);
120
121
  __exportStar(require("./util/pythPullOracleUtils"), exports);
@@ -10,7 +10,7 @@ function oraclePriceBands(market, oraclePriceData) {
10
10
  const offset = oraclePriceData.price
11
11
  .mul(new index_1.BN(maxPercentDiff))
12
12
  .div(numericConstants_1.MARGIN_PRECISION);
13
- (0, assert_1.assert)(offset.gt(numericConstants_1.ZERO));
13
+ (0, assert_1.assert)(offset.gte(numericConstants_1.ZERO));
14
14
  return [oraclePriceData.price.sub(offset), oraclePriceData.price.add(offset)];
15
15
  }
16
16
  exports.oraclePriceBands = oraclePriceBands;
@@ -13,7 +13,8 @@ export declare enum ExchangeStatus {
13
13
  LIQ_PAUSED = 16,
14
14
  FUNDING_PAUSED = 32,
15
15
  SETTLE_PNL_PAUSED = 64,
16
- PAUSED = 127
16
+ AMM_IMMEDIATE_FILL_PAUSED = 128,
17
+ PAUSED = 255
17
18
  }
18
19
  export declare class MarketStatus {
19
20
  static readonly INITIALIZED: {
@@ -13,7 +13,8 @@ var ExchangeStatus;
13
13
  ExchangeStatus[ExchangeStatus["LIQ_PAUSED"] = 16] = "LIQ_PAUSED";
14
14
  ExchangeStatus[ExchangeStatus["FUNDING_PAUSED"] = 32] = "FUNDING_PAUSED";
15
15
  ExchangeStatus[ExchangeStatus["SETTLE_PNL_PAUSED"] = 64] = "SETTLE_PNL_PAUSED";
16
- ExchangeStatus[ExchangeStatus["PAUSED"] = 127] = "PAUSED";
16
+ ExchangeStatus[ExchangeStatus["AMM_IMMEDIATE_FILL_PAUSED"] = 128] = "AMM_IMMEDIATE_FILL_PAUSED";
17
+ ExchangeStatus[ExchangeStatus["PAUSED"] = 255] = "PAUSED";
17
18
  })(ExchangeStatus = exports.ExchangeStatus || (exports.ExchangeStatus = {}));
18
19
  class MarketStatus {
19
20
  }
@@ -1,17 +1,17 @@
1
1
  import { MemcmpFilter } from '@solana/web3.js';
2
- import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
3
2
  import { DriftClient } from '../driftClient';
4
3
  import { ReferrerInfo } from '../types';
5
4
  export declare class ReferrerMap {
6
5
  /**
7
- * map from authority pubkey to ReferrerInfo.
8
- * - if a user has not been entered into the map, the value is undefined
9
- * - if a user has no referrer, the value is null
10
- * - if a user has a referrer, the value is a ReferrerInfo object
6
+ * map from authority pubkey to referrer pubkey.
11
7
  */
12
- private referrerMap;
8
+ private authorityReferrerMap;
9
+ /**
10
+ * map from referrer pubkey to ReferrerInfo.
11
+ * Will be undefined if the referrer is not in the map yet.
12
+ */
13
+ private referrerReferrerInfoMap;
13
14
  private driftClient;
14
- private bulkAccountLoader;
15
15
  private parallelSync;
16
16
  private fetchPromise?;
17
17
  private fetchPromiseResolver;
@@ -19,16 +19,15 @@ export declare class ReferrerMap {
19
19
  * Creates a new UserStatsMap instance.
20
20
  *
21
21
  * @param {DriftClient} driftClient - The DriftClient instance.
22
- * @param {BulkAccountLoader} [bulkAccountLoader] - If not provided, a new BulkAccountLoader with polling disabled will be created.
23
22
  */
24
- constructor(driftClient: DriftClient, bulkAccountLoader?: BulkAccountLoader, parallelSync?: boolean);
23
+ constructor(driftClient: DriftClient, parallelSync?: boolean);
25
24
  /**
26
25
  * Subscribe to all UserStats accounts.
27
26
  */
28
27
  subscribe(): Promise<void>;
29
28
  has(authorityPublicKey: string): boolean;
30
29
  get(authorityPublicKey: string): ReferrerInfo | undefined;
31
- addReferrerInfo(authority: string, referrerInfo?: ReferrerInfo | null): Promise<void>;
30
+ addReferrer(authority: string, referrer?: string): Promise<void>;
32
31
  /**
33
32
  * Enforce that a UserStats will exist for the given authorityPublicKey,
34
33
  * reading one from the blockchain if necessary.
@@ -36,8 +35,9 @@ export declare class ReferrerMap {
36
35
  * @returns
37
36
  */
38
37
  mustGet(authorityPublicKey: string): Promise<ReferrerInfo | undefined>;
39
- values(): IterableIterator<ReferrerInfo | null>;
38
+ getReferrer(authorityPublicKey: string): ReferrerInfo | undefined;
40
39
  size(): number;
40
+ numberOfReferred(): number;
41
41
  sync(): Promise<void>;
42
42
  syncAll(): Promise<void>;
43
43
  syncReferrer(referrerFilter: MemcmpFilter): Promise<void>;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReferrerMap = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
- const bulkAccountLoader_1 = require("../accounts/bulkAccountLoader");
6
5
  const pda_1 = require("../addresses/pda");
7
6
  const memcmp_1 = require("../memcmp");
8
7
  const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
@@ -12,21 +11,18 @@ class ReferrerMap {
12
11
  * Creates a new UserStatsMap instance.
13
12
  *
14
13
  * @param {DriftClient} driftClient - The DriftClient instance.
15
- * @param {BulkAccountLoader} [bulkAccountLoader] - If not provided, a new BulkAccountLoader with polling disabled will be created.
16
14
  */
17
- constructor(driftClient, bulkAccountLoader, parallelSync) {
15
+ constructor(driftClient, parallelSync) {
18
16
  /**
19
- * map from authority pubkey to ReferrerInfo.
20
- * - if a user has not been entered into the map, the value is undefined
21
- * - if a user has no referrer, the value is null
22
- * - if a user has a referrer, the value is a ReferrerInfo object
17
+ * map from authority pubkey to referrer pubkey.
23
18
  */
24
- this.referrerMap = new Map();
19
+ this.authorityReferrerMap = new Map();
20
+ /**
21
+ * map from referrer pubkey to ReferrerInfo.
22
+ * Will be undefined if the referrer is not in the map yet.
23
+ */
24
+ this.referrerReferrerInfoMap = new Map();
25
25
  this.driftClient = driftClient;
26
- if (!bulkAccountLoader) {
27
- bulkAccountLoader = new bulkAccountLoader_1.BulkAccountLoader(driftClient.connection, driftClient.opts.commitment, 0);
28
- }
29
- this.bulkAccountLoader = bulkAccountLoader;
30
26
  this.parallelSync = parallelSync !== undefined ? parallelSync : true;
31
27
  }
32
28
  /**
@@ -40,27 +36,20 @@ class ReferrerMap {
40
36
  await this.sync();
41
37
  }
42
38
  has(authorityPublicKey) {
43
- return this.referrerMap.has(authorityPublicKey);
39
+ return this.authorityReferrerMap.has(authorityPublicKey);
44
40
  }
45
41
  get(authorityPublicKey) {
46
- const info = this.referrerMap.get(authorityPublicKey);
47
- return info === null ? undefined : info;
42
+ return this.getReferrer(authorityPublicKey);
48
43
  }
49
- async addReferrerInfo(authority, referrerInfo) {
50
- if (referrerInfo || referrerInfo === null) {
51
- this.referrerMap.set(authority, referrerInfo);
44
+ async addReferrer(authority, referrer) {
45
+ if (referrer) {
46
+ this.authorityReferrerMap.set(authority, referrer);
52
47
  }
53
- else if (referrerInfo === undefined) {
48
+ else if (referrer === undefined) {
54
49
  const userStatsAccountPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, new web3_js_1.PublicKey(authority));
55
50
  const buffer = (await this.driftClient.connection.getAccountInfo(userStatsAccountPublicKey, 'processed')).data;
56
51
  const referrer = bytes_1.bs58.encode(buffer.subarray(40, 72));
57
- const referrerKey = new web3_js_1.PublicKey(referrer);
58
- this.addReferrerInfo(authority, referrer === DEFAULT_PUBLIC_KEY
59
- ? null
60
- : {
61
- referrer: (0, pda_1.getUserAccountPublicKeySync)(this.driftClient.program.programId, referrerKey, 0),
62
- referrerStats: (0, pda_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, referrerKey),
63
- });
52
+ this.addReferrer(authority, referrer);
64
53
  }
65
54
  }
66
55
  /**
@@ -71,15 +60,35 @@ class ReferrerMap {
71
60
  */
72
61
  async mustGet(authorityPublicKey) {
73
62
  if (!this.has(authorityPublicKey)) {
74
- await this.addReferrerInfo(authorityPublicKey);
63
+ await this.addReferrer(authorityPublicKey);
75
64
  }
76
- return this.get(authorityPublicKey);
65
+ return this.getReferrer(authorityPublicKey);
77
66
  }
78
- values() {
79
- return this.referrerMap.values();
67
+ getReferrer(authorityPublicKey) {
68
+ const referrer = this.authorityReferrerMap.get(authorityPublicKey);
69
+ if (!referrer) {
70
+ // return undefined if the referrer is not in the map
71
+ return undefined;
72
+ }
73
+ if (referrer === DEFAULT_PUBLIC_KEY) {
74
+ return undefined;
75
+ }
76
+ if (this.referrerReferrerInfoMap.has(referrer)) {
77
+ return this.referrerReferrerInfoMap.get(referrer);
78
+ }
79
+ const referrerKey = new web3_js_1.PublicKey(referrer);
80
+ const referrerInfo = {
81
+ referrer: (0, pda_1.getUserAccountPublicKeySync)(this.driftClient.program.programId, referrerKey, 0),
82
+ referrerStats: (0, pda_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, referrerKey),
83
+ };
84
+ this.referrerReferrerInfoMap.set(referrer, referrerInfo);
85
+ return referrerInfo;
80
86
  }
81
87
  size() {
82
- return this.referrerMap.size;
88
+ return this.authorityReferrerMap.size;
89
+ }
90
+ numberOfReferred() {
91
+ return Array.from(this.authorityReferrerMap.values()).filter((referrer) => referrer !== DEFAULT_PUBLIC_KEY).length;
83
92
  }
84
93
  async sync() {
85
94
  if (this.fetchPromise) {
@@ -102,9 +111,6 @@ class ReferrerMap {
102
111
  await this.syncReferrer((0, memcmp_1.getUserStatsIsReferredOrReferrerFilter)());
103
112
  }
104
113
  }
105
- catch (e) {
106
- console.error('error in referrerMap.sync', e);
107
- }
108
114
  finally {
109
115
  this.fetchPromiseResolver();
110
116
  this.fetchPromise = undefined;
@@ -132,7 +138,7 @@ class ReferrerMap {
132
138
  // only add if it isn't already in the map
133
139
  // so that if syncReferrer already set it, we dont overwrite
134
140
  if (!this.has(account.pubkey)) {
135
- this.addReferrerInfo(account.pubkey, null);
141
+ this.addReferrer(account.pubkey, DEFAULT_PUBLIC_KEY);
136
142
  }
137
143
  }
138
144
  }
@@ -162,19 +168,14 @@ class ReferrerMap {
162
168
  const buffer = Buffer.from(programAccount.account.data[0], programAccount.account.data[1]);
163
169
  const authority = bytes_1.bs58.encode(buffer.subarray(8, 40));
164
170
  const referrer = bytes_1.bs58.encode(buffer.subarray(40, 72));
165
- const referrerKey = new web3_js_1.PublicKey(referrer);
166
- this.addReferrerInfo(authority, referrer === DEFAULT_PUBLIC_KEY
167
- ? null
168
- : {
169
- referrer: (0, pda_1.getUserAccountPublicKeySync)(this.driftClient.program.programId, referrerKey, 0),
170
- referrerStats: (0, pda_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, referrerKey),
171
- });
171
+ this.addReferrer(authority, referrer);
172
172
  }));
173
173
  await new Promise((resolve) => setTimeout(resolve, 0));
174
174
  }
175
175
  }
176
176
  async unsubscribe() {
177
- this.referrerMap.clear();
177
+ this.authorityReferrerMap.clear();
178
+ this.referrerReferrerInfoMap.clear();
178
179
  }
179
180
  }
180
181
  exports.ReferrerMap = ReferrerMap;