Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Jan 7, 2024
1 parent b29d348 commit 304f86c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 38 deletions.
31 changes: 12 additions & 19 deletions crates/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ sol!(
#[cfg(test)]
pub mod test {
use crate::IOrderBookV3::*;
use alloy_sol_types::{SolCall, SolError, SolEvent, abi::token::WordToken};
use alloy_primitives::{hex, Address, U256, keccak256};
use alloy_primitives::{hex, keccak256, Address, U256};
use alloy_sol_types::{abi::token::WordToken, SolCall, SolError, SolEvent};

#[test]
fn test_deposit_function() {
Expand All @@ -29,10 +29,7 @@ pub mod test {
"0000000000000000000000000000000000000000000000000000000000000001" // vaultId
);

assert_eq!(
call_data,
expected_call_data
);
assert_eq!(call_data, expected_call_data);
}

#[test]
Expand All @@ -45,13 +42,11 @@ pub mod test {
);
assert_eq!(
ZeroDepositAmount::abi_decode_raw(&call_data, true),
Ok(
ZeroDepositAmount {
sender: Address::repeat_byte(0x11),
token: Address::repeat_byte(0x22),
vaultId: U256::from(1),
}
)
Ok(ZeroDepositAmount {
sender: Address::repeat_byte(0x11),
token: Address::repeat_byte(0x22),
vaultId: U256::from(1),
})
);
}

Expand All @@ -67,9 +62,7 @@ pub mod test {
};
assert_eq!(
deposit_event.encode_topics_array::<1>(),
[
WordToken(Deposit::SIGNATURE_HASH)
]
[WordToken(Deposit::SIGNATURE_HASH)]
);
assert_eq!(
deposit_event.encode_data(),
Expand All @@ -86,7 +79,7 @@ pub mod test {
assert_eq!(T::SIGNATURE, expected);
assert_eq!(T::SELECTOR, keccak256(expected)[..4]);
}

fn assert_error_signature<T: SolError>(expected: &str) {
assert_eq!(T::SIGNATURE, expected);
assert_eq!(T::SELECTOR, keccak256(expected)[..4]);
Expand All @@ -95,5 +88,5 @@ pub mod test {
fn assert_event_signature<T: SolEvent>(expected: &str) {
assert_eq!(T::SIGNATURE, expected);
assert_eq!(T::SIGNATURE_HASH, keccak256(expected));
}
}
}
}
12 changes: 5 additions & 7 deletions crates/cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cli::order::Order;
use anyhow::Result;
use clap::command;
use clap::{Parser, Subcommand};
use crate::cli::order::Order;

mod order;

Expand All @@ -15,16 +15,14 @@ struct Cli {
#[derive(Subcommand)]
pub enum Orderbook {
#[command(subcommand)]
Order(Order)
Order(Order),
}

pub async fn dispatch(orderbook: Orderbook) -> Result<()> {
match orderbook {
Orderbook::Order(order) => {
match order {
Order::Ls => Ok(order::ls().await?),
}
}
Orderbook::Order(order) => match order {
Order::Ls => Ok(order::ls().await?),
},
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/cli/src/cli/order.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use clap::{Subcommand};
use clap::Subcommand;

#[derive(Subcommand)]
#[command(about = "Interact with an order(s) onchain and offchain.")]
pub enum Order {
#[command(about = "List all orders from the subgraph.")]
Ls
Ls,
}

pub async fn ls() -> anyhow::Result<()> {
let orders = rain_orderbook_subgraph_queries::orders::query().await?;
dbg!(orders);
Ok(())
}
}
2 changes: 1 addition & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ mod cli;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
cli::main().await
}
}
2 changes: 1 addition & 1 deletion crates/subgraph/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod orders;
pub mod orders;
19 changes: 12 additions & 7 deletions crates/subgraph/src/orders/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use anyhow::anyhow;
use graphql_client::GraphQLQuery;
use graphql_client::Response;
use once_cell::sync::Lazy;
use reqwest::Url;
use rust_bigint::BigInt;
use serde_bytes::ByteBuf as Bytes;
use anyhow::anyhow;
use once_cell::sync::Lazy;

use crate::orders::orders_query::OrdersQueryOrders;

static BASE_URL: Lazy<Url> =
Lazy::new(|| Url::parse("https://api.thegraph.com/subgraphs/name/siddharth2207/rainorderbook").unwrap());
static BASE_URL: Lazy<Url> = Lazy::new(|| {
Url::parse("https://api.thegraph.com/subgraphs/name/siddharth2207/rainorderbook").unwrap()
});

#[derive(GraphQLQuery)]
#[graphql(
Expand All @@ -23,13 +24,17 @@ pub async fn query() -> anyhow::Result<Vec<OrdersQueryOrders>> {
let variables = orders_query::Variables {};
let request_body = OrdersQuery::build_query(variables);
let client = reqwest::Client::new();
let res = client.post((*BASE_URL).clone()).json(&request_body).send().await?;
let res = client
.post((*BASE_URL).clone())
.json(&request_body)
.send()
.await?;
let response_body: Response<orders_query::ResponseData> = res.json().await?;
match response_body {
Response {
data: Some(orders_query::ResponseData { orders }),
..
} => Ok(orders),
_ => Err(anyhow!("Failed to get orders"))
_ => Err(anyhow!("Failed to get orders")),
}
}
}

0 comments on commit 304f86c

Please sign in to comment.