Skip to content

Commit

Permalink
updated : review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ocdbytes committed Apr 15, 2024
1 parent 46a5e33 commit cb76d46
Show file tree
Hide file tree
Showing 29 changed files with 535 additions and 857 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linters-cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
run: |
cargo fmt -- --check
cargo clippy --no-deps -- -D warnings
cargo clippy --tests --no-deps -- -D warnings
cargo clippy --tests --no-deps -- -D warnings
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
- name: Checkout toml files
uses: actions/checkout@v3
- name: Run toml check
run: npx @taplo/cli fmt --config ./taplo/taplo.toml --check
run: npx @taplo/cli fmt --config ./taplo/taplo.toml --check
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
linters_cargo:
name: Run Cargo linters
uses: ./.github/workflows/linters-cargo.yml
needs: rust_build
needs: rust_build
2 changes: 1 addition & 1 deletion .github/workflows/rust-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:

- name: Build the project
run: |
cargo build --release --workspace
cargo build --release --workspace
9 changes: 9 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"MD033": false,
"MD041": false,
"MD045": false,
"MD003": false,
"MD013": {
"code_blocks": false
}
}
40 changes: 20 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.80"
cairo-vm = { git = "https://github.com/keep-starknet-strange/cairo-rs", branch = "no_std-support-21eff70", default-features = false, features = [
"std",
"cairo-1-hints",
"parity-scale-codec",
] }
ethers = { git = "https://github.com/gakonst/ethers-rs", rev = "f0e5b194f09c533feb10d1a686ddb9e5946ec107" }
hex = { version = "0.4.3", default-features = false, features = ["std"] }
reqwest = { version = "0.11.22", default-features = false }
serde = { version = "1.0.192", default-features = false, features = ["std"] }
serde_json = { version = "1.0.108", default-features = false, features = [
"std",
] }
serde_with = { version = "2.3.3", default-features = false }
thiserror-no-std = "2.0.2"
hex = { version = "0.4.3", default-features = false, features = ["std"] }
anyhow = "1.0.80"
reqwest = { version = "0.11.22", default-features = false }
url = "2.4.1"

# Substrate primitives dependencies
Expand All @@ -38,36 +38,36 @@ starknet-token-bridge-client = { git = "https://github.com/karnotxyz/zaun", pack
zaun-utils = { git = "https://github.com/karnotxyz/zaun", package = "utils", branch = "starkgate" }

# Starknet Deps
starknet-ff = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false, features = [
starknet-accounts = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
starknet-contract = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
starknet-core = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false, features = [
"std",
] }
starknet-core = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false, features = [
starknet-ff = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false, features = [
"std",
] }
starknet-providers = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
starknet-signers = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
starknet_api = { git = "https://github.com/keep-starknet-strange/starknet-api", branch = "no_std-support-dc83f05", features = [
"std",
"testing",
"parity-scale-codec",
], default-features = false }
starknet-accounts = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
starknet-providers = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
starknet-signers = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }
starknet-contract = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "64ebc36", default-features = false }

# Third Party
scale-info = { version = "2.10.0", default-features = false, features = [
"std",
] }
assert_matches = "1.5.0"
async-lock = "3.1.0"
async-trait = "0.1.74"
clap = { version = "4.4.11", features = ["derive", "env"] }
dotenv = "0.15.0"
env_logger = "0.11.3"
log = "0.4.21"
parity-scale-codec = { version = "3.2.2", default-features = false, features = [
"std",
] }
async-lock = "3.1.0"
rstest = "0.18.1"
scale-info = { version = "2.10.0", default-features = false, features = [
"std",
] }
thiserror = "1.0.50"
assert_matches = "1.5.0"
async-trait = "0.1.74"
tokio = {version = "1.36.0", features = ["macros", "rt-multi-thread"]}
log = "0.4.21"
clap = { version = "4.4.11", features = ["derive", "env"] }
env_logger = "0.11.3"
dotenv = "0.15.0"
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ RUST_LOG=debug cargo test -- --no-capture

```shell
RUST_LOG=debug cargo run -- --help
```
```
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
channel = "nightly"
components = ["rustfmt", "clippy", "rust-analyzer"]
targets = ["wasm32-unknown-unknown"]
profile = "minimal"
profile = "minimal"
20 changes: 20 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
edition = "2021"
newline_style = "Unix"
use_field_init_shorthand = true
use_small_heuristics = "Max"
use_try_shorthand = true
max_width = 120

# Unstable features below
unstable_features = true
version = "Two"
comment_width = 100
format_code_in_doc_comments = true
format_macro_bodies = true
format_macro_matchers = true
format_strings = true
imports_granularity = "Module"
group_imports = "StdExternalCrate"
normalize_comments = true
normalize_doc_attributes = true
wrap_comments = true
52 changes: 20 additions & 32 deletions src/bridge/deploy_erc20_bridge.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
use crate::bridge::contract_clients::config::Config;
use crate::bridge::contract_clients::eth_bridge::BridgeDeployable;
use crate::bridge::contract_clients::starknet_sovereign::StarknetSovereignContract;
use crate::bridge::contract_clients::token_bridge::StarknetTokenBridge;
use crate::ArgConfig;
use std::str::FromStr;
use std::time::Duration;

use anyhow::Ok;
use sp_core::{H160, U256};
use starknet_core::{
types::{BlockId, BlockTag, FunctionCall},
utils::get_selector_from_name,
};
use starknet_core::types::{BlockId, BlockTag, FunctionCall};
use starknet_core::utils::get_selector_from_name;
use starknet_ff::FieldElement;
use starknet_providers::jsonrpc::HttpTransport;
use starknet_providers::{JsonRpcClient, Provider};
use std::{str::FromStr, time::Duration};
use tokio::time::sleep;

use crate::contract_clients::config::Config;
use crate::contract_clients::eth_bridge::BridgeDeployable;
use crate::contract_clients::starknet_sovereign::StarknetSovereignContract;
use crate::contract_clients::token_bridge::StarknetTokenBridge;
use crate::{ArgConfig, CliArgs};

pub async fn deploy_erc20_bridge(
clients: &Config,
arg_config: ArgConfig,
arg_config: &CliArgs,
core_contract: &StarknetSovereignContract,
) -> Result<(StarknetTokenBridge, FieldElement, FieldElement), anyhow::Error> {
let token_bridge = StarknetTokenBridge::deploy(core_contract.client().clone()).await;

log::debug!("Token Bridge Deployment Successful [✅]");
log::debug!(
"[🚀] Token Bridge Address : {:?}",
token_bridge.bridge_address()
);
log::debug!("[🚀] Token Bridge Address : {:?}", token_bridge.bridge_address());
log::debug!("[🚀] ERC 20 Token Address : {:?}", token_bridge.address());

let l2_bridge_address = StarknetTokenBridge::deploy_l2_contracts(
Expand Down Expand Up @@ -56,22 +54,14 @@ pub async fn deploy_erc20_bridge(
)
.await;

sleep(Duration::from_secs(
arg_config.l1_wait_time.parse().unwrap(),
))
.await;
sleep(Duration::from_secs(arg_config.l1_wait_time.parse().unwrap())).await;

// We need to wait a little bit more for message to be consumed and executed
sleep(Duration::from_millis(60000)).await;

let l2_erc20_token_address = get_l2_token_address(
&clients.provider_l2(),
&l2_bridge_address,
&token_bridge.address(),
)
.await;
log::debug!(
"[🚀] L2 ERC 20 Token Address : {:?}",
l2_erc20_token_address
);
let l2_erc20_token_address =
get_l2_token_address(&clients.provider_l2(), &l2_bridge_address, &token_bridge.address()).await;
log::debug!("[🚀] L2 ERC 20 Token Address : {:?}", l2_erc20_token_address);

Ok((token_bridge, l2_bridge_address, l2_erc20_token_address))
}
Expand All @@ -86,9 +76,7 @@ async fn get_l2_token_address(
FunctionCall {
contract_address: l2_bridge_address.clone(),
entry_point_selector: get_selector_from_name("get_l2_token").unwrap(),
calldata: vec![
FieldElement::from_byte_slice_be(l1_erc_20_address.as_bytes()).unwrap(),
],
calldata: vec![FieldElement::from_byte_slice_be(l1_erc_20_address.as_bytes()).unwrap()],
},
BlockId::Tag(BlockTag::Latest),
)
Expand Down
54 changes: 25 additions & 29 deletions src/bridge/deploy_eth_bridge.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
use crate::bridge::contract_clients::config::{build_single_owner_account, Config};
use crate::bridge::contract_clients::eth_bridge::{BridgeDeployable, StarknetLegacyEthBridge};
use crate::bridge::contract_clients::starknet_sovereign::StarknetSovereignContract;
use crate::bridge::helpers::account_actions::{
get_contract_address_from_deploy_tx, AccountActions,
};
use crate::utils::arg_config::ArgConfig;
use crate::utils::constants::{ERC20_CASM_PATH, ERC20_SIERRA_PATH};
use crate::utils::utils::wait_for_transaction;
use std::str::FromStr;
use std::sync::Arc;

use starknet_accounts::Account;
use starknet_contract::ContractFactory;
use starknet_ff::FieldElement;
use starknet_providers::{jsonrpc::HttpTransport, JsonRpcClient};
use std::str::FromStr;
use std::sync::Arc;
use starknet_providers::jsonrpc::HttpTransport;
use starknet_providers::JsonRpcClient;

use crate::bridge::helpers::account_actions::{get_contract_address_from_deploy_tx, AccountActions};
use crate::contract_clients::config::Config;
use crate::contract_clients::eth_bridge::{BridgeDeployable, StarknetLegacyEthBridge};
use crate::contract_clients::starknet_sovereign::StarknetSovereignContract;
use crate::contract_clients::utils::build_single_owner_account;
use crate::tests::constants::{ERC20_CASM_PATH, ERC20_SIERRA_PATH};
use crate::utils::arg_config::ArgConfig;
use crate::utils::wait_for_transaction;
use crate::CliArgs;

pub async fn deploy_eth_bridge(
clients: &Config,
arg_config: ArgConfig,
arg_config: &CliArgs,
core_contract: &StarknetSovereignContract,
) -> Result<(StarknetLegacyEthBridge, FieldElement, FieldElement), anyhow::Error> {
let eth_bridge = StarknetLegacyEthBridge::deploy(core_contract.client().clone()).await;
Expand Down Expand Up @@ -58,9 +61,7 @@ pub async fn deploy_eth_bridge(
.await;
log::debug!("ETH Bridge L2 setup complete [✅]");

eth_bridge
.setup_l1_bridge("10000000000000000", "10000000000000000", l2_bridge_address)
.await;
eth_bridge.setup_l1_bridge("10000000000000000", "10000000000000000", l2_bridge_address).await;
log::debug!("ETH Bridge L1 setup complete [✅]");

Ok((eth_bridge, l2_bridge_address, l2_eth_address))
Expand All @@ -74,8 +75,7 @@ pub async fn deploy_eth_token_on_l2(
) -> FieldElement {
let account = build_single_owner_account(&rpc_provider_l2, private_key, address, false);

let (class_hash, contract_artifact) =
account.declare_contract_params_sierra(ERC20_SIERRA_PATH, ERC20_CASM_PATH);
let (class_hash, contract_artifact) = account.declare_contract_params_sierra(ERC20_SIERRA_PATH, ERC20_CASM_PATH);
let flattened_class = contract_artifact.clone().flatten().unwrap();

let declare_txn = account
Expand All @@ -85,9 +85,7 @@ pub async fn deploy_eth_token_on_l2(
.expect("Unable to declare ERC20 token on L2");
let sierra_class_hash = contract_artifact.class_hash().unwrap();

wait_for_transaction(rpc_provider_l2, declare_txn.transaction_hash)
.await
.unwrap();
wait_for_transaction(rpc_provider_l2, declare_txn.transaction_hash).await.unwrap();

let contract_factory = ContractFactory::new(sierra_class_hash, account.clone());

Expand All @@ -98,11 +96,11 @@ pub async fn deploy_eth_token_on_l2(
FieldElement::from_byte_slice_be("ETH".as_bytes()).unwrap(), // Symbol
FieldElement::from_str("18").unwrap(), // Decimals
FieldElement::from_str("10000000000000000000").unwrap(), // Initial supply low
FieldElement::from_str("0").unwrap(), // Initial supply high
account.address(), // recipient
minter, // permitted_minter
account.address(), // provisional_governance_admin
FieldElement::from_str("0").unwrap(), // upgrade_delay
FieldElement::from_str("0").unwrap(), // Initial supply high
account.address(), // recipient
minter, // permitted_minter
account.address(), // provisional_governance_admin
FieldElement::from_str("0").unwrap(), // upgrade_delay
],
FieldElement::ZERO,
true,
Expand All @@ -111,9 +109,7 @@ pub async fn deploy_eth_token_on_l2(
.await
.expect("[❌] Unable to deploy ERC20 token on L2");

wait_for_transaction(rpc_provider_l2, declare_txn.transaction_hash)
.await
.unwrap();
wait_for_transaction(rpc_provider_l2, declare_txn.transaction_hash).await.unwrap();

let address = get_contract_address_from_deploy_tx(&rpc_provider_l2, deploy_tx)
.await
Expand Down
Loading

0 comments on commit cb76d46

Please sign in to comment.