Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tkporter committed Dec 12, 2024
1 parent 2365692 commit 4124a15
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion rust/main/chains/hyperlane-sealevel/src/trait_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ pub struct HeliusPriorityFeeOracleConfig {
}

/// The priority fee level to use
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Default)]
pub enum HeliusPriorityFeeLevel {
/// 50th percentile, but a floor of 10k microlamports.
/// The floor results in a staked Helius connection being used. (https://docs.helius.dev/guides/sending-transactions-on-solana#staked-connections)
#[default]
Recommended,
/// 0th percentile
Min,
Expand Down
45 changes: 27 additions & 18 deletions rust/main/hyperlane-base/src/settings/parser/connection_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,18 @@ fn parse_priority_fee_oracle_config(
Some(PriorityFeeOracleConfig::Constant(fee))
}
"helius" => {
let fee_level = parse_helius_priority_fee_level(&value_parser, err);
if !err.is_ok() {
return None;
}
let config = HeliusPriorityFeeOracleConfig {
url: value_parser
.chain(err)
.get_key("url")
.parse_from_str("Invalid url")
.end()
.unwrap(),
fee_level: parse_helius_priority_fee_level(&value_parser, err),
fee_level: fee_level.unwrap(),
};
Some(PriorityFeeOracleConfig::Helius(config))
}
Expand All @@ -273,28 +277,33 @@ fn parse_priority_fee_oracle_config(
fn parse_helius_priority_fee_level(
value_parser: &ValueParser,
err: &mut ConfigParsingError,
) -> HeliusPriorityFeeLevel {
) -> Option<HeliusPriorityFeeLevel> {
let level = value_parser
.chain(err)
.get_key("feeLevel")
.get_opt_key("feeLevel")
.parse_string()
.end()
.unwrap_or_default();
.end();

match level.to_lowercase().as_str() {
"min" => HeliusPriorityFeeLevel::Min,
"low" => HeliusPriorityFeeLevel::Low,
"medium" => HeliusPriorityFeeLevel::Medium,
"high" => HeliusPriorityFeeLevel::High,
"veryhigh" => HeliusPriorityFeeLevel::VeryHigh,
"unsafemax" => HeliusPriorityFeeLevel::UnsafeMax,
_ => {
err.push(
&value_parser.cwp + "feeLevel",
eyre!("Unknown priority fee level"),
);
HeliusPriorityFeeLevel::Medium
if let Some(level) = level {
match level.to_lowercase().as_str() {
"recommended" => Some(HeliusPriorityFeeLevel::Recommended),
"min" => Some(HeliusPriorityFeeLevel::Min),
"low" => Some(HeliusPriorityFeeLevel::Low),
"medium" => Some(HeliusPriorityFeeLevel::Medium),
"high" => Some(HeliusPriorityFeeLevel::High),
"veryhigh" => Some(HeliusPriorityFeeLevel::VeryHigh),
"unsafemax" => Some(HeliusPriorityFeeLevel::UnsafeMax),
_ => {
err.push(
&value_parser.cwp + "feeLevel",
eyre!("Unknown priority fee level"),
);
None
}
}
} else {
// If not specified at all, use the default
Some(HeliusPriorityFeeLevel::default())
}
}

Expand Down

0 comments on commit 4124a15

Please sign in to comment.