Skip to content

Commit

Permalink
Merge pull request #13 from madara-alliance/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
Mohiiit authored Oct 23, 2024
2 parents a3152b2 + b0b6475 commit 27f3679
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 105 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

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

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ serde_with = { version = "2.3.3", default-features = false }
url = "2.4.1"

# Zaun Deps
ethereum-instance = { git = "https://github.com/karnotxyz/zaun", package = "ethereum-instance", branch = "update/core-contract-v13.2.0" }
starkgate-manager-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-manager-client", branch = "update/core-contract-v13.2.0" }
starkgate-registry-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-registry-client", branch = "update/core-contract-v13.2.0" }
starknet-core-contract-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-core-contract-client", branch = "update/core-contract-v13.2.0" }
starknet-erc20-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-erc20-client", branch = "update/core-contract-v13.2.0" }
starknet-eth-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-eth-bridge-client", branch = "update/core-contract-v13.2.0" }
starknet-proxy-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-proxy-client", branch = "update/core-contract-v13.2.0" }
starknet-token-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-token-bridge-client", branch = "update/core-contract-v13.2.0" }
zaun-utils = { git = "https://github.com/karnotxyz/zaun", package = "utils", branch = "update/core-contract-v13.2.0" }
ethereum-instance = { git = "https://github.com/karnotxyz/zaun", package = "ethereum-instance", rev = "782967e5" }
starkgate-manager-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-manager-client", rev = "782967e5" }
starkgate-registry-client = { git = "https://github.com/karnotxyz/zaun", package = "starkgate-registry-client", rev = "782967e5" }
starknet-core-contract-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-core-contract-client", rev = "782967e5" }
starknet-erc20-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-erc20-client", rev = "782967e5" }
starknet-eth-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-eth-bridge-client", rev = "782967e5" }
starknet-proxy-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-proxy-client", rev = "782967e5" }
starknet-token-bridge-client = { git = "https://github.com/karnotxyz/zaun", package = "starknet-token-bridge-client", rev = "782967e5" }
zaun-utils = { git = "https://github.com/karnotxyz/zaun", package = "utils", rev = "782967e5" }

# Starknet Deps
starknet = "0.11.0"
Expand Down
Binary file added src/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion src/contract_clients/starknet_validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::contract_clients::core_contract::{
use crate::utils::convert_felt_to_u256;

pub struct StarknetValidityContract {
core_contract_client: StarknetValidityContractClient,
pub core_contract_client: StarknetValidityContractClient,
}

impl CoreContractDeploy<StarknetValidityContract> for StarknetValidityContract {
Expand Down
22 changes: 18 additions & 4 deletions src/contract_clients/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub(crate) enum DeclarationInput<'a> {
// inputs : sierra_path, casm_path
DeclarationInputs(String, String, RpcAccount<'a>),
// input : artifact_path
LegacyDeclarationInputs(String, String),
LegacyDeclarationInputs(String, String, &'a JsonRpcClient<HttpTransport>),
}

#[allow(private_interfaces)]
Expand All @@ -130,6 +130,10 @@ pub async fn declare_contract(input: DeclarationInput<'_>) -> Felt {
let class_hash = contract_artifact_casm.class_hash().unwrap();
let sierra_class_hash = contract_artifact.class_hash().unwrap();

if account.provider().get_class(BlockId::Tag(Pending), sierra_class_hash).await.is_ok() {
return sierra_class_hash;
}

let flattened_class = contract_artifact.flatten().unwrap();

account
Expand All @@ -140,12 +144,17 @@ pub async fn declare_contract(input: DeclarationInput<'_>) -> Felt {
.expect("Error in declaring the contract using Cairo 1 declaration using the provided account");
sierra_class_hash
}
LegacyDeclarationInputs(artifact_path, url) => {
LegacyDeclarationInputs(artifact_path, url, provider) => {
let contract_abi_artifact_temp: LegacyContractClass = serde_json::from_reader(
std::fs::File::open(env!("CARGO_MANIFEST_DIR").to_owned() + "/" + &artifact_path).unwrap(),
)
.unwrap();

let class_hash = contract_abi_artifact_temp.class_hash().expect("Failed to get class hash");
if provider.get_class(BlockId::Tag(Pending), class_hash).await.is_ok() {
return class_hash;
}

let contract_abi_artifact: CompressedLegacyContractClass = contract_abi_artifact_temp
.clone()
.compress()
Expand Down Expand Up @@ -183,7 +192,7 @@ pub async fn declare_contract(input: DeclarationInput<'_>) -> Felt {
}
}

contract_abi_artifact_temp.class_hash().unwrap()
class_hash
}
}
}
Expand All @@ -203,9 +212,14 @@ pub(crate) async fn deploy_account_using_priv_key(

let deploy_txn = oz_account_factory.deploy_v1(Felt::ZERO).max_fee(Felt::ZERO);
let account_address = deploy_txn.address();
log::trace!("OZ Account Deployed : {:?}", account_address);
log::trace!("OZ Account Deploy Address: {:?}", account_address);
save_to_json("account_address", &JsonValueType::StringType(account_address.to_string())).unwrap();

if provider.get_class_at(BlockId::Tag(Pending), account_address).await.is_ok() {
log::debug!("ℹ️ Account is already deployed. Skipping....");
return account_address;
}

let sent_txn = deploy_txn.send().await.expect("Error in deploying the OZ account");

log::trace!("deploy account txn_hash : {:?}", sent_txn.transaction_hash);
Expand Down
Loading

0 comments on commit 27f3679

Please sign in to comment.