Skip to content

Commit

Permalink
Merge branch 'main' into 2025-01-22-deposit-withdraw-calldatas
Browse files Browse the repository at this point in the history
  • Loading branch information
hardingjam authored Jan 28, 2025
2 parents ef8e833 + 1d211ae commit a203684
Show file tree
Hide file tree
Showing 64 changed files with 3,522 additions and 565 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tauri-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@v2

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop .#tauri-shell -c ob-tauri-unit-test

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tauri.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@v2

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop .#tauri-shell -c ob-tauri-unit-test

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-ui-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop -c npm run svelte-lint-format-check
working-directory: packages/ui-components
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/test-webapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop -c npm run svelte-lint-format-check
working-directory: packages/webapp
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop -c npm run test
working-directory: packages/webapp
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}
4 changes: 4 additions & 0 deletions .github/workflows/vercel-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop .#webapp-shell -c npm run build
working-directory: packages/webapp
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- name: Install Vercel CLI
run: npm install --global vercel@canary
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/vercel-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main

- run: ./prep-all.sh
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- run: nix develop .#webapp-shell -c npm run build
working-directory: packages/webapp
env:
PUBLIC_WALLETCONNECT_PROJECT_ID: ${{ secrets.WALLETCONNECT_PROJECT_ID }}

- name: Install Vercel CLI
run: npm install --global vercel@canary
Expand Down
32 changes: 20 additions & 12 deletions crates/js_api/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use base64::{engine::general_purpose::URL_SAFE, Engine};
use flate2::{read::GzDecoder, write::GzEncoder, Compression};
use rain_orderbook_app_settings::{
deployment::Deployment,
gui::{Gui, GuiDeployment, GuiFieldDefinition, GuiPreset, ParseGuiConfigSourceError},
gui::{
Gui, GuiDeployment, GuiFieldDefinition, GuiPreset, NameAndDescription,
ParseGuiConfigSourceError,
},
network::Network,
order::Order,
yaml::YamlError,
Expand Down Expand Up @@ -39,11 +42,8 @@ pub struct TokenInfo {
impl_all_wasm_traits!(TokenInfo);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Tsify)]
pub struct GuiDetails {
name: String,
description: String,
}
impl_all_wasm_traits!(GuiDetails);
pub struct DeploymentDetails(BTreeMap<String, NameAndDescription>);
impl_all_wasm_traits!(DeploymentDetails);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[wasm_bindgen]
Expand Down Expand Up @@ -87,7 +87,7 @@ impl DotrainOrderGui {
let gui = self
.dotrain_order
.dotrain_yaml()
.get_gui()?
.get_gui(Some(self.selected_deployment.clone()))?
.ok_or(GuiError::GuiConfigNotFound)?;
Ok(gui)
}
Expand Down Expand Up @@ -146,11 +146,19 @@ impl DotrainOrderGui {
Ok(token_info)
}

#[wasm_bindgen(js_name = "getGuiDetails")]
pub fn get_gui_details(&self) -> Result<GuiDetails, GuiError> {
let (name, description) =
Gui::parse_gui_details(self.dotrain_order.dotrain_yaml().documents.clone())?;
Ok(GuiDetails { name, description })
#[wasm_bindgen(js_name = "getStrategyDetails")]
pub async fn get_strategy_details(dotrain: String) -> Result<NameAndDescription, GuiError> {
let dotrain_order = DotrainOrder::new(dotrain, None).await?;
let details = Gui::parse_strategy_details(dotrain_order.dotrain_yaml().documents.clone())?;
Ok(details)
}

#[wasm_bindgen(js_name = "getDeploymentDetails")]
pub async fn get_deployment_details(dotrain: String) -> Result<DeploymentDetails, GuiError> {
let dotrain_order = DotrainOrder::new(dotrain, None).await?;
let deployment_details =
Gui::parse_deployment_details(dotrain_order.dotrain_yaml().documents.clone())?;
Ok(DeploymentDetails(deployment_details.into_iter().collect()))
}
}

Expand Down
60 changes: 60 additions & 0 deletions crates/settings/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ impl Deployer {
return require_string(deployer_yaml, Some("network"), None)
.or_else(|_| Ok(deployer_key.to_string()));
}
} else {
return Err(YamlError::ParseError(
"deployers field must be a map".to_string(),
));
}
}
Err(YamlError::ParseError(format!(
Expand Down Expand Up @@ -333,4 +337,60 @@ deployers:
let network_key = Deployer::parse_network_key(documents, "mainnet").unwrap();
assert_eq!(network_key, "mainnet");
}

#[test]
fn test_parse_network_key() {
let yaml = r#"
networks:
mainnet:
rpc: https://rpc.com
chain-id: 1
deployers: test
"#;
let error = Deployer::parse_network_key(vec![get_document(yaml)], "mainnet").unwrap_err();
assert_eq!(
error,
YamlError::ParseError("deployers field must be a map".to_string())
);

let yaml = r#"
networks:
mainnet:
rpc: https://rpc.com
chain-id: 1
deployers:
- test
"#;
let error = Deployer::parse_network_key(vec![get_document(yaml)], "mainnet").unwrap_err();
assert_eq!(
error,
YamlError::ParseError("deployers field must be a map".to_string())
);

let yaml = r#"
networks:
mainnet:
rpc: https://rpc.com
chain-id: 1
deployers:
- test: test
"#;
let error = Deployer::parse_network_key(vec![get_document(yaml)], "mainnet").unwrap_err();
assert_eq!(
error,
YamlError::ParseError("deployers field must be a map".to_string())
);

let yaml = r#"
networks:
mainnet:
rpc: https://rpc.com
chain-id: 1
deployers:
mainnet:
address: 0x1234567890123456789012345678901234567890
"#;
let res = Deployer::parse_network_key(vec![get_document(yaml)], "mainnet").unwrap();
assert_eq!(res, "mainnet");
}
}
71 changes: 63 additions & 8 deletions crates/settings/src/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use strict_yaml_rust::StrictYaml;
use thiserror::Error;
use typeshare::typeshare;
use yaml::{
context::Context, default_document, require_hash, require_string, YamlError, YamlParsableHash,
context::{Context, GuiContextTrait},
default_document, require_hash, require_string, YamlError, YamlParsableHash,
};

#[cfg(target_family = "wasm")]
Expand Down Expand Up @@ -44,6 +45,10 @@ impl Deployment {
{
return require_string(deployment_yaml, Some("order"), None);
}
} else {
return Err(YamlError::ParseError(
"deployments field must be a map".to_string(),
));
}
}
Err(YamlError::ParseError(format!(
Expand All @@ -59,28 +64,34 @@ impl YamlParsableHash for Deployment {
) -> Result<HashMap<String, Self>, YamlError> {
let mut deployments = HashMap::new();

let orders = Order::parse_all_from_yaml(documents.clone(), context)?;

for document in &documents {
let document_read = document.read().map_err(|_| YamlError::ReadLockError)?;

if let Ok(deployments_hash) = require_hash(&document_read, Some("deployments"), None) {
for (key_yaml, deployment_yaml) in deployments_hash {
let deployment_key = key_yaml.as_str().unwrap_or_default().to_string();

if let Some(context) = context {
if let Some(current_deployment) = context.get_current_deployment() {
if current_deployment != &deployment_key {
continue;
}
}
}

let mut context = Context::from_context(context);

let order_key = require_string(
deployment_yaml,
Some("order"),
Some(format!(
"order string missing in deployment: {deployment_key}"
)),
)?;
let order = orders
.get(&order_key)
.ok_or_else(|| YamlError::KeyNotFound(order_key.clone()))?
.clone();
context.add_current_order(order_key.clone());

let mut context = Context::new();
let order =
Order::parse_from_yaml(documents.clone(), &order_key, Some(&context))?;
context.add_order(Arc::new(order.clone()));

let scenario = Scenario::parse_from_yaml(
Expand Down Expand Up @@ -513,4 +524,48 @@ deployments:
YamlError::KeyShadowing("DuplicateDeployment".to_string())
);
}

#[test]
fn test_parse_order_key() {
let yaml = r#"
deployments: test
"#;
let error =
Deployment::parse_order_key(vec![get_document(yaml)], "deployment1").unwrap_err();
assert_eq!(
error,
YamlError::ParseError("deployments field must be a map".to_string())
);

let yaml = r#"
deployments:
- test
"#;
let error =
Deployment::parse_order_key(vec![get_document(yaml)], "deployment1").unwrap_err();
assert_eq!(
error,
YamlError::ParseError("deployments field must be a map".to_string())
);

let yaml = r#"
deployments:
- test: test
"#;
let error =
Deployment::parse_order_key(vec![get_document(yaml)], "deployment1").unwrap_err();
assert_eq!(
error,
YamlError::ParseError("deployments field must be a map".to_string())
);

let yaml = r#"
deployments:
deployment1:
order: order1
scenario: scenario1
"#;
let res = Deployment::parse_order_key(vec![get_document(yaml)], "deployment1").unwrap();
assert_eq!(res, "order1");
}
}
Loading

0 comments on commit a203684

Please sign in to comment.