Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
325 changes: 163 additions & 162 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ manual_saturating_arithmetic = "warn"
rex-cli = { path = "cli" }
rex-sdk = { path = "sdk" }

ethrex-common = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-common", tag = "v7.0.0" }
ethrex-blockchain = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-blockchain", tag = "v7.0.0" }
ethrex-rlp = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-rlp", tag = "v7.0.0" }
ethrex-rpc = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-rpc", tag = "v7.0.0" }
ethrex-l2-rpc = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-l2-rpc", tag = "v7.0.0" }
ethrex-sdk = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-sdk", tag = "v7.0.0" }
ethrex-l2-common = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-l2-common", tag = "v7.0.0" }
ethrex-common = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-common", branch = "7702_on_generic_tx" }
ethrex-blockchain = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-blockchain", branch = "7702_on_generic_tx" }
ethrex-rlp = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-rlp", branch = "7702_on_generic_tx" }
ethrex-rpc = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-rpc", branch = "7702_on_generic_tx" }
ethrex-l2-rpc = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-l2-rpc", branch = "7702_on_generic_tx" }
ethrex-sdk = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-sdk", branch = "7702_on_generic_tx" }
ethrex-l2-common = { git = "https://github.com/lambdaclass/ethrex", package = "ethrex-l2-common", branch = "7702_on_generic_tx" }

keccak-hash = "0.11.0"
thiserror = "2.0.11"
Expand Down
62 changes: 55 additions & 7 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
use crate::commands::l2;
use crate::common::AuthorizeArgs;
use crate::utils::{parse_contract_creation, parse_func_call, parse_hex, parse_hex_string};
use crate::{
commands::autocomplete,
common::{CallArgs, DeployArgs, SendArgs, TransferArgs},
utils::parse_private_key,
};
use clap::{ArgAction, Parser, Subcommand};
use ethrex_common::types::TxType;
use ethrex_common::types::{AuthorizationTupleEntry, TxType};
use ethrex_common::{Address, Bytes, H256, H520};
use ethrex_l2_common::calldata::Value;
use ethrex_l2_common::utils::get_address_from_secret_key;
use ethrex_l2_rpc::signer::{LocalSigner, Signer};
use ethrex_rlp::encode::RLPEncode;
use ethrex_rpc::EthClient;
use ethrex_rpc::clients::Overrides;
use ethrex_rpc::types::block_identifier::{BlockIdentifier, BlockTag};
use ethrex_sdk::calldata::decode_calldata;
use ethrex_sdk::{build_generic_tx, create2_deploy_from_bytecode, send_generic_transaction};
use ethrex_sdk::{compile_contract, git_clone};
use keccak_hash::keccak;
use rex_sdk::authorize::build_authorization_tuple;
use rex_sdk::client::eth::get_token_balance;
use rex_sdk::create::{
DETERMINISTIC_DEPLOYER, brute_force_create2, compute_create_address, compute_create2_address,
};
use rex_sdk::l2::authorize::parse_authorization_list;
use rex_sdk::sign::{get_address_from_message_and_signature, sign_hash};
use rex_sdk::utils::to_checksum_address;
use rex_sdk::{balance_in_eth, deploy, transfer, wait_for_transaction_receipt};
Expand Down Expand Up @@ -276,6 +280,13 @@ pub(crate) enum Command {
#[arg(value_parser = parse_hex)]
data: Bytes,
},
#[clap(about = "Authorize a delegated account")]
Authorize {
#[clap(flatten)]
args: AuthorizeArgs,
#[arg(long, default_value = "http://localhost:8545", env = "RPC_URL")]
rpc_url: Url,
},
}

impl Command {
Expand Down Expand Up @@ -401,7 +412,8 @@ impl Command {
random,
} => {
let address = if let Some(private_key) = from_private_key {
get_address_from_secret_key(&private_key).map_err(|e| eyre::eyre!(e))?
get_address_from_secret_key(&private_key.secret_bytes())
.map_err(|e| eyre::eyre!(e))?
} else if zero {
Address::zero()
} else if random {
Expand Down Expand Up @@ -446,15 +458,16 @@ impl Command {
todo!("Display transaction URL in the explorer")
}

let from =
get_address_from_secret_key(&args.private_key).map_err(|e| eyre::eyre!(e))?;
let from = get_address_from_secret_key(&args.private_key.secret_bytes())
.map_err(|e| eyre::eyre!(e))?;

let client = EthClient::new(rpc_url)?;

let tx_hash = transfer(
args.amount,
from,
args.to,
TxType::EIP1559,
&args.private_key,
&client,
Overrides::default(),
Expand All @@ -472,8 +485,8 @@ impl Command {
todo!("Display transaction URL in the explorer")
}

let from =
get_address_from_secret_key(&args.private_key).map_err(|e| eyre::eyre!(e))?;
let from = get_address_from_secret_key(&args.private_key.secret_bytes())
.map_err(|e| eyre::eyre!(e))?;

let client = EthClient::new(rpc_url)?;

Expand All @@ -483,9 +496,27 @@ impl Command {
parse_func_call(args._args)?
};

let tx_type = if args.auth_tuple.is_empty() {
TxType::EIP1559
} else {
TxType::EIP7702
};

let auth_list = parse_authorization_list(&args.auth_tuple)?;
let auth_list = if auth_list.is_empty() {
None
} else {
Some(
auth_list
.iter()
.map(AuthorizationTupleEntry::from)
.collect(),
)
};

let tx = build_generic_tx(
&client,
TxType::EIP1559,
tx_type,
args.to,
from,
calldata,
Expand All @@ -497,6 +528,7 @@ impl Command {
max_fee_per_gas: args.max_fee_per_gas,
max_priority_fee_per_gas: args.max_priority_fee_per_gas,
from: Some(from),
authorization_list: auth_list,
..Default::default()
},
)
Expand Down Expand Up @@ -661,6 +693,21 @@ impl Command {
print_calldata(0, elem);
}
}
Command::Authorize { args, rpc_url } => {
let client = EthClient::new(rpc_url)?;

let auth_tuple = build_authorization_tuple(
&client,
args.delegated_address,
&args.private_key,
args.chain_id,
args.nonce,
)
.await?;
let mut buf = Vec::new();
auth_tuple.encode(&mut buf);
println!("0x{:x}", Bytes::from(buf));
}
};
Ok(())
}
Expand Down Expand Up @@ -770,6 +817,7 @@ async fn compile_contract_from_path(args: DeployArgs) -> eyre::Result<Bytes> {
output_dir,
contract_path,
false,
false,
Some(&solc_remappings_ref),
&include_paths,
)
Expand Down
Loading
Loading