@drift-labs/sdk 2.10.0-beta.1 → 2.10.0-beta.3

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 (63) hide show
  1. package/lib/accounts/bulkAccountLoader.d.ts +2 -1
  2. package/lib/accounts/pollingDriftClientAccountSubscriber.js +12 -3
  3. package/lib/accounts/types.d.ts +5 -4
  4. package/lib/adminClient.js +96 -34
  5. package/lib/config.d.ts +2 -2
  6. package/lib/constants/perpMarkets.d.ts +1 -1
  7. package/lib/constants/spotMarkets.d.ts +1 -1
  8. package/lib/dlob/DLOB.d.ts +4 -4
  9. package/lib/dlob/DLOBNode.d.ts +2 -2
  10. package/lib/dlob/DLOBOrders.d.ts +2 -2
  11. package/lib/dlob/NodeList.d.ts +1 -1
  12. package/lib/driftClient.d.ts +4 -3
  13. package/lib/driftClient.js +105 -64
  14. package/lib/driftClientConfig.d.ts +3 -3
  15. package/lib/events/fetchLogs.d.ts +2 -2
  16. package/lib/events/types.d.ts +13 -13
  17. package/lib/factory/bigNum.js +4 -4
  18. package/lib/idl/drift.json +1 -1
  19. package/lib/index.d.ts +1 -0
  20. package/lib/index.js +1 -0
  21. package/lib/math/amm.d.ts +1 -1
  22. package/lib/math/amm.js +15 -6
  23. package/lib/math/oracles.js +2 -2
  24. package/lib/math/repeg.d.ts +1 -1
  25. package/lib/math/repeg.js +46 -19
  26. package/lib/math/trade.d.ts +1 -1
  27. package/lib/oracles/types.d.ts +2 -2
  28. package/lib/serum/types.d.ts +1 -1
  29. package/lib/slot/SlotSubscriber.d.ts +1 -1
  30. package/lib/testClient.d.ts +8 -0
  31. package/lib/testClient.js +22 -0
  32. package/lib/tx/retryTxSender.d.ts +1 -1
  33. package/lib/tx/types.d.ts +1 -1
  34. package/lib/types.d.ts +43 -43
  35. package/lib/user.d.ts +1 -0
  36. package/lib/user.js +10 -6
  37. package/lib/userConfig.d.ts +2 -2
  38. package/lib/userMap/userMap.js +3 -0
  39. package/lib/userMap/userStatsMap.js +3 -0
  40. package/lib/userStatsConfig.d.ts +2 -2
  41. package/package.json +1 -1
  42. package/src/accounts/pollingDriftClientAccountSubscriber.ts +26 -3
  43. package/src/adminClient.ts +301 -169
  44. package/src/driftClient.ts +199 -118
  45. package/src/driftClientConfig.ts +1 -1
  46. package/src/idl/drift.json +1 -1
  47. package/src/index.ts +1 -0
  48. package/src/math/amm.ts +27 -12
  49. package/src/math/oracles.ts +6 -4
  50. package/src/math/repeg.ts +54 -26
  51. package/src/testClient.ts +40 -0
  52. package/src/user.ts +5 -0
  53. package/src/userMap/userMap.ts +2 -0
  54. package/src/userMap/userStatsMap.ts +2 -0
  55. package/src/assert/assert.js +0 -9
  56. package/src/examples/makeTradeExample.js +0 -157
  57. package/src/token/index.js +0 -38
  58. package/src/tx/types.js +0 -2
  59. package/src/tx/utils.js +0 -17
  60. package/src/util/computeUnits.js +0 -27
  61. package/src/util/getTokenAddress.js +0 -9
  62. package/src/util/promiseTimeout.js +0 -14
  63. package/src/util/tps.js +0 -27
@@ -1,6 +1,6 @@
1
1
  import { Commitment, TransactionSignature } from '@solana/web3.js';
2
2
  import { DepositRecord, FundingPaymentRecord, FundingRateRecord, LiquidationRecord, NewUserRecord, OrderActionRecord, OrderRecord, SettlePnlRecord, LPRecord, InsuranceFundRecord, SpotInterestRecord, InsuranceFundStakeRecord, CurveRecord } from '../index';
3
- export declare type EventSubscriptionOptions = {
3
+ export type EventSubscriptionOptions = {
4
4
  eventTypes?: EventType[];
5
5
  maxEventsPerType?: number;
6
6
  orderBy?: EventSubscriptionOrderBy;
@@ -11,17 +11,17 @@ export declare type EventSubscriptionOptions = {
11
11
  untilTx?: TransactionSignature;
12
12
  };
13
13
  export declare const DefaultEventSubscriptionOptions: EventSubscriptionOptions;
14
- export declare type EventSubscriptionOrderBy = 'blockchain' | 'client';
15
- export declare type EventSubscriptionOrderDirection = 'asc' | 'desc';
16
- export declare type Event<T> = T & {
14
+ export type EventSubscriptionOrderBy = 'blockchain' | 'client';
15
+ export type EventSubscriptionOrderDirection = 'asc' | 'desc';
16
+ export type Event<T> = T & {
17
17
  txSig: TransactionSignature;
18
18
  slot: number;
19
19
  };
20
- export declare type WrappedEvent<Type extends EventType> = EventMap[Type] & {
20
+ export type WrappedEvent<Type extends EventType> = EventMap[Type] & {
21
21
  eventType: Type;
22
22
  };
23
- export declare type WrappedEvents = WrappedEvent<EventType>[];
24
- export declare type EventMap = {
23
+ export type WrappedEvents = WrappedEvent<EventType>[];
24
+ export type EventMap = {
25
25
  DepositRecord: Event<DepositRecord>;
26
26
  FundingPaymentRecord: Event<FundingPaymentRecord>;
27
27
  LiquidationRecord: Event<LiquidationRecord>;
@@ -36,22 +36,22 @@ export declare type EventMap = {
36
36
  InsuranceFundStakeRecord: Event<InsuranceFundStakeRecord>;
37
37
  CurveRecord: Event<CurveRecord>;
38
38
  };
39
- export declare type EventType = keyof EventMap;
39
+ export type EventType = keyof EventMap;
40
40
  export interface EventSubscriberEvents {
41
41
  newEvent: (event: WrappedEvent<EventType>) => void;
42
42
  }
43
- export declare type SortFn = (currentRecord: EventMap[EventType], newRecord: EventMap[EventType]) => 'less than' | 'greater than';
44
- export declare type logProviderCallback = (txSig: TransactionSignature, slot: number, logs: string[], mostRecentBlockTime: number | undefined) => void;
43
+ export type SortFn = (currentRecord: EventMap[EventType], newRecord: EventMap[EventType]) => 'less than' | 'greater than';
44
+ export type logProviderCallback = (txSig: TransactionSignature, slot: number, logs: string[], mostRecentBlockTime: number | undefined) => void;
45
45
  export interface LogProvider {
46
46
  isSubscribed(): boolean;
47
47
  subscribe(callback: logProviderCallback, skipHistory?: boolean): boolean;
48
48
  unsubscribe(): Promise<boolean>;
49
49
  }
50
- export declare type WebSocketLogProviderConfig = {
50
+ export type WebSocketLogProviderConfig = {
51
51
  type: 'websocket';
52
52
  };
53
- export declare type PollingLogProviderConfig = {
53
+ export type PollingLogProviderConfig = {
54
54
  type: 'polling';
55
55
  frequency: number;
56
56
  };
57
- export declare type LogProviderConfig = WebSocketLogProviderConfig | PollingLogProviderConfig;
57
+ export type LogProviderConfig = WebSocketLogProviderConfig | PollingLogProviderConfig;
@@ -5,15 +5,15 @@ const anchor_1 = require("@project-serum/anchor");
5
5
  const assert_1 = require("../assert/assert");
6
6
  const numericConstants_1 = require("./../constants/numericConstants");
7
7
  class BigNum {
8
+ static setLocale(locale) {
9
+ BigNum.delim = (1.1).toLocaleString(locale).slice(1, 2) || '.';
10
+ BigNum.spacer = (1000).toLocaleString(locale).slice(1, 2) || ',';
11
+ }
8
12
  constructor(val, precisionVal = new anchor_1.BN(0)) {
9
13
  this.toString = (base, length) => this.val.toString(base, length);
10
14
  this.val = new anchor_1.BN(val);
11
15
  this.precision = new anchor_1.BN(precisionVal);
12
16
  }
13
- static setLocale(locale) {
14
- BigNum.delim = (1.1).toLocaleString(locale).slice(1, 2) || '.';
15
- BigNum.spacer = (1000).toLocaleString(locale).slice(1, 2) || ',';
16
- }
17
17
  bigNumFromParam(bn) {
18
18
  return anchor_1.BN.isBN(bn) ? BigNum.from(bn) : bn;
19
19
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.10.0-beta.1",
2
+ "version": "2.10.0-beta.3",
3
3
  "name": "drift",
4
4
  "instructions": [
5
5
  {
package/lib/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export * from './accounts/pollingUserStatsAccountSubscriber';
20
20
  export * from './accounts/types';
21
21
  export * from './addresses/pda';
22
22
  export * from './adminClient';
23
+ export * from './testClient';
23
24
  export * from './user';
24
25
  export * from './userConfig';
25
26
  export * from './userStats';
package/lib/index.js CHANGED
@@ -43,6 +43,7 @@ __exportStar(require("./accounts/pollingUserStatsAccountSubscriber"), exports);
43
43
  __exportStar(require("./accounts/types"), exports);
44
44
  __exportStar(require("./addresses/pda"), exports);
45
45
  __exportStar(require("./adminClient"), exports);
46
+ __exportStar(require("./testClient"), exports);
46
47
  __exportStar(require("./user"), exports);
47
48
  __exportStar(require("./userConfig"), exports);
48
49
  __exportStar(require("./userStats"), exports);
package/lib/math/amm.d.ts CHANGED
@@ -22,7 +22,7 @@ export declare function calculateBidAskPrice(amm: AMM, oraclePriceData: OraclePr
22
22
  * @returns price : Precision PRICE_PRECISION
23
23
  */
24
24
  export declare function calculatePrice(baseAssetReserves: BN, quoteAssetReserves: BN, pegMultiplier: BN): BN;
25
- export declare type AssetType = 'quote' | 'base';
25
+ export type AssetType = 'quote' | 'base';
26
26
  /**
27
27
  * Calculates what the amm reserves would be after swapping a quote or base asset amount.
28
28
  *
package/lib/math/amm.js CHANGED
@@ -23,6 +23,7 @@ function calculateOptimalPegAndBudget(amm, oraclePriceData) {
23
23
  const prePegCost = (0, repeg_1.calculateRepegCost)(amm, newPeg);
24
24
  const totalFeeLB = amm.totalExchangeFee.div(new anchor_1.BN(2));
25
25
  const budget = anchor_1.BN.max(numericConstants_1.ZERO, amm.totalFeeMinusDistributions.sub(totalFeeLB));
26
+ let checkLowerBound = true;
26
27
  if (budget.lt(prePegCost)) {
27
28
  const halfMaxPriceSpread = new anchor_1.BN(amm.maxSpread)
28
29
  .div(new anchor_1.BN(2))
@@ -42,19 +43,23 @@ function calculateOptimalPegAndBudget(amm, oraclePriceData) {
42
43
  }
43
44
  newOptimalPeg = calculatePegFromTargetPrice(newTargetPrice, amm.baseAssetReserve, amm.quoteAssetReserve);
44
45
  newBudget = (0, repeg_1.calculateRepegCost)(amm, newOptimalPeg);
46
+ checkLowerBound = false;
45
47
  return [newTargetPrice, newOptimalPeg, newBudget, false];
46
48
  }
49
+ else if (amm.totalFeeMinusDistributions.lt(amm.totalExchangeFee.div(new anchor_1.BN(2)))) {
50
+ checkLowerBound = false;
51
+ }
47
52
  }
48
- return [targetPrice, newPeg, budget, true];
53
+ return [targetPrice, newPeg, budget, checkLowerBound];
49
54
  }
50
55
  exports.calculateOptimalPegAndBudget = calculateOptimalPegAndBudget;
51
56
  function calculateNewAmm(amm, oraclePriceData) {
52
57
  let pKNumer = new anchor_1.BN(1);
53
58
  let pKDenom = new anchor_1.BN(1);
54
- const [targetPrice, _newPeg, budget, checkLowerBound] = calculateOptimalPegAndBudget(amm, oraclePriceData);
59
+ const [targetPrice, _newPeg, budget, _checkLowerBound] = calculateOptimalPegAndBudget(amm, oraclePriceData);
55
60
  let prePegCost = (0, repeg_1.calculateRepegCost)(amm, _newPeg);
56
61
  let newPeg = _newPeg;
57
- if (prePegCost.gt(budget) && checkLowerBound) {
62
+ if (prePegCost.gte(budget) && prePegCost.gt(numericConstants_1.ZERO)) {
58
63
  [pKNumer, pKDenom] = [new anchor_1.BN(999), new anchor_1.BN(1000)];
59
64
  const deficitMadeup = (0, repeg_1.calculateAdjustKCost)(amm, pKNumer, pKDenom);
60
65
  (0, assert_1.assert)(deficitMadeup.lte(new anchor_1.BN(0)));
@@ -76,7 +81,7 @@ function calculateNewAmm(amm, oraclePriceData) {
76
81
  }
77
82
  exports.calculateNewAmm = calculateNewAmm;
78
83
  function calculateUpdatedAMM(amm, oraclePriceData) {
79
- if (amm.curveUpdateIntensity == 0) {
84
+ if (amm.curveUpdateIntensity == 0 || oraclePriceData === undefined) {
80
85
  return amm;
81
86
  }
82
87
  const newAmm = Object.assign({}, amm);
@@ -325,8 +330,12 @@ function calculateSpreadBN(baseSpread, lastOracleReservePriceSpreadPct, lastOrac
325
330
  spreadTerms.longSpreadwEL = longSpread;
326
331
  spreadTerms.shortSpreadwEL = shortSpread;
327
332
  if (netRevenueSinceLastFunding.lt(numericConstants_1.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT)) {
328
- const revenueRetreatAmount = Math.min(maxTargetSpread / 10, Math.floor((baseSpread * netRevenueSinceLastFunding.abs().toNumber()) /
329
- numericConstants_1.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT.abs().toNumber()));
333
+ const maxRetreat = maxTargetSpread / 10;
334
+ let revenueRetreatAmount = maxRetreat;
335
+ if (netRevenueSinceLastFunding.gte(numericConstants_1.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT.mul(new anchor_1.BN(1000)))) {
336
+ revenueRetreatAmount = Math.min(maxRetreat, Math.floor((baseSpread * netRevenueSinceLastFunding.abs().toNumber()) /
337
+ numericConstants_1.DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT.abs().toNumber()));
338
+ }
330
339
  const halfRevenueRetreatAmount = Math.floor(revenueRetreatAmount / 2);
331
340
  spreadTerms.revenueRetreatAmount = revenueRetreatAmount;
332
341
  spreadTerms.halfRevenueRetreatAmount = halfRevenueRetreatAmount;
@@ -53,7 +53,7 @@ function isOracleTooDivergent(amm, oraclePriceData, oracleGuardRails, now) {
53
53
  }
54
54
  exports.isOracleTooDivergent = isOracleTooDivergent;
55
55
  function calculateLiveOracleTwap(amm, oraclePriceData, now) {
56
- const sinceLastUpdate = now.sub(amm.historicalOracleData.lastOraclePriceTwapTs);
56
+ const sinceLastUpdate = index_1.BN.max(numericConstants_1.ONE, now.sub(amm.historicalOracleData.lastOraclePriceTwapTs));
57
57
  const sinceStart = index_1.BN.max(numericConstants_1.ZERO, amm.fundingPeriod.sub(sinceLastUpdate));
58
58
  const clampRange = amm.historicalOracleData.lastOraclePriceTwap.div(new index_1.BN(3));
59
59
  const clampedOraclePrice = index_1.BN.min(amm.historicalOracleData.lastOraclePriceTwap.add(clampRange), index_1.BN.max(oraclePriceData.price, amm.historicalOracleData.lastOraclePriceTwap.sub(clampRange)));
@@ -65,7 +65,7 @@ function calculateLiveOracleTwap(amm, oraclePriceData, now) {
65
65
  }
66
66
  exports.calculateLiveOracleTwap = calculateLiveOracleTwap;
67
67
  function calculateLiveOracleStd(amm, oraclePriceData, now) {
68
- const sinceLastUpdate = now.sub(amm.historicalOracleData.lastOraclePriceTwapTs);
68
+ const sinceLastUpdate = index_1.BN.max(numericConstants_1.ONE, now.sub(amm.historicalOracleData.lastOraclePriceTwapTs));
69
69
  const sinceStart = index_1.BN.max(numericConstants_1.ZERO, amm.fundingPeriod.sub(sinceLastUpdate));
70
70
  const liveOracleTwap = calculateLiveOracleTwap(amm, oraclePriceData, now);
71
71
  const priceDeltaVsTwap = oraclePriceData.price.sub(liveOracleTwap).abs();
@@ -19,4 +19,4 @@ export declare function calculateAdjustKCost(amm: AMM, numerator: BN, denomenato
19
19
  export declare function calculateRepegCost(amm: AMM, newPeg: BN): BN;
20
20
  export declare function calculateBudgetedKBN(x: BN, y: BN, budget: BN, Q: BN, d: BN): [BN, BN];
21
21
  export declare function calculateBudgetedK(amm: AMM, cost: BN): [BN, BN];
22
- export declare function calculateBudgetedPeg(amm: AMM, cost: BN, targetPrice: BN): BN;
22
+ export declare function calculateBudgetedPeg(amm: AMM, budget: BN, targetPrice: BN): BN;
package/lib/math/repeg.js CHANGED
@@ -20,16 +20,46 @@ function calculateAdjustKCost(amm, numerator, denomenator) {
20
20
  const quoteScale = y.mul(d).mul(Q); //.div(AMM_RESERVE_PRECISION);
21
21
  const p = numerator.mul(numericConstants_1.PRICE_PRECISION).div(denomenator);
22
22
  const cost = quoteScale
23
+ .mul(numericConstants_1.PERCENTAGE_PRECISION)
24
+ .mul(numericConstants_1.PERCENTAGE_PRECISION)
23
25
  .div(x.add(d))
24
26
  .sub(quoteScale
25
27
  .mul(p)
28
+ .mul(numericConstants_1.PERCENTAGE_PRECISION)
29
+ .mul(numericConstants_1.PERCENTAGE_PRECISION)
26
30
  .div(numericConstants_1.PRICE_PRECISION)
27
31
  .div(x.mul(p).div(numericConstants_1.PRICE_PRECISION).add(d)))
32
+ .div(numericConstants_1.PERCENTAGE_PRECISION)
33
+ .div(numericConstants_1.PERCENTAGE_PRECISION)
28
34
  .div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
29
35
  .div(numericConstants_1.PEG_PRECISION);
30
36
  return cost.mul(new anchor_1.BN(-1));
31
37
  }
32
38
  exports.calculateAdjustKCost = calculateAdjustKCost;
39
+ // /**
40
+ // * Helper function calculating adjust k cost
41
+ // * @param amm
42
+ // * @param numerator
43
+ // * @param denomenator
44
+ // * @returns cost : Precision QUOTE_ASSET_PRECISION
45
+ // */
46
+ // export function calculateAdjustKCost2(
47
+ // amm: AMM,
48
+ // numerator: BN,
49
+ // denomenator: BN
50
+ // ): BN {
51
+ // // const k = market.amm.sqrtK.mul(market.amm.sqrtK);
52
+ // const directionToClose = amm.baseAssetAmountWithAmm.gt(ZERO)
53
+ // ? PositionDirection.SHORT
54
+ // : PositionDirection.LONG;
55
+ // const [newQuoteAssetReserve, _newBaseAssetReserve] =
56
+ // calculateAmmReservesAfterSwap(
57
+ // amm,
58
+ // 'base',
59
+ // amm.baseAssetAmountWithAmm.abs(),
60
+ // getSwapDirection('base', directionToClose)
61
+ // );
62
+ // }
33
63
  /**
34
64
  * Helper function calculating adjust pegMultiplier (repeg) cost
35
65
  *
@@ -107,31 +137,28 @@ function calculateBudgetedK(amm, cost) {
107
137
  return [numerator, denominator];
108
138
  }
109
139
  exports.calculateBudgetedK = calculateBudgetedK;
110
- function calculateBudgetedPeg(amm, cost, targetPrice) {
111
- // wolframalpha.com
112
- // (1/(x+d) - p/(x*p+d))*y*d*Q = C solve for p
113
- // p = (d(y*d*Q - C(x+d))) / (C*x(x+d) + y*y*d*Q)
114
- // todo: assumes k = x * y
115
- // otherwise use: (y(1-p) + (kp^2/(x*p+d)) - k/(x+d)) * Q = C solve for p
140
+ function calculateBudgetedPeg(amm, budget, targetPrice) {
141
+ let perPegCost = amm.quoteAssetReserve
142
+ .sub(amm.terminalQuoteAssetReserve)
143
+ .div(numericConstants_1.AMM_RESERVE_PRECISION.div(numericConstants_1.PRICE_PRECISION));
144
+ if (perPegCost.gt(numericConstants_1.ZERO)) {
145
+ perPegCost = perPegCost.add(numericConstants_1.ONE);
146
+ }
147
+ else if (perPegCost.lt(numericConstants_1.ZERO)) {
148
+ perPegCost = perPegCost.sub(numericConstants_1.ONE);
149
+ }
116
150
  const targetPeg = targetPrice
117
151
  .mul(amm.baseAssetReserve)
118
152
  .div(amm.quoteAssetReserve)
119
153
  .div(numericConstants_1.PRICE_DIV_PEG);
120
- const k = amm.sqrtK.mul(amm.sqrtK);
121
- const x = amm.baseAssetReserve;
122
- const y = amm.quoteAssetReserve;
123
- const d = amm.baseAssetAmountWithAmm;
124
- const Q = amm.pegMultiplier;
125
- const C = cost.mul(new anchor_1.BN(-1));
126
- const deltaQuoteAssetReserves = y.sub(k.div(x.add(d)));
127
- const pegChangeDirection = targetPeg.sub(Q);
128
- const useTargetPeg = (deltaQuoteAssetReserves.lt(numericConstants_1.ZERO) && pegChangeDirection.gt(numericConstants_1.ZERO)) ||
129
- (deltaQuoteAssetReserves.gt(numericConstants_1.ZERO) && pegChangeDirection.lt(numericConstants_1.ZERO));
130
- if (deltaQuoteAssetReserves.eq(numericConstants_1.ZERO) || useTargetPeg) {
154
+ const pegChangeDirection = targetPeg.sub(amm.pegMultiplier);
155
+ const useTargetPeg = (perPegCost.lt(numericConstants_1.ZERO) && pegChangeDirection.gt(numericConstants_1.ZERO)) ||
156
+ (perPegCost.gt(numericConstants_1.ZERO) && pegChangeDirection.lt(numericConstants_1.ZERO));
157
+ if (perPegCost.eq(numericConstants_1.ZERO) || useTargetPeg) {
131
158
  return targetPeg;
132
159
  }
133
- const deltaPegMultiplier = C.mul(numericConstants_1.PRICE_PRECISION).div(deltaQuoteAssetReserves.div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO));
134
- const newPeg = Q.sub(deltaPegMultiplier.mul(numericConstants_1.PEG_PRECISION).div(numericConstants_1.PRICE_PRECISION));
160
+ const budgetDeltaPeg = budget.mul(numericConstants_1.PEG_PRECISION).div(perPegCost);
161
+ const newPeg = anchor_1.BN.max(numericConstants_1.ONE, amm.pegMultiplier.add(budgetDeltaPeg));
135
162
  return newPeg;
136
163
  }
137
164
  exports.calculateBudgetedPeg = calculateBudgetedPeg;
@@ -3,7 +3,7 @@ import { PerpMarketAccount, PositionDirection } from '../types';
3
3
  import { BN } from '@project-serum/anchor';
4
4
  import { AssetType } from './amm';
5
5
  import { OraclePriceData } from '../oracles/types';
6
- export declare type PriceImpactUnit = 'entryPrice' | 'maxPrice' | 'priceDelta' | 'priceDeltaAsNumber' | 'pctAvg' | 'pctMax' | 'quoteAssetAmount' | 'quoteAssetAmountPeg' | 'acquiredBaseAssetAmount' | 'acquiredQuoteAssetAmount' | 'all';
6
+ export type PriceImpactUnit = 'entryPrice' | 'maxPrice' | 'priceDelta' | 'priceDeltaAsNumber' | 'pctAvg' | 'pctMax' | 'quoteAssetAmount' | 'quoteAssetAmountPeg' | 'acquiredBaseAssetAmount' | 'acquiredQuoteAssetAmount' | 'all';
7
7
  /**
8
8
  * Calculates avg/max slippage (price impact) for candidate trade
9
9
  * @param direction
@@ -3,7 +3,7 @@
3
3
  import { BN } from '@project-serum/anchor';
4
4
  import { PublicKey } from '@solana/web3.js';
5
5
  import { OracleSource } from '../types';
6
- export declare type OraclePriceData = {
6
+ export type OraclePriceData = {
7
7
  price: BN;
8
8
  slot: BN;
9
9
  confidence: BN;
@@ -11,7 +11,7 @@ export declare type OraclePriceData = {
11
11
  twap?: BN;
12
12
  twapConfidence?: BN;
13
13
  };
14
- export declare type OracleInfo = {
14
+ export type OracleInfo = {
15
15
  publicKey: PublicKey;
16
16
  source: OracleSource;
17
17
  };
@@ -1,6 +1,6 @@
1
1
  import { Connection, PublicKey } from '@solana/web3.js';
2
2
  import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
3
- export declare type SerumMarketSubscriberConfig = {
3
+ export type SerumMarketSubscriberConfig = {
4
4
  connection: Connection;
5
5
  programId: PublicKey;
6
6
  marketAddress: PublicKey;
@@ -2,7 +2,7 @@
2
2
  import { Connection } from '@solana/web3.js';
3
3
  import { EventEmitter } from 'events';
4
4
  import StrictEventEmitter from 'strict-event-emitter-types/types/src';
5
- declare type SlotSubscriberConfig = {};
5
+ type SlotSubscriberConfig = {};
6
6
  export interface SlotSubscriberEvents {
7
7
  newSlot: (newSlot: number) => void;
8
8
  }
@@ -0,0 +1,8 @@
1
+ import { AdminClient } from './adminClient';
2
+ import { ConfirmOptions, Signer, Transaction } from '@solana/web3.js';
3
+ import { TxSigAndSlot } from './tx/types';
4
+ import { DriftClientConfig } from './driftClientConfig';
5
+ export declare class TestClient extends AdminClient {
6
+ constructor(config: DriftClientConfig);
7
+ sendTransaction(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions, preSigned?: boolean): Promise<TxSigAndSlot>;
8
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestClient = void 0;
4
+ const adminClient_1 = require("./adminClient");
5
+ class TestClient extends adminClient_1.AdminClient {
6
+ constructor(config) {
7
+ if (config.accountSubscription.type !== 'polling') {
8
+ throw new Error('Test client must be polling');
9
+ }
10
+ super(config);
11
+ }
12
+ async sendTransaction(tx, additionalSigners, opts, preSigned) {
13
+ const { txSig, slot } = await super.sendTransaction(tx, additionalSigners, opts, preSigned);
14
+ let lastFetchedSlot = this.accountSubscriber.accountLoader.mostRecentSlot;
15
+ while (lastFetchedSlot < slot) {
16
+ await this.fetchAccounts();
17
+ lastFetchedSlot = this.accountSubscriber.accountLoader.mostRecentSlot;
18
+ }
19
+ return { txSig, slot };
20
+ }
21
+ }
22
+ exports.TestClient = TestClient;
@@ -2,7 +2,7 @@
2
2
  import { TxSender, TxSigAndSlot } from './types';
3
3
  import { Commitment, ConfirmOptions, RpcResponseAndContext, Signer, SignatureResult, Transaction, TransactionSignature, Connection } from '@solana/web3.js';
4
4
  import { AnchorProvider } from '@project-serum/anchor';
5
- declare type ResolveReference = {
5
+ type ResolveReference = {
6
6
  resolve?: () => void;
7
7
  };
8
8
  export declare class RetryTxSender implements TxSender {
package/lib/tx/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Provider } from '@project-serum/anchor';
2
2
  import { ConfirmOptions, Signer, Transaction, TransactionSignature } from '@solana/web3.js';
3
- export declare type TxSigAndSlot = {
3
+ export type TxSigAndSlot = {
4
4
  txSig: TransactionSignature;
5
5
  slot: number;
6
6
  };