@drift-labs/sdk 2.52.0-beta.1 → 2.52.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/VERSION +1 -1
  2. package/examples/phoenix.ts +11 -4
  3. package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
  4. package/lib/accounts/webSocketAccountSubscriber.js +7 -4
  5. package/lib/accounts/webSocketProgramAccountSubscriber.d.ts +1 -1
  6. package/lib/accounts/webSocketProgramAccountSubscriber.js +7 -4
  7. package/lib/dlob/orderBookLevels.d.ts +22 -0
  8. package/lib/dlob/orderBookLevels.js +115 -1
  9. package/lib/driftClient.d.ts +3 -1
  10. package/lib/driftClient.js +30 -8
  11. package/lib/events/webSocketLogProvider.js +3 -3
  12. package/lib/factory/bigNum.d.ts +1 -1
  13. package/lib/factory/bigNum.js +5 -2
  14. package/lib/idl/drift.json +52 -1
  15. package/lib/index.d.ts +1 -1
  16. package/lib/index.js +1 -1
  17. package/lib/math/amm.d.ts +5 -1
  18. package/lib/math/amm.js +62 -13
  19. package/lib/math/state.js +3 -0
  20. package/lib/orderSubscriber/OrderSubscriber.js +1 -0
  21. package/lib/orderSubscriber/WebsocketSubscription.d.ts +4 -1
  22. package/lib/orderSubscriber/WebsocketSubscription.js +25 -1
  23. package/lib/orderSubscriber/types.d.ts +1 -0
  24. package/lib/phoenix/phoenixSubscriber.js +10 -6
  25. package/lib/priorityFee/averageOverSlotsStrategy.d.ts +12 -0
  26. package/lib/priorityFee/averageOverSlotsStrategy.js +28 -0
  27. package/lib/priorityFee/averageStrategy.d.ts +7 -0
  28. package/lib/priorityFee/averageStrategy.js +11 -0
  29. package/lib/priorityFee/ewmaStrategy.d.ts +13 -0
  30. package/lib/priorityFee/ewmaStrategy.js +33 -0
  31. package/lib/priorityFee/index.d.ts +7 -0
  32. package/lib/priorityFee/index.js +23 -0
  33. package/lib/priorityFee/maxOverSlotsStrategy.d.ts +12 -0
  34. package/lib/priorityFee/maxOverSlotsStrategy.js +29 -0
  35. package/lib/priorityFee/maxStrategy.d.ts +7 -0
  36. package/lib/priorityFee/maxStrategy.js +9 -0
  37. package/lib/priorityFee/priorityFeeSubscriber.d.ts +15 -4
  38. package/lib/priorityFee/priorityFeeSubscriber.js +38 -14
  39. package/lib/priorityFee/types.d.ts +6 -0
  40. package/lib/priorityFee/types.js +2 -0
  41. package/lib/slot/SlotSubscriber.d.ts +11 -3
  42. package/lib/slot/SlotSubscriber.js +40 -4
  43. package/lib/types.d.ts +4 -1
  44. package/lib/types.js +1 -0
  45. package/lib/user.d.ts +1 -1
  46. package/lib/user.js +15 -8
  47. package/lib/userMap/userMap.d.ts +3 -0
  48. package/lib/userMap/userMap.js +9 -0
  49. package/package.json +1 -1
  50. package/src/accounts/webSocketAccountSubscriber.ts +7 -4
  51. package/src/accounts/webSocketProgramAccountSubscriber.ts +7 -4
  52. package/src/dlob/orderBookLevels.ts +136 -0
  53. package/src/driftClient.ts +46 -8
  54. package/src/events/webSocketLogProvider.ts +3 -3
  55. package/src/factory/bigNum.ts +11 -2
  56. package/src/idl/drift.json +52 -1
  57. package/src/index.ts +1 -1
  58. package/src/math/amm.ts +159 -25
  59. package/src/math/state.ts +3 -0
  60. package/src/orderSubscriber/OrderSubscriber.ts +1 -0
  61. package/src/orderSubscriber/WebsocketSubscription.ts +28 -0
  62. package/src/orderSubscriber/types.ts +1 -0
  63. package/src/phoenix/phoenixSubscriber.ts +14 -8
  64. package/src/priorityFee/averageOverSlotsStrategy.ts +30 -0
  65. package/src/priorityFee/averageStrategy.ts +11 -0
  66. package/src/priorityFee/ewmaStrategy.ts +40 -0
  67. package/src/priorityFee/index.ts +7 -0
  68. package/src/priorityFee/maxOverSlotsStrategy.ts +31 -0
  69. package/src/priorityFee/maxStrategy.ts +7 -0
  70. package/src/priorityFee/priorityFeeSubscriber.ts +46 -19
  71. package/src/priorityFee/types.ts +5 -0
  72. package/src/slot/SlotSubscriber.ts +52 -5
  73. package/src/types.ts +2 -1
  74. package/src/user.ts +25 -8
  75. package/src/userMap/userMap.ts +12 -0
  76. package/tests/amm/test.ts +219 -11
  77. package/tests/bn/test.ts +27 -0
  78. package/tests/dlob/helpers.ts +1 -1
  79. package/tests/dlob/test.ts +372 -2
  80. package/tests/tx/priorityFeeStrategy.ts +97 -0
  81. package/tests/user/helpers.ts +1 -0
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.52.0-beta.1
1
+ 2.52.0-beta.11
@@ -1,5 +1,5 @@
1
1
  import { Connection, PublicKey } from '@solana/web3.js';
2
- import { PRICE_PRECISION, PhoenixSubscriber } from '../src';
2
+ import { BASE_PRECISION, PRICE_PRECISION, PhoenixSubscriber } from '../src';
3
3
  import { PROGRAM_ID } from '@ellipsis-labs/phoenix-sdk';
4
4
 
5
5
  export async function listenToBook(): Promise<void> {
@@ -19,9 +19,16 @@ export async function listenToBook(): Promise<void> {
19
19
  await phoenixSubscriber.subscribe();
20
20
 
21
21
  for (let i = 0; i < 10; i++) {
22
- const bid = phoenixSubscriber.getBestBid().toNumber() / PRICE_PRECISION;
23
- const ask = phoenixSubscriber.getBestAsk().toNumber() / PRICE_PRECISION;
24
- console.log(`iter ${i}:`, bid.toFixed(3), '@', ask.toFixed(3));
22
+ const bids = phoenixSubscriber.getL2Levels("bids");
23
+ const asks = phoenixSubscriber.getL2Levels("asks");
24
+ console.log("bids");
25
+ for (const bid of bids) {
26
+ console.log(bid.price.toNumber() / PRICE_PRECISION.toNumber(), bid.size.toNumber() / BASE_PRECISION.toNumber());
27
+ }
28
+ console.log("asks");
29
+ for (const ask of asks) {
30
+ console.log(ask.price.toNumber() / PRICE_PRECISION.toNumber(), ask.size.toNumber() / BASE_PRECISION.toNumber());
31
+ }
25
32
  await new Promise((r) => setTimeout(r, 2000));
26
33
  }
27
34
 
@@ -24,5 +24,5 @@ export declare class WebSocketAccountSubscriber<T> implements AccountSubscriber<
24
24
  fetch(): Promise<void>;
25
25
  handleRpcResponse(context: Context, accountInfo?: AccountInfo<Buffer>): void;
26
26
  decodeBuffer(buffer: Buffer): T;
27
- unsubscribe(): Promise<void>;
27
+ unsubscribe(onResub?: boolean): Promise<void>;
28
28
  }
@@ -15,7 +15,7 @@ class WebSocketAccountSubscriber {
15
15
  commitment !== null && commitment !== void 0 ? commitment : this.program.provider.opts.commitment;
16
16
  }
17
17
  async subscribe(onChange) {
18
- if (this.listenerId || this.isUnsubscribing) {
18
+ if (this.listenerId != null || this.isUnsubscribing) {
19
19
  return;
20
20
  }
21
21
  this.onChange = onChange;
@@ -58,7 +58,7 @@ class WebSocketAccountSubscriber {
58
58
  }
59
59
  if (this.receivingData) {
60
60
  console.log(`No ws data from ${this.accountName} in ${this.resubTimeoutMs}ms, resubscribing`);
61
- await this.unsubscribe();
61
+ await this.unsubscribe(true);
62
62
  this.receivingData = false;
63
63
  await this.subscribe(this.onChange);
64
64
  }
@@ -114,11 +114,14 @@ class WebSocketAccountSubscriber {
114
114
  return this.program.account[this.accountName].coder.accounts.decode((0, utils_1.capitalize)(this.accountName), buffer);
115
115
  }
116
116
  }
117
- unsubscribe() {
117
+ unsubscribe(onResub = false) {
118
+ if (!onResub) {
119
+ this.resubTimeoutMs = undefined;
120
+ }
118
121
  this.isUnsubscribing = true;
119
122
  clearTimeout(this.timeoutId);
120
123
  this.timeoutId = undefined;
121
- if (this.listenerId) {
124
+ if (this.listenerId != null) {
122
125
  const promise = this.program.provider.connection
123
126
  .removeAccountChangeListener(this.listenerId)
124
127
  .then(() => {
@@ -29,5 +29,5 @@ export declare class WebSocketProgramAccountSubscriber<T> implements ProgramAcco
29
29
  subscribe(onChange: (accountId: PublicKey, data: T, context: Context) => void): Promise<void>;
30
30
  private setTimeout;
31
31
  handleRpcResponse(context: Context, keyedAccountInfo: KeyedAccountInfo): void;
32
- unsubscribe(): Promise<void>;
32
+ unsubscribe(onResub?: boolean): Promise<void>;
33
33
  }
@@ -17,7 +17,7 @@ class WebSocketProgramAccountSubscriber {
17
17
  }
18
18
  async subscribe(onChange) {
19
19
  var _a;
20
- if (this.listenerId || this.isUnsubscribing) {
20
+ if (this.listenerId != null || this.isUnsubscribing) {
21
21
  return;
22
22
  }
23
23
  this.onChange = onChange;
@@ -47,7 +47,7 @@ class WebSocketProgramAccountSubscriber {
47
47
  }
48
48
  if (this.receivingData) {
49
49
  console.log(`No ws data from ${this.subscriptionName} in ${this.resubTimeoutMs}ms, resubscribing`);
50
- await this.unsubscribe();
50
+ await this.unsubscribe(true);
51
51
  this.receivingData = false;
52
52
  await this.subscribe(this.onChange);
53
53
  }
@@ -93,11 +93,14 @@ class WebSocketProgramAccountSubscriber {
93
93
  this.onChange(keyedAccountInfo.accountId, account, context);
94
94
  }
95
95
  }
96
- unsubscribe() {
96
+ unsubscribe(onResub = false) {
97
+ if (!onResub) {
98
+ this.resubTimeoutMs = undefined;
99
+ }
97
100
  this.isUnsubscribing = true;
98
101
  clearTimeout(this.timeoutId);
99
102
  this.timeoutId = undefined;
100
- if (this.listenerId) {
103
+ if (this.listenerId != null) {
101
104
  const promise = this.program.provider.connection
102
105
  .removeAccountChangeListener(this.listenerId)
103
106
  .then(() => {
@@ -47,4 +47,26 @@ export declare function getVammL2Generator({ marketAccount, oraclePriceData, num
47
47
  topOfBookQuoteAmounts?: BN[];
48
48
  }): L2OrderBookGenerator;
49
49
  export declare function groupL2(l2: L2OrderBook, grouping: BN, depth: number): L2OrderBook;
50
+ /**
51
+ * The purpose of this function is uncross the L2 orderbook by modifying the bid/ask price at the top of the book
52
+ * This will make the liquidity look worse but more intuitive (users familiar with clob get confused w temporarily
53
+ * crossing book)
54
+ *
55
+ * Things to note about how it works:
56
+ * - it will not uncross the user's liquidity
57
+ * - it does the uncrossing by "shifting" the crossing liquidity to the nearest uncrossed levels. Thus the output liquidity maintains the same total size.
58
+ *
59
+ * @param bids
60
+ * @param asks
61
+ * @param oraclePrice
62
+ * @param oracleTwap5Min
63
+ * @param markTwap5Min
64
+ * @param grouping
65
+ * @param userBids
66
+ * @param userAsks
67
+ */
68
+ export declare function uncrossL2(bids: L2Level[], asks: L2Level[], oraclePrice: BN, oracleTwap5Min: BN, markTwap5Min: BN, grouping: BN, userBids: Set<string>, userAsks: Set<string>): {
69
+ bids: L2Level[];
70
+ asks: L2Level[];
71
+ };
50
72
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.groupL2 = exports.getVammL2Generator = exports.createL2Levels = exports.mergeL2LevelGenerators = exports.getL2GeneratorFromDLOBNodes = exports.DEFAULT_TOP_OF_BOOK_QUOTE_AMOUNTS = void 0;
3
+ exports.uncrossL2 = exports.groupL2 = exports.getVammL2Generator = exports.createL2Levels = exports.mergeL2LevelGenerators = exports.getL2GeneratorFromDLOBNodes = exports.DEFAULT_TOP_OF_BOOK_QUOTE_AMOUNTS = void 0;
4
4
  const __1 = require("..");
5
5
  const assert_1 = require("../assert/assert");
6
6
  exports.DEFAULT_TOP_OF_BOOK_QUOTE_AMOUNTS = [
@@ -245,3 +245,117 @@ function groupL2Levels(levels, grouping, direction, depth) {
245
245
  }
246
246
  return groupedLevels;
247
247
  }
248
+ /**
249
+ * The purpose of this function is uncross the L2 orderbook by modifying the bid/ask price at the top of the book
250
+ * This will make the liquidity look worse but more intuitive (users familiar with clob get confused w temporarily
251
+ * crossing book)
252
+ *
253
+ * Things to note about how it works:
254
+ * - it will not uncross the user's liquidity
255
+ * - it does the uncrossing by "shifting" the crossing liquidity to the nearest uncrossed levels. Thus the output liquidity maintains the same total size.
256
+ *
257
+ * @param bids
258
+ * @param asks
259
+ * @param oraclePrice
260
+ * @param oracleTwap5Min
261
+ * @param markTwap5Min
262
+ * @param grouping
263
+ * @param userBids
264
+ * @param userAsks
265
+ */
266
+ function uncrossL2(bids, asks, oraclePrice, oracleTwap5Min, markTwap5Min, grouping, userBids, userAsks) {
267
+ // If there are no bids or asks, there is nothing to center
268
+ if (bids.length === 0 || asks.length === 0) {
269
+ return { bids, asks };
270
+ }
271
+ // If the top of the book is already centered, there is nothing to do
272
+ if (bids[0].price.lt(asks[0].price)) {
273
+ return { bids, asks };
274
+ }
275
+ const newBids = [];
276
+ const newAsks = [];
277
+ const updateLevels = (newPrice, oldLevel, levels) => {
278
+ if (levels.length > 0 && levels[levels.length - 1].price.eq(newPrice)) {
279
+ levels[levels.length - 1].size = levels[levels.length - 1].size.add(oldLevel.size);
280
+ for (const [source, size] of Object.entries(oldLevel.sources)) {
281
+ if (levels[levels.length - 1].sources[source]) {
282
+ levels[levels.length - 1].sources = {
283
+ ...levels[levels.length - 1].sources,
284
+ [source]: levels[levels.length - 1].sources[source].add(size),
285
+ };
286
+ }
287
+ else {
288
+ levels[levels.length - 1].sources[source] = size;
289
+ }
290
+ }
291
+ }
292
+ else {
293
+ levels.push({
294
+ price: newPrice,
295
+ size: oldLevel.size,
296
+ sources: oldLevel.sources,
297
+ });
298
+ }
299
+ };
300
+ // This is the best estimate of the premium in the market vs oracle to filter crossing around
301
+ const referencePrice = oraclePrice.add(markTwap5Min.sub(oracleTwap5Min));
302
+ let bidIndex = 0;
303
+ let askIndex = 0;
304
+ while (bidIndex < bids.length || askIndex < asks.length) {
305
+ const nextBid = bids[bidIndex];
306
+ const nextAsk = asks[askIndex];
307
+ if (!nextBid) {
308
+ newAsks.push(nextAsk);
309
+ askIndex++;
310
+ continue;
311
+ }
312
+ if (!nextAsk) {
313
+ newBids.push(nextBid);
314
+ bidIndex++;
315
+ continue;
316
+ }
317
+ if (nextBid.price.gt(nextAsk.price)) {
318
+ if (userBids.has(nextBid.price.toString())) {
319
+ newBids.push(nextBid);
320
+ bidIndex++;
321
+ continue;
322
+ }
323
+ if (userAsks.has(nextAsk.price.toString())) {
324
+ newAsks.push(nextAsk);
325
+ askIndex++;
326
+ continue;
327
+ }
328
+ if (nextBid.price.gt(referencePrice) &&
329
+ nextAsk.price.gt(referencePrice)) {
330
+ const newBidPrice = nextAsk.price.sub(grouping);
331
+ updateLevels(newBidPrice, nextBid, newBids);
332
+ bidIndex++;
333
+ }
334
+ else if (nextAsk.price.lt(referencePrice) &&
335
+ nextBid.price.lt(referencePrice)) {
336
+ const newAskPrice = nextBid.price.add(grouping);
337
+ updateLevels(newAskPrice, nextAsk, newAsks);
338
+ askIndex++;
339
+ }
340
+ else {
341
+ const newBidPrice = referencePrice.sub(grouping);
342
+ const newAskPrice = referencePrice.add(grouping);
343
+ updateLevels(newBidPrice, nextBid, newBids);
344
+ updateLevels(newAskPrice, nextAsk, newAsks);
345
+ bidIndex++;
346
+ askIndex++;
347
+ }
348
+ }
349
+ else {
350
+ newAsks.push(nextAsk);
351
+ askIndex++;
352
+ newBids.push(nextBid);
353
+ bidIndex++;
354
+ }
355
+ }
356
+ return {
357
+ bids: newBids,
358
+ asks: newAsks,
359
+ };
360
+ }
361
+ exports.uncrossL2 = uncrossL2;
@@ -133,8 +133,10 @@ export declare class DriftClient {
133
133
  getUserAccountsForAuthority(authority: PublicKey): Promise<UserAccount[]>;
134
134
  getReferredUserStatsAccountsByReferrer(referrer: PublicKey): Promise<UserStatsAccount[]>;
135
135
  getReferrerNameAccountsForAuthority(authority: PublicKey): Promise<ReferrerNameAccount[]>;
136
- getUserDeletionIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
137
136
  deleteUser(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
137
+ getUserDeletionIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
138
+ reclaimRent(subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
139
+ getReclaimRentIx(userAccountPublicKey: PublicKey): Promise<anchor.web3.TransactionInstruction>;
138
140
  getUser(subAccountId?: number, authority?: PublicKey): User;
139
141
  hasUser(subAccountId?: number, authority?: PublicKey): boolean;
140
142
  getUsers(): User[];
@@ -665,6 +665,16 @@ class DriftClient {
665
665
  ]);
666
666
  return programAccounts.map((programAccount) => programAccount.account);
667
667
  }
668
+ async deleteUser(subAccountId = 0, txParams) {
669
+ var _a;
670
+ const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
671
+ const ix = await this.getUserDeletionIx(userAccountPublicKey);
672
+ const { txSig } = await this.sendTransaction(await this.buildTransaction(ix, txParams), [], this.opts);
673
+ const userMapKey = this.getUserMapKey(subAccountId, this.wallet.publicKey);
674
+ await ((_a = this.users.get(userMapKey)) === null || _a === void 0 ? void 0 : _a.unsubscribe());
675
+ this.users.delete(userMapKey);
676
+ return txSig;
677
+ }
668
678
  async getUserDeletionIx(userAccountPublicKey) {
669
679
  const ix = await this.program.instruction.deleteUser({
670
680
  accounts: {
@@ -676,16 +686,23 @@ class DriftClient {
676
686
  });
677
687
  return ix;
678
688
  }
679
- async deleteUser(subAccountId = 0, txParams) {
680
- var _a;
689
+ async reclaimRent(subAccountId = 0, txParams) {
681
690
  const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
682
- const ix = await this.getUserDeletionIx(userAccountPublicKey);
691
+ const ix = await this.getReclaimRentIx(userAccountPublicKey);
683
692
  const { txSig } = await this.sendTransaction(await this.buildTransaction(ix, txParams), [], this.opts);
684
- const userMapKey = this.getUserMapKey(subAccountId, this.wallet.publicKey);
685
- await ((_a = this.users.get(userMapKey)) === null || _a === void 0 ? void 0 : _a.unsubscribe());
686
- this.users.delete(userMapKey);
687
693
  return txSig;
688
694
  }
695
+ async getReclaimRentIx(userAccountPublicKey) {
696
+ return await this.program.instruction.reclaimRent({
697
+ accounts: {
698
+ user: userAccountPublicKey,
699
+ userStats: this.getUserStatsAccountPublicKey(),
700
+ authority: this.wallet.publicKey,
701
+ state: await this.getStatePublicKey(),
702
+ rent: anchor.web3.SYSVAR_RENT_PUBKEY,
703
+ },
704
+ });
705
+ }
689
706
  getUser(subAccountId, authority) {
690
707
  subAccountId = subAccountId !== null && subAccountId !== void 0 ? subAccountId : this.activeSubAccountId;
691
708
  authority = authority !== null && authority !== void 0 ? authority : this.authority;
@@ -2216,8 +2233,13 @@ class DriftClient {
2216
2233
  async getSwapIx({ outMarketIndex, inMarketIndex, amountIn, inTokenAccount, outTokenAccount, limitPrice, reduceOnly, userAccountPublicKey, }) {
2217
2234
  const userAccountPublicKeyToUse = userAccountPublicKey || (await this.getUserAccountPublicKey());
2218
2235
  const userAccounts = [];
2219
- if (this.hasUser() && this.getUser().getUserAccountAndSlot()) {
2220
- userAccounts.push(this.getUser().getUserAccountAndSlot().data);
2236
+ try {
2237
+ if (this.hasUser() && this.getUser().getUserAccountAndSlot()) {
2238
+ userAccounts.push(this.getUser().getUserAccountAndSlot().data);
2239
+ }
2240
+ }
2241
+ catch (err) {
2242
+ // ignore
2221
2243
  }
2222
2244
  const remainingAccounts = this.getRemainingAccounts({
2223
2245
  userAccounts,
@@ -17,7 +17,7 @@ class WebSocketLogProvider {
17
17
  }
18
18
  }
19
19
  async subscribe(callback) {
20
- if (this.subscriptionId) {
20
+ if (this.subscriptionId != null) {
21
21
  return true;
22
22
  }
23
23
  this.callback = callback;
@@ -48,14 +48,14 @@ class WebSocketLogProvider {
48
48
  }, this.commitment);
49
49
  }
50
50
  isSubscribed() {
51
- return this.subscriptionId !== undefined;
51
+ return this.subscriptionId != null;
52
52
  }
53
53
  async unsubscribe(external = false) {
54
54
  this.isUnsubscribing = true;
55
55
  this.externalUnsubscribe = external;
56
56
  clearTimeout(this.timeoutId);
57
57
  this.timeoutId = undefined;
58
- if (this.subscriptionId !== undefined) {
58
+ if (this.subscriptionId != null) {
59
59
  try {
60
60
  await this.connection.removeOnLogsListener(this.subscriptionId);
61
61
  this.subscriptionId = undefined;
@@ -86,7 +86,7 @@ export declare class BigNum {
86
86
  * @returns
87
87
  */
88
88
  toNotional(useTradePrecision?: boolean, precisionOverride?: number): string;
89
- toMillified(precision?: number, rounded?: boolean): string;
89
+ toMillified(precision?: number, rounded?: boolean, type?: 'financial' | 'scientific'): string;
90
90
  toJSON(): {
91
91
  val: string;
92
92
  precision: string;
@@ -330,7 +330,7 @@ class BigNum {
330
330
  }
331
331
  return `${prefix}${val.replace('-', '')}`;
332
332
  }
333
- toMillified(precision = 3, rounded = false) {
333
+ toMillified(precision = 3, rounded = false, type = 'financial') {
334
334
  if (rounded) {
335
335
  return this.toRounded(precision).toMillified(precision);
336
336
  }
@@ -346,7 +346,10 @@ class BigNum {
346
346
  if (leftSide.length <= 3) {
347
347
  return this.shift(new anchor_1.BN(precision)).toPrecision(precision, true);
348
348
  }
349
- const unitTicks = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
349
+ const unitTicks = type === 'financial'
350
+ ? ['', 'K', 'M', 'B', 'T', 'Q']
351
+ : ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
352
+ // TODO -- handle nubers which are larger than the max unit tick
350
353
  const unitNumber = Math.floor((leftSide.length - 1) / 3);
351
354
  const unit = unitTicks[unitNumber];
352
355
  let leadDigits = leftSide.slice(0, precision);
@@ -1173,6 +1173,37 @@
1173
1173
  ],
1174
1174
  "args": []
1175
1175
  },
1176
+ {
1177
+ "name": "reclaimRent",
1178
+ "accounts": [
1179
+ {
1180
+ "name": "user",
1181
+ "isMut": true,
1182
+ "isSigner": false
1183
+ },
1184
+ {
1185
+ "name": "userStats",
1186
+ "isMut": true,
1187
+ "isSigner": false
1188
+ },
1189
+ {
1190
+ "name": "state",
1191
+ "isMut": false,
1192
+ "isSigner": false
1193
+ },
1194
+ {
1195
+ "name": "authority",
1196
+ "isMut": false,
1197
+ "isSigner": true
1198
+ },
1199
+ {
1200
+ "name": "rent",
1201
+ "isMut": false,
1202
+ "isSigner": false
1203
+ }
1204
+ ],
1205
+ "args": []
1206
+ },
1176
1207
  {
1177
1208
  "name": "fillPerpOrder",
1178
1209
  "accounts": [
@@ -7343,12 +7374,24 @@
7343
7374
  "name": "totalFeeEarnedPerLp",
7344
7375
  "type": "u64"
7345
7376
  },
7377
+ {
7378
+ "name": "netUnsettledFundingPnl",
7379
+ "type": "i64"
7380
+ },
7381
+ {
7382
+ "name": "quoteAssetAmountWithUnsettledLp",
7383
+ "type": "i64"
7384
+ },
7385
+ {
7386
+ "name": "referencePriceOffset",
7387
+ "type": "i32"
7388
+ },
7346
7389
  {
7347
7390
  "name": "padding",
7348
7391
  "type": {
7349
7392
  "array": [
7350
7393
  "u8",
7351
- 32
7394
+ 12
7352
7395
  ]
7353
7396
  }
7354
7397
  }
@@ -8232,6 +8275,9 @@
8232
8275
  },
8233
8276
  {
8234
8277
  "name": "Transfer"
8278
+ },
8279
+ {
8280
+ "name": "Borrow"
8235
8281
  }
8236
8282
  ]
8237
8283
  }
@@ -11124,6 +11170,11 @@
11124
11170
  "code": 6256,
11125
11171
  "name": "CantPayUserInitFee",
11126
11172
  "msg": "CantPayUserInitFee"
11173
+ },
11174
+ {
11175
+ "code": 6257,
11176
+ "name": "CantReclaimRent",
11177
+ "msg": "CantReclaimRent"
11127
11178
  }
11128
11179
  ]
11129
11180
  }
package/lib/index.d.ts CHANGED
@@ -68,7 +68,7 @@ export * from './constants/numericConstants';
68
68
  export * from './serum/serumSubscriber';
69
69
  export * from './serum/serumFulfillmentConfigMap';
70
70
  export * from './phoenix/phoenixSubscriber';
71
- export * from './priorityFee/priorityFeeSubscriber';
71
+ export * from './priorityFee';
72
72
  export * from './phoenix/phoenixFulfillmentConfigMap';
73
73
  export * from './tx/fastSingleTxSender';
74
74
  export * from './tx/retryTxSender';
package/lib/index.js CHANGED
@@ -91,7 +91,7 @@ __exportStar(require("./constants/numericConstants"), exports);
91
91
  __exportStar(require("./serum/serumSubscriber"), exports);
92
92
  __exportStar(require("./serum/serumFulfillmentConfigMap"), exports);
93
93
  __exportStar(require("./phoenix/phoenixSubscriber"), exports);
94
- __exportStar(require("./priorityFee/priorityFeeSubscriber"), exports);
94
+ __exportStar(require("./priorityFee"), exports);
95
95
  __exportStar(require("./phoenix/phoenixFulfillmentConfigMap"), exports);
96
96
  __exportStar(require("./tx/fastSingleTxSender"), exports);
97
97
  __exportStar(require("./tx/retryTxSender"), exports);
package/lib/math/amm.d.ts CHANGED
@@ -34,7 +34,9 @@ export type AssetType = 'quote' | 'base';
34
34
  */
35
35
  export declare function calculateAmmReservesAfterSwap(amm: Pick<AMM, 'pegMultiplier' | 'quoteAssetReserve' | 'sqrtK' | 'baseAssetReserve'>, inputAssetType: AssetType, swapAmount: BN, swapDirection: SwapDirection): [BN, BN];
36
36
  export declare function calculateMarketOpenBidAsk(baseAssetReserve: BN, minBaseAssetReserve: BN, maxBaseAssetReserve: BN, stepSize?: BN): [BN, BN];
37
+ export declare function calculateInventoryLiquidityRatio(baseAssetAmountWithAmm: BN, baseAssetReserve: BN, minBaseAssetReserve: BN, maxBaseAssetReserve: BN): BN;
37
38
  export declare function calculateInventoryScale(baseAssetAmountWithAmm: BN, baseAssetReserve: BN, minBaseAssetReserve: BN, maxBaseAssetReserve: BN, directionalSpread: number, maxSpread: number): number;
39
+ export declare function calculateReferencePriceOffset(reservePrice: BN, last24hAvgFundingRate: BN, liquidityFraction: BN, oracleTwapFast: BN, markTwapFast: BN, oracleTwapSlow: BN, markTwapSlow: BN, maxOffsetPct: number): BN;
38
40
  export declare function calculateEffectiveLeverage(baseSpread: number, quoteAssetReserve: BN, terminalQuoteAssetReserve: BN, pegMultiplier: BN, netBaseAssetAmount: BN, reservePrice: BN, totalFeeMinusDistributions: BN): number;
39
41
  export declare function calculateMaxSpread(marginRatioInitial: number): number;
40
42
  export declare function calculateVolSpreadBN(lastOracleConfPct: BN, reservePrice: BN, markStd: BN, oracleStd: BN, longIntensity: BN, shortIntensity: BN, volume24H: BN): [BN, BN];
@@ -55,11 +57,13 @@ export declare function calculateSpreadBN(baseSpread: number, lastOracleReserveP
55
57
  halfRevenueRetreatAmount: number;
56
58
  longSpreadwRevRetreat: number;
57
59
  shortSpreadwRevRetreat: number;
60
+ longSpreadwOffsetShrink: number;
61
+ shortSpreadwOffsetShrink: number;
58
62
  totalSpread: number;
59
63
  longSpread: number;
60
64
  shortSpread: number;
61
65
  };
62
- export declare function calculateSpread(amm: AMM, oraclePriceData: OraclePriceData, now?: BN): [number, number];
66
+ export declare function calculateSpread(amm: AMM, oraclePriceData: OraclePriceData, now?: BN, reservePrice?: BN): [number, number];
63
67
  export declare function calculateSpreadReserves(amm: AMM, oraclePriceData: OraclePriceData, now?: BN): {
64
68
  baseAssetReserve: any;
65
69
  quoteAssetReserve: any;