Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions crates/primitives/src/basefee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ mod tests {
use super::*;

#[cfg(feature = "optimism")]
use crate::chain::{OP_BASE_FEE_PARAMS, OP_SEPOLIA_BASE_FEE_PARAMS};
use crate::chain::{
BASE_SEPOLIA_BASE_FEE_PARAMS, OP_BASE_FEE_PARAMS, OP_SEPOLIA_BASE_FEE_PARAMS,
};

#[test]
fn calculate_base_fee_success() {
Expand Down Expand Up @@ -92,7 +94,7 @@ mod tests {
18000000, 18000000,
];
let next_base_fee = [
1180000000, 1146666666, 1122857142, 1244299375, 1189416692, 1028254188, 1144836295, 1,
1100000048, 1080000000, 1065714297, 1167067046, 1128881311, 1028254188, 1098203452, 1,
2, 3,
];

Expand All @@ -108,4 +110,37 @@ mod tests {
);
}
}

#[cfg(feature = "optimism")]
#[test]
fn calculate_base_sepolia_base_fee_success() {
let base_fee = [
1000000000, 1000000000, 1000000000, 1072671875, 1059263476, 1049238967, 1049238967, 0,
1, 2,
];
let gas_used = [
10000000, 10000000, 10000000, 9000000, 10001000, 0, 10000000, 10000000, 10000000,
10000000,
];
let gas_limit = [
10000000, 12000000, 14000000, 10000000, 14000000, 2000000, 18000000, 18000000,
18000000, 18000000,
];
let next_base_fee = [
1180000000, 1146666666, 1122857142, 1244299375, 1189416692, 1028254188, 1144836295, 1,
2, 3,
];

for i in 0..base_fee.len() {
assert_eq!(
next_base_fee[i],
calc_next_block_base_fee(
gas_used[i] as u128,
gas_limit[i] as u128,
base_fee[i] as u128,
BASE_SEPOLIA_BASE_FEE_PARAMS,
) as u64
);
Comment on lines +116 to +143
Copy link
Copy Markdown
Member

@Rjected Rjected Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these from an op-geth test? or just adjusted

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adjusted from before! This was a copy of the original calculate_optimism_sepolia_base_fee_success test above (since it already was setup for using an elasticity multiplier of 10)

And then I changed calculate_optimism_sepolia_base_fee_success to expect the correct values when using an elasticity multiplier of 6

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, makes sense

}
}
}
4 changes: 3 additions & 1 deletion crates/primitives/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ pub use spec::{BASE_MAINNET, BASE_SEPOLIA, OP_MAINNET, OP_SEPOLIA};

#[cfg(feature = "optimism")]
#[cfg(test)]
pub(crate) use spec::{OP_BASE_FEE_PARAMS, OP_SEPOLIA_BASE_FEE_PARAMS};
pub(crate) use spec::{
BASE_SEPOLIA_BASE_FEE_PARAMS, OP_BASE_FEE_PARAMS, OP_SEPOLIA_BASE_FEE_PARAMS,
};

// The chain spec module.
mod spec;
Expand Down
8 changes: 4 additions & 4 deletions crates/primitives/src/chain/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub use alloy_eips::eip1559::BaseFeeParams;
#[cfg(feature = "optimism")]
pub(crate) use crate::{
constants::{
OP_BASE_FEE_PARAMS, OP_CANYON_BASE_FEE_PARAMS, OP_SEPOLIA_BASE_FEE_PARAMS,
OP_SEPOLIA_CANYON_BASE_FEE_PARAMS,
BASE_SEPOLIA_BASE_FEE_PARAMS, BASE_SEPOLIA_CANYON_BASE_FEE_PARAMS, OP_BASE_FEE_PARAMS,
OP_CANYON_BASE_FEE_PARAMS, OP_SEPOLIA_BASE_FEE_PARAMS, OP_SEPOLIA_CANYON_BASE_FEE_PARAMS,
},
net::{base_nodes, base_testnet_nodes, op_nodes, op_testnet_nodes},
};
Expand Down Expand Up @@ -397,8 +397,8 @@ pub static BASE_SEPOLIA: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
]),
base_fee_params: BaseFeeParamsKind::Variable(
vec![
(Hardfork::London, OP_SEPOLIA_BASE_FEE_PARAMS),
(Hardfork::Canyon, OP_SEPOLIA_CANYON_BASE_FEE_PARAMS),
(Hardfork::London, BASE_SEPOLIA_BASE_FEE_PARAMS),
(Hardfork::Canyon, BASE_SEPOLIA_CANYON_BASE_FEE_PARAMS),
]
.into(),
),
Expand Down
21 changes: 20 additions & 1 deletion crates/primitives/src/constants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,26 @@ pub const OP_SEPOLIA_EIP1559_BASE_FEE_MAX_CHANGE_DENOMINATOR_CANYON: u128 = 250;
/// Base fee max change denominator for Optimism Sepolia as defined in the Optimism
/// [transaction costs](https://community.optimism.io/docs/developers/build/differences/#transaction-costs) doc.
#[cfg(feature = "optimism")]
pub const OP_SEPOLIA_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER: u128 = 10;
pub const OP_SEPOLIA_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER: u128 = 6;

/// Base fee max change denominator for Base Sepolia as defined in the Optimism
/// [transaction costs](https://community.optimism.io/docs/developers/build/differences/#transaction-costs) doc.
#[cfg(feature = "optimism")]
pub const BASE_SEPOLIA_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER: u128 = 10;

/// Get the base fee parameters for Base Sepolia.
#[cfg(feature = "optimism")]
pub const BASE_SEPOLIA_BASE_FEE_PARAMS: BaseFeeParams = BaseFeeParams {
max_change_denominator: OP_SEPOLIA_EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR,
elasticity_multiplier: BASE_SEPOLIA_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER,
};

/// Get the base fee parameters for Base Sepolia (post Canyon).
#[cfg(feature = "optimism")]
pub const BASE_SEPOLIA_CANYON_BASE_FEE_PARAMS: BaseFeeParams = BaseFeeParams {
max_change_denominator: OP_SEPOLIA_EIP1559_BASE_FEE_MAX_CHANGE_DENOMINATOR_CANYON,
elasticity_multiplier: BASE_SEPOLIA_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER,
};

/// Get the base fee parameters for Optimism Sepolia.
#[cfg(feature = "optimism")]
Expand Down