Skip to content

Commit

Permalink
Merge branch 'main' into 2024-12-16-ob-yaml-sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
findolor committed Dec 19, 2024
2 parents e768197 + 9be5363 commit 391e35b
Show file tree
Hide file tree
Showing 57 changed files with 1,468 additions and 1,356 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/manual-sol-artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
echo "verifier_url_secret_name=CI_DEPLOY_${network^^}_VERIFIER_URL" >> $GITHUB_ENV
echo "metaboard_address_secret_name=CI_DEPLOY_${network^^}_METABOARD_ADDRESS" >> $GITHUB_ENV
echo "route_processor_4_address_secret_name=CI_DEPLOY_${network^^}_ROUTE_PROCESSOR_4_ADDRESS" >> $GITHUB_ENV
echo "raindex_address_secret_name=CI_DEPLOY_${network^^}_RAINDEX_ADDRESS" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
Expand All @@ -71,4 +72,5 @@ jobs:
DEPLOY_VERIFIER: ${{ secrets[env.verifier_secret_name] || vars[env.verifier_secret_name] || '' }}
DEPLOY_VERIFIER_URL: ${{ secrets[env.verifier_url_secret_name] || vars[env.verifier_url_secret_name] || '' }}
DEPLOY_METABOARD_ADDRESS: ${{ secrets[env.metaboard_address_secret_name] || vars[env.metaboard_address_secret_name] || '' }}
DEPLOY_ROUTE_PROCESSOR_4_ADDRESS: ${{ secrets[env.route_processor_4_address_secret_name] || vars[env.route_processor_4_address_secret_name] || '' }}
DEPLOY_ROUTE_PROCESSOR_4_ADDRESS: ${{ secrets[env.route_processor_4_address_secret_name] || vars[env.route_processor_4_address_secret_name] || '' }}
DEPLOY_RAINDEX_ADDRESS: ${{ secrets[env.raindex_address_secret_name] || vars[env.raindex_address_secret_name] || '' }}
3 changes: 0 additions & 3 deletions crates/common/src/add_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ price: 2e18;
key: "".to_string(),
network: network_arc.clone(),
address: Address::default(),
label: None,
};
let deployer_arc = Arc::new(deployer);
let scenario = Scenario {
Expand Down Expand Up @@ -550,7 +549,6 @@ _ _: 0 0;
key: "".to_string(),
network: network_arc.clone(),
address: *local_evm.deployer.address(),
label: None,
};
let deployer_arc = Arc::new(deployer);
let scenario = Scenario {
Expand Down Expand Up @@ -691,7 +689,6 @@ _ _: 0 0;
key: "".to_string(),
network: network_arc.clone(),
address: Address::default(),
label: None,
};
let deployer_arc = Arc::new(deployer);
let scenario = Scenario {
Expand Down
42 changes: 38 additions & 4 deletions crates/js_api/src/subgraph/order.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
use cynic::Id;
use rain_orderbook_bindings::wasm_traits::prelude::*;
use rain_orderbook_common::types::OrderDetailExtended;
use rain_orderbook_subgraph_client::{
types::common::OrdersListFilterArgs, MultiOrderbookSubgraphClient, MultiSubgraphArgs,
OrderbookSubgraphClient, OrderbookSubgraphClientError, PaginationArgs,
types::common::{Order, OrdersListFilterArgs},
MultiOrderbookSubgraphClient, MultiSubgraphArgs, OrderbookSubgraphClient,
OrderbookSubgraphClientError, PaginationArgs,
};
use reqwest::Url;

/// Internal function to fetch a single order
/// Returns the Order struct
async fn get_sg_order(url: &str, id: &str) -> Result<Order, OrderbookSubgraphClientError> {
let client = OrderbookSubgraphClient::new(Url::parse(url)?);
let order = client.order_detail(Id::new(id)).await?;
Ok(order)
}

/// Fetch all orders from multiple subgraphs
/// Returns a list of OrderWithSubgraphName structs
#[wasm_bindgen(js_name = "getOrders")]
Expand All @@ -23,11 +33,20 @@ pub async fn get_orders(
/// Returns the Order struct
#[wasm_bindgen(js_name = "getOrder")]
pub async fn get_order(url: &str, id: &str) -> Result<JsValue, OrderbookSubgraphClientError> {
let client = OrderbookSubgraphClient::new(Url::parse(url)?);
let order = client.order_detail(Id::new(id)).await?;
let order = get_sg_order(url, id).await?;
Ok(to_value(&order)?)
}

/// Extend an order to include Rainlang string
/// Returns an OrderDetailExtended struct
#[wasm_bindgen(js_name = "extendOrder")]
pub fn order_detail_extended(order: Order) -> Result<JsValue, OrderbookSubgraphClientError> {
let order_extended: OrderDetailExtended = order
.try_into()
.map_err(|_| OrderbookSubgraphClientError::OrderDetailExtendError)?;
Ok(to_value(&order_extended)?)
}

/// Fetch trades for a specific order
/// Returns a list of Trade structs
#[wasm_bindgen(js_name = "getOrderTradesList")]
Expand Down Expand Up @@ -83,3 +102,18 @@ pub async fn get_order_trades_count(
// Convert the count to a JavaScript-compatible value and return
Ok(to_value(&trades_count)?)
}

/// Fetch volume information for vaults associated with an order
#[wasm_bindgen(js_name = "getOrderVaultsVolume")]
pub async fn order_vaults_volume(
url: &str,
order_id: &str,
start_timestamp: Option<u64>,
end_timestamp: Option<u64>,
) -> Result<JsValue, OrderbookSubgraphClientError> {
let client = OrderbookSubgraphClient::new(Url::parse(url)?);
let volumes = client
.order_vaults_volume(Id::new(order_id), start_timestamp, end_timestamp)
.await?;
Ok(to_value(&volumes)?)
}
18 changes: 14 additions & 4 deletions crates/settings/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use super::config_source::ConfigSourceError;
use crate::*;
use alloy::primitives::U256;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::Arc;
use std::{collections::HashMap, sync::RwLock};
use strict_yaml_rust::StrictYaml;
use subgraph::Subgraph;
use thiserror::Error;
use typeshare::typeshare;
use url::Url;
Expand Down Expand Up @@ -45,7 +47,6 @@ pub struct Config {
#[cfg(target_family = "wasm")]
impl_all_wasm_traits!(Config);

pub type Subgraph = Url;
pub type Metaboard = Url;
pub type Vault = U256;

Expand Down Expand Up @@ -95,7 +96,16 @@ impl TryFrom<ConfigSource> for Config {
let subgraphs = item
.subgraphs
.into_iter()
.map(|(name, subgraph)| Ok((name, Arc::new(subgraph))))
.map(|(name, subgraph)| {
Ok((
name.clone(),
Arc::new(Subgraph {
document: Arc::new(RwLock::new(StrictYaml::String("".to_string()))),
key: name.clone(),
url: subgraph.clone(),
}),
))
})
.collect::<Result<HashMap<String, Arc<Subgraph>>, ParseConfigSourceError>>()?;

let metaboards = item
Expand Down Expand Up @@ -343,7 +353,7 @@ mod tests {
// Verify subgraphs
assert_eq!(config.subgraphs.len(), 1);
let mainnet_subgraph = config.subgraphs.get("mainnet").unwrap();
assert_eq!(mainnet_subgraph.as_str(), "https://mainnet.subgraph/");
assert_eq!(mainnet_subgraph.url.as_str(), "https://mainnet.subgraph/");

// Verify orderbooks
assert_eq!(config.orderbooks.len(), 1);
Expand Down
7 changes: 0 additions & 7 deletions crates/settings/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub struct Deployer {
pub address: Address,
#[typeshare(typescript(type = "Network"))]
pub network: Arc<Network>,
pub label: Option<String>,
}
impl Deployer {
pub fn dummy() -> Self {
Expand All @@ -37,7 +36,6 @@ impl Deployer {
key: "".to_string(),
address: Address::default(),
network: Arc::new(Network::dummy()),
label: None,
}
}

Expand Down Expand Up @@ -95,7 +93,6 @@ impl DeployerConfigSource {
key: name,
address: self.address,
network: network_ref,
label: self.label,
})
}
}
Expand Down Expand Up @@ -130,14 +127,11 @@ impl YamlParsableHash for Deployer {
};
let network = Network::parse_from_yaml(document.clone(), &network_name)?;

let label = optional_string(deployer_yaml, "label");

let deployer = Deployer {
document: document.clone(),
key: deployer_key.clone(),
address,
network: Arc::new(network),
label,
};

Ok((deployer_key, deployer))
Expand Down Expand Up @@ -171,7 +165,6 @@ mod tests {
deployer.network.as_ref().label,
Some(network_name.to_string())
);
assert_eq!(deployer.label, Some("Test Deployer".to_string()));
}

#[test]
Expand Down
61 changes: 40 additions & 21 deletions crates/settings/src/metaboard.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
use crate::config::Metaboard;
use crate::yaml::{require_hash, require_string, YamlError, YamlParsableHash};
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
sync::{Arc, RwLock},
};
use strict_yaml_rust::StrictYaml;
use typeshare::typeshare;
use url::{ParseError, Url};

#[derive(Clone, Debug)]
pub struct YamlMetaboard(Metaboard);
#[typeshare]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "kebab-case")]
#[serde(default)]
pub struct Metaboard {
#[serde(skip)]
pub document: Arc<RwLock<StrictYaml>>,
pub key: String,
#[typeshare(typescript(type = "string"))]
pub url: Url,
}

impl YamlMetaboard {
impl Metaboard {
pub fn validate_url(value: &str) -> Result<Url, ParseError> {
Url::parse(value)
}
}

impl YamlParsableHash for YamlMetaboard {
impl YamlParsableHash for Metaboard {
fn parse_all_from_yaml(
document: Arc<RwLock<StrictYaml>>,
) -> Result<HashMap<String, YamlMetaboard>, YamlError> {
) -> Result<HashMap<String, Metaboard>, YamlError> {
let document_read = document.read().map_err(|_| YamlError::ReadLockError)?;
let metaboards_hash = require_hash(
&document_read,
Expand All @@ -32,29 +42,39 @@ impl YamlParsableHash for YamlMetaboard {
.map(|(key_yaml, metaboard_yaml)| {
let metaboard_key = key_yaml.as_str().unwrap_or_default().to_string();

let url = YamlMetaboard::validate_url(&require_string(
let url = Metaboard::validate_url(&require_string(
metaboard_yaml,
None,
Some(format!(
"metaboard value must be a string for key: {metaboard_key}"
)),
)?)?;

Ok((metaboard_key, YamlMetaboard(url)))
let metaboard = Metaboard {
document: document.clone(),
key: metaboard_key.clone(),
url,
};

Ok((metaboard_key, metaboard))
})
.collect()
}
}

impl From<Metaboard> for YamlMetaboard {
fn from(value: Metaboard) -> Self {
YamlMetaboard(value)
impl Default for Metaboard {
fn default() -> Self {
Self {
document: Arc::new(RwLock::new(StrictYaml::String("".to_string()))),
key: "".to_string(),
url: Url::parse("https://metaboard.com").unwrap(),
}
}
}

impl From<YamlMetaboard> for Metaboard {
fn from(value: YamlMetaboard) -> Self {
value.0
impl PartialEq for Metaboard {
fn eq(&self, other: &Self) -> bool {
self.key == other.key && self.url == other.url
}
}

Expand All @@ -68,7 +88,7 @@ mod test {
let yaml = r#"
test: test
"#;
let error = YamlMetaboard::parse_all_from_yaml(get_document(yaml)).unwrap_err();
let error = Metaboard::parse_all_from_yaml(get_document(yaml)).unwrap_err();
assert_eq!(
error,
YamlError::ParseError("missing field: metaboards".to_string())
Expand All @@ -79,7 +99,7 @@ metaboards:
TestMetaboard:
test: https://metaboard.com
"#;
let error = YamlMetaboard::parse_all_from_yaml(get_document(yaml)).unwrap_err();
let error = Metaboard::parse_all_from_yaml(get_document(yaml)).unwrap_err();
assert_eq!(
error,
YamlError::ParseError(
Expand All @@ -92,7 +112,7 @@ metaboards:
TestMetaboard:
- https://metaboard.com
"#;
let error = YamlMetaboard::parse_all_from_yaml(get_document(yaml)).unwrap_err();
let error = Metaboard::parse_all_from_yaml(get_document(yaml)).unwrap_err();
assert_eq!(
error,
YamlError::ParseError(
Expand All @@ -102,10 +122,9 @@ metaboards:

let yaml = r#"
metaboards:
TestMetaboard: https://metaboard.com
TestMetaboard: invalid-url
"#;
let result = YamlMetaboard::parse_all_from_yaml(get_document(yaml)).unwrap();
assert_eq!(result.len(), 1);
assert!(result.contains_key("TestMetaboard"));
let res = Metaboard::parse_all_from_yaml(get_document(yaml));
assert!(res.is_err());
}
}
8 changes: 4 additions & 4 deletions crates/settings/src/orderbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::str::FromStr;
use std::sync::{Arc, RwLock};
use strict_yaml_rust::StrictYaml;
use subgraph::YamlSubgraph;
use subgraph::Subgraph;
use thiserror::Error;
use typeshare::typeshare;
use yaml::{optional_string, require_hash, require_string, YamlError, YamlParsableHash};
Expand Down Expand Up @@ -68,8 +68,8 @@ impl YamlParsableHash for Orderbook {
Some(subgraph_name) => subgraph_name,
None => orderbook_key.clone(),
};
let subgraph = YamlSubgraph::parse_from_yaml(document.clone(), &subgraph_name)?;
let subgraph = Arc::new(subgraph.into());
let subgraph =
Arc::new(Subgraph::parse_from_yaml(document.clone(), &subgraph_name)?);

let label = optional_string(orderbook_yaml, "label");

Expand All @@ -95,7 +95,7 @@ impl Default for Orderbook {
key: "".to_string(),
address: Address::ZERO,
network: Arc::new(Network::default()),
subgraph: Arc::new(Subgraph::parse("https://subgraph.com").unwrap()),
subgraph: Arc::new(Subgraph::default()),
label: None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/settings/src/scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl ScenarioConfigSource {

// Check for non-matching override: if both the current and parent deployers are present and different, it's an error.
if let (deployer, Some(parent_deployer)) = (deployer_ref, parent.deployer.as_ref()) {
if deployer.label != parent_deployer.label {
if deployer.key != parent_deployer.key {
return Err(ParseScenarioConfigSourceError::ParentDeployerShadowedError(
resolved_name.clone(),
));
Expand Down
Loading

0 comments on commit 391e35b

Please sign in to comment.