@drift-labs/sdk 2.24.0 → 2.25.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 (124) hide show
  1. package/README.md +1 -1
  2. package/lib/accounts/fetch.d.ts +1 -1
  3. package/lib/accounts/pollingDriftClientAccountSubscriber.d.ts +1 -1
  4. package/lib/accounts/pollingOracleAccountSubscriber.d.ts +1 -1
  5. package/lib/accounts/pollingTokenAccountSubscriber.d.ts +1 -1
  6. package/lib/accounts/pollingUserAccountSubscriber.d.ts +1 -1
  7. package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +1 -1
  8. package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
  9. package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +1 -1
  10. package/lib/accounts/webSocketUserAccountSubscriber.d.ts +1 -1
  11. package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +1 -1
  12. package/lib/addresses/pda.d.ts +1 -2
  13. package/lib/addresses/pda.js +1 -1
  14. package/lib/adminClient.d.ts +1 -2
  15. package/lib/adminClient.js +2 -2
  16. package/lib/constants/numericConstants.d.ts +59 -61
  17. package/lib/constants/perpMarkets.js +10 -0
  18. package/lib/constants/spotMarkets.d.ts +0 -1
  19. package/lib/dlob/DLOB.d.ts +0 -1
  20. package/lib/dlob/DLOBNode.d.ts +0 -1
  21. package/lib/dlob/DLOBOrders.d.ts +1 -1
  22. package/lib/dlob/DLOBOrders.js +1 -1
  23. package/lib/dlob/NodeList.d.ts +0 -1
  24. package/lib/driftClient.d.ts +38 -23
  25. package/lib/driftClient.js +85 -131
  26. package/lib/events/eventSubscriber.d.ts +1 -1
  27. package/lib/events/eventSubscriber.js +3 -2
  28. package/lib/events/fetchLogs.d.ts +1 -1
  29. package/lib/events/fetchLogs.js +3 -2
  30. package/lib/examples/loadDlob.js +1 -1
  31. package/lib/examples/makeTradeExample.js +1 -1
  32. package/lib/factory/bigNum.d.ts +8 -9
  33. package/lib/factory/bigNum.js +1 -1
  34. package/lib/factory/oracleClient.js +1 -1
  35. package/lib/idl/drift.json +181 -14
  36. package/lib/index.d.ts +1 -1
  37. package/lib/index.js +1 -1
  38. package/lib/math/amm.d.ts +2 -3
  39. package/lib/math/amm.js +1 -1
  40. package/lib/math/auction.d.ts +0 -1
  41. package/lib/math/conversion.d.ts +1 -2
  42. package/lib/math/funding.d.ts +1 -2
  43. package/lib/math/funding.js +1 -1
  44. package/lib/math/insurance.d.ts +1 -1
  45. package/lib/math/insurance.js +17 -1
  46. package/lib/math/margin.d.ts +1 -2
  47. package/lib/math/margin.js +1 -1
  48. package/lib/math/market.d.ts +1 -2
  49. package/lib/math/market.js +1 -1
  50. package/lib/math/oracles.d.ts +0 -1
  51. package/lib/math/oracles.js +2 -3
  52. package/lib/math/orders.d.ts +1 -2
  53. package/lib/math/orders.js +1 -1
  54. package/lib/math/position.d.ts +0 -1
  55. package/lib/math/repeg.d.ts +1 -2
  56. package/lib/math/repeg.js +1 -1
  57. package/lib/math/spotBalance.d.ts +1 -2
  58. package/lib/math/spotBalance.js +1 -1
  59. package/lib/math/spotMarket.d.ts +1 -2
  60. package/lib/math/spotMarket.js +1 -1
  61. package/lib/math/spotPosition.d.ts +1 -2
  62. package/lib/math/trade.d.ts +1 -2
  63. package/lib/math/trade.js +1 -1
  64. package/lib/math/utils.d.ts +0 -1
  65. package/lib/oracles/pythClient.d.ts +2 -3
  66. package/lib/oracles/pythClient.js +1 -1
  67. package/lib/oracles/quoteAssetOracleClient.js +1 -1
  68. package/lib/oracles/types.d.ts +1 -2
  69. package/lib/orderParams.d.ts +1 -2
  70. package/lib/serum/serumSubscriber.d.ts +1 -2
  71. package/lib/serum/serumSubscriber.js +1 -1
  72. package/lib/tokenFaucet.d.ts +2 -3
  73. package/lib/tokenFaucet.js +2 -2
  74. package/lib/tx/retryTxSender.d.ts +1 -1
  75. package/lib/tx/types.d.ts +1 -1
  76. package/lib/types.d.ts +8 -3
  77. package/lib/types.js +2 -1
  78. package/lib/user.d.ts +0 -1
  79. package/package.json +2 -2
  80. package/src/accounts/fetch.ts +1 -1
  81. package/src/accounts/pollingDriftClientAccountSubscriber.ts +1 -1
  82. package/src/accounts/pollingOracleAccountSubscriber.ts +1 -1
  83. package/src/accounts/pollingTokenAccountSubscriber.ts +1 -1
  84. package/src/accounts/pollingUserAccountSubscriber.ts +1 -1
  85. package/src/accounts/pollingUserStatsAccountSubscriber.ts +1 -1
  86. package/src/accounts/webSocketAccountSubscriber.ts +1 -1
  87. package/src/accounts/webSocketDriftClientAccountSubscriber.ts +1 -1
  88. package/src/accounts/webSocketUserAccountSubscriber.ts +1 -1
  89. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +1 -1
  90. package/src/addresses/pda.ts +2 -2
  91. package/src/adminClient.ts +2 -2
  92. package/src/constants/perpMarkets.ts +10 -0
  93. package/src/dlob/DLOBOrders.ts +2 -2
  94. package/src/driftClient.ts +136 -153
  95. package/src/events/eventSubscriber.ts +7 -3
  96. package/src/events/fetchLogs.ts +7 -3
  97. package/src/examples/loadDlob.ts +1 -1
  98. package/src/examples/makeTradeExample.ts +1 -1
  99. package/src/factory/bigNum.ts +1 -1
  100. package/src/factory/oracleClient.ts +1 -1
  101. package/src/idl/drift.json +181 -14
  102. package/src/index.ts +1 -1
  103. package/src/math/amm.ts +1 -1
  104. package/src/math/funding.ts +1 -1
  105. package/src/math/insurance.ts +29 -0
  106. package/src/math/margin.ts +1 -1
  107. package/src/math/market.ts +1 -1
  108. package/src/math/oracles.ts +2 -3
  109. package/src/math/orders.ts +1 -1
  110. package/src/math/repeg.ts +1 -1
  111. package/src/math/spotBalance.ts +1 -1
  112. package/src/math/spotMarket.ts +1 -1
  113. package/src/math/spotPosition.ts +1 -1
  114. package/src/math/trade.ts +1 -1
  115. package/src/oracles/pythClient.ts +1 -1
  116. package/src/oracles/quoteAssetOracleClient.ts +1 -1
  117. package/src/oracles/types.ts +1 -1
  118. package/src/orderParams.ts +1 -1
  119. package/src/serum/serumSubscriber.ts +1 -1
  120. package/src/tokenFaucet.ts +2 -2
  121. package/src/tx/retryTxSender.ts +1 -1
  122. package/src/tx/types.ts +1 -1
  123. package/src/types.ts +6 -1
  124. package/src/userMap/userStatsMap.ts +1 -1
package/lib/math/amm.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { AMM, PositionDirection, SwapDirection, PerpMarketAccount } from '../types';
4
3
  import { OraclePriceData } from '../oracles/types';
5
4
  export declare function calculatePegFromTargetPrice(targetPrice: BN, baseAssetReserve: BN, quoteAssetReserve: BN): BN;
@@ -87,7 +86,7 @@ export declare function getSwapDirection(inputAssetType: AssetType, positionDire
87
86
  * @param market
88
87
  * @returns cost : Precision PRICE_PRECISION
89
88
  */
90
- export declare function calculateTerminalPrice(market: PerpMarketAccount): BN;
89
+ export declare function calculateTerminalPrice(market: PerpMarketAccount): any;
91
90
  export declare function calculateMaxBaseAssetAmountToTrade(amm: AMM, limit_price: BN, direction: PositionDirection, oraclePriceData?: OraclePriceData, now?: BN): [BN, PositionDirection];
92
91
  export declare function calculateQuoteAssetAmountSwapped(quoteAssetReserves: BN, pegMultiplier: BN, swapDirection: SwapDirection): BN;
93
92
  export declare function calculateMaxBaseAssetAmountFillable(amm: AMM, orderDirection: PositionDirection): BN;
package/lib/math/amm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateMaxBaseAssetAmountFillable = exports.calculateQuoteAssetAmountSwapped = exports.calculateMaxBaseAssetAmountToTrade = exports.calculateTerminalPrice = exports.getSwapDirection = exports.calculateSwapOutput = exports.calculateSpreadReserves = exports.calculateSpread = exports.calculateSpreadBN = exports.calculateVolSpreadBN = exports.calculateMaxSpread = exports.calculateEffectiveLeverage = exports.calculateInventoryScale = exports.calculateMarketOpenBidAsk = exports.calculateAmmReservesAfterSwap = exports.calculatePrice = exports.calculateBidAskPrice = exports.calculateUpdatedAMMSpreadReserves = exports.calculateUpdatedAMM = exports.calculateNewAmm = exports.calculateOptimalPegAndBudget = exports.calculatePegFromTargetPrice = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
6
  const types_1 = require("../types");
7
7
  const assert_1 = require("../assert/assert");
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { Order } from '../types';
3
2
  import { BN } from '../.';
4
3
  export declare function isAuctionComplete(order: Order, slot: number): boolean;
@@ -1,2 +1 @@
1
- import { BN } from '../';
2
- export declare const convertToNumber: (bigNumber: BN, precision?: BN) => number;
1
+ export declare const convertToNumber: (bigNumber: BN, precision?: BN) => any;
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { PerpMarketAccount } from '../types';
4
3
  import { OraclePriceData } from '../oracles/types';
5
4
  /**
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateFundingPool = exports.calculateLongShortFundingRateAndLiveTwaps = exports.calculateLongShortFundingRate = exports.calculateEstimatedFundingRate = exports.calculateAllEstimatedFundingRate = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
6
  const types_1 = require("../types");
7
7
  const amm_1 = require("./amm");
@@ -1,4 +1,4 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '../index';
3
2
  export declare function stakeAmountToShares(amount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
4
3
  export declare function unstakeSharesToAmount(nShares: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
4
+ export declare function unstakeSharesToAmountWithOpenRequest(nShares: BN, withdrawRequestShares: BN, withdrawRequestAmount: BN, totalIfShares: BN, insuranceFundVaultBalance: BN): BN;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unstakeSharesToAmount = exports.stakeAmountToShares = void 0;
3
+ exports.unstakeSharesToAmountWithOpenRequest = exports.unstakeSharesToAmount = exports.stakeAmountToShares = void 0;
4
4
  const numericConstants_1 = require("../constants/numericConstants");
5
5
  const index_1 = require("../index");
6
6
  function stakeAmountToShares(amount, totalIfShares, insuranceFundVaultBalance) {
@@ -25,3 +25,19 @@ function unstakeSharesToAmount(nShares, totalIfShares, insuranceFundVaultBalance
25
25
  return amount;
26
26
  }
27
27
  exports.unstakeSharesToAmount = unstakeSharesToAmount;
28
+ function unstakeSharesToAmountWithOpenRequest(nShares, withdrawRequestShares, withdrawRequestAmount, totalIfShares, insuranceFundVaultBalance) {
29
+ let stakedAmount;
30
+ if (totalIfShares.gt(numericConstants_1.ZERO)) {
31
+ stakedAmount = index_1.BN.max(numericConstants_1.ZERO, nShares
32
+ .sub(withdrawRequestShares)
33
+ .mul(insuranceFundVaultBalance)
34
+ .div(totalIfShares));
35
+ }
36
+ else {
37
+ stakedAmount = numericConstants_1.ZERO;
38
+ }
39
+ const withdrawAmount = index_1.BN.min(withdrawRequestAmount, withdrawRequestShares.mul(insuranceFundVaultBalance).div(totalIfShares));
40
+ const amount = withdrawAmount.add(stakedAmount);
41
+ return amount;
42
+ }
43
+ exports.unstakeSharesToAmountWithOpenRequest = unstakeSharesToAmountWithOpenRequest;
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { OraclePriceData } from '../oracles/types';
4
3
  import { PerpMarketAccount, PerpPosition } from '..';
5
4
  export declare function calculateSizePremiumLiabilityWeight(size: BN, // AMM_RESERVE_PRECISION
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateWorstCaseBaseAssetAmount = exports.calculateBaseAssetValueWithOracle = exports.calculateOraclePriceForPerpMargin = exports.calculateSizeDiscountAssetWeight = exports.calculateSizePremiumLiabilityWeight = void 0;
4
4
  const utils_1 = require("./utils");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
- const anchor_1 = require("@project-serum/anchor");
6
+ const anchor_1 = require("@coral-xyz/anchor");
7
7
  const types_1 = require("../types");
8
8
  const assert_1 = require("../assert/assert");
9
9
  function calculateSizePremiumLiabilityWeight(size, // AMM_RESERVE_PRECISION
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { PerpMarketAccount, PositionDirection, MarginCategory, SpotMarketAccount } from '../types';
4
3
  import { OraclePriceData } from '../oracles/types';
5
4
  import { DLOB } from '../dlob/DLOB';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateAvailablePerpLiquidity = exports.calculateNetUserPnlImbalance = exports.calculateNetUserPnl = exports.calculateMarketMaxAvailableInsurance = exports.calculateMarketAvailablePNL = exports.calculateUnrealizedAssetWeight = exports.calculateMarketMarginRatio = exports.calculateOracleSpread = exports.calculateOracleReserveSpread = exports.calculateNewMarketAfterTrade = exports.calculateAskPrice = exports.calculateBidPrice = exports.calculateReservePrice = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const types_1 = require("../types");
6
6
  const amm_1 = require("./amm");
7
7
  const margin_1 = require("./margin");
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { AMM, OracleGuardRails } from '../types';
3
2
  import { OraclePriceData } from '../oracles/types';
4
3
  import { BN, HistoricalOracleData, PerpMarketAccount } from '../index';
@@ -21,11 +21,10 @@ function isOracleValid(amm, oraclePriceData, oracleGuardRails, slot) {
21
21
  amm.historicalOracleData.lastOraclePriceTwap
22
22
  .div(index_1.BN.max(numericConstants_1.ONE, oraclePriceData.price))
23
23
  .gt(oracleGuardRails.validity.tooVolatileRatio);
24
- const isConfidenceTooLarge = new index_1.BN(amm.baseSpread)
25
- .add(index_1.BN.max(numericConstants_1.ONE, oraclePriceData.confidence))
24
+ const isConfidenceTooLarge = index_1.BN.max(numericConstants_1.ONE, oraclePriceData.confidence)
26
25
  .mul(numericConstants_1.BID_ASK_SPREAD_PRECISION)
27
26
  .div(oraclePriceData.price)
28
- .gt(new index_1.BN(amm.maxSpread));
27
+ .gt(oracleGuardRails.validity.confidenceIntervalMaxSize);
29
28
  const oracleIsStale = oraclePriceData.slot
30
29
  .sub(new index_1.BN(slot))
31
30
  .gt(oracleGuardRails.validity.slotsBeforeStaleForAmm);
@@ -1,7 +1,6 @@
1
- /// <reference types="bn.js" />
2
1
  import { User } from '../user';
3
2
  import { PerpMarketAccount, AMM, Order } from '../types';
4
- import { BN } from '@project-serum/anchor';
3
+ import { BN } from '@coral-xyz/anchor';
5
4
  import { OraclePriceData } from '../oracles/types';
6
5
  export declare function isOrderRiskIncreasing(user: User, order: Order): boolean;
7
6
  export declare function isOrderRiskIncreasingInSameDirection(user: User, order: Order): boolean;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isTakingOrder = exports.isRestingLimitOrder = exports.isTriggered = exports.mustBeTriggered = exports.isLimitOrder = exports.isMarketOrder = exports.isOrderExpired = exports.calculateBaseAssetAmountToFillUpToLimitPrice = exports.calculateBaseAssetAmountForAmmToFulfill = exports.isFillableByVAMM = exports.hasAuctionPrice = exports.hasLimitPrice = exports.getLimitPrice = exports.standardizeBaseAssetAmount = exports.isOrderReduceOnly = exports.isOrderRiskIncreasingInSameDirection = exports.isOrderRiskIncreasing = void 0;
4
4
  const types_1 = require("../types");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
- const anchor_1 = require("@project-serum/anchor");
6
+ const anchor_1 = require("@coral-xyz/anchor");
7
7
  const auction_1 = require("./auction");
8
8
  const amm_1 = require("./amm");
9
9
  function isOrderRiskIncreasing(user, order) {
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN, SpotMarketAccount } from '../';
3
2
  import { OraclePriceData } from '../oracles/types';
4
3
  import { PerpMarketAccount, PositionDirection, PerpPosition } from '../types';
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { AMM } from '../types';
4
3
  /**
5
4
  * Helper function calculating adjust k cost
package/lib/math/repeg.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateBudgetedPeg = exports.calculateBudgetedK = exports.calculateBudgetedKBN = exports.calculateRepegCost = exports.calculateAdjustKCost = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const assert_1 = require("../assert/assert");
6
6
  const numericConstants_1 = require("../constants/numericConstants");
7
7
  /**
@@ -1,6 +1,5 @@
1
- /// <reference types="bn.js" />
2
1
  import { SpotMarketAccount, SpotBalanceType, MarginCategory } from '../types';
3
- import { BN } from '@project-serum/anchor';
2
+ import { BN } from '@coral-xyz/anchor';
4
3
  import { OraclePriceData } from '../oracles/types';
5
4
  export declare function getBalance(tokenAmount: BN, spotMarket: SpotMarketAccount, balanceType: SpotBalanceType): BN;
6
5
  export declare function getTokenAmount(balanceAmount: BN, spotMarket: SpotMarketAccount, balanceType: SpotBalanceType): BN;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateWithdrawLimit = exports.calculateInterestAccumulated = exports.calculateBorrowRate = exports.calculateDepositRate = exports.calculateInterestRate = exports.calculateUtilization = exports.calculateLiabilityWeight = exports.calculateAssetWeight = exports.getTokenValue = exports.getStrictTokenValue = exports.getSignedTokenAmount = exports.getTokenAmount = exports.getBalance = void 0;
4
4
  const types_1 = require("../types");
5
- const anchor_1 = require("@project-serum/anchor");
5
+ const anchor_1 = require("@coral-xyz/anchor");
6
6
  const numericConstants_1 = require("../constants/numericConstants");
7
7
  const margin_1 = require("./margin");
8
8
  const numericConstants_2 = require("../constants/numericConstants");
@@ -1,5 +1,4 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
1
+ import { BN } from '@coral-xyz/anchor';
3
2
  import { MarginCategory, SpotBalanceType, SpotMarketAccount } from '../types';
4
3
  export declare function castNumberToSpotPrecision(value: number, spotMarket: SpotMarketAccount): BN;
5
4
  export declare function calculateSpotMarketMarginRatio(market: SpotMarketAccount, marginCategory: MarginCategory, size: BN, balanceType: SpotBalanceType): number;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateSpotMarketMarginRatio = exports.castNumberToSpotPrecision = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const types_1 = require("../types");
6
6
  const spotBalance_1 = require("./spotBalance");
7
7
  const numericConstants_1 = require("../constants/numericConstants");
@@ -1,6 +1,5 @@
1
- /// <reference types="bn.js" />
2
1
  import { SpotMarketAccount, SpotPosition } from '../types';
3
- import { BN } from '@project-serum/anchor';
2
+ import { BN } from '@coral-xyz/anchor';
4
3
  import { OraclePriceData } from '../oracles/types';
5
4
  export declare function isSpotPositionAvailable(position: SpotPosition): boolean;
6
5
  export declare function getWorstCaseTokenAmounts(spotPosition: SpotPosition, spotMarketAccount: SpotMarketAccount, oraclePriceData: OraclePriceData): [BN, BN];
@@ -1,6 +1,5 @@
1
- /// <reference types="bn.js" />
2
1
  import { PerpMarketAccount, PositionDirection, SpotMarketAccount } from '../types';
3
- import { BN } from '@project-serum/anchor';
2
+ import { BN } from '@coral-xyz/anchor';
4
3
  import { AssetType } from './amm';
5
4
  import { OraclePriceData } from '../oracles/types';
6
5
  import { DLOB } from '../dlob/DLOB';
package/lib/math/trade.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateEstimatedSpotEntryPrice = exports.calculateEstimatedPerpEntryPrice = exports.calculateTargetPriceTrade = exports.calculateTradeAcquiredAmounts = exports.calculateTradeSlippage = void 0;
4
4
  const types_1 = require("../types");
5
- const anchor_1 = require("@project-serum/anchor");
5
+ const anchor_1 = require("@coral-xyz/anchor");
6
6
  const assert_1 = require("../assert/assert");
7
7
  const numericConstants_1 = require("../constants/numericConstants");
8
8
  const market_1 = require("./market");
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { BN } from '../';
3
2
  export declare function clampBN(x: BN, min: BN, max: BN): BN;
4
3
  export declare const squareRootBN: (n: BN) => BN;
@@ -1,13 +1,12 @@
1
- /// <reference types="bn.js" />
2
1
  /// <reference types="node" />
3
2
  import { Connection, PublicKey } from '@solana/web3.js';
4
3
  import { OracleClient, OraclePriceData } from './types';
5
- import { BN } from '@project-serum/anchor';
4
+ import { BN } from '@coral-xyz/anchor';
6
5
  export declare class PythClient implements OracleClient {
7
6
  private connection;
8
7
  private multiple;
9
8
  private stableCoin;
10
- constructor(connection: Connection, multiple?: BN, stableCoin?: boolean);
9
+ constructor(connection: Connection, multiple?: any, stableCoin?: boolean);
11
10
  getOraclePriceData(pricePublicKey: PublicKey): Promise<OraclePriceData>;
12
11
  getOraclePriceDataFromBuffer(buffer: Buffer): OraclePriceData;
13
12
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertPythPrice = exports.PythClient = void 0;
4
4
  const client_1 = require("@pythnetwork/client");
5
- const anchor_1 = require("@project-serum/anchor");
5
+ const anchor_1 = require("@coral-xyz/anchor");
6
6
  const numericConstants_1 = require("../constants/numericConstants");
7
7
  class PythClient {
8
8
  constructor(connection, multiple = numericConstants_1.ONE, stableCoin = false) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QuoteAssetOracleClient = exports.QUOTE_ORACLE_PRICE_DATA = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
5
  const numericConstants_1 = require("../constants/numericConstants");
6
6
  exports.QUOTE_ORACLE_PRICE_DATA = {
7
7
  price: numericConstants_1.PRICE_PRECISION,
@@ -1,6 +1,5 @@
1
- /// <reference types="bn.js" />
2
1
  /// <reference types="node" />
3
- import { BN } from '@project-serum/anchor';
2
+ import { BN } from '@coral-xyz/anchor';
4
3
  import { PublicKey } from '@solana/web3.js';
5
4
  import { OracleSource } from '../types';
6
5
  export type OraclePriceData = {
@@ -1,6 +1,5 @@
1
- /// <reference types="bn.js" />
2
1
  import { OptionalOrderParams, OrderTriggerCondition } from './types';
3
- import { BN } from '@project-serum/anchor';
2
+ import { BN } from '@coral-xyz/anchor';
4
3
  export declare function getLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType' | 'marketType'> & {
5
4
  price: BN;
6
5
  }): OptionalOrderParams;
@@ -1,9 +1,8 @@
1
- /// <reference types="bn.js" />
2
1
  import { Connection, PublicKey } from '@solana/web3.js';
3
2
  import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
4
3
  import { Market, Orderbook } from '@project-serum/serum';
5
4
  import { SerumMarketSubscriberConfig } from './types';
6
- import { BN } from '@project-serum/anchor';
5
+ import { BN } from '@coral-xyz/anchor';
7
6
  export declare class SerumSubscriber {
8
7
  connection: Connection;
9
8
  programId: PublicKey;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SerumSubscriber = void 0;
4
4
  const serum_1 = require("@project-serum/serum");
5
- const anchor_1 = require("@project-serum/anchor");
5
+ const anchor_1 = require("@coral-xyz/anchor");
6
6
  const numericConstants_1 = require("../constants/numericConstants");
7
7
  class SerumSubscriber {
8
8
  constructor(config) {
@@ -1,6 +1,5 @@
1
- /// <reference types="bn.js" />
2
- import * as anchor from '@project-serum/anchor';
3
- import { AnchorProvider, Program } from '@project-serum/anchor';
1
+ import * as anchor from '@coral-xyz/anchor';
2
+ import { AnchorProvider, Program } from '@coral-xyz/anchor';
4
3
  import { AccountInfo } from '@solana/spl-token';
5
4
  import { ConfirmOptions, Connection, PublicKey, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
6
5
  import { BN } from '.';
@@ -27,8 +27,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.TokenFaucet = void 0;
30
- const anchor = __importStar(require("@project-serum/anchor"));
31
- const anchor_1 = require("@project-serum/anchor");
30
+ const anchor = __importStar(require("@coral-xyz/anchor"));
31
+ const anchor_1 = require("@coral-xyz/anchor");
32
32
  const spl_token_1 = require("@solana/spl-token");
33
33
  const web3_js_1 = require("@solana/web3.js");
34
34
  const token_faucet_json_1 = __importDefault(require("./idl/token_faucet.json"));
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { TxSender, TxSigAndSlot } from './types';
3
3
  import { Commitment, ConfirmOptions, RpcResponseAndContext, Signer, SignatureResult, Transaction, TransactionSignature, Connection, TransactionInstruction, AddressLookupTableAccount } from '@solana/web3.js';
4
- import { AnchorProvider } from '@project-serum/anchor';
4
+ import { AnchorProvider } from '@coral-xyz/anchor';
5
5
  type ResolveReference = {
6
6
  resolve?: () => void;
7
7
  };
package/lib/tx/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Provider } from '@project-serum/anchor';
1
+ import { Provider } from '@coral-xyz/anchor';
2
2
  import { AddressLookupTableAccount, ConfirmOptions, Signer, Transaction, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
3
3
  export type TxSigAndSlot = {
4
4
  txSig: TransactionSignature;
package/lib/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="bn.js" />
2
1
  import { PublicKey, Transaction } from '@solana/web3.js';
3
2
  import { BN } from '.';
4
3
  export declare enum ExchangeStatus {
@@ -253,8 +252,11 @@ export declare class OrderTriggerCondition {
253
252
  };
254
253
  }
255
254
  export declare class SpotFulfillmentType {
256
- static readonly SERUM_v3: {
257
- serumV3: {};
255
+ static readonly EXTERNAL: {
256
+ external: {};
257
+ };
258
+ static readonly MATCH: {
259
+ match: {};
258
260
  };
259
261
  }
260
262
  export declare class SpotFulfillmentStatus {
@@ -928,6 +930,9 @@ export type NecessaryOrderParams = {
928
930
  export type OptionalOrderParams = {
929
931
  [Property in keyof OrderParams]?: OrderParams[Property];
930
932
  } & NecessaryOrderParams;
933
+ export type ModifyOrderParams = {
934
+ [Property in keyof OrderParams]?: OrderParams[Property] | null;
935
+ };
931
936
  export declare const DefaultOrderParams: OrderParams;
932
937
  export type MakerInfo = {
933
938
  maker: PublicKey;
package/lib/types.js CHANGED
@@ -162,7 +162,8 @@ OrderTriggerCondition.TRIGGERED_BELOW = { triggeredBelow: {} }; // below conditi
162
162
  class SpotFulfillmentType {
163
163
  }
164
164
  exports.SpotFulfillmentType = SpotFulfillmentType;
165
- SpotFulfillmentType.SERUM_v3 = { serumV3: {} };
165
+ SpotFulfillmentType.EXTERNAL = { external: {} };
166
+ SpotFulfillmentType.MATCH = { match: {} };
166
167
  class SpotFulfillmentStatus {
167
168
  }
168
169
  exports.SpotFulfillmentStatus = SpotFulfillmentStatus;
package/lib/user.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="bn.js" />
3
2
  import { PublicKey } from '@solana/web3.js';
4
3
  import { EventEmitter } from 'events';
5
4
  import StrictEventEmitter from 'strict-event-emitter-types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.24.0",
3
+ "version": "2.25.0-beta.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -33,7 +33,7 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@project-serum/anchor": "0.25.0-beta.1",
36
+ "@coral-xyz/anchor": "0.26.0",
37
37
  "@project-serum/serum": "^0.13.38",
38
38
  "@pythnetwork/client": "2.5.3",
39
39
  "@solana/spl-token": "^0.1.6",
@@ -4,7 +4,7 @@ import {
4
4
  getUserAccountPublicKey,
5
5
  getUserStatsAccountPublicKey,
6
6
  } from '../addresses/pda';
7
- import { Program } from '@project-serum/anchor';
7
+ import { Program } from '@coral-xyz/anchor';
8
8
 
9
9
  export async function fetchUserAccounts(
10
10
  connection: Connection,
@@ -6,7 +6,7 @@ import {
6
6
  NotSubscribedError,
7
7
  OraclesToPoll,
8
8
  } from './types';
9
- import { Program } from '@project-serum/anchor';
9
+ import { Program } from '@coral-xyz/anchor';
10
10
  import StrictEventEmitter from 'strict-event-emitter-types';
11
11
  import { EventEmitter } from 'events';
12
12
  import {
@@ -4,7 +4,7 @@ import {
4
4
  OracleEvents,
5
5
  OracleAccountSubscriber,
6
6
  } from './types';
7
- import { Program } from '@project-serum/anchor';
7
+ import { Program } from '@coral-xyz/anchor';
8
8
  import StrictEventEmitter from 'strict-event-emitter-types';
9
9
  import { EventEmitter } from 'events';
10
10
  import { PublicKey } from '@solana/web3.js';
@@ -4,7 +4,7 @@ import {
4
4
  TokenAccountEvents,
5
5
  TokenAccountSubscriber,
6
6
  } from './types';
7
- import { Program } from '@project-serum/anchor';
7
+ import { Program } from '@coral-xyz/anchor';
8
8
  import StrictEventEmitter from 'strict-event-emitter-types';
9
9
  import { EventEmitter } from 'events';
10
10
  import { PublicKey } from '@solana/web3.js';
@@ -5,7 +5,7 @@ import {
5
5
  UserAccountEvents,
6
6
  UserAccountSubscriber,
7
7
  } from './types';
8
- import { Program } from '@project-serum/anchor';
8
+ import { Program } from '@coral-xyz/anchor';
9
9
  import StrictEventEmitter from 'strict-event-emitter-types';
10
10
  import { EventEmitter } from 'events';
11
11
  import { PublicKey } from '@solana/web3.js';
@@ -5,7 +5,7 @@ import {
5
5
  UserStatsAccountSubscriber,
6
6
  UserStatsAccountEvents,
7
7
  } from './types';
8
- import { Program } from '@project-serum/anchor';
8
+ import { Program } from '@coral-xyz/anchor';
9
9
  import StrictEventEmitter from 'strict-event-emitter-types';
10
10
  import { EventEmitter } from 'events';
11
11
  import { PublicKey } from '@solana/web3.js';
@@ -1,5 +1,5 @@
1
1
  import { DataAndSlot, BufferAndSlot, AccountSubscriber } from './types';
2
- import { AnchorProvider, Program } from '@project-serum/anchor';
2
+ import { AnchorProvider, Program } from '@coral-xyz/anchor';
3
3
  import { AccountInfo, Context, PublicKey } from '@solana/web3.js';
4
4
  import { capitalize } from './utils';
5
5
  import * as Buffer from 'buffer';
@@ -5,7 +5,7 @@ import {
5
5
  } from './types';
6
6
  import { AccountSubscriber, NotSubscribedError } from './types';
7
7
  import { SpotMarketAccount, PerpMarketAccount, StateAccount } from '../types';
8
- import { Program } from '@project-serum/anchor';
8
+ import { Program } from '@coral-xyz/anchor';
9
9
  import StrictEventEmitter from 'strict-event-emitter-types';
10
10
  import { EventEmitter } from 'events';
11
11
  import {
@@ -5,7 +5,7 @@ import {
5
5
  UserAccountEvents,
6
6
  UserAccountSubscriber,
7
7
  } from './types';
8
- import { Program } from '@project-serum/anchor';
8
+ import { Program } from '@coral-xyz/anchor';
9
9
  import StrictEventEmitter from 'strict-event-emitter-types';
10
10
  import { EventEmitter } from 'events';
11
11
  import { PublicKey } from '@solana/web3.js';
@@ -5,7 +5,7 @@ import {
5
5
  UserStatsAccountSubscriber,
6
6
  UserStatsAccountEvents,
7
7
  } from './types';
8
- import { Program } from '@project-serum/anchor';
8
+ import { Program } from '@coral-xyz/anchor';
9
9
  import StrictEventEmitter from 'strict-event-emitter-types';
10
10
  import { EventEmitter } from 'events';
11
11
  import { PublicKey } from '@solana/web3.js';
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
- import * as anchor from '@project-serum/anchor';
3
- import { BN } from '@project-serum/anchor';
2
+ import * as anchor from '@coral-xyz/anchor';
3
+ import { BN } from '@coral-xyz/anchor';
4
4
 
5
5
  export async function getDriftStateAccountPublicKeyAndNonce(
6
6
  programId: PublicKey
@@ -14,8 +14,8 @@ import {
14
14
  SpotFulfillmentConfigStatus,
15
15
  } from './types';
16
16
  import { DEFAULT_MARKET_NAME, encodeName } from './userName';
17
- import { BN } from '@project-serum/anchor';
18
- import * as anchor from '@project-serum/anchor';
17
+ import { BN } from '@coral-xyz/anchor';
18
+ import * as anchor from '@coral-xyz/anchor';
19
19
  import {
20
20
  getDriftStateAccountPublicKeyAndNonce,
21
21
  getSpotMarketPublicKey,
@@ -94,6 +94,16 @@ export const DevnetPerpMarkets: PerpMarketConfig[] = [
94
94
  launchTs: 1680808053000,
95
95
  oracleSource: OracleSource.PYTH,
96
96
  },
97
+ {
98
+ fullName: 'Binance Coin',
99
+ category: ['Exchange'],
100
+ symbol: 'BNB-PERP',
101
+ baseAssetSymbol: 'BNB',
102
+ marketIndex: 8,
103
+ oracle: new PublicKey('GwzBgrXb4PG59zjce24SF2b9JXbLEjJJTBkmytuEZj1b'),
104
+ launchTs: 1680808053000,
105
+ oracleSource: OracleSource.PYTH,
106
+ },
97
107
  ];
98
108
 
99
109
  export const MainnetPerpMarkets: PerpMarketConfig[] = [
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
- import { Idl } from '@project-serum/anchor';
3
- import { IdlCoder } from '@project-serum/anchor/dist/cjs/coder/borsh/idl';
2
+ import { Idl } from '@coral-xyz/anchor';
3
+ import { IdlCoder } from '@coral-xyz/anchor/dist/cjs/coder/borsh/idl';
4
4
  import dlobIDL from './dlobIdl.json';
5
5
  import { Order } from '../types';
6
6