Skip to content

Commit

Permalink
Merge branch 'main' into 2025-02-18-rm-typeshare
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt authored Feb 19, 2025
2 parents 8dc14df + c89463b commit 2dbc449
Show file tree
Hide file tree
Showing 28 changed files with 378 additions and 30 deletions.
3 changes: 2 additions & 1 deletion crates/cli/src/commands/order/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ mod tests {
"from": encode_prefixed(alloy::primitives::Address::random())
}
}],
"trades": []
"trades": [],
"removeEvents": []
}
}
})
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/commands/order/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ mod tests {
"from": encode_prefixed(alloy::primitives::Address::random())
}
}],
"trades": []
"trades": [],
"removeEvents": []
}]
}
})
Expand Down
1 change: 1 addition & 0 deletions crates/js_api/src/subgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use wasm_bindgen_utils::prelude::*;

pub mod add_order;
pub mod order;
pub mod remove_order;
pub mod transaction;
pub mod vault;

Expand Down
16 changes: 16 additions & 0 deletions crates/js_api/src/subgraph/remove_order.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use cynic::Id;
use rain_orderbook_bindings::wasm_traits::prelude::*;
use rain_orderbook_subgraph_client::{OrderbookSubgraphClient, OrderbookSubgraphClientError};
use reqwest::Url;

/// Internal function to fetch Remove Orders for a given transaction
/// Returns an array of RemoveOrder structs
#[wasm_bindgen(js_name = "getTransactionRemoveOrders")]
pub async fn get_transaction_remove_orders(
url: &str,
tx_hash: &str,
) -> Result<JsValue, OrderbookSubgraphClientError> {
let client = OrderbookSubgraphClient::new(Url::parse(url)?);
let remove_orders = client.transaction_remove_orders(Id::new(tx_hash)).await?;
Ok(to_value(&remove_orders)?)
}
3 changes: 2 additions & 1 deletion crates/quote/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ mod tests {
}],
"meta": null,
"timestampAdded": "0",
"trades": []
"trades": [],
"removeEvents": []
}]
}
});
Expand Down
1 change: 1 addition & 0 deletions crates/quote/src/order_quotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ amount price: context<3 0>() context<4 0>();
meta: None,
timestamp_added: SgBigInt(0.to_string()),
trades: vec![],
remove_events: vec![],
};

let result = get_order_quotes(vec![order], None, local_evm.url(), None)
Expand Down
3 changes: 2 additions & 1 deletion crates/quote/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ mod tests {
}],
"meta": null,
"timestampAdded": "0",
"trades": []
"trades": [],
"removeEvents": []
});
let retrun_sg_data = if batch {
json!({
Expand Down
21 changes: 21 additions & 0 deletions crates/subgraph/src/orderbook_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::types::order::{
use crate::types::order_trade::{SgOrderTradeDetailQuery, SgOrderTradesListQuery};
use crate::types::transaction::SgTransactionDetailQuery;
use crate::types::vault::{SgVaultDetailQuery, SgVaultsListQuery};
use crate::types::remove_order::{TransactionRemoveOrdersQuery, TransactionRemoveOrdersVariables};
use crate::vault_balance_changes_query::VaultBalanceChangesListPageQueryClient;
use cynic::Id;
use reqwest::Url;
Expand Down Expand Up @@ -420,4 +421,24 @@ impl OrderbookSubgraphClient {

Ok(data.add_orders)
}

/// Fetch all remove orders for a given transaction
pub async fn transaction_remove_orders(
&self,
id: Id,
) -> Result<Vec<RemoveOrderWithOrder>, OrderbookSubgraphClientError> {
let data = self
.query::<TransactionRemoveOrdersQuery, TransactionRemoveOrdersVariables>(
TransactionRemoveOrdersVariables {
id: Bytes(id.inner().to_string()),
},
)
.await?;

if data.remove_orders.is_empty() {
return Err(OrderbookSubgraphClientError::Empty);
}

Ok(data.remove_orders)
}
}
1 change: 1 addition & 0 deletions crates/subgraph/src/performance/order_performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ mod test {
meta: None,
add_events: vec![],
trades: vec![],
remove_events: vec![],
}
}

Expand Down
16 changes: 16 additions & 0 deletions crates/subgraph/src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub struct SgOrder {
pub meta: Option<SgRainMetaV1>,
pub add_events: Vec<SgAddOrder>,
pub trades: Vec<SgOrderStructPartialTrade>,
pub remove_events: Vec<RemoveOrder>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -363,6 +364,12 @@ pub struct SgTransaction {
pub struct SgAddOrder {
pub transaction: SgTransaction,
}
#[derive(cynic::QueryFragment, Debug, Serialize, Clone)]
#[cfg_attr(target_family = "wasm", derive(Tsify))]
#[typeshare]
pub struct RemoveOrder {
pub transaction: Transaction,
}

#[derive(cynic::QueryFragment, Debug, Serialize, Clone)]
#[cfg_attr(target_family = "wasm", derive(Tsify))]
Expand All @@ -372,6 +379,15 @@ pub struct SgAddOrderWithOrder {
pub order: SgOrder,
}

#[derive(cynic::QueryFragment, Debug, Serialize, Clone)]
#[cfg_attr(target_family = "wasm", derive(Tsify))]
#[cynic(graphql_type = "RemoveOrder")]
pub struct RemoveOrderWithOrder {
pub transaction: Transaction,
#[cfg_attr(target_family = "wasm", tsify(type = "OrderSubgraph"))]
pub order: Order,
}

#[derive(cynic::Scalar, Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(target_family = "wasm", derive(Tsify))]
#[cynic(graphql_type = "BigInt")]
Expand Down
1 change: 1 addition & 0 deletions crates/subgraph/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod impls;
pub mod order;
pub mod order_detail_traits;
pub mod order_trade;
pub mod remove_order;
pub mod transaction;
pub mod vault;

Expand Down
3 changes: 2 additions & 1 deletion crates/subgraph/src/types/order_detail_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ mod tests {
},
// Only the order_bytes field is used for the conversion
order_bytes: SgBytes("0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000006171c21b2e553c59a64d1337211b77c367cefe5d00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000379b966dc6b117dd47b5fc5308534256a4ab1bcc0000000000000000000000006e4b01603edbda617002a077420e98c86595748e000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000950000000000000000000000000000000000000000000000000000000000000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000b1a2bc2ec5000000000000000000000000000000000000000000000000000000000000000000015020000000c020200020110000001100001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000050c5725949a6f0c72e6c4a641f24049a917db0cb000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda0291300000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000001".into()),
trades: vec![]
trades: vec![],
remove_events: vec![],
};

let order_v3: OrderV3 = order_detail.try_into().unwrap();
Expand Down
16 changes: 16 additions & 0 deletions crates/subgraph/src/types/remove_order.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use super::common::{Bytes, RemoveOrderWithOrder};
use crate::schema;
use typeshare::typeshare;

#[derive(cynic::QueryVariables, Debug)]
pub struct TransactionRemoveOrdersVariables {
pub id: Bytes,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Query", variables = "TransactionRemoveOrdersVariables")]
#[typeshare]
pub struct TransactionRemoveOrdersQuery {
#[arguments(where: { transaction_: { id: $id } })]
pub remove_orders: Vec<RemoveOrderWithOrder>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,13 @@ query SgBatchOrderDetailQuery($id_list: Order_filter!) {
trades {
id
}
removeEvents {
transaction {
id
from
blockNumber
timestamp
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/subgraph/tests/order_test.rs
assertion_line: 13
expression: request_body.query
---
query SgOrderDetailQuery($id: ID!) {
Expand Down Expand Up @@ -309,5 +310,13 @@ query SgOrderDetailQuery($id: ID!) {
trades {
id
}
removeEvents {
transaction {
id
from
blockNumber
timestamp
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/subgraph/tests/orders_test.rs
assertion_line: 15
expression: request_body.query
---
query SgOrdersListQuery($first: Int, $skip: Int, $filters: Order_filter) {
Expand Down Expand Up @@ -309,5 +310,13 @@ query SgOrdersListQuery($first: Int, $skip: Int, $filters: Order_filter) {
trades {
id
}
removeEvents {
transaction {
id
from
blockNumber
timestamp
}
}
}
}
3 changes: 2 additions & 1 deletion packages/orderbook/test/js_api/addOrder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ const mockAddOrder: SgAddOrderWithOrder = {
}
}
],
trades: []
trades: [],
removeEvents: []
}
};

Expand Down
9 changes: 6 additions & 3 deletions packages/orderbook/test/js_api/order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ const order1: SgOrder = {
orderbook: {
id: '0x0000000000000000000000000000000000000000'
},
trades: []
trades: [],
removeEvents: []
} as unknown as SgOrder;

const order2 = {
Expand Down Expand Up @@ -148,7 +149,8 @@ const order2 = {
orderbook: {
id: '0x0000000000000000000000000000000000000000'
},
trades: []
trades: [],
removeEvents: []
} as unknown as SgOrder;

export const order3 = {
Expand Down Expand Up @@ -215,7 +217,8 @@ export const order3 = {
orderbook: {
id: '0x0000000000000000000000000000000000000000'
},
trades: []
trades: [],
removeEvents: []
} as unknown as SgOrder;

const mockOrderTradesList: SgTrade[] = [
Expand Down
Loading

0 comments on commit 2dbc449

Please sign in to comment.