Skip to content

Commit

Permalink
Merge pull request #844 from rainlanguage/2024-09-09-order-trade-count
Browse files Browse the repository at this point in the history
Order trade count
  • Loading branch information
hardyjosh authored Sep 10, 2024
2 parents 112c8bc + cc999d8 commit 1c56209
Show file tree
Hide file tree
Showing 23 changed files with 107 additions and 605 deletions.
1 change: 1 addition & 0 deletions crates/cli/src/commands/order/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ mod tests {
"from": encode_prefixed(alloy::primitives::Address::random())
}
}],
"trades": []
}
}
})
Expand Down
10 changes: 9 additions & 1 deletion crates/cli/src/commands/order/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -73,6 +73,7 @@ fn build_table(orders: Vec<OrderFlattened>) -> Result<Table> {
"Owner",
"Input Tokens",
"Output Tokens",
"Trades",
]);

for order in orders.into_iter() {
Expand All @@ -83,6 +84,12 @@ fn build_table(orders: Vec<OrderFlattened>) -> Result<Table> {
order.owner.0,
order.valid_inputs_token_symbols_display,
order.valid_outputs_token_symbols_display,
order
.trades
.split(LIST_DELIMITER)
.collect::<Vec<&str>>()
.len()
.to_string(),
]);
}

Expand Down Expand Up @@ -251,6 +258,7 @@ mod tests {
"from": encode_prefixed(alloy::primitives::Address::random())
}
}],
"trades": []
}]
}
})
Expand Down
9 changes: 8 additions & 1 deletion crates/common/src/types/orders_list_flattened.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Order> for OrderFlattened {
Expand Down Expand Up @@ -66,6 +67,12 @@ impl TryFrom<Order> for OrderFlattened {
.map(|vault| vault.token.symbol.unwrap_or(NO_SYMBOL.into()))
.collect::<Vec<String>>()
.join(LIST_DELIMITER),
trades: val
.trades
.into_iter()
.map(|trade| trade.id.0)
.collect::<Vec<String>>()
.join(LIST_DELIMITER),
})
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/quote/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ mod tests {
}],
"meta": null,
"timestampAdded": "0",
"trades": []
}]
}
});
Expand Down
1 change: 1 addition & 0 deletions crates/quote/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ mod tests {
}],
"meta": null,
"timestampAdded": "0",
"trades": []
});
let retrun_sg_data = if batch {
json!({
Expand Down
3 changes: 3 additions & 0 deletions crates/subgraph/queries/ordersList.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ query OrdersListQuery($skip: Int = 0, $first: Int = 25) {
timestamp
}
}
trades(first: 1) {
id
}
}
}
1 change: 1 addition & 0 deletions crates/subgraph/src/orderbook_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl OrderbookSubgraphClient {
let data = self
.query::<OrdersListQuery, OrdersListQueryVariables>(variables)
.await?;

Ok(data.orders)
}

Expand Down
19 changes: 18 additions & 1 deletion crates/subgraph/src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ pub struct Order {
pub timestamp_added: BigInt,
pub meta: Option<RainMetaV1>,
pub add_events: Vec<AddOrder>,
pub trades: Vec<OrderStructPartialTrade>,
}

#[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)]
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions crates/subgraph/src/types/order_detail_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,8 @@ query BatchOrderDetailQuery($id_list: Order_filter!) {
timestamp
}
}
trades {
id
}
}
}
Loading

0 comments on commit 1c56209

Please sign in to comment.