@drift-labs/sdk 2.18.0 → 2.19.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 (86) hide show
  1. package/lib/accounts/bulkAccountLoader.d.ts +2 -1
  2. package/lib/accounts/bulkAccountLoader.js +3 -3
  3. package/lib/accounts/fetch.js +2 -2
  4. package/lib/accounts/pollingDriftClientAccountSubscriber.js +7 -7
  5. package/lib/accounts/pollingTokenAccountSubscriber.js +2 -2
  6. package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
  7. package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
  8. package/lib/accounts/types.d.ts +5 -4
  9. package/lib/accounts/webSocketAccountSubscriber.js +1 -1
  10. package/lib/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
  11. package/lib/addresses/marketAddresses.js +1 -1
  12. package/lib/addresses/pda.js +5 -1
  13. package/lib/adminClient.js +61 -57
  14. package/lib/config.d.ts +2 -2
  15. package/lib/constants/perpMarkets.d.ts +1 -1
  16. package/lib/constants/perpMarkets.js +33 -3
  17. package/lib/constants/spotMarkets.d.ts +1 -1
  18. package/lib/dlob/DLOB.d.ts +4 -4
  19. package/lib/dlob/DLOB.js +89 -76
  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 +2 -2
  24. package/lib/dlob/NodeList.js +4 -4
  25. package/lib/driftClient.d.ts +1 -1
  26. package/lib/driftClient.js +99 -95
  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 +6 -3
  36. package/lib/idl/drift.json +7 -4
  37. package/lib/index.js +5 -1
  38. package/lib/math/amm.d.ts +1 -1
  39. package/lib/math/amm.js +33 -38
  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 +24 -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 +43 -43
  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/serumSubscriber.d.ts +4 -3
  59. package/lib/serum/serumSubscriber.js +40 -11
  60. package/lib/serum/types.d.ts +3 -1
  61. package/lib/slot/SlotSubscriber.d.ts +1 -1
  62. package/lib/tokenFaucet.js +5 -1
  63. package/lib/tx/retryTxSender.d.ts +1 -1
  64. package/lib/tx/retryTxSender.js +1 -1
  65. package/lib/tx/types.d.ts +1 -1
  66. package/lib/types.d.ts +49 -46
  67. package/lib/types.js +2 -1
  68. package/lib/user.js +63 -63
  69. package/lib/userConfig.d.ts +2 -2
  70. package/lib/userMap/userMap.js +1 -1
  71. package/lib/userMap/userStatsMap.js +3 -3
  72. package/lib/userStats.js +2 -2
  73. package/lib/userStatsConfig.d.ts +2 -2
  74. package/package.json +1 -1
  75. package/src/constants/perpMarkets.ts +33 -3
  76. package/src/dlob/DLOB.ts +17 -5
  77. package/src/dlob/NodeList.ts +2 -5
  78. package/src/factory/oracleClient.ts +5 -1
  79. package/src/idl/drift.json +7 -4
  80. package/src/math/amm.ts +22 -23
  81. package/src/math/trade.ts +1 -1
  82. package/src/serum/serumSubscriber.ts +62 -20
  83. package/src/serum/types.ts +9 -5
  84. package/src/types.ts +2 -1
  85. package/tests/amm/test.ts +177 -5
  86. package/tests/dlob/test.ts +2 -1
package/lib/user.js CHANGED
@@ -13,6 +13,12 @@ const webSocketUserAccountSubscriber_1 = require("./accounts/webSocketUserAccoun
13
13
  const spotPosition_1 = require("./math/spotPosition");
14
14
  const oracles_1 = require("./math/oracles");
15
15
  class User {
16
+ get isSubscribed() {
17
+ return this._isSubscribed && this.accountSubscriber.isSubscribed;
18
+ }
19
+ set isSubscribed(val) {
20
+ this._isSubscribed = val;
21
+ }
16
22
  constructor(config) {
17
23
  var _a;
18
24
  this._isSubscribed = false;
@@ -26,12 +32,6 @@ class User {
26
32
  }
27
33
  this.eventEmitter = this.accountSubscriber.eventEmitter;
28
34
  }
29
- get isSubscribed() {
30
- return this._isSubscribed && this.accountSubscriber.isSubscribed;
31
- }
32
- set isSubscribed(val) {
33
- this._isSubscribed = val;
34
- }
35
35
  /**
36
36
  * Subscribe to User state accounts
37
37
  * @returns SusbcriptionSuccess result
@@ -142,7 +142,7 @@ class User {
142
142
  return [numericConstants_1.ZERO, numericConstants_1.ZERO];
143
143
  }
144
144
  const market = this.driftClient.getPerpMarketAccount(marketIndex);
145
- const [marketOpenBids, marketOpenAsks] = amm_1.calculateMarketOpenBidAsk(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.amm.orderStepSize);
145
+ const [marketOpenBids, marketOpenAsks] = (0, amm_1.calculateMarketOpenBidAsk)(market.amm.baseAssetReserve, market.amm.minBaseAssetReserve, market.amm.maxBaseAssetReserve, market.amm.orderStepSize);
146
146
  const lpOpenBids = marketOpenBids
147
147
  .mul(position.lpShares)
148
148
  .div(market.amm.sqrtK);
@@ -245,13 +245,13 @@ class User {
245
245
  getPerpBuyingPower(marketIndex) {
246
246
  const perpPosition = this.getPerpPosition(marketIndex);
247
247
  const worstCaseBaseAssetAmount = perpPosition
248
- ? margin_1.calculateWorstCaseBaseAssetAmount(perpPosition)
248
+ ? (0, margin_1.calculateWorstCaseBaseAssetAmount)(perpPosition)
249
249
  : numericConstants_1.ZERO;
250
250
  const freeCollateral = this.getFreeCollateral();
251
251
  return this.getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, worstCaseBaseAssetAmount);
252
252
  }
253
253
  getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex, freeCollateral, baseAssetAmount) {
254
- const marginRatio = _1.calculateMarketMarginRatio(this.driftClient.getPerpMarketAccount(marketIndex), baseAssetAmount, 'Initial');
254
+ const marginRatio = (0, _1.calculateMarketMarginRatio)(this.driftClient.getPerpMarketAccount(marketIndex), baseAssetAmount, 'Initial');
255
255
  return freeCollateral.mul(numericConstants_1.MARGIN_PRECISION).div(new _1.BN(marginRatio));
256
256
  }
257
257
  /**
@@ -302,11 +302,11 @@ class User {
302
302
  if (perpPosition.lpShares.gt(numericConstants_1.ZERO)) {
303
303
  perpPosition = this.getSettledLPPosition(perpPosition.marketIndex)[0];
304
304
  }
305
- let positionUnrealizedPnl = _1.calculatePositionPNL(market, perpPosition, withFunding, oraclePriceData);
305
+ let positionUnrealizedPnl = (0, _1.calculatePositionPNL)(market, perpPosition, withFunding, oraclePriceData);
306
306
  if (withWeightMarginCategory !== undefined) {
307
307
  if (positionUnrealizedPnl.gt(numericConstants_1.ZERO)) {
308
308
  positionUnrealizedPnl = positionUnrealizedPnl
309
- .mul(_1.calculateUnrealizedAssetWeight(market, quoteSpotMarket, positionUnrealizedPnl, withWeightMarginCategory, oraclePriceData))
309
+ .mul((0, _1.calculateUnrealizedAssetWeight)(market, quoteSpotMarket, positionUnrealizedPnl, withWeightMarginCategory, oraclePriceData))
310
310
  .div(new _1.BN(numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION));
311
311
  }
312
312
  }
@@ -322,7 +322,7 @@ class User {
322
322
  .perpPositions.filter((pos) => marketIndex ? pos.marketIndex === marketIndex : true)
323
323
  .reduce((pnl, perpPosition) => {
324
324
  const market = this.driftClient.getPerpMarketAccount(perpPosition.marketIndex);
325
- return pnl.add(_1.calculatePositionFundingPNL(market, perpPosition));
325
+ return pnl.add((0, _1.calculatePositionFundingPNL)(market, perpPosition));
326
326
  }, numericConstants_1.ZERO);
327
327
  }
328
328
  getSpotMarketAssetAndLiabilityValue(marketIndex, marginCategory, liquidationBuffer, includeOpenOrders, strict = false, now) {
@@ -335,15 +335,15 @@ class User {
335
335
  const countForQuote = marketIndex === undefined ||
336
336
  marketIndex === numericConstants_1.QUOTE_SPOT_MARKET_INDEX ||
337
337
  (includeOpenOrders && spotPosition.openOrders !== 0);
338
- if (spotPosition_1.isSpotPositionAvailable(spotPosition) ||
338
+ if ((0, spotPosition_1.isSpotPositionAvailable)(spotPosition) ||
339
339
  (!countForBase && !countForQuote)) {
340
340
  continue;
341
341
  }
342
342
  const spotMarketAccount = this.driftClient.getSpotMarketAccount(spotPosition.marketIndex);
343
343
  if (spotPosition.marketIndex === numericConstants_1.QUOTE_SPOT_MARKET_INDEX &&
344
344
  countForQuote) {
345
- if (types_1.isVariant(spotPosition.balanceType, 'borrow')) {
346
- const tokenAmount = spotBalance_1.getTokenAmount(spotPosition.scaledBalance, spotMarketAccount, spotPosition.balanceType);
345
+ if ((0, types_1.isVariant)(spotPosition.balanceType, 'borrow')) {
346
+ const tokenAmount = (0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarketAccount, spotPosition.balanceType);
347
347
  let weight = numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION;
348
348
  if (marginCategory === 'Initial') {
349
349
  weight = _1.BN.max(weight, new _1.BN(this.getUserAccount().maxMarginRatio));
@@ -355,27 +355,27 @@ class User {
355
355
  continue;
356
356
  }
357
357
  else {
358
- const tokenAmount = spotBalance_1.getTokenAmount(spotPosition.scaledBalance, spotMarketAccount, spotPosition.balanceType);
358
+ const tokenAmount = (0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarketAccount, spotPosition.balanceType);
359
359
  netQuoteValue = netQuoteValue.add(tokenAmount);
360
360
  continue;
361
361
  }
362
362
  }
363
363
  const oraclePriceData = this.getOracleDataForSpotMarket(spotPosition.marketIndex);
364
364
  if (!includeOpenOrders && countForBase) {
365
- if (types_1.isVariant(spotPosition.balanceType, 'borrow')) {
366
- const tokenAmount = spotBalance_1.getTokenAmount(spotPosition.scaledBalance, spotMarketAccount, spotPosition.balanceType);
365
+ if ((0, types_1.isVariant)(spotPosition.balanceType, 'borrow')) {
366
+ const tokenAmount = (0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarketAccount, spotPosition.balanceType);
367
367
  const liabilityValue = this.getSpotLiabilityValue(tokenAmount, oraclePriceData, spotMarketAccount, marginCategory, liquidationBuffer, strict, now);
368
368
  totalLiabilityValue = totalLiabilityValue.add(liabilityValue);
369
369
  continue;
370
370
  }
371
371
  else {
372
- const tokenAmount = spotBalance_1.getTokenAmount(spotPosition.scaledBalance, spotMarketAccount, spotPosition.balanceType);
372
+ const tokenAmount = (0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarketAccount, spotPosition.balanceType);
373
373
  const assetValue = this.getSpotAssetValue(tokenAmount, oraclePriceData, spotMarketAccount, marginCategory, strict, now);
374
374
  totalAssetValue = totalAssetValue.add(assetValue);
375
375
  continue;
376
376
  }
377
377
  }
378
- const [worstCaseTokenAmount, worstCaseQuoteTokenAmount] = spotPosition_1.getWorstCaseTokenAmounts(spotPosition, spotMarketAccount, this.getOracleDataForSpotMarket(spotPosition.marketIndex));
378
+ const [worstCaseTokenAmount, worstCaseQuoteTokenAmount] = (0, spotPosition_1.getWorstCaseTokenAmounts)(spotPosition, spotMarketAccount, this.getOracleDataForSpotMarket(spotPosition.marketIndex));
379
379
  if (worstCaseTokenAmount.gt(numericConstants_1.ZERO) && countForBase) {
380
380
  const baseAssetValue = this.getSpotAssetValue(worstCaseTokenAmount, oraclePriceData, spotMarketAccount, marginCategory, strict, now);
381
381
  totalAssetValue = totalAssetValue.add(baseAssetValue);
@@ -417,15 +417,15 @@ class User {
417
417
  getSpotLiabilityValue(tokenAmount, oraclePriceData, spotMarketAccount, marginCategory, liquidationBuffer, strict = false, now) {
418
418
  let liabilityValue = null;
419
419
  if (strict && spotMarketAccount.marketIndex != numericConstants_1.QUOTE_SPOT_MARKET_INDEX) {
420
- const estOracleTwap = oracles_1.calculateLiveOracleTwap(spotMarketAccount.historicalOracleData, oraclePriceData, now, numericConstants_1.FIVE_MINUTE // 5MIN
420
+ const estOracleTwap = (0, oracles_1.calculateLiveOracleTwap)(spotMarketAccount.historicalOracleData, oraclePriceData, now, numericConstants_1.FIVE_MINUTE // 5MIN
421
421
  );
422
- liabilityValue = _1.getStrictTokenValue(tokenAmount, spotMarketAccount.decimals, oraclePriceData, estOracleTwap);
422
+ liabilityValue = (0, _1.getStrictTokenValue)(tokenAmount, spotMarketAccount.decimals, oraclePriceData, estOracleTwap);
423
423
  }
424
424
  else {
425
- liabilityValue = _1.getTokenValue(tokenAmount, spotMarketAccount.decimals, oraclePriceData);
425
+ liabilityValue = (0, _1.getTokenValue)(tokenAmount, spotMarketAccount.decimals, oraclePriceData);
426
426
  }
427
427
  if (marginCategory !== undefined) {
428
- let weight = spotBalance_1.calculateLiabilityWeight(tokenAmount, spotMarketAccount, marginCategory);
428
+ let weight = (0, spotBalance_1.calculateLiabilityWeight)(tokenAmount, spotMarketAccount, marginCategory);
429
429
  if (marginCategory === 'Initial') {
430
430
  weight = _1.BN.max(weight, new _1.BN(this.getUserAccount().maxMarginRatio));
431
431
  }
@@ -445,22 +445,22 @@ class User {
445
445
  getSpotAssetValue(tokenAmount, oraclePriceData, spotMarketAccount, marginCategory, strict = false, now) {
446
446
  let assetValue = null;
447
447
  if (strict && spotMarketAccount.marketIndex != numericConstants_1.QUOTE_SPOT_MARKET_INDEX) {
448
- const estOracleTwap = oracles_1.calculateLiveOracleTwap(spotMarketAccount.historicalOracleData, oraclePriceData, now, numericConstants_1.FIVE_MINUTE // 5MIN
448
+ const estOracleTwap = (0, oracles_1.calculateLiveOracleTwap)(spotMarketAccount.historicalOracleData, oraclePriceData, now, numericConstants_1.FIVE_MINUTE // 5MIN
449
449
  );
450
- assetValue = _1.getStrictTokenValue(tokenAmount, spotMarketAccount.decimals, oraclePriceData, estOracleTwap);
450
+ assetValue = (0, _1.getStrictTokenValue)(tokenAmount, spotMarketAccount.decimals, oraclePriceData, estOracleTwap);
451
451
  }
452
452
  else {
453
- assetValue = _1.getTokenValue(tokenAmount, spotMarketAccount.decimals, oraclePriceData);
453
+ assetValue = (0, _1.getTokenValue)(tokenAmount, spotMarketAccount.decimals, oraclePriceData);
454
454
  }
455
455
  if (marginCategory !== undefined) {
456
- const weight = spotBalance_1.calculateAssetWeight(tokenAmount, spotMarketAccount, marginCategory);
456
+ const weight = (0, spotBalance_1.calculateAssetWeight)(tokenAmount, spotMarketAccount, marginCategory);
457
457
  assetValue = assetValue.mul(weight).div(numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION);
458
458
  }
459
459
  return assetValue;
460
460
  }
461
461
  getSpotTokenAmount(marketIndex) {
462
462
  const spotPosition = this.getSpotPosition(marketIndex);
463
- return spotBalance_1.getTokenAmount(spotPosition.scaledBalance, this.driftClient.getSpotMarketAccount(marketIndex), spotPosition.balanceType);
463
+ return (0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, this.driftClient.getSpotMarketAccount(marketIndex), spotPosition.balanceType);
464
464
  }
465
465
  getSpotPositionValue(marketIndex, marginCategory, includeOpenOrders, strict = false, now) {
466
466
  const { totalAssetValue, totalLiabilityValue } = this.getSpotMarketAssetAndLiabilityValue(marketIndex, marginCategory, undefined, includeOpenOrders, strict, now);
@@ -483,8 +483,8 @@ class User {
483
483
  */
484
484
  getHealth() {
485
485
  const userAccount = this.getUserAccount();
486
- if (types_1.isVariant(userAccount.status, 'beingLiquidated') ||
487
- types_1.isVariant(userAccount.status, 'bankrupt')) {
486
+ if ((0, types_1.isVariant)(userAccount.status, 'beingLiquidated') ||
487
+ (0, types_1.isVariant)(userAccount.status, 'bankrupt')) {
488
488
  return 0;
489
489
  }
490
490
  const totalCollateral = this.getTotalCollateral('Maintenance');
@@ -530,25 +530,25 @@ class User {
530
530
  perpPosition.openBids = totalOpenBids;
531
531
  }
532
532
  let valuationPrice = this.getOracleDataForPerpMarket(market.marketIndex).price;
533
- if (types_1.isVariant(market.status, 'settlement')) {
533
+ if ((0, types_1.isVariant)(market.status, 'settlement')) {
534
534
  valuationPrice = market.expiryPrice;
535
535
  }
536
536
  const baseAssetAmount = includeOpenOrders
537
- ? margin_1.calculateWorstCaseBaseAssetAmount(perpPosition)
537
+ ? (0, margin_1.calculateWorstCaseBaseAssetAmount)(perpPosition)
538
538
  : perpPosition.baseAssetAmount;
539
539
  let baseAssetValue = baseAssetAmount
540
540
  .abs()
541
541
  .mul(valuationPrice)
542
542
  .div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO.mul(numericConstants_1.PRICE_PRECISION));
543
543
  if (marginCategory) {
544
- let marginRatio = new _1.BN(_1.calculateMarketMarginRatio(market, baseAssetAmount.abs(), marginCategory));
544
+ let marginRatio = new _1.BN((0, _1.calculateMarketMarginRatio)(market, baseAssetAmount.abs(), marginCategory));
545
545
  if (marginCategory === 'Initial') {
546
546
  marginRatio = _1.BN.max(marginRatio, new _1.BN(this.getUserAccount().maxMarginRatio));
547
547
  }
548
548
  if (liquidationBuffer !== undefined) {
549
549
  marginRatio = marginRatio.add(liquidationBuffer);
550
550
  }
551
- if (types_1.isVariant(market.status, 'settlement')) {
551
+ if ((0, types_1.isVariant)(market.status, 'settlement')) {
552
552
  marginRatio = numericConstants_1.ZERO;
553
553
  }
554
554
  baseAssetValue = baseAssetValue
@@ -568,7 +568,7 @@ class User {
568
568
  getPerpPositionValue(marketIndex, oraclePriceData, includeOpenOrders = false) {
569
569
  const userPosition = this.getPerpPosition(marketIndex) || this.getEmptyPosition(marketIndex);
570
570
  const market = this.driftClient.getPerpMarketAccount(userPosition.marketIndex);
571
- return margin_1.calculateBaseAssetValueWithOracle(market, userPosition, oraclePriceData, includeOpenOrders);
571
+ return (0, margin_1.calculateBaseAssetValueWithOracle)(market, userPosition, oraclePriceData, includeOpenOrders);
572
572
  }
573
573
  getPositionSide(currentPosition) {
574
574
  if (currentPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
@@ -587,11 +587,11 @@ class User {
587
587
  */
588
588
  getPositionEstimatedExitPriceAndPnl(position, amountToClose, useAMMClose = false) {
589
589
  const market = this.driftClient.getPerpMarketAccount(position.marketIndex);
590
- const entryPrice = position_1.calculateEntryPrice(position);
590
+ const entryPrice = (0, position_1.calculateEntryPrice)(position);
591
591
  const oraclePriceData = this.getOracleDataForPerpMarket(position.marketIndex);
592
592
  if (amountToClose) {
593
593
  if (amountToClose.eq(numericConstants_1.ZERO)) {
594
- return [_1.calculateReservePrice(market, oraclePriceData), numericConstants_1.ZERO];
594
+ return [(0, _1.calculateReservePrice)(market, oraclePriceData), numericConstants_1.ZERO];
595
595
  }
596
596
  position = {
597
597
  baseAssetAmount: amountToClose,
@@ -602,10 +602,10 @@ class User {
602
602
  }
603
603
  let baseAssetValue;
604
604
  if (useAMMClose) {
605
- baseAssetValue = _1.calculateBaseAssetValue(market, position, oraclePriceData);
605
+ baseAssetValue = (0, _1.calculateBaseAssetValue)(market, position, oraclePriceData);
606
606
  }
607
607
  else {
608
- baseAssetValue = margin_1.calculateBaseAssetValueWithOracle(market, position, oraclePriceData);
608
+ baseAssetValue = (0, margin_1.calculateBaseAssetValueWithOracle)(market, position, oraclePriceData);
609
609
  }
610
610
  if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
611
611
  return [numericConstants_1.ZERO, numericConstants_1.ZERO];
@@ -667,7 +667,7 @@ class User {
667
667
  return numericConstants_1.ZERO;
668
668
  }
669
669
  const totalLiabilityValue = perpLiabilityValue.add(spotLiabilityValue);
670
- const marginRatio = _1.calculateMarketMarginRatio(market, numericConstants_1.ZERO, // todo
670
+ const marginRatio = (0, _1.calculateMarketMarginRatio)(market, numericConstants_1.ZERO, // todo
671
671
  category);
672
672
  const freeCollateral = this.getFreeCollateral();
673
673
  // how much more liabilities can be opened w remaining free collateral
@@ -702,14 +702,14 @@ class User {
702
702
  const tradeQuoteAmount = this.getMaxTradeSizeUSDCForSpot(spotMarketIndex, direction, currentQuoteAssetValue, currentSpotMarketNetValue);
703
703
  let assetValueToAdd = numericConstants_1.ZERO;
704
704
  let liabilityValueToAdd = numericConstants_1.ZERO;
705
- const newQuoteNetValue = types_1.isVariant(direction, 'short')
705
+ const newQuoteNetValue = (0, types_1.isVariant)(direction, 'short')
706
706
  ? currentQuoteValue.add(tradeQuoteAmount)
707
707
  : currentQuoteValue.sub(tradeQuoteAmount);
708
708
  const newQuoteAssetValue = _1.BN.max(newQuoteNetValue, numericConstants_1.ZERO);
709
709
  const newQuoteLiabilityValue = _1.BN.min(newQuoteNetValue, numericConstants_1.ZERO).abs();
710
710
  assetValueToAdd = assetValueToAdd.add(newQuoteAssetValue.sub(currentQuoteAssetValue));
711
711
  liabilityValueToAdd = liabilityValueToAdd.add(newQuoteLiabilityValue.sub(currentQuoteLiabilityValue));
712
- const newSpotMarketNetValue = types_1.isVariant(direction, 'long')
712
+ const newSpotMarketNetValue = (0, types_1.isVariant)(direction, 'long')
713
713
  ? currentSpotMarketNetValue.add(tradeQuoteAmount)
714
714
  : currentSpotMarketNetValue.sub(tradeQuoteAmount);
715
715
  const newSpotMarketAssetValue = _1.BN.max(newSpotMarketNetValue, numericConstants_1.ZERO);
@@ -740,7 +740,7 @@ class User {
740
740
  const totalCollateral = this.getTotalCollateral('Maintenance');
741
741
  // if user being liq'd, can continue to be liq'd until total collateral above the margin requirement plus buffer
742
742
  let liquidationBuffer = undefined;
743
- const isBeingLiquidated = types_1.isVariant(this.getUserAccount().status, 'beingLiquidated');
743
+ const isBeingLiquidated = (0, types_1.isVariant)(this.getUserAccount().status, 'beingLiquidated');
744
744
  if (isBeingLiquidated) {
745
745
  liquidationBuffer = new _1.BN(this.driftClient.getStateAccount().liquidationMarginBufferRatio);
746
746
  }
@@ -748,13 +748,13 @@ class User {
748
748
  return totalCollateral.lt(maintenanceRequirement);
749
749
  }
750
750
  isBeingLiquidated() {
751
- return types_1.isOneOfVariant(this.getUserAccount().status, [
751
+ return (0, types_1.isOneOfVariant)(this.getUserAccount().status, [
752
752
  'beingLiquidated',
753
753
  'bankrupt',
754
754
  ]);
755
755
  }
756
756
  isBankrupt() {
757
- return types_1.isVariant(this.getUserAccount().status, 'bankrupt');
757
+ return (0, types_1.isVariant)(this.getUserAccount().status, 'bankrupt');
758
758
  }
759
759
  /**
760
760
  * Checks if any user position cumulative funding differs from respective market cumulative funding
@@ -788,7 +788,7 @@ class User {
788
788
  const maintenanceMarginRequirement = this.getMaintenanceMarginRequirement();
789
789
  const freeCollateral = _1.BN.max(numericConstants_1.ZERO, totalCollateral.sub(maintenanceMarginRequirement));
790
790
  const market = this.driftClient.getSpotMarketAccount(marketIndex);
791
- let signedTokenAmount = _1.getSignedTokenAmount(spotBalance_1.getTokenAmount(currentSpotPosition.scaledBalance, market, currentSpotPosition.balanceType), currentSpotPosition.balanceType);
791
+ let signedTokenAmount = (0, _1.getSignedTokenAmount)((0, spotBalance_1.getTokenAmount)(currentSpotPosition.scaledBalance, market, currentSpotPosition.balanceType), currentSpotPosition.balanceType);
792
792
  signedTokenAmount = signedTokenAmount.add(positionBaseSizeChange);
793
793
  if (signedTokenAmount.eq(numericConstants_1.ZERO)) {
794
794
  return new _1.BN(-1);
@@ -841,7 +841,7 @@ class User {
841
841
  if (spotMarketWithSameOracle) {
842
842
  const spotPosition = this.getSpotPosition(spotMarketWithSameOracle.marketIndex);
843
843
  if (spotPosition) {
844
- const signedTokenAmount = _1.getSignedTokenAmount(spotBalance_1.getTokenAmount(spotPosition.scaledBalance, spotMarketWithSameOracle, spotPosition.balanceType), spotPosition.balanceType);
844
+ const signedTokenAmount = (0, _1.getSignedTokenAmount)((0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarketWithSameOracle, spotPosition.balanceType), spotPosition.balanceType);
845
845
  const spotFreeCollateralDelta = this.calculateFreeCollateralDeltaForSpot(spotMarketWithSameOracle, signedTokenAmount);
846
846
  freeCollateralDelta = freeCollateralDelta.add(spotFreeCollateralDelta || numericConstants_1.ZERO);
847
847
  }
@@ -861,11 +861,11 @@ class User {
861
861
  }
862
862
  calculateFreeCollateralDeltaForPerp(market, perpPosition, positionBaseSizeChange) {
863
863
  const currentBaseAssetAmount = perpPosition.baseAssetAmount;
864
- const worstCaseBaseAssetAmount = margin_1.calculateWorstCaseBaseAssetAmount(perpPosition);
864
+ const worstCaseBaseAssetAmount = (0, margin_1.calculateWorstCaseBaseAssetAmount)(perpPosition);
865
865
  const orderBaseAssetAmount = worstCaseBaseAssetAmount.sub(currentBaseAssetAmount);
866
866
  const proposedBaseAssetAmount = currentBaseAssetAmount.add(positionBaseSizeChange);
867
867
  const proposedWorstCaseBaseAssetAmount = worstCaseBaseAssetAmount.add(positionBaseSizeChange);
868
- const marginRatio = _1.calculateMarketMarginRatio(market, proposedWorstCaseBaseAssetAmount.abs(), 'Maintenance');
868
+ const marginRatio = (0, _1.calculateMarketMarginRatio)(market, proposedWorstCaseBaseAssetAmount.abs(), 'Maintenance');
869
869
  const marginRatioQuotePrecision = new _1.BN(marginRatio)
870
870
  .mul(numericConstants_1.QUOTE_PRECISION)
871
871
  .div(numericConstants_1.MARGIN_PRECISION);
@@ -892,14 +892,14 @@ class User {
892
892
  calculateFreeCollateralDeltaForSpot(market, signedTokenAmount) {
893
893
  const tokenPrecision = new _1.BN(Math.pow(10, market.decimals));
894
894
  if (signedTokenAmount.gt(numericConstants_1.ZERO)) {
895
- const assetWeight = spotBalance_1.calculateAssetWeight(signedTokenAmount, market, 'Maintenance');
895
+ const assetWeight = (0, spotBalance_1.calculateAssetWeight)(signedTokenAmount, market, 'Maintenance');
896
896
  return numericConstants_1.QUOTE_PRECISION.mul(assetWeight)
897
897
  .div(numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION)
898
898
  .mul(signedTokenAmount)
899
899
  .div(tokenPrecision);
900
900
  }
901
901
  else {
902
- const liabilityWeight = spotBalance_1.calculateLiabilityWeight(signedTokenAmount.abs(), market, 'Maintenance');
902
+ const liabilityWeight = (0, spotBalance_1.calculateLiabilityWeight)(signedTokenAmount.abs(), market, 'Maintenance');
903
903
  return numericConstants_1.QUOTE_PRECISION.neg()
904
904
  .mul(liabilityWeight)
905
905
  .div(numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION)
@@ -949,7 +949,7 @@ class User {
949
949
  getMaxTradeSizeUSDCForPerp(targetMarketIndex, tradeSide) {
950
950
  const currentPosition = this.getPerpPosition(targetMarketIndex) ||
951
951
  this.getEmptyPosition(targetMarketIndex);
952
- const targetSide = types_1.isVariant(tradeSide, 'short') ? 'short' : 'long';
952
+ const targetSide = (0, types_1.isVariant)(tradeSide, 'short') ? 'short' : 'long';
953
953
  const currentPositionSide = (currentPosition === null || currentPosition === void 0 ? void 0 : currentPosition.baseAssetAmount.isNeg())
954
954
  ? 'short'
955
955
  : 'long';
@@ -1013,26 +1013,26 @@ class User {
1013
1013
  currentSpotMarketNetValue =
1014
1014
  currentSpotMarketNetValue !== null && currentSpotMarketNetValue !== void 0 ? currentSpotMarketNetValue : this.getSpotPositionValue(targetMarketIndex);
1015
1015
  let freeCollateral = this.getFreeCollateral();
1016
- const marginRatio = _1.calculateSpotMarketMarginRatio(market, 'Initial', numericConstants_1.ZERO, types_1.isVariant(direction, 'long')
1016
+ const marginRatio = (0, _1.calculateSpotMarketMarginRatio)(market, 'Initial', numericConstants_1.ZERO, (0, types_1.isVariant)(direction, 'long')
1017
1017
  ? _1.SpotBalanceType.DEPOSIT
1018
1018
  : _1.SpotBalanceType.BORROW);
1019
1019
  let tradeAmount = numericConstants_1.ZERO;
1020
1020
  if (this.getUserAccount().isMarginTradingEnabled) {
1021
1021
  // if the user is buying/selling and already short/long, need to account for closing out short/long
1022
- if (types_1.isVariant(direction, 'long') && currentSpotMarketNetValue.lt(numericConstants_1.ZERO)) {
1022
+ if ((0, types_1.isVariant)(direction, 'long') && currentSpotMarketNetValue.lt(numericConstants_1.ZERO)) {
1023
1023
  tradeAmount = currentSpotMarketNetValue.abs();
1024
- const marginRatio = _1.calculateSpotMarketMarginRatio(market, 'Initial', this.getSpotTokenAmount(targetMarketIndex), _1.SpotBalanceType.BORROW);
1024
+ const marginRatio = (0, _1.calculateSpotMarketMarginRatio)(market, 'Initial', this.getSpotTokenAmount(targetMarketIndex), _1.SpotBalanceType.BORROW);
1025
1025
  freeCollateral = freeCollateral.add(tradeAmount.mul(new _1.BN(marginRatio)).div(numericConstants_1.MARGIN_PRECISION));
1026
1026
  }
1027
- else if (types_1.isVariant(direction, 'short') &&
1027
+ else if ((0, types_1.isVariant)(direction, 'short') &&
1028
1028
  currentSpotMarketNetValue.gt(numericConstants_1.ZERO)) {
1029
1029
  tradeAmount = currentSpotMarketNetValue;
1030
- const marginRatio = _1.calculateSpotMarketMarginRatio(market, 'Initial', this.getSpotTokenAmount(targetMarketIndex), _1.SpotBalanceType.DEPOSIT);
1030
+ const marginRatio = (0, _1.calculateSpotMarketMarginRatio)(market, 'Initial', this.getSpotTokenAmount(targetMarketIndex), _1.SpotBalanceType.DEPOSIT);
1031
1031
  freeCollateral = freeCollateral.add(tradeAmount.mul(new _1.BN(marginRatio)).div(numericConstants_1.MARGIN_PRECISION));
1032
1032
  }
1033
1033
  tradeAmount = tradeAmount.add(freeCollateral.mul(numericConstants_1.MARGIN_PRECISION).div(new _1.BN(marginRatio)));
1034
1034
  }
1035
- else if (types_1.isVariant(direction, 'long')) {
1035
+ else if ((0, types_1.isVariant)(direction, 'long')) {
1036
1036
  tradeAmount = _1.BN.min(currentQuoteAssetValue, freeCollateral.mul(numericConstants_1.MARGIN_PRECISION).div(new _1.BN(marginRatio)));
1037
1037
  }
1038
1038
  else {
@@ -1051,7 +1051,7 @@ class User {
1051
1051
  * @returns leverageRatio : Precision TEN_THOUSAND
1052
1052
  */
1053
1053
  accountLeverageRatioAfterTrade(targetMarketIndex, targetMarketType, tradeQuoteAmount, tradeSide, includeOpenOrders = true) {
1054
- const tradeIsPerp = types_1.isVariant(targetMarketType, 'perp');
1054
+ const tradeIsPerp = (0, types_1.isVariant)(targetMarketType, 'perp');
1055
1055
  if (!tradeIsPerp) {
1056
1056
  // calculate new asset/liability values for base and quote market to find new account leverage
1057
1057
  const totalLiabilityValue = this.getTotalLiabilityValue();
@@ -1142,7 +1142,7 @@ class User {
1142
1142
  const nowTs = new _1.BN(Math.floor(Date.now() / 1000));
1143
1143
  const spotMarket = this.driftClient.getSpotMarketAccount(marketIndex);
1144
1144
  // eslint-disable-next-line prefer-const
1145
- let { borrowLimit, withdrawLimit } = spotBalance_1.calculateWithdrawLimit(spotMarket, nowTs);
1145
+ let { borrowLimit, withdrawLimit } = (0, spotBalance_1.calculateWithdrawLimit)(spotMarket, nowTs);
1146
1146
  const freeCollateral = this.getFreeCollateral();
1147
1147
  const oracleData = this.getOracleDataForSpotMarket(marketIndex);
1148
1148
  const precisionIncrease = numericConstants_1.TEN.pow(new _1.BN(spotMarket.decimals - 6));
@@ -1188,7 +1188,7 @@ class User {
1188
1188
  netDeposits,
1189
1189
  };
1190
1190
  }
1191
- if (types_1.isVariant(position.balanceType, 'borrow')) {
1191
+ if ((0, types_1.isVariant)(position.balanceType, 'borrow')) {
1192
1192
  return {
1193
1193
  canBypass: false,
1194
1194
  maxDepositAmount,
@@ -1196,7 +1196,7 @@ class User {
1196
1196
  depositAmount: numericConstants_1.ZERO,
1197
1197
  };
1198
1198
  }
1199
- const depositAmount = spotBalance_1.getTokenAmount(position.scaledBalance, spotMarket, _1.SpotBalanceType.DEPOSIT);
1199
+ const depositAmount = (0, spotBalance_1.getTokenAmount)(position.scaledBalance, spotMarket, _1.SpotBalanceType.DEPOSIT);
1200
1200
  if (netDeposits.lt(numericConstants_1.ZERO)) {
1201
1201
  return {
1202
1202
  canBypass: false,
@@ -1,12 +1,12 @@
1
1
  import { DriftClient } from './driftClient';
2
2
  import { PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
- export declare type UserConfig = {
4
+ export type UserConfig = {
5
5
  accountSubscription?: UserSubscriptionConfig;
6
6
  driftClient: DriftClient;
7
7
  userAccountPublicKey: PublicKey;
8
8
  };
9
- export declare type UserSubscriptionConfig = {
9
+ export type UserSubscriptionConfig = {
10
10
  type: 'websocket';
11
11
  } | {
12
12
  type: 'polling';
@@ -26,7 +26,7 @@ class UserMap {
26
26
  userAccountArray.push(programUserAccount.account);
27
27
  }
28
28
  if (this.accountSubscription.type === 'polling') {
29
- await __1.bulkPollingUserSubscribe(userArray, this.accountSubscription.accountLoader);
29
+ await (0, __1.bulkPollingUserSubscribe)(userArray, this.accountSubscription.accountLoader);
30
30
  }
31
31
  else {
32
32
  await Promise.all(userArray.map((user, i) => user.subscribe(userAccountArray[i])));
@@ -23,14 +23,14 @@ class UserStatsMap {
23
23
  }
24
24
  const chUserStat = new __1.UserStats({
25
25
  driftClient: this.driftClient,
26
- userStatsAccountPublicKey: __1.getUserStatsAccountPublicKey(this.driftClient.program.programId, userStat.authority),
26
+ userStatsAccountPublicKey: (0, __1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, userStat.authority),
27
27
  accountSubscription: this.accountSubscription,
28
28
  });
29
29
  userStatArray.push(chUserStat);
30
30
  userStatsAccountArray.push(userStat);
31
31
  }
32
32
  if (this.accountSubscription.type === 'polling') {
33
- await __1.bulkPollingUserStatsSubscribe(userStatArray, this.accountSubscription.accountLoader);
33
+ await (0, __1.bulkPollingUserStatsSubscribe)(userStatArray, this.accountSubscription.accountLoader);
34
34
  }
35
35
  else {
36
36
  await Promise.all(userStatArray.map((userStat, i) => userStat.subscribe(userStatsAccountArray[i])));
@@ -42,7 +42,7 @@ class UserStatsMap {
42
42
  async addUserStat(authority) {
43
43
  const userStat = new __1.UserStats({
44
44
  driftClient: this.driftClient,
45
- userStatsAccountPublicKey: __1.getUserStatsAccountPublicKey(this.driftClient.program.programId, authority),
45
+ userStatsAccountPublicKey: (0, __1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, authority),
46
46
  accountSubscription: this.accountSubscription,
47
47
  });
48
48
  await userStat.subscribe();
package/lib/userStats.js CHANGED
@@ -40,8 +40,8 @@ class UserStats {
40
40
  }
41
41
  else {
42
42
  return {
43
- referrer: pda_1.getUserAccountPublicKeySync(this.driftClient.program.programId, this.getAccount().referrer, 0),
44
- referrerStats: pda_1.getUserStatsAccountPublicKey(this.driftClient.program.programId, this.getAccount().referrer),
43
+ referrer: (0, pda_1.getUserAccountPublicKeySync)(this.driftClient.program.programId, this.getAccount().referrer, 0),
44
+ referrerStats: (0, pda_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, this.getAccount().referrer),
45
45
  };
46
46
  }
47
47
  }
@@ -1,12 +1,12 @@
1
1
  import { DriftClient } from './driftClient';
2
2
  import { PublicKey } from '@solana/web3.js';
3
3
  import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
- export declare type UserStatsConfig = {
4
+ export type UserStatsConfig = {
5
5
  accountSubscription?: UserStatsSubscriptionConfig;
6
6
  driftClient: DriftClient;
7
7
  userStatsAccountPublicKey: PublicKey;
8
8
  };
9
- export declare type UserStatsSubscriptionConfig = {
9
+ export type UserStatsSubscriptionConfig = {
10
10
  type: 'websocket';
11
11
  } | {
12
12
  type: 'polling';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.18.0",
3
+ "version": "2.19.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -57,12 +57,22 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
57
57
  {
58
58
  fullName: 'Bonk',
59
59
  category: ['Meme'],
60
- symbol: 'BONK-PERP',
61
- baseAssetSymbol: 'BONK',
60
+ symbol: '1MBONK-PERP',
61
+ baseAssetSymbol: '1MBONK',
62
62
  marketIndex: 4,
63
63
  oracle: new PublicKey('6bquU99ktV1VRiHDr8gMhDFt3kMfhCQo5nfNrg2Urvsn'),
64
64
  launchTs: 1677068931000,
65
- oracleSource: OracleSource.PYTH_1000,
65
+ oracleSource: OracleSource.PYTH_1M,
66
+ },
67
+ {
68
+ fullName: 'Polygon',
69
+ category: ['L2', 'Infra'],
70
+ symbol: 'MATIC-PERP',
71
+ baseAssetSymbol: 'MATIC',
72
+ marketIndex: 5,
73
+ oracle: new PublicKey('FBirwuDFuRAu4iSGc7RGxN5koHB7EJM1wbCmyPuQoGur'),
74
+ launchTs: 1677690149000, //todo
75
+ oracleSource: OracleSource.PYTH,
66
76
  },
67
77
  ];
68
78
 
@@ -107,6 +117,26 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
107
117
  launchTs: 1675802661000,
108
118
  oracleSource: OracleSource.PYTH,
109
119
  },
120
+ {
121
+ fullName: 'Bonk',
122
+ category: ['Meme'],
123
+ symbol: '1MBONK-PERP',
124
+ baseAssetSymbol: '1MBONK',
125
+ marketIndex: 4,
126
+ oracle: new PublicKey('8ihFLu5FimgTQ1Unh4dVyEHUGodJ5gJQCrQf4KUVB9bN'),
127
+ launchTs: 1677690149000,
128
+ oracleSource: OracleSource.PYTH_1M,
129
+ },
130
+ {
131
+ fullName: 'Polygon',
132
+ category: ['L2', 'Infra'],
133
+ symbol: 'MATIC-PERP',
134
+ baseAssetSymbol: 'MATIC',
135
+ marketIndex: 5,
136
+ oracle: new PublicKey('7KVswB9vkCgeM3SHP7aGDijvdRAHK8P5wi9JXViCrtYh'),
137
+ launchTs: 1677690149000, //todo
138
+ oracleSource: OracleSource.PYTH,
139
+ },
110
140
  ];
111
141
 
112
142
  export const PerpMarkets: { [key in DriftEnv]: PerpMarketConfig[] } = {
package/src/dlob/DLOB.ts CHANGED
@@ -450,8 +450,9 @@ export class DLOB {
450
450
  }
451
451
 
452
452
  public getOrder(orderId: number, userAccount: PublicKey): Order | undefined {
453
+ const orderSignature = getOrderSignature(orderId, userAccount);
453
454
  for (const nodeList of this.getNodeLists()) {
454
- const node = nodeList.get(orderId, userAccount);
455
+ const node = nodeList.get(orderSignature);
455
456
  if (node) {
456
457
  return node.order;
457
458
  }
@@ -1383,18 +1384,29 @@ export class DLOB {
1383
1384
  const bidSlot = bidNode.order.slot.add(
1384
1385
  new BN(bidNode.order.auctionDuration)
1385
1386
  );
1386
- if (askSlot.lte(bidSlot) && !bidNode.order.postOnly) {
1387
+
1388
+ if (bidNode.order.postOnly && askNode.order.postOnly) {
1389
+ return undefined;
1390
+ } else if (bidNode.order.postOnly) {
1391
+ return {
1392
+ takerNode: askNode,
1393
+ makerNode: bidNode,
1394
+ };
1395
+ } else if (askNode.order.postOnly) {
1387
1396
  return {
1388
1397
  takerNode: bidNode,
1389
1398
  makerNode: askNode,
1390
1399
  };
1391
- } else if (bidSlot.lte(askSlot) && !askNode.order.postOnly) {
1400
+ } else if (askSlot.lte(bidSlot)) {
1401
+ return {
1402
+ takerNode: bidNode,
1403
+ makerNode: askNode,
1404
+ };
1405
+ } else {
1392
1406
  return {
1393
1407
  takerNode: askNode,
1394
1408
  makerNode: bidNode,
1395
1409
  };
1396
- } else {
1397
- return undefined;
1398
1410
  }
1399
1411
  }
1400
1412
 
@@ -146,11 +146,8 @@ export class NodeList<NodeType extends keyof DLOBNodeMap>
146
146
  return this.nodeMap.has(getOrderSignature(order.orderId, userAccount));
147
147
  }
148
148
 
149
- public get(
150
- orderId: number,
151
- userAccount: PublicKey
152
- ): DLOBNodeMap[NodeType] | undefined {
153
- return this.nodeMap.get(getOrderSignature(orderId, userAccount));
149
+ public get(orderSignature: string): DLOBNodeMap[NodeType] | undefined {
150
+ return this.nodeMap.get(orderSignature);
154
151
  }
155
152
 
156
153
  public print(): void {
@@ -14,10 +14,14 @@ export function getOracleClient(
14
14
  return new PythClient(connection);
15
15
  }
16
16
 
17
- if (isVariant(oracleSource, 'pyth1000')) {
17
+ if (isVariant(oracleSource, 'pyth1K')) {
18
18
  return new PythClient(connection, new BN(1000));
19
19
  }
20
20
 
21
+ if (isVariant(oracleSource, 'pyth1M')) {
22
+ return new PythClient(connection, new BN(1000000));
23
+ }
24
+
21
25
  // if (isVariant(oracleSource, 'switchboard')) {
22
26
  // return new SwitchboardClient(connection);
23
27
  // }