@drift-labs/sdk-browser 2.104.0-beta.29 → 2.104.0-beta.31

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.29
1
+ 2.104.0-beta.31
@@ -244,6 +244,7 @@ class PollingDriftClientAccountSubscriber {
244
244
  this.accountsToPoll.clear();
245
245
  this.oraclesToPoll.clear();
246
246
  this.isSubscribed = false;
247
+ this.accountLoader.accountsToLoad = new Map();
247
248
  }
248
249
  async addSpotMarket(marketIndex) {
249
250
  const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
@@ -195,16 +195,16 @@ export declare class AdminClient extends DriftClient {
195
195
  getUpdatePerpMarketFuelIx(perpMarketIndex: number, fuelBoostTaker?: number, fuelBoostMaker?: number, fuelBoostPosition?: number): Promise<TransactionInstruction>;
196
196
  initUserFuel(user: PublicKey, authority: PublicKey, fuelBonusDeposits?: number, fuelBonusBorrows?: number, fuelBonusTaker?: number, fuelBonusMaker?: number, fuelBonusInsurance?: number): Promise<TransactionSignature>;
197
197
  getInitUserFuelIx(user: PublicKey, authority: PublicKey, fuelBonusDeposits?: number, fuelBonusBorrows?: number, fuelBonusTaker?: number, fuelBonusMaker?: number, fuelBonusInsurance?: number): Promise<TransactionInstruction>;
198
- initializePythPullOracle(feedId: string, isAdmin?: boolean): Promise<TransactionSignature>;
199
- getInitializePythPullOracleIx(feedId: string, isAdmin?: boolean): Promise<TransactionInstruction>;
200
- initializePythLazerOracle(feedId: number, isAdmin?: boolean): Promise<TransactionSignature>;
201
- getInitializePythLazerOracleIx(feedId: number, isAdmin?: boolean): Promise<TransactionInstruction>;
198
+ initializePythPullOracle(feedId: string): Promise<TransactionSignature>;
199
+ getInitializePythPullOracleIx(feedId: string): Promise<TransactionInstruction>;
200
+ initializePythLazerOracle(feedId: number): Promise<TransactionSignature>;
201
+ getInitializePythLazerOracleIx(feedId: number): Promise<TransactionInstruction>;
202
202
  initializeHighLeverageModeConfig(maxUsers: number): Promise<TransactionSignature>;
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>;
206
+ initializeProtectedMakerModeConfig(maxUsers: number, stateAdmin?: boolean): Promise<TransactionSignature>;
207
+ getInitializeProtectedMakerModeConfigIx(maxUsers: number, stateAdmin?: boolean): Promise<TransactionInstruction>;
208
208
  updateProtectedMakerModeConfig(maxUsers: number, reduceOnly: boolean): Promise<TransactionSignature>;
209
209
  getUpdateProtectedMakerModeConfigIx(maxUsers: number, reduceOnly: boolean): Promise<TransactionInstruction>;
210
210
  }
@@ -463,7 +463,9 @@ class AdminClient extends driftClient_1.DriftClient {
463
463
  const tokenProgram = this.getTokenProgramForSpotMarket(spotMarket);
464
464
  return await this.program.instruction.depositIntoSpotMarketVault(amount, {
465
465
  accounts: {
466
- admin: this.wallet.publicKey,
466
+ admin: this.useHotWalletAdmin
467
+ ? this.wallet.publicKey
468
+ : this.getStateAccount().admin,
467
469
  state: await this.getStatePublicKey(),
468
470
  sourceVault,
469
471
  spotMarket: spotMarket.pubkey,
@@ -525,7 +527,9 @@ class AdminClient extends driftClient_1.DriftClient {
525
527
  netUnsettledFundingPnl: netUnsettledFundingPnl !== null && netUnsettledFundingPnl !== void 0 ? netUnsettledFundingPnl : null,
526
528
  }, {
527
529
  accounts: {
528
- admin: this.wallet.publicKey,
530
+ admin: this.useHotWalletAdmin
531
+ ? this.wallet.publicKey
532
+ : this.getStateAccount().admin,
529
533
  state: await this.getStatePublicKey(),
530
534
  perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
531
535
  spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, numericConstants_1.QUOTE_SPOT_MARKET_INDEX),
@@ -1776,24 +1780,28 @@ class AdminClient extends driftClient_1.DriftClient {
1776
1780
  const userStats = await (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, authority);
1777
1781
  return await this.program.instruction.initUserFuel(fuelBonusDeposits || null, fuelBonusBorrows || null, fuelBonusTaker || null, fuelBonusMaker || null, fuelBonusInsurance || null, {
1778
1782
  accounts: {
1779
- admin: this.wallet.publicKey,
1783
+ admin: this.useHotWalletAdmin
1784
+ ? this.wallet.publicKey
1785
+ : this.getStateAccount().admin,
1780
1786
  state: await this.getStatePublicKey(),
1781
1787
  user,
1782
1788
  userStats,
1783
1789
  },
1784
1790
  });
1785
1791
  }
1786
- async initializePythPullOracle(feedId, isAdmin = false) {
1787
- const initializePythPullOracleIx = await this.getInitializePythPullOracleIx(feedId, isAdmin);
1792
+ async initializePythPullOracle(feedId) {
1793
+ const initializePythPullOracleIx = await this.getInitializePythPullOracleIx(feedId);
1788
1794
  const tx = await this.buildTransaction(initializePythPullOracleIx);
1789
1795
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
1790
1796
  return txSig;
1791
1797
  }
1792
- async getInitializePythPullOracleIx(feedId, isAdmin = false) {
1798
+ async getInitializePythPullOracleIx(feedId) {
1793
1799
  const feedIdBuffer = (0, pythOracleUtils_1.getFeedIdUint8Array)(feedId);
1794
1800
  return await this.program.instruction.initializePythPullOracle(feedIdBuffer, {
1795
1801
  accounts: {
1796
- admin: isAdmin ? this.getStateAccount().admin : this.wallet.publicKey,
1802
+ admin: this.useHotWalletAdmin
1803
+ ? this.wallet.publicKey
1804
+ : this.getStateAccount().admin,
1797
1805
  state: await this.getStatePublicKey(),
1798
1806
  systemProgram: web3_js_1.SystemProgram.programId,
1799
1807
  priceFeed: (0, pda_1.getPythPullOraclePublicKey)(this.program.programId, feedIdBuffer),
@@ -1801,16 +1809,18 @@ class AdminClient extends driftClient_1.DriftClient {
1801
1809
  },
1802
1810
  });
1803
1811
  }
1804
- async initializePythLazerOracle(feedId, isAdmin = false) {
1805
- const initializePythPullOracleIx = await this.getInitializePythLazerOracleIx(feedId, isAdmin);
1812
+ async initializePythLazerOracle(feedId) {
1813
+ const initializePythPullOracleIx = await this.getInitializePythLazerOracleIx(feedId);
1806
1814
  const tx = await this.buildTransaction(initializePythPullOracleIx);
1807
1815
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
1808
1816
  return txSig;
1809
1817
  }
1810
- async getInitializePythLazerOracleIx(feedId, isAdmin = false) {
1818
+ async getInitializePythLazerOracleIx(feedId) {
1811
1819
  return await this.program.instruction.initializePythLazerOracle(feedId, {
1812
1820
  accounts: {
1813
- admin: isAdmin ? this.getStateAccount().admin : this.wallet.publicKey,
1821
+ admin: this.useHotWalletAdmin
1822
+ ? this.wallet.publicKey
1823
+ : this.getStateAccount().admin,
1814
1824
  state: await this.getStatePublicKey(),
1815
1825
  systemProgram: web3_js_1.SystemProgram.programId,
1816
1826
  lazerOracle: (0, pda_1.getPythLazerOraclePublicKey)(this.program.programId, feedId),
@@ -1854,16 +1864,16 @@ class AdminClient extends driftClient_1.DriftClient {
1854
1864
  },
1855
1865
  });
1856
1866
  }
1857
- async initializeProtectedMakerModeConfig(maxUsers) {
1858
- const initializeProtectedMakerModeConfigIx = await this.getInitializeProtectedMakerModeConfigIx(maxUsers);
1867
+ async initializeProtectedMakerModeConfig(maxUsers, stateAdmin) {
1868
+ const initializeProtectedMakerModeConfigIx = await this.getInitializeProtectedMakerModeConfigIx(maxUsers, stateAdmin);
1859
1869
  const tx = await this.buildTransaction(initializeProtectedMakerModeConfigIx);
1860
1870
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
1861
1871
  return txSig;
1862
1872
  }
1863
- async getInitializeProtectedMakerModeConfigIx(maxUsers) {
1873
+ async getInitializeProtectedMakerModeConfigIx(maxUsers, stateAdmin) {
1864
1874
  return await this.program.instruction.initializeProtectedMakerModeConfig(maxUsers, {
1865
1875
  accounts: {
1866
- admin: this.isSubscribed
1876
+ admin: stateAdmin
1867
1877
  ? this.getStateAccount().admin
1868
1878
  : this.wallet.publicKey,
1869
1879
  state: await this.getStatePublicKey(),
@@ -42,6 +42,7 @@ export declare class DriftClient {
42
42
  program: Program;
43
43
  provider: AnchorProvider;
44
44
  opts?: ConfirmOptions;
45
+ useHotWalletAdmin?: boolean;
45
46
  users: Map<string, User>;
46
47
  userStats?: UserStats;
47
48
  activeSubAccountId: number;
@@ -280,11 +281,11 @@ export declare class DriftClient {
280
281
  getTokenProgramForSpotMarket(spotMarketAccount: SpotMarketAccount): PublicKey;
281
282
  addTokenMintToRemainingAccounts(spotMarketAccount: SpotMarketAccount, remainingAccounts: AccountMeta[]): void;
282
283
  getAssociatedTokenAccountCreationIx(tokenMintAddress: PublicKey, associatedTokenAddress: PublicKey, tokenProgram: PublicKey): anchor.web3.TransactionInstruction;
283
- createInitializeUserAccountAndDepositCollateralIxs(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, donateAmount?: BN, customMaxMarginRatio?: number): Promise<{
284
+ createInitializeUserAccountAndDepositCollateralIxs(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, donateAmount?: BN, customMaxMarginRatio?: number, poolId?: number): Promise<{
284
285
  ixs: TransactionInstruction[];
285
286
  userAccountPublicKey: PublicKey;
286
287
  }>;
287
- createInitializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, donateAmount?: BN, txParams?: TxParams, customMaxMarginRatio?: number): Promise<[Transaction | VersionedTransaction, PublicKey]>;
288
+ createInitializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, donateAmount?: BN, txParams?: TxParams, customMaxMarginRatio?: number, poolId?: number): Promise<[Transaction | VersionedTransaction, PublicKey]>;
288
289
  /**
289
290
  * Creates the User account for a user, and deposits some initial collateral
290
291
  * @param amount
@@ -298,7 +299,7 @@ export declare class DriftClient {
298
299
  * @param txParams
299
300
  * @returns
300
301
  */
301
- initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, donateAmount?: BN, txParams?: TxParams, customMaxMarginRatio?: number): Promise<[TransactionSignature, PublicKey]>;
302
+ initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo, donateAmount?: BN, txParams?: TxParams, customMaxMarginRatio?: number, poolId?: number): Promise<[TransactionSignature, PublicKey]>;
302
303
  initializeUserAccountForDevnet(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
303
304
  getWithdrawalIxs(amount: BN, marketIndex: number, associatedTokenAddress: PublicKey, reduceOnly?: boolean, subAccountId?: number, updateFuel?: boolean): Promise<TransactionInstruction[]>;
304
305
  /**
@@ -83,7 +83,7 @@ class DriftClient {
83
83
  this._isSubscribed = val;
84
84
  }
85
85
  constructor(config) {
86
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19;
86
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20;
87
87
  this.users = new Map();
88
88
  this._isSubscribed = false;
89
89
  this.perpMarketLastSlotCache = new Map();
@@ -95,7 +95,8 @@ class DriftClient {
95
95
  this.opts = config.opts || {
96
96
  ...config_1.DEFAULT_CONFIRMATION_OPTS,
97
97
  };
98
- if ((_a = config === null || config === void 0 ? void 0 : config.connection) === null || _a === void 0 ? void 0 : _a.commitment) {
98
+ this.useHotWalletAdmin = (_a = config.useHotWalletAdmin) !== null && _a !== void 0 ? _a : false;
99
+ if ((_b = config === null || config === void 0 ? void 0 : config.connection) === null || _b === void 0 ? void 0 : _b.commitment) {
99
100
  // At the moment this ensures that our transaction simulations (which use Connection object) will use the same commitment level as our Transaction blockhashes (which use these opts)
100
101
  this.opts.commitment = config.connection.commitment;
101
102
  this.opts.preflightCommitment = config.connection.commitment;
@@ -103,17 +104,17 @@ class DriftClient {
103
104
  this.provider = new anchor_1.AnchorProvider(config.connection,
104
105
  // @ts-ignore
105
106
  config.wallet, this.opts);
106
- this.program = new anchor_1.Program(drift_json_1.default, (_b = config.programID) !== null && _b !== void 0 ? _b : new web3_js_1.PublicKey(config_1.DRIFT_PROGRAM_ID), this.provider);
107
- this.authority = (_c = config.authority) !== null && _c !== void 0 ? _c : this.wallet.publicKey;
108
- this.activeSubAccountId = (_d = config.activeSubAccountId) !== null && _d !== void 0 ? _d : 0;
109
- this.skipLoadUsers = (_e = config.skipLoadUsers) !== null && _e !== void 0 ? _e : false;
110
- this.txVersion = (_f = config.txVersion) !== null && _f !== void 0 ? _f : 'legacy';
107
+ this.program = new anchor_1.Program(drift_json_1.default, (_c = config.programID) !== null && _c !== void 0 ? _c : new web3_js_1.PublicKey(config_1.DRIFT_PROGRAM_ID), this.provider);
108
+ this.authority = (_d = config.authority) !== null && _d !== void 0 ? _d : this.wallet.publicKey;
109
+ this.activeSubAccountId = (_e = config.activeSubAccountId) !== null && _e !== void 0 ? _e : 0;
110
+ this.skipLoadUsers = (_f = config.skipLoadUsers) !== null && _f !== void 0 ? _f : false;
111
+ this.txVersion = (_g = config.txVersion) !== null && _g !== void 0 ? _g : 'legacy';
111
112
  this.txParams = {
112
- computeUnits: (_h = (_g = config.txParams) === null || _g === void 0 ? void 0 : _g.computeUnits) !== null && _h !== void 0 ? _h : 600000,
113
- computeUnitsPrice: (_k = (_j = config.txParams) === null || _j === void 0 ? void 0 : _j.computeUnitsPrice) !== null && _k !== void 0 ? _k : 0,
113
+ computeUnits: (_j = (_h = config.txParams) === null || _h === void 0 ? void 0 : _h.computeUnits) !== null && _j !== void 0 ? _j : 600000,
114
+ computeUnitsPrice: (_l = (_k = config.txParams) === null || _k === void 0 ? void 0 : _k.computeUnitsPrice) !== null && _l !== void 0 ? _l : 0,
114
115
  };
115
116
  this.txHandler =
116
- (_l = config === null || config === void 0 ? void 0 : config.txHandler) !== null && _l !== void 0 ? _l : new txHandler_1.TxHandler({
117
+ (_m = config === null || config === void 0 ? void 0 : config.txHandler) !== null && _m !== void 0 ? _m : new txHandler_1.TxHandler({
117
118
  connection: this.connection,
118
119
  // @ts-ignore
119
120
  wallet: this.provider.wallet,
@@ -139,8 +140,8 @@ class DriftClient {
139
140
  : config.subAccountIds
140
141
  ? new Map([[this.authority.toString(), config.subAccountIds]])
141
142
  : new Map();
142
- this.includeDelegates = (_m = config.includeDelegates) !== null && _m !== void 0 ? _m : false;
143
- if (((_o = config.accountSubscription) === null || _o === void 0 ? void 0 : _o.type) === 'polling') {
143
+ this.includeDelegates = (_o = config.includeDelegates) !== null && _o !== void 0 ? _o : false;
144
+ if (((_p = config.accountSubscription) === null || _p === void 0 ? void 0 : _p.type) === 'polling') {
144
145
  this.userAccountSubscriptionConfig = {
145
146
  type: 'polling',
146
147
  accountLoader: config.accountSubscription.accountLoader,
@@ -150,32 +151,32 @@ class DriftClient {
150
151
  accountLoader: config.accountSubscription.accountLoader,
151
152
  };
152
153
  }
153
- else if (((_p = config.accountSubscription) === null || _p === void 0 ? void 0 : _p.type) === 'grpc') {
154
+ else if (((_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.type) === 'grpc') {
154
155
  this.userAccountSubscriptionConfig = {
155
156
  type: 'grpc',
156
- resubTimeoutMs: (_q = config.accountSubscription) === null || _q === void 0 ? void 0 : _q.resubTimeoutMs,
157
- logResubMessages: (_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.logResubMessages,
158
- grpcConfigs: (_s = config.accountSubscription) === null || _s === void 0 ? void 0 : _s.grpcConfigs,
157
+ resubTimeoutMs: (_r = config.accountSubscription) === null || _r === void 0 ? void 0 : _r.resubTimeoutMs,
158
+ logResubMessages: (_s = config.accountSubscription) === null || _s === void 0 ? void 0 : _s.logResubMessages,
159
+ grpcConfigs: (_t = config.accountSubscription) === null || _t === void 0 ? void 0 : _t.grpcConfigs,
159
160
  };
160
161
  this.userStatsAccountSubscriptionConfig = {
161
162
  type: 'grpc',
162
- grpcConfigs: (_t = config.accountSubscription) === null || _t === void 0 ? void 0 : _t.grpcConfigs,
163
- resubTimeoutMs: (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.resubTimeoutMs,
164
- logResubMessages: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.logResubMessages,
163
+ grpcConfigs: (_u = config.accountSubscription) === null || _u === void 0 ? void 0 : _u.grpcConfigs,
164
+ resubTimeoutMs: (_v = config.accountSubscription) === null || _v === void 0 ? void 0 : _v.resubTimeoutMs,
165
+ logResubMessages: (_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.logResubMessages,
165
166
  };
166
167
  }
167
168
  else {
168
169
  this.userAccountSubscriptionConfig = {
169
170
  type: 'websocket',
170
- resubTimeoutMs: (_w = config.accountSubscription) === null || _w === void 0 ? void 0 : _w.resubTimeoutMs,
171
- logResubMessages: (_x = config.accountSubscription) === null || _x === void 0 ? void 0 : _x.logResubMessages,
172
- commitment: (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.commitment,
171
+ resubTimeoutMs: (_x = config.accountSubscription) === null || _x === void 0 ? void 0 : _x.resubTimeoutMs,
172
+ logResubMessages: (_y = config.accountSubscription) === null || _y === void 0 ? void 0 : _y.logResubMessages,
173
+ commitment: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.commitment,
173
174
  };
174
175
  this.userStatsAccountSubscriptionConfig = {
175
176
  type: 'websocket',
176
- resubTimeoutMs: (_z = config.accountSubscription) === null || _z === void 0 ? void 0 : _z.resubTimeoutMs,
177
- logResubMessages: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.logResubMessages,
178
- commitment: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.commitment,
177
+ resubTimeoutMs: (_0 = config.accountSubscription) === null || _0 === void 0 ? void 0 : _0.resubTimeoutMs,
178
+ logResubMessages: (_1 = config.accountSubscription) === null || _1 === void 0 ? void 0 : _1.logResubMessages,
179
+ commitment: (_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.commitment,
179
180
  };
180
181
  }
181
182
  if (config.userStats) {
@@ -193,20 +194,20 @@ class DriftClient {
193
194
  const noMarketsAndOraclesSpecified = config.perpMarketIndexes === undefined &&
194
195
  config.spotMarketIndexes === undefined &&
195
196
  config.oracleInfos === undefined;
196
- if (((_2 = config.accountSubscription) === null || _2 === void 0 ? void 0 : _2.type) === 'polling') {
197
- this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_3 = config.perpMarketIndexes) !== null && _3 !== void 0 ? _3 : [], (_4 = config.spotMarketIndexes) !== null && _4 !== void 0 ? _4 : [], (_5 = config.oracleInfos) !== null && _5 !== void 0 ? _5 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
197
+ if (((_3 = config.accountSubscription) === null || _3 === void 0 ? void 0 : _3.type) === 'polling') {
198
+ this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, (_4 = config.perpMarketIndexes) !== null && _4 !== void 0 ? _4 : [], (_5 = config.spotMarketIndexes) !== null && _5 !== void 0 ? _5 : [], (_6 = config.oracleInfos) !== null && _6 !== void 0 ? _6 : [], noMarketsAndOraclesSpecified, delistedMarketSetting);
198
199
  }
199
- else if (((_6 = config.accountSubscription) === null || _6 === void 0 ? void 0 : _6.type) === 'grpc') {
200
- this.accountSubscriber = new grpcDriftClientAccountSubscriber_1.gprcDriftClientAccountSubscriber(config.accountSubscription.grpcConfigs, this.program, (_7 = config.perpMarketIndexes) !== null && _7 !== void 0 ? _7 : [], (_8 = config.spotMarketIndexes) !== null && _8 !== void 0 ? _8 : [], (_9 = config.oracleInfos) !== null && _9 !== void 0 ? _9 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
201
- resubTimeoutMs: (_10 = config.accountSubscription) === null || _10 === void 0 ? void 0 : _10.resubTimeoutMs,
202
- logResubMessages: (_11 = config.accountSubscription) === null || _11 === void 0 ? void 0 : _11.logResubMessages,
200
+ else if (((_7 = config.accountSubscription) === null || _7 === void 0 ? void 0 : _7.type) === 'grpc') {
201
+ this.accountSubscriber = new grpcDriftClientAccountSubscriber_1.gprcDriftClientAccountSubscriber(config.accountSubscription.grpcConfigs, this.program, (_8 = config.perpMarketIndexes) !== null && _8 !== void 0 ? _8 : [], (_9 = config.spotMarketIndexes) !== null && _9 !== void 0 ? _9 : [], (_10 = config.oracleInfos) !== null && _10 !== void 0 ? _10 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
202
+ resubTimeoutMs: (_11 = config.accountSubscription) === null || _11 === void 0 ? void 0 : _11.resubTimeoutMs,
203
+ logResubMessages: (_12 = config.accountSubscription) === null || _12 === void 0 ? void 0 : _12.logResubMessages,
203
204
  });
204
205
  }
205
206
  else {
206
- this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_12 = config.perpMarketIndexes) !== null && _12 !== void 0 ? _12 : [], (_13 = config.spotMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.oracleInfos) !== null && _14 !== void 0 ? _14 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
207
- resubTimeoutMs: (_15 = config.accountSubscription) === null || _15 === void 0 ? void 0 : _15.resubTimeoutMs,
208
- logResubMessages: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.logResubMessages,
209
- }, (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.commitment);
207
+ this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, (_13 = config.perpMarketIndexes) !== null && _13 !== void 0 ? _13 : [], (_14 = config.spotMarketIndexes) !== null && _14 !== void 0 ? _14 : [], (_15 = config.oracleInfos) !== null && _15 !== void 0 ? _15 : [], noMarketsAndOraclesSpecified, delistedMarketSetting, {
208
+ resubTimeoutMs: (_16 = config.accountSubscription) === null || _16 === void 0 ? void 0 : _16.resubTimeoutMs,
209
+ logResubMessages: (_17 = config.accountSubscription) === null || _17 === void 0 ? void 0 : _17.logResubMessages,
210
+ }, (_18 = config.accountSubscription) === null || _18 === void 0 ? void 0 : _18.commitment);
210
211
  }
211
212
  this.eventEmitter = this.accountSubscriber.eventEmitter;
212
213
  this.metricsEventEmitter = new events_1.EventEmitter();
@@ -214,14 +215,14 @@ class DriftClient {
214
215
  this.enableMetricsEvents = true;
215
216
  }
216
217
  this.txSender =
217
- (_18 = config.txSender) !== null && _18 !== void 0 ? _18 : new retryTxSender_1.RetryTxSender({
218
+ (_19 = config.txSender) !== null && _19 !== void 0 ? _19 : new retryTxSender_1.RetryTxSender({
218
219
  connection: this.connection,
219
220
  wallet: this.wallet,
220
221
  opts: this.opts,
221
222
  txHandler: this.txHandler,
222
223
  });
223
224
  this.sbOnDemandProgramdId =
224
- config_1.configs[(_19 = config.env) !== null && _19 !== void 0 ? _19 : 'mainnet-beta'].SB_ON_DEMAND_PID;
225
+ config_1.configs[(_20 = config.env) !== null && _20 !== void 0 ? _20 : 'mainnet-beta'].SB_ON_DEMAND_PID;
225
226
  }
226
227
  getUserMapKey(subAccountId, authority) {
227
228
  return `${subAccountId}_${authority.toString()}`;
@@ -1439,7 +1440,7 @@ class DriftClient {
1439
1440
  getAssociatedTokenAccountCreationIx(tokenMintAddress, associatedTokenAddress, tokenProgram) {
1440
1441
  return (0, spl_token_1.createAssociatedTokenAccountInstruction)(this.wallet.publicKey, associatedTokenAddress, this.wallet.publicKey, tokenMintAddress, tokenProgram);
1441
1442
  }
1442
- async createInitializeUserAccountAndDepositCollateralIxs(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name, fromSubAccountId, referrerInfo, donateAmount, customMaxMarginRatio) {
1443
+ async createInitializeUserAccountAndDepositCollateralIxs(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name, fromSubAccountId, referrerInfo, donateAmount, customMaxMarginRatio, poolId) {
1443
1444
  const ixs = [];
1444
1445
  const [userAccountPublicKey, initializeUserAccountIx] = await this.getInitializeUserInstructions(subAccountId, name, referrerInfo);
1445
1446
  const spotMarket = this.getSpotMarketAccount(marketIndex);
@@ -1471,7 +1472,11 @@ class DriftClient {
1471
1472
  ixs.push(await this.getInitializeUserStatsIx());
1472
1473
  }
1473
1474
  }
1474
- ixs.push(initializeUserAccountIx, depositCollateralIx);
1475
+ ixs.push(initializeUserAccountIx);
1476
+ if (poolId) {
1477
+ ixs.push(await this.getUpdateUserPoolIdIx(poolId, subAccountId));
1478
+ }
1479
+ ixs.push(depositCollateralIx);
1475
1480
  if (!donateAmount.eq(numericConstants_1.ZERO)) {
1476
1481
  const donateIx = await this.getDepositIntoSpotMarketRevenuePoolIx(1, donateAmount, wsolTokenAccount);
1477
1482
  ixs.push(donateIx);
@@ -1490,8 +1495,8 @@ class DriftClient {
1490
1495
  userAccountPublicKey,
1491
1496
  };
1492
1497
  }
1493
- async createInitializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name, fromSubAccountId, referrerInfo, donateAmount, txParams, customMaxMarginRatio) {
1494
- const { ixs, userAccountPublicKey } = await this.createInitializeUserAccountAndDepositCollateralIxs(amount, userTokenAccount, marketIndex, subAccountId, name, fromSubAccountId, referrerInfo, donateAmount, customMaxMarginRatio);
1498
+ async createInitializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name, fromSubAccountId, referrerInfo, donateAmount, txParams, customMaxMarginRatio, poolId) {
1499
+ const { ixs, userAccountPublicKey } = await this.createInitializeUserAccountAndDepositCollateralIxs(amount, userTokenAccount, marketIndex, subAccountId, name, fromSubAccountId, referrerInfo, donateAmount, customMaxMarginRatio, poolId);
1495
1500
  const tx = await this.buildTransaction(ixs, txParams);
1496
1501
  return [tx, userAccountPublicKey];
1497
1502
  }
@@ -1508,8 +1513,8 @@ class DriftClient {
1508
1513
  * @param txParams
1509
1514
  * @returns
1510
1515
  */
1511
- async initializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name, fromSubAccountId, referrerInfo, donateAmount, txParams, customMaxMarginRatio) {
1512
- const [tx, userAccountPublicKey] = await this.createInitializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex, subAccountId, name, fromSubAccountId, referrerInfo, donateAmount, txParams, customMaxMarginRatio);
1516
+ async initializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name, fromSubAccountId, referrerInfo, donateAmount, txParams, customMaxMarginRatio, poolId) {
1517
+ const [tx, userAccountPublicKey] = await this.createInitializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex, subAccountId, name, fromSubAccountId, referrerInfo, donateAmount, txParams, customMaxMarginRatio, poolId);
1513
1518
  const additionalSigners = [];
1514
1519
  const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
1515
1520
  this.spotMarketLastSlotCache.set(marketIndex, slot);
@@ -4505,8 +4510,7 @@ class DriftClient {
4505
4510
  }
4506
4511
  getPostPythLazerOracleUpdateIxs(feedIds, pythMessageHex, precedingIxs = [], overrideIxCount) {
4507
4512
  const pythMessageBytes = Buffer.from(pythMessageHex, 'hex');
4508
- const updateData = new Uint8Array(pythMessageBytes);
4509
- const verifyIx = (0, pythOracleUtils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 0, updateData);
4513
+ const verifyIx = (0, pythOracleUtils_1.createMinimalEd25519VerifyIx)(overrideIxCount || precedingIxs.length + 1, 12, pythMessageBytes);
4510
4514
  const remainingAccountsMeta = feedIds.map((feedId) => {
4511
4515
  return {
4512
4516
  pubkey: (0, pda_1.getPythLazerOraclePublicKey)(this.program.programId, feedId),
@@ -31,6 +31,7 @@ export type DriftClientConfig = {
31
31
  enableMetricsEvents?: boolean;
32
32
  txHandlerConfig?: TxHandlerConfig;
33
33
  delistedMarketSetting?: DelistedMarketSetting;
34
+ useHotWalletAdmin?: boolean;
34
35
  };
35
36
  export type DriftClientSubscriptionConfig = {
36
37
  type: 'grpc';
@@ -14315,7 +14315,7 @@
14315
14315
  {
14316
14316
  "code": 6288,
14317
14317
  "name": "InvalidSwiftOrderParam",
14318
- "msg": "Swift only available for market/oracle perp orders"
14318
+ "msg": "Invalid swift order param"
14319
14319
  },
14320
14320
  {
14321
14321
  "code": 6289,
@@ -1,10 +1,11 @@
1
1
  import { TransactionInstruction } from '@solana/web3.js';
2
2
  export declare function trimFeedId(feedId: string): string;
3
3
  export declare function getFeedIdUint8Array(feedId: string): Uint8Array;
4
- export declare function getEd25519ArgsFromHex(hex: string): {
4
+ export declare function getEd25519ArgsFromHex(hex: string, customInstructionIndex?: number): {
5
5
  publicKey: Uint8Array;
6
6
  signature: Uint8Array;
7
7
  message: Uint8Array;
8
+ instructionIndex?: number;
8
9
  };
9
10
  /**
10
11
  * Constructs a minimal Ed25519 verification instruction that references the data
@@ -1,7 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.createMinimalEd25519VerifyIx = exports.getEd25519ArgsFromHex = exports.getFeedIdUint8Array = exports.trimFeedId = void 0;
4
27
  const web3_js_1 = require("@solana/web3.js");
28
+ const BufferLayout = __importStar(require("@solana/buffer-layout"));
5
29
  function trimFeedId(feedId) {
6
30
  if (feedId.startsWith('0x')) {
7
31
  return feedId.slice(2);
@@ -18,7 +42,7 @@ const SIGNATURE_LEN = 64;
18
42
  const PUBKEY_LEN = 32;
19
43
  const MAGIC_LEN = 4;
20
44
  const MESSAGE_SIZE_LEN = 2;
21
- function getEd25519ArgsFromHex(hex) {
45
+ function getEd25519ArgsFromHex(hex, customInstructionIndex) {
22
46
  const cleanedHex = hex.startsWith('0x') ? hex.slice(2) : hex;
23
47
  const buffer = new Uint8Array(Buffer.from(cleanedHex, 'hex'));
24
48
  const signatureOffset = MAGIC_LEN;
@@ -39,9 +63,24 @@ function getEd25519ArgsFromHex(hex) {
39
63
  publicKey,
40
64
  signature,
41
65
  message,
66
+ instructionIndex: customInstructionIndex,
42
67
  };
43
68
  }
44
69
  exports.getEd25519ArgsFromHex = getEd25519ArgsFromHex;
70
+ const readUint16LE = (data, offset) => {
71
+ return data[offset] | (data[offset + 1] << 8);
72
+ };
73
+ const ED25519_INSTRUCTION_LAYOUT = BufferLayout.struct([
74
+ BufferLayout.u8('numSignatures'),
75
+ BufferLayout.u8('padding'),
76
+ BufferLayout.u16('signatureOffset'),
77
+ BufferLayout.u16('signatureInstructionIndex'),
78
+ BufferLayout.u16('publicKeyOffset'),
79
+ BufferLayout.u16('publicKeyInstructionIndex'),
80
+ BufferLayout.u16('messageDataOffset'),
81
+ BufferLayout.u16('messageDataSize'),
82
+ BufferLayout.u16('messageInstructionIndex'),
83
+ ]);
45
84
  /**
46
85
  * Constructs a minimal Ed25519 verification instruction that references the data
47
86
  * inside the main instruction (postPythLazerOracleUpdate).
@@ -55,53 +94,23 @@ function createMinimalEd25519VerifyIx(customInstructionIndex, messageOffset, cus
55
94
  const publicKeyOffset = signatureOffset + SIGNATURE_LEN;
56
95
  const messageDataSizeOffset = publicKeyOffset + PUBKEY_LEN;
57
96
  const messageDataOffset = messageDataSizeOffset + MESSAGE_SIZE_LEN;
58
- if (messageDataOffset > customInstructionData.length) {
59
- throw new Error('Not enough data in main instruction to read message size');
60
- }
61
- const messageSize = customInstructionData[messageDataSizeOffset] |
62
- (customInstructionData[messageDataSizeOffset + 1] << 8);
63
- // Construct Ed25519SignatureOffsets
64
- // struct Ed25519SignatureOffsets (14 bytes):
65
- // u16 signature_offset
66
- // u16 signature_instruction_index
67
- // u16 public_key_offset
68
- // u16 public_key_instruction_index
69
- // u16 message_data_offset
70
- // u16 message_data_size
71
- // u16 message_instruction_index
72
- const offsets = new Uint8Array(14);
73
- const dv = new DataView(offsets.buffer);
74
- let byteOffset = 0;
75
- dv.setUint16(byteOffset, signatureOffset, true);
76
- byteOffset += 2;
77
- dv.setUint16(byteOffset, customInstructionIndex, true);
78
- byteOffset += 2;
79
- dv.setUint16(byteOffset, publicKeyOffset, true);
80
- byteOffset += 2;
81
- dv.setUint16(byteOffset, customInstructionIndex, true);
82
- byteOffset += 2;
83
- dv.setUint16(byteOffset, messageDataOffset, true);
84
- byteOffset += 2;
85
- dv.setUint16(byteOffset, messageSize, true);
86
- byteOffset += 2;
87
- dv.setUint16(byteOffset, customInstructionIndex, true);
88
- byteOffset += 2;
89
- const numSignatures = 1;
90
- const padding = 0;
91
- const ixData = new Uint8Array(2 + offsets.length);
92
- ixData[0] = numSignatures;
93
- ixData[1] = padding;
94
- ixData.set(offsets, 2);
97
+ const messageDataSize = readUint16LE(customInstructionData, messageDataSizeOffset - messageOffset);
98
+ const instructionData = Buffer.alloc(16);
99
+ ED25519_INSTRUCTION_LAYOUT.encode({
100
+ numSignatures: 1,
101
+ padding: 0,
102
+ signatureOffset,
103
+ signatureInstructionIndex: customInstructionIndex,
104
+ publicKeyOffset,
105
+ publicKeyInstructionIndex: customInstructionIndex,
106
+ messageDataOffset,
107
+ messageDataSize: messageDataSize,
108
+ messageInstructionIndex: customInstructionIndex,
109
+ }, instructionData);
95
110
  return new web3_js_1.TransactionInstruction({
96
- keys: [
97
- {
98
- pubkey: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
99
- isSigner: false,
100
- isWritable: false,
101
- },
102
- ],
111
+ keys: [],
103
112
  programId: web3_js_1.Ed25519Program.programId,
104
- data: Buffer.from(ixData),
113
+ data: instructionData,
105
114
  });
106
115
  }
107
116
  exports.createMinimalEd25519VerifyIx = createMinimalEd25519VerifyIx;
@@ -244,6 +244,7 @@ class PollingDriftClientAccountSubscriber {
244
244
  this.accountsToPoll.clear();
245
245
  this.oraclesToPoll.clear();
246
246
  this.isSubscribed = false;
247
+ this.accountLoader.accountsToLoad = new Map();
247
248
  }
248
249
  async addSpotMarket(marketIndex) {
249
250
  const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
@@ -195,16 +195,16 @@ export declare class AdminClient extends DriftClient {
195
195
  getUpdatePerpMarketFuelIx(perpMarketIndex: number, fuelBoostTaker?: number, fuelBoostMaker?: number, fuelBoostPosition?: number): Promise<TransactionInstruction>;
196
196
  initUserFuel(user: PublicKey, authority: PublicKey, fuelBonusDeposits?: number, fuelBonusBorrows?: number, fuelBonusTaker?: number, fuelBonusMaker?: number, fuelBonusInsurance?: number): Promise<TransactionSignature>;
197
197
  getInitUserFuelIx(user: PublicKey, authority: PublicKey, fuelBonusDeposits?: number, fuelBonusBorrows?: number, fuelBonusTaker?: number, fuelBonusMaker?: number, fuelBonusInsurance?: number): Promise<TransactionInstruction>;
198
- initializePythPullOracle(feedId: string, isAdmin?: boolean): Promise<TransactionSignature>;
199
- getInitializePythPullOracleIx(feedId: string, isAdmin?: boolean): Promise<TransactionInstruction>;
200
- initializePythLazerOracle(feedId: number, isAdmin?: boolean): Promise<TransactionSignature>;
201
- getInitializePythLazerOracleIx(feedId: number, isAdmin?: boolean): Promise<TransactionInstruction>;
198
+ initializePythPullOracle(feedId: string): Promise<TransactionSignature>;
199
+ getInitializePythPullOracleIx(feedId: string): Promise<TransactionInstruction>;
200
+ initializePythLazerOracle(feedId: number): Promise<TransactionSignature>;
201
+ getInitializePythLazerOracleIx(feedId: number): Promise<TransactionInstruction>;
202
202
  initializeHighLeverageModeConfig(maxUsers: number): Promise<TransactionSignature>;
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>;
206
+ initializeProtectedMakerModeConfig(maxUsers: number, stateAdmin?: boolean): Promise<TransactionSignature>;
207
+ getInitializeProtectedMakerModeConfigIx(maxUsers: number, stateAdmin?: boolean): Promise<TransactionInstruction>;
208
208
  updateProtectedMakerModeConfig(maxUsers: number, reduceOnly: boolean): Promise<TransactionSignature>;
209
209
  getUpdateProtectedMakerModeConfigIx(maxUsers: number, reduceOnly: boolean): Promise<TransactionInstruction>;
210
210
  }