diff --git a/orderbook-rs/src/errors.rs b/orderbook-rs/src/errors.rs index eec97296b..0d34a3430 100644 --- a/orderbook-rs/src/errors.rs +++ b/orderbook-rs/src/errors.rs @@ -1,43 +1,41 @@ -use thiserror::Error; -use url::ParseError; use ethers::contract::ContractError; +use ethers::middleware::signer::SignerMiddlewareError; use ethers::providers::ProviderError; use ethers::providers::{Http, Provider}; -use rustc_hex::FromHexError; -use ethers::middleware::signer::SignerMiddlewareError; use ethers::signers::Ledger; - +use rustc_hex::FromHexError; +use thiserror::Error; +use url::ParseError; /// RainOrderbookError /// Enum representing errors thrown by the crate -#[derive(Error, Debug)] -pub enum RainOrderbookError{ +#[derive(Error, Debug)] +pub enum RainOrderbookError { #[error("Invalid RPC URL")] - InvalidRPC{ + InvalidRPC { #[from] - source: ParseError + source: ParseError, }, #[error("Invalid Contract Function Call")] - InvalidContractFunctionCall{ + InvalidContractFunctionCall { #[from] - source: ContractError> + source: ContractError>, }, #[error("Invalid Address")] - InvalidAddress{ + InvalidAddress { #[from] - source: FromHexError + source: FromHexError, }, #[error("Failed to confirm transaction")] - TransactionConfirmationError{ + TransactionConfirmationError { #[from] - source: ProviderError + source: ProviderError, }, #[error("Error in Transaction")] - TransactionError{ + TransactionError { #[from] - source: SignerMiddlewareError, Ledger> + source: SignerMiddlewareError, Ledger>, }, #[error("Failed to fetch Transaction Receipt")] TransactionReceiptError, - -} \ No newline at end of file +} diff --git a/orderbook-rs/src/gasoracle/mod.rs b/orderbook-rs/src/gasoracle/mod.rs index 6d9ce8663..614f65c87 100644 --- a/orderbook-rs/src/gasoracle/mod.rs +++ b/orderbook-rs/src/gasoracle/mod.rs @@ -4,7 +4,8 @@ use reqwest::{header::AUTHORIZATION, Client}; use url::Url; /// Bloacknative Base Url for fetching blockprices -static BLOCKNATIVE_BLOCKPRICES_URL: &'static str = "https://api.blocknative.com/gasprices/blockprices"; +static BLOCKNATIVE_BLOCKPRICES_URL: &'static str = + "https://api.blocknative.com/gasprices/blockprices"; /// Blocknative Gas Oracle. /// Returns max priority fee and max fee from blocknative api. @@ -17,9 +18,9 @@ pub async fn gas_price_oracle( api_key: Option, chain_id: u64, ) -> anyhow::Result<(f64, f64)> { - let client = Client::new(); - let mut url = Url::parse(BLOCKNATIVE_BLOCKPRICES_URL.into())? ; - url.set_query(Some(format!("chainid={}",chain_id).as_str())); + let client = Client::new(); + let mut url = Url::parse(BLOCKNATIVE_BLOCKPRICES_URL.into())?; + url.set_query(Some(format!("chainid={}", chain_id).as_str())); let mut request = client.get(url); if let Some(api_key) = api_key.as_ref() { request = request.header(AUTHORIZATION, api_key); diff --git a/orderbook-rs/src/interpreter/mod.rs b/orderbook-rs/src/interpreter/mod.rs index ee252603a..a53cfd94b 100644 --- a/orderbook-rs/src/interpreter/mod.rs +++ b/orderbook-rs/src/interpreter/mod.rs @@ -1,4 +1,7 @@ -use crate::{registry::{IExpressionDeployerV3, IParserV1}, errors::RainOrderbookError}; +use crate::{ + errors::RainOrderbookError, + registry::{IExpressionDeployerV3, IParserV1}, +}; use alloy_primitives::{Address, Bytes, U256}; use ethers::{ providers::{Http, Provider}, @@ -16,40 +19,30 @@ use std::sync::Arc; pub async fn get_disp( deployer_npe2: Address, rpc_url: String, -) -> Result<(Address, Address, Address),RainOrderbookError> { +) -> Result<(Address, Address, Address), RainOrderbookError> { let provider = match Provider::::try_from(rpc_url.clone()) { - Ok(provider) => provider, - Err(err) => { - return Err(RainOrderbookError::InvalidRPC { source: err }) - } + Ok(provider) => provider, + Err(err) => return Err(RainOrderbookError::InvalidRPC { source: err }), }; - let deployer_npe2_address = match H160::from_str(&deployer_npe2.to_string()){ + let deployer_npe2_address = match H160::from_str(&deployer_npe2.to_string()) { Ok(deployer) => deployer, - Err(err) => { - return Err(RainOrderbookError::InvalidAddress { source: err }) - } + Err(err) => return Err(RainOrderbookError::InvalidAddress { source: err }), }; let deployer_npe2 = IExpressionDeployerV3::new(deployer_npe2_address, Arc::new(provider.clone())); let interpreter = match deployer_npe2.i_interpreter().call().await { Ok(i_interpreter) => i_interpreter, - Err(err) => { - return Err(RainOrderbookError::InvalidContractFunctionCall { source: err }) - } + Err(err) => return Err(RainOrderbookError::InvalidContractFunctionCall { source: err }), }; let store = match deployer_npe2.i_store().call().await { Ok(i_store) => i_store, - Err(err) => { - return Err(RainOrderbookError::InvalidContractFunctionCall { source: err }) - } + Err(err) => return Err(RainOrderbookError::InvalidContractFunctionCall { source: err }), }; let parser = match deployer_npe2.i_parser().call().await { Ok(i_parser) => i_parser, - Err(err) => { - return Err(RainOrderbookError::InvalidContractFunctionCall { source: err }) - } + Err(err) => return Err(RainOrderbookError::InvalidContractFunctionCall { source: err }), }; let store = Address::new(store.to_fixed_bytes()); @@ -69,19 +62,15 @@ pub async fn parse_rainstring( parser_address: Address, rainstring: String, rpc_url: String, -) -> Result<(Bytes, Vec),RainOrderbookError> { +) -> Result<(Bytes, Vec), RainOrderbookError> { let provider = match Provider::::try_from(rpc_url.clone()) { Ok(provider) => provider, - Err(err) => { - return Err(RainOrderbookError::InvalidRPC { source: err }) - } + Err(err) => return Err(RainOrderbookError::InvalidRPC { source: err }), }; let parser_address = match H160::from_str(&parser_address.to_string()) { Ok(parser) => parser, - Err(err) => { - return Err(RainOrderbookError::InvalidAddress { source: err }) - } + Err(err) => return Err(RainOrderbookError::InvalidAddress { source: err }), }; let rain_parser = IParserV1::new(parser_address, Arc::new(provider.clone())); @@ -91,9 +80,7 @@ pub async fn parse_rainstring( .await { Ok(parse_result) => parse_result, - Err(err) => { - return Err(RainOrderbookError::InvalidContractFunctionCall { source: err }) - } + Err(err) => return Err(RainOrderbookError::InvalidContractFunctionCall { source: err }), }; let bytecode_npe2 = Bytes::from(sources.to_vec()); diff --git a/orderbook-rs/src/lib.rs b/orderbook-rs/src/lib.rs index 2b3144349..267c235fd 100644 --- a/orderbook-rs/src/lib.rs +++ b/orderbook-rs/src/lib.rs @@ -1,6 +1,6 @@ +pub mod errors; pub mod gasoracle; pub mod interpreter; pub mod orderbook; pub mod registry; pub mod transaction; -pub mod errors; diff --git a/orderbook-rs/src/orderbook/add_order/v3.rs b/orderbook-rs/src/orderbook/add_order/v3.rs index 988ef23f5..193b8765e 100644 --- a/orderbook-rs/src/orderbook/add_order/v3.rs +++ b/orderbook-rs/src/orderbook/add_order/v3.rs @@ -1,11 +1,11 @@ use crate::{ + errors::RainOrderbookError, interpreter::{get_disp, parse_rainstring}, - registry::IOrderBookV3::{self, EvaluableConfigV3, OrderConfigV2, IO}, errors::RainOrderbookError, + registry::IOrderBookV3::{self, EvaluableConfigV3, OrderConfigV2, IO}, }; use alloy_primitives::Address; use alloy_sol_types::SolCall; - /// Returns [IOrderBookV3::addOrderCall] transaction data encoded with /// the function selector, encoding [IOrderBookV3::OrderConfigV2] built from /// the function parameters : Input Vaults, Output Vaults, and Order expression rainlang string. @@ -23,19 +23,15 @@ pub async fn add_ob_order( output_vaults: Vec, rainlang_order_string: String, rpc_url: String, -) -> Result,RainOrderbookError> { +) -> Result, RainOrderbookError> { let (_, _, rain_parser) = match get_disp(deployer_address.clone(), rpc_url.clone()).await { Ok(parse_result) => parse_result, - Err(err) => { - return Err(err) - } + Err(err) => return Err(err), }; let (bytecode, constants) = match parse_rainstring(rain_parser, rainlang_order_string, rpc_url.clone()).await { Ok(parse_result) => parse_result, - Err(err) => { - return Err(err) - } + Err(err) => return Err(err), }; let evaluable_config = EvaluableConfigV3 { diff --git a/orderbook-rs/src/transaction/mod.rs b/orderbook-rs/src/transaction/mod.rs index c65db1035..3a749d96e 100644 --- a/orderbook-rs/src/transaction/mod.rs +++ b/orderbook-rs/src/transaction/mod.rs @@ -32,12 +32,10 @@ pub async fn execute_transaction( rpc_url: String, wallet: Ledger, blocknative_api_key: Option, -) -> Result { +) -> Result { let provider = match Provider::::try_from(rpc_url.clone()) { Ok(provider) => provider, - Err(err) => { - return Err(RainOrderbookError::InvalidRPC { source: err }) - } + Err(err) => return Err(RainOrderbookError::InvalidRPC { source: err }), }; let chain_id = provider.clone().get_chainid().await.unwrap().as_u64(); @@ -74,9 +72,7 @@ pub async fn execute_transaction( let approve_receipt = match tx_result.confirmations(1).await { Ok(receipt) => match receipt { Some(receipt) => receipt, - None => { - return Err(RainOrderbookError::TransactionReceiptError) - } + None => return Err(RainOrderbookError::TransactionReceiptError), }, Err(err) => { return Err(RainOrderbookError::TransactionConfirmationError { source: err }) @@ -89,9 +85,7 @@ pub async fn execute_transaction( ); approve_receipt } - Err(err) => { - return Err(RainOrderbookError::TransactionError { source: err }) - } + Err(err) => return Err(RainOrderbookError::TransactionError { source: err }), }; Ok(receipt)