@drift-labs/sdk-browser 2.104.0-beta.23 → 2.104.0-beta.25

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.104.0-beta.23
1
+ 2.104.0-beta.25
@@ -30,3 +30,4 @@ export declare function getPythPullOraclePublicKey(progarmId: PublicKey, feedId:
30
30
  export declare function getPythLazerOraclePublicKey(progarmId: PublicKey, feedId: number): PublicKey;
31
31
  export declare function getTokenProgramForSpotMarket(spotMarketAccount: SpotMarketAccount): PublicKey;
32
32
  export declare function getHighLeverageModeConfigPublicKey(programId: PublicKey): PublicKey;
33
+ export declare function getProtectedMakerModeConfigPublicKey(programId: PublicKey): PublicKey;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythLazerOraclePublicKey = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSwiftUserAccountPublicKey = exports.getRFQUserAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
26
+ exports.getProtectedMakerModeConfigPublicKey = exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythLazerOraclePublicKey = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSwiftUserAccountPublicKey = exports.getRFQUserAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
27
27
  const web3_js_1 = require("@solana/web3.js");
28
28
  const anchor = __importStar(require("@coral-xyz/anchor"));
29
29
  const spl_token_1 = require("@solana/spl-token");
@@ -209,3 +209,9 @@ function getHighLeverageModeConfigPublicKey(programId) {
209
209
  return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(anchor.utils.bytes.utf8.encode('high_leverage_mode_config'))], programId)[0];
210
210
  }
211
211
  exports.getHighLeverageModeConfigPublicKey = getHighLeverageModeConfigPublicKey;
212
+ function getProtectedMakerModeConfigPublicKey(programId) {
213
+ return web3_js_1.PublicKey.findProgramAddressSync([
214
+ Buffer.from(anchor.utils.bytes.utf8.encode('protected_maker_mode_config')),
215
+ ], programId)[0];
216
+ }
217
+ exports.getProtectedMakerModeConfigPublicKey = getProtectedMakerModeConfigPublicKey;
@@ -203,4 +203,8 @@ export declare class AdminClient extends DriftClient {
203
203
  getInitializeHighLeverageModeConfigIx(maxUsers: number): Promise<TransactionInstruction>;
204
204
  updateUpdateHighLeverageModeConfig(maxUsers: number, reduceOnly: boolean): Promise<TransactionSignature>;
205
205
  getUpdateHighLeverageModeConfigIx(maxUsers: number, reduceOnly: boolean): Promise<TransactionInstruction>;
206
+ initializeProtectedMakerModeConfig(maxUsers: number): Promise<TransactionSignature>;
207
+ getInitializeProtectedMakerModeConfigIx(maxUsers: number): Promise<TransactionInstruction>;
208
+ updateProtectedMakerModeConfig(maxUsers: number, reduceOnly: boolean): Promise<TransactionSignature>;
209
+ getUpdateProtectedMakerModeConfigIx(maxUsers: number, reduceOnly: boolean): Promise<TransactionInstruction>;
206
210
  }
@@ -1854,5 +1854,41 @@ class AdminClient extends driftClient_1.DriftClient {
1854
1854
  },
1855
1855
  });
1856
1856
  }
1857
+ async initializeProtectedMakerModeConfig(maxUsers) {
1858
+ const initializeProtectedMakerModeConfigIx = await this.getInitializeProtectedMakerModeConfigIx(maxUsers);
1859
+ const tx = await this.buildTransaction(initializeProtectedMakerModeConfigIx);
1860
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1861
+ return txSig;
1862
+ }
1863
+ async getInitializeProtectedMakerModeConfigIx(maxUsers) {
1864
+ return await this.program.instruction.initializeProtectedMakerModeConfig(maxUsers, {
1865
+ accounts: {
1866
+ admin: this.isSubscribed
1867
+ ? this.getStateAccount().admin
1868
+ : this.wallet.publicKey,
1869
+ state: await this.getStatePublicKey(),
1870
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
1871
+ systemProgram: anchor.web3.SystemProgram.programId,
1872
+ protectedMakerModeConfig: (0, pda_1.getProtectedMakerModeConfigPublicKey)(this.program.programId),
1873
+ },
1874
+ });
1875
+ }
1876
+ async updateProtectedMakerModeConfig(maxUsers, reduceOnly) {
1877
+ const updateProtectedMakerModeConfigIx = await this.getUpdateProtectedMakerModeConfigIx(maxUsers, reduceOnly);
1878
+ const tx = await this.buildTransaction(updateProtectedMakerModeConfigIx);
1879
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1880
+ return txSig;
1881
+ }
1882
+ async getUpdateProtectedMakerModeConfigIx(maxUsers, reduceOnly) {
1883
+ return await this.program.instruction.updateProtectedMakerModeConfig(maxUsers, reduceOnly, {
1884
+ accounts: {
1885
+ admin: this.isSubscribed
1886
+ ? this.getStateAccount().admin
1887
+ : this.wallet.publicKey,
1888
+ state: await this.getStatePublicKey(),
1889
+ protectedMakerModeConfig: (0, pda_1.getProtectedMakerModeConfigPublicKey)(this.program.programId),
1890
+ },
1891
+ });
1892
+ }
1857
1893
  }
1858
1894
  exports.AdminClient = AdminClient;
@@ -834,6 +834,8 @@ export declare class DriftClient {
834
834
  disableUserHighLeverageMode(user: PublicKey, userAccount?: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
835
835
  getDisableHighLeverageModeIx(user: PublicKey, userAccount?: UserAccount): Promise<TransactionInstruction>;
836
836
  fetchHighLeverageModeConfig(): Promise<HighLeverageModeConfig>;
837
+ updateUserProtectedMakerOrders(subAccountId: number, txParams?: TxParams): Promise<TransactionSignature>;
838
+ getUpdateUserProtectedMakerOrdersIx(subAccountId: number): Promise<TransactionInstruction>;
837
839
  private handleSignedTransaction;
838
840
  private handlePreSignedTransaction;
839
841
  private isVersionedTransaction;
@@ -429,13 +429,17 @@ class DriftClient {
429
429
  userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
430
430
  accountSubscription: this.userStatsAccountSubscriptionConfig,
431
431
  });
432
- await this.userStats.subscribe();
432
+ const subscriptionPromises = [this.userStats.subscribe()];
433
433
  let success = true;
434
434
  if (this.isSubscribed) {
435
- await Promise.all(this.unsubscribeUsers());
436
- this.users.clear();
437
- success = await this.addAndSubscribeToUsers();
435
+ const reSubscribeUsersPromise = async () => {
436
+ await Promise.all(this.unsubscribeUsers());
437
+ this.users.clear();
438
+ success = await this.addAndSubscribeToUsers();
439
+ };
440
+ subscriptionPromises.push(reSubscribeUsersPromise());
438
441
  }
442
+ await Promise.all(subscriptionPromises);
439
443
  return success;
440
444
  }
441
445
  /**
@@ -4684,6 +4688,21 @@ class DriftClient {
4684
4688
  const config = await this.program.account.highLeverageModeConfig.fetch((0, pda_1.getHighLeverageModeConfigPublicKey)(this.program.programId));
4685
4689
  return config;
4686
4690
  }
4691
+ async updateUserProtectedMakerOrders(subAccountId, txParams) {
4692
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateUserProtectedMakerOrdersIx(subAccountId), txParams), [], this.opts);
4693
+ return txSig;
4694
+ }
4695
+ async getUpdateUserProtectedMakerOrdersIx(subAccountId) {
4696
+ const ix = await this.program.instruction.updateUserProtectedMakerOrders(subAccountId, {
4697
+ accounts: {
4698
+ state: await this.getStatePublicKey(),
4699
+ user: (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId),
4700
+ authority: this.wallet.publicKey,
4701
+ protectedMakerModeConfig: (0, pda_1.getProtectedMakerModeConfigPublicKey)(this.program.programId),
4702
+ },
4703
+ });
4704
+ return ix;
4705
+ }
4687
4706
  handleSignedTransaction(signedTxs) {
4688
4707
  if (this.enableMetricsEvents && this.metricsEventEmitter) {
4689
4708
  this.metricsEventEmitter.emit('txSigned', signedTxs);
@@ -30,3 +30,4 @@ export declare function getPythPullOraclePublicKey(progarmId: PublicKey, feedId:
30
30
  export declare function getPythLazerOraclePublicKey(progarmId: PublicKey, feedId: number): PublicKey;
31
31
  export declare function getTokenProgramForSpotMarket(spotMarketAccount: SpotMarketAccount): PublicKey;
32
32
  export declare function getHighLeverageModeConfigPublicKey(programId: PublicKey): PublicKey;
33
+ export declare function getProtectedMakerModeConfigPublicKey(programId: PublicKey): PublicKey;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythLazerOraclePublicKey = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSwiftUserAccountPublicKey = exports.getRFQUserAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
26
+ exports.getProtectedMakerModeConfigPublicKey = exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythLazerOraclePublicKey = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSwiftUserAccountPublicKey = exports.getRFQUserAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
27
27
  const web3_js_1 = require("@solana/web3.js");
28
28
  const anchor = __importStar(require("@coral-xyz/anchor"));
29
29
  const spl_token_1 = require("@solana/spl-token");
@@ -209,3 +209,9 @@ function getHighLeverageModeConfigPublicKey(programId) {
209
209
  return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(anchor.utils.bytes.utf8.encode('high_leverage_mode_config'))], programId)[0];
210
210
  }
211
211
  exports.getHighLeverageModeConfigPublicKey = getHighLeverageModeConfigPublicKey;
212
+ function getProtectedMakerModeConfigPublicKey(programId) {
213
+ return web3_js_1.PublicKey.findProgramAddressSync([
214
+ Buffer.from(anchor.utils.bytes.utf8.encode('protected_maker_mode_config')),
215
+ ], programId)[0];
216
+ }
217
+ exports.getProtectedMakerModeConfigPublicKey = getProtectedMakerModeConfigPublicKey;
@@ -203,4 +203,8 @@ export declare class AdminClient extends DriftClient {
203
203
  getInitializeHighLeverageModeConfigIx(maxUsers: number): Promise<TransactionInstruction>;
204
204
  updateUpdateHighLeverageModeConfig(maxUsers: number, reduceOnly: boolean): Promise<TransactionSignature>;
205
205
  getUpdateHighLeverageModeConfigIx(maxUsers: number, reduceOnly: boolean): Promise<TransactionInstruction>;
206
+ initializeProtectedMakerModeConfig(maxUsers: number): Promise<TransactionSignature>;
207
+ getInitializeProtectedMakerModeConfigIx(maxUsers: number): Promise<TransactionInstruction>;
208
+ updateProtectedMakerModeConfig(maxUsers: number, reduceOnly: boolean): Promise<TransactionSignature>;
209
+ getUpdateProtectedMakerModeConfigIx(maxUsers: number, reduceOnly: boolean): Promise<TransactionInstruction>;
206
210
  }
@@ -1854,5 +1854,41 @@ class AdminClient extends driftClient_1.DriftClient {
1854
1854
  },
1855
1855
  });
1856
1856
  }
1857
+ async initializeProtectedMakerModeConfig(maxUsers) {
1858
+ const initializeProtectedMakerModeConfigIx = await this.getInitializeProtectedMakerModeConfigIx(maxUsers);
1859
+ const tx = await this.buildTransaction(initializeProtectedMakerModeConfigIx);
1860
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1861
+ return txSig;
1862
+ }
1863
+ async getInitializeProtectedMakerModeConfigIx(maxUsers) {
1864
+ return await this.program.instruction.initializeProtectedMakerModeConfig(maxUsers, {
1865
+ accounts: {
1866
+ admin: this.isSubscribed
1867
+ ? this.getStateAccount().admin
1868
+ : this.wallet.publicKey,
1869
+ state: await this.getStatePublicKey(),
1870
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
1871
+ systemProgram: anchor.web3.SystemProgram.programId,
1872
+ protectedMakerModeConfig: (0, pda_1.getProtectedMakerModeConfigPublicKey)(this.program.programId),
1873
+ },
1874
+ });
1875
+ }
1876
+ async updateProtectedMakerModeConfig(maxUsers, reduceOnly) {
1877
+ const updateProtectedMakerModeConfigIx = await this.getUpdateProtectedMakerModeConfigIx(maxUsers, reduceOnly);
1878
+ const tx = await this.buildTransaction(updateProtectedMakerModeConfigIx);
1879
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
1880
+ return txSig;
1881
+ }
1882
+ async getUpdateProtectedMakerModeConfigIx(maxUsers, reduceOnly) {
1883
+ return await this.program.instruction.updateProtectedMakerModeConfig(maxUsers, reduceOnly, {
1884
+ accounts: {
1885
+ admin: this.isSubscribed
1886
+ ? this.getStateAccount().admin
1887
+ : this.wallet.publicKey,
1888
+ state: await this.getStatePublicKey(),
1889
+ protectedMakerModeConfig: (0, pda_1.getProtectedMakerModeConfigPublicKey)(this.program.programId),
1890
+ },
1891
+ });
1892
+ }
1857
1893
  }
1858
1894
  exports.AdminClient = AdminClient;
@@ -834,6 +834,8 @@ export declare class DriftClient {
834
834
  disableUserHighLeverageMode(user: PublicKey, userAccount?: UserAccount, txParams?: TxParams): Promise<TransactionSignature>;
835
835
  getDisableHighLeverageModeIx(user: PublicKey, userAccount?: UserAccount): Promise<TransactionInstruction>;
836
836
  fetchHighLeverageModeConfig(): Promise<HighLeverageModeConfig>;
837
+ updateUserProtectedMakerOrders(subAccountId: number, txParams?: TxParams): Promise<TransactionSignature>;
838
+ getUpdateUserProtectedMakerOrdersIx(subAccountId: number): Promise<TransactionInstruction>;
837
839
  private handleSignedTransaction;
838
840
  private handlePreSignedTransaction;
839
841
  private isVersionedTransaction;
@@ -429,13 +429,17 @@ class DriftClient {
429
429
  userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
430
430
  accountSubscription: this.userStatsAccountSubscriptionConfig,
431
431
  });
432
- await this.userStats.subscribe();
432
+ const subscriptionPromises = [this.userStats.subscribe()];
433
433
  let success = true;
434
434
  if (this.isSubscribed) {
435
- await Promise.all(this.unsubscribeUsers());
436
- this.users.clear();
437
- success = await this.addAndSubscribeToUsers();
435
+ const reSubscribeUsersPromise = async () => {
436
+ await Promise.all(this.unsubscribeUsers());
437
+ this.users.clear();
438
+ success = await this.addAndSubscribeToUsers();
439
+ };
440
+ subscriptionPromises.push(reSubscribeUsersPromise());
438
441
  }
442
+ await Promise.all(subscriptionPromises);
439
443
  return success;
440
444
  }
441
445
  /**
@@ -4684,6 +4688,21 @@ class DriftClient {
4684
4688
  const config = await this.program.account.highLeverageModeConfig.fetch((0, pda_1.getHighLeverageModeConfigPublicKey)(this.program.programId));
4685
4689
  return config;
4686
4690
  }
4691
+ async updateUserProtectedMakerOrders(subAccountId, txParams) {
4692
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateUserProtectedMakerOrdersIx(subAccountId), txParams), [], this.opts);
4693
+ return txSig;
4694
+ }
4695
+ async getUpdateUserProtectedMakerOrdersIx(subAccountId) {
4696
+ const ix = await this.program.instruction.updateUserProtectedMakerOrders(subAccountId, {
4697
+ accounts: {
4698
+ state: await this.getStatePublicKey(),
4699
+ user: (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId),
4700
+ authority: this.wallet.publicKey,
4701
+ protectedMakerModeConfig: (0, pda_1.getProtectedMakerModeConfigPublicKey)(this.program.programId),
4702
+ },
4703
+ });
4704
+ return ix;
4705
+ }
4687
4706
  handleSignedTransaction(signedTxs) {
4688
4707
  if (this.enableMetricsEvents && this.metricsEventEmitter) {
4689
4708
  this.metricsEventEmitter.emit('txSigned', signedTxs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk-browser",
3
- "version": "2.104.0-beta.23",
3
+ "version": "2.104.0-beta.25",
4
4
  "main": "lib/node/index.js",
5
5
  "types": "lib/node/index.d.ts",
6
6
  "browser": "./lib/browser/index.js",
@@ -353,3 +353,16 @@ export function getHighLeverageModeConfigPublicKey(
353
353
  programId
354
354
  )[0];
355
355
  }
356
+
357
+ export function getProtectedMakerModeConfigPublicKey(
358
+ programId: PublicKey
359
+ ): PublicKey {
360
+ return PublicKey.findProgramAddressSync(
361
+ [
362
+ Buffer.from(
363
+ anchor.utils.bytes.utf8.encode('protected_maker_mode_config')
364
+ ),
365
+ ],
366
+ programId
367
+ )[0];
368
+ }
@@ -34,6 +34,7 @@ import {
34
34
  getUserStatsAccountPublicKey,
35
35
  getHighLeverageModeConfigPublicKey,
36
36
  getPythLazerOraclePublicKey,
37
+ getProtectedMakerModeConfigPublicKey,
37
38
  } from './addresses/pda';
38
39
  import { squareRootBN } from './math/utils';
39
40
  import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
@@ -4027,4 +4028,75 @@ export class AdminClient extends DriftClient {
4027
4028
  }
4028
4029
  );
4029
4030
  }
4031
+
4032
+ public async initializeProtectedMakerModeConfig(
4033
+ maxUsers: number
4034
+ ): Promise<TransactionSignature> {
4035
+ const initializeProtectedMakerModeConfigIx =
4036
+ await this.getInitializeProtectedMakerModeConfigIx(maxUsers);
4037
+
4038
+ const tx = await this.buildTransaction(
4039
+ initializeProtectedMakerModeConfigIx
4040
+ );
4041
+
4042
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
4043
+
4044
+ return txSig;
4045
+ }
4046
+
4047
+ public async getInitializeProtectedMakerModeConfigIx(
4048
+ maxUsers: number
4049
+ ): Promise<TransactionInstruction> {
4050
+ return await this.program.instruction.initializeProtectedMakerModeConfig(
4051
+ maxUsers,
4052
+ {
4053
+ accounts: {
4054
+ admin: this.isSubscribed
4055
+ ? this.getStateAccount().admin
4056
+ : this.wallet.publicKey,
4057
+ state: await this.getStatePublicKey(),
4058
+ rent: SYSVAR_RENT_PUBKEY,
4059
+ systemProgram: anchor.web3.SystemProgram.programId,
4060
+ protectedMakerModeConfig: getProtectedMakerModeConfigPublicKey(
4061
+ this.program.programId
4062
+ ),
4063
+ },
4064
+ }
4065
+ );
4066
+ }
4067
+
4068
+ public async updateProtectedMakerModeConfig(
4069
+ maxUsers: number,
4070
+ reduceOnly: boolean
4071
+ ): Promise<TransactionSignature> {
4072
+ const updateProtectedMakerModeConfigIx =
4073
+ await this.getUpdateProtectedMakerModeConfigIx(maxUsers, reduceOnly);
4074
+
4075
+ const tx = await this.buildTransaction(updateProtectedMakerModeConfigIx);
4076
+
4077
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
4078
+
4079
+ return txSig;
4080
+ }
4081
+
4082
+ public async getUpdateProtectedMakerModeConfigIx(
4083
+ maxUsers: number,
4084
+ reduceOnly: boolean
4085
+ ): Promise<TransactionInstruction> {
4086
+ return await this.program.instruction.updateProtectedMakerModeConfig(
4087
+ maxUsers,
4088
+ reduceOnly,
4089
+ {
4090
+ accounts: {
4091
+ admin: this.isSubscribed
4092
+ ? this.getStateAccount().admin
4093
+ : this.wallet.publicKey,
4094
+ state: await this.getStatePublicKey(),
4095
+ protectedMakerModeConfig: getProtectedMakerModeConfigPublicKey(
4096
+ this.program.programId
4097
+ ),
4098
+ },
4099
+ }
4100
+ );
4101
+ }
4030
4102
  }
@@ -93,6 +93,7 @@ import {
93
93
  getOpenbookV2FulfillmentConfigPublicKey,
94
94
  getPerpMarketPublicKey,
95
95
  getPhoenixFulfillmentConfigPublicKey,
96
+ getProtectedMakerModeConfigPublicKey,
96
97
  getPythLazerOraclePublicKey,
97
98
  getPythPullOraclePublicKey,
98
99
  getReferrerNamePublicKeySync,
@@ -776,16 +777,22 @@ export class DriftClient {
776
777
  accountSubscription: this.userStatsAccountSubscriptionConfig,
777
778
  });
778
779
 
779
- await this.userStats.subscribe();
780
+ const subscriptionPromises: Promise<any>[] = [this.userStats.subscribe()];
780
781
 
781
782
  let success = true;
782
783
 
783
784
  if (this.isSubscribed) {
784
- await Promise.all(this.unsubscribeUsers());
785
- this.users.clear();
786
- success = await this.addAndSubscribeToUsers();
785
+ const reSubscribeUsersPromise = async () => {
786
+ await Promise.all(this.unsubscribeUsers());
787
+ this.users.clear();
788
+ success = await this.addAndSubscribeToUsers();
789
+ };
790
+
791
+ subscriptionPromises.push(reSubscribeUsersPromise());
787
792
  }
788
793
 
794
+ await Promise.all(subscriptionPromises);
795
+
789
796
  return success;
790
797
  }
791
798
 
@@ -8890,6 +8897,45 @@ export class DriftClient {
8890
8897
  return config as HighLeverageModeConfig;
8891
8898
  }
8892
8899
 
8900
+ public async updateUserProtectedMakerOrders(
8901
+ subAccountId: number,
8902
+ txParams?: TxParams
8903
+ ): Promise<TransactionSignature> {
8904
+ const { txSig } = await this.sendTransaction(
8905
+ await this.buildTransaction(
8906
+ await this.getUpdateUserProtectedMakerOrdersIx(subAccountId),
8907
+ txParams
8908
+ ),
8909
+ [],
8910
+ this.opts
8911
+ );
8912
+ return txSig;
8913
+ }
8914
+
8915
+ public async getUpdateUserProtectedMakerOrdersIx(
8916
+ subAccountId: number
8917
+ ): Promise<TransactionInstruction> {
8918
+ const ix = await this.program.instruction.updateUserProtectedMakerOrders(
8919
+ subAccountId,
8920
+ {
8921
+ accounts: {
8922
+ state: await this.getStatePublicKey(),
8923
+ user: getUserAccountPublicKeySync(
8924
+ this.program.programId,
8925
+ this.wallet.publicKey,
8926
+ subAccountId
8927
+ ),
8928
+ authority: this.wallet.publicKey,
8929
+ protectedMakerModeConfig: getProtectedMakerModeConfigPublicKey(
8930
+ this.program.programId
8931
+ ),
8932
+ },
8933
+ }
8934
+ );
8935
+
8936
+ return ix;
8937
+ }
8938
+
8893
8939
  private handleSignedTransaction(signedTxs: SignedTxData[]) {
8894
8940
  if (this.enableMetricsEvents && this.metricsEventEmitter) {
8895
8941
  this.metricsEventEmitter.emit('txSigned', signedTxs);