@drift-labs/sdk 2.59.0-beta.2 → 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.2
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>;
@@ -48,6 +48,7 @@ class PriorityFeeSubscriber {
48
48
  throw new Error('connection must be provided to use SOLANA priority fee API');
49
49
  }
50
50
  }
51
+ this.maxFeeMicroLamports = config.maxFeeMicroLamports;
51
52
  }
52
53
  async subscribe() {
53
54
  if (this.intervalId) {
@@ -70,20 +71,41 @@ class PriorityFeeSubscriber {
70
71
  var _a, _b;
71
72
  const sample = await (0, heliusPriorityFeeMethod_1.fetchHeliusPriorityFee)(this.heliusRpcUrl, this.lookbackDistance, this.addresses);
72
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
+ }
73
83
  }
74
84
  getHeliusPriorityFeeLevel(level = heliusPriorityFeeMethod_1.HeliusPriorityLevel.MEDIUM) {
75
85
  if (this.lastHeliusSample === undefined) {
76
86
  return 0;
77
87
  }
88
+ if (this.maxFeeMicroLamports !== undefined) {
89
+ return Math.max(this.maxFeeMicroLamports, this.lastHeliusSample[level]);
90
+ }
78
91
  return this.lastHeliusSample[level];
79
92
  }
80
93
  getCustomStrategyResult() {
94
+ if (this.maxFeeMicroLamports !== undefined) {
95
+ return Math.max(this.maxFeeMicroLamports, this.lastCustomStrategyResult);
96
+ }
81
97
  return this.lastCustomStrategyResult;
82
98
  }
83
99
  getAvgStrategyResult() {
100
+ if (this.maxFeeMicroLamports !== undefined) {
101
+ return Math.max(this.maxFeeMicroLamports, this.lastAvgStrategyResult);
102
+ }
84
103
  return this.lastAvgStrategyResult;
85
104
  }
86
105
  getMaxStrategyResult() {
106
+ if (this.maxFeeMicroLamports !== undefined) {
107
+ return Math.max(this.maxFeeMicroLamports, this.lastMaxStrategyResult);
108
+ }
87
109
  return this.lastMaxStrategyResult;
88
110
  }
89
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.2",
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;
@@ -69,6 +70,8 @@ export class PriorityFeeSubscriber {
69
70
  );
70
71
  }
71
72
  }
73
+
74
+ this.maxFeeMicroLamports = config.maxFeeMicroLamports;
72
75
  }
73
76
 
74
77
  public async subscribe(): Promise<void> {
@@ -103,6 +106,16 @@ export class PriorityFeeSubscriber {
103
106
  this.addresses
104
107
  );
105
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
+ }
106
119
  }
107
120
 
108
121
  public getHeliusPriorityFeeLevel(
@@ -111,18 +124,30 @@ export class PriorityFeeSubscriber {
111
124
  if (this.lastHeliusSample === undefined) {
112
125
  return 0;
113
126
  }
127
+ if (this.maxFeeMicroLamports !== undefined) {
128
+ return Math.max(this.maxFeeMicroLamports, this.lastHeliusSample[level]);
129
+ }
114
130
  return this.lastHeliusSample[level];
115
131
  }
116
132
 
117
133
  public getCustomStrategyResult(): number {
134
+ if (this.maxFeeMicroLamports !== undefined) {
135
+ return Math.max(this.maxFeeMicroLamports, this.lastCustomStrategyResult);
136
+ }
118
137
  return this.lastCustomStrategyResult;
119
138
  }
120
139
 
121
140
  public getAvgStrategyResult(): number {
141
+ if (this.maxFeeMicroLamports !== undefined) {
142
+ return Math.max(this.maxFeeMicroLamports, this.lastAvgStrategyResult);
143
+ }
122
144
  return this.lastAvgStrategyResult;
123
145
  }
124
146
 
125
147
  public getMaxStrategyResult(): number {
148
+ if (this.maxFeeMicroLamports !== undefined) {
149
+ return Math.max(this.maxFeeMicroLamports, this.lastMaxStrategyResult);
150
+ }
126
151
  return this.lastMaxStrategyResult;
127
152
  }
128
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
  };