@drift-labs/sdk 2.38.1-beta.4 → 2.38.1-beta.5

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.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.38.1-beta.4
1
+ 2.38.1-beta.5
package/lib/index.d.ts CHANGED
@@ -59,6 +59,7 @@ export * from './constants/numericConstants';
59
59
  export * from './serum/serumSubscriber';
60
60
  export * from './serum/serumFulfillmentConfigMap';
61
61
  export * from './phoenix/phoenixSubscriber';
62
+ export * from './priorityFee/priorityFeeSubscriber';
62
63
  export * from './phoenix/phoenixFulfillmentConfigMap';
63
64
  export * from './tx/fastSingleTxSender';
64
65
  export * from './tx/retryTxSender';
package/lib/index.js CHANGED
@@ -82,6 +82,7 @@ __exportStar(require("./constants/numericConstants"), exports);
82
82
  __exportStar(require("./serum/serumSubscriber"), exports);
83
83
  __exportStar(require("./serum/serumFulfillmentConfigMap"), exports);
84
84
  __exportStar(require("./phoenix/phoenixSubscriber"), exports);
85
+ __exportStar(require("./priorityFee/priorityFeeSubscriber"), exports);
85
86
  __exportStar(require("./phoenix/phoenixFulfillmentConfigMap"), exports);
86
87
  __exportStar(require("./tx/fastSingleTxSender"), exports);
87
88
  __exportStar(require("./tx/retryTxSender"), exports);
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ import { Connection, PublicKey } from '@solana/web3.js';
3
+ export declare class PriorityFeeSubscriber {
4
+ connection: Connection;
5
+ frequencyMs: number;
6
+ addresses: PublicKey[];
7
+ slotsToCheck: number;
8
+ intervalId?: NodeJS.Timer;
9
+ latestPriorityFee: number;
10
+ avgPriorityFee: number;
11
+ maxPriorityFee: number;
12
+ lastSlotSeen: number;
13
+ constructor({ connection, frequencyMs, addresses, slotsToCheck, }: {
14
+ connection: Connection;
15
+ frequencyMs: number;
16
+ addresses: PublicKey[];
17
+ slotsToCheck?: number;
18
+ });
19
+ subscribe(): Promise<void>;
20
+ load(): Promise<void>;
21
+ unsubscribe(): Promise<void>;
22
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PriorityFeeSubscriber = void 0;
4
+ class PriorityFeeSubscriber {
5
+ constructor({ connection, frequencyMs, addresses, slotsToCheck = 10, }) {
6
+ this.latestPriorityFee = 0;
7
+ // avg of last {slotsToCheck} slots
8
+ this.avgPriorityFee = 0;
9
+ // max of last {slotsToCheck} slots
10
+ this.maxPriorityFee = 0;
11
+ this.lastSlotSeen = 0;
12
+ this.connection = connection;
13
+ this.frequencyMs = frequencyMs;
14
+ this.addresses = addresses;
15
+ this.slotsToCheck = slotsToCheck;
16
+ }
17
+ async subscribe() {
18
+ if (this.intervalId) {
19
+ return;
20
+ }
21
+ this.intervalId = setInterval(this.load.bind(this), this.frequencyMs);
22
+ }
23
+ async load() {
24
+ var _a, _b, _c;
25
+ // @ts-ignore
26
+ const rpcJSONResponse = await this.connection._rpcRequest('getRecentPrioritizationFees', [this.addresses]);
27
+ const descResults = (_c = (_b = (_a = rpcJSONResponse === null || rpcJSONResponse === void 0 ? void 0 : rpcJSONResponse.result) === null || _a === void 0 ? void 0 : _a.sort((a, b) => b.slot - a.slot)) === null || _b === void 0 ? void 0 : _b.slice(0, this.slotsToCheck)) !== null && _c !== void 0 ? _c : [];
28
+ if (!(descResults === null || descResults === void 0 ? void 0 : descResults.length))
29
+ return;
30
+ const mostRecentResult = descResults[0];
31
+ this.latestPriorityFee = mostRecentResult.prioritizationFee;
32
+ this.lastSlotSeen = mostRecentResult.slot;
33
+ this.avgPriorityFee =
34
+ descResults.reduce((a, b) => {
35
+ return a + b.prioritizationFee;
36
+ }, 0) / descResults.length;
37
+ this.maxPriorityFee = Math.max(...descResults.map((result) => result.prioritizationFee));
38
+ }
39
+ async unsubscribe() {
40
+ if (this.intervalId) {
41
+ clearInterval(this.intervalId);
42
+ this.intervalId = undefined;
43
+ }
44
+ }
45
+ }
46
+ exports.PriorityFeeSubscriber = PriorityFeeSubscriber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.38.1-beta.4",
3
+ "version": "2.38.1-beta.5",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
package/src/index.ts CHANGED
@@ -60,6 +60,7 @@ export * from './constants/numericConstants';
60
60
  export * from './serum/serumSubscriber';
61
61
  export * from './serum/serumFulfillmentConfigMap';
62
62
  export * from './phoenix/phoenixSubscriber';
63
+ export * from './priorityFee/priorityFeeSubscriber';
63
64
  export * from './phoenix/phoenixFulfillmentConfigMap';
64
65
  export * from './tx/fastSingleTxSender';
65
66
  export * from './tx/retryTxSender';
@@ -0,0 +1,75 @@
1
+ import { Connection, PublicKey } from '@solana/web3.js';
2
+
3
+ export class PriorityFeeSubscriber {
4
+ connection: Connection;
5
+ frequencyMs: number;
6
+ addresses: PublicKey[];
7
+ slotsToCheck: number;
8
+
9
+ intervalId?: NodeJS.Timer;
10
+
11
+ latestPriorityFee = 0;
12
+ // avg of last {slotsToCheck} slots
13
+ avgPriorityFee = 0;
14
+ // max of last {slotsToCheck} slots
15
+ maxPriorityFee = 0;
16
+ lastSlotSeen = 0;
17
+
18
+ public constructor({
19
+ connection,
20
+ frequencyMs,
21
+ addresses,
22
+ slotsToCheck = 10,
23
+ }: {
24
+ connection: Connection;
25
+ frequencyMs: number;
26
+ addresses: PublicKey[];
27
+ slotsToCheck?: number;
28
+ }) {
29
+ this.connection = connection;
30
+ this.frequencyMs = frequencyMs;
31
+ this.addresses = addresses;
32
+ this.slotsToCheck = slotsToCheck;
33
+ }
34
+
35
+ public async subscribe(): Promise<void> {
36
+ if (this.intervalId) {
37
+ return;
38
+ }
39
+
40
+ this.intervalId = setInterval(this.load.bind(this), this.frequencyMs);
41
+ }
42
+
43
+ public async load(): Promise<void> {
44
+ // @ts-ignore
45
+ const rpcJSONResponse: any = await this.connection._rpcRequest(
46
+ 'getRecentPrioritizationFees',
47
+ [this.addresses]
48
+ );
49
+
50
+ const descResults: { slot: number; prioritizationFee: number }[] =
51
+ rpcJSONResponse?.result
52
+ ?.sort((a, b) => b.slot - a.slot)
53
+ ?.slice(0, this.slotsToCheck) ?? [];
54
+
55
+ if (!descResults?.length) return;
56
+
57
+ const mostRecentResult = descResults[0];
58
+ this.latestPriorityFee = mostRecentResult.prioritizationFee;
59
+ this.lastSlotSeen = mostRecentResult.slot;
60
+ this.avgPriorityFee =
61
+ descResults.reduce((a, b) => {
62
+ return a + b.prioritizationFee;
63
+ }, 0) / descResults.length;
64
+ this.maxPriorityFee = Math.max(
65
+ ...descResults.map((result) => result.prioritizationFee)
66
+ );
67
+ }
68
+
69
+ public async unsubscribe(): Promise<void> {
70
+ if (this.intervalId) {
71
+ clearInterval(this.intervalId);
72
+ this.intervalId = undefined;
73
+ }
74
+ }
75
+ }