Skip to content

Commit 5a9360d

Browse files
committed
wip
1 parent 2f1a06c commit 5a9360d

File tree

44 files changed

+1177
-1007
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1177
-1007
lines changed

Cargo.lock

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

crates/chain-spec/src/dev.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ use katana_primitives::chain::ChainId;
1515
use katana_primitives::class::ClassHash;
1616
use katana_primitives::contract::ContractAddress;
1717
use katana_primitives::da::L1DataAvailabilityMode;
18+
use katana_primitives::env::VersionedConstantsOverrides;
1819
use katana_primitives::state::StateUpdatesWithClasses;
1920
use katana_primitives::utils::split_u256;
2021
use katana_primitives::version::StarknetVersion;
2122
use katana_primitives::Felt;
2223
use lazy_static::lazy_static;
23-
use serde::{Deserialize, Serialize};
2424
use starknet::core::utils::cairo_short_string_to_felt;
2525

26-
use crate::SettlementLayer;
26+
use crate::{FeeContracts, SettlementLayer};
2727

2828
#[derive(Debug, Clone, PartialEq, Eq)]
2929
pub struct ChainSpec {
@@ -37,6 +37,8 @@ pub struct ChainSpec {
3737
pub fee_contracts: FeeContracts,
3838

3939
pub settlement: Option<SettlementLayer>,
40+
41+
pub versioned_constants_overrides: Option<VersionedConstantsOverrides>,
4042
}
4143

4244
//////////////////////////////////////////////////////////////
@@ -106,17 +108,6 @@ impl ChainSpec {
106108
}
107109
}
108110

109-
/// Tokens that can be used for transaction fee payments in the chain. As
110-
/// supported on Starknet.
111-
// TODO: include both l1 and l2 addresses
112-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
113-
pub struct FeeContracts {
114-
/// L2 ETH fee token address. Used for paying pre-V3 transactions.
115-
pub eth: ContractAddress,
116-
/// L2 STRK fee token address. Used for paying V3 transactions.
117-
pub strk: ContractAddress,
118-
}
119-
120111
impl Default for ChainSpec {
121112
fn default() -> Self {
122113
DEV.clone()
@@ -149,6 +140,7 @@ lazy_static! {
149140
genesis,
150141
fee_contracts,
151142
settlement: None,
143+
versioned_constants_overrides: None,
152144
}
153145
};
154146
}
@@ -336,6 +328,7 @@ mod tests {
336328
strk: DEFAULT_STRK_FEE_TOKEN_ADDRESS,
337329
},
338330
settlement: None,
331+
versioned_constants_overrides: None,
339332
};
340333

341334
// setup expected storage values

crates/chain-spec/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use katana_genesis::Genesis;
22
use katana_primitives::block::BlockNumber;
33
use katana_primitives::chain::ChainId;
4+
use katana_primitives::env::VersionedConstantsOverrides;
45
use katana_primitives::{eth, ContractAddress};
56
use serde::{Deserialize, Serialize};
67
use url::Url;
@@ -44,6 +45,20 @@ impl ChainSpec {
4445
Self::Rollup(spec) => Some(&spec.settlement),
4546
}
4647
}
48+
49+
pub fn fee_contracts(&self) -> &FeeContracts {
50+
match self {
51+
Self::Dev(spec) => &spec.fee_contracts,
52+
Self::Rollup(spec) => &spec.fee_contracts,
53+
}
54+
}
55+
56+
pub fn versioned_constants_overrides(&self) -> Option<&VersionedConstantsOverrides> {
57+
match self {
58+
Self::Dev(spec) => spec.versioned_constants_overrides.as_ref(),
59+
Self::Rollup(spec) => spec.versioned_constants_overrides.as_ref(),
60+
}
61+
}
4762
}
4863

4964
impl From<dev::ChainSpec> for ChainSpec {
@@ -106,3 +121,14 @@ pub enum SettlementLayer {
106121
// availability layer to the chain spec for Katana to sync from it.
107122
},
108123
}
124+
125+
/// Tokens that can be used for transaction fee payments in the chain. As
126+
/// supported on Starknet.
127+
// TODO: include both l1 and l2 addresses
128+
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
129+
pub struct FeeContracts {
130+
/// L2 ETH fee token address. Used for paying pre-V3 transactions.
131+
pub eth: ContractAddress,
132+
/// L2 STRK fee token address. Used for paying V3 transactions.
133+
pub strk: ContractAddress,
134+
}

crates/chain-spec/src/rollup/file.rs

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use std::path::{Path, PathBuf};
55
use katana_genesis::json::GenesisJson;
66
use katana_genesis::Genesis;
77
use katana_primitives::chain::ChainId;
8+
use katana_primitives::ContractAddress;
89
use serde::{Deserialize, Serialize};
910

10-
use super::FeeContract;
1111
use crate::rollup::ChainSpec;
12-
use crate::SettlementLayer;
12+
use crate::{FeeContracts, SettlementLayer};
1313

1414
#[derive(Debug, thiserror::Error)]
1515
pub enum Error {
@@ -86,7 +86,8 @@ pub fn read(dir: &ChainConfigDir) -> Result<ChainSpec, Error> {
8686
genesis,
8787
id: chain_spec.id,
8888
settlement: chain_spec.settlement,
89-
fee_contract: chain_spec.fee_contract,
89+
fee_contracts: chain_spec.fee_contract.into(),
90+
versioned_constants_overrides: None,
9091
})
9192
}
9293

@@ -95,7 +96,7 @@ pub fn write(dir: &ChainConfigDir, chain_spec: &ChainSpec) -> Result<(), Error>
9596
let cfg = ChainSpecFile {
9697
id: chain_spec.id,
9798
settlement: chain_spec.settlement.clone(),
98-
fee_contract: chain_spec.fee_contract.clone(),
99+
fee_contract: chain_spec.fee_contracts.clone().into(),
99100
};
100101

101102
let content = toml::to_string_pretty(&cfg)?;
@@ -140,11 +141,28 @@ fn list_at<P: AsRef<Path>>(dir: P) -> Result<Vec<ChainId>, Error> {
140141
Ok(chains)
141142
}
142143

144+
#[derive(Debug, Serialize, Deserialize)]
145+
pub struct FileFeeContract {
146+
pub strk: ContractAddress,
147+
}
148+
149+
impl From<FileFeeContract> for FeeContracts {
150+
fn from(fee_contract: FileFeeContract) -> Self {
151+
Self { strk: fee_contract.strk, eth: fee_contract.strk }
152+
}
153+
}
154+
155+
impl From<FeeContracts> for FileFeeContract {
156+
fn from(fee_contracts: FeeContracts) -> Self {
157+
Self { strk: fee_contracts.strk }
158+
}
159+
}
160+
143161
#[derive(Debug, Serialize, Deserialize)]
144162
#[serde(rename_all = "kebab-case")]
145163
struct ChainSpecFile {
146164
id: ChainId,
147-
fee_contract: FeeContract,
165+
fee_contract: FileFeeContract,
148166
settlement: SettlementLayer,
149167
}
150168

@@ -292,10 +310,10 @@ mod tests {
292310
use tempfile::TempDir;
293311
use url::Url;
294312

295-
use super::Error;
313+
use super::{Error, FileFeeContract};
296314
use crate::rollup::file::{local_dir, ChainConfigDir, LocalChainConfigDir, KATANA_LOCAL_DIR};
297-
use crate::rollup::{ChainSpec, FeeContract};
298-
use crate::SettlementLayer;
315+
use crate::rollup::ChainSpec;
316+
use crate::{FeeContracts, SettlementLayer};
299317

300318
static TEMPDIR: OnceLock<TempDir> = OnceLock::new();
301319

@@ -333,7 +351,11 @@ mod tests {
333351
ChainSpec {
334352
id: ChainId::default(),
335353
genesis: Genesis::default(),
336-
fee_contract: FeeContract { strk: ContractAddress::default() },
354+
fee_contracts: FeeContracts {
355+
eth: ContractAddress::default(),
356+
strk: ContractAddress::default(),
357+
},
358+
versioned_constants_overrides: None,
337359
settlement: SettlementLayer::Starknet {
338360
block: 0,
339361
id: ChainId::default(),
@@ -353,7 +375,7 @@ mod tests {
353375
let read_spec = read(&id).unwrap();
354376

355377
assert_eq!(chain_spec.id, read_spec.id);
356-
assert_eq!(chain_spec.fee_contract, read_spec.fee_contract);
378+
// assert_eq!(chain_spec.fee_contract, read_spec.fee_contract);
357379
assert_eq!(chain_spec.settlement, read_spec.settlement);
358380
}
359381

crates/chain-spec/src/rollup/mod.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
use katana_genesis::Genesis;
22
use katana_primitives::block::{ExecutableBlock, GasPrices, PartialHeader};
33
use katana_primitives::chain::ChainId;
4-
use katana_primitives::contract::ContractAddress;
54
use katana_primitives::da::L1DataAvailabilityMode;
5+
use katana_primitives::env::VersionedConstantsOverrides;
66
use katana_primitives::version::CURRENT_STARKNET_VERSION;
7-
use serde::{Deserialize, Serialize};
87

98
mod file;
109
mod utils;
1110

1211
pub use file::*;
1312
pub use utils::DEFAULT_APPCHAIN_FEE_TOKEN_ADDRESS;
1413

15-
use crate::SettlementLayer;
14+
use crate::{FeeContracts, SettlementLayer};
1615

1716
/// The rollup chain specification.
1817
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -24,10 +23,12 @@ pub struct ChainSpec {
2423
pub genesis: Genesis,
2524

2625
/// The chain fee token contract.
27-
pub fee_contract: FeeContract,
26+
pub fee_contracts: FeeContracts,
2827

2928
/// The chain's settlement layer configurations.
3029
pub settlement: SettlementLayer,
30+
31+
pub versioned_constants_overrides: Option<VersionedConstantsOverrides>,
3132
}
3233

3334
//////////////////////////////////////////////////////////////
@@ -54,14 +55,15 @@ impl ChainSpec {
5455
}
5556
}
5657

57-
/// Token that can be used for transaction fee payments on the chain.
58-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
59-
pub struct FeeContract {
60-
pub strk: ContractAddress,
61-
}
58+
// /// Token that can be used for transaction fee payments on the chain.
59+
// #[derive(Debug, Clone, Serialize, Deserialize)]
60+
// #[cfg_attr(test, derive(PartialEq))]
61+
// pub struct FeeContract {
62+
// pub strk: ContractAddress,
63+
// }
6264

63-
impl Default for FeeContract {
64-
fn default() -> Self {
65-
Self { strk: DEFAULT_APPCHAIN_FEE_TOKEN_ADDRESS }
66-
}
67-
}
65+
// impl Default for FeeContract {
66+
// fn default() -> Self {
67+
// Self { strk: DEFAULT_APPCHAIN_FEE_TOKEN_ADDRESS }
68+
// }
69+
// }

0 commit comments

Comments
 (0)