feat: add strategy-builder CLI subcommand#2544
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR adds a new ChangesStrategy Builder CLI Command
🎯 2 (Simple) | ⏱️ ~12 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/cli/src/commands/strategy_builder.rs`:
- Around line 48-55: parse_key_value_pairs currently silently overwrites
duplicate keys; update it to detect duplicate keys and return an error instead
of replacing the previous entry. In the function parse_key_value_pairs(args:
&[String]) -> Result<HashMap<String, String>>, after splitting into key/value
check whether map.contains_key(&key.to_string()) (or lookups using &key) and if
present return an anyhow::anyhow! error indicating a duplicate override for that
key and the original arg; only insert when the key is new. Ensure the function
returns an Err on duplicates so callers cannot proceed with silent collisions.
- Around line 86-89: The parser currently uses line.split_once(' ') which fails
on tabs or multiple/mixed whitespace; change the logic that extracts key and
url_str from each line to use line.split_whitespace() (collect into fields),
validate that fields.len() == 2 and return the same anyhow::anyhow!("invalid
registry line (expected 'key url'): {line}') error if not, then set key =
fields[0] and url_str = fields[1] before calling
order_urls.insert(key.to_string(), url_str.trim().to_string()) so the code
accepts any whitespace delimiter.
- Around line 59-65: The fetch_text function currently calls reqwest::get
without a timeout and can block indefinitely; change it to build and reuse a
reqwest::Client with an explicit timeout (e.g., Duration::from_secs(10)) and
perform client.get(url.as_str()).send().await instead of reqwest::get, ensuring
you propagate errors as before; update fetch_text to accept or create that
client (or create a local client with Client::builder().timeout(...).build()?)
and use response.text().await? to return the body. Also add the necessary
std::time::Duration import and preserve the existing HTTP error handling around
response.status() and anyhow::bail! when non-success.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: c75248ce-047a-4e27-b189-fdb73b5de209
📒 Files selected for processing (4)
crates/cli/Cargo.tomlcrates/cli/src/commands/mod.rscrates/cli/src/commands/strategy_builder.rscrates/cli/src/lib.rs
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
♻️ Duplicate comments (1)
crates/cli/src/commands/strategy_builder.rs (1)
48-60:⚠️ Potential issue | 🟡 MinorReject empty
KEYvalues duringKEY=VALUEparsing.
=valuecurrently passes parsing and creates an empty key, which degrades CLI validation and error clarity. Validate non-empty trimmed keys at parse time and add a test for it.Suggested patch
fn parse_key_value_pairs(args: &[String]) -> Result<HashMap<String, String>> { let mut map = HashMap::new(); for arg in args { - let (key, value) = arg + let (raw_key, value) = arg .split_once('=') .ok_or_else(|| anyhow::anyhow!("expected KEY=VALUE, got: {arg}"))?; + let key = raw_key.trim(); + if key.is_empty() { + anyhow::bail!("expected non-empty KEY in KEY=VALUE, got: {arg}"); + } if map.contains_key(key) { anyhow::bail!("duplicate key: {key}"); } map.insert(key.to_string(), value.to_string()); } Ok(map) } @@ fn parse_key_value_pairs_duplicate_key_fails() { let args = vec!["key=first".to_string(), "key=second".to_string()]; let err = parse_key_value_pairs(&args).unwrap_err().to_string(); assert!(err.contains("duplicate key: key"), "got: {err}"); } + + #[test] + fn parse_key_value_pairs_empty_key_fails() { + let args = vec!["=value".to_string()]; + let err = parse_key_value_pairs(&args).unwrap_err().to_string(); + assert!(err.contains("expected non-empty KEY"), "got: {err}"); + } }Also applies to: 165-202
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/cli/src/commands/strategy_builder.rs` around lines 48 - 60, parse_key_value_pairs accepts inputs like "=value" producing empty keys; update the function (parse_key_value_pairs) to trim the key part, reject empty keys by returning an error (e.g., bail or anyhow::anyhow! with a clear message referencing the original arg), and keep the duplicate-key check and insertion behavior. Apply the same non-empty-trimmed-key validation to the other parsing occurrence in this file (the duplicate block around the later function), and add a unit test that asserts parsing "=value" (and keys with only whitespace) returns an error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@crates/cli/src/commands/strategy_builder.rs`:
- Around line 48-60: parse_key_value_pairs accepts inputs like "=value"
producing empty keys; update the function (parse_key_value_pairs) to trim the
key part, reject empty keys by returning an error (e.g., bail or anyhow::anyhow!
with a clear message referencing the original arg), and keep the duplicate-key
check and insertion behavior. Apply the same non-empty-trimmed-key validation to
the other parsing occurrence in this file (the duplicate block around the later
function), and add a unit test that asserts parsing "=value" (and keys with only
whitespace) returns an error.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5ccb4e7f-ad28-409d-a17f-fce8982ea92f
📒 Files selected for processing (2)
crates/cli/Cargo.tomlcrates/cli/src/commands/strategy_builder.rs
ba92f20 to
9a5eb91
Compare
How to use the Graphite Merge QueueAdd the label Raindex-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/cli/src/commands/strategy_builder.rs`:
- Around line 77-82: The error message builds its "available" list from
registry.get_order_keys() which relies on map iteration order and yields
non-deterministic text; change the code that assigns available (from
registry.get_order_keys().unwrap_or_default()) to collect into a Vec, sort it
(e.g., sort_unstable or sort()), and then use that sorted Vec in the anyhow!
message so the "Available: {:?}" output is deterministic; update the variable
named available near the anyhow! call in strategy_builder.rs accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 81056df2-7093-4391-9355-e31e7fee657e
📒 Files selected for processing (5)
crates/cli/Cargo.tomlcrates/cli/src/commands/mod.rscrates/cli/src/commands/strategy_builder.rscrates/cli/src/lib.rscrates/settings/src/remote/tokens.rs
72e5a29 to
ea4b4dd
Compare
Merge activity
|
## Motivation The Raindex orderbook protocol has a rich GUI builder flow in the webapp for configuring and deploying strategies. There is currently no way to do the same from a terminal or from a non-interactive agent — the webapp is the only entry point. That forces anyone automating a deployment (CI, scripts, AI agents) to either drive the browser or hand-roll the calldata. ## Solution Add a `strategy-builder` subcommand to the raindex CLI that generates deployment calldata from a remote registry strategy. ``` raindex strategy-builder \ --registry <url> \ --strategy <key> \ --deployment <key> \ --owner <0x-address> \ [--select-token KEY=ADDRESS ...] \ [--set-field BINDING=VALUE ...] \ [--set-deposit TOKEN=AMOUNT ...] ``` Outputs one `<address>:<calldata>` line per transaction on stdout — approvals first, then the deployment multicall, then optional metaboard meta emission. Each line is one signable transaction. Implementation reuses `RaindexOrderBuilder` from the common crate (same object the webapp drives) and `DotrainRegistry` from the js_api crate, so the CLI and webapp use identical resolution semantics. Follow-up PRs in this stack add `--interactive` (#2546), `--tokens` (#2549), the template-fallback operator (#2551), and `--describe` (#2548). ## Checks - [x] made this PR as small as possible - [x] unit-tested any new functionality - [x] linked any relevant issues or PRs - [ ] included screenshots (if this involves a front-end change) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a new `strategy-builder` command that generates deployment calldata from registry strategies with configurable field bindings, token selections, and deposit amounts. * **Improvements** * Token logo URIs are now optional, improving compatibility with token data sources. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
ea4b4dd to
70fbd42
Compare
## Motivation The Raindex orderbook protocol has a rich GUI builder flow in the webapp for configuring and deploying strategies. There is currently no way to do the same from a terminal or from a non-interactive agent — the webapp is the only entry point. That forces anyone automating a deployment (CI, scripts, AI agents) to either drive the browser or hand-roll the calldata. ## Solution Add a `strategy-builder` subcommand to the raindex CLI that generates deployment calldata from a remote registry strategy. ``` raindex strategy-builder \ --registry <url> \ --strategy <key> \ --deployment <key> \ --owner <0x-address> \ [--select-token KEY=ADDRESS ...] \ [--set-field BINDING=VALUE ...] \ [--set-deposit TOKEN=AMOUNT ...] ``` Outputs one `<address>:<calldata>` line per transaction on stdout — approvals first, then the deployment multicall, then optional metaboard meta emission. Each line is one signable transaction. Implementation reuses `RaindexOrderBuilder` from the common crate (same object the webapp drives) and `DotrainRegistry` from the js_api crate, so the CLI and webapp use identical resolution semantics. Follow-up PRs in this stack add `--interactive` (#2546), `--tokens` (#2549), the template-fallback operator (#2551), and `--describe` (#2548). ## Checks - [x] made this PR as small as possible - [x] unit-tested any new functionality - [x] linked any relevant issues or PRs - [ ] included screenshots (if this involves a front-end change) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a new `strategy-builder` command that generates deployment calldata from registry strategies with configurable field bindings, token selections, and deposit amounts. * **Improvements** * Token logo URIs are now optional, improving compatibility with token data sources. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
70fbd42 to
a1e2ce7
Compare
## Motivation The Raindex orderbook protocol has a rich GUI builder flow in the webapp for configuring and deploying strategies. There is currently no way to do the same from a terminal or from a non-interactive agent — the webapp is the only entry point. That forces anyone automating a deployment (CI, scripts, AI agents) to either drive the browser or hand-roll the calldata. ## Solution Add a `strategy-builder` subcommand to the raindex CLI that generates deployment calldata from a remote registry strategy. ``` raindex strategy-builder \ --registry <url> \ --strategy <key> \ --deployment <key> \ --owner <0x-address> \ [--select-token KEY=ADDRESS ...] \ [--set-field BINDING=VALUE ...] \ [--set-deposit TOKEN=AMOUNT ...] ``` Outputs one `<address>:<calldata>` line per transaction on stdout — approvals first, then the deployment multicall, then optional metaboard meta emission. Each line is one signable transaction. Implementation reuses `RaindexOrderBuilder` from the common crate (same object the webapp drives) and `DotrainRegistry` from the js_api crate, so the CLI and webapp use identical resolution semantics. Follow-up PRs in this stack add `--interactive` (#2546), `--tokens` (#2549), the template-fallback operator (#2551), and `--describe` (#2548). ## Checks - [x] made this PR as small as possible - [x] unit-tested any new functionality - [x] linked any relevant issues or PRs - [ ] included screenshots (if this involves a front-end change) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added `strategy-builder` command to the CLI for generating deployment calldata from registry-based strategies. The command accepts required parameters for registry URL, strategy identifier, deployment address, and owner. Users can further customize strategy deployments with repeatable options to set field bindings, select tokens, and configure deposit amounts, enabling streamlined deployment workflows. [](https://app.coderabbit.ai/change-stack/rainlanguage/raindex/pull/2544) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
a1e2ce7 to
50d4083
Compare

Motivation
The Raindex orderbook protocol has a rich GUI builder flow in the webapp for configuring and deploying strategies. There is currently no way to do the same from a terminal or from a non-interactive agent — the webapp is the only entry point. That forces anyone automating a deployment (CI, scripts, AI agents) to either drive the browser or hand-roll the calldata.
Solution
Add a
strategy-buildersubcommand to the raindex CLI that generates deployment calldata from a remote registry strategy.Outputs one
<address>:<calldata>line per transaction on stdout — approvals first, then the deployment multicall, then optional metaboard meta emission. Each line is one signable transaction.Implementation reuses
RaindexOrderBuilderfrom the common crate (same object the webapp drives) andDotrainRegistryfrom the js_api crate, so the CLI and webapp use identical resolution semantics.Follow-up PRs in this stack add
--interactive(#2546),--tokens(#2549), the template-fallback operator (#2551), and--describe(#2548).Checks
Summary by CodeRabbit
strategy-buildercommand to the CLI for generating deployment calldata from registry-based strategies. The command accepts required parameters for registry URL, strategy identifier, deployment address, and owner. Users can further customize strategy deployments with repeatable options to set field bindings, select tokens, and configure deposit amounts, enabling streamlined deployment workflows.