-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: L1 Fee Scalar calculation (#183)
* add dep * basic impl * wip: test on latitude instance * fix * wip * wip * simplify * wip * buffer the fees, calculate correctly * works * add l1 fee scalar * fix: concurrent native host runners * concurrent native host runners * wip * fix * fix --------- Co-authored-by: Ubuntu <[email protected]>
- Loading branch information
1 parent
04a32bc
commit 4bdb558
Showing
16 changed files
with
535 additions
and
182 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"genesis": { | ||
"l1": { | ||
"number": 17481768, | ||
"hash": "0x5c13d307623a926cd31415036c8b7fa14572f9dac64528e857a470511fc30771" | ||
}, | ||
"l2": { | ||
"number": 0, | ||
"hash": "0xf712aa9241cc24369b143cf6dce85f0902a9731e70d66818a3a5845b296c73dd" | ||
}, | ||
"l2_time": 1686789347, | ||
"system_config": { | ||
"batcherAddr": "0x5050f69a9786f081509234f1a7f4684b5e5b76c9", | ||
"overhead": "0xbc", | ||
"scalar": "0xa6fe0", | ||
"gasLimit": 30000000, | ||
"baseFeeScalar": null, | ||
"blobBaseFeeScalar": null, | ||
"eip1559Denominator": null, | ||
"eip1559Elasticity": null | ||
} | ||
}, | ||
"block_time": 2, | ||
"max_sequencer_drift": 600, | ||
"seq_window_size": 3600, | ||
"channel_timeout": 300, | ||
"granite_channel_timeout": 50, | ||
"l1_chain_id": 1, | ||
"l2_chain_id": 8453, | ||
"base_fee_params": { | ||
"max_change_denominator": "0x32", | ||
"elasticity_multiplier": "0x6" | ||
}, | ||
"canyon_base_fee_params": { | ||
"max_change_denominator": "0xfa", | ||
"elasticity_multiplier": "0x6" | ||
}, | ||
"regolith_time": 0, | ||
"canyon_time": 1704992401, | ||
"delta_time": 1708560000, | ||
"ecotone_time": 1710374401, | ||
"fjord_time": 1720627201, | ||
"granite_time": 1726070401, | ||
"batch_inbox_address": "0xff00000000000000000000000000000000008453", | ||
"deposit_contract_address": "0x49048044d57e1c92a77f79988d21fa8faf74e97e", | ||
"l1_system_config_address": "0x73a79fab69143498ed3712e519a88a918e1f4072", | ||
"protocol_versions_address": "0x0000000000000000000000000000000000000000" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "op-succinct-fees" | ||
version = "0.1.0" | ||
license.workspace = true | ||
edition.workspace = true | ||
authors.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
|
||
[[bin]] | ||
name = "l1-fee-scalar" | ||
path = "bin/l1_fee_scalar.rs" | ||
|
||
[dependencies] | ||
op-succinct-host-utils = { workspace = true } | ||
clap = { workspace = true } | ||
anyhow = { workspace = true } | ||
tokio = { workspace = true } | ||
dotenv = { workspace = true } | ||
alloy-primitives = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::time::Instant; | ||
|
||
use alloy_primitives::U256; | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use op_succinct_fees::aggregate_fee_data; | ||
use op_succinct_host_utils::fetcher::OPSuccinctDataFetcher; | ||
|
||
#[derive(Parser)] | ||
struct Args { | ||
#[clap(long)] | ||
start: u64, | ||
#[clap(long)] | ||
end: u64, | ||
#[clap(long, default_value = None)] | ||
l1_fee_scalar: Option<U256>, | ||
#[clap(long, default_value = ".env")] | ||
env_file: String, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let args = Args::parse(); | ||
dotenv::from_filename(args.env_file).ok(); | ||
let fetcher = OPSuccinctDataFetcher::default(); | ||
|
||
let start_time = Instant::now(); | ||
let (fee_data, modified_fee_data) = tokio::join!( | ||
fetcher.get_l2_fee_data_range(args.start, args.end), | ||
fetcher.get_l2_fee_data_with_modified_l1_fee_scalar( | ||
args.start, | ||
args.end, | ||
args.l1_fee_scalar | ||
) | ||
); | ||
let duration = start_time.elapsed(); | ||
println!("Done getting fee data. Time taken: {:?}", duration); | ||
|
||
let fee_data = fee_data?; | ||
let modified_fee_data = modified_fee_data?; | ||
|
||
let total_aggregate_fee_data = aggregate_fee_data(fee_data)?; | ||
let modified_total_aggregate_fee_data = aggregate_fee_data(modified_fee_data)?; | ||
|
||
println!("{modified_total_aggregate_fee_data}"); | ||
println!("{total_aggregate_fee_data}"); | ||
|
||
assert_eq!( | ||
total_aggregate_fee_data.total_l1_fee, | ||
modified_total_aggregate_fee_data.total_l1_fee | ||
); | ||
|
||
println!("Success!"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::fmt; | ||
|
||
use alloy_primitives::U256; | ||
use anyhow::Result; | ||
use op_succinct_host_utils::fetcher::FeeData; | ||
|
||
pub struct AggregateFeeData { | ||
pub start: u64, | ||
pub end: u64, | ||
pub num_transactions: u64, | ||
pub total_l1_fee: U256, | ||
} | ||
|
||
impl fmt::Display for AggregateFeeData { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
let eth = self.total_l1_fee / U256::from(10).pow(U256::from(18)); | ||
let gwei = (self.total_l1_fee / U256::from(10).pow(U256::from(9))) | ||
% U256::from(10).pow(U256::from(9)); | ||
write!( | ||
f, | ||
"Start: {}, End: {}, Aggregate: {} transactions, {}.{:09} ETH L1 fee", | ||
self.start, self.end, self.num_transactions, eth, gwei | ||
) | ||
} | ||
} | ||
|
||
pub fn aggregate_fee_data(fee_data: Vec<FeeData>) -> Result<AggregateFeeData> { | ||
let mut aggregate_fee_data = AggregateFeeData { | ||
start: fee_data[0].block_number, | ||
end: fee_data[fee_data.len() - 1].block_number, | ||
num_transactions: 0, | ||
total_l1_fee: U256::ZERO, | ||
}; | ||
|
||
for data in fee_data { | ||
aggregate_fee_data.num_transactions += 1; | ||
aggregate_fee_data.total_l1_fee += data.l1_gas_cost; | ||
} | ||
|
||
Ok(aggregate_fee_data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.