Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod erc20;
pub mod fuzz;
pub mod local_db;
pub mod meta;
pub mod oracle;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's find and examine the oracle module
fd -t f oracle.rs crates/common/src

Repository: rainlanguage/rain.orderbook

Length of output: 98


🏁 Script executed:

# Check the main Cargo.toml for reqwest configuration
cat crates/common/Cargo.toml

Repository: rainlanguage/rain.orderbook

Length of output: 2576


🏁 Script executed:

# Look for WASM-related build configurations
rg "wasm" --include="*.toml" --include="*.yml" --include="*.yaml" | head -50

Repository: rainlanguage/rain.orderbook

Length of output: 512


🏁 Script executed:

# Read the oracle.rs file to see what it uses
cat -n crates/common/src/oracle.rs

Repository: rainlanguage/rain.orderbook

Length of output: 4308


🏁 Script executed:

# Check workspace Cargo.toml for reqwest configuration
fd -t f Cargo.toml | head -5 | xargs grep -l "reqwest" | head -1 | xargs cat | grep -A 10 -B 2 "reqwest"

Repository: rainlanguage/rain.orderbook

Length of output: 427


🏁 Script executed:

# Search for WASM builds in CI/github workflows
fd "\.yml\|\.yaml" .github/workflows --exec grep -l "wasm" {} \; 2>/dev/null || echo "No wasm in workflows"

Repository: rainlanguage/rain.orderbook

Length of output: 53


🏁 Script executed:

# Check the full lib.rs to see what's exported and how oracle fits
cat -n crates/common/src/lib.rs

Repository: rainlanguage/rain.orderbook

Length of output: 972


🏁 Script executed:

# Search for uses of oracle module
rg "oracle" crates/common/src --type rs -n

Repository: rainlanguage/rain.orderbook

Length of output: 97


🏁 Script executed:

# Check if there are any WASM-specific build targets or configurations
rg "cdylib\|wasm" Cargo.toml crates/*/Cargo.toml -A 2 -B 2

Repository: rainlanguage/rain.orderbook

Length of output: 53


🏁 Script executed:

# Search oracle usage with correct syntax
rg "oracle" crates/common/src -n

Repository: rainlanguage/rain.orderbook

Length of output: 5667


🏁 Script executed:

# Check raindex_client to see if other non-guarded modules use wasm-incompatible features
head -50 crates/common/src/raindex_client/mod.rs

Repository: rainlanguage/rain.orderbook

Length of output: 1634


🏁 Script executed:

# Search for actual WASM compilation or build targets
fd Cargo.toml | xargs grep -l "wasm32"

Repository: rainlanguage/rain.orderbook

Length of output: 55


🏁 Script executed:

# Check what features are actually used when building
rg "wasm_bindgen" crates/common/src --type-list

Repository: rainlanguage/rain.orderbook

Length of output: 460


🏁 Script executed:

# Check if the functions that call oracle are exposed/used by WASM
rg "fetch_oracle_for_order|fetch_signed_context" crates/common/src/take_orders/candidates.rs -B 5 -A 5

Repository: rainlanguage/rain.orderbook

Length of output: 1272


🏁 Script executed:

# Check if these WASM-exposed raindex_client functions actually call oracle code
rg "pub async fn|pub fn" crates/common/src/raindex_client/order_quotes.rs | head -20

Repository: rainlanguage/rain.orderbook

Length of output: 242


🏁 Script executed:

# See if there's any cfg guard around the actual reqwest usage in oracle
rg "Client::builder|timeout" crates/common/src/oracle.rs -B 5 -A 5

Repository: rainlanguage/rain.orderbook

Length of output: 526


🏁 Script executed:

# Check if take_orders is part of WASM-exposed APIs
rg "take_orders" crates/common/src/raindex_client/mod.rs

Repository: rainlanguage/rain.orderbook

Length of output: 91


🏁 Script executed:

# Check if there are any WASM build tests or targets
rg "wasm32\|wasm_bindgen_test" Cargo.toml .github/ -l

Repository: rainlanguage/rain.orderbook

Length of output: 53


🏁 Script executed:

# Check the actual build configuration - does cdylib mean WASM or something else?
rg "crate-type" crates/*/Cargo.toml -B 2 -A 2

Repository: rainlanguage/rain.orderbook

Length of output: 593


Add cfg guard to oracle module for WASM compatibility.

The oracle module uses reqwest::Client::builder().timeout(...) (line 49–50 of oracle.rs), which is unavailable on WASM targets when reqwest is not built with the wasm feature. Since the workspace reqwest has only the json feature enabled, this code cannot compile for WASM. The module is publicly exported without guards and is called from WASM-exposed raindex_client functions. Add #[cfg(not(target_family = "wasm"))] to the oracle module declaration (line 10) to prevent this compilation failure, consistent with the pattern used for replays (line 15–16).

🤖 Prompt for AI Agents
In `@crates/common/src/lib.rs` at line 10, Add a cfg guard to the oracle module
declaration so it is excluded from WASM builds: wrap the pub mod oracle; line
with #[cfg(not(target_family = "wasm"))] (matching how replays is guarded)
because oracle.rs uses reqwest::Client::builder().timeout(...) which fails when
reqwest lacks the wasm feature; ensure the oracle module is only compiled on
non-wasm targets to avoid compilation errors from raindex_client functions that
are exposed to WASM.

pub mod parsed_meta;
pub mod raindex_client;
pub mod rainlang;
Expand Down
3 changes: 3 additions & 0 deletions crates/common/src/oracle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Re-export oracle types and functions from the quote crate.
// This maintains backward compatibility for code in common that uses oracle functionality.
pub use rain_orderbook_quote::oracle::*;
4 changes: 3 additions & 1 deletion crates/common/src/raindex_client/order_quotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ impl RaindexOrder {
) -> Result<Vec<RaindexOrderQuote>, RaindexError> {
let gas_amount = gas.map(|v| v.parse::<u64>()).transpose()?;
let rpcs = self.get_rpc_urls()?;
let sg_order = self.clone().into_sg_order()?;

let order_quotes = get_order_quotes(
vec![self.clone().into_sg_order()?],
vec![sg_order],
block_number,
rpcs.iter().map(|s| s.to_string()).collect(),
gas_amount,
Expand Down
1 change: 1 addition & 0 deletions crates/common/src/raindex_client/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ impl RaindexOrder {
&rpc_urls,
Some(block_number),
sell_token,
self.oracle_url(),
)
.await
}
Expand Down
20 changes: 20 additions & 0 deletions crates/common/src/raindex_client/take_orders/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub fn build_candidate_from_quote(
output_io_index,
max_output: data.max_output,
ratio: data.ratio,
signed_context: vec![],
}))
}

Expand Down Expand Up @@ -102,6 +103,7 @@ pub fn estimate_take_order(
))
}

#[allow(clippy::too_many_arguments)]
pub async fn execute_single_take(
candidate: TakeOrderCandidate,
mode: ParsedTakeOrdersMode,
Expand All @@ -110,7 +112,25 @@ pub async fn execute_single_take(
rpc_urls: &[Url],
block_number: Option<u64>,
sell_token: Address,
oracle_url: Option<String>,
) -> Result<TakeOrdersCalldataResult, RaindexError> {
// Fetch signed context from oracle if URL provided
let mut candidate = candidate;
if let Some(url) = oracle_url {
let body = crate::oracle::encode_oracle_body(
&candidate.order,
candidate.input_io_index,
candidate.output_io_index,
taker,
);
match crate::oracle::fetch_signed_context(&url, body).await {
Ok(ctx) => candidate.signed_context = vec![ctx],
Err(e) => {
tracing::warn!("Failed to fetch oracle data from {}: {}", url, e);
}
}
}

let zero = Float::zero()?;

if candidate.ratio.gt(price_cap)? {
Expand Down
15 changes: 15 additions & 0 deletions crates/common/src/raindex_client/take_orders/single_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ async fn test_single_order_take_happy_path_buy_up_to() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed with BuyUpTo mode");
Expand Down Expand Up @@ -248,6 +249,7 @@ async fn test_single_order_take_happy_path_buy_exact() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed with BuyExact mode");
Expand Down Expand Up @@ -350,6 +352,7 @@ async fn test_single_order_take_happy_path_spend_up_to() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed with SpendUpTo mode");
Expand Down Expand Up @@ -576,6 +579,7 @@ async fn test_single_order_take_buy_exact_insufficient_liquidity() {
&rpc_urls,
None,
setup.token1,
None,
)
.await;

Expand Down Expand Up @@ -667,6 +671,7 @@ async fn test_single_order_take_price_exceeds_cap() {
&rpc_urls,
None,
setup.token1,
None,
)
.await;

Expand Down Expand Up @@ -799,6 +804,7 @@ async fn test_single_order_take_preflight_insufficient_balance() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed with approval result");
Expand Down Expand Up @@ -904,6 +910,7 @@ async fn test_single_order_take_preflight_insufficient_allowance() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed with approval result");
Expand Down Expand Up @@ -1010,6 +1017,7 @@ async fn test_single_order_take_approval_then_ready_flow() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed with approval result");
Expand Down Expand Up @@ -1056,6 +1064,7 @@ async fn test_single_order_take_approval_then_ready_flow() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed with ready result after approval");
Expand Down Expand Up @@ -1168,6 +1177,7 @@ async fn test_single_order_take_calldata_encoding_buy_mode() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed");
Expand Down Expand Up @@ -1275,6 +1285,7 @@ async fn test_single_order_take_expected_spend_calculation() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed");
Expand Down Expand Up @@ -1386,6 +1397,7 @@ async fn test_single_order_take_spend_exact_mode() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed with SpendExact mode");
Expand Down Expand Up @@ -1616,6 +1628,7 @@ async fn test_single_order_take_spend_exact_insufficient_liquidity() {
&rpc_urls,
None,
setup.token1,
None,
)
.await;

Expand Down Expand Up @@ -1709,6 +1722,7 @@ async fn test_single_order_take_calldata_encoding_spend_mode() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed");
Expand Down Expand Up @@ -1825,6 +1839,7 @@ async fn test_single_order_take_expected_receive_calculation() {
&rpc_urls,
None,
setup.token1,
None,
)
.await
.expect("Should succeed");
Expand Down
Loading