Skip to content

Commit

Permalink
feat: add wasm binding for get_order_quote
Browse files Browse the repository at this point in the history
  • Loading branch information
findolor committed Oct 23, 2024
1 parent 1a87fee commit d4555be
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions crates/quote/src/js_api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use crate::{error::Error, BatchQuoteSpec as MainBatchQuoteSpec, QuoteSpec as MainQuoteSpec};
use crate::{BatchQuoteTarget as MainBatchQuoteTarget, QuoteTarget as MainQuoteTarget};
use crate::{
get_order_quotes, BatchQuoteTarget as MainBatchQuoteTarget, QuoteTarget as MainQuoteTarget,
};
use alloy::primitives::{
hex::{encode_prefixed, FromHex},
Address, U256,
};
use rain_orderbook_bindings::js_api::{Quote, SignedContextV1};
use rain_orderbook_subgraph_client::utils::make_order_id;
use rain_orderbook_subgraph_client::{types::common::Order, utils::make_order_id};
use serde::{Deserialize, Serialize};
use serde_wasm_bindgen::to_value;
use std::str::FromStr;
Expand Down Expand Up @@ -175,3 +177,18 @@ pub async fn get_batch_quote_target_from_subgraph(
)?),
}
}

#[derive(Debug, Clone, Serialize, Deserialize, Tsify)]
#[serde(transparent)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct WasmOrder(pub Order);

#[wasm_bindgen(js_name = "getOrderQuote")]
pub async fn get_order_quote(
order: WasmOrder,
rpc_url: String,
block_number: Option<u64>,
) -> Result<JsValue, Error> {
let result = get_order_quotes(vec![order.0], block_number, rpc_url).await?;
Ok(to_value(&result)?)
}

0 comments on commit d4555be

Please sign in to comment.