Skip to content

Commit

Permalink
refactor, removed ethers dep
Browse files Browse the repository at this point in the history
  • Loading branch information
hardyjosh committed Jan 9, 2024
1 parent 8bf9b0d commit 06249f7
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 169 deletions.
29 changes: 14 additions & 15 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ serde_bytes = "0.11.9"
tokio = { version = "1.28.0", features = ["full"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
ethers = "2.0.7"
ethers-signers = { version = "2.0.8", features = ["ledger"] }
url = "2.5.0"
3 changes: 1 addition & 2 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ homepage = "https://github.com/rainprotocol/rain.orderbook"
[dependencies]
rain_orderbook_subgraph_queries = { path = "../subgraph" }
rain_orderbook_bindings = { path = "../bindings" }
rain_orderbook_transactions = { path = "../transaction" }
alloy-ethers-typecast = { git = "https://github.com/rainlanguage/alloy-ethers-typecast", rev = "d35a8e08ef240c4a66177f6de4e1de6fcb165b5f" }
anyhow = "1.0.70"
clap = { version = "4.2.5", features = ["cargo", "derive"] }
graphql_client = "0.12.0"
Expand All @@ -25,5 +25,4 @@ tracing = "0.1.37"
tracing-subscriber = "0.3.17"
alloy-primitives = "0.5.4"
alloy-sol-types = { version = "0.5.4" }
ethers-signers = { version = "2.0.8", features = ["ledger"] }

44 changes: 26 additions & 18 deletions crates/cli/src/commands/deposit.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
use crate::transaction::TransactionArgs;
use alloy_primitives::{Address, U256};
use crate::transaction::CliTransactionArgs;
use alloy_ethers_typecast::client::LedgerClient;
use alloy_ethers_typecast::request_shim::AlloyTransactionRequest;
use alloy_ethers_typecast::transaction::ExecutableTransaction;
use alloy_primitives::{Address, U256, U64};
use alloy_sol_types::SolCall;
use anyhow::Result;
use clap::Args;
use clap::Parser;
use ethers_signers::{HDPath, Ledger};
use rain_orderbook_bindings::IOrderBookV3::depositCall;
use rain_orderbook_transactions::execute::execute_transaction;

#[derive(Parser)]
pub struct Deposit {
#[clap(flatten)]
deposit_args: DepositArgs,
#[clap(flatten)]
transaction_args: TransactionArgs,
transaction_args: CliTransactionArgs,
}

impl Deposit {
pub async fn execute(self) -> Result<()> {
let deposit_call = self.deposit_args.to_deposit_call()?;
let call_data = deposit_call.abi_encode();
execute_transaction(
call_data,
self.transaction_args.orderbook_address.parse::<Address>()?,
U256::from(0),
self.transaction_args.rpc_url,
Ledger::new(
HDPath::LedgerLive(self.transaction_args.derivation_path.unwrap_or(0)),
self.transaction_args.chain_id,
)
.await?,
self.transaction_args.blocknative_api_key,
let call_data = self.deposit_args.to_deposit_call()?.abi_encode();

let tx = AlloyTransactionRequest::default()
.with_to(self.transaction_args.orderbook_address.parse::<Address>()?)
.with_data(call_data.clone())
.with_chain_id(U64::from(self.transaction_args.chain_id));

let ledger_client = LedgerClient::new(
self.transaction_args.derivation_path,
self.transaction_args.chain_id,
self.transaction_args.rpc_url.clone(),
)
.await?;

let transaction =
ExecutableTransaction::from_alloy_transaction_request(tx, ledger_client.client).await?;

transaction
.execute()
.await
.map_err(|e| anyhow::anyhow!(e))?;

Ok(())
}
}
Expand Down
5 changes: 1 addition & 4 deletions crates/cli/src/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::Args;

#[derive(Args)]
pub struct TransactionArgs {
pub struct CliTransactionArgs {
#[arg(short, long, help = "Orderbook contract address")]
pub orderbook_address: String,

Expand All @@ -13,7 +13,4 @@ pub struct TransactionArgs {

#[arg(short, long, help = "RPC URL")]
pub rpc_url: String,

#[arg(short, long, help = "Blocknative API Key")]
pub blocknative_api_key: Option<String>,
}
18 changes: 0 additions & 18 deletions crates/transaction/Cargo.toml

This file was deleted.

76 changes: 0 additions & 76 deletions crates/transaction/src/execute.rs

This file was deleted.

32 changes: 0 additions & 32 deletions crates/transaction/src/gasoracle.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/transaction/src/lib.rs

This file was deleted.

0 comments on commit 06249f7

Please sign in to comment.