Skip to content
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

feat(katana): rollup and dev chain spec #2957

Merged
merged 18 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 13 additions & 8 deletions bin/katana/src/cli/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use std::sync::Arc;
use anyhow::{Context, Result};
use clap::Args;
use inquire::{Confirm, CustomType, Select};
use katana_chain_spec::{SettlementLayer, DEV_UNALLOCATED};
use katana_chain_spec::rollup::FeeContract;
use katana_chain_spec::{rollup, SettlementLayer};
use katana_primitives::chain::ChainId;
use katana_primitives::genesis::allocation::DevAllocationsGenerator;
use katana_primitives::genesis::constant::DEFAULT_PREFUNDED_ACCOUNT_BALANCE;
use katana_primitives::genesis::Genesis;
use katana_primitives::{ContractAddress, Felt};
use katana_primitives::{felt, ContractAddress, Felt, U256};
use lazy_static::lazy_static;
use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount};
use starknet::core::types::{BlockId, BlockTag};
Expand Down Expand Up @@ -40,12 +42,12 @@ impl InitArgs {
core_contract: input.settlement_contract,
};

let mut chain_spec = DEV_UNALLOCATED.clone();
chain_spec.genesis = GENESIS.clone();
chain_spec.id = ChainId::parse(&input.id)?;
chain_spec.settlement = Some(settlement);
let id = ChainId::parse(&input.id)?;
let genesis = GENESIS.clone();
let fee_contract = FeeContract { strk: DEFAULT_APPCHAIN_FEE_TOKEN_ADDRESS.into() };

katana_chain_spec::file::write(&chain_spec).context("failed to write chain spec file")?;
let chain_spec = rollup::ChainSpec { id, genesis, settlement, fee_contract };
rollup::file::write(&chain_spec).context("failed to write chain spec file")?;

Ok(())
}
Expand Down Expand Up @@ -181,9 +183,12 @@ struct PromptOutcome {
lazy_static! {
static ref GENESIS: Genesis = {
// master account
let accounts = DevAllocationsGenerator::new(1).generate();
let accounts = DevAllocationsGenerator::new(1).with_balance(U256::from(DEFAULT_PREFUNDED_ACCOUNT_BALANCE)).generate();
let mut genesis = Genesis::default();
genesis.extend_allocations(accounts.into_iter().map(|(k, v)| (k, v.into())));
genesis
};
}

const DEFAULT_APPCHAIN_FEE_TOKEN_ADDRESS: Felt =
felt!("0x2e7442625bab778683501c0eadbc1ea17b3535da040a12ac7d281066e915eea");
9 changes: 5 additions & 4 deletions crates/dojo/test-utils/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl TestSequencer {
let url =
Url::parse(&format!("http://{}", handle.rpc.addr())).expect("Failed to parse URL");

let account = handle.node.backend.chain_spec.genesis.accounts().next().unwrap();
let account = handle.node.backend.chain_spec.genesis().accounts().next().unwrap();
let account = TestAccount {
private_key: Felt::from_bytes_be(&account.1.private_key().unwrap().to_bytes_be()),
account_address: Felt::from_bytes_be(&account.0.to_bytes_be()),
Expand Down Expand Up @@ -81,7 +81,7 @@ impl TestSequencer {
index: usize,
) -> SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet> {
let accounts: Vec<_> =
self.handle.node.backend.chain_spec.genesis.accounts().collect::<_>();
self.handle.node.backend.chain_spec.genesis().accounts().collect::<_>();

let account = accounts[index];
let private_key = Felt::from_bytes_be(&account.1.private_key().unwrap().to_bytes_be());
Expand Down Expand Up @@ -115,7 +115,8 @@ impl TestSequencer {

pub fn get_default_test_config(sequencing: SequencingConfig) -> Config {
let dev = DevConfig { fee: false, account_validation: true, fixed_gas_prices: None };
let mut chain = ChainSpec { id: ChainId::SEPOLIA, ..Default::default() };
let mut chain =
katana_chain_spec::dev::ChainSpec { id: ChainId::SEPOLIA, ..Default::default() };
chain.genesis.sequencer_address = *DEFAULT_SEQUENCER_ADDRESS;

let rpc = RpcConfig {
Expand All @@ -128,5 +129,5 @@ pub fn get_default_test_config(sequencing: SequencingConfig) -> Config {
max_proof_keys: Some(100),
};

Config { sequencing, rpc, dev, chain: chain.into(), ..Default::default() }
Config { sequencing, rpc, dev, chain: ChainSpec::Dev(chain).into(), ..Default::default() }
}
5 changes: 3 additions & 2 deletions crates/katana/chain-spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ katana-primitives.workspace = true

alloy-primitives.workspace = true
anyhow.workspace = true
dirs = "6.0.0"
lazy_static.workspace = true
num-traits.workspace = true
serde.workspace = true
serde_json.workspace = true
starknet.workspace = true
thiserror.workspace = true
url.workspace = true
dirs = "6.0.0"
toml.workspace = true
url.workspace = true

[dev-dependencies]
similar-asserts.workspace = true
Expand Down
Loading
Loading