Skip to content

Commit

Permalink
sdk: catch error in priorityFeeSubscriber.load (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpipta committed Jan 24, 2024
1 parent f0b6b3a commit 38a92a5
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions sdk/src/priorityFee/priorityFeeSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,40 @@ export class PriorityFeeSubscriber {
}

public async load(): Promise<void> {
// @ts-ignore
const rpcJSONResponse: any = await this.connection._rpcRequest(
'getRecentPrioritizationFees',
[this.addresses]
);
try {
// @ts-ignore
const rpcJSONResponse: any = await this.connection._rpcRequest(
'getRecentPrioritizationFees',
[this.addresses]
);

const results: { slot: number; prioritizationFee: number }[] =
rpcJSONResponse?.result;
const results: { slot: number; prioritizationFee: number }[] =
rpcJSONResponse?.result;

if (!results.length) return;
if (!results.length) return;

// # Sort and filter results based on the slot lookback setting
const descResults = results.sort((a, b) => b.slot - a.slot);
const mostRecentResult = descResults[0];
const cutoffSlot = mostRecentResult.slot - this.lookbackDistance;
// # Sort and filter results based on the slot lookback setting
const descResults = results.sort((a, b) => b.slot - a.slot);
const mostRecentResult = descResults[0];
const cutoffSlot = mostRecentResult.slot - this.lookbackDistance;

const resultsToUse = descResults.filter(
(result) => result.slot >= cutoffSlot
);
const resultsToUse = descResults.filter(
(result) => result.slot >= cutoffSlot
);

// # Handle results
this.latestPriorityFee = mostRecentResult.prioritizationFee;
this.lastSlotSeen = mostRecentResult.slot;
// # Handle results
this.latestPriorityFee = mostRecentResult.prioritizationFee;
this.lastSlotSeen = mostRecentResult.slot;

this.lastAvgStrategyResult = this.averageStrategy.calculate(resultsToUse);
this.lastMaxStrategyResult = this.maxStrategy.calculate(resultsToUse);
if (this.customStrategy) {
this.lastCustomStrategyResult =
this.customStrategy.calculate(resultsToUse);
this.lastAvgStrategyResult = this.averageStrategy.calculate(resultsToUse);
this.lastMaxStrategyResult = this.maxStrategy.calculate(resultsToUse);
if (this.customStrategy) {
this.lastCustomStrategyResult =
this.customStrategy.calculate(resultsToUse);
}
} catch (err) {
// It's possible to get here with "TypeError: failed to fetch"
return;
}
}

Expand Down

0 comments on commit 38a92a5

Please sign in to comment.