@drift-labs/sdk 0.1.36-master.7 → 0.2.0-master.2

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 (197) hide show
  1. package/lib/accounts/bulkAccountLoader.d.ts +6 -6
  2. package/lib/accounts/bulkAccountLoader.js +81 -95
  3. package/lib/accounts/bulkUserSubscription.js +13 -57
  4. package/lib/accounts/fetch.d.ts +4 -0
  5. package/lib/accounts/fetch.js +18 -0
  6. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +34 -38
  7. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +224 -224
  8. package/lib/accounts/pollingOracleSubscriber.d.ts +3 -3
  9. package/lib/accounts/pollingOracleSubscriber.js +37 -49
  10. package/lib/accounts/pollingTokenAccountSubscriber.d.ts +3 -3
  11. package/lib/accounts/pollingTokenAccountSubscriber.js +35 -50
  12. package/lib/accounts/pollingUserAccountSubscriber.d.ts +7 -13
  13. package/lib/accounts/pollingUserAccountSubscriber.js +71 -134
  14. package/lib/accounts/types.d.ts +34 -41
  15. package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -4
  16. package/lib/accounts/webSocketAccountSubscriber.js +39 -35
  17. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +33 -28
  18. package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +153 -185
  19. package/lib/accounts/webSocketUserAccountSubscriber.d.ts +5 -11
  20. package/lib/accounts/webSocketUserAccountSubscriber.js +22 -67
  21. package/lib/addresses/marketAddresses.d.ts +4 -0
  22. package/lib/addresses/marketAddresses.js +15 -0
  23. package/lib/addresses/pda.d.ts +12 -0
  24. package/lib/addresses/pda.js +83 -0
  25. package/lib/admin.d.ts +9 -17
  26. package/lib/admin.js +375 -558
  27. package/lib/clearingHouse.d.ts +86 -109
  28. package/lib/clearingHouse.js +828 -895
  29. package/lib/clearingHouseConfig.d.ts +34 -0
  30. package/lib/clearingHouseConfig.js +2 -0
  31. package/lib/clearingHouseUser.d.ts +19 -22
  32. package/lib/clearingHouseUser.js +155 -141
  33. package/lib/clearingHouseUserConfig.d.ts +14 -0
  34. package/lib/clearingHouseUserConfig.js +2 -0
  35. package/lib/config.d.ts +12 -0
  36. package/lib/config.js +35 -4
  37. package/lib/constants/banks.d.ts +16 -0
  38. package/lib/constants/banks.js +34 -0
  39. package/lib/constants/markets.d.ts +8 -3
  40. package/lib/constants/markets.js +13 -206
  41. package/lib/constants/numericConstants.d.ts +17 -0
  42. package/lib/constants/numericConstants.js +23 -6
  43. package/lib/events/eventList.d.ts +22 -0
  44. package/lib/events/eventList.js +77 -0
  45. package/lib/events/eventSubscriber.d.ts +34 -0
  46. package/lib/events/eventSubscriber.js +126 -0
  47. package/lib/events/fetchLogs.d.ts +13 -0
  48. package/lib/events/fetchLogs.js +39 -0
  49. package/lib/events/pollingLogProvider.d.ts +15 -0
  50. package/lib/events/pollingLogProvider.js +53 -0
  51. package/lib/events/sort.d.ts +2 -0
  52. package/lib/events/sort.js +44 -0
  53. package/lib/events/txEventCache.d.ts +24 -0
  54. package/lib/events/txEventCache.js +71 -0
  55. package/lib/events/types.d.ts +49 -0
  56. package/lib/events/types.js +20 -0
  57. package/lib/events/webSocketLogProvider.d.ts +12 -0
  58. package/lib/events/webSocketLogProvider.js +30 -0
  59. package/lib/examples/makeTradeExample.js +26 -27
  60. package/lib/factory/bigNum.d.ts +118 -0
  61. package/lib/factory/bigNum.js +364 -0
  62. package/lib/factory/oracleClient.d.ts +1 -2
  63. package/lib/factory/oracleClient.js +6 -2
  64. package/lib/idl/clearing_house.json +2287 -2938
  65. package/lib/index.d.ts +12 -4
  66. package/lib/index.js +12 -4
  67. package/lib/math/amm.d.ts +24 -29
  68. package/lib/math/amm.js +239 -178
  69. package/lib/math/auction.d.ts +5 -0
  70. package/lib/math/auction.js +39 -0
  71. package/lib/math/bankBalance.d.ts +9 -0
  72. package/lib/math/bankBalance.js +75 -0
  73. package/lib/math/conversion.d.ts +0 -1
  74. package/lib/math/conversion.js +1 -5
  75. package/lib/math/funding.d.ts +6 -6
  76. package/lib/math/funding.js +158 -175
  77. package/lib/math/market.d.ts +6 -6
  78. package/lib/math/market.js +10 -9
  79. package/lib/math/orders.d.ts +5 -0
  80. package/lib/math/orders.js +31 -1
  81. package/lib/math/position.d.ts +7 -5
  82. package/lib/math/position.js +27 -27
  83. package/lib/math/repeg.d.ts +22 -0
  84. package/lib/math/repeg.js +128 -0
  85. package/lib/math/trade.d.ts +5 -4
  86. package/lib/math/trade.js +29 -21
  87. package/lib/mockUSDCFaucet.js +87 -116
  88. package/lib/oracles/oracleClientCache.d.ts +8 -0
  89. package/lib/oracles/oracleClientCache.js +19 -0
  90. package/lib/oracles/pythClient.d.ts +3 -5
  91. package/lib/oracles/pythClient.js +12 -31
  92. package/lib/oracles/quoteAssetOracleClient.d.ts +9 -0
  93. package/lib/oracles/quoteAssetOracleClient.js +21 -0
  94. package/lib/oracles/switchboardClient.d.ts +3 -5
  95. package/lib/oracles/switchboardClient.js +29 -50
  96. package/lib/oracles/types.d.ts +6 -1
  97. package/lib/orders.d.ts +6 -7
  98. package/lib/orders.js +10 -80
  99. package/lib/slot/SlotSubscriber.d.ts +12 -0
  100. package/lib/slot/SlotSubscriber.js +23 -0
  101. package/lib/tx/retryTxSender.d.ts +2 -2
  102. package/lib/tx/retryTxSender.js +108 -123
  103. package/lib/tx/types.d.ts +5 -1
  104. package/lib/tx/utils.d.ts +1 -1
  105. package/lib/tx/utils.js +11 -2
  106. package/lib/types.d.ts +110 -109
  107. package/lib/types.js +14 -1
  108. package/lib/userName.d.ts +4 -0
  109. package/lib/userName.js +20 -0
  110. package/lib/util/computeUnits.js +10 -21
  111. package/lib/util/tps.js +11 -22
  112. package/lib/wallet.js +7 -20
  113. package/package.json +11 -4
  114. package/src/accounts/bulkAccountLoader.ts +21 -15
  115. package/src/accounts/bulkUserSubscription.ts +1 -45
  116. package/src/accounts/fetch.ts +33 -0
  117. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +249 -214
  118. package/src/accounts/pollingOracleSubscriber.ts +16 -8
  119. package/src/accounts/pollingTokenAccountSubscriber.ts +11 -8
  120. package/src/accounts/pollingUserAccountSubscriber.ts +21 -86
  121. package/src/accounts/types.ts +41 -70
  122. package/src/accounts/webSocketAccountSubscriber.ts +33 -16
  123. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +190 -240
  124. package/src/accounts/webSocketUserAccountSubscriber.ts +11 -71
  125. package/src/addresses/marketAddresses.ts +18 -0
  126. package/src/addresses/pda.ts +118 -0
  127. package/src/admin.ts +218 -346
  128. package/src/clearingHouse.ts +983 -952
  129. package/src/clearingHouseConfig.ts +37 -0
  130. package/src/clearingHouseUser.ts +275 -185
  131. package/src/clearingHouseUserConfig.ts +18 -0
  132. package/src/config.ts +54 -1
  133. package/src/constants/banks.ts +43 -0
  134. package/src/constants/markets.ts +16 -207
  135. package/src/constants/numericConstants.ts +34 -5
  136. package/src/events/eventList.ts +94 -0
  137. package/src/events/eventSubscriber.ts +194 -0
  138. package/src/events/fetchLogs.ts +80 -0
  139. package/src/events/pollingLogProvider.ts +79 -0
  140. package/src/events/sort.ts +65 -0
  141. package/src/events/txEventCache.ts +74 -0
  142. package/src/events/types.ts +98 -0
  143. package/src/events/webSocketLogProvider.ts +38 -0
  144. package/src/examples/makeTradeExample.ts +20 -11
  145. package/src/factory/bigNum.ts +524 -0
  146. package/src/factory/oracleClient.ts +7 -4
  147. package/src/idl/clearing_house.json +2287 -2938
  148. package/src/index.ts +12 -4
  149. package/src/math/amm.ts +414 -245
  150. package/src/math/auction.ts +39 -0
  151. package/src/math/bankBalance.ts +112 -0
  152. package/src/math/conversion.ts +1 -11
  153. package/src/math/funding.ts +12 -9
  154. package/src/math/market.ts +37 -30
  155. package/src/math/orders.ts +38 -0
  156. package/src/math/position.ts +48 -35
  157. package/src/math/repeg.ts +176 -0
  158. package/src/math/trade.ts +45 -35
  159. package/src/math/utils.js +27 -0
  160. package/src/math/utils.js.map +1 -0
  161. package/src/oracles/oracleClientCache.ts +20 -0
  162. package/src/oracles/pythClient.ts +4 -11
  163. package/src/oracles/quoteAssetOracleClient.ts +25 -0
  164. package/src/oracles/switchboardClient.ts +11 -24
  165. package/src/oracles/types.ts +7 -1
  166. package/src/orders.ts +24 -126
  167. package/src/slot/SlotSubscriber.ts +32 -0
  168. package/src/tx/retryTxSender.ts +6 -4
  169. package/src/tx/types.ts +6 -1
  170. package/src/tx/utils.ts +22 -3
  171. package/src/types.ts +111 -122
  172. package/src/userName.ts +20 -0
  173. package/src/util/computeUnits.js +17 -0
  174. package/src/util/computeUnits.js.map +1 -0
  175. package/tests/bn/test.ts +255 -0
  176. package/tsconfig.json +12 -12
  177. package/lib/addresses.d.ts +0 -10
  178. package/lib/addresses.js +0 -93
  179. package/lib/constants/accounts.d.ts +0 -15
  180. package/lib/constants/accounts.js +0 -18
  181. package/lib/factory/clearingHouse.d.ts +0 -35
  182. package/lib/factory/clearingHouse.js +0 -81
  183. package/lib/factory/clearingHouseUser.d.ts +0 -19
  184. package/lib/factory/clearingHouseUser.js +0 -34
  185. package/lib/math/insuranceFund.d.ts +0 -15
  186. package/lib/math/insuranceFund.js +0 -33
  187. package/lib/settlement.d.ts +0 -4
  188. package/lib/settlement.js +0 -10
  189. package/lib/tx/defaultTxSender.d.ts +0 -8
  190. package/lib/tx/defaultTxSender.js +0 -12
  191. package/src/addresses.ts +0 -82
  192. package/src/constants/accounts.ts +0 -26
  193. package/src/factory/clearingHouse.ts +0 -173
  194. package/src/factory/clearingHouseUser.ts +0 -73
  195. package/src/math/insuranceFund.ts +0 -29
  196. package/src/settlement.ts +0 -9
  197. package/src/tx/defaultTxSender.ts +0 -24
package/src/orders.ts CHANGED
@@ -1,28 +1,15 @@
1
1
  import {
2
2
  isVariant,
3
- Market,
3
+ MarketAccount,
4
4
  Order,
5
5
  PositionDirection,
6
- SwapDirection,
7
6
  UserAccount,
8
7
  UserPosition,
9
8
  } from './types';
10
- import {
11
- BN,
12
- calculateAmmReservesAfterSwap,
13
- calculateBaseAssetValue,
14
- calculateSpreadReserves,
15
- ClearingHouseUser,
16
- isOrderRiskIncreasingInSameDirection,
17
- TEN_THOUSAND,
18
- } from '.';
19
- import {
20
- calculateMarkPrice,
21
- calculateNewMarketAfterTrade,
22
- } from './math/market';
9
+ import { BN, standardizeBaseAssetAmount } from '.';
10
+ import { calculateNewMarketAfterTrade } from './math/market';
23
11
  import {
24
12
  AMM_TO_QUOTE_PRECISION_RATIO,
25
- TWO,
26
13
  PEG_PRECISION,
27
14
  ZERO,
28
15
  } from './constants/numericConstants';
@@ -36,9 +23,9 @@ import { OraclePriceData } from '.';
36
23
  export function calculateNewStateAfterOrder(
37
24
  userAccount: UserAccount,
38
25
  userPosition: UserPosition,
39
- market: Market,
26
+ market: MarketAccount,
40
27
  order: Order
41
- ): [UserAccount, UserPosition, Market] | null {
28
+ ): [UserAccount, UserPosition, MarketAccount] | null {
42
29
  if (isVariant(order.status, 'init')) {
43
30
  return null;
44
31
  }
@@ -47,7 +34,7 @@ export function calculateNewStateAfterOrder(
47
34
  market,
48
35
  order
49
36
  );
50
- if (baseAssetAmountToTrade.lt(market.amm.minimumBaseAssetTradeSize)) {
37
+ if (baseAssetAmountToTrade.lt(market.amm.baseAssetAmountStepSize)) {
51
38
  return null;
52
39
  }
53
40
 
@@ -155,8 +142,8 @@ export function calculateNewStateAfterOrder(
155
142
  }
156
143
 
157
144
  function calculateAmountSwapped(
158
- marketBefore: Market,
159
- marketAfter: Market
145
+ marketBefore: MarketAccount,
146
+ marketAfter: MarketAccount
160
147
  ): { quoteAssetAmountSwapped: BN; baseAssetAmountSwapped: BN } {
161
148
  return {
162
149
  quoteAssetAmountSwapped: marketBefore.amm.quoteAssetReserve
@@ -172,7 +159,7 @@ function calculateAmountSwapped(
172
159
  }
173
160
 
174
161
  export function calculateBaseAssetAmountMarketCanExecute(
175
- market: Market,
162
+ market: MarketAccount,
176
163
  order: Order,
177
164
  oraclePriceData?: OraclePriceData
178
165
  ): BN {
@@ -181,7 +168,6 @@ export function calculateBaseAssetAmountMarketCanExecute(
181
168
  } else if (isVariant(order.orderType, 'triggerLimit')) {
182
169
  return calculateAmountToTradeForTriggerLimit(market, order);
183
170
  } else if (isVariant(order.orderType, 'market')) {
184
- // should never be a market order queued
185
171
  return ZERO;
186
172
  } else {
187
173
  return calculateAmountToTradeForTriggerMarket(market, order);
@@ -189,7 +175,7 @@ export function calculateBaseAssetAmountMarketCanExecute(
189
175
  }
190
176
 
191
177
  export function calculateAmountToTradeForLimit(
192
- market: Market,
178
+ market: MarketAccount,
193
179
  order: Order,
194
180
  oraclePriceData?: OraclePriceData
195
181
  ): BN {
@@ -213,8 +199,12 @@ export function calculateAmountToTradeForLimit(
213
199
  const [maxAmountToTrade, direction] = calculateMaxBaseAssetAmountToTrade(
214
200
  market.amm,
215
201
  limitPrice,
216
- order.direction,
217
- !order.postOnly
202
+ order.direction
203
+ );
204
+
205
+ const baseAssetAmount = standardizeBaseAssetAmount(
206
+ maxAmountToTrade,
207
+ market.amm.baseAssetAmountStepSize
218
208
  );
219
209
 
220
210
  // Check that directions are the same
@@ -223,23 +213,17 @@ export function calculateAmountToTradeForLimit(
223
213
  return ZERO;
224
214
  }
225
215
 
226
- return maxAmountToTrade.gt(order.baseAssetAmount)
216
+ return baseAssetAmount.gt(order.baseAssetAmount)
227
217
  ? order.baseAssetAmount
228
- : maxAmountToTrade;
218
+ : baseAssetAmount;
229
219
  }
230
220
 
231
221
  export function calculateAmountToTradeForTriggerLimit(
232
- market: Market,
222
+ market: MarketAccount,
233
223
  order: Order
234
224
  ): BN {
235
- if (order.baseAssetAmountFilled.eq(ZERO)) {
236
- const baseAssetAmount = calculateAmountToTradeForTriggerMarket(
237
- market,
238
- order
239
- );
240
- if (baseAssetAmount.eq(ZERO)) {
241
- return ZERO;
242
- }
225
+ if (!order.triggered) {
226
+ return ZERO;
243
227
  }
244
228
 
245
229
  return calculateAmountToTradeForLimit(market, order);
@@ -256,98 +240,12 @@ function isSameDirection(
256
240
  }
257
241
 
258
242
  function calculateAmountToTradeForTriggerMarket(
259
- market: Market,
243
+ market: MarketAccount,
260
244
  order: Order
261
245
  ): BN {
262
- return isTriggerConditionSatisfied(market, order)
263
- ? order.baseAssetAmount
264
- : ZERO;
265
- }
266
-
267
- function isTriggerConditionSatisfied(market: Market, order: Order): boolean {
268
- const markPrice = calculateMarkPrice(market);
269
- if (isVariant(order.triggerCondition, 'above')) {
270
- return markPrice.gt(order.triggerPrice);
271
- } else {
272
- return markPrice.lt(order.triggerPrice);
273
- }
274
- }
275
-
276
- export function calculateBaseAssetAmountUserCanExecute(
277
- market: Market,
278
- order: Order,
279
- user: ClearingHouseUser
280
- ): BN {
281
- const maxLeverage = user.getMaxLeverage(order.marketIndex, 'Initial');
282
- const freeCollateral = user.getFreeCollateral();
283
- let quoteAssetAmount: BN;
284
- if (isOrderRiskIncreasingInSameDirection(user, order)) {
285
- quoteAssetAmount = freeCollateral.mul(maxLeverage).div(TEN_THOUSAND);
286
- } else {
287
- const position =
288
- user.getUserPosition(order.marketIndex) ||
289
- user.getEmptyPosition(order.marketIndex);
290
- const positionValue = calculateBaseAssetValue(market, position);
291
- quoteAssetAmount = freeCollateral
292
- .mul(maxLeverage)
293
- .div(TEN_THOUSAND)
294
- .add(positionValue.mul(TWO));
295
- }
296
-
297
- if (quoteAssetAmount.lte(ZERO)) {
246
+ if (!order.triggered) {
298
247
  return ZERO;
299
248
  }
300
249
 
301
- const swapDirection = isVariant(order.direction, 'long')
302
- ? SwapDirection.ADD
303
- : SwapDirection.REMOVE;
304
-
305
- const useSpread = !order.postOnly;
306
- let amm: Parameters<typeof calculateAmmReservesAfterSwap>[0];
307
- if (useSpread) {
308
- const { baseAssetReserve, quoteAssetReserve } = calculateSpreadReserves(
309
- market.amm,
310
- order.direction
311
- );
312
- amm = {
313
- baseAssetReserve,
314
- quoteAssetReserve,
315
- sqrtK: market.amm.sqrtK,
316
- pegMultiplier: market.amm.pegMultiplier,
317
- };
318
- } else {
319
- amm = market.amm;
320
- }
321
-
322
- const baseAssetReservesBefore = amm.baseAssetReserve;
323
- const [_, baseAssetReservesAfter] = calculateAmmReservesAfterSwap(
324
- amm,
325
- 'quote',
326
- quoteAssetAmount,
327
- swapDirection
328
- );
329
-
330
- let baseAssetAmount = baseAssetReservesBefore
331
- .sub(baseAssetReservesAfter)
332
- .abs();
333
- if (order.reduceOnly) {
334
- const position =
335
- user.getUserPosition(order.marketIndex) ||
336
- user.getEmptyPosition(order.marketIndex);
337
- if (
338
- isVariant(order.direction, 'long') &&
339
- position.baseAssetAmount.gte(ZERO)
340
- ) {
341
- baseAssetAmount = ZERO;
342
- } else if (
343
- isVariant(order.direction, 'short') &&
344
- position.baseAssetAmount.lte(ZERO)
345
- ) {
346
- baseAssetAmount = ZERO;
347
- } else {
348
- BN.min(baseAssetAmount, position.baseAssetAmount.abs());
349
- }
350
- }
351
-
352
- return baseAssetAmount;
250
+ return order.baseAssetAmount;
353
251
  }
@@ -0,0 +1,32 @@
1
+ import { Connection } from '@solana/web3.js';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/ban-types
4
+ type SlotSubscriberConfig = {}; // for future customization
5
+
6
+ export class SlotSubscriber {
7
+ currentSlot: number;
8
+ subscriptionId: number;
9
+
10
+ public constructor(
11
+ private connection: Connection,
12
+ _config?: SlotSubscriberConfig
13
+ ) {}
14
+
15
+ public async subscribe(): Promise<void> {
16
+ this.currentSlot = await this.connection.getSlot('confirmed');
17
+
18
+ this.subscriptionId = this.connection.onSlotChange((slotInfo) => {
19
+ this.currentSlot = slotInfo.slot;
20
+ });
21
+ }
22
+
23
+ public getSlot(): number {
24
+ return this.currentSlot;
25
+ }
26
+
27
+ public async unsubscribe(): Promise<void> {
28
+ if (this.subscriptionId) {
29
+ await this.connection.removeSlotChangeListener(this.subscriptionId);
30
+ }
31
+ }
32
+ }
@@ -1,4 +1,4 @@
1
- import { TxSender } from './types';
1
+ import { TxSender, TxSigAndSlot } from './types';
2
2
  import {
3
3
  Commitment,
4
4
  ConfirmOptions,
@@ -43,7 +43,7 @@ export class RetryTxSender implements TxSender {
43
43
  tx: Transaction,
44
44
  additionalSigners?: Array<Signer>,
45
45
  opts?: ConfirmOptions
46
- ): Promise<TransactionSignature> {
46
+ ): Promise<TxSigAndSlot> {
47
47
  if (additionalSigners === undefined) {
48
48
  additionalSigners = [];
49
49
  }
@@ -86,8 +86,10 @@ export class RetryTxSender implements TxSender {
86
86
  }
87
87
  })();
88
88
 
89
+ let slot: number;
89
90
  try {
90
- await this.confirmTransaction(txid, opts.commitment);
91
+ const result = await this.confirmTransaction(txid, opts.commitment);
92
+ slot = result.context.slot;
91
93
  } catch (e) {
92
94
  console.error(e);
93
95
  throw e;
@@ -95,7 +97,7 @@ export class RetryTxSender implements TxSender {
95
97
  stopWaiting();
96
98
  }
97
99
 
98
- return txid;
100
+ return { txSig: txid, slot };
99
101
  }
100
102
 
101
103
  async prepareTx(
package/src/tx/types.ts CHANGED
@@ -6,6 +6,11 @@ import {
6
6
  TransactionSignature,
7
7
  } from '@solana/web3.js';
8
8
 
9
+ export type TxSigAndSlot = {
10
+ txSig: TransactionSignature;
11
+ slot: number;
12
+ };
13
+
9
14
  export interface TxSender {
10
15
  provider: Provider;
11
16
 
@@ -13,5 +18,5 @@ export interface TxSender {
13
18
  tx: Transaction,
14
19
  additionalSigners?: Array<Signer>,
15
20
  opts?: ConfirmOptions
16
- ): Promise<TransactionSignature>;
21
+ ): Promise<TxSigAndSlot>;
17
22
  }
package/src/tx/utils.ts CHANGED
@@ -1,5 +1,24 @@
1
- import { Transaction, TransactionInstruction } from '@solana/web3.js';
1
+ import {
2
+ Transaction,
3
+ TransactionInstruction,
4
+ ComputeBudgetProgram,
5
+ } from '@solana/web3.js';
2
6
 
3
- export function wrapInTx(instruction: TransactionInstruction): Transaction {
4
- return new Transaction().add(instruction);
7
+ const COMPUTE_UNITS_DEFAULT = 200_000;
8
+
9
+ export function wrapInTx(
10
+ instruction: TransactionInstruction,
11
+ computeUnits = 500_000 // TODO, requires less code change
12
+ ): Transaction {
13
+ const tx = new Transaction();
14
+ if (computeUnits != COMPUTE_UNITS_DEFAULT) {
15
+ tx.add(
16
+ ComputeBudgetProgram.requestUnits({
17
+ units: computeUnits,
18
+ additionalFee: 0,
19
+ })
20
+ );
21
+ }
22
+
23
+ return tx.add(instruction);
5
24
  }