Skip to content

Commit

Permalink
use elements from helius-sdk for send logic
Browse files Browse the repository at this point in the history
rm helius error

rm unused code

add get_priority_fee_estimate

wip
  • Loading branch information
SwenSchaeferjohann committed Jan 14, 2025
1 parent a92f42d commit 287a29f
Show file tree
Hide file tree
Showing 12 changed files with 524 additions and 68 deletions.
51 changes: 51 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ solana-cli-output = "=1.18.22"
solana-transaction-status = "=1.18.22"
solana-account-decoder = "=1.18.22"
solana-rpc = "=1.18.22"
solana-rpc-client-api = "=1.18.22"
spl-token = "=4.0.0"
spl-token-2022 = {version="3.0.5", no-default-features = true, features = ["no-entrypoint"]}

Expand Down
5 changes: 5 additions & 0 deletions forester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ photon-api = { workspace = true }
forester-utils = { workspace = true }
light-client = { workspace = true }
light-merkle-tree-metadata = { workspace = true }
solana-transaction-status = { workspace = true }
bincode = "1.3"
url = "2.2"
tokio-tungstenite = "0.16"
bb8 = { workspace = true }

serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
Expand Down
23 changes: 11 additions & 12 deletions forester/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,35 @@ It subscribes to the nullifier queue and nullifies merkle tree leaves.
## Configuration

Forester requires a configuration file, `forester.toml`, specifying necessary keys:

- `STATE_MERKLE_TREE_PUBKEY`: Address of the State Merkle tree.
- `NULLIFIER_QUEUE_PUBKEY`: Address of the State Nullifier queue.
- `ADDRESS_MERKLE_TREE_PUBKEY`: Address of the Address Merkle tree.
- `ADDRESS_MERKLE_TREE_QUEUE_PUBKEY`: Address of the Address queue.
- `REGISTRY_PUBKEY`: Address of the Registry program.

To setup your environment properly, copy `.env.example` to `.env`
and update the `FORESTER_PAYER` field with your appropriate key.

To setup your environment properly, copy `.env.example` to `.env`
and update the `FORESTER_PAYER` field with your appropriate key.

Alternatively, if you prefer to use a terminal profile file,
add the key to your `~/.zshrc` (zsh) or `~/.bashrc` (bash)
Alternatively, if you prefer to use a terminal profile file,
add the key to your `~/.zshrc` (zsh) or `~/.bashrc` (bash)
by including this line: `export FORESTER_PAYER=your_value_here`.
Substitute `your_value_here` with your actual key.
Substitute `your_value_here` with your actual key.

Remember to restart your terminal or source your terminal profile for the changes to take effect.

## Usage

1. Run the service:
To subscribe to nullify the state merkle tree, use the following command:
`cargo run -- subscribe`
To subscribe to nullify the state merkle tree, use the following command:
`cargo run -- subscribe`
2. To manually nullify state merkle tree leaves, use the following command:
`cargo run -- nullify-state`
`cargo run -- nullify-state`
3. To manually nullify address merkle tree leaves, use the following command:
`cargo run -- nullify-addresses`
4. To manually nullify state *and* address merkle tree leaves, use the following command:
`cargo run -- nullify-addresses`
4. To manually nullify state _and_ address merkle tree leaves, use the following command:
`cargo run -- nullify`


## TODO

1. Add indexer URL to the configuration file.
Expand Down
127 changes: 127 additions & 0 deletions forester/src/helius_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
use std::time::Duration;

use serde::{Deserialize, Serialize};
use solana_sdk::{address_lookup_table::AddressLookupTableAccount, instruction::Instruction};

#[derive(Serialize, Deserialize, Debug, Default)]
pub struct MicroLamportPriorityFeeLevels {
pub min: f64,
pub low: f64,
pub medium: f64,
pub high: f64,
#[serde(rename = "veryHigh")]
pub very_high: f64,
#[serde(rename = "unsafeMax")]
pub unsafe_max: f64,
}

#[derive(Serialize, Deserialize, Debug)]
pub enum PriorityLevel {
Min,
Low,
Medium,
High,
VeryHigh,
UnsafeMax,
Default,
}

#[derive(Serialize, Deserialize, Debug)]
pub enum UiTransactionEncoding {
Binary,
Base64,
Base58,
Json,
JsonParsed,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
pub struct RpcRequest<T> {
pub jsonrpc: String,
pub id: String,
pub method: String,
#[serde(rename = "params")]
pub parameters: T,
}

impl<T> RpcRequest<T> {
pub fn new(method: String, parameters: T) -> Self {
Self {
jsonrpc: "2.0".to_string(),
id: "1".to_string(),
method,
parameters,
}
}
}

#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
pub struct RpcResponse<T> {
pub jsonrpc: String,
pub id: String,
pub result: T,
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetPriorityFeeEstimateOptions {
pub priority_level: Option<PriorityLevel>,
pub include_all_priority_fee_levels: Option<bool>,
pub transaction_encoding: Option<UiTransactionEncoding>,
pub lookback_slots: Option<u8>,
pub recommended: Option<bool>,
pub include_vote: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug, Default)]
pub struct GetPriorityFeeEstimateRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub transaction: Option<String>,
#[serde(rename = "accountKeys", skip_serializing_if = "Option::is_none")]
pub account_keys: Option<Vec<String>>,
pub options: Option<GetPriorityFeeEstimateOptions>,
}

#[derive(Serialize, Deserialize, Debug, Default)]
pub struct GetPriorityFeeEstimateResponse {
pub priority_fee_estimate: Option<f64>,
pub priority_fee_levels: Option<MicroLamportPriorityFeeLevels>,
}

pub struct Timeout {
pub duration: Duration,
}

impl Default for Timeout {
fn default() -> Self {
Self {
duration: Duration::from_secs(60),
}
}
}

impl From<Timeout> for Duration {
fn from(val: Timeout) -> Self {
val.duration
}
}

#[derive(Clone)]
pub struct CreateSmartTransactionSeedConfig {
pub instructions: Vec<Instruction>,
pub signer_seeds: Vec<[u8; 32]>,
pub fee_payer_seed: Option<[u8; 32]>,
pub lookup_tables: Option<Vec<AddressLookupTableAccount>>,
pub priority_fee_cap: Option<u64>,
}

impl CreateSmartTransactionSeedConfig {
pub fn new(instructions: Vec<Instruction>, signer_seeds: Vec<[u8; 32]>) -> Self {
Self {
instructions,
signer_seeds,
fee_payer_seed: None,
lookup_tables: None,
priority_fee_cap: None,
}
}
}
2 changes: 2 additions & 0 deletions forester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod config;
pub mod epoch_manager;
pub mod errors;
pub mod forester_status;
pub mod helius_types;
pub mod metrics;
pub mod pagerduty;
pub mod photon_indexer;
Expand All @@ -14,6 +15,7 @@ pub mod queue_helpers;
pub mod rollover;
pub mod send_transaction;
mod slot_tracker;
pub mod smart_transaction;
pub mod telemetry;
pub mod tree_data_sync;
pub mod tree_finder;
Expand Down
Loading

0 comments on commit 287a29f

Please sign in to comment.