@drift-labs/sdk 2.142.0-beta.8 → 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 +245 -44
  4. package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +7 -4
  5. package/lib/browser/accounts/grpcMultiAccountSubscriber.js +115 -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 +245 -44
  22. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +7 -4
  23. package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
  24. package/lib/node/accounts/grpcMultiAccountSubscriber.js +115 -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 -126
  47. package/src/accounts/grpcDriftClientAccountSubscriberV2.ts +401 -75
  48. package/src/accounts/grpcMultiAccountSubscriber.ts +167 -34
  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
@@ -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,7 +1,9 @@
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>[];
7
9
  //# sourceMappingURL=parse.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/events/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAQnD,wBAAgB,SAAS,CACxB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,SAAiB,GACxB,KAAK,EAAE,CAGT;AAED,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,SAAiB,GACxB;IAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CA2BxC"}
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../src/events/parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAUvC,wBAAgB,SAAS,CACxB,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,SAAiB,GACxB,KAAK,EAAE,CAGT;AAED,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,SAAiB,GACxB;IAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CA2BxC;AAsGD,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,SAAiB,GACxB,KAAK,CAAC,YAAY,CAAC,EAAE,CAmCvB"}
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseLogsWithRaw = exports.parseLogs = void 0;
3
+ exports.parseLogsForCuUsage = exports.parseLogsWithRaw = exports.parseLogs = void 0;
4
4
  const driftProgramId = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
5
5
  const PROGRAM_LOG = 'Program log: ';
6
+ const PROGRAM_INSTRUCTION = 'Program log: Instruction: ';
6
7
  const PROGRAM_DATA = 'Program data: ';
7
8
  const PROGRAM_LOG_START_INDEX = PROGRAM_LOG.length;
8
9
  const PROGRAM_DATA_START_INDEX = PROGRAM_DATA.length;
10
+ const PROGRAM_INSTRUCTION_START_INDEX = PROGRAM_INSTRUCTION.length;
9
11
  function parseLogs(program, logs, programId = driftProgramId) {
10
12
  const { events } = parseLogsWithRaw(program, logs, programId);
11
13
  return events;
@@ -87,6 +89,7 @@ function handleSystemLog(log, programId = driftProgramId) {
87
89
  class ExecutionContext {
88
90
  constructor() {
89
91
  this.stack = [];
92
+ this.ixStack = [];
90
93
  }
91
94
  program() {
92
95
  if (!this.stack.length) {
@@ -103,4 +106,94 @@ class ExecutionContext {
103
106
  }
104
107
  this.stack.pop();
105
108
  }
109
+ ix() {
110
+ if (!this.ixStack.length) {
111
+ throw new Error('Expected the ix stack to have elements');
112
+ }
113
+ return this.ixStack[this.ixStack.length - 1];
114
+ }
115
+ pushIx(newIx) {
116
+ this.ixStack.push(newIx);
117
+ }
118
+ popIx() {
119
+ this.ixStack.pop();
120
+ }
121
+ }
122
+ function parseLogsForCuUsage(logs, programId = driftProgramId) {
123
+ const cuUsageEvents = [];
124
+ const execution = new ExecutionContext();
125
+ for (const log of logs) {
126
+ if (log.startsWith('Log truncated')) {
127
+ break;
128
+ }
129
+ const [newProgram, newIx, didPopProgram, didPopIx] = handleLogForCuUsage(execution, log, programId);
130
+ if (newProgram) {
131
+ execution.push(newProgram);
132
+ }
133
+ if (newIx) {
134
+ execution.pushIx(newIx);
135
+ }
136
+ if (didPopProgram) {
137
+ execution.pop();
138
+ }
139
+ if (didPopIx !== null) {
140
+ cuUsageEvents.push({
141
+ name: 'CuUsage',
142
+ data: {
143
+ instruction: execution.ix(),
144
+ cuUsage: didPopIx,
145
+ },
146
+ });
147
+ execution.popIx();
148
+ }
149
+ }
150
+ return cuUsageEvents;
151
+ }
152
+ exports.parseLogsForCuUsage = parseLogsForCuUsage;
153
+ function handleLogForCuUsage(execution, log, programId = driftProgramId) {
154
+ if (execution.stack.length > 0 && execution.program() === programId) {
155
+ return handleProgramLogForCuUsage(log, programId);
156
+ }
157
+ else {
158
+ return handleSystemLogForCuUsage(log, programId);
159
+ }
160
+ }
161
+ function handleProgramLogForCuUsage(log, programId = driftProgramId) {
162
+ if (log.startsWith(PROGRAM_INSTRUCTION)) {
163
+ const ixStr = log.slice(PROGRAM_INSTRUCTION_START_INDEX);
164
+ return [null, ixStr, false, null];
165
+ }
166
+ else {
167
+ return handleSystemLogForCuUsage(log, programId);
168
+ }
169
+ }
170
+ function handleSystemLogForCuUsage(log, programId = driftProgramId) {
171
+ // System component.
172
+ const logStart = log.split(':')[0];
173
+ const programStart = `Program ${programId} invoke`;
174
+ // Did the program finish executing?
175
+ if (logStart.match(/^Program (.*) success/g) !== null) {
176
+ return [null, null, true, null];
177
+ // Recursive call.
178
+ }
179
+ else if (logStart.startsWith(programStart)) {
180
+ return [programId, null, false, null];
181
+ // Consumed CU log.
182
+ }
183
+ else if (log.startsWith(`Program ${programId} consumed `)) {
184
+ // Extract CU usage, e.g. 'Program ... consumed 29242 of 199700 compute units'
185
+ // We need to extract the consumed value (29242)
186
+ const matches = log.match(/consumed (\d+) of \d+ compute units/);
187
+ if (matches) {
188
+ return [null, null, false, Number(matches[1])];
189
+ }
190
+ return [null, null, false, null];
191
+ }
192
+ // CPI call.
193
+ else if (logStart.includes('invoke')) {
194
+ return ['cpi', null, false, null]; // Any string will do.
195
+ }
196
+ else {
197
+ return [null, null, false, null];
198
+ }
106
199
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { Commitment, PublicKey, TransactionSignature } from '@solana/web3.js';
3
- import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SignedMsgOrderRecord, DeleteUserRecord, FuelSweepRecord, FuelSeasonRecord, InsuranceFundSwapRecord, TransferProtocolIfSharesToRevenuePoolRecord, LPMintRedeemRecord, LPSettleRecord, LPSwapRecord } from '../types';
3
+ import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord, SwapRecord, SpotMarketVaultDepositRecord, SignedMsgOrderRecord, DeleteUserRecord, FuelSweepRecord, FuelSeasonRecord, InsuranceFundSwapRecord, TransferProtocolIfSharesToRevenuePoolRecord, LPMintRedeemRecord, LPSettleRecord, LPSwapRecord, LPBorrowLendDepositRecord } from '../types';
4
4
  import { EventEmitter } from 'events';
5
5
  export type EventSubscriptionOptions = {
6
6
  address?: PublicKey;
@@ -47,12 +47,12 @@ export type EventMap = {
47
47
  FuelSeasonRecord: Event<FuelSeasonRecord>;
48
48
  InsuranceFundSwapRecord: Event<InsuranceFundSwapRecord>;
49
49
  TransferProtocolIfSharesToRevenuePoolRecord: Event<TransferProtocolIfSharesToRevenuePoolRecord>;
50
- LPMintRedeemRecord: Event<LPMintRedeemRecord>;
51
50
  LPSettleRecord: Event<LPSettleRecord>;
51
+ LPMintRedeemRecord: Event<LPMintRedeemRecord>;
52
52
  LPSwapRecord: Event<LPSwapRecord>;
53
53
  };
54
54
  export type EventType = keyof EventMap;
55
- export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord> | Event<SignedMsgOrderRecord> | Event<DeleteUserRecord> | Event<FuelSweepRecord> | Event<FuelSeasonRecord> | Event<InsuranceFundSwapRecord> | Event<TransferProtocolIfSharesToRevenuePoolRecord> | Event<LPSettleRecord> | Event<LPSwapRecord> | Event<LPMintRedeemRecord>;
55
+ export type DriftEvent = Event<DepositRecord> | Event<FundingPaymentRecord> | Event<LiquidationRecord> | Event<FundingRateRecord> | Event<OrderRecord> | Event<OrderActionRecord> | Event<SettlePnlRecord> | Event<NewUserRecord> | Event<LPRecord> | Event<InsuranceFundRecord> | Event<SpotInterestRecord> | Event<InsuranceFundStakeRecord> | Event<CurveRecord> | Event<SwapRecord> | Event<SpotMarketVaultDepositRecord> | Event<SignedMsgOrderRecord> | Event<DeleteUserRecord> | Event<FuelSweepRecord> | Event<FuelSeasonRecord> | Event<InsuranceFundSwapRecord> | Event<TransferProtocolIfSharesToRevenuePoolRecord> | Event<LPSettleRecord> | Event<LPMintRedeemRecord> | Event<LPSwapRecord> | Event<LPBorrowLendDepositRecord> | Event<CuUsage>;
56
56
  export interface EventSubscriberEvents {
57
57
  newEvent: (event: WrappedEvent<EventType>) => void;
58
58
  }
@@ -84,4 +84,23 @@ export type EventsServerLogProviderConfig = StreamingLogProviderConfig & {
84
84
  url: string;
85
85
  };
86
86
  export type LogProviderConfig = WebSocketLogProviderConfig | PollingLogProviderConfig | EventsServerLogProviderConfig;
87
+ export type CuUsageEvent = {
88
+ name: 'CuUsage';
89
+ fields: [
90
+ {
91
+ name: 'instruction';
92
+ type: 'string';
93
+ index: false;
94
+ },
95
+ {
96
+ name: 'cuUsage';
97
+ type: 'u32';
98
+ index: false;
99
+ }
100
+ ];
101
+ };
102
+ export type CuUsage = {
103
+ instruction: string;
104
+ cuUsage: number;
105
+ };
87
106
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/events/types.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EACN,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,QAAQ,EACR,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EACxB,WAAW,EACX,UAAU,EACV,4BAA4B,EAC5B,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,2CAA2C,EAC3C,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,MAAM,wBAAwB,GAAG;IACtC,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,wBAAwB,CAAC;IACnC,QAAQ,CAAC,EAAE,+BAA+B,CAAC;IAC3C,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAGtC,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAC/B,CAAC;AAEF,eAAO,MAAM,+BAA+B,EAAE,wBAmC7C,CAAC;AAGF,MAAM,MAAM,wBAAwB,GAAG,YAAY,GAAG,QAAQ,CAAC;AAC/D,MAAM,MAAM,+BAA+B,GAAG,KAAK,GAAG,MAAM,CAAC;AAE7D,MAAM,MAAM,KAAK,C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AAc,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACtC,IAAI,EAAE,SAAS,CAAC;IAEhB,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,0BAA0B,GAAG;IACxE,IAAI,EAAE,eAAe,CAAC;IAEtB,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAC1B,0BAA0B,GAC1B,wBAAwB,GACxB,6BAA6B,CAAC;AAEjC,MAAM,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE;QACP;YACC,IAAI,EAAE,aAAa,CAAC;YACpB,IAAI,EAAE,QAAQ,CAAC;YACf,KAAK,EAAE,KAAK,CAAC;SACb;QACD;YACC,IAAI,EAAE,SAAS,CAAC;YAChB,IAAI,EAAE,KAAK,CAAC;YACZ,KAAK,EAAE,KAAK,CAAC;SACb;KACD,CAAC;CACF,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.141.0",
2
+ "version": "2.142.0",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
@@ -5874,6 +5874,32 @@
5874
5874
  }
5875
5875
  ]
5876
5876
  },
5877
+ {
5878
+ "name": "updatePerpMarketReferencePriceOffsetDeadbandPct",
5879
+ "accounts": [
5880
+ {
5881
+ "name": "admin",
5882
+ "isMut": false,
5883
+ "isSigner": true
5884
+ },
5885
+ {
5886
+ "name": "state",
5887
+ "isMut": false,
5888
+ "isSigner": false
5889
+ },
5890
+ {
5891
+ "name": "perpMarket",
5892
+ "isMut": true,
5893
+ "isSigner": false
5894
+ }
5895
+ ],
5896
+ "args": [
5897
+ {
5898
+ "name": "referencePriceOffsetDeadbandPct",
5899
+ "type": "u8"
5900
+ }
5901
+ ]
5902
+ },
5877
5903
  {
5878
5904
  "name": "updateLpCooldownTime",
5879
5905
  "accounts": [
@@ -11209,12 +11235,16 @@
11209
11235
  ],
11210
11236
  "type": "i8"
11211
11237
  },
11238
+ {
11239
+ "name": "referencePriceOffsetDeadbandPct",
11240
+ "type": "u8"
11241
+ },
11212
11242
  {
11213
11243
  "name": "padding",
11214
11244
  "type": {
11215
11245
  "array": [
11216
11246
  "u8",
11217
- 3
11247
+ 2
11218
11248
  ]
11219
11249
  }
11220
11250
  },
@@ -14875,6 +14905,11 @@
14875
14905
  "name": "lpPrice",
14876
14906
  "type": "u128",
14877
14907
  "index": false
14908
+ },
14909
+ {
14910
+ "name": "lpPool",
14911
+ "type": "publicKey",
14912
+ "index": false
14878
14913
  }
14879
14914
  ]
14880
14915
  },
@@ -14985,6 +15020,11 @@
14985
15020
  "name": "outSwapId",
14986
15021
  "type": "u64",
14987
15022
  "index": false
15023
+ },
15024
+ {
15025
+ "name": "lpPool",
15026
+ "type": "publicKey",
15027
+ "index": false
14988
15028
  }
14989
15029
  ]
14990
15030
  },
@@ -15080,6 +15120,68 @@
15080
15120
  "name": "inMarketTargetWeight",
15081
15121
  "type": "i64",
15082
15122
  "index": false
15123
+ },
15124
+ {
15125
+ "name": "lpPool",
15126
+ "type": "publicKey",
15127
+ "index": false
15128
+ }
15129
+ ]
15130
+ },
15131
+ {
15132
+ "name": "LPBorrowLendDepositRecord",
15133
+ "fields": [
15134
+ {
15135
+ "name": "ts",
15136
+ "type": "i64",
15137
+ "index": false
15138
+ },
15139
+ {
15140
+ "name": "slot",
15141
+ "type": "u64",
15142
+ "index": false
15143
+ },
15144
+ {
15145
+ "name": "spotMarketIndex",
15146
+ "type": "u16",
15147
+ "index": false
15148
+ },
15149
+ {
15150
+ "name": "constituentIndex",
15151
+ "type": "u16",
15152
+ "index": false
15153
+ },
15154
+ {
15155
+ "name": "direction",
15156
+ "type": {
15157
+ "defined": "DepositDirection"
15158
+ },
15159
+ "index": false
15160
+ },
15161
+ {
15162
+ "name": "tokenBalance",
15163
+ "type": "i64",
15164
+ "index": false
15165
+ },
15166
+ {
15167
+ "name": "lastTokenBalance",
15168
+ "type": "i64",
15169
+ "index": false
15170
+ },
15171
+ {
15172
+ "name": "interestAccruedTokenAmount",
15173
+ "type": "i64",
15174
+ "index": false
15175
+ },
15176
+ {
15177
+ "name": "amountDepositWithdraw",
15178
+ "type": "u64",
15179
+ "index": false
15180
+ },
15181
+ {
15182
+ "name": "lpPool",
15183
+ "type": "publicKey",
15184
+ "index": false
15083
15185
  }
15084
15186
  ]
15085
15187
  }
@@ -16710,8 +16812,5 @@
16710
16812
  "name": "UnableToLoadRevenueShareAccount",
16711
16813
  "msg": "Unable to load builder account"
16712
16814
  }
16713
- ],
16714
- "metadata": {
16715
- "address": "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH"
16716
- }
16815
+ ]
16717
16816
  }
@@ -35,6 +35,7 @@ export type AssetType = 'quote' | 'base';
35
35
  export declare function calculateAmmReservesAfterSwap(amm: Pick<AMM, 'pegMultiplier' | 'quoteAssetReserve' | 'sqrtK' | 'baseAssetReserve'>, inputAssetType: AssetType, swapAmount: BN, swapDirection: SwapDirection): [BN, BN];
36
36
  export declare function calculateMarketOpenBidAsk(baseAssetReserve: BN, minBaseAssetReserve: BN, maxBaseAssetReserve: BN, stepSize?: BN): [BN, BN];
37
37
  export declare function calculateInventoryLiquidityRatio(baseAssetAmountWithAmm: BN, baseAssetReserve: BN, minBaseAssetReserve: BN, maxBaseAssetReserve: BN): BN;
38
+ export declare function calculateInventoryLiquidityRatioForReferencePriceOffset(baseAssetAmountWithAmm: BN, baseAssetReserve: BN, minBaseAssetReserve: BN, maxBaseAssetReserve: BN): BN;
38
39
  export declare function calculateInventoryScale(baseAssetAmountWithAmm: BN, baseAssetReserve: BN, minBaseAssetReserve: BN, maxBaseAssetReserve: BN, directionalSpread: number, maxSpread: number): number;
39
40
  export declare function calculateReferencePriceOffset(reservePrice: BN, last24hAvgFundingRate: BN, liquidityFraction: BN, oracleTwapFast: BN, markTwapFast: BN, oracleTwapSlow: BN, markTwapSlow: BN, maxOffsetPct: number): BN;
40
41
  export declare function calculateEffectiveLeverage(baseSpread: number, quoteAssetReserve: BN, terminalQuoteAssetReserve: BN, pegMultiplier: BN, netBaseAssetAmount: BN, reservePrice: BN, totalFeeMinusDistributions: BN): number;
@@ -1 +1 @@
1
- {"version":3,"file":"amm.d.ts","sourceRoot":"","sources":["../../../src/math/amm.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAiBvC,OAAO,EACN,GAAG,EACH,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EAEjB,MAAM,UAAU,CAAC;AAKlB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAStE,wBAAgB,2BAA2B,CAC1C,WAAW,EAAE,EAAE,EACf,gBAAgB,EAAE,EAAE,EACpB,iBAAiB,EAAE,EAAE,GACnB,EAAE,CASJ;AAED,wBAAgB,4BAA4B,CAC3C,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,iBAAiB,GAClC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,CAwDvB;AAED,wBAAgB,eAAe,CAC9B,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,iBAAiB,GAClC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAqClB;AAED,wBAAgB,mBAAmB,CAClC,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,iBAAiB,GAClC,GAAG,CAmCL;AAED,wBAAgB,iCAAiC,CAChD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,iBAAiB,EAC5B,iBAAiB,EAAE,iBAAiB,EACpC,YAAY,UAAQ,EACpB,UAAU,CAAC,EAAE,EA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AAgB,gCAAgC,CAC/C,kBAAkB,EAAE,EAAE,EACtB,aAAa,EAAE,EAAE,EACjB,aAAa,EAAE,aAAa,GAC1B,EAAE,CAcJ;AAED,wBAAgB,mCAAmC,CAClD,GAAG,EAAE,GAAG,EACR,cAAc,EAAE,iBAAiB,GAC/B,EAAE,CAqBJ"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateMaxBaseAssetAmountFillable = exports.calculateQuoteAssetAmountSwapped = exports.calculateMaxBaseAssetAmountToTrade = exports.calculateTerminalPrice = exports.getSwapDirection = exports.calculateSwapOutput = exports.calculateSpreadReserves = exports.getQuoteAssetReservePredictionMarketBounds = exports.calculateSpread = exports.calculateSpreadBN = exports.calculateVolSpreadBN = exports.calculateMaxSpread = exports.calculateEffectiveLeverage = exports.calculateReferencePriceOffset = exports.calculateInventoryScale = exports.calculateInventoryLiquidityRatio = exports.calculateMarketOpenBidAsk = exports.calculateAmmReservesAfterSwap = exports.calculatePrice = exports.calculateBidAskPrice = exports.calculateUpdatedAMMSpreadReserves = exports.calculateUpdatedAMM = exports.calculateNewAmm = exports.calculateOptimalPegAndBudget = exports.calculatePegFromTargetPrice = void 0;
3
+ exports.calculateMaxBaseAssetAmountFillable = exports.calculateQuoteAssetAmountSwapped = exports.calculateMaxBaseAssetAmountToTrade = exports.calculateTerminalPrice = exports.getSwapDirection = exports.calculateSwapOutput = exports.calculateSpreadReserves = exports.getQuoteAssetReservePredictionMarketBounds = exports.calculateSpread = exports.calculateSpreadBN = exports.calculateVolSpreadBN = exports.calculateMaxSpread = exports.calculateEffectiveLeverage = exports.calculateReferencePriceOffset = exports.calculateInventoryScale = exports.calculateInventoryLiquidityRatioForReferencePriceOffset = exports.calculateInventoryLiquidityRatio = exports.calculateMarketOpenBidAsk = exports.calculateAmmReservesAfterSwap = exports.calculatePrice = exports.calculateBidAskPrice = exports.calculateUpdatedAMMSpreadReserves = exports.calculateUpdatedAMM = exports.calculateNewAmm = exports.calculateOptimalPegAndBudget = exports.calculatePegFromTargetPrice = void 0;
4
4
  const anchor_1 = require("@coral-xyz/anchor");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
6
  const types_1 = require("../types");
@@ -213,6 +213,17 @@ function calculateInventoryLiquidityRatio(baseAssetAmountWithAmm, baseAssetReser
213
213
  return inventoryScaleBN;
214
214
  }
215
215
  exports.calculateInventoryLiquidityRatio = calculateInventoryLiquidityRatio;
216
+ function calculateInventoryLiquidityRatioForReferencePriceOffset(baseAssetAmountWithAmm, baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve) {
217
+ // inventory skew
218
+ const [openBids, openAsks] = calculateMarketOpenBidAsk(baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve);
219
+ const avgSideLiquidity = openBids.abs().add(openAsks.abs()).div(numericConstants_1.TWO);
220
+ const inventoryScaleBN = anchor_1.BN.min(baseAssetAmountWithAmm
221
+ .mul(numericConstants_1.PERCENTAGE_PRECISION)
222
+ .div(anchor_1.BN.max(avgSideLiquidity, numericConstants_1.ONE))
223
+ .abs(), numericConstants_1.PERCENTAGE_PRECISION);
224
+ return inventoryScaleBN;
225
+ }
226
+ exports.calculateInventoryLiquidityRatioForReferencePriceOffset = calculateInventoryLiquidityRatioForReferencePriceOffset;
216
227
  function calculateInventoryScale(baseAssetAmountWithAmm, baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve, directionalSpread, maxSpread) {
217
228
  if (baseAssetAmountWithAmm.eq(numericConstants_1.ZERO)) {
218
229
  return 1;
@@ -227,7 +238,7 @@ function calculateInventoryScale(baseAssetAmountWithAmm, baseAssetReserve, minBa
227
238
  }
228
239
  exports.calculateInventoryScale = calculateInventoryScale;
229
240
  function calculateReferencePriceOffset(reservePrice, last24hAvgFundingRate, liquidityFraction, oracleTwapFast, markTwapFast, oracleTwapSlow, markTwapSlow, maxOffsetPct) {
230
- if (last24hAvgFundingRate.eq(numericConstants_1.ZERO)) {
241
+ if (last24hAvgFundingRate.eq(numericConstants_1.ZERO) || liquidityFraction.eq(numericConstants_1.ZERO)) {
231
242
  return numericConstants_1.ZERO;
232
243
  }
233
244
  const maxOffsetInPrice = new anchor_1.BN(maxOffsetPct)
@@ -526,9 +537,22 @@ function calculateSpreadReserves(amm, mmOraclePriceData, now, isPrediction = fal
526
537
  if (amm.curveUpdateIntensity > 100) {
527
538
  maxOffset = Math.max(amm.maxSpread / 2, (numericConstants_1.PERCENTAGE_PRECISION.toNumber() / 10000) *
528
539
  (amm.curveUpdateIntensity - 100));
529
- const liquidityFraction = calculateInventoryLiquidityRatio(amm.baseAssetAmountWithAmm, amm.baseAssetReserve, amm.minBaseAssetReserve, amm.maxBaseAssetReserve);
540
+ const liquidityFraction = calculateInventoryLiquidityRatioForReferencePriceOffset(amm.baseAssetAmountWithAmm, amm.baseAssetReserve, amm.minBaseAssetReserve, amm.maxBaseAssetReserve);
530
541
  const liquidityFractionSigned = liquidityFraction.mul((0, utils_1.sigNum)(amm.baseAssetAmountWithAmm.add(amm.baseAssetAmountWithUnsettledLp)));
531
- referencePriceOffset = calculateReferencePriceOffset(reservePrice, amm.last24HAvgFundingRate, liquidityFractionSigned, amm.historicalOracleData.lastOraclePriceTwap5Min, amm.lastMarkPriceTwap5Min, amm.historicalOracleData.lastOraclePriceTwap, amm.lastMarkPriceTwap, maxOffset).toNumber();
542
+ let liquidityFractionAfterDeadband = liquidityFractionSigned;
543
+ const deadbandPct = amm.referencePriceOffsetDeadbandPct
544
+ ? numericConstants_1.PERCENTAGE_PRECISION.mul(new anchor_1.BN(amm.referencePriceOffsetDeadbandPct)).divn(100)
545
+ : numericConstants_1.ZERO;
546
+ if (!liquidityFractionAfterDeadband.eq(numericConstants_1.ZERO) && deadbandPct.gt(numericConstants_1.ZERO)) {
547
+ const abs = liquidityFractionAfterDeadband.abs();
548
+ if (abs.lte(deadbandPct)) {
549
+ liquidityFractionAfterDeadband = numericConstants_1.ZERO;
550
+ }
551
+ else {
552
+ liquidityFractionAfterDeadband = liquidityFractionAfterDeadband.sub(deadbandPct.mul((0, utils_1.sigNum)(liquidityFractionAfterDeadband)));
553
+ }
554
+ }
555
+ referencePriceOffset = calculateReferencePriceOffset(reservePrice, amm.last24HAvgFundingRate, liquidityFractionAfterDeadband, amm.historicalOracleData.lastOraclePriceTwap5Min, amm.lastMarkPriceTwap5Min, amm.historicalOracleData.lastOraclePriceTwap, amm.lastMarkPriceTwap, maxOffset).toNumber();
532
556
  }
533
557
  let [longSpread, shortSpread] = calculateSpread(amm, mmOraclePriceData, now, reservePrice);
534
558
  const doReferencePricOffsetSmooth = Math.sign(referencePriceOffset) !== Math.sign(amm.referencePriceOffset) &&