Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth2207 committed Dec 24, 2023
1 parent d137941 commit 192f30d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 54 deletions.
4 changes: 2 additions & 2 deletions orderbook-rs/src/gasoracle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use reqwest::{header::AUTHORIZATION, Client};

/// Blocknative Gas Oracle.
/// Returns max priority fee and max fee from blocknative api.
///
///
/// # Arguments
/// * `api_key` - Optional blocknative api key.
/// * `chain_id` - Network Chain Id.
///
///
pub async fn gas_price_oracle(
api_key: Option<String>,
chain_id: u64,
Expand Down
30 changes: 15 additions & 15 deletions orderbook-rs/src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use std::sync::Arc;
use tracing::error;

/// Get RainInterpreterNPE2, RainterpreterStoreNPE2 and RainterpreterParserNPE2 addresses corresponding to a RainterpreterExpressionDeployerNPE2 contract.
///
///
/// # Arguments
/// * `deployer_npe2` - Address of RainterpreterExpressionDeployerNPE2.
/// * `rpc_url` - Network RPC URL.
///
///
pub async fn get_disp(
deployer_npe2: Address,
rpc_url: String,
Expand All @@ -31,21 +31,21 @@ pub async fn get_disp(
let deployer_npe2 =
IExpressionDeployerV3::new(deployer_npe2_address, Arc::new(provider.clone()));

let interpreter = match deployer_npe2.i_interpreter().call().await{
let interpreter = match deployer_npe2.i_interpreter().call().await {
Ok(i_interpreter) => i_interpreter,
Err(err) => {
error!("iInterpreter");
return Err(anyhow!(err));
}
};
let store = match deployer_npe2.i_store().call().await{
let store = match deployer_npe2.i_store().call().await {
Ok(i_store) => i_store,
Err(err) => {
error!("iStore");
return Err(anyhow!(err));
}
};
let parser = match deployer_npe2.i_parser().call().await{
let parser = match deployer_npe2.i_parser().call().await {
Ok(i_parser) => i_parser,
Err(err) => {
error!("iParser");
Expand All @@ -61,7 +61,7 @@ pub async fn get_disp(
}

/// Parses rainlang expression string with RainterpreterParserNPE2 and returns the expression bytecode and constants
///
///
/// # Arguments
/// * `parser_address` - RainterpreterParserNPE2 address.
/// * `rainstring` - Rainlang Expression string.
Expand All @@ -79,7 +79,7 @@ pub async fn parse_rainstring(
}
};

let parser_address = match H160::from_str(&parser_address.to_string()){
let parser_address = match H160::from_str(&parser_address.to_string()) {
Ok(parser) => parser,
Err(err) => {
error!("INVALID PARSER");
Expand All @@ -91,14 +91,14 @@ pub async fn parse_rainstring(
let (sources, constants) = match rain_parser
.parse(ethers::types::Bytes::from(rainstring.as_bytes().to_vec()))
.call()
.await{
Ok(parse_result) => parse_result,
Err(err) => {
error!("FAILED TO PARSE");
return Err(anyhow!(err));
}
};
.await
{
Ok(parse_result) => parse_result,
Err(err) => {
error!("FAILED TO PARSE");
return Err(anyhow!(err));
}
};

let bytecode_npe2 = Bytes::from(sources.to_vec());

Expand Down
36 changes: 16 additions & 20 deletions orderbook-rs/src/orderbook/add_order/v3.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,45 @@
use alloy_primitives::Address;
use alloy_sol_types::SolCall;
use anyhow::anyhow;
use crate::{
interpreter::{get_disp, parse_rainstring},
registry::IOrderBookV3::{self, EvaluableConfigV3, OrderConfigV2, IO},
};
use alloy_primitives::Address;
use alloy_sol_types::SolCall;
use anyhow::anyhow;
use tracing::error;

/// Returns [IOrderBookV3::addOrderCall] transaction data encoded with
/// 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.
///
///
/// # Arguments
/// * `deployer_address` - Address of RainterpreterExpressionDeployerNPE2.
/// * `input_vaults` - [IOrderBookV3::IO] Order Input Vaults
/// * `output_vaults` - [IOrderBookV3::IO] Order Output Vaults
/// * `rainlang_order_string` - Order Expression String
/// * `rpc_url` - Network RPC URL
///
///
pub async fn add_ob_order(
deployer_address: Address,
input_vaults: Vec<IO>,
output_vaults: Vec<IO>,
rainlang_order_string: String,
rpc_url: String,
) -> anyhow::Result<Vec<u8>> {
let (_, _, rain_parser) = match get_disp(deployer_address.clone(), rpc_url.clone())
.await
{
let (_, _, rain_parser) = match get_disp(deployer_address.clone(), rpc_url.clone()).await {
Ok(parse_result) => parse_result,
Err(err) => {
error!("DISP");
return Err(anyhow!(err));
}
};
let (bytecode, constants) =
match parse_rainstring(rain_parser, rainlang_order_string, rpc_url.clone()).await {
Ok(parse_result) => parse_result,
Err(err) => {
error!("DISP");
error!("FAILED TO PARSE");
return Err(anyhow!(err));
}
};
let (bytecode, constants) =
match parse_rainstring(rain_parser, rainlang_order_string, rpc_url.clone())
.await
{
Ok(parse_result) => parse_result,
Err(err) => {
error!("FAILED TO PARSE");
return Err(anyhow!(err));
}
};

let evaluable_config = EvaluableConfigV3 {
deployer: deployer_address,
Expand Down
31 changes: 14 additions & 17 deletions orderbook-rs/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ use tracing::{error, info, warn};
use crate::gasoracle::gas_price_oracle;

/// Sign and submit transaction on chain via [Ledger] wallet.
///
/// # Arguments
///
/// # Arguments
/// * `tx_data` - Abi encoded transaction data, encoded with the function selector.
/// * `tx_to` - [Eip1559TransactionRequest::to]
/// * `tx_value` - [Eip1559TransactionRequest::value]
/// * `rpc_url` - Network RPC
/// * `wallet` - [Ledger] wallet instance
/// * `blocknative_api_key` - Optional Blocknative API Key.
///
///
pub async fn execute_transaction(
tx_data: Vec<u8>,
tx_to: Address,
Expand Down Expand Up @@ -51,22 +51,19 @@ pub async fn execute_transaction(
tx.data = Some(ethers::types::Bytes::from(tx_data));
tx.chain_id = Some(U64::from_dec_str(&chain_id.to_string()).unwrap());

match gas_price_oracle(blocknative_api_key, chain_id).await {
Ok((max_priority, max_fee)) => {
let max_priority: ethers::types::U256 =
parse_units(max_priority.to_string(), 9).unwrap().into();
let max_fee: ethers::types::U256 = parse_units(max_fee.to_string(), 9).unwrap().into();

match gas_price_oracle(blocknative_api_key, chain_id)
.await{
Ok((max_priority, max_fee)) => {
let max_priority: ethers::types::U256 =
parse_units(max_priority.to_string(), 9).unwrap().into();
let max_fee: ethers::types::U256 = parse_units(max_fee.to_string(), 9).unwrap().into();

tx.max_priority_fee_per_gas = Some(max_priority);
tx.max_fee_per_gas = Some(max_fee);
},
Err(_) => {
warn!("BLOCKNATIVE UNSUPPORTED NETWORK");
}
tx.max_priority_fee_per_gas = Some(max_priority);
tx.max_fee_per_gas = Some(max_fee);
}
Err(_) => {
warn!("BLOCKNATIVE UNSUPPORTED NETWORK");
}
};


let tx_result = client.send_transaction(tx, None).await;

Expand Down

0 comments on commit 192f30d

Please sign in to comment.