@drift-labs/sdk 2.142.0-beta.9 → 2.142.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/VERSION +1 -1
  2. package/lib/browser/accounts/grpcDriftClientAccountSubscriberV2.d.ts +46 -5
  3. package/lib/browser/accounts/grpcDriftClientAccountSubscriberV2.js +242 -41
  4. package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +6 -3
  5. package/lib/browser/accounts/grpcMultiAccountSubscriber.js +112 -19
  6. package/lib/browser/adminClient.d.ts +4 -0
  7. package/lib/browser/adminClient.js +34 -0
  8. package/lib/browser/constants/perpMarkets.js +35 -0
  9. package/lib/browser/constants/spotMarkets.js +4 -4
  10. package/lib/browser/driftClient.d.ts +35 -5
  11. package/lib/browser/driftClient.js +41 -14
  12. package/lib/browser/events/parse.d.ts +2 -0
  13. package/lib/browser/events/parse.js +94 -1
  14. package/lib/browser/events/types.d.ts +22 -3
  15. package/lib/browser/idl/drift.json +105 -6
  16. package/lib/browser/math/amm.d.ts +1 -0
  17. package/lib/browser/math/amm.js +28 -4
  18. package/lib/browser/types.d.ts +20 -0
  19. package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts +46 -5
  20. package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.d.ts.map +1 -1
  21. package/lib/node/accounts/grpcDriftClientAccountSubscriberV2.js +242 -41
  22. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +6 -3
  23. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
  24. package/lib/node/accounts/grpcMultiAccountSubscriber.js +112 -19
  25. package/lib/node/adminClient.d.ts +4 -0
  26. package/lib/node/adminClient.d.ts.map +1 -1
  27. package/lib/node/adminClient.js +34 -0
  28. package/lib/node/constants/perpMarkets.d.ts.map +1 -1
  29. package/lib/node/constants/perpMarkets.js +35 -0
  30. package/lib/node/constants/spotMarkets.js +4 -4
  31. package/lib/node/driftClient.d.ts +35 -5
  32. package/lib/node/driftClient.d.ts.map +1 -1
  33. package/lib/node/driftClient.js +41 -14
  34. package/lib/node/events/parse.d.ts +2 -0
  35. package/lib/node/events/parse.d.ts.map +1 -1
  36. package/lib/node/events/parse.js +94 -1
  37. package/lib/node/events/types.d.ts +22 -3
  38. package/lib/node/events/types.d.ts.map +1 -1
  39. package/lib/node/idl/drift.json +105 -6
  40. package/lib/node/math/amm.d.ts +1 -0
  41. package/lib/node/math/amm.d.ts.map +1 -1
  42. package/lib/node/math/amm.js +28 -4
  43. package/lib/node/types.d.ts +20 -0
  44. package/lib/node/types.d.ts.map +1 -1
  45. package/package.json +2 -1
  46. package/scripts/client-test.ts +294 -135
  47. package/src/accounts/grpcDriftClientAccountSubscriberV2.ts +398 -72
  48. package/src/accounts/grpcMultiAccountSubscriber.ts +163 -31
  49. package/src/adminClient.ts +74 -0
  50. package/src/constants/perpMarkets.ts +37 -0
  51. package/src/constants/spotMarkets.ts +4 -4
  52. package/src/driftClient.ts +65 -14
  53. package/src/events/parse.ts +115 -0
  54. package/src/events/types.ts +26 -2
  55. package/src/idl/drift.json +105 -6
  56. package/src/math/amm.ts +52 -8
  57. package/src/types.ts +22 -0
  58. package/tests/events/parseLogsForCuUsage.ts +139 -0
@@ -31,13 +31,27 @@ const web3_js_1 = require("@solana/web3.js");
31
31
  const Buffer = __importStar(require("buffer"));
32
32
  const bs58_1 = __importDefault(require("bs58"));
33
33
  const grpc_1 = require("../isomorphic/grpc");
34
+ function commitmentLevelToCommitment(commitmentLevel) {
35
+ switch (commitmentLevel) {
36
+ case grpc_1.CommitmentLevel.PROCESSED:
37
+ return 'processed';
38
+ case grpc_1.CommitmentLevel.CONFIRMED:
39
+ return 'confirmed';
40
+ case grpc_1.CommitmentLevel.FINALIZED:
41
+ return 'finalized';
42
+ default:
43
+ return 'confirmed';
44
+ }
45
+ }
34
46
  class grpcMultiAccountSubscriber {
35
- constructor(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe) {
47
+ constructor(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe, accountPropsMap) {
36
48
  this.isUnsubscribing = false;
37
49
  this.receivingData = false;
38
50
  this.subscribedAccounts = new Set();
39
51
  this.onChangeMap = new Map();
40
52
  this.dataMap = new Map();
53
+ this.accountPropsMap = new Map();
54
+ this.bufferMap = new Map();
41
55
  this.client = client;
42
56
  this.commitmentLevel = commitmentLevel;
43
57
  this.accountName = accountName;
@@ -45,8 +59,9 @@ class grpcMultiAccountSubscriber {
45
59
  this.decodeBufferFn = decodeBuffer;
46
60
  this.resubOpts = resubOpts;
47
61
  this.onUnsubscribe = onUnsubscribe;
62
+ this.accountPropsMap = accountPropsMap;
48
63
  }
49
- static async create(grpcConfigs, accountName, program, decodeBuffer, resubOpts, clientProp, onUnsubscribe) {
64
+ static async create(grpcConfigs, accountName, program, decodeBuffer, resubOpts, clientProp, onUnsubscribe, accountPropsMap) {
50
65
  var _a, _b;
51
66
  const client = clientProp
52
67
  ? clientProp
@@ -54,7 +69,7 @@ class grpcMultiAccountSubscriber {
54
69
  const commitmentLevel =
55
70
  // @ts-ignore :: isomorphic exported enum fails typescript but will work at runtime
56
71
  (_b = grpcConfigs.commitmentLevel) !== null && _b !== void 0 ? _b : grpc_1.CommitmentLevel.CONFIRMED;
57
- return new grpcMultiAccountSubscriber(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe);
72
+ return new grpcMultiAccountSubscriber(client, commitmentLevel, accountName, program, decodeBuffer, resubOpts, onUnsubscribe, accountPropsMap);
58
73
  }
59
74
  setAccountData(accountPubkey, data, slot) {
60
75
  this.dataMap.set(accountPubkey, { data, slot });
@@ -65,7 +80,60 @@ class grpcMultiAccountSubscriber {
65
80
  getAccountDataMap() {
66
81
  return this.dataMap;
67
82
  }
83
+ async fetch() {
84
+ var _a;
85
+ try {
86
+ // Chunk account IDs into groups of 100 (getMultipleAccounts limit)
87
+ const chunkSize = 100;
88
+ const chunks = [];
89
+ const accountIds = Array.from(this.subscribedAccounts.values());
90
+ for (let i = 0; i < accountIds.length; i += chunkSize) {
91
+ chunks.push(accountIds.slice(i, i + chunkSize));
92
+ }
93
+ // Process all chunks concurrently
94
+ await Promise.all(chunks.map(async (chunk) => {
95
+ const accountAddresses = chunk.map((accountId) => new web3_js_1.PublicKey(accountId));
96
+ const rpcResponseAndContext = await this.program.provider.connection.getMultipleAccountsInfoAndContext(accountAddresses, {
97
+ commitment: commitmentLevelToCommitment(this.commitmentLevel),
98
+ });
99
+ const rpcResponse = rpcResponseAndContext.value;
100
+ const currentSlot = rpcResponseAndContext.context.slot;
101
+ for (let i = 0; i < chunk.length; i++) {
102
+ const accountId = chunk[i];
103
+ const accountInfo = rpcResponse[i];
104
+ if (accountInfo) {
105
+ const prev = this.bufferMap.get(accountId);
106
+ const newBuffer = accountInfo.data;
107
+ if (prev && currentSlot < prev.slot) {
108
+ continue;
109
+ }
110
+ if (prev &&
111
+ prev.buffer &&
112
+ newBuffer &&
113
+ newBuffer.equals(prev.buffer)) {
114
+ continue;
115
+ }
116
+ this.bufferMap.set(accountId, {
117
+ buffer: newBuffer,
118
+ slot: currentSlot,
119
+ });
120
+ const accountDecoded = this.program.coder.accounts.decode(this.capitalize(this.accountName), newBuffer);
121
+ this.setAccountData(accountId, accountDecoded, currentSlot);
122
+ }
123
+ }
124
+ }));
125
+ }
126
+ catch (error) {
127
+ if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
128
+ console.log(`[${this.accountName}] grpcMultiAccountSubscriber error fetching accounts:`, error);
129
+ }
130
+ }
131
+ }
68
132
  async subscribe(accounts, onChange) {
133
+ var _a;
134
+ if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.logResubMessages) {
135
+ console.log(`[${this.accountName}] grpcMultiAccountSubscriber subscribe`);
136
+ }
69
137
  if (this.listenerId != null || this.isUnsubscribing) {
70
138
  return;
71
139
  }
@@ -73,9 +141,9 @@ class grpcMultiAccountSubscriber {
73
141
  for (const pk of accounts) {
74
142
  const key = pk.toBase58();
75
143
  this.subscribedAccounts.add(key);
76
- this.onChangeMap.set(key, (data, ctx, buffer) => {
144
+ this.onChangeMap.set(key, (data, ctx, buffer, accountProps) => {
77
145
  this.setAccountData(key, data, ctx.slot);
78
- onChange(new web3_js_1.PublicKey(key), data, ctx, buffer);
146
+ onChange(new web3_js_1.PublicKey(key), data, ctx, buffer, accountProps);
79
147
  });
80
148
  }
81
149
  this.stream =
@@ -98,7 +166,7 @@ class grpcMultiAccountSubscriber {
98
166
  transactionsStatus: {},
99
167
  };
100
168
  this.stream.on('data', (chunk) => {
101
- var _a;
169
+ var _a, _b;
102
170
  if (!chunk.account) {
103
171
  return;
104
172
  }
@@ -108,6 +176,17 @@ class grpcMultiAccountSubscriber {
108
176
  if (!accountPubkey || !this.subscribedAccounts.has(accountPubkey)) {
109
177
  return;
110
178
  }
179
+ // Touch resub timer on any incoming account update for subscribed keys
180
+ if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
181
+ this.receivingData = true;
182
+ clearTimeout(this.timeoutId);
183
+ this.setTimeout();
184
+ }
185
+ // Skip processing if we already have data for this account at a newer slot
186
+ const existing = this.dataMap.get(accountPubkey);
187
+ if ((existing === null || existing === void 0 ? void 0 : existing.slot) !== undefined && existing.slot > slot) {
188
+ return;
189
+ }
111
190
  const accountInfo = {
112
191
  owner: new web3_js_1.PublicKey(chunk.account.account.owner),
113
192
  lamports: Number(chunk.account.account.lamports),
@@ -117,21 +196,36 @@ class grpcMultiAccountSubscriber {
117
196
  };
118
197
  const context = { slot };
119
198
  const buffer = accountInfo.data;
120
- const data = this.decodeBufferFn
121
- ? this.decodeBufferFn(buffer, accountPubkey)
122
- : this.program.account[this.accountName].coder.accounts.decode(this.capitalize(this.accountName), buffer);
123
- const handler = this.onChangeMap.get(accountPubkey);
124
- if (handler) {
125
- if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
126
- this.receivingData = true;
127
- clearTimeout(this.timeoutId);
128
- handler(data, context, buffer);
129
- this.setTimeout();
199
+ // Check existing buffer for this account and skip if unchanged or slot regressed
200
+ const prevBuffer = this.bufferMap.get(accountPubkey);
201
+ if (prevBuffer && slot < prevBuffer.slot) {
202
+ return;
203
+ }
204
+ if (prevBuffer &&
205
+ prevBuffer.buffer &&
206
+ buffer &&
207
+ buffer.equals(prevBuffer.buffer)) {
208
+ return;
209
+ }
210
+ this.bufferMap.set(accountPubkey, { buffer, slot });
211
+ const accountProps = (_b = this.accountPropsMap) === null || _b === void 0 ? void 0 : _b.get(accountPubkey);
212
+ const handleDataBuffer = (context, buffer, accountProps) => {
213
+ const data = this.decodeBufferFn
214
+ ? this.decodeBufferFn(buffer, accountPubkey, accountProps)
215
+ : this.program.account[this.accountName].coder.accounts.decode(this.capitalize(this.accountName), buffer);
216
+ const handler = this.onChangeMap.get(accountPubkey);
217
+ if (handler) {
218
+ handler(data, context, buffer, accountProps);
130
219
  }
131
- else {
132
- handler(data, context, buffer);
220
+ };
221
+ if (Array.isArray(accountProps)) {
222
+ for (const props of accountProps) {
223
+ handleDataBuffer(context, buffer, props);
133
224
  }
134
225
  }
226
+ else {
227
+ handleDataBuffer(context, buffer, accountProps);
228
+ }
135
229
  });
136
230
  return new Promise((resolve, reject) => {
137
231
  this.stream.write(request, (err) => {
@@ -140,7 +234,6 @@ class grpcMultiAccountSubscriber {
140
234
  this.listenerId = 1;
141
235
  if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
142
236
  this.receivingData = true;
143
- this.setTimeout();
144
237
  }
145
238
  resolve();
146
239
  }
@@ -53,6 +53,8 @@ export declare class AdminClient extends DriftClient {
53
53
  getUpdateAdminIx(admin: PublicKey): Promise<TransactionInstruction>;
54
54
  updatePerpMarketCurveUpdateIntensity(perpMarketIndex: number, curveUpdateIntensity: number): Promise<TransactionSignature>;
55
55
  getUpdatePerpMarketCurveUpdateIntensityIx(perpMarketIndex: number, curveUpdateIntensity: number): Promise<TransactionInstruction>;
56
+ updatePerpMarketReferencePriceOffsetDeadbandPct(perpMarketIndex: number, referencePriceOffsetDeadbandPct: number): Promise<TransactionSignature>;
57
+ getUpdatePerpMarketReferencePriceOffsetDeadbandPctIx(perpMarketIndex: number, referencePriceOffsetDeadbandPct: number): Promise<TransactionInstruction>;
56
58
  updatePerpMarketTargetBaseAssetAmountPerLp(perpMarketIndex: number, targetBaseAssetAmountPerLP: number): Promise<TransactionSignature>;
57
59
  updatePerpMarketAmmSummaryStats(perpMarketIndex: number, updateAmmSummaryStats?: boolean, quoteAssetAmountWithUnsettledLp?: BN, netUnsettledFundingPnl?: BN, excludeTotalLiqFee?: boolean): Promise<TransactionSignature>;
58
60
  getUpdatePerpMarketAmmSummaryStatsIx(perpMarketIndex: number, updateAmmSummaryStats?: boolean, quoteAssetAmountWithUnsettledLp?: BN, netUnsettledFundingPnl?: BN, excludeTotalLiqFee?: boolean): Promise<TransactionInstruction>;
@@ -246,4 +248,6 @@ export declare class AdminClient extends DriftClient {
246
248
  getUpdateFeatureBitFlagsBuilderCodesIx(enable: boolean): Promise<TransactionInstruction>;
247
249
  updateFeatureBitFlagsBuilderReferral(enable: boolean): Promise<TransactionSignature>;
248
250
  getUpdateFeatureBitFlagsBuilderReferralIx(enable: boolean): Promise<TransactionInstruction>;
251
+ adminDisableUpdatePerpBidAskTwap(authority: PublicKey, disable: boolean): Promise<TransactionSignature>;
252
+ getAdminDisableUpdatePerpBidAskTwapIx(authority: PublicKey, disable: boolean): Promise<TransactionInstruction>;
249
253
  }
@@ -550,6 +550,23 @@ class AdminClient extends driftClient_1.DriftClient {
550
550
  },
551
551
  });
552
552
  }
553
+ async updatePerpMarketReferencePriceOffsetDeadbandPct(perpMarketIndex, referencePriceOffsetDeadbandPct) {
554
+ const updatePerpMarketReferencePriceOffsetDeadbandPctIx = await this.getUpdatePerpMarketReferencePriceOffsetDeadbandPctIx(perpMarketIndex, referencePriceOffsetDeadbandPct);
555
+ const tx = await this.buildTransaction(updatePerpMarketReferencePriceOffsetDeadbandPctIx);
556
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
557
+ return txSig;
558
+ }
559
+ async getUpdatePerpMarketReferencePriceOffsetDeadbandPctIx(perpMarketIndex, referencePriceOffsetDeadbandPct) {
560
+ return await this.program.instruction.updatePerpMarketReferencePriceOffsetDeadbandPct(referencePriceOffsetDeadbandPct, {
561
+ accounts: {
562
+ admin: this.useHotWalletAdmin
563
+ ? this.wallet.publicKey
564
+ : this.getStateAccount().admin,
565
+ state: await this.getStatePublicKey(),
566
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
567
+ },
568
+ });
569
+ }
553
570
  async updatePerpMarketTargetBaseAssetAmountPerLp(perpMarketIndex, targetBaseAssetAmountPerLP) {
554
571
  const updatePerpMarketTargetBaseAssetAmountPerLpIx = await this.getUpdatePerpMarketTargetBaseAssetAmountPerLpIx(perpMarketIndex, targetBaseAssetAmountPerLP);
555
572
  const tx = await this.buildTransaction(updatePerpMarketTargetBaseAssetAmountPerLpIx);
@@ -2248,5 +2265,22 @@ class AdminClient extends driftClient_1.DriftClient {
2248
2265
  },
2249
2266
  });
2250
2267
  }
2268
+ async adminDisableUpdatePerpBidAskTwap(authority, disable) {
2269
+ const disableBidAskTwapUpdateIx = await this.getAdminDisableUpdatePerpBidAskTwapIx(authority, disable);
2270
+ const tx = await this.buildTransaction(disableBidAskTwapUpdateIx);
2271
+ const { txSig } = await this.sendTransaction(tx, [], this.opts);
2272
+ return txSig;
2273
+ }
2274
+ async getAdminDisableUpdatePerpBidAskTwapIx(authority, disable) {
2275
+ return await this.program.instruction.adminDisableUpdatePerpBidAskTwap(disable, {
2276
+ accounts: {
2277
+ admin: this.useHotWalletAdmin
2278
+ ? this.wallet.publicKey
2279
+ : this.getStateAccount().admin,
2280
+ state: await this.getStatePublicKey(),
2281
+ userStats: (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, authority),
2282
+ },
2283
+ });
2284
+ }
2251
2285
  }
2252
2286
  exports.AdminClient = AdminClient;
@@ -1252,6 +1252,41 @@ exports.MainnetPerpMarkets = [
1252
1252
  pythFeedId: '0xf2b3ab1c49e35e881003c3c0482d18b181a1560b697b844c24c8f85aba1cab95',
1253
1253
  pythLazerId: 2316,
1254
1254
  },
1255
+ {
1256
+ fullName: 'ZCash',
1257
+ category: ['Privacy'],
1258
+ symbol: 'ZEC-PERP',
1259
+ baseAssetSymbol: 'ZEC',
1260
+ marketIndex: 79,
1261
+ oracle: new web3_js_1.PublicKey('BXunfRSyiQWJHv88qMvE42mpMpksWEC8Bf13p2msnRms'),
1262
+ launchTs: 1760366017000,
1263
+ oracleSource: types_1.OracleSource.PYTH_LAZER,
1264
+ pythFeedId: '0xbe9b59d178f0d6a97ab4c343bff2aa69caa1eaae3e9048a65788c529b125bb24',
1265
+ pythLazerId: 66,
1266
+ },
1267
+ {
1268
+ fullName: 'Mantle',
1269
+ category: ['L1'],
1270
+ symbol: 'MNT-PERP',
1271
+ baseAssetSymbol: 'MNT',
1272
+ marketIndex: 80,
1273
+ oracle: new web3_js_1.PublicKey('Gy7cJ4U1nxMA44XXC3hwqkpcxEB1mZTYiwJVkaqZfU7u'),
1274
+ launchTs: 1760366017000,
1275
+ oracleSource: types_1.OracleSource.PYTH_LAZER,
1276
+ pythFeedId: '0x4e3037c822d852d79af3ac80e35eb420ee3b870dca49f9344a38ef4773fb0585',
1277
+ pythLazerId: 199,
1278
+ },
1279
+ {
1280
+ fullName: '1KPUMP',
1281
+ category: ['Launchpad'],
1282
+ symbol: '1KPUMP-PERP',
1283
+ baseAssetSymbol: '1KPUMP',
1284
+ marketIndex: 81,
1285
+ oracle: new web3_js_1.PublicKey('5r8RWTaRiMgr9Lph3FTUE3sGb1vymhpCrm83Bovjfcps'),
1286
+ launchTs: 1760366017000,
1287
+ oracleSource: types_1.OracleSource.PYTH_LAZER_1K,
1288
+ pythLazerId: 1578,
1289
+ },
1255
1290
  ];
1256
1291
  exports.PerpMarkets = {
1257
1292
  devnet: exports.DevnetPerpMarkets,
@@ -11,8 +11,8 @@ exports.DevnetSpotMarkets = [
11
11
  symbol: 'USDC',
12
12
  marketIndex: 0,
13
13
  poolId: 0,
14
- oracle: new web3_js_1.PublicKey('En8hkHLkRe9d9DraYmBTrus518BvmVH448YcvmrFM6Ce'),
15
- oracleSource: types_1.OracleSource.PYTH_STABLE_COIN_PULL,
14
+ oracle: new web3_js_1.PublicKey('9VCioxmni2gDLv11qufWzT3RDERhQE4iY5Gf7NTfYyAV'),
15
+ oracleSource: types_1.OracleSource.PYTH_LAZER_STABLE_COIN,
16
16
  mint: new web3_js_1.PublicKey('8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2'),
17
17
  precision: new anchor_1.BN(10).pow(numericConstants_1.SIX),
18
18
  precisionExp: numericConstants_1.SIX,
@@ -23,8 +23,8 @@ exports.DevnetSpotMarkets = [
23
23
  symbol: 'SOL',
24
24
  marketIndex: 1,
25
25
  poolId: 0,
26
- oracle: new web3_js_1.PublicKey('BAtFj4kQttZRVep3UZS2aZRDixkGYgWsbqTBVDbnSsPF'),
27
- oracleSource: types_1.OracleSource.PYTH_PULL,
26
+ oracle: new web3_js_1.PublicKey('3m6i4RFWEDw2Ft4tFHPJtYgmpPe21k56M3FHeWYrgGBz'),
27
+ oracleSource: types_1.OracleSource.PYTH_LAZER,
28
28
  mint: new web3_js_1.PublicKey(exports.WRAPPED_SOL_MINT),
29
29
  precision: numericConstants_1.LAMPORTS_PRECISION,
30
30
  precisionExp: numericConstants_1.LAMPORTS_EXP,
@@ -180,7 +180,26 @@ export declare class DriftClient {
180
180
  getMigrateReferrerIx(authority: PublicKey): Promise<TransactionInstruction>;
181
181
  resizeRevenueShareEscrowOrders(authority: PublicKey, numOrders: number, txParams?: TxParams): Promise<TransactionSignature>;
182
182
  getResizeRevenueShareEscrowOrdersIx(authority: PublicKey, numOrders: number): Promise<TransactionInstruction>;
183
+ /**
184
+ * Creates the transaction to add or update an approved builder.
185
+ * This allows the builder to receive revenue share from referrals.
186
+ *
187
+ * @param builder - The public key of the builder to add or update.
188
+ * @param maxFeeTenthBps - The maximum fee tenth bps to set for the builder.
189
+ * @param add - Whether to add or update the builder. If the builder already exists, `add = true` will update the `maxFeeTenthBps`, otherwise it will add the builder. If `add = false`, the builder's `maxFeeTenthBps` will be set to 0.
190
+ * @param txParams - The transaction parameters to use for the transaction.
191
+ * @returns The transaction to add or update an approved builder.
192
+ */
183
193
  changeApprovedBuilder(builder: PublicKey, maxFeeTenthBps: number, add: boolean, txParams?: TxParams): Promise<TransactionSignature>;
194
+ /**
195
+ * Creates the transaction instruction to add or update an approved builder.
196
+ * This allows the builder to receive revenue share from referrals.
197
+ *
198
+ * @param builder - The public key of the builder to add or update.
199
+ * @param maxFeeTenthBps - The maximum fee tenth bps to set for the builder.
200
+ * @param add - Whether to add or update the builder. If the builder already exists, `add = true` will update the `maxFeeTenthBps`, otherwise it will add the builder. If `add = false`, the builder's `maxFeeTenthBps` will be set to 0.
201
+ * @returns The transaction instruction to add or update an approved builder.
202
+ */
184
203
  getChangeApprovedBuilderIx(builder: PublicKey, maxFeeTenthBps: number, add: boolean): Promise<TransactionInstruction>;
185
204
  addSignedMsgWsDelegate(authority: PublicKey, delegate: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
186
205
  getAddSignedMsgWsDelegateIx(authority: PublicKey, delegate: PublicKey): Promise<TransactionInstruction>;
@@ -461,7 +480,9 @@ export declare class DriftClient {
461
480
  * @param user - The user to cancel the orders for. If provided, it will be prioritized over the subAccountId.
462
481
  * @returns The transaction signature.
463
482
  */
464
- cancelOrdersByIds(orderIds?: number[], txParams?: TxParams, subAccountId?: number, user?: User): Promise<TransactionSignature>;
483
+ cancelOrdersByIds(orderIds?: number[], txParams?: TxParams, subAccountId?: number, user?: User, overrides?: {
484
+ authority?: PublicKey;
485
+ }): Promise<TransactionSignature>;
465
486
  /**
466
487
  * Returns the transaction instruction to cancel the provided order ids.
467
488
  *
@@ -470,7 +491,9 @@ export declare class DriftClient {
470
491
  * @param user - The user to cancel the orders for. If provided, it will be prioritized over the subAccountId.
471
492
  * @returns The transaction instruction to cancel the orders.
472
493
  */
473
- getCancelOrdersByIdsIx(orderIds?: number[], subAccountId?: number, user?: User): Promise<TransactionInstruction>;
494
+ getCancelOrdersByIdsIx(orderIds?: number[], subAccountId?: number, user?: User, overrides?: {
495
+ authority?: PublicKey;
496
+ }): Promise<TransactionInstruction>;
474
497
  cancelOrders(marketType?: MarketType, marketIndex?: number, direction?: PositionDirection, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
475
498
  getCancelOrdersIx(marketType: MarketType | null, marketIndex: number | null, direction: PositionDirection | null, subAccountId?: number): Promise<TransactionInstruction>;
476
499
  cancelAndPlaceOrders(cancelOrderParams: {
@@ -482,7 +505,9 @@ export declare class DriftClient {
482
505
  preparePlaceOrdersTx(params: OrderParams[], txParams?: TxParams, subAccountId?: number, optionalIxs?: TransactionInstruction[]): Promise<{
483
506
  placeOrdersTx: anchor.web3.Transaction | anchor.web3.VersionedTransaction;
484
507
  }>;
485
- getPlaceOrdersIx(params: OptionalOrderParams[], subAccountId?: number): Promise<TransactionInstruction>;
508
+ getPlaceOrdersIx(params: OptionalOrderParams[], subAccountId?: number, overrides?: {
509
+ authority?: PublicKey;
510
+ }): Promise<TransactionInstruction>;
486
511
  getPlaceOrdersAndSetPositionMaxLevIx(params: OptionalOrderParams[], positionMaxLev: number, subAccountId?: number): Promise<TransactionInstruction[]>;
487
512
  fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, txParams?: TxParams, fillerSubAccountId?: number, fillerAuthority?: PublicKey, hasBuilderFee?: boolean): Promise<TransactionSignature>;
488
513
  getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, fillerSubAccountId?: number, isSignedMsg?: boolean, fillerAuthority?: PublicKey, hasBuilderFee?: boolean): Promise<TransactionInstruction>;
@@ -605,7 +630,9 @@ export declare class DriftClient {
605
630
  signedCancelExistingOrdersTx?: Transaction;
606
631
  signedSettlePnlTx?: Transaction;
607
632
  }>;
608
- getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, auctionDurationPercentage?: number, subAccountId?: number): Promise<TransactionInstruction>;
633
+ getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], referrerInfo?: ReferrerInfo, successCondition?: PlaceAndTakeOrderSuccessCondition, auctionDurationPercentage?: number, subAccountId?: number, overrides?: {
634
+ authority?: PublicKey;
635
+ }): Promise<TransactionInstruction>;
609
636
  placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, txParams?: TxParams, subAccountId?: number): Promise<TransactionSignature>;
610
637
  getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo, subAccountId?: number): Promise<TransactionInstruction>;
611
638
  signSignedMsgOrderParamsMessage(orderParamsMessage: SignedMsgOrderParamsMessage | SignedMsgOrderParamsDelegateMessage, delegateSigner?: boolean): SignedMsgOrderParams;
@@ -737,7 +764,10 @@ export declare class DriftClient {
737
764
  bitFlags?: number;
738
765
  maxTs?: BN;
739
766
  policy?: number;
740
- }, subAccountId?: number, userPublicKey?: PublicKey): Promise<TransactionInstruction>;
767
+ }, subAccountId?: number, overrides?: {
768
+ user?: User;
769
+ authority?: PublicKey;
770
+ }): Promise<TransactionInstruction>;
741
771
  /**
742
772
  * Modifies an open order by closing it and replacing it with a new order.
743
773
  * @param orderParams.userOrderId: The open order to modify
@@ -768,12 +768,31 @@ class DriftClient {
768
768
  },
769
769
  });
770
770
  }
771
+ /**
772
+ * Creates the transaction to add or update an approved builder.
773
+ * This allows the builder to receive revenue share from referrals.
774
+ *
775
+ * @param builder - The public key of the builder to add or update.
776
+ * @param maxFeeTenthBps - The maximum fee tenth bps to set for the builder.
777
+ * @param add - Whether to add or update the builder. If the builder already exists, `add = true` will update the `maxFeeTenthBps`, otherwise it will add the builder. If `add = false`, the builder's `maxFeeTenthBps` will be set to 0.
778
+ * @param txParams - The transaction parameters to use for the transaction.
779
+ * @returns The transaction to add or update an approved builder.
780
+ */
771
781
  async changeApprovedBuilder(builder, maxFeeTenthBps, add, txParams) {
772
782
  const ix = await this.getChangeApprovedBuilderIx(builder, maxFeeTenthBps, add);
773
783
  const tx = await this.buildTransaction([ix], txParams);
774
784
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
775
785
  return txSig;
776
786
  }
787
+ /**
788
+ * Creates the transaction instruction to add or update an approved builder.
789
+ * This allows the builder to receive revenue share from referrals.
790
+ *
791
+ * @param builder - The public key of the builder to add or update.
792
+ * @param maxFeeTenthBps - The maximum fee tenth bps to set for the builder.
793
+ * @param add - Whether to add or update the builder. If the builder already exists, `add = true` will update the `maxFeeTenthBps`, otherwise it will add the builder. If `add = false`, the builder's `maxFeeTenthBps` will be set to 0.
794
+ * @returns The transaction instruction to add or update an approved builder.
795
+ */
777
796
  async getChangeApprovedBuilderIx(builder, maxFeeTenthBps, add) {
778
797
  const authority = this.wallet.publicKey;
779
798
  const escrow = (0, pda_1.getRevenueShareEscrowAccountPublicKey)(this.program.programId, authority);
@@ -2456,8 +2475,8 @@ class DriftClient {
2456
2475
  * @param user - The user to cancel the orders for. If provided, it will be prioritized over the subAccountId.
2457
2476
  * @returns The transaction signature.
2458
2477
  */
2459
- async cancelOrdersByIds(orderIds, txParams, subAccountId, user) {
2460
- const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrdersByIdsIx(orderIds, subAccountId, user), txParams), [], this.opts);
2478
+ async cancelOrdersByIds(orderIds, txParams, subAccountId, user, overrides) {
2479
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrdersByIdsIx(orderIds, subAccountId, user, overrides), txParams), [], this.opts);
2461
2480
  return txSig;
2462
2481
  }
2463
2482
  /**
@@ -2468,19 +2487,20 @@ class DriftClient {
2468
2487
  * @param user - The user to cancel the orders for. If provided, it will be prioritized over the subAccountId.
2469
2488
  * @returns The transaction instruction to cancel the orders.
2470
2489
  */
2471
- async getCancelOrdersByIdsIx(orderIds, subAccountId, user) {
2472
- var _a, _b;
2490
+ async getCancelOrdersByIdsIx(orderIds, subAccountId, user, overrides) {
2491
+ var _a, _b, _c;
2473
2492
  const userAccountPubKey = (_a = user === null || user === void 0 ? void 0 : user.userAccountPublicKey) !== null && _a !== void 0 ? _a : (await this.getUserAccountPublicKey(subAccountId));
2474
2493
  const userAccount = (_b = user === null || user === void 0 ? void 0 : user.getUserAccount()) !== null && _b !== void 0 ? _b : this.getUserAccount(subAccountId);
2475
2494
  const remainingAccounts = this.getRemainingAccounts({
2476
2495
  userAccounts: [userAccount],
2477
2496
  useMarketLastSlotCache: true,
2478
2497
  });
2498
+ const authority = (_c = overrides === null || overrides === void 0 ? void 0 : overrides.authority) !== null && _c !== void 0 ? _c : this.wallet.publicKey;
2479
2499
  return await this.program.instruction.cancelOrdersByIds(orderIds, {
2480
2500
  accounts: {
2481
2501
  state: await this.getStatePublicKey(),
2482
2502
  user: userAccountPubKey,
2483
- authority: this.wallet.publicKey,
2503
+ authority,
2484
2504
  },
2485
2505
  remainingAccounts,
2486
2506
  });
@@ -2536,7 +2556,8 @@ class DriftClient {
2536
2556
  placeOrdersTx: tx,
2537
2557
  };
2538
2558
  }
2539
- async getPlaceOrdersIx(params, subAccountId) {
2559
+ async getPlaceOrdersIx(params, subAccountId, overrides) {
2560
+ var _a;
2540
2561
  const user = await this.getUserAccountPublicKey(subAccountId);
2541
2562
  const readablePerpMarketIndex = [];
2542
2563
  const readableSpotMarketIndexes = [];
@@ -2567,12 +2588,13 @@ class DriftClient {
2567
2588
  }
2568
2589
  }
2569
2590
  const formattedParams = params.map((item) => (0, orderParams_1.getOrderParams)(item));
2591
+ const authority = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.authority) !== null && _a !== void 0 ? _a : this.wallet.publicKey;
2570
2592
  return await this.program.instruction.placeOrders(formattedParams, {
2571
2593
  accounts: {
2572
2594
  state: await this.getStatePublicKey(),
2573
2595
  user,
2574
2596
  userStats: this.getUserStatsAccountPublicKey(),
2575
- authority: this.wallet.publicKey,
2597
+ authority,
2576
2598
  },
2577
2599
  remainingAccounts,
2578
2600
  });
@@ -3532,7 +3554,8 @@ class DriftClient {
3532
3554
  signedSettlePnlTx: signedTxs.settlePnlTx,
3533
3555
  };
3534
3556
  }
3535
- async getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, successCondition, auctionDurationPercentage, subAccountId) {
3557
+ async getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, successCondition, auctionDurationPercentage, subAccountId, overrides) {
3558
+ var _a;
3536
3559
  orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
3537
3560
  const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
3538
3561
  const user = await this.getUserAccountPublicKey(subAccountId);
@@ -3590,12 +3613,13 @@ class DriftClient {
3590
3613
  optionalParams =
3591
3614
  ((auctionDurationPercentage !== null && auctionDurationPercentage !== void 0 ? auctionDurationPercentage : 100) << 8) | (successCondition !== null && successCondition !== void 0 ? successCondition : 0);
3592
3615
  }
3616
+ const authority = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.authority) !== null && _a !== void 0 ? _a : this.wallet.publicKey;
3593
3617
  return await this.program.instruction.placeAndTakePerpOrder(orderParams, optionalParams, {
3594
3618
  accounts: {
3595
3619
  state: await this.getStatePublicKey(),
3596
3620
  user,
3597
3621
  userStats: userStatsPublicKey,
3598
- authority: this.wallet.publicKey,
3622
+ authority,
3599
3623
  },
3600
3624
  remainingAccounts,
3601
3625
  });
@@ -4025,10 +4049,12 @@ class DriftClient {
4025
4049
  * @param userPublicKey: Optional - The public key of the user to modify the order for. This takes precedence over subAccountId.
4026
4050
  * @returns
4027
4051
  */
4028
- async getModifyOrderIx({ orderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, bitFlags, maxTs, policy, }, subAccountId, userPublicKey) {
4029
- const user = userPublicKey !== null && userPublicKey !== void 0 ? userPublicKey : (await this.getUserAccountPublicKey(subAccountId));
4052
+ async getModifyOrderIx({ orderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, bitFlags, maxTs, policy, }, subAccountId, overrides) {
4053
+ var _a, _b, _c, _d, _e, _f, _g;
4054
+ const userPubKey = (_b = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.user) === null || _a === void 0 ? void 0 : _a.getUserAccountPublicKey()) !== null && _b !== void 0 ? _b : (await this.getUserAccountPublicKey(subAccountId));
4055
+ const userAccount = (_d = (_c = overrides === null || overrides === void 0 ? void 0 : overrides.user) === null || _c === void 0 ? void 0 : _c.getUserAccount()) !== null && _d !== void 0 ? _d : this.getUserAccount(subAccountId);
4030
4056
  const remainingAccounts = this.getRemainingAccounts({
4031
- userAccounts: [this.getUserAccount(subAccountId)],
4057
+ userAccounts: [userAccount],
4032
4058
  useMarketLastSlotCache: true,
4033
4059
  });
4034
4060
  const orderParams = {
@@ -4047,12 +4073,13 @@ class DriftClient {
4047
4073
  policy: policy || null,
4048
4074
  maxTs: maxTs || null,
4049
4075
  };
4076
+ const authority = (_g = (_e = overrides === null || overrides === void 0 ? void 0 : overrides.authority) !== null && _e !== void 0 ? _e : (_f = overrides === null || overrides === void 0 ? void 0 : overrides.user) === null || _f === void 0 ? void 0 : _f.getUserAccount().authority) !== null && _g !== void 0 ? _g : this.wallet.publicKey;
4050
4077
  return await this.program.instruction.modifyOrder(orderId, orderParams, {
4051
4078
  accounts: {
4052
4079
  state: await this.getStatePublicKey(),
4053
- user,
4080
+ user: userPubKey,
4054
4081
  userStats: this.getUserStatsAccountPublicKey(),
4055
- authority: this.wallet.publicKey,
4082
+ authority,
4056
4083
  },
4057
4084
  remainingAccounts,
4058
4085
  });
@@ -1,6 +1,8 @@
1
1
  import { Program, Event } from '@coral-xyz/anchor';
2
+ import { CuUsageEvent } from './types';
2
3
  export declare function parseLogs(program: Program, logs: string[], programId?: string): Event[];
3
4
  export declare function parseLogsWithRaw(program: Program, logs: string[], programId?: string): {
4
5
  events: Event[];
5
6
  rawLogs: string[];
6
7
  };
8
+ export declare function parseLogsForCuUsage(logs: string[], programId?: string): Event<CuUsageEvent>[];