Skip to content

Commit 6abb068

Browse files
jayantkaditya520
authored andcommitted
make everything configurable
1 parent 90929ed commit 6abb068

File tree

8 files changed

+257
-49
lines changed

8 files changed

+257
-49
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/argus/src/adapters/ethereum.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,19 @@ impl<T: JsonRpcClient + 'static + Clone> SignablePythContractInner<T> {
5656
provider: Provider<T>,
5757
) -> Result<SignablePythContractInner<T>> {
5858
let chain_id = provider.get_chainid().await?;
59-
let gas_oracle =
60-
EthProviderOracle::new(provider.clone(), chain_config.priority_fee_multiplier_pct);
59+
let gas_oracle = EthProviderOracle::new(
60+
provider.clone(),
61+
chain_config.priority_fee_multiplier_pct,
62+
0, // min_reward_samples - default value
63+
10, // fee_estimation_past_blocks - default value
64+
5.0, // fee_estimation_reward_percentile - default value
65+
3_000, // eip1559_fee_estimation_default_priority_fee - default value
66+
100_000, // eip1559_fee_estimation_priority_fee_trigger - default value
67+
200, // eip1559_fee_estimation_threshold_max_change - default value
68+
40_000, // surge_threshold_1 - default value
69+
100_000, // surge_threshold_2 - default value
70+
200_000, // surge_threshold_3 - default value
71+
);
6172
let wallet__ = private_key
6273
.parse::<LocalWallet>()?
6374
.with_chain_id(chain_id.as_u64());

apps/fortuna/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fortuna"
3-
version = "9.3.0"
3+
version = "9.4.0"
44
edition = "2021"
55

66
[lib]

apps/fortuna/src/api.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,15 @@ mod test {
603603
legacy_tx: false,
604604
gas_limit: 500000,
605605
priority_fee_multiplier_pct: 100,
606+
min_reward_samples: 0,
607+
fee_estimation_past_blocks: 10,
608+
fee_estimation_reward_percentile: 5.0,
609+
eip1559_fee_estimation_default_priority_fee: 3000,
610+
eip1559_fee_estimation_priority_fee_trigger: 100000,
611+
eip1559_fee_estimation_threshold_max_change: 200,
612+
surge_threshold_1: 40000,
613+
surge_threshold_2: 100000,
614+
surge_threshold_3: 200000,
606615
escalation_policy: crate::config::EscalationPolicyConfig::default(),
607616
min_profit_pct: 0,
608617
target_profit_pct: 20,
@@ -627,6 +636,15 @@ mod test {
627636
legacy_tx: false,
628637
gas_limit: 600000,
629638
priority_fee_multiplier_pct: 100,
639+
min_reward_samples: 0,
640+
fee_estimation_past_blocks: 10,
641+
fee_estimation_reward_percentile: 5.0,
642+
eip1559_fee_estimation_default_priority_fee: 3000,
643+
eip1559_fee_estimation_priority_fee_trigger: 100000,
644+
eip1559_fee_estimation_threshold_max_change: 200,
645+
surge_threshold_1: 40000,
646+
surge_threshold_2: 100000,
647+
surge_threshold_3: 200000,
630648
escalation_policy: crate::config::EscalationPolicyConfig::default(),
631649
min_profit_pct: 0,
632650
target_profit_pct: 20,

apps/fortuna/src/chain/ethereum.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,19 @@ impl<T: JsonRpcClient + 'static + Clone> SignablePythContractInner<T> {
167167
provider: Provider<T>,
168168
network_id: u64,
169169
) -> Result<SignablePythContractInner<T>> {
170-
let gas_oracle =
171-
EthProviderOracle::new(provider.clone(), chain_config.priority_fee_multiplier_pct);
170+
let gas_oracle = EthProviderOracle::new(
171+
provider.clone(),
172+
chain_config.priority_fee_multiplier_pct,
173+
chain_config.min_reward_samples,
174+
chain_config.fee_estimation_past_blocks,
175+
chain_config.fee_estimation_reward_percentile,
176+
chain_config.eip1559_fee_estimation_default_priority_fee,
177+
chain_config.eip1559_fee_estimation_priority_fee_trigger,
178+
chain_config.eip1559_fee_estimation_threshold_max_change,
179+
chain_config.surge_threshold_1,
180+
chain_config.surge_threshold_2,
181+
chain_config.surge_threshold_3,
182+
);
172183
let wallet__ = private_key
173184
.parse::<LocalWallet>()?
174185
.with_chain_id(network_id);

apps/fortuna/src/config.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,54 @@ pub struct EthereumConfig {
157157
#[serde(default = "default_priority_fee_multiplier_pct")]
158158
pub priority_fee_multiplier_pct: u64,
159159

160+
/// The minimum number of reward samples required for priority fee estimation.
161+
/// If fewer samples are available, the priority fee will be set to zero.
162+
/// Defaults to 0 if not provided.
163+
#[serde(default = "default_min_reward_samples")]
164+
pub min_reward_samples: usize,
165+
166+
/// The number of past blocks to use for fee estimation.
167+
/// Defaults to 10 if not provided.
168+
#[serde(default = "default_fee_estimation_past_blocks")]
169+
pub fee_estimation_past_blocks: u64,
170+
171+
/// The reward percentile to use for fee estimation (e.g., 5.0 for the 5th percentile).
172+
/// Defaults to 5.0 if not provided.
173+
#[serde(default = "default_fee_estimation_reward_percentile")]
174+
pub fee_estimation_reward_percentile: f64,
175+
176+
/// The default max priority fee per gas, used in case the base fee is within a threshold.
177+
/// Defaults to 3000 if not provided.
178+
#[serde(default = "default_eip1559_fee_estimation_default_priority_fee")]
179+
pub eip1559_fee_estimation_default_priority_fee: u64,
180+
181+
/// The threshold for base fee below which we use the default priority fee, and beyond which we
182+
/// estimate an appropriate value for priority fee.
183+
/// Defaults to 100000 if not provided.
184+
#[serde(default = "default_eip1559_fee_estimation_priority_fee_trigger")]
185+
pub eip1559_fee_estimation_priority_fee_trigger: u64,
186+
187+
/// The threshold max change/difference (in %) at which we will ignore the fee history values
188+
/// under it.
189+
/// Defaults to 200 if not provided.
190+
#[serde(default = "default_eip1559_fee_estimation_threshold_max_change")]
191+
pub eip1559_fee_estimation_threshold_max_change: i64,
192+
193+
/// First threshold at which the base fee gets a multiplier.
194+
/// Defaults to 40000 if not provided.
195+
#[serde(default = "default_surge_threshold_1")]
196+
pub surge_threshold_1: u64,
197+
198+
/// Second threshold at which the base fee gets a multiplier.
199+
/// Defaults to 100000 if not provided.
200+
#[serde(default = "default_surge_threshold_2")]
201+
pub surge_threshold_2: u64,
202+
203+
/// Third threshold at which the base fee gets a multiplier.
204+
/// Defaults to 200000 if not provided.
205+
#[serde(default = "default_surge_threshold_3")]
206+
pub surge_threshold_3: u64,
207+
160208
/// The escalation policy governs how the gas limit and fee are increased during backoff retries.
161209
#[serde(default)]
162210
pub escalation_policy: EscalationPolicyConfig,
@@ -226,6 +274,42 @@ fn default_priority_fee_multiplier_pct() -> u64 {
226274
100
227275
}
228276

277+
fn default_min_reward_samples() -> usize {
278+
0
279+
}
280+
281+
fn default_fee_estimation_past_blocks() -> u64 {
282+
10
283+
}
284+
285+
fn default_fee_estimation_reward_percentile() -> f64 {
286+
5.0
287+
}
288+
289+
fn default_eip1559_fee_estimation_default_priority_fee() -> u64 {
290+
3_000
291+
}
292+
293+
fn default_eip1559_fee_estimation_priority_fee_trigger() -> u64 {
294+
100_000
295+
}
296+
297+
fn default_eip1559_fee_estimation_threshold_max_change() -> i64 {
298+
200
299+
}
300+
301+
fn default_surge_threshold_1() -> u64 {
302+
40_000
303+
}
304+
305+
fn default_surge_threshold_2() -> u64 {
306+
100_000
307+
}
308+
309+
fn default_surge_threshold_3() -> u64 {
310+
200_000
311+
}
312+
229313
fn default_backlog_range() -> u64 {
230314
1000
231315
}

0 commit comments

Comments
 (0)