@drift-labs/sdk 2.59.0-beta.1 → 2.59.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.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.59.0-beta.1
1
+ 2.59.0-beta.3
@@ -12,6 +12,7 @@ export declare class PriorityFeeSubscriber {
12
12
  maxStrategy: MaxOverSlotsStrategy;
13
13
  priorityFeeMethod: PriorityFeeMethod;
14
14
  lookbackDistance: number;
15
+ maxFeeMicroLamports?: number;
15
16
  heliusRpcUrl?: string;
16
17
  lastHeliusSample?: HeliusPriorityFeeLevels;
17
18
  intervalId?: ReturnType<typeof setTimeout>;
@@ -38,6 +38,9 @@ class PriorityFeeSubscriber {
38
38
  throw new Error('Connection must be helius, or heliusRpcUrl must be provided to use PriorityFeeMethod.HELIUS');
39
39
  }
40
40
  }
41
+ else {
42
+ this.heliusRpcUrl = config.heliusRpcUrl;
43
+ }
41
44
  }
42
45
  }
43
46
  if (this.priorityFeeMethod === types_1.PriorityFeeMethod.SOLANA) {
@@ -45,6 +48,7 @@ class PriorityFeeSubscriber {
45
48
  throw new Error('connection must be provided to use SOLANA priority fee API');
46
49
  }
47
50
  }
51
+ this.maxFeeMicroLamports = config.maxFeeMicroLamports;
48
52
  }
49
53
  async subscribe() {
50
54
  if (this.intervalId) {
@@ -67,20 +71,41 @@ class PriorityFeeSubscriber {
67
71
  var _a, _b;
68
72
  const sample = await (0, heliusPriorityFeeMethod_1.fetchHeliusPriorityFee)(this.heliusRpcUrl, this.lookbackDistance, this.addresses);
69
73
  this.lastHeliusSample = (_b = (_a = sample === null || sample === void 0 ? void 0 : sample.result) === null || _a === void 0 ? void 0 : _a.priorityFeeLevels) !== null && _b !== void 0 ? _b : undefined;
74
+ if (this.lastHeliusSample) {
75
+ this.lastAvgStrategyResult =
76
+ this.heliusRpcUrl[heliusPriorityFeeMethod_1.HeliusPriorityLevel.MEDIUM];
77
+ this.lastMaxStrategyResult =
78
+ this.heliusRpcUrl[heliusPriorityFeeMethod_1.HeliusPriorityLevel.UNSAFE_MAX];
79
+ if (this.customStrategy) {
80
+ this.lastCustomStrategyResult = this.customStrategy.calculate(sample);
81
+ }
82
+ }
70
83
  }
71
84
  getHeliusPriorityFeeLevel(level = heliusPriorityFeeMethod_1.HeliusPriorityLevel.MEDIUM) {
72
85
  if (this.lastHeliusSample === undefined) {
73
86
  return 0;
74
87
  }
88
+ if (this.maxFeeMicroLamports !== undefined) {
89
+ return Math.max(this.maxFeeMicroLamports, this.lastHeliusSample[level]);
90
+ }
75
91
  return this.lastHeliusSample[level];
76
92
  }
77
93
  getCustomStrategyResult() {
94
+ if (this.maxFeeMicroLamports !== undefined) {
95
+ return Math.max(this.maxFeeMicroLamports, this.lastCustomStrategyResult);
96
+ }
78
97
  return this.lastCustomStrategyResult;
79
98
  }
80
99
  getAvgStrategyResult() {
100
+ if (this.maxFeeMicroLamports !== undefined) {
101
+ return Math.max(this.maxFeeMicroLamports, this.lastAvgStrategyResult);
102
+ }
81
103
  return this.lastAvgStrategyResult;
82
104
  }
83
105
  getMaxStrategyResult() {
106
+ if (this.maxFeeMicroLamports !== undefined) {
107
+ return Math.max(this.maxFeeMicroLamports, this.lastMaxStrategyResult);
108
+ }
84
109
  return this.lastMaxStrategyResult;
85
110
  }
86
111
  async load() {
@@ -16,4 +16,5 @@ export type PriorityFeeSubscriberConfig = {
16
16
  priorityFeeMethod?: PriorityFeeMethod;
17
17
  slotsToCheck?: number;
18
18
  heliusRpcUrl?: string;
19
+ maxFeeMicroLamports?: number;
19
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.59.0-beta.1",
3
+ "version": "2.59.0-beta.3",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -22,6 +22,7 @@ export class PriorityFeeSubscriber {
22
22
  maxStrategy = new MaxOverSlotsStrategy();
23
23
  priorityFeeMethod = PriorityFeeMethod.SOLANA;
24
24
  lookbackDistance: number;
25
+ maxFeeMicroLamports?: number;
25
26
 
26
27
  heliusRpcUrl?: string;
27
28
  lastHeliusSample?: HeliusPriorityFeeLevels;
@@ -56,6 +57,8 @@ export class PriorityFeeSubscriber {
56
57
  'Connection must be helius, or heliusRpcUrl must be provided to use PriorityFeeMethod.HELIUS'
57
58
  );
58
59
  }
60
+ } else {
61
+ this.heliusRpcUrl = config.heliusRpcUrl;
59
62
  }
60
63
  }
61
64
  }
@@ -67,6 +70,8 @@ export class PriorityFeeSubscriber {
67
70
  );
68
71
  }
69
72
  }
73
+
74
+ this.maxFeeMicroLamports = config.maxFeeMicroLamports;
70
75
  }
71
76
 
72
77
  public async subscribe(): Promise<void> {
@@ -101,6 +106,16 @@ export class PriorityFeeSubscriber {
101
106
  this.addresses
102
107
  );
103
108
  this.lastHeliusSample = sample?.result?.priorityFeeLevels ?? undefined;
109
+
110
+ if (this.lastHeliusSample) {
111
+ this.lastAvgStrategyResult =
112
+ this.heliusRpcUrl[HeliusPriorityLevel.MEDIUM];
113
+ this.lastMaxStrategyResult =
114
+ this.heliusRpcUrl[HeliusPriorityLevel.UNSAFE_MAX];
115
+ if (this.customStrategy) {
116
+ this.lastCustomStrategyResult = this.customStrategy.calculate(sample!);
117
+ }
118
+ }
104
119
  }
105
120
 
106
121
  public getHeliusPriorityFeeLevel(
@@ -109,18 +124,30 @@ export class PriorityFeeSubscriber {
109
124
  if (this.lastHeliusSample === undefined) {
110
125
  return 0;
111
126
  }
127
+ if (this.maxFeeMicroLamports !== undefined) {
128
+ return Math.max(this.maxFeeMicroLamports, this.lastHeliusSample[level]);
129
+ }
112
130
  return this.lastHeliusSample[level];
113
131
  }
114
132
 
115
133
  public getCustomStrategyResult(): number {
134
+ if (this.maxFeeMicroLamports !== undefined) {
135
+ return Math.max(this.maxFeeMicroLamports, this.lastCustomStrategyResult);
136
+ }
116
137
  return this.lastCustomStrategyResult;
117
138
  }
118
139
 
119
140
  public getAvgStrategyResult(): number {
141
+ if (this.maxFeeMicroLamports !== undefined) {
142
+ return Math.max(this.maxFeeMicroLamports, this.lastAvgStrategyResult);
143
+ }
120
144
  return this.lastAvgStrategyResult;
121
145
  }
122
146
 
123
147
  public getMaxStrategyResult(): number {
148
+ if (this.maxFeeMicroLamports !== undefined) {
149
+ return Math.max(this.maxFeeMicroLamports, this.lastMaxStrategyResult);
150
+ }
124
151
  return this.lastMaxStrategyResult;
125
152
  }
126
153
 
@@ -30,4 +30,6 @@ export type PriorityFeeSubscriberConfig = {
30
30
  slotsToCheck?: number;
31
31
  /// url for helius rpc, required if using priorityFeeMethod.HELIUS
32
32
  heliusRpcUrl?: string;
33
+ /// clamp any returned priority fee value to this value.
34
+ maxFeeMicroLamports?: number;
33
35
  };