Skip to content

Commit 8007fbe

Browse files
committed
filter out 0s, take median
1 parent 4754cb9 commit 8007fbe

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

sdk/src/contexts/solana/context.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const SOLANA_SEQ_LOG = 'Program log: Sequence: ';
7979
const SOLANA_CHAIN_NAME = MAINNET_CONFIG.chains.solana!.key;
8080

8181
// Add priority fee according to 75th percentile of recent fees paid
82-
const SOLANA_FEE_PERCENTILE = 0.75;
82+
const SOLANA_FEE_PERCENTILE = 0.5;
8383

8484
const SOLANA_MAINNET_EMMITER_ID =
8585
'ec7372995d5cc8732397fb0ad35c0121e0eaa90d26f828a534cab54391b3a4f5';
@@ -1225,7 +1225,9 @@ export class SolanaContext<
12251225
async determineComputeBudget(
12261226
lockedWritableAccounts: PublicKey[] = [],
12271227
): Promise<TransactionInstruction[]> {
1228-
let fee = 100_000; // Set fee to 100,000 microlamport by default
1228+
// https://twitter.com/0xMert_/status/1768669928825962706
1229+
1230+
let fee = 1; // Set fee to 100,000 microlamport by default
12291231

12301232
try {
12311233
const recentFeesResponse =
@@ -1237,11 +1239,14 @@ export class SolanaContext<
12371239
// Get 75th percentile fee paid in recent slots
12381240
const recentFees = recentFeesResponse
12391241
.map((dp) => dp.prioritizationFee)
1242+
.filter((dp) => dp > 0)
12401243
.sort((a, b) => a - b);
1241-
fee = Math.max(
1242-
recentFees[Math.floor(recentFees.length * SOLANA_FEE_PERCENTILE)],
1243-
fee,
1244-
);
1244+
1245+
if (recentFees.length > 0) {
1246+
const medianFee =
1247+
recentFees[Math.floor(recentFees.length * SOLANA_FEE_PERCENTILE)];
1248+
fee = Math.max(fee, medianFee);
1249+
}
12451250
}
12461251
} catch (e) {
12471252
console.error('Error fetching Solana recent fees', e);

0 commit comments

Comments
 (0)