From 49f9d88ec8d18c2fa446512a05b221d38911ae44 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Sun, 17 Nov 2024 13:32:42 +0200 Subject: [PATCH] api: add `skipZeros` to `gRPF` solfees (#20) --- API.md | 5 +++-- CHANGELOG.md | 1 + solfees-be/src/bin/solfees-ws-client.rs | 6 ++++++ solfees-be/src/rpc_solana.rs | 7 ++++++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index 128346a..989d025 100644 --- a/API.md +++ b/API.md @@ -16,7 +16,7 @@ Accept `percentile` option that calculate fee as percentile (bps, i.e. allowed v #### `getRecentPrioritizationFees` -Provide more filters: accept read-write accounts, read-only accounts and up to 5 desired percentile levels. Response includes number of transactions, number of filtered transactions, average fee and requested levels with slot and commitment. +Provide more filters: accept read-write accounts, read-only accounts, up to 5 desired percentile levels and allow to exclude transactions with zero unit price. Response includes number of transactions, number of filtered transactions, average fee and requested levels with slot and commitment. ## Original Solana API @@ -149,7 +149,8 @@ defaults: - `readWrite`: `[]` - `readOnly`: `[]` - - `percentile`: `0` + - `levels`: `[]` + - `skipZeros`: `false` ``` > {"method":"getRecentPrioritizationFees","jsonrpc":"2.0","params":[{"readWrite":[],"readOnly":["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"],"levels":[5000, 9500]}],"id":"1"} diff --git a/CHANGELOG.md b/CHANGELOG.md index 3efa7ef..75f95a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,5 +29,6 @@ The minor version will be incremented upon a breaking change and the patch versi - geyser: do not stream outdated data ([#17](https://github.com/solana-stream-solutions/solfees/pull/17)) - backend: add metrics of used resources ([#18](https://github.com/solana-stream-solutions/solfees/pull/18)) - backend: fix ws stream shutdown ([#19](https://github.com/solana-stream-solutions/solfees/pull/19)) +- api: add `skipZeros` to `gRPF` solfees ([#20](https://github.com/solana-stream-solutions/solfees/pull/20)) ### Breaking diff --git a/solfees-be/src/bin/solfees-ws-client.rs b/solfees-be/src/bin/solfees-ws-client.rs index 77269d4..97557c5 100644 --- a/solfees-be/src/bin/solfees-ws-client.rs +++ b/solfees-be/src/bin/solfees-ws-client.rs @@ -24,6 +24,10 @@ struct Args { /// Up to 5 levels (bps) #[clap(long, default_values_t = [2000, 5000, 9000])] levels: Vec, + + /// Skip transactions with zero unit price + #[clap(long, default_value_t = false)] + skip_zeros: bool, } #[derive(Debug, Serialize)] @@ -32,6 +36,7 @@ struct SubscriptionParams { read_write: Vec, read_only: Vec, levels: Vec, + skip_zeros: bool, } #[tokio::main] @@ -46,6 +51,7 @@ async fn main() -> anyhow::Result<()> { read_write: args.read_write.unwrap_or_default(), read_only: args.read_only.unwrap_or_default(), levels: args.levels, + skip_zeros: args.skip_zeros, } })) .context("failed to create request")?; diff --git a/solfees-be/src/rpc_solana.rs b/solfees-be/src/rpc_solana.rs index ada40ca..adacfcd 100644 --- a/solfees-be/src/rpc_solana.rs +++ b/solfees-be/src/rpc_solana.rs @@ -1267,7 +1267,9 @@ impl StreamsSlotInfo { .iter() .all(|pubkey| tx.accounts.readable.contains(pubkey)) }) { - fees.push(transaction.unit_price); + if transaction.unit_price > 0 || !filter.skip_zeros { + fees.push(transaction.unit_price); + } } let total_transactions_filtered = fees.len(); @@ -1389,6 +1391,7 @@ struct ReqParamsSlotsSubscribeConfig { read_write: Vec, read_only: Vec, levels: Vec, + skip_zeros: bool, } #[derive(Debug)] @@ -1396,6 +1399,7 @@ struct SlotSubscribeFilter { read_write: Vec, read_only: Vec, levels: Vec, + skip_zeros: bool, } impl TryFrom for SlotSubscribeFilter { @@ -1446,6 +1450,7 @@ impl TryFrom for SlotSubscribeFilter { read_write, read_only, levels: config.levels, + skip_zeros: config.skip_zeros, }) } }