Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
dev: refactor namings (#1347)
Browse files Browse the repository at this point in the history
* refactor namings

* fix imports
  • Loading branch information
greged93 authored Aug 26, 2024
1 parent 2bf12da commit 13d712f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn setup_tracing() -> Result<()> {
#[allow(clippy::significant_drop_tightening)]
#[cfg(feature = "hive")]
async fn setup_hive(starknet_provider: &JsonRpcClient<HttpTransport>) -> Result<()> {
use kakarot_rpc::providers::eth_provider::constant::{CHAIN_ID, DEPLOY_WALLET, DEPLOY_WALLET_NONCE};
use kakarot_rpc::providers::eth_provider::constant::hive::{CHAIN_ID, DEPLOY_WALLET, DEPLOY_WALLET_NONCE};
use starknet::{accounts::ConnectedAccount, core::types::Felt, providers::Provider as _};

let chain_id = starknet_provider.chain_id().await?;
Expand Down
75 changes: 36 additions & 39 deletions src/providers/eth_provider/constant.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
use reth_primitives::{B256, U256};
use serde::{Deserialize, Serialize};
use std::{str::FromStr, sync::LazyLock};
#[cfg(feature = "hive")]
use {
crate::config::KakarotRpcConfig,
starknet::core::types::Felt,
starknet::{
accounts::{ExecutionEncoding, SingleOwnerAccount},
providers::{jsonrpc::HttpTransport, JsonRpcClient},
signers::{LocalWallet, SigningKey},
},
std::sync::Arc,
std::{env::var, sync::OnceLock},
tokio::sync::Mutex,
};

/// Maximum priority fee per gas
pub static MAX_PRIORITY_FEE_PER_GAS: LazyLock<u64> = LazyLock::new(|| 0);
Expand All @@ -37,32 +24,6 @@ pub const ADDRESS_HEX_STRING_LEN: usize = 40;
/// Starknet Modulus: 0x800000000000011000000000000000000000000000000000000000000000001
pub const STARKNET_MODULUS: U256 = U256::from_limbs([0x1, 0, 0, 0x0800_0000_0000_0011]);

#[cfg(feature = "hive")]
pub static CHAIN_ID: OnceLock<Felt> = OnceLock::new();

#[cfg(feature = "hive")]
pub static RPC_CONFIG: LazyLock<KakarotRpcConfig> =
LazyLock::new(|| KakarotRpcConfig::from_env().expect("Failed to load Kakarot RPC config"));

#[cfg(feature = "hive")]
pub static DEPLOY_WALLET: LazyLock<SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet>> =
LazyLock::new(|| {
SingleOwnerAccount::new(
JsonRpcClient::new(HttpTransport::new(RPC_CONFIG.network_url.clone())),
LocalWallet::from_signing_key(SigningKey::from_secret_scalar(
Felt::from_str(&var("KATANA_PRIVATE_KEY").expect("Missing deployer private key"))
.expect("Failed to parse deployer private key"),
)),
Felt::from_str(&var("KATANA_ACCOUNT_ADDRESS").expect("Missing deployer address"))
.expect("Failed to parse deployer address"),
*CHAIN_ID.get().expect("Failed to get chain id"),
ExecutionEncoding::New,
)
});

#[cfg(feature = "hive")]
pub static DEPLOY_WALLET_NONCE: LazyLock<Arc<Mutex<Felt>>> = LazyLock::new(|| Arc::new(Mutex::new(Felt::ZERO)));

/// Struct used to return the constant values from the `kakarot_getConfig` endpoint
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct Constant {
Expand All @@ -79,3 +40,39 @@ pub struct Constant {
/// List of whitelisted hashes allow to submit pre EIP-155 transactions.
pub white_listed_eip_155_transaction_hashes: Vec<B256>,
}

#[cfg(feature = "hive")]
pub mod hive {
use crate::config::KakarotRpcConfig;
use starknet::{
accounts::{ExecutionEncoding, SingleOwnerAccount},
core::types::Felt,
providers::{jsonrpc::HttpTransport, JsonRpcClient},
signers::{LocalWallet, SigningKey},
};
use std::{
env::var,
str::FromStr,
sync::{Arc, LazyLock, OnceLock},
};
use tokio::sync::Mutex;

pub static CHAIN_ID: OnceLock<Felt> = OnceLock::new();
pub static RPC_CONFIG: LazyLock<KakarotRpcConfig> =
LazyLock::new(|| KakarotRpcConfig::from_env().expect("Failed to load Kakarot RPC config"));
pub static DEPLOY_WALLET: LazyLock<SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet>> =
LazyLock::new(|| {
SingleOwnerAccount::new(
JsonRpcClient::new(HttpTransport::new(RPC_CONFIG.network_url.clone())),
LocalWallet::from_signing_key(SigningKey::from_secret_scalar(
Felt::from_str(&var("KATANA_PRIVATE_KEY").expect("Missing deployer private key"))
.expect("Failed to parse deployer private key"),
)),
Felt::from_str(&var("KATANA_ACCOUNT_ADDRESS").expect("Missing deployer address"))
.expect("Failed to parse deployer address"),
*CHAIN_ID.get().expect("Failed to get chain id"),
ExecutionEncoding::New,
)
});
pub static DEPLOY_WALLET_NONCE: LazyLock<Arc<Mutex<Felt>>> = LazyLock::new(|| Arc::new(Mutex::new(Felt::ZERO)));
}
2 changes: 1 addition & 1 deletion src/providers/eth_provider/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ where
// Set a high gas limit to make sure the transaction will not fail due to gas.
let request = TransactionRequest { gas: Some(u128::from(u64::MAX)), ..request };

let gas_used = self.estimate_gas_helper(request, block_id).await?;
let gas_used = self.estimate_gas(request, block_id).await?;

// Increase the gas used by 20% to make sure the transaction will not fail due to gas.
// This is a temporary solution until we have a proper gas estimation.
Expand Down
4 changes: 2 additions & 2 deletions src/providers/eth_provider/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ where
}

/// Estimate the gas used in Kakarot for the given request.
pub(crate) async fn estimate_gas_helper(
pub(crate) async fn estimate_gas(
&self,
request: TransactionRequest,
block_id: Option<BlockId>,
Expand Down Expand Up @@ -297,7 +297,7 @@ where
/// Deploy the EVM transaction signer if a corresponding contract is not found on
/// Starknet.
pub(crate) async fn deploy_evm_transaction_signer(&self, signer: Address) -> EthProviderResult<()> {
use crate::providers::eth_provider::constant::{DEPLOY_WALLET, DEPLOY_WALLET_NONCE};
use crate::providers::eth_provider::constant::hive::{DEPLOY_WALLET, DEPLOY_WALLET_NONCE};
use starknet::{
accounts::{Call, ExecutionV1},
core::{types::BlockTag, utils::get_selector_from_name},
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/eth_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ async fn test_fee_history(#[future] katana: Katana, _setup: ()) {
async fn test_predeploy_eoa(#[future] katana: Katana, _setup: ()) {
use alloy_primitives::b256;
use futures::future::join_all;
use kakarot_rpc::{providers::eth_provider::constant::CHAIN_ID, test_utils::eoa::KakarotEOA};
use kakarot_rpc::{providers::eth_provider::constant::hive::CHAIN_ID, test_utils::eoa::KakarotEOA};
use starknet::providers::Provider;

// Given
Expand Down

0 comments on commit 13d712f

Please sign in to comment.