From 8a0b8006423f7973655ee42c4f6fec22caa7e990 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Mon, 12 Feb 2024 16:28:09 -0700 Subject: [PATCH 1/6] feat: take orders query & cli command --- crates/cli/src/commands/order/list_takes.rs | 80 +++++++ crates/cli/src/commands/order/mod.rs | 6 + .../subgraph/queries/orderTakesList.graphql | 44 ++++ crates/subgraph/src/client.rs | 22 ++ crates/subgraph/src/types/flattened.rs | 52 ++++- crates/subgraph/src/types/mod.rs | 1 + crates/subgraph/src/types/order_takes_list.rs | 195 ++++++++++++++++++ flake.nix | 1 + 8 files changed, 400 insertions(+), 1 deletion(-) create mode 100644 crates/cli/src/commands/order/list_takes.rs create mode 100644 crates/subgraph/queries/orderTakesList.graphql create mode 100644 crates/subgraph/src/types/order_takes_list.rs diff --git a/crates/cli/src/commands/order/list_takes.rs b/crates/cli/src/commands/order/list_takes.rs new file mode 100644 index 000000000..82e1bff18 --- /dev/null +++ b/crates/cli/src/commands/order/list_takes.rs @@ -0,0 +1,80 @@ +use crate::{ + execute::Execute, + subgraph::{CliPaginationArgs, CliSubgraphArgs}, +}; +use anyhow::Result; +use clap::Args; +use comfy_table::Table; +use rain_orderbook_common::subgraph::SubgraphArgs; +use rain_orderbook_subgraph_client::{ + types::flattened::{TryIntoFlattenedError, OrderTakeFlattened}, + PaginationArgs, TryIntoCsv, +}; +use tracing::info; + +#[derive(Args, Clone)] +pub struct CliOrderListTakes { + #[arg(short = 'i', long, help = "ID of the Order")] + order_id: String, + + #[clap(flatten)] + pagination_args: CliPaginationArgs, + + #[clap(flatten)] + subgraph_args: CliSubgraphArgs, +} + +impl Execute for CliOrderListTakes { + async fn execute(&self) -> Result<()> { + let subgraph_args: SubgraphArgs = self.subgraph_args.clone().into(); + let pagination_args: PaginationArgs = self.pagination_args.clone().into(); + let order_takes = subgraph_args + .to_subgraph_client() + .await? + .order_takes_list(self.order_id.clone().into(), pagination_args) + .await?; + let order_takes_flattened: Vec = + order_takes + .into_iter() + .map(|o| o.try_into()) + .collect::, TryIntoFlattenedError>>()?; + + if self.pagination_args.csv { + let csv_text = order_takes_flattened.try_into_csv()?; + println!("{}", csv_text); + } else { + let table = build_table(order_takes_flattened)?; + info!("\n{}", table); + } + + Ok(()) + } +} + +fn build_table(order_take: Vec) -> Result { + let mut table = comfy_table::Table::new(); + table + .load_preset(comfy_table::presets::UTF8_FULL) + .set_content_arrangement(comfy_table::ContentArrangement::Dynamic) + .set_header(vec![ + "ID", + "Taken At", + "Sender", + "Input", + "Output", + "IO Ratio" + ]); + + for order_take in order_take.into_iter() { + table.add_row(vec![ + order_take.id, + order_take.timestamp_display, + order_take.sender.0, + format!("{} {}", order_take.input_display.0, order_take.input_token_symbol), + format!("{} {}", order_take.output_display.0, order_take.output_token_symbol), + format!("{} {}/{}", order_take.ioratio.0, order_take.input_token_symbol, order_take.output_token_symbol), + ]); + } + + Ok(table) +} diff --git a/crates/cli/src/commands/order/mod.rs b/crates/cli/src/commands/order/mod.rs index 7c6730118..863d9773e 100644 --- a/crates/cli/src/commands/order/mod.rs +++ b/crates/cli/src/commands/order/mod.rs @@ -2,6 +2,7 @@ mod add; mod detail; mod list; mod remove; +mod list_takes; use crate::execute::Execute; use add::CliOrderAddArgs; @@ -10,6 +11,7 @@ use clap::Parser; use detail::CliOrderDetailArgs; use list::CliOrderListArgs; use remove::CliOrderRemoveArgs; +use list_takes::CliOrderListTakes; #[derive(Parser)] pub enum Order { @@ -24,6 +26,9 @@ pub enum Order { #[command(about = "Remove an Order", alias = "rm")] Remove(CliOrderRemoveArgs), + + #[command(about = "List takes for an Order", alias = "ls-takes")] + ListTakes(CliOrderListTakes), } impl Execute for Order { @@ -33,6 +38,7 @@ impl Execute for Order { Order::Detail(detail) => detail.execute().await, Order::Create(create) => create.execute().await, Order::Remove(remove) => remove.execute().await, + Order::ListTakes(list_takes) => list_takes.execute().await, } } } diff --git a/crates/subgraph/queries/orderTakesList.graphql b/crates/subgraph/queries/orderTakesList.graphql new file mode 100644 index 000000000..1718e9a31 --- /dev/null +++ b/crates/subgraph/queries/orderTakesList.graphql @@ -0,0 +1,44 @@ +query OrderTakesListQuery($id: ID!, $skip: Int = 0, $first: Int = 25) { + takeOrderEntities(orderBy: timestamp, orderDirection: desc, skip: $skip, first: $first, where: { + order_: { + id: $id + } + }) { + id + transaction { + id + } + sender { + id + } + timestamp + order { + id + } + IORatio + input + inputDisplay + inputToken { + id + name + symbol + decimals + } + inputIOIndex + output + outputDisplay + outputToken { + id + name + symbol + decimals + } + outputIOIndex + context { + callingContext + calculationsContext + vaultInputsContext + vaultOutputsContext + } + } +} \ No newline at end of file diff --git a/crates/subgraph/src/client.rs b/crates/subgraph/src/client.rs index 2f410b873..b5a51d912 100644 --- a/crates/subgraph/src/client.rs +++ b/crates/subgraph/src/client.rs @@ -17,6 +17,8 @@ use crate::types::{ }, vaults_list, vaults_list::{VaultsListQuery, VaultsListQueryVariables}, + order_takes_list, + order_takes_list::{OrderTakesListQuery, OrderTakesListQueryVariables} }; use crate::PageQueryClient; use chrono::NaiveDateTime; @@ -155,6 +157,26 @@ impl OrderbookSubgraphClient { Ok(data.order_clears) } + + pub async fn order_takes_list( + &self, + order_id: cynic::Id, + pagination_args: PaginationArgs, + ) -> Result, OrderbookSubgraphClientError> { + let pagination_variables = Self::parse_pagination_args(pagination_args); + let data = self + .query::( + self.url.clone(), + OrderTakesListQueryVariables { + id: &order_id, + first: pagination_variables.first, + skip: pagination_variables.skip, + }, + ) + .await?; + + Ok(data.take_order_entities) + } } pub struct VaultListBalanceChangesPageQueryClient { diff --git a/crates/subgraph/src/types/flattened.rs b/crates/subgraph/src/types/flattened.rs index b765789c7..87115d690 100644 --- a/crates/subgraph/src/types/flattened.rs +++ b/crates/subgraph/src/types/flattened.rs @@ -2,7 +2,7 @@ use std::num::ParseIntError; use super::{ order_clears_list, orders_list, vault_balance_change::VaultBalanceChange, - vault_list_balance_changes, vaults_list, + vault_list_balance_changes, vaults_list, order_takes_list, }; use crate::utils::format_bigint_timestamp_display; use crate::{csv::TryIntoCsv, utils::FormatTimestampDisplayError}; @@ -204,3 +204,53 @@ impl TryFrom for OrderClearFlattened { } impl TryIntoCsv for Vec {} + + +#[derive(Serialize, Deserialize, Clone)] +pub struct OrderTakeFlattened { + pub id: String, + pub timestamp: order_takes_list::BigInt, + pub timestamp_display: String, + pub transaction: cynic::Id, + pub sender: order_takes_list::Bytes, + pub order_id: cynic::Id, + pub ioratio: order_takes_list::BigDecimal, + pub input: order_takes_list::BigInt, + pub input_display: order_takes_list::BigDecimal, + pub input_token_id: cynic::Id, + pub input_token_symbol: String, + pub input_ioindex: order_takes_list::BigInt, + pub output: order_takes_list::BigInt, + pub output_display:order_takes_list:: BigDecimal, + pub output_token_id: cynic::Id, + pub output_token_symbol: String, + pub output_ioindex: order_takes_list::BigInt, +} + +impl TryFrom for OrderTakeFlattened { + type Error = TryIntoFlattenedError; + + fn try_from(val: order_takes_list::TakeOrderEntity) -> Result { + Ok(Self { + id: val.id.into_inner(), + timestamp: val.timestamp.clone(), + timestamp_display: format_bigint_timestamp_display(val.timestamp.0)?, + transaction: val.transaction.id, + sender: val.sender.id, + order_id: val.order.id, + ioratio: val.ioratio, + input: val.input, + input_display: val.input_display, + input_token_id: val.input_token.id, + input_token_symbol: val.input_token.symbol, + input_ioindex: val.input_ioindex, + output: val.output, + output_display: val.output_display, + output_token_id: val.output_token.id, + output_token_symbol: val.output_token.symbol, + output_ioindex: val.output_ioindex, + }) + } +} + +impl TryIntoCsv for Vec {} diff --git a/crates/subgraph/src/types/mod.rs b/crates/subgraph/src/types/mod.rs index 70d7eb0d6..9c710f8a0 100644 --- a/crates/subgraph/src/types/mod.rs +++ b/crates/subgraph/src/types/mod.rs @@ -7,3 +7,4 @@ pub mod vault_balance_change; pub mod vault_detail; pub mod vault_list_balance_changes; pub mod vaults_list; +pub mod order_takes_list; \ No newline at end of file diff --git a/crates/subgraph/src/types/order_takes_list.rs b/crates/subgraph/src/types/order_takes_list.rs new file mode 100644 index 000000000..915d06d8a --- /dev/null +++ b/crates/subgraph/src/types/order_takes_list.rs @@ -0,0 +1,195 @@ +use crate::schema; +use serde::Serialize; +use typeshare::typeshare; + +#[typeshare] +#[derive(cynic::QueryVariables, Debug)] +pub struct OrderTakesListQueryVariables<'a> { + pub first: Option, + pub id: &'a cynic::Id, + pub skip: Option, +} + +#[typeshare] +#[derive(cynic::QueryFragment, Debug)] +#[cynic(graphql_type = "Query", variables = "OrderTakesListQueryVariables")] +pub struct OrderTakesListQuery { + #[arguments(orderBy: "timestamp", orderDirection: "desc", skip: $skip, first: $first, where: { order_: { id: $id } })] + pub take_order_entities: Vec, +} + +#[typeshare] +#[derive(cynic::QueryFragment, Debug, Serialize)] +pub struct TakeOrderEntity { + pub id: cynic::Id, + pub transaction: Transaction, + pub sender: Account, + pub timestamp: BigInt, + pub order: Order, + #[cynic(rename = "IORatio")] + pub ioratio: BigDecimal, + pub input: BigInt, + pub input_display: BigDecimal, + pub input_token: Erc20, + #[cynic(rename = "inputIOIndex")] + pub input_ioindex: BigInt, + pub output: BigInt, + pub output_display: BigDecimal, + pub output_token: Erc20, + #[cynic(rename = "outputIOIndex")] + pub output_ioindex: BigInt, + pub context: Option, +} + +#[typeshare] +#[derive(cynic::QueryFragment, Debug, Serialize)] +pub struct Transaction { + pub id: cynic::Id, +} + +#[typeshare] +#[derive(cynic::QueryFragment, Debug, Serialize)] +pub struct Order { + pub id: cynic::Id, +} + +#[typeshare] +#[derive(cynic::QueryFragment, Debug, Serialize)] +#[cynic(graphql_type = "ERC20")] +pub struct Erc20 { + pub id: cynic::Id, + pub name: String, + pub symbol: String, + pub decimals: i32, +} + +#[typeshare] +#[derive(cynic::QueryFragment, Debug, Serialize)] +pub struct ContextEntity { + pub calling_context: Option>, + pub calculations_context: Option>, + pub vault_inputs_context: Option>, + pub vault_outputs_context: Option>, +} + +#[typeshare] +#[derive(cynic::QueryFragment, Debug, Serialize)] +pub struct Account { + pub id: Bytes, +} + +#[derive(cynic::Enum, Clone, Copy, Debug)] +pub enum OrderDirection { + #[cynic(rename = "asc")] + Asc, + #[cynic(rename = "desc")] + Desc, +} + +#[derive(cynic::Enum, Clone, Copy, Debug)] +#[cynic(graphql_type = "TakeOrderEntity_orderBy")] +pub enum TakeOrderEntityOrderBy { + #[cynic(rename = "id")] + Id, + #[cynic(rename = "sender")] + Sender, + #[cynic(rename = "sender__id")] + SenderId, + #[cynic(rename = "order")] + Order, + #[cynic(rename = "order__id")] + OrderId, + #[cynic(rename = "order__orderHash")] + OrderOrderHash, + #[cynic(rename = "order__interpreter")] + OrderInterpreter, + #[cynic(rename = "order__interpreterStore")] + OrderInterpreterStore, + #[cynic(rename = "order__expressionDeployer")] + OrderExpressionDeployer, + #[cynic(rename = "order__expression")] + OrderExpression, + #[cynic(rename = "order__orderActive")] + OrderOrderActive, + #[cynic(rename = "order__handleIO")] + OrderHandleIo, + #[cynic(rename = "order__orderJSONString")] + OrderOrderJsonstring, + #[cynic(rename = "order__expressionJSONString")] + OrderExpressionJsonstring, + #[cynic(rename = "order__timestamp")] + OrderTimestamp, + #[cynic(rename = "input")] + Input, + #[cynic(rename = "inputDisplay")] + InputDisplay, + #[cynic(rename = "output")] + Output, + #[cynic(rename = "outputDisplay")] + OutputDisplay, + #[cynic(rename = "IORatio")] + Ioratio, + #[cynic(rename = "inputIOIndex")] + InputIoindex, + #[cynic(rename = "outputIOIndex")] + OutputIoindex, + #[cynic(rename = "inputToken")] + InputToken, + #[cynic(rename = "inputToken__id")] + InputTokenId, + #[cynic(rename = "inputToken__name")] + InputTokenName, + #[cynic(rename = "inputToken__symbol")] + InputTokenSymbol, + #[cynic(rename = "inputToken__totalSupply")] + InputTokenTotalSupply, + #[cynic(rename = "inputToken__totalSupplyDisplay")] + InputTokenTotalSupplyDisplay, + #[cynic(rename = "inputToken__decimals")] + InputTokenDecimals, + #[cynic(rename = "outputToken")] + OutputToken, + #[cynic(rename = "outputToken__id")] + OutputTokenId, + #[cynic(rename = "outputToken__name")] + OutputTokenName, + #[cynic(rename = "outputToken__symbol")] + OutputTokenSymbol, + #[cynic(rename = "outputToken__totalSupply")] + OutputTokenTotalSupply, + #[cynic(rename = "outputToken__totalSupplyDisplay")] + OutputTokenTotalSupplyDisplay, + #[cynic(rename = "outputToken__decimals")] + OutputTokenDecimals, + #[cynic(rename = "transaction")] + Transaction, + #[cynic(rename = "transaction__id")] + TransactionId, + #[cynic(rename = "transaction__timestamp")] + TransactionTimestamp, + #[cynic(rename = "transaction__blockNumber")] + TransactionBlockNumber, + #[cynic(rename = "emitter")] + Emitter, + #[cynic(rename = "emitter__id")] + EmitterId, + #[cynic(rename = "timestamp")] + Timestamp, + #[cynic(rename = "context")] + Context, + #[cynic(rename = "context__id")] + ContextId, + #[cynic(rename = "context__timestamp")] + ContextTimestamp, +} + +#[derive(cynic::Scalar, Debug, Clone)] +pub struct BigDecimal(pub String); + +#[derive(cynic::Scalar, Debug, Clone)] +pub struct BigInt(pub String); + +#[derive(cynic::Scalar, Debug, Clone)] +pub struct Bytes(pub String); + + diff --git a/flake.nix b/flake.nix index 6d2294621..b59e1e046 100644 --- a/flake.nix +++ b/flake.nix @@ -31,6 +31,7 @@ typeshare crates/subgraph/src/types/orders_list.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/ordersList.ts; typeshare crates/subgraph/src/types/orders_list_for_vault.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/ordersListForVault.ts; typeshare crates/subgraph/src/types/order_clears_list.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/orderClearsList.ts; + typeshare crates/subgraph/src/types/order_takes_list.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/orderTakesList.ts; typeshare tauri-app/src-tauri/src/toast.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/toast.ts; typeshare tauri-app/src-tauri/src/transaction_status.rs --lang=typescript --output-file=tauri-app/src/lib/typeshare/transactionStatus.ts; From e400215d6d234734049960fd9b1c72eac355724f Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Mon, 12 Feb 2024 16:48:31 -0700 Subject: [PATCH 2/6] chore: fmt + clippy --- crates/cli/src/commands/order/list_takes.rs | 113 +++++++++--------- crates/cli/src/commands/order/mod.rs | 4 +- crates/subgraph/src/client.rs | 4 +- crates/subgraph/src/types/flattened.rs | 7 +- crates/subgraph/src/types/mod.rs | 2 +- crates/subgraph/src/types/order_takes_list.rs | 2 - 6 files changed, 66 insertions(+), 66 deletions(-) diff --git a/crates/cli/src/commands/order/list_takes.rs b/crates/cli/src/commands/order/list_takes.rs index 82e1bff18..0d9b6a9f0 100644 --- a/crates/cli/src/commands/order/list_takes.rs +++ b/crates/cli/src/commands/order/list_takes.rs @@ -1,80 +1,83 @@ use crate::{ - execute::Execute, - subgraph::{CliPaginationArgs, CliSubgraphArgs}, + execute::Execute, + subgraph::{CliPaginationArgs, CliSubgraphArgs}, }; use anyhow::Result; use clap::Args; use comfy_table::Table; use rain_orderbook_common::subgraph::SubgraphArgs; use rain_orderbook_subgraph_client::{ - types::flattened::{TryIntoFlattenedError, OrderTakeFlattened}, - PaginationArgs, TryIntoCsv, + types::flattened::{OrderTakeFlattened, TryIntoFlattenedError}, + PaginationArgs, TryIntoCsv, }; use tracing::info; #[derive(Args, Clone)] pub struct CliOrderListTakes { - #[arg(short = 'i', long, help = "ID of the Order")] - order_id: String, + #[arg(short = 'i', long, help = "ID of the Order")] + order_id: String, - #[clap(flatten)] - pagination_args: CliPaginationArgs, + #[clap(flatten)] + pagination_args: CliPaginationArgs, - #[clap(flatten)] - subgraph_args: CliSubgraphArgs, + #[clap(flatten)] + subgraph_args: CliSubgraphArgs, } impl Execute for CliOrderListTakes { - async fn execute(&self) -> Result<()> { - let subgraph_args: SubgraphArgs = self.subgraph_args.clone().into(); - let pagination_args: PaginationArgs = self.pagination_args.clone().into(); - let order_takes = subgraph_args - .to_subgraph_client() - .await? - .order_takes_list(self.order_id.clone().into(), pagination_args) - .await?; - let order_takes_flattened: Vec = - order_takes - .into_iter() - .map(|o| o.try_into()) - .collect::, TryIntoFlattenedError>>()?; + async fn execute(&self) -> Result<()> { + let subgraph_args: SubgraphArgs = self.subgraph_args.clone().into(); + let pagination_args: PaginationArgs = self.pagination_args.clone().into(); + let order_takes = subgraph_args + .to_subgraph_client() + .await? + .order_takes_list(self.order_id.clone().into(), pagination_args) + .await?; + let order_takes_flattened: Vec = order_takes + .into_iter() + .map(|o| o.try_into()) + .collect::, TryIntoFlattenedError>>()?; - if self.pagination_args.csv { - let csv_text = order_takes_flattened.try_into_csv()?; - println!("{}", csv_text); - } else { - let table = build_table(order_takes_flattened)?; - info!("\n{}", table); - } + if self.pagination_args.csv { + let csv_text = order_takes_flattened.try_into_csv()?; + println!("{}", csv_text); + } else { + let table = build_table(order_takes_flattened)?; + info!("\n{}", table); + } - Ok(()) - } + Ok(()) + } } fn build_table(order_take: Vec) -> Result
{ - let mut table = comfy_table::Table::new(); - table - .load_preset(comfy_table::presets::UTF8_FULL) - .set_content_arrangement(comfy_table::ContentArrangement::Dynamic) - .set_header(vec![ - "ID", - "Taken At", - "Sender", - "Input", - "Output", - "IO Ratio" - ]); + let mut table = comfy_table::Table::new(); + table + .load_preset(comfy_table::presets::UTF8_FULL) + .set_content_arrangement(comfy_table::ContentArrangement::Dynamic) + .set_header(vec![ + "ID", "Taken At", "Sender", "Input", "Output", "IO Ratio", + ]); - for order_take in order_take.into_iter() { - table.add_row(vec![ - order_take.id, - order_take.timestamp_display, - order_take.sender.0, - format!("{} {}", order_take.input_display.0, order_take.input_token_symbol), - format!("{} {}", order_take.output_display.0, order_take.output_token_symbol), - format!("{} {}/{}", order_take.ioratio.0, order_take.input_token_symbol, order_take.output_token_symbol), - ]); - } + for order_take in order_take.into_iter() { + table.add_row(vec![ + order_take.id, + order_take.timestamp_display, + order_take.sender.0, + format!( + "{} {}", + order_take.input_display.0, order_take.input_token_symbol + ), + format!( + "{} {}", + order_take.output_display.0, order_take.output_token_symbol + ), + format!( + "{} {}/{}", + order_take.ioratio.0, order_take.input_token_symbol, order_take.output_token_symbol + ), + ]); + } - Ok(table) + Ok(table) } diff --git a/crates/cli/src/commands/order/mod.rs b/crates/cli/src/commands/order/mod.rs index 863d9773e..c4f62521a 100644 --- a/crates/cli/src/commands/order/mod.rs +++ b/crates/cli/src/commands/order/mod.rs @@ -1,8 +1,8 @@ mod add; mod detail; mod list; -mod remove; mod list_takes; +mod remove; use crate::execute::Execute; use add::CliOrderAddArgs; @@ -10,8 +10,8 @@ use anyhow::Result; use clap::Parser; use detail::CliOrderDetailArgs; use list::CliOrderListArgs; -use remove::CliOrderRemoveArgs; use list_takes::CliOrderListTakes; +use remove::CliOrderRemoveArgs; #[derive(Parser)] pub enum Order { diff --git a/crates/subgraph/src/client.rs b/crates/subgraph/src/client.rs index b5a51d912..65825f7d4 100644 --- a/crates/subgraph/src/client.rs +++ b/crates/subgraph/src/client.rs @@ -7,6 +7,8 @@ use crate::types::{ order_clears_list::{OrderClearsListQuery, OrderClearsListQueryVariables}, order_detail, order_detail::{OrderDetailQuery, OrderDetailQueryVariables}, + order_takes_list, + order_takes_list::{OrderTakesListQuery, OrderTakesListQueryVariables}, orders_list, orders_list::{OrdersListQuery, OrdersListQueryVariables}, vault_balance_change::VaultBalanceChange, @@ -17,8 +19,6 @@ use crate::types::{ }, vaults_list, vaults_list::{VaultsListQuery, VaultsListQueryVariables}, - order_takes_list, - order_takes_list::{OrderTakesListQuery, OrderTakesListQueryVariables} }; use crate::PageQueryClient; use chrono::NaiveDateTime; diff --git a/crates/subgraph/src/types/flattened.rs b/crates/subgraph/src/types/flattened.rs index 87115d690..dd4fc190a 100644 --- a/crates/subgraph/src/types/flattened.rs +++ b/crates/subgraph/src/types/flattened.rs @@ -1,8 +1,8 @@ use std::num::ParseIntError; use super::{ - order_clears_list, orders_list, vault_balance_change::VaultBalanceChange, - vault_list_balance_changes, vaults_list, order_takes_list, + order_clears_list, order_takes_list, orders_list, vault_balance_change::VaultBalanceChange, + vault_list_balance_changes, vaults_list, }; use crate::utils::format_bigint_timestamp_display; use crate::{csv::TryIntoCsv, utils::FormatTimestampDisplayError}; @@ -205,7 +205,6 @@ impl TryFrom for OrderClearFlattened { impl TryIntoCsv for Vec {} - #[derive(Serialize, Deserialize, Clone)] pub struct OrderTakeFlattened { pub id: String, @@ -221,7 +220,7 @@ pub struct OrderTakeFlattened { pub input_token_symbol: String, pub input_ioindex: order_takes_list::BigInt, pub output: order_takes_list::BigInt, - pub output_display:order_takes_list:: BigDecimal, + pub output_display: order_takes_list::BigDecimal, pub output_token_id: cynic::Id, pub output_token_symbol: String, pub output_ioindex: order_takes_list::BigInt, diff --git a/crates/subgraph/src/types/mod.rs b/crates/subgraph/src/types/mod.rs index 9c710f8a0..96e33246f 100644 --- a/crates/subgraph/src/types/mod.rs +++ b/crates/subgraph/src/types/mod.rs @@ -2,9 +2,9 @@ pub mod flattened; pub mod order_clears_list; pub mod order_detail; pub mod order_detail_traits; +pub mod order_takes_list; pub mod orders_list; pub mod vault_balance_change; pub mod vault_detail; pub mod vault_list_balance_changes; pub mod vaults_list; -pub mod order_takes_list; \ No newline at end of file diff --git a/crates/subgraph/src/types/order_takes_list.rs b/crates/subgraph/src/types/order_takes_list.rs index 915d06d8a..9ccc6bbc7 100644 --- a/crates/subgraph/src/types/order_takes_list.rs +++ b/crates/subgraph/src/types/order_takes_list.rs @@ -191,5 +191,3 @@ pub struct BigInt(pub String); #[derive(cynic::Scalar, Debug, Clone)] pub struct Bytes(pub String); - - From ddac6a42cd47b15a5a9cb6f87cd84a822bf7939f Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Mon, 12 Feb 2024 16:48:52 -0700 Subject: [PATCH 3/6] test: graphql query generation test --- .../subgraph/queries/orderTakesList.graphql | 2 +- crates/subgraph/tests/order_takes_test.rs | 19 ++++++++ ...r_takes_test__vaults_query_gql_output.snap | 46 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 crates/subgraph/tests/order_takes_test.rs create mode 100644 crates/subgraph/tests/snapshots/order_takes_test__vaults_query_gql_output.snap diff --git a/crates/subgraph/queries/orderTakesList.graphql b/crates/subgraph/queries/orderTakesList.graphql index 1718e9a31..dd0abbc38 100644 --- a/crates/subgraph/queries/orderTakesList.graphql +++ b/crates/subgraph/queries/orderTakesList.graphql @@ -6,7 +6,7 @@ query OrderTakesListQuery($id: ID!, $skip: Int = 0, $first: Int = 25) { }) { id transaction { - id + id } sender { id diff --git a/crates/subgraph/tests/order_takes_test.rs b/crates/subgraph/tests/order_takes_test.rs new file mode 100644 index 000000000..7c009bd3a --- /dev/null +++ b/crates/subgraph/tests/order_takes_test.rs @@ -0,0 +1,19 @@ +use cynic::Id; +use insta::assert_snapshot; +use rain_orderbook_subgraph_client::types::order_takes_list::{ + OrderTakesListQuery, OrderTakesListQueryVariables, +}; + +#[test] +fn vaults_query_gql_output() { + use cynic::QueryBuilder; + + let id = Id::new("1234"); + let request_body = OrderTakesListQuery::build(OrderTakesListQueryVariables { + id: &id, + skip: Some(0), + first: Some(10), + }); + + assert_snapshot!(request_body.query); +} diff --git a/crates/subgraph/tests/snapshots/order_takes_test__vaults_query_gql_output.snap b/crates/subgraph/tests/snapshots/order_takes_test__vaults_query_gql_output.snap new file mode 100644 index 000000000..535c6b542 --- /dev/null +++ b/crates/subgraph/tests/snapshots/order_takes_test__vaults_query_gql_output.snap @@ -0,0 +1,46 @@ +--- +source: crates/subgraph/tests/order_takes_test.rs +expression: request_body.query +--- +query OrderTakesListQuery($first: Int, $id: ID!, $skip: Int) { + takeOrderEntities(orderBy: timestamp, orderDirection: desc, skip: $skip, first: $first, where: {order_: {id: $id, }, }) { + id + transaction { + id + } + sender { + id + } + timestamp + order { + id + } + IORatio + input + inputDisplay + inputToken { + id + name + symbol + decimals + } + inputIOIndex + output + outputDisplay + outputToken { + id + name + symbol + decimals + } + outputIOIndex + context { + callingContext + calculationsContext + vaultInputsContext + vaultOutputsContext + } + } +} + + From 39d21c5ae8163fda66d920ca73fc7fb0273daf64 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Mon, 12 Feb 2024 16:50:00 -0700 Subject: [PATCH 4/6] doc: type generation for query --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2a409cdca..3bf71cbc3 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/ cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/ordersList.graphql > crates/subgraph/src/types/orders_list.rs cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/vaultBalanceChangesList.graphql > crates/subgraph/src/types/vault_list_balance_changes.rs cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/orderClearsList.graphql > crates/subgraph/src/types/order_clears_list.rs +cynic querygen --schema crates/subgraph/schema/orderbook.graphql --query crates/subgraph/queries/orderTakesList.graphql > crates/subgraph/src/types/order_takes_list.rs ``` 2. Prepend each generated types file with the following: From 90c2c6adf6c24d17f5357a38f2516ec9c729548d Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Mon, 12 Feb 2024 17:21:01 -0700 Subject: [PATCH 5/6] refactor(cli): change command to 'order-take list' --- crates/cli/src/commands/mod.rs | 3 ++- crates/cli/src/commands/order/mod.rs | 6 ------ .../list_takes.rs => order_take/list.rs} | 4 ++-- crates/cli/src/commands/order_take/mod.rs | 20 +++++++++++++++++++ crates/cli/src/lib.rs | 6 +++++- 5 files changed, 29 insertions(+), 10 deletions(-) rename crates/cli/src/commands/{order/list_takes.rs => order_take/list.rs} (97%) create mode 100644 crates/cli/src/commands/order_take/mod.rs diff --git a/crates/cli/src/commands/mod.rs b/crates/cli/src/commands/mod.rs index 2aa8e9080..586946b55 100644 --- a/crates/cli/src/commands/mod.rs +++ b/crates/cli/src/commands/mod.rs @@ -1,5 +1,6 @@ mod order; mod order_clear; mod vault; +mod order_take; -pub use self::{order::Order, order_clear::OrderClear, vault::Vault}; +pub use self::{order::Order, order_clear::OrderClear, vault::Vault, order_take::OrderTake}; diff --git a/crates/cli/src/commands/order/mod.rs b/crates/cli/src/commands/order/mod.rs index c4f62521a..7c6730118 100644 --- a/crates/cli/src/commands/order/mod.rs +++ b/crates/cli/src/commands/order/mod.rs @@ -1,7 +1,6 @@ mod add; mod detail; mod list; -mod list_takes; mod remove; use crate::execute::Execute; @@ -10,7 +9,6 @@ use anyhow::Result; use clap::Parser; use detail::CliOrderDetailArgs; use list::CliOrderListArgs; -use list_takes::CliOrderListTakes; use remove::CliOrderRemoveArgs; #[derive(Parser)] @@ -26,9 +24,6 @@ pub enum Order { #[command(about = "Remove an Order", alias = "rm")] Remove(CliOrderRemoveArgs), - - #[command(about = "List takes for an Order", alias = "ls-takes")] - ListTakes(CliOrderListTakes), } impl Execute for Order { @@ -38,7 +33,6 @@ impl Execute for Order { Order::Detail(detail) => detail.execute().await, Order::Create(create) => create.execute().await, Order::Remove(remove) => remove.execute().await, - Order::ListTakes(list_takes) => list_takes.execute().await, } } } diff --git a/crates/cli/src/commands/order/list_takes.rs b/crates/cli/src/commands/order_take/list.rs similarity index 97% rename from crates/cli/src/commands/order/list_takes.rs rename to crates/cli/src/commands/order_take/list.rs index 0d9b6a9f0..71dea7574 100644 --- a/crates/cli/src/commands/order/list_takes.rs +++ b/crates/cli/src/commands/order_take/list.rs @@ -13,7 +13,7 @@ use rain_orderbook_subgraph_client::{ use tracing::info; #[derive(Args, Clone)] -pub struct CliOrderListTakes { +pub struct CliOrderTakesListArgs { #[arg(short = 'i', long, help = "ID of the Order")] order_id: String, @@ -24,7 +24,7 @@ pub struct CliOrderListTakes { subgraph_args: CliSubgraphArgs, } -impl Execute for CliOrderListTakes { +impl Execute for CliOrderTakesListArgs { async fn execute(&self) -> Result<()> { let subgraph_args: SubgraphArgs = self.subgraph_args.clone().into(); let pagination_args: PaginationArgs = self.pagination_args.clone().into(); diff --git a/crates/cli/src/commands/order_take/mod.rs b/crates/cli/src/commands/order_take/mod.rs new file mode 100644 index 000000000..0a3448e1a --- /dev/null +++ b/crates/cli/src/commands/order_take/mod.rs @@ -0,0 +1,20 @@ +mod list; + +use crate::execute::Execute; +use anyhow::Result; +use clap::Parser; +use list::CliOrderTakesListArgs; + +#[derive(Parser)] +pub enum OrderTake { + #[command(about = "List takes for an Order", alias = "ls")] + List(CliOrderTakesListArgs), +} + +impl Execute for OrderTake { + async fn execute(&self) -> Result<()> { + match self { + OrderTake::List(list) => list.execute().await, + } + } +} diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index c64fe1a09..c5982f00c 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -1,4 +1,4 @@ -use crate::commands::{Order, OrderClear, Vault}; +use crate::commands::{Order, OrderClear, Vault, OrderTake}; use crate::execute::Execute; use anyhow::Result; use clap::Subcommand; @@ -19,6 +19,9 @@ pub enum Orderbook { #[command(subcommand)] OrderClear(OrderClear), + + #[command(subcommand)] + OrderTake(OrderTake), } impl Orderbook { @@ -27,6 +30,7 @@ impl Orderbook { Orderbook::Order(order) => order.execute().await, Orderbook::Vault(vault) => (*vault).execute().await, Orderbook::OrderClear(order_clear) => (order_clear).execute().await, + Orderbook::OrderTake(order_take) => (order_take).execute().await, } } } From 75ade5e76b78cb5d9d80315248e40ffddcb3c831 Mon Sep 17 00:00:00 2001 From: Matt Gabrenya Date: Mon, 12 Feb 2024 17:23:27 -0700 Subject: [PATCH 6/6] chore: fmt +clippy --- crates/cli/src/commands/mod.rs | 4 ++-- crates/cli/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/cli/src/commands/mod.rs b/crates/cli/src/commands/mod.rs index 586946b55..11a1afd7e 100644 --- a/crates/cli/src/commands/mod.rs +++ b/crates/cli/src/commands/mod.rs @@ -1,6 +1,6 @@ mod order; mod order_clear; -mod vault; mod order_take; +mod vault; -pub use self::{order::Order, order_clear::OrderClear, vault::Vault, order_take::OrderTake}; +pub use self::{order::Order, order_clear::OrderClear, order_take::OrderTake, vault::Vault}; diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index c5982f00c..218d49611 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -1,4 +1,4 @@ -use crate::commands::{Order, OrderClear, Vault, OrderTake}; +use crate::commands::{Order, OrderClear, OrderTake, Vault}; use crate::execute::Execute; use anyhow::Result; use clap::Subcommand;