Skip to content

Commit 963cb45

Browse files
authored
Relayer fee config (#578)
* relayer and estimated bridge tx fee in config * main file fixed * BRIDGE_TRANSACTION_FEE 0.001 ETH Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com> --------- Signed-off-by: Maciej Skrzypkowski <mskr@gmx.com>
1 parent 01ccd92 commit 963cb45

File tree

7 files changed

+54
-19
lines changed

7 files changed

+54
-19
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resolver = "2"
1010
default-members = ["node"]
1111

1212
[workspace.package]
13-
version = "1.4.2"
13+
version = "1.5.0"
1414
edition = "2024"
1515
repository = "https://github.com/NethermindEth/Catalyst"
1616
license = "MIT"

node/src/funds_monitor/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub struct FundsMonitor {
1515
amount_to_bridge_from_l2_to_l1: u128,
1616
disable_bridging: bool,
1717
cancel_token: CancellationToken,
18+
bridge_relayer_fee: u64,
19+
bridge_transaction_fee: u64,
1820
}
1921

2022
const MONITOR_INTERVAL_SEC: u64 = 60;
@@ -35,6 +37,8 @@ impl FundsMonitor {
3537
amount_to_bridge_from_l2_to_l1: u128,
3638
disable_bridging: bool,
3739
cancel_token: CancellationToken,
40+
bridge_relayer_fee: u64,
41+
bridge_transaction_fee: u64,
3842
) -> Self {
3943
Self {
4044
ethereum_l1,
@@ -47,6 +51,8 @@ impl FundsMonitor {
4751
amount_to_bridge_from_l2_to_l1,
4852
disable_bridging,
4953
cancel_token,
54+
bridge_relayer_fee,
55+
bridge_transaction_fee,
5056
}
5157
}
5258

@@ -173,11 +179,18 @@ impl FundsMonitor {
173179
if !self.disable_bridging
174180
&& let Ok(l2_eth_balance) = l2_eth_balance
175181
&& l2_eth_balance
176-
> U256::from(self.amount_to_bridge_from_l2_to_l1 + self.taiko.get_bridging_fee())
182+
> U256::from(
183+
self.amount_to_bridge_from_l2_to_l1
184+
+ u128::from(self.bridge_relayer_fee)
185+
+ u128::from(self.bridge_transaction_fee), // estimated transaction fee
186+
)
177187
{
178188
match self
179189
.taiko
180-
.transfer_eth_from_l2_to_l1(self.amount_to_bridge_from_l2_to_l1)
190+
.transfer_eth_from_l2_to_l1(
191+
self.amount_to_bridge_from_l2_to_l1,
192+
self.bridge_relayer_fee,
193+
)
181194
.await
182195
{
183196
Ok(_) => info!(

node/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ async fn main() -> Result<(), Error> {
230230
config.amount_to_bridge_from_l2_to_l1,
231231
config.disable_bridging,
232232
cancel_token.clone(),
233+
config.bridge_relayer_fee,
234+
config.bridge_transaction_fee,
233235
);
234236
funds_monitor.run();
235237

node/src/taiko/l2_execution_layer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ use std::time::Duration;
2424
use tokio::sync::RwLock;
2525
use tracing::{debug, info, warn};
2626

27-
pub const L2_TO_L1_BRIDGING_FEE: u64 = 10000;
28-
pub const ESTIMATED_L2_BRIDGING_TRANSACTION_FEE: u128 = 1000000000000;
29-
3027
pub struct L2ExecutionLayer {
3128
provider: RwLock<DynProvider>,
3229
taiko_anchor: RwLock<TaikoAnchor::TaikoAnchorInstance<DynProvider>>,
@@ -291,6 +288,7 @@ impl L2ExecutionLayer {
291288
amount: u128,
292289
dest_chain_id: u64,
293290
preconfer_address: Address,
291+
bridge_relayer_fee: u64,
294292
) -> Result<(), Error> {
295293
info!(
296294
"Transfer ETH from L2 to L1: srcChainId: {}, dstChainId: {}",
@@ -309,6 +307,7 @@ impl L2ExecutionLayer {
309307
amount,
310308
dest_chain_id,
311309
preconfer_address,
310+
bridge_relayer_fee,
312311
)
313312
.await?;
314313

@@ -321,6 +320,7 @@ impl L2ExecutionLayer {
321320
amount: u128,
322321
dest_chain_id: u64,
323322
preconfer_address: Address,
323+
bridge_relayer_fee: u64,
324324
) -> Result<(), Error> {
325325
let contract = Bridge::new(self.config.taiko_bridge_address, provider.clone());
326326
let gas_limit = contract
@@ -331,7 +331,7 @@ impl L2ExecutionLayer {
331331

332332
let message = Bridge::Message {
333333
id: 0,
334-
fee: L2_TO_L1_BRIDGING_FEE,
334+
fee: bridge_relayer_fee,
335335
gasLimit: gas_limit + 1,
336336
from: preconfer_address,
337337
srcChainId: self.chain_id,
@@ -355,7 +355,7 @@ impl L2ExecutionLayer {
355355
let tx_send_message = contract
356356
.sendMessage(message)
357357
.value(Uint::<256, 4>::from(
358-
amount + u128::from(L2_TO_L1_BRIDGING_FEE),
358+
amount + u128::from(bridge_relayer_fee),
359359
))
360360
.from(preconfer_address)
361361
.nonce(nonce)

node/src/taiko/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,22 +434,22 @@ impl Taiko {
434434
.await
435435
}
436436

437-
pub async fn transfer_eth_from_l2_to_l1(&self, amount: u128) -> Result<(), Error> {
437+
pub async fn transfer_eth_from_l2_to_l1(
438+
&self,
439+
amount: u128,
440+
bridge_relayer_fee: u64,
441+
) -> Result<(), Error> {
438442
self.l2_execution_layer
439443
.transfer_eth_from_l2_to_l1(
440444
amount,
441445
self.ethereum_l1.execution_layer.chain_id(),
442446
self.ethereum_l1
443447
.execution_layer
444448
.get_preconfer_alloy_address(),
449+
bridge_relayer_fee,
445450
)
446451
.await
447452
}
448-
449-
pub fn get_bridging_fee(&self) -> u128 {
450-
u128::from(l2_execution_layer::L2_TO_L1_BRIDGING_FEE)
451-
+ l2_execution_layer::ESTIMATED_L2_BRIDGING_TRANSACTION_FEE
452-
}
453453
}
454454

455455
pub trait PreconfDriver {

node/src/utils/config.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ pub struct Config {
4949
pub extra_gas_percentage: u64,
5050
pub preconf_min_txs: u64,
5151
pub preconf_max_skipped_l2_slots: u64,
52+
pub bridge_relayer_fee: u64,
53+
pub bridge_transaction_fee: u64,
5254
}
5355

5456
#[derive(Debug, Clone)]
@@ -367,6 +369,18 @@ impl Config {
367369
.parse::<u64>()
368370
.expect("PRECONF_MAX_SKIPPED_L2_SLOTS must be a number");
369371

372+
// 0.003 eth
373+
let bridge_relayer_fee = std::env::var("BRIDGE_RELAYER_FEE")
374+
.unwrap_or("3047459064000000".to_string())
375+
.parse::<u64>()
376+
.expect("BRIDGE_RELAYER_FEE must be a number");
377+
378+
// 0.001 eth
379+
let bridge_transaction_fee = std::env::var("BRIDGE_TRANSACTION_FEE")
380+
.unwrap_or("1000000000000000".to_string())
381+
.parse::<u64>()
382+
.expect("BRIDGE_TRANSACTION_FEE must be a number");
383+
370384
let config = Self {
371385
preconfer_address,
372386
taiko_geth_rpc_url: std::env::var("TAIKO_GETH_RPC_URL")
@@ -422,6 +436,8 @@ impl Config {
422436
extra_gas_percentage,
423437
preconf_min_txs,
424438
preconf_max_skipped_l2_slots,
439+
bridge_relayer_fee,
440+
bridge_transaction_fee,
425441
};
426442

427443
info!(
@@ -456,7 +472,7 @@ max bytes size of batch: {}
456472
max blocks per batch value: {}
457473
max time shift between blocks: {}s
458474
max anchor height offset reduction value: {}
459-
min priority fee per gas wei: {}
475+
min priority fee per gas: {}wei
460476
tx fees increase percentage: {}
461477
max attempts to send tx: {}
462478
max attempts to wait tx: {}
@@ -469,6 +485,8 @@ simulate not submitting at the end of epoch: {}
469485
propose_forced_inclusion: {}
470486
min number of transaction to create a L2 block: {}
471487
max number of skipped L2 slots while creating a L2 block: {}
488+
bridge relayer fee: {}wei
489+
bridge transaction fee: {}wei
472490
"#,
473491
if let Some(preconfer_address) = &config.preconfer_address {
474492
format!("\npreconfer address: {preconfer_address}")
@@ -524,6 +542,8 @@ max number of skipped L2 slots while creating a L2 block: {}
524542
config.propose_forced_inclusion,
525543
config.preconf_min_txs,
526544
config.preconf_max_skipped_l2_slots,
545+
config.bridge_relayer_fee,
546+
config.bridge_transaction_fee,
527547
);
528548

529549
config

0 commit comments

Comments
 (0)