@drift-labs/sdk 2.19.0 → 2.20.0-beta.1

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 (81) hide show
  1. package/lib/accounts/bulkAccountLoader.d.ts +2 -1
  2. package/lib/accounts/bulkAccountLoader.js +7 -7
  3. package/lib/accounts/fetch.d.ts +1 -0
  4. package/lib/accounts/fetch.js +8 -4
  5. package/lib/accounts/pollingDriftClientAccountSubscriber.js +7 -7
  6. package/lib/accounts/pollingTokenAccountSubscriber.js +2 -2
  7. package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
  8. package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
  9. package/lib/accounts/types.d.ts +5 -4
  10. package/lib/accounts/webSocketAccountSubscriber.js +1 -1
  11. package/lib/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
  12. package/lib/addresses/marketAddresses.js +1 -1
  13. package/lib/addresses/pda.js +5 -1
  14. package/lib/adminClient.js +61 -57
  15. package/lib/config.d.ts +2 -2
  16. package/lib/constants/perpMarkets.d.ts +1 -1
  17. package/lib/constants/spotMarkets.d.ts +1 -1
  18. package/lib/dlob/DLOB.d.ts +6 -5
  19. package/lib/dlob/DLOB.js +105 -75
  20. package/lib/dlob/DLOBNode.d.ts +2 -2
  21. package/lib/dlob/DLOBNode.js +7 -7
  22. package/lib/dlob/DLOBOrders.d.ts +2 -2
  23. package/lib/dlob/NodeList.d.ts +1 -1
  24. package/lib/dlob/NodeList.js +2 -2
  25. package/lib/driftClient.d.ts +5 -4
  26. package/lib/driftClient.js +139 -112
  27. package/lib/driftClientConfig.d.ts +3 -3
  28. package/lib/events/eventSubscriber.js +2 -2
  29. package/lib/events/fetchLogs.d.ts +2 -2
  30. package/lib/events/pollingLogProvider.js +1 -1
  31. package/lib/events/types.d.ts +14 -14
  32. package/lib/examples/loadDlob.js +2 -2
  33. package/lib/examples/makeTradeExample.js +9 -9
  34. package/lib/factory/bigNum.js +13 -13
  35. package/lib/factory/oracleClient.js +4 -4
  36. package/lib/idl/drift.json +52 -1
  37. package/lib/index.js +5 -1
  38. package/lib/math/amm.d.ts +1 -1
  39. package/lib/math/amm.js +23 -23
  40. package/lib/math/auction.js +6 -6
  41. package/lib/math/exchangeStatus.js +2 -2
  42. package/lib/math/funding.js +2 -2
  43. package/lib/math/margin.js +4 -4
  44. package/lib/math/market.js +15 -15
  45. package/lib/math/oracles.js +1 -1
  46. package/lib/math/orders.js +27 -24
  47. package/lib/math/position.js +5 -5
  48. package/lib/math/repeg.js +1 -1
  49. package/lib/math/spotBalance.js +9 -9
  50. package/lib/math/spotMarket.js +3 -3
  51. package/lib/math/spotPosition.js +3 -3
  52. package/lib/math/trade.d.ts +1 -1
  53. package/lib/math/trade.js +42 -42
  54. package/lib/math/utils.js +1 -1
  55. package/lib/oracles/oracleClientCache.js +1 -1
  56. package/lib/oracles/pythClient.js +1 -1
  57. package/lib/oracles/types.d.ts +2 -2
  58. package/lib/serum/types.d.ts +1 -1
  59. package/lib/slot/SlotSubscriber.d.ts +1 -1
  60. package/lib/tokenFaucet.js +5 -1
  61. package/lib/tx/retryTxSender.d.ts +1 -1
  62. package/lib/tx/retryTxSender.js +1 -1
  63. package/lib/tx/types.d.ts +1 -1
  64. package/lib/types.d.ts +66 -45
  65. package/lib/user.js +63 -63
  66. package/lib/userConfig.d.ts +2 -2
  67. package/lib/userMap/userMap.js +1 -1
  68. package/lib/userMap/userStatsMap.js +3 -3
  69. package/lib/userStats.js +2 -2
  70. package/lib/userStatsConfig.d.ts +2 -2
  71. package/package.json +1 -1
  72. package/src/accounts/bulkAccountLoader.ts +5 -5
  73. package/src/accounts/fetch.ts +8 -0
  74. package/src/dlob/DLOB.ts +55 -8
  75. package/src/driftClient.ts +57 -20
  76. package/src/idl/drift.json +52 -1
  77. package/src/math/orders.ts +5 -1
  78. package/src/types.ts +23 -1
  79. package/src/userMap/userStatsMap.ts +1 -4
  80. package/tests/amm/test.ts +24 -28
  81. package/tests/dlob/test.ts +67 -73
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -38,7 +42,7 @@ class AdminClient extends driftClient_1.DriftClient {
38
42
  if (stateAccountRPCResponse.value !== null) {
39
43
  throw new Error('Clearing house already initialized');
40
44
  }
41
- const [driftStatePublicKey] = await pda_1.getDriftStateAccountPublicKeyAndNonce(this.program.programId);
45
+ const [driftStatePublicKey] = await (0, pda_1.getDriftStateAccountPublicKeyAndNonce)(this.program.programId);
42
46
  const initializeTx = await this.program.transaction.initialize({
43
47
  accounts: {
44
48
  admin: this.wallet.publicKey,
@@ -55,10 +59,10 @@ class AdminClient extends driftClient_1.DriftClient {
55
59
  }
56
60
  async initializeSpotMarket(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = 0, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
57
61
  const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
58
- const spotMarket = await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex);
59
- const spotMarketVault = await pda_1.getSpotMarketVaultPublicKey(this.program.programId, spotMarketIndex);
60
- const insuranceFundVault = await pda_1.getInsuranceFundVaultPublicKey(this.program.programId, spotMarketIndex);
61
- const nameBuffer = userName_1.encodeName(name);
62
+ const spotMarket = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex);
63
+ const spotMarketVault = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, spotMarketIndex);
64
+ const insuranceFundVault = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, spotMarketIndex);
65
+ const nameBuffer = (0, userName_1.encodeName)(name);
62
66
  const initializeTx = await this.program.transaction.initializeSpotMarket(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidatorFee, activeStatus, nameBuffer, {
63
67
  accounts: {
64
68
  admin: this.wallet.publicKey,
@@ -83,8 +87,8 @@ class AdminClient extends driftClient_1.DriftClient {
83
87
  return txSig;
84
88
  }
85
89
  async initializeSerumFulfillmentConfig(marketIndex, serumMarket, serumProgram) {
86
- const serumOpenOrders = pda_1.getSerumOpenOrdersPublicKey(this.program.programId, serumMarket);
87
- const serumFulfillmentConfig = pda_1.getSerumFulfillmentConfigPublicKey(this.program.programId, serumMarket);
90
+ const serumOpenOrders = (0, pda_1.getSerumOpenOrdersPublicKey)(this.program.programId, serumMarket);
91
+ const serumFulfillmentConfig = (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
88
92
  const tx = await this.program.transaction.initializeSerumFulfillmentConfig(marketIndex, {
89
93
  accounts: {
90
94
  admin: this.wallet.publicKey,
@@ -105,8 +109,8 @@ class AdminClient extends driftClient_1.DriftClient {
105
109
  }
106
110
  async initializePerpMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
107
111
  const currentPerpMarketIndex = this.getStateAccount().numberOfMarkets;
108
- const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, currentPerpMarketIndex);
109
- const nameBuffer = userName_1.encodeName(name);
112
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, currentPerpMarketIndex);
113
+ const nameBuffer = (0, userName_1.encodeName)(name);
110
114
  const initializeMarketTx = await this.program.transaction.initializePerpMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidatorFee, activeStatus, nameBuffer, {
111
115
  accounts: {
112
116
  state: await this.getStatePublicKey(),
@@ -129,9 +133,9 @@ class AdminClient extends driftClient_1.DriftClient {
129
133
  return txSig;
130
134
  }
131
135
  async moveAmmPrice(perpMarketIndex, baseAssetReserve, quoteAssetReserve, sqrtK) {
132
- const marketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
136
+ const marketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
133
137
  if (sqrtK == undefined) {
134
- sqrtK = utils_1.squareRootBN(baseAssetReserve.mul(quoteAssetReserve));
138
+ sqrtK = (0, utils_1.squareRootBN)(baseAssetReserve.mul(quoteAssetReserve));
135
139
  }
136
140
  const tx = await this.program.transaction.moveAmmPrice(baseAssetReserve, quoteAssetReserve, sqrtK, {
137
141
  accounts: {
@@ -148,7 +152,7 @@ class AdminClient extends driftClient_1.DriftClient {
148
152
  accounts: {
149
153
  state: await this.getStatePublicKey(),
150
154
  admin: this.wallet.publicKey,
151
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
155
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
152
156
  oracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
153
157
  },
154
158
  });
@@ -160,16 +164,16 @@ class AdminClient extends driftClient_1.DriftClient {
160
164
  accounts: {
161
165
  state: await this.getStatePublicKey(),
162
166
  admin: this.wallet.publicKey,
163
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
167
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
164
168
  },
165
169
  });
166
170
  }
167
171
  async moveAmmToPrice(perpMarketIndex, targetPrice) {
168
172
  const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
169
- const [direction, tradeSize, _] = trade_1.calculateTargetPriceTrade(perpMarket, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
173
+ const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(perpMarket, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
170
174
  );
171
- const [newQuoteAssetAmount, newBaseAssetAmount] = amm_1.calculateAmmReservesAfterSwap(perpMarket.amm, 'quote', tradeSize, amm_1.getSwapDirection('quote', direction));
172
- const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
175
+ const [newQuoteAssetAmount, newBaseAssetAmount] = (0, amm_1.calculateAmmReservesAfterSwap)(perpMarket.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction));
176
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
173
177
  const tx = await this.program.transaction.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, perpMarket.amm.sqrtK, {
174
178
  accounts: {
175
179
  state: await this.getStatePublicKey(),
@@ -181,7 +185,7 @@ class AdminClient extends driftClient_1.DriftClient {
181
185
  return txSig;
182
186
  }
183
187
  async repegAmmCurve(newPeg, perpMarketIndex) {
184
- const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
188
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
185
189
  const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
186
190
  const tx = await this.program.transaction.repegAmmCurve(newPeg, {
187
191
  accounts: {
@@ -196,7 +200,7 @@ class AdminClient extends driftClient_1.DriftClient {
196
200
  }
197
201
  async updatePerpMarketAmmOracleTwap(perpMarketIndex) {
198
202
  const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
199
- const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
203
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
200
204
  return await this.program.rpc.updatePerpMarketAmmOracleTwap({
201
205
  accounts: {
202
206
  state: await this.getStatePublicKey(),
@@ -208,7 +212,7 @@ class AdminClient extends driftClient_1.DriftClient {
208
212
  }
209
213
  async resetPerpMarketAmmOracleTwap(perpMarketIndex) {
210
214
  const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
211
- const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
215
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
212
216
  return await this.program.rpc.resetPerpMarketAmmOracleTwap({
213
217
  accounts: {
214
218
  state: await this.getStatePublicKey(),
@@ -224,7 +228,7 @@ class AdminClient extends driftClient_1.DriftClient {
224
228
  accounts: {
225
229
  admin: this.wallet.publicKey,
226
230
  state: await this.getStatePublicKey(),
227
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
231
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
228
232
  sourceVault,
229
233
  driftSigner: this.getSignerPublicKey(),
230
234
  quoteSpotMarket: spotMarket.pubkey,
@@ -252,7 +256,7 @@ class AdminClient extends driftClient_1.DriftClient {
252
256
  accounts: {
253
257
  admin: this.wallet.publicKey,
254
258
  state: await this.getStatePublicKey(),
255
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
259
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
256
260
  },
257
261
  });
258
262
  }
@@ -261,7 +265,7 @@ class AdminClient extends driftClient_1.DriftClient {
261
265
  accounts: {
262
266
  admin: this.wallet.publicKey,
263
267
  state: await this.getStatePublicKey(),
264
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
268
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
265
269
  },
266
270
  });
267
271
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -272,7 +276,7 @@ class AdminClient extends driftClient_1.DriftClient {
272
276
  accounts: {
273
277
  admin: this.wallet.publicKey,
274
278
  state: await this.getStatePublicKey(),
275
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
279
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
276
280
  },
277
281
  });
278
282
  }
@@ -281,7 +285,7 @@ class AdminClient extends driftClient_1.DriftClient {
281
285
  accounts: {
282
286
  admin: this.wallet.publicKey,
283
287
  state: await this.getStatePublicKey(),
284
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
288
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
285
289
  },
286
290
  });
287
291
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -292,36 +296,36 @@ class AdminClient extends driftClient_1.DriftClient {
292
296
  accounts: {
293
297
  admin: this.wallet.publicKey,
294
298
  state: await this.getStatePublicKey(),
295
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
299
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
296
300
  },
297
301
  });
298
302
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
299
303
  return txSig;
300
304
  }
301
305
  async updatePerpMarketName(perpMarketIndex, name) {
302
- const nameBuffer = userName_1.encodeName(name);
306
+ const nameBuffer = (0, userName_1.encodeName)(name);
303
307
  const tx = await this.program.transaction.updatePerpMarketName(nameBuffer, {
304
308
  accounts: {
305
309
  admin: this.wallet.publicKey,
306
310
  state: await this.getStatePublicKey(),
307
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
311
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
308
312
  },
309
313
  });
310
314
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
311
315
  return txSig;
312
316
  }
313
317
  async updateSpotMarketName(spotMarketIndex, name) {
314
- const nameBuffer = userName_1.encodeName(name);
318
+ const nameBuffer = (0, userName_1.encodeName)(name);
315
319
  return await this.program.rpc.updateSpotMarketName(nameBuffer, {
316
320
  accounts: {
317
321
  admin: this.wallet.publicKey,
318
322
  state: await this.getStatePublicKey(),
319
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
323
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
320
324
  },
321
325
  });
322
326
  }
323
327
  async updatePerpMarketMaxSpread(perpMarketIndex, maxSpread) {
324
- const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
328
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
325
329
  return await this.program.rpc.updatePerpMarketMaxSpread(maxSpread, {
326
330
  accounts: {
327
331
  admin: this.wallet.publicKey,
@@ -389,7 +393,7 @@ class AdminClient extends driftClient_1.DriftClient {
389
393
  accounts: {
390
394
  admin: this.wallet.publicKey,
391
395
  state: await this.getStatePublicKey(),
392
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
396
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
393
397
  },
394
398
  });
395
399
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -400,7 +404,7 @@ class AdminClient extends driftClient_1.DriftClient {
400
404
  accounts: {
401
405
  admin: this.wallet.publicKey,
402
406
  state: await this.getStatePublicKey(),
403
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
407
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
404
408
  },
405
409
  });
406
410
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -411,7 +415,7 @@ class AdminClient extends driftClient_1.DriftClient {
411
415
  accounts: {
412
416
  admin: this.wallet.publicKey,
413
417
  state: await this.getStatePublicKey(),
414
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
418
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
415
419
  },
416
420
  });
417
421
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -422,7 +426,7 @@ class AdminClient extends driftClient_1.DriftClient {
422
426
  accounts: {
423
427
  admin: this.wallet.publicKey,
424
428
  state: await this.getStatePublicKey(),
425
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
429
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
426
430
  },
427
431
  });
428
432
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -433,7 +437,7 @@ class AdminClient extends driftClient_1.DriftClient {
433
437
  accounts: {
434
438
  admin: this.wallet.publicKey,
435
439
  state: await this.getStatePublicKey(),
436
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
440
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
437
441
  },
438
442
  });
439
443
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -454,7 +458,7 @@ class AdminClient extends driftClient_1.DriftClient {
454
458
  accounts: {
455
459
  admin: this.wallet.publicKey,
456
460
  state: await this.getStatePublicKey(),
457
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
461
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
458
462
  oracle: oracle,
459
463
  },
460
464
  });
@@ -466,7 +470,7 @@ class AdminClient extends driftClient_1.DriftClient {
466
470
  accounts: {
467
471
  admin: this.wallet.publicKey,
468
472
  state: await this.getStatePublicKey(),
469
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
473
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
470
474
  },
471
475
  });
472
476
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -477,7 +481,7 @@ class AdminClient extends driftClient_1.DriftClient {
477
481
  accounts: {
478
482
  admin: this.wallet.publicKey,
479
483
  state: await this.getStatePublicKey(),
480
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
484
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
481
485
  },
482
486
  });
483
487
  }
@@ -486,7 +490,7 @@ class AdminClient extends driftClient_1.DriftClient {
486
490
  accounts: {
487
491
  admin: this.wallet.publicKey,
488
492
  state: await this.getStatePublicKey(),
489
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
493
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
490
494
  },
491
495
  });
492
496
  }
@@ -495,7 +499,7 @@ class AdminClient extends driftClient_1.DriftClient {
495
499
  accounts: {
496
500
  admin: this.wallet.publicKey,
497
501
  state: await this.getStatePublicKey(),
498
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
502
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
499
503
  },
500
504
  });
501
505
  }
@@ -504,7 +508,7 @@ class AdminClient extends driftClient_1.DriftClient {
504
508
  accounts: {
505
509
  admin: this.wallet.publicKey,
506
510
  state: await this.getStatePublicKey(),
507
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
511
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
508
512
  },
509
513
  });
510
514
  }
@@ -513,7 +517,7 @@ class AdminClient extends driftClient_1.DriftClient {
513
517
  accounts: {
514
518
  admin: this.wallet.publicKey,
515
519
  state: await this.getStatePublicKey(),
516
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
520
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
517
521
  oracle: oracle,
518
522
  },
519
523
  });
@@ -523,7 +527,7 @@ class AdminClient extends driftClient_1.DriftClient {
523
527
  accounts: {
524
528
  admin: this.wallet.publicKey,
525
529
  state: await this.getStatePublicKey(),
526
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
530
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
527
531
  },
528
532
  });
529
533
  }
@@ -541,7 +545,7 @@ class AdminClient extends driftClient_1.DriftClient {
541
545
  accounts: {
542
546
  admin: this.wallet.publicKey,
543
547
  state: await this.getStatePublicKey(),
544
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
548
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
545
549
  },
546
550
  });
547
551
  }
@@ -570,7 +574,7 @@ class AdminClient extends driftClient_1.DriftClient {
570
574
  accounts: {
571
575
  admin: this.wallet.publicKey,
572
576
  state: await this.getStatePublicKey(),
573
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
577
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
574
578
  },
575
579
  });
576
580
  }
@@ -579,7 +583,7 @@ class AdminClient extends driftClient_1.DriftClient {
579
583
  accounts: {
580
584
  admin: this.wallet.publicKey,
581
585
  state: await this.getStatePublicKey(),
582
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
586
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
583
587
  },
584
588
  });
585
589
  }
@@ -588,7 +592,7 @@ class AdminClient extends driftClient_1.DriftClient {
588
592
  accounts: {
589
593
  admin: this.wallet.publicKey,
590
594
  state: await this.getStatePublicKey(),
591
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
595
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
592
596
  },
593
597
  });
594
598
  const { txSig } = await this.sendTransaction(tx);
@@ -599,7 +603,7 @@ class AdminClient extends driftClient_1.DriftClient {
599
603
  accounts: {
600
604
  admin: this.wallet.publicKey,
601
605
  state: await this.getStatePublicKey(),
602
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
606
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
603
607
  },
604
608
  });
605
609
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -610,7 +614,7 @@ class AdminClient extends driftClient_1.DriftClient {
610
614
  accounts: {
611
615
  admin: this.wallet.publicKey,
612
616
  state: await this.getStatePublicKey(),
613
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
617
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
614
618
  },
615
619
  });
616
620
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -621,7 +625,7 @@ class AdminClient extends driftClient_1.DriftClient {
621
625
  accounts: {
622
626
  admin: this.wallet.publicKey,
623
627
  state: await this.getStatePublicKey(),
624
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
628
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
625
629
  },
626
630
  });
627
631
  const { txSig } = await this.sendTransaction(tx, [], this.opts);
@@ -658,7 +662,7 @@ class AdminClient extends driftClient_1.DriftClient {
658
662
  accounts: {
659
663
  admin: this.wallet.publicKey,
660
664
  state: await this.getStatePublicKey(),
661
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
665
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
662
666
  },
663
667
  });
664
668
  }
@@ -676,7 +680,7 @@ class AdminClient extends driftClient_1.DriftClient {
676
680
  accounts: {
677
681
  admin: this.wallet.publicKey,
678
682
  state: await this.getStatePublicKey(),
679
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
683
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
680
684
  },
681
685
  });
682
686
  }
@@ -685,7 +689,7 @@ class AdminClient extends driftClient_1.DriftClient {
685
689
  accounts: {
686
690
  admin: this.wallet.publicKey,
687
691
  state: await this.getStatePublicKey(),
688
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
692
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
689
693
  },
690
694
  });
691
695
  }
@@ -694,7 +698,7 @@ class AdminClient extends driftClient_1.DriftClient {
694
698
  accounts: {
695
699
  admin: this.wallet.publicKey,
696
700
  state: await this.getStatePublicKey(),
697
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
701
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
698
702
  },
699
703
  });
700
704
  }
@@ -712,7 +716,7 @@ class AdminClient extends driftClient_1.DriftClient {
712
716
  accounts: {
713
717
  admin: this.wallet.publicKey,
714
718
  state: await this.getStatePublicKey(),
715
- perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
719
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
716
720
  },
717
721
  });
718
722
  }
@@ -721,7 +725,7 @@ class AdminClient extends driftClient_1.DriftClient {
721
725
  accounts: {
722
726
  admin: this.wallet.publicKey,
723
727
  state: await this.getStatePublicKey(),
724
- spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
728
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
725
729
  },
726
730
  });
727
731
  }
package/lib/config.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PerpMarketConfig } from './constants/perpMarkets';
2
2
  import { SpotMarketConfig } from './constants/spotMarkets';
3
3
  import { OracleInfo } from './oracles/types';
4
- declare type DriftConfig = {
4
+ type DriftConfig = {
5
5
  ENV: DriftEnv;
6
6
  PYTH_ORACLE_MAPPING_ADDRESS: string;
7
7
  DRIFT_PROGRAM_ID: string;
@@ -12,7 +12,7 @@ declare type DriftConfig = {
12
12
  SPOT_MARKETS: SpotMarketConfig[];
13
13
  MARKET_LOOKUP_TABLE: string;
14
14
  };
15
- export declare type DriftEnv = 'devnet' | 'mainnet-beta';
15
+ export type DriftEnv = 'devnet' | 'mainnet-beta';
16
16
  export declare const configs: {
17
17
  [key in DriftEnv]: DriftConfig;
18
18
  };
@@ -1,7 +1,7 @@
1
1
  import { OracleSource } from '../';
2
2
  import { DriftEnv } from '../';
3
3
  import { PublicKey } from '@solana/web3.js';
4
- export declare type PerpMarketConfig = {
4
+ export type PerpMarketConfig = {
5
5
  fullName?: string;
6
6
  category?: string[];
7
7
  symbol: string;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="bn.js" />
2
2
  import { PublicKey } from '@solana/web3.js';
3
3
  import { BN, DriftEnv, OracleSource } from '../';
4
- export declare type SpotMarketConfig = {
4
+ export type SpotMarketConfig = {
5
5
  symbol: string;
6
6
  marketIndex: number;
7
7
  oracle: PublicKey;
@@ -4,7 +4,7 @@ import { MarketType, BN, DriftClient, Order, SpotMarketAccount, PerpMarketAccoun
4
4
  import { PublicKey } from '@solana/web3.js';
5
5
  import { DLOBNode, DLOBNodeType, TriggerOrderNode } from '..';
6
6
  import { DLOBOrders } from './DLOBOrders';
7
- export declare type MarketNodeLists = {
7
+ export type MarketNodeLists = {
8
8
  restingLimit: {
9
9
  ask: NodeList<'restingLimit'>;
10
10
  bid: NodeList<'restingLimit'>;
@@ -26,12 +26,12 @@ export declare type MarketNodeLists = {
26
26
  below: NodeList<'trigger'>;
27
27
  };
28
28
  };
29
- declare type OrderBookCallback = () => void;
30
- export declare type NodeToFill = {
29
+ type OrderBookCallback = () => void;
30
+ export type NodeToFill = {
31
31
  node: DLOBNode;
32
- makerNode?: DLOBNode;
32
+ makerNodes: DLOBNode[];
33
33
  };
34
- export declare type NodeToTrigger = {
34
+ export type NodeToTrigger = {
35
35
  node: TriggerOrderNode;
36
36
  };
37
37
  export declare class DLOB {
@@ -61,6 +61,7 @@ export declare class DLOB {
61
61
  updateRestingLimitOrdersForMarketType(slot: number, marketTypeStr: MarketTypeStr): void;
62
62
  getOrder(orderId: number, userAccount: PublicKey): Order | undefined;
63
63
  findNodesToFill(marketIndex: number, fallbackBid: BN | undefined, fallbackAsk: BN | undefined, slot: number, ts: number, marketType: MarketType, oraclePriceData: OraclePriceData, stateAccount: StateAccount, marketAccount: PerpMarketAccount | SpotMarketAccount): NodeToFill[];
64
+ mergeNodesToFill(restingLimitOrderNodesToFill: NodeToFill[], takingOrderNodesToFill: NodeToFill[]): NodeToFill[];
64
65
  findRestingLimitOrderNodesToFill(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, isAmmPaused: boolean, minAuctionDuration: number, fallbackAsk: BN | undefined, fallbackBid: BN | undefined): NodeToFill[];
65
66
  findTakingNodesToFill(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, isAmmPaused: boolean, minAuctionDuration: number, fallbackAsk: BN | undefined, fallbackBid?: BN | undefined): NodeToFill[];
66
67
  findTakingNodesCrossingMakerNodes(marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, takerNodeGenerator: Generator<DLOBNode>, makerNodeGeneratorFn: (marketIndex: number, slot: number, marketType: MarketType, oraclePriceData: OraclePriceData, fallbackPrice?: BN) => Generator<DLOBNode>, doesCross: (takerPrice: BN | undefined, makerPrice: BN) => boolean, fallbackPrice?: BN): NodeToFill[];