Skip to content

feat: implement auto-invest registry contract with rule creation, upd… - #1155

Merged
Chucks1093 merged 12 commits into
accesslayerorg:mainfrom
extolkom:feat/auto-invest-registry-1029
Oct 20, 2026
Merged

Chucks1093 merged 12 commits into
accesslayerorg:mainfrom
extolkom:feat/auto-invest-registry-1029

Conversation

@extolkom

Copy link
Copy Markdown
Contributor

Summary

Implements GitHub issue #1029 by introducing a dedicated auto-invest-registry Soroban contract for automated, rule-based creator key purchases. Investors can configure, update, and deactivate purchase rules on-chain, and off-chain execution services can evaluate key eligibility before executing purchases.

  • Workspace Registration: Added auto-invest-registry to Cargo.toml.
  • Criteria & Rule Model:
    • Criteria: key_category (0 = wildcard, non-zero = explicit category), min_rating (scaled 100..=500), max_price (i128 > 0), max_per_key (u32 > 0).
    • Rule: id, owner, criteria, active, created_at.
  • Contract Functions:
    • register_rule(wallet, criteria): Validates inputs, enforces MAX_RULES_PER_WALLET = 50, stores rules in registration order, and emits RuleRegistered.
    • update_rule(rule_id, criteria): Requires owner auth; owner and ID are immutable; fails with RuleDeactivated if the rule is deactivated; emits RuleUpdated.
    • deactivate_rule(rule_id): Requires owner auth; disables rule without deleting; fails with RuleAlreadyDeactivated if already inactive.
    • check_rule_with_context(wallet, key_id, category, rating, price, current_holdings): Pure evaluation against caller-supplied market metrics; iterates active rules in FIFO registration order and returns CheckResult.
    • check_rule(wallet, key_id, category, rating, price, current_holdings): Delegates directly to check_rule_with_context.
    • get_rules(wallet): Returns all registered rules for wallet in registration order.
    • get_rule(rule_id): Fetches a single rule by ID.
  • Events:
    • Emits RuleRegistered (rule_reg) and RuleUpdated (rule_upd) compliant with docs/contract-event-conventions.md.

Design Decisions & Assumptions

  1. Stateless Market Data Evaluation: Because the on-chain creator-keys contract does not store key categories, category filtering requires metadata supplied by the caller (indexed off-chain). Passing market metrics directly into check_rule avoids unauthenticated state-changing setters, eliminates cross-contract call failure traps, and prevents reentrancy risks.
  2. Advisory Check Function: check_rule and check_rule_with_context rely on caller-supplied data and are explicitly documented as advisory pre-flight validation for automated purchase bots, not an on-chain security gate.
  3. Rating Scale: Enforces min_rating in 100..=500 (representing 1.00 to 5.00 stars), matching average_score_scaled in creator-keys.
  4. FIFO Ordering: Rules are evaluated strictly in order of registration. The first active rule where all criteria match determines eligibility.
  5. No Admin/Trust Roles: No privileged backdoors or unauthenticated setters. All state changes require owner authorization.

Testing

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace

Note on Clippy & Test: Formatting was verified locally (cargo fmt --all -- --check passed with code 0). Native host execution on Windows was blocked by the missing MSVC link.exe linker (see WINDOWS_BUILD_GUIDE.md); full clippy and test suites will execute automatically in the Ubuntu CI pipeline.

Test Coverage in auto-invest-registry/src/test.rs

  • Rule registration and criteria field verification.
  • Full eligibility evaluation against all criteria (category match/mismatch, rating threshold, max price limit, holder cap).
  • Boundary value coverage (exact rating match, exact price match, holdings one below max vs at max).
  • Wildcard category matching (key_category == 0) and explicit non-wildcard category behavior.
  • Exclusion of deactivated rules from check evaluation and fallback to subsequent active rules.
  • Stable FIFO ordering in get_rules, including after rule deactivations.
  • Rejection of invalid criteria (min_rating < 100 or > 500, max_price <= 0, max_per_key == 0).
  • Rejection of update_rule on deactivated rules (RuleDeactivated).
  • Rejection of double deactivation (RuleAlreadyDeactivated).
  • Boundary enforcement for MAX_RULES_PER_WALLET = 50 (50 succeeds, 51st returns TooManyRules).
  • Unauthorized call rejections when owner signature is absent.
  • Event emission and payload verification for RuleRegistered and RuleUpdated.

Checklist

  • Linked issue or backlog item (Implement auto-invest registry contract for rule-based key purchases #1029)
  • Added unit tests in auto-invest-registry/src/test.rs covering every acceptance criterion and error path
  • Ran cargo fmt --all -- --check cleanly; explained build tools dependency for local test run
  • Reviewed storage against docs/storage-key-invariants.md (isolated namespace, persistent keys with 30-day TTL extension)
  • Event names (rule_reg, rule_upd), topics, and payload schemas conform to docs/contract-event-conventions.md
  • Scope strictly limited to auto-invest-registry/ and 1-line workspace registration in root Cargo.toml without touching unrelated crates

Closes #1029

@drips-wave

drips-wave Bot commented Oct 19, 2026

Copy link
Copy Markdown

@extolkom Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Chucks1093
Chucks1093 merged commit d1fb9d8 into accesslayerorg:main Oct 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement auto-invest registry contract for rule-based key purchases

2 participants