diff --git a/crates/cli/src/commands/order/detail.rs b/crates/cli/src/commands/order/detail.rs index 220eb33a4..77719c3df 100644 --- a/crates/cli/src/commands/order/detail.rs +++ b/crates/cli/src/commands/order/detail.rs @@ -136,6 +136,7 @@ mod tests { "from": encode_prefixed(alloy::primitives::Address::random()) } }], + "trades": [] } } }) diff --git a/crates/cli/src/commands/order/list.rs b/crates/cli/src/commands/order/list.rs index 0333508ea..7c202baa8 100644 --- a/crates/cli/src/commands/order/list.rs +++ b/crates/cli/src/commands/order/list.rs @@ -8,7 +8,7 @@ use comfy_table::Table; use rain_orderbook_common::{ csv::TryIntoCsv, subgraph::SubgraphArgs, - types::{FlattenError, OrderFlattened}, + types::{FlattenError, OrderFlattened, LIST_DELIMITER}, }; use tracing::info; @@ -73,6 +73,7 @@ fn build_table(orders: Vec) -> Result { "Owner", "Input Tokens", "Output Tokens", + "Trades", ]); for order in orders.into_iter() { @@ -83,6 +84,12 @@ fn build_table(orders: Vec) -> Result
{ order.owner.0, order.valid_inputs_token_symbols_display, order.valid_outputs_token_symbols_display, + order + .trades + .split(LIST_DELIMITER) + .collect::>() + .len() + .to_string(), ]); } @@ -251,6 +258,7 @@ mod tests { "from": encode_prefixed(alloy::primitives::Address::random()) } }], + "trades": [] }] } }) diff --git a/crates/common/src/types/orders_list_flattened.rs b/crates/common/src/types/orders_list_flattened.rs index 789cd3b3c..3d9cff5fe 100644 --- a/crates/common/src/types/orders_list_flattened.rs +++ b/crates/common/src/types/orders_list_flattened.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use super::FlattenError; -const LIST_DELIMITER: &str = ", "; +pub const LIST_DELIMITER: &str = ", "; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct OrderFlattened { @@ -24,6 +24,7 @@ pub struct OrderFlattened { pub valid_outputs_vaults: String, pub valid_inputs_token_symbols_display: String, pub valid_outputs_token_symbols_display: String, + pub trades: String, } impl TryFrom for OrderFlattened { @@ -66,6 +67,12 @@ impl TryFrom for OrderFlattened { .map(|vault| vault.token.symbol.unwrap_or(NO_SYMBOL.into())) .collect::>() .join(LIST_DELIMITER), + trades: val + .trades + .into_iter() + .map(|trade| trade.id.0) + .collect::>() + .join(LIST_DELIMITER), }) } } diff --git a/crates/quote/src/cli/mod.rs b/crates/quote/src/cli/mod.rs index eb62fe4b9..71676932b 100644 --- a/crates/quote/src/cli/mod.rs +++ b/crates/quote/src/cli/mod.rs @@ -372,6 +372,7 @@ mod tests { }], "meta": null, "timestampAdded": "0", + "trades": [] }] } }); diff --git a/crates/quote/src/quote.rs b/crates/quote/src/quote.rs index 5d642bd18..4c041ae79 100644 --- a/crates/quote/src/quote.rs +++ b/crates/quote/src/quote.rs @@ -408,6 +408,7 @@ mod tests { }], "meta": null, "timestampAdded": "0", + "trades": [] }); let retrun_sg_data = if batch { json!({ diff --git a/crates/subgraph/queries/ordersList.graphql b/crates/subgraph/queries/ordersList.graphql index 47901c884..894491b34 100644 --- a/crates/subgraph/queries/ordersList.graphql +++ b/crates/subgraph/queries/ordersList.graphql @@ -36,5 +36,8 @@ query OrdersListQuery($skip: Int = 0, $first: Int = 25) { timestamp } } + trades(first: 1) { + id + } } } \ No newline at end of file diff --git a/crates/subgraph/src/orderbook_client.rs b/crates/subgraph/src/orderbook_client.rs index cc8a18a97..872540e9c 100644 --- a/crates/subgraph/src/orderbook_client.rs +++ b/crates/subgraph/src/orderbook_client.rs @@ -92,6 +92,7 @@ impl OrderbookSubgraphClient { let data = self .query::(variables) .await?; + Ok(data.orders) } diff --git a/crates/subgraph/src/types/common.rs b/crates/subgraph/src/types/common.rs index 8aa75ee79..db8bf3372 100644 --- a/crates/subgraph/src/types/common.rs +++ b/crates/subgraph/src/types/common.rs @@ -72,6 +72,16 @@ pub struct Order { pub timestamp_added: BigInt, pub meta: Option, pub add_events: Vec, + pub trades: Vec, +} + +#[derive(cynic::QueryFragment, Debug, Serialize, Clone)] +#[cynic(graphql_type = "Order")] +#[serde(rename_all = "camelCase")] +#[typeshare] +pub struct TradeStructPartialOrder { + pub id: Bytes, + pub order_hash: Bytes, } #[derive(cynic::QueryFragment, Debug, Serialize, Clone)] @@ -215,12 +225,19 @@ pub struct Trade { pub id: Bytes, pub trade_event: TradeEvent, pub output_vault_balance_change: TradeVaultBalanceChange, - pub order: Order, + pub order: TradeStructPartialOrder, pub input_vault_balance_change: TradeVaultBalanceChange, pub timestamp: BigInt, pub orderbook: Orderbook, } +#[derive(cynic::QueryFragment, Debug, Clone, Serialize)] +#[cynic(graphql_type = "Trade")] +#[typeshare] +pub struct OrderStructPartialTrade { + pub id: Bytes, +} + #[derive(cynic::QueryFragment, Debug, Serialize, Clone)] #[cynic(graphql_type = "ERC20")] #[typeshare] diff --git a/crates/subgraph/src/types/order_detail_traits.rs b/crates/subgraph/src/types/order_detail_traits.rs index cc542aee6..b9f375706 100644 --- a/crates/subgraph/src/types/order_detail_traits.rs +++ b/crates/subgraph/src/types/order_detail_traits.rs @@ -86,6 +86,7 @@ mod tests { }, // Only the order_bytes field is used for the conversion order_bytes: Bytes("0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000006171c21b2e553c59a64d1337211b77c367cefe5d00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000379b966dc6b117dd47b5fc5308534256a4ab1bcc0000000000000000000000006e4b01603edbda617002a077420e98c86595748e000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000950000000000000000000000000000000000000000000000000000000000000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000b1a2bc2ec5000000000000000000000000000000000000000000000000000000000000000000015020000000c020200020110000001100001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000050c5725949a6f0c72e6c4a641f24049a917db0cb000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda0291300000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000001".into()), + trades: vec![] }; let order_v3: OrderV3 = order_detail.try_into().unwrap(); diff --git a/crates/subgraph/tests/snapshots/batch_order_test__batch_order_query_gql_output.snap b/crates/subgraph/tests/snapshots/batch_order_test__batch_order_query_gql_output.snap index 75ccd9a36..37a91776a 100644 --- a/crates/subgraph/tests/snapshots/batch_order_test__batch_order_query_gql_output.snap +++ b/crates/subgraph/tests/snapshots/batch_order_test__batch_order_query_gql_output.snap @@ -242,5 +242,8 @@ query BatchOrderDetailQuery($id_list: Order_filter!) { timestamp } } + trades { + id + } } } diff --git a/crates/subgraph/tests/snapshots/order_take_test__vaults_query_gql_output.snap b/crates/subgraph/tests/snapshots/order_take_test__vaults_query_gql_output.snap index 611552e9c..d82c6bb1a 100644 --- a/crates/subgraph/tests/snapshots/order_take_test__vaults_query_gql_output.snap +++ b/crates/subgraph/tests/snapshots/order_take_test__vaults_query_gql_output.snap @@ -43,243 +43,7 @@ query OrderTakeDetailQuery($id: ID!) { } order { id - orderBytes orderHash - owner - outputs { - id - owner - vaultId - balance - token { - id - address - name - symbol - decimals - } - orderbook { - id - } - ordersAsOutput { - id - orderHash - active - } - ordersAsInput { - id - orderHash - active - } - balanceChanges { - __typename - ... on Withdrawal { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - ... on TradeVaultBalanceChange { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - ... on Deposit { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - } - } - inputs { - id - owner - vaultId - balance - token { - id - address - name - symbol - decimals - } - orderbook { - id - } - ordersAsOutput { - id - orderHash - active - } - ordersAsInput { - id - orderHash - active - } - balanceChanges { - __typename - ... on Withdrawal { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - ... on TradeVaultBalanceChange { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - ... on Deposit { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - } - } - orderbook { - id - } - active - timestampAdded - meta - addEvents { - transaction { - id - from - blockNumber - timestamp - } - } } inputVaultBalanceChange { id 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 index 90c32d10d..986db96a7 100644 --- 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 @@ -43,243 +43,7 @@ query OrderTakesListQuery($first: Int, $id: Bytes!, $skip: Int) { } order { id - orderBytes orderHash - owner - outputs { - id - owner - vaultId - balance - token { - id - address - name - symbol - decimals - } - orderbook { - id - } - ordersAsOutput { - id - orderHash - active - } - ordersAsInput { - id - orderHash - active - } - balanceChanges { - __typename - ... on Withdrawal { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - ... on TradeVaultBalanceChange { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - ... on Deposit { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - } - } - inputs { - id - owner - vaultId - balance - token { - id - address - name - symbol - decimals - } - orderbook { - id - } - ordersAsOutput { - id - orderHash - active - } - ordersAsInput { - id - orderHash - active - } - balanceChanges { - __typename - ... on Withdrawal { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - ... on TradeVaultBalanceChange { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - ... on Deposit { - id - __typename - amount - newVaultBalance - oldVaultBalance - vault { - id - token { - id - address - name - symbol - decimals - } - } - timestamp - transaction { - id - from - blockNumber - timestamp - } - orderbook { - id - } - } - } - } - orderbook { - id - } - active - timestampAdded - meta - addEvents { - transaction { - id - from - blockNumber - timestamp - } - } } inputVaultBalanceChange { id diff --git a/crates/subgraph/tests/snapshots/order_test__orders_query_gql_output.snap b/crates/subgraph/tests/snapshots/order_test__orders_query_gql_output.snap index 14bfc02d7..45e878e8d 100644 --- a/crates/subgraph/tests/snapshots/order_test__orders_query_gql_output.snap +++ b/crates/subgraph/tests/snapshots/order_test__orders_query_gql_output.snap @@ -242,5 +242,8 @@ query OrderDetailQuery($id: ID!) { timestamp } } + trades { + id + } } } diff --git a/crates/subgraph/tests/snapshots/orders_test__orders_query_gql_output.snap b/crates/subgraph/tests/snapshots/orders_test__orders_query_gql_output.snap index 80caa4527..7a089004d 100644 --- a/crates/subgraph/tests/snapshots/orders_test__orders_query_gql_output.snap +++ b/crates/subgraph/tests/snapshots/orders_test__orders_query_gql_output.snap @@ -242,5 +242,8 @@ query OrdersListQuery($first: Int, $skip: Int, $filters: Order_filter) { timestamp } } + trades { + id + } } } diff --git a/tauri-app/src-tauri/src/commands/order_quote.rs b/tauri-app/src-tauri/src/commands/order_quote.rs index f0c6a4dcc..b6f2eb356 100644 --- a/tauri-app/src-tauri/src/commands/order_quote.rs +++ b/tauri-app/src-tauri/src/commands/order_quote.rs @@ -261,6 +261,7 @@ amount price: 16 52; add_events: vec![], meta: None, timestamp_added: BigInt(0.to_string()), + trades: vec![] }; let input_io_index = 0; @@ -427,6 +428,7 @@ amount price: 16 52; add_events: vec![], meta: None, timestamp_added: BigInt(0.to_string()), + trades: vec![] }; let rpc_url = local_evm.url(); diff --git a/tauri-app/src/lib/components/modal/ModalQuoteDebug.test.ts b/tauri-app/src/lib/components/modal/ModalQuoteDebug.test.ts index df9febd45..1a5e628cc 100644 --- a/tauri-app/src/lib/components/modal/ModalQuoteDebug.test.ts +++ b/tauri-app/src/lib/components/modal/ModalQuoteDebug.test.ts @@ -31,6 +31,7 @@ test('renders table with the correct data', async () => { active: true, addEvents: [], timestampAdded: '123', + trades: [], }, rpcUrl: 'https://rpc-url.com', inputIOIndex: 0, diff --git a/tauri-app/src/lib/components/tables/OrderTradesListTable.test.ts b/tauri-app/src/lib/components/tables/OrderTradesListTable.test.ts index 7978ed10a..673e460ff 100644 --- a/tauri-app/src/lib/components/tables/OrderTradesListTable.test.ts +++ b/tauri-app/src/lib/components/tables/OrderTradesListTable.test.ts @@ -73,17 +73,6 @@ const mockTakeOrdersList: Trade[] = [ order: { id: 'order_id', orderHash: 'orderHash', - timestampAdded: '1632000000', - orderBytes: '0x123456', - owner: '0x1111111111111111111111111111111111111111', - outputs: [], - inputs: [], - active: true, - addEvents: [], - meta: 'metadata1', - orderbook: { - id: '0x00', - }, }, inputVaultBalanceChange: { vault: { @@ -154,17 +143,6 @@ const mockTakeOrdersList: Trade[] = [ order: { id: 'order_id', orderHash: 'orderHash', - timestampAdded: '1632000000', - orderBytes: '0x123456', - owner: '0x1111111111111111111111111111111111111111', - outputs: [], - inputs: [], - active: true, - addEvents: [], - meta: 'metadata1', - orderbook: { - id: '0x00', - }, }, inputVaultBalanceChange: { vault: { diff --git a/tauri-app/src/lib/components/tables/OrdersListTable.svelte b/tauri-app/src/lib/components/tables/OrdersListTable.svelte index d1b412f6c..6e234abd7 100644 --- a/tauri-app/src/lib/components/tables/OrdersListTable.svelte +++ b/tauri-app/src/lib/components/tables/OrdersListTable.svelte @@ -71,6 +71,7 @@ Output Token(s) + Trades @@ -82,15 +83,15 @@ Inactive {/if} - - - + + + + + + + + + {formatTimestampSecondsAsLocal(BigInt(item.timestampAdded))} @@ -100,6 +101,9 @@ {item.outputs?.map((t) => t.token.symbol)} + {item.trades.length > 99 ? '>99' : item.trades.length} {#if $walletAddressMatchesOrBlank(item.owner) && item.active}