diff --git a/sdk/src/priorityFee/priorityFeeSubscriber.ts b/sdk/src/priorityFee/priorityFeeSubscriber.ts index 601cb8594..aca4ac9ec 100644 --- a/sdk/src/priorityFee/priorityFeeSubscriber.ts +++ b/sdk/src/priorityFee/priorityFeeSubscriber.ts @@ -22,6 +22,7 @@ export class PriorityFeeSubscriber { maxStrategy = new MaxOverSlotsStrategy(); priorityFeeMethod = PriorityFeeMethod.SOLANA; lookbackDistance: number; + maxFeeMicroLamports?: number; heliusRpcUrl?: string; lastHeliusSample?: HeliusPriorityFeeLevels; @@ -69,6 +70,8 @@ export class PriorityFeeSubscriber { ); } } + + this.maxFeeMicroLamports = config.maxFeeMicroLamports; } public async subscribe(): Promise { @@ -103,6 +106,16 @@ export class PriorityFeeSubscriber { this.addresses ); this.lastHeliusSample = sample?.result?.priorityFeeLevels ?? undefined; + + if (this.lastHeliusSample) { + this.lastAvgStrategyResult = + this.heliusRpcUrl[HeliusPriorityLevel.MEDIUM]; + this.lastMaxStrategyResult = + this.heliusRpcUrl[HeliusPriorityLevel.UNSAFE_MAX]; + if (this.customStrategy) { + this.lastCustomStrategyResult = this.customStrategy.calculate(sample!); + } + } } public getHeliusPriorityFeeLevel( @@ -111,18 +124,30 @@ export class PriorityFeeSubscriber { if (this.lastHeliusSample === undefined) { return 0; } + if (this.maxFeeMicroLamports !== undefined) { + return Math.max(this.maxFeeMicroLamports, this.lastHeliusSample[level]); + } return this.lastHeliusSample[level]; } public getCustomStrategyResult(): number { + if (this.maxFeeMicroLamports !== undefined) { + return Math.max(this.maxFeeMicroLamports, this.lastCustomStrategyResult); + } return this.lastCustomStrategyResult; } public getAvgStrategyResult(): number { + if (this.maxFeeMicroLamports !== undefined) { + return Math.max(this.maxFeeMicroLamports, this.lastAvgStrategyResult); + } return this.lastAvgStrategyResult; } public getMaxStrategyResult(): number { + if (this.maxFeeMicroLamports !== undefined) { + return Math.max(this.maxFeeMicroLamports, this.lastMaxStrategyResult); + } return this.lastMaxStrategyResult; } diff --git a/sdk/src/priorityFee/types.ts b/sdk/src/priorityFee/types.ts index 3d9c19fb9..8a04ce962 100644 --- a/sdk/src/priorityFee/types.ts +++ b/sdk/src/priorityFee/types.ts @@ -30,4 +30,6 @@ export type PriorityFeeSubscriberConfig = { slotsToCheck?: number; /// url for helius rpc, required if using priorityFeeMethod.HELIUS heliusRpcUrl?: string; + /// clamp any returned priority fee value to this value. + maxFeeMicroLamports?: number; };