-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hotfix(katana): missing erc20 class on custom genesis #2582
Conversation
WalkthroughOhayo, sensei! This pull request refactors the fee token handling in the Changes
Possibly related PRs
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- crates/katana/primitives/src/chain_spec.rs (3 hunks)
🔇 Additional comments (2)
crates/katana/primitives/src/chain_spec.rs (2)
16-17
: LGTM! Constants are properly organized.Ohayo! The constants are well-organized and maintain clear separation between ERC20 and UDC-related constants.
110-110
: LGTM! Clean refactoring of fee token initialization.Ohayo sensei! The refactoring nicely consolidates the fee token initialization into a single function call, improving code organization and maintainability.
fn add_default_fee_tokens(states: &mut StateUpdatesWithDeclaredClasses, genesis: &Genesis) { | ||
// declare erc20 token contract | ||
states | ||
.declared_compiled_classes | ||
.entry(DEFAULT_LEGACY_ERC20_CLASS_HASH) | ||
.or_insert_with(|| DEFAULT_LEGACY_ERC20_CASM.clone()); | ||
|
||
// -- ETH | ||
add_fee_token( | ||
states, | ||
"Ether", | ||
"ETH", | ||
18, | ||
DEFAULT_ETH_FEE_TOKEN_ADDRESS, | ||
DEFAULT_LEGACY_ERC20_CLASS_HASH, | ||
&genesis.allocations, | ||
); | ||
|
||
// -- STRK | ||
add_fee_token( | ||
states, | ||
"Starknet Token", | ||
"STRK", | ||
18, | ||
DEFAULT_STRK_FEE_TOKEN_ADDRESS, | ||
DEFAULT_LEGACY_ERC20_CLASS_HASH, | ||
&genesis.allocations, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider adding error handling for class declaration.
Ohayo sensei! While the implementation is solid, consider adding error handling for the ERC20 class declaration. If the class hash is already declared with a different compiled class hash, it could lead to inconsistencies.
Consider this approach:
fn add_default_fee_tokens(states: &mut StateUpdatesWithDeclaredClasses, genesis: &Genesis) {
// declare erc20 token contract
- states
- .declared_compiled_classes
- .entry(DEFAULT_LEGACY_ERC20_CLASS_HASH)
- .or_insert_with(|| DEFAULT_LEGACY_ERC20_CASM.clone());
+ if let Some(existing_casm) = states.declared_compiled_classes.get(&DEFAULT_LEGACY_ERC20_CLASS_HASH) {
+ if existing_casm != &DEFAULT_LEGACY_ERC20_CASM {
+ // Handle the case where the class is already declared with different bytecode
+ panic!("ERC20 class hash already declared with different bytecode");
+ }
+ } else {
+ states
+ .declared_compiled_classes
+ .insert(DEFAULT_LEGACY_ERC20_CLASS_HASH, DEFAULT_LEGACY_ERC20_CASM.clone());
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
fn add_default_fee_tokens(states: &mut StateUpdatesWithDeclaredClasses, genesis: &Genesis) { | |
// declare erc20 token contract | |
states | |
.declared_compiled_classes | |
.entry(DEFAULT_LEGACY_ERC20_CLASS_HASH) | |
.or_insert_with(|| DEFAULT_LEGACY_ERC20_CASM.clone()); | |
// -- ETH | |
add_fee_token( | |
states, | |
"Ether", | |
"ETH", | |
18, | |
DEFAULT_ETH_FEE_TOKEN_ADDRESS, | |
DEFAULT_LEGACY_ERC20_CLASS_HASH, | |
&genesis.allocations, | |
); | |
// -- STRK | |
add_fee_token( | |
states, | |
"Starknet Token", | |
"STRK", | |
18, | |
DEFAULT_STRK_FEE_TOKEN_ADDRESS, | |
DEFAULT_LEGACY_ERC20_CLASS_HASH, | |
&genesis.allocations, | |
); | |
} | |
fn add_default_fee_tokens(states: &mut StateUpdatesWithDeclaredClasses, genesis: &Genesis) { | |
// declare erc20 token contract | |
if let Some(existing_casm) = states.declared_compiled_classes.get(&DEFAULT_LEGACY_ERC20_CLASS_HASH) { | |
if existing_casm != &DEFAULT_LEGACY_ERC20_CASM { | |
// Handle the case where the class is already declared with different bytecode | |
panic!("ERC20 class hash already declared with different bytecode"); | |
} | |
} else { | |
states | |
.declared_compiled_classes | |
.insert(DEFAULT_LEGACY_ERC20_CLASS_HASH, DEFAULT_LEGACY_ERC20_CASM.clone()); | |
} | |
// -- ETH | |
add_fee_token( | |
states, | |
"Ether", | |
"ETH", | |
18, | |
DEFAULT_ETH_FEE_TOKEN_ADDRESS, | |
DEFAULT_LEGACY_ERC20_CLASS_HASH, | |
&genesis.allocations, | |
); | |
// -- STRK | |
add_fee_token( | |
states, | |
"Starknet Token", | |
"STRK", | |
18, | |
DEFAULT_STRK_FEE_TOKEN_ADDRESS, | |
DEFAULT_LEGACY_ERC20_CLASS_HASH, | |
&genesis.allocations, | |
); | |
} |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2582 +/- ##
==========================================
- Coverage 69.63% 69.62% -0.01%
==========================================
Files 401 401
Lines 50759 50768 +9
==========================================
+ Hits 35344 35347 +3
- Misses 15415 15421 +6 ☔ View full report in Codecov by Sentry. |
Summary by CodeRabbit