@drift-labs/sdk 2.12.0-beta.2 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/lib/accounts/bulkAccountLoader.js +3 -3
  2. package/lib/accounts/fetch.js +2 -2
  3. package/lib/accounts/pollingDriftClientAccountSubscriber.js +7 -7
  4. package/lib/accounts/pollingTokenAccountSubscriber.js +2 -2
  5. package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
  6. package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
  7. package/lib/accounts/webSocketAccountSubscriber.js +1 -1
  8. package/lib/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
  9. package/lib/addresses/marketAddresses.js +1 -1
  10. package/lib/addresses/pda.js +1 -5
  11. package/lib/adminClient.js +57 -61
  12. package/lib/dlob/DLOB.d.ts +8 -8
  13. package/lib/dlob/DLOB.js +91 -84
  14. package/lib/dlob/DLOBNode.js +7 -7
  15. package/lib/dlob/NodeList.js +2 -2
  16. package/lib/driftClient.d.ts +3 -3
  17. package/lib/driftClient.js +83 -87
  18. package/lib/events/eventSubscriber.js +2 -2
  19. package/lib/events/pollingLogProvider.js +1 -1
  20. package/lib/examples/makeTradeExample.js +9 -9
  21. package/lib/factory/bigNum.js +9 -9
  22. package/lib/factory/oracleClient.js +2 -2
  23. package/lib/idl/drift.json +1 -1
  24. package/lib/index.js +1 -5
  25. package/lib/math/amm.js +23 -23
  26. package/lib/math/auction.js +6 -6
  27. package/lib/math/exchangeStatus.js +2 -2
  28. package/lib/math/funding.js +2 -2
  29. package/lib/math/margin.js +5 -5
  30. package/lib/math/market.js +12 -12
  31. package/lib/math/oracles.js +1 -1
  32. package/lib/math/orders.js +23 -23
  33. package/lib/math/position.js +5 -5
  34. package/lib/math/repeg.js +1 -1
  35. package/lib/math/spotBalance.js +7 -7
  36. package/lib/math/spotPosition.js +3 -3
  37. package/lib/math/trade.d.ts +35 -3
  38. package/lib/math/trade.js +225 -47
  39. package/lib/oracles/oracleClientCache.js +1 -1
  40. package/lib/oracles/pythClient.js +1 -1
  41. package/lib/tokenFaucet.js +1 -5
  42. package/lib/tx/retryTxSender.js +1 -1
  43. package/lib/tx/utils.d.ts +1 -1
  44. package/lib/tx/utils.js +7 -4
  45. package/lib/types.d.ts +4 -0
  46. package/lib/user.js +47 -47
  47. package/lib/userMap/userMap.js +1 -1
  48. package/lib/userMap/userStatsMap.js +3 -3
  49. package/lib/userStats.js +2 -2
  50. package/package.json +1 -1
  51. package/src/dlob/DLOB.ts +34 -26
  52. package/src/driftClient.ts +11 -4
  53. package/src/idl/drift.json +1 -1
  54. package/src/math/trade.ts +322 -16
  55. package/src/tx/utils.ts +11 -3
  56. package/src/types.ts +5 -0
  57. package/tests/dlob/test.ts +307 -38
@@ -7,7 +7,7 @@ const anchor_1 = require("@project-serum/anchor");
7
7
  const auction_1 = require("./auction");
8
8
  const amm_1 = require("./amm");
9
9
  function isOrderRiskIncreasing(user, order) {
10
- if ((0, types_1.isVariant)(order.status, 'init')) {
10
+ if (types_1.isVariant(order.status, 'init')) {
11
11
  return false;
12
12
  }
13
13
  const position = user.getPerpPosition(order.marketIndex) ||
@@ -17,12 +17,12 @@ function isOrderRiskIncreasing(user, order) {
17
17
  return true;
18
18
  }
19
19
  // if position is long and order is long
20
- if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && (0, types_1.isVariant)(order.direction, 'long')) {
20
+ if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && types_1.isVariant(order.direction, 'long')) {
21
21
  return true;
22
22
  }
23
23
  // if position is short and order is short
24
24
  if (position.baseAssetAmount.lt(numericConstants_1.ZERO) &&
25
- (0, types_1.isVariant)(order.direction, 'short')) {
25
+ types_1.isVariant(order.direction, 'short')) {
26
26
  return true;
27
27
  }
28
28
  const baseAssetAmountToFill = order.baseAssetAmount.sub(order.baseAssetAmountFilled);
@@ -34,7 +34,7 @@ function isOrderRiskIncreasing(user, order) {
34
34
  }
35
35
  exports.isOrderRiskIncreasing = isOrderRiskIncreasing;
36
36
  function isOrderRiskIncreasingInSameDirection(user, order) {
37
- if ((0, types_1.isVariant)(order.status, 'init')) {
37
+ if (types_1.isVariant(order.status, 'init')) {
38
38
  return false;
39
39
  }
40
40
  const position = user.getPerpPosition(order.marketIndex) ||
@@ -44,31 +44,31 @@ function isOrderRiskIncreasingInSameDirection(user, order) {
44
44
  return true;
45
45
  }
46
46
  // if position is long and order is long
47
- if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && (0, types_1.isVariant)(order.direction, 'long')) {
47
+ if (position.baseAssetAmount.gt(numericConstants_1.ZERO) && types_1.isVariant(order.direction, 'long')) {
48
48
  return true;
49
49
  }
50
50
  // if position is short and order is short
51
51
  if (position.baseAssetAmount.lt(numericConstants_1.ZERO) &&
52
- (0, types_1.isVariant)(order.direction, 'short')) {
52
+ types_1.isVariant(order.direction, 'short')) {
53
53
  return true;
54
54
  }
55
55
  return false;
56
56
  }
57
57
  exports.isOrderRiskIncreasingInSameDirection = isOrderRiskIncreasingInSameDirection;
58
58
  function isOrderReduceOnly(user, order) {
59
- if ((0, types_1.isVariant)(order.status, 'init')) {
59
+ if (types_1.isVariant(order.status, 'init')) {
60
60
  return false;
61
61
  }
62
62
  const position = user.getPerpPosition(order.marketIndex) ||
63
63
  user.getEmptyPosition(order.marketIndex);
64
64
  // if position is long and order is long
65
65
  if (position.baseAssetAmount.gte(numericConstants_1.ZERO) &&
66
- (0, types_1.isVariant)(order.direction, 'long')) {
66
+ types_1.isVariant(order.direction, 'long')) {
67
67
  return false;
68
68
  }
69
69
  // if position is short and order is short
70
70
  if (position.baseAssetAmount.lte(numericConstants_1.ZERO) &&
71
- (0, types_1.isVariant)(order.direction, 'short')) {
71
+ types_1.isVariant(order.direction, 'short')) {
72
72
  return false;
73
73
  }
74
74
  return true;
@@ -82,7 +82,7 @@ exports.standardizeBaseAssetAmount = standardizeBaseAssetAmount;
82
82
  function getLimitPrice(order, oraclePriceData, slot, fallbackPrice) {
83
83
  let limitPrice;
84
84
  if (hasAuctionPrice(order, slot)) {
85
- limitPrice = (0, auction_1.getAuctionPrice)(order, slot, oraclePriceData.price);
85
+ limitPrice = auction_1.getAuctionPrice(order, slot, oraclePriceData.price);
86
86
  }
87
87
  else if (order.oraclePriceOffset !== 0) {
88
88
  limitPrice = oraclePriceData.price.add(new anchor_1.BN(order.oraclePriceOffset));
@@ -99,15 +99,15 @@ exports.getLimitPrice = getLimitPrice;
99
99
  function hasLimitPrice(order, slot) {
100
100
  return (order.price.gt(numericConstants_1.ZERO) ||
101
101
  order.oraclePriceOffset != 0 ||
102
- !(0, auction_1.isAuctionComplete)(order, slot));
102
+ !auction_1.isAuctionComplete(order, slot));
103
103
  }
104
104
  exports.hasLimitPrice = hasLimitPrice;
105
105
  function hasAuctionPrice(order, slot) {
106
- return isMarketOrder(order) && !(0, auction_1.isAuctionComplete)(order, slot);
106
+ return isMarketOrder(order) && !auction_1.isAuctionComplete(order, slot);
107
107
  }
108
108
  exports.hasAuctionPrice = hasAuctionPrice;
109
109
  function isFillableByVAMM(order, market, oraclePriceData, slot, ts) {
110
- return (((0, auction_1.isAuctionComplete)(order, slot) &&
110
+ return ((auction_1.isAuctionComplete(order, slot) &&
111
111
  !calculateBaseAssetAmountForAmmToFulfill(order, market, oraclePriceData, slot).eq(numericConstants_1.ZERO)) ||
112
112
  isOrderExpired(order, ts));
113
113
  }
@@ -118,19 +118,19 @@ function calculateBaseAssetAmountForAmmToFulfill(order, market, oraclePriceData,
118
118
  }
119
119
  const limitPrice = getLimitPrice(order, oraclePriceData, slot);
120
120
  let baseAssetAmount;
121
- const updatedAMM = (0, amm_1.calculateUpdatedAMM)(market.amm, oraclePriceData);
121
+ const updatedAMM = amm_1.calculateUpdatedAMM(market.amm, oraclePriceData);
122
122
  if (limitPrice !== undefined) {
123
123
  baseAssetAmount = calculateBaseAssetAmountToFillUpToLimitPrice(order, updatedAMM, limitPrice, oraclePriceData);
124
124
  }
125
125
  else {
126
126
  baseAssetAmount = order.baseAssetAmount.sub(order.baseAssetAmountFilled);
127
127
  }
128
- const maxBaseAssetAmount = (0, amm_1.calculateMaxBaseAssetAmountFillable)(updatedAMM, order.direction);
128
+ const maxBaseAssetAmount = amm_1.calculateMaxBaseAssetAmountFillable(updatedAMM, order.direction);
129
129
  return anchor_1.BN.min(maxBaseAssetAmount, baseAssetAmount);
130
130
  }
131
131
  exports.calculateBaseAssetAmountForAmmToFulfill = calculateBaseAssetAmountForAmmToFulfill;
132
132
  function calculateBaseAssetAmountToFillUpToLimitPrice(order, amm, limitPrice, oraclePriceData) {
133
- const [maxAmountToTrade, direction] = (0, amm_1.calculateMaxBaseAssetAmountToTrade)(amm, limitPrice, order.direction, oraclePriceData);
133
+ const [maxAmountToTrade, direction] = amm_1.calculateMaxBaseAssetAmountToTrade(amm, limitPrice, order.direction, oraclePriceData);
134
134
  const baseAssetAmount = standardizeBaseAssetAmount(maxAmountToTrade, amm.orderStepSize);
135
135
  // Check that directions are the same
136
136
  const sameDirection = isSameDirection(direction, order.direction);
@@ -144,12 +144,12 @@ function calculateBaseAssetAmountToFillUpToLimitPrice(order, amm, limitPrice, or
144
144
  }
145
145
  exports.calculateBaseAssetAmountToFillUpToLimitPrice = calculateBaseAssetAmountToFillUpToLimitPrice;
146
146
  function isSameDirection(firstDirection, secondDirection) {
147
- return (((0, types_1.isVariant)(firstDirection, 'long') && (0, types_1.isVariant)(secondDirection, 'long')) ||
148
- ((0, types_1.isVariant)(firstDirection, 'short') && (0, types_1.isVariant)(secondDirection, 'short')));
147
+ return ((types_1.isVariant(firstDirection, 'long') && types_1.isVariant(secondDirection, 'long')) ||
148
+ (types_1.isVariant(firstDirection, 'short') && types_1.isVariant(secondDirection, 'short')));
149
149
  }
150
150
  function isOrderExpired(order, ts) {
151
151
  if (mustBeTriggered(order) ||
152
- !(0, types_1.isVariant)(order.status, 'open') ||
152
+ !types_1.isVariant(order.status, 'open') ||
153
153
  order.maxTs.eq(numericConstants_1.ZERO)) {
154
154
  return false;
155
155
  }
@@ -157,19 +157,19 @@ function isOrderExpired(order, ts) {
157
157
  }
158
158
  exports.isOrderExpired = isOrderExpired;
159
159
  function isMarketOrder(order) {
160
- return (0, types_1.isOneOfVariant)(order.orderType, ['market', 'triggerMarket', 'oracle']);
160
+ return types_1.isOneOfVariant(order.orderType, ['market', 'triggerMarket', 'oracle']);
161
161
  }
162
162
  exports.isMarketOrder = isMarketOrder;
163
163
  function isLimitOrder(order) {
164
- return (0, types_1.isOneOfVariant)(order.orderType, ['limit', 'triggerLimit']);
164
+ return types_1.isOneOfVariant(order.orderType, ['limit', 'triggerLimit']);
165
165
  }
166
166
  exports.isLimitOrder = isLimitOrder;
167
167
  function mustBeTriggered(order) {
168
- return (0, types_1.isOneOfVariant)(order.orderType, ['triggerMarket', 'triggerLimit']);
168
+ return types_1.isOneOfVariant(order.orderType, ['triggerMarket', 'triggerLimit']);
169
169
  }
170
170
  exports.mustBeTriggered = mustBeTriggered;
171
171
  function isTriggered(order) {
172
- return (0, types_1.isOneOfVariant)(order.triggerCondition, [
172
+ return types_1.isOneOfVariant(order.triggerCondition, [
173
173
  'triggeredAbove',
174
174
  'triggeredBelow',
175
175
  ]);
@@ -23,7 +23,7 @@ function calculateBaseAssetValue(market, userPosition, oraclePriceData, useSprea
23
23
  let prepegAmm;
24
24
  if (!skipUpdate) {
25
25
  if (market.amm.baseSpread > 0 && useSpread) {
26
- const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = (0, amm_1.calculateUpdatedAMMSpreadReserves)(market.amm, directionToClose, oraclePriceData);
26
+ const { baseAssetReserve, quoteAssetReserve, sqrtK, newPeg } = amm_1.calculateUpdatedAMMSpreadReserves(market.amm, directionToClose, oraclePriceData);
27
27
  prepegAmm = {
28
28
  baseAssetReserve,
29
29
  quoteAssetReserve,
@@ -32,13 +32,13 @@ function calculateBaseAssetValue(market, userPosition, oraclePriceData, useSprea
32
32
  };
33
33
  }
34
34
  else {
35
- prepegAmm = (0, amm_1.calculateUpdatedAMM)(market.amm, oraclePriceData);
35
+ prepegAmm = amm_1.calculateUpdatedAMM(market.amm, oraclePriceData);
36
36
  }
37
37
  }
38
38
  else {
39
39
  prepegAmm = market.amm;
40
40
  }
41
- const [newQuoteAssetReserve, _] = (0, amm_1.calculateAmmReservesAfterSwap)(prepegAmm, 'base', userPosition.baseAssetAmount.abs(), (0, amm_1.getSwapDirection)('base', directionToClose));
41
+ const [newQuoteAssetReserve, _] = amm_1.calculateAmmReservesAfterSwap(prepegAmm, 'base', userPosition.baseAssetAmount.abs(), amm_1.getSwapDirection('base', directionToClose));
42
42
  switch (directionToClose) {
43
43
  case types_1.PositionDirection.SHORT:
44
44
  return prepegAmm.quoteAssetReserve
@@ -67,7 +67,7 @@ function calculatePositionPNL(market, perpPosition, withFunding = false, oracleP
67
67
  if (perpPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
68
68
  return perpPosition.quoteAssetAmount;
69
69
  }
70
- const baseAssetValue = (0, margin_1.calculateBaseAssetValueWithOracle)(market, perpPosition, oraclePriceData);
70
+ const baseAssetValue = margin_1.calculateBaseAssetValueWithOracle(market, perpPosition, oraclePriceData);
71
71
  const baseAssetValueSign = perpPosition.baseAssetAmount.isNeg()
72
72
  ? new __1.BN(-1)
73
73
  : new __1.BN(1);
@@ -86,7 +86,7 @@ function calculateClaimablePnl(market, spotMarket, perpPosition, oraclePriceData
86
86
  const fundingPnL = calculatePositionFundingPNL(market, perpPosition);
87
87
  let unsettledPnl = unrealizedPnl.add(fundingPnL);
88
88
  if (unrealizedPnl.gt(numericConstants_1.ZERO)) {
89
- const excessPnlPool = __1.BN.max(numericConstants_1.ZERO, (0, market_1.calculateNetUserPnlImbalance)(market, spotMarket, oraclePriceData).mul(new __1.BN(-1)));
89
+ const excessPnlPool = __1.BN.max(numericConstants_1.ZERO, market_1.calculateNetUserPnlImbalance(market, spotMarket, oraclePriceData).mul(new __1.BN(-1)));
90
90
  const maxPositivePnl = __1.BN.max(perpPosition.quoteAssetAmount.sub(perpPosition.quoteEntryAmount), numericConstants_1.ZERO).add(excessPnlPool);
91
91
  unsettledPnl = __1.BN.min(maxPositivePnl, unrealizedPnl);
92
92
  }
package/lib/math/repeg.js CHANGED
@@ -77,7 +77,7 @@ function calculateRepegCost(amm, newPeg) {
77
77
  }
78
78
  exports.calculateRepegCost = calculateRepegCost;
79
79
  function calculateBudgetedKBN(x, y, budget, Q, d) {
80
- (0, assert_1.assert)(Q.gt(new anchor_1.BN(0)));
80
+ assert_1.assert(Q.gt(new anchor_1.BN(0)));
81
81
  const C = budget.mul(new anchor_1.BN(-1));
82
82
  let dSign = new anchor_1.BN(1);
83
83
  if (d.lt(new anchor_1.BN(0))) {
@@ -8,11 +8,11 @@ const margin_1 = require("./margin");
8
8
  const numericConstants_2 = require("../constants/numericConstants");
9
9
  function getBalance(tokenAmount, spotMarket, balanceType) {
10
10
  const precisionIncrease = numericConstants_1.TEN.pow(new anchor_1.BN(19 - spotMarket.decimals));
11
- const cumulativeInterest = (0, types_1.isVariant)(balanceType, 'deposit')
11
+ const cumulativeInterest = types_1.isVariant(balanceType, 'deposit')
12
12
  ? spotMarket.cumulativeDepositInterest
13
13
  : spotMarket.cumulativeBorrowInterest;
14
14
  let balance = tokenAmount.mul(precisionIncrease).div(cumulativeInterest);
15
- if (!balance.eq(numericConstants_1.ZERO) && (0, types_1.isVariant)(balanceType, 'borrow')) {
15
+ if (!balance.eq(numericConstants_1.ZERO) && types_1.isVariant(balanceType, 'borrow')) {
16
16
  balance = balance.add(numericConstants_1.ONE);
17
17
  }
18
18
  return balance;
@@ -20,14 +20,14 @@ function getBalance(tokenAmount, spotMarket, balanceType) {
20
20
  exports.getBalance = getBalance;
21
21
  function getTokenAmount(balanceAmount, spotMarket, balanceType) {
22
22
  const precisionDecrease = numericConstants_1.TEN.pow(new anchor_1.BN(19 - spotMarket.decimals));
23
- const cumulativeInterest = (0, types_1.isVariant)(balanceType, 'deposit')
23
+ const cumulativeInterest = types_1.isVariant(balanceType, 'deposit')
24
24
  ? spotMarket.cumulativeDepositInterest
25
25
  : spotMarket.cumulativeBorrowInterest;
26
26
  return balanceAmount.mul(cumulativeInterest).div(precisionDecrease);
27
27
  }
28
28
  exports.getTokenAmount = getTokenAmount;
29
29
  function getSignedTokenAmount(tokenAmount, balanceType) {
30
- if ((0, types_1.isVariant)(balanceType, 'deposit')) {
30
+ if (types_1.isVariant(balanceType, 'deposit')) {
31
31
  return tokenAmount;
32
32
  }
33
33
  else {
@@ -57,7 +57,7 @@ function calculateAssetWeight(balanceAmount, spotMarket, marginCategory) {
57
57
  let assetWeight;
58
58
  switch (marginCategory) {
59
59
  case 'Initial':
60
- assetWeight = (0, margin_1.calculateSizeDiscountAssetWeight)(sizeInAmmReservePrecision, new anchor_1.BN(spotMarket.imfFactor), new anchor_1.BN(spotMarket.initialAssetWeight));
60
+ assetWeight = margin_1.calculateSizeDiscountAssetWeight(sizeInAmmReservePrecision, new anchor_1.BN(spotMarket.imfFactor), new anchor_1.BN(spotMarket.initialAssetWeight));
61
61
  break;
62
62
  case 'Maintenance':
63
63
  assetWeight = new anchor_1.BN(spotMarket.maintenanceAssetWeight);
@@ -83,10 +83,10 @@ function calculateLiabilityWeight(balanceAmount, spotMarket, marginCategory) {
83
83
  let assetWeight;
84
84
  switch (marginCategory) {
85
85
  case 'Initial':
86
- assetWeight = (0, margin_1.calculateSizePremiumLiabilityWeight)(sizeInAmmReservePrecision, new anchor_1.BN(spotMarket.imfFactor), new anchor_1.BN(spotMarket.initialLiabilityWeight), numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION);
86
+ assetWeight = margin_1.calculateSizePremiumLiabilityWeight(sizeInAmmReservePrecision, new anchor_1.BN(spotMarket.imfFactor), new anchor_1.BN(spotMarket.initialLiabilityWeight), numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION);
87
87
  break;
88
88
  case 'Maintenance':
89
- assetWeight = (0, margin_1.calculateSizePremiumLiabilityWeight)(sizeInAmmReservePrecision, new anchor_1.BN(spotMarket.imfFactor), new anchor_1.BN(spotMarket.maintenanceLiabilityWeight), numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION);
89
+ assetWeight = margin_1.calculateSizePremiumLiabilityWeight(sizeInAmmReservePrecision, new anchor_1.BN(spotMarket.imfFactor), new anchor_1.BN(spotMarket.maintenanceLiabilityWeight), numericConstants_1.SPOT_MARKET_WEIGHT_PRECISION);
90
90
  break;
91
91
  default:
92
92
  assetWeight = spotMarket.initialLiabilityWeight;
@@ -8,15 +8,15 @@ function isSpotPositionAvailable(position) {
8
8
  }
9
9
  exports.isSpotPositionAvailable = isSpotPositionAvailable;
10
10
  function getWorstCaseTokenAmounts(spotPosition, spotMarketAccount, oraclePriceData) {
11
- const tokenAmount = (0, spotBalance_1.getSignedTokenAmount)((0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarketAccount, spotPosition.balanceType), spotPosition.balanceType);
11
+ const tokenAmount = spotBalance_1.getSignedTokenAmount(spotBalance_1.getTokenAmount(spotPosition.scaledBalance, spotMarketAccount, spotPosition.balanceType), spotPosition.balanceType);
12
12
  const tokenAmountAllBidsFill = tokenAmount.add(spotPosition.openBids);
13
13
  const tokenAmountAllAsksFill = tokenAmount.add(spotPosition.openAsks);
14
14
  if (tokenAmountAllAsksFill.abs().gt(tokenAmountAllBidsFill.abs())) {
15
- const worstCaseQuoteTokenAmount = (0, spotBalance_1.getTokenValue)(spotPosition.openAsks.neg(), spotMarketAccount.decimals, oraclePriceData);
15
+ const worstCaseQuoteTokenAmount = spotBalance_1.getTokenValue(spotPosition.openAsks.neg(), spotMarketAccount.decimals, oraclePriceData);
16
16
  return [tokenAmountAllBidsFill, worstCaseQuoteTokenAmount];
17
17
  }
18
18
  else {
19
- const worstCaseQuoteTokenAmount = (0, spotBalance_1.getTokenValue)(spotPosition.openBids.neg(), spotMarketAccount.decimals, oraclePriceData);
19
+ const worstCaseQuoteTokenAmount = spotBalance_1.getTokenValue(spotPosition.openBids.neg(), spotMarketAccount.decimals, oraclePriceData);
20
20
  return [tokenAmountAllAsksFill, worstCaseQuoteTokenAmount];
21
21
  }
22
22
  }
@@ -1,9 +1,11 @@
1
1
  /// <reference types="bn.js" />
2
- import { PerpMarketAccount, PositionDirection } from '../types';
2
+ import { PerpMarketAccount, PositionDirection, SpotMarketAccount } from '../types';
3
3
  import { BN } from '@project-serum/anchor';
4
4
  import { AssetType } from './amm';
5
5
  import { OraclePriceData } from '../oracles/types';
6
6
  import { DLOB } from '../dlob/DLOB';
7
+ import { PublicKey } from '@solana/web3.js';
8
+ import { Orderbook } from '@project-serum/serum';
7
9
  export declare type PriceImpactUnit = 'entryPrice' | 'maxPrice' | 'priceDelta' | 'priceDeltaAsNumber' | 'pctAvg' | 'pctMax' | 'quoteAssetAmount' | 'quoteAssetAmountPeg' | 'acquiredBaseAssetAmount' | 'acquiredQuoteAssetAmount' | 'all';
8
10
  /**
9
11
  * Calculates avg/max slippage (price impact) for candidate trade
@@ -64,6 +66,36 @@ export declare function calculateTargetPriceTrade(market: PerpMarketAccount, tar
64
66
  * @param oraclePriceData
65
67
  * @param dlob
66
68
  * @param slot
67
- * @param minPerpAuctionDuration
69
+ * @param usersToSkip
68
70
  */
69
- export declare function calculateEstimatedPerpEntryPrice(assetType: AssetType, amount: BN, direction: PositionDirection, market: PerpMarketAccount, oraclePriceData: OraclePriceData, dlob: DLOB, slot: number, minPerpAuctionDuration: number): [BN, BN];
71
+ export declare function calculateEstimatedPerpEntryPrice(assetType: AssetType, amount: BN, direction: PositionDirection, market: PerpMarketAccount, oraclePriceData: OraclePriceData, dlob: DLOB, slot: number, usersToSkip?: Map<PublicKey, boolean>): {
72
+ entryPrice: BN;
73
+ priceImpact: BN;
74
+ bestPrice: BN;
75
+ worstPrice: BN;
76
+ baseFilled: BN;
77
+ quoteFilled: BN;
78
+ };
79
+ /**
80
+ * Calculates the estimated entry price and price impact of order, in base or quote
81
+ * Price impact is based on the difference between the entry price and the best bid/ask price (whether it's dlob or serum)
82
+ *
83
+ * @param assetType
84
+ * @param amount
85
+ * @param direction
86
+ * @param market
87
+ * @param oraclePriceData
88
+ * @param dlob
89
+ * @param serumBids
90
+ * @param serumAsks
91
+ * @param slot
92
+ * @param usersToSkip
93
+ */
94
+ export declare function calculateEstimatedSpotEntryPrice(assetType: AssetType, amount: BN, direction: PositionDirection, market: SpotMarketAccount, oraclePriceData: OraclePriceData, dlob: DLOB, serumBids: Orderbook, serumAsks: Orderbook, slot: number, usersToSkip?: Map<PublicKey, boolean>): {
95
+ entryPrice: BN;
96
+ priceImpact: BN;
97
+ bestPrice: BN;
98
+ worstPrice: BN;
99
+ baseFilled: BN;
100
+ quoteFilled: BN;
101
+ };