@drift-labs/sdk 2.100.0-beta.0 → 2.100.0-beta.10

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.100.0-beta.0
1
+ 2.100.0-beta.10
@@ -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,
@@ -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>;
@@ -176,6 +178,8 @@ export declare class DriftClient {
176
178
  getReferrerNameAccountsForAuthority(authority: PublicKey): Promise<ReferrerNameAccount[]>;
177
179
  deleteUser(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
178
180
  getUserDeletionIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
181
+ deleteSwiftUserOrders(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
182
+ getSwiftUserOrdersDeletionIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
179
183
  reclaimRent(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
180
184
  getReclaimRentIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
181
185
  getUser(subAccountId?: number, authority?: PublicKey): User;
@@ -501,8 +505,6 @@ export declare class DriftClient {
501
505
  getUpdateUserFuelBonusIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, userAuthority: PublicKey): Promise<TransactionInstruction>;
502
506
  updateUserStatsReferrerStatus(userAuthority: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
503
507
  getUpdateUserStatsReferrerStatusIx(userAuthority: PublicKey): Promise<TransactionInstruction>;
504
- updateUserStatsReferrerInfo(userStatsAccountPublicKey: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
505
- getUpdateUserStatsReferrerInfoIx(userStatsAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
506
508
  updateUserOpenOrdersCount(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams, fillerPublicKey?: PublicKey): Promise<TransactionSignature>;
507
509
  getUpdateUserOpenOrdersCountIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
508
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();
@@ -895,6 +913,27 @@ class DriftClient {
895
913
  });
896
914
  return ix;
897
915
  }
916
+ async deleteSwiftUserOrders(subAccountId = 0, txParams) {
917
+ var _a;
918
+ const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
919
+ const ix = await this.getSwiftUserOrdersDeletionIx(userAccountPublicKey);
920
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(ix, txParams), [], this.opts);
921
+ const userMapKey = this.getUserMapKey(subAccountId, this.wallet.publicKey);
922
+ await ((_a = this.users.get(userMapKey)) === null || _a === void 0 ? void 0 : _a.unsubscribe());
923
+ this.users.delete(userMapKey);
924
+ return txSig;
925
+ }
926
+ async getSwiftUserOrdersDeletionIx(userAccountPublicKey) {
927
+ const ix = await this.program.instruction.deleteSwiftUserOrders({
928
+ accounts: {
929
+ user: userAccountPublicKey,
930
+ swiftUserOrders: (0, pda_1.getSwiftUserAccountPublicKey)(this.program.programId, userAccountPublicKey),
931
+ authority: this.wallet.publicKey,
932
+ state: await this.getStatePublicKey(),
933
+ },
934
+ });
935
+ return ix;
936
+ }
898
937
  async reclaimRent(subAccountId = 0, txParams) {
899
938
  const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
900
939
  const ix = await this.getReclaimRentIx(userAccountPublicKey);
@@ -2803,20 +2842,7 @@ class DriftClient {
2803
2842
  }
2804
2843
  async getUpdateUserStatsReferrerStatusIx(userAuthority) {
2805
2844
  const userStatsAccountPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAuthority);
2806
- return await this.program.instruction.updateStatsReferrerStatus({
2807
- accounts: {
2808
- state: await this.getStatePublicKey(),
2809
- userStats: userStatsAccountPublicKey,
2810
- authority: this.wallet.publicKey,
2811
- },
2812
- });
2813
- }
2814
- async updateUserStatsReferrerInfo(userStatsAccountPublicKey, txParams) {
2815
- const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateUserStatsReferrerInfoIx(userStatsAccountPublicKey), txParams), [], this.opts);
2816
- return txSig;
2817
- }
2818
- async getUpdateUserStatsReferrerInfoIx(userStatsAccountPublicKey) {
2819
- return await this.program.instruction.updateUserStatsReferrerInfo({
2845
+ return await this.program.instruction.updateUserStatsReferrerStatus({
2820
2846
  accounts: {
2821
2847
  state: await this.getStatePublicKey(),
2822
2848
  userStats: userStatsAccountPublicKey,
@@ -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",
@@ -1422,6 +1458,32 @@
1422
1458
  ],
1423
1459
  "args": []
1424
1460
  },
1461
+ {
1462
+ "name": "deleteSwiftUserOrders",
1463
+ "accounts": [
1464
+ {
1465
+ "name": "user",
1466
+ "isMut": true,
1467
+ "isSigner": false
1468
+ },
1469
+ {
1470
+ "name": "swiftUserOrders",
1471
+ "isMut": true,
1472
+ "isSigner": false
1473
+ },
1474
+ {
1475
+ "name": "state",
1476
+ "isMut": true,
1477
+ "isSigner": false
1478
+ },
1479
+ {
1480
+ "name": "authority",
1481
+ "isMut": false,
1482
+ "isSigner": true
1483
+ }
1484
+ ],
1485
+ "args": []
1486
+ },
1425
1487
  {
1426
1488
  "name": "reclaimRent",
1427
1489
  "accounts": [
@@ -7589,6 +7651,9 @@
7589
7651
  },
7590
7652
  {
7591
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
+ ],
7592
7657
  "type": {
7593
7658
  "kind": "struct",
7594
7659
  "fields": [
@@ -7596,15 +7661,16 @@
7596
7661
  "name": "userPubkey",
7597
7662
  "type": "publicKey"
7598
7663
  },
7664
+ {
7665
+ "name": "padding",
7666
+ "type": "u32"
7667
+ },
7599
7668
  {
7600
7669
  "name": "swiftOrderData",
7601
7670
  "type": {
7602
- "array": [
7603
- {
7604
- "defined": "SwiftOrderId"
7605
- },
7606
- 32
7607
- ]
7671
+ "vec": {
7672
+ "defined": "SwiftOrderId"
7673
+ }
7608
7674
  }
7609
7675
  }
7610
7676
  ]
@@ -9810,6 +9876,30 @@
9810
9876
  {
9811
9877
  "name": "orderId",
9812
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"
9813
9903
  }
9814
9904
  ]
9815
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;
@@ -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,
@@ -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>;
@@ -176,6 +178,8 @@ export declare class DriftClient {
176
178
  getReferrerNameAccountsForAuthority(authority: PublicKey): Promise<ReferrerNameAccount[]>;
177
179
  deleteUser(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
178
180
  getUserDeletionIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
181
+ deleteSwiftUserOrders(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
182
+ getSwiftUserOrdersDeletionIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
179
183
  reclaimRent(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
180
184
  getReclaimRentIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
181
185
  getUser(subAccountId?: number, authority?: PublicKey): User;
@@ -501,8 +505,6 @@ export declare class DriftClient {
501
505
  getUpdateUserFuelBonusIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, userAuthority: PublicKey): Promise<TransactionInstruction>;
502
506
  updateUserStatsReferrerStatus(userAuthority: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
503
507
  getUpdateUserStatsReferrerStatusIx(userAuthority: PublicKey): Promise<TransactionInstruction>;
504
- updateUserStatsReferrerInfo(userStatsAccountPublicKey: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
505
- getUpdateUserStatsReferrerInfoIx(userStatsAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
506
508
  updateUserOpenOrdersCount(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams, fillerPublicKey?: PublicKey): Promise<TransactionSignature>;
507
509
  getUpdateUserOpenOrdersCountIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey): Promise<TransactionInstruction>;
508
510
  placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;