Skip to content

feat: Add update_orchestrator function to allow users to rotate their… - #34

Open
olaleyeolajide81-sketch wants to merge 2 commits into
clevercon-protocol:mainfrom
olaleyeolajide81-sketch:feature/update-orchestrator
Open

feat: Add update_orchestrator function to allow users to rotate their…#34
olaleyeolajide81-sketch wants to merge 2 commits into
clevercon-protocol:mainfrom
olaleyeolajide81-sketch:feature/update-orchestrator

Conversation

@olaleyeolajide81-sketch

@olaleyeolajide81-sketch olaleyeolajide81-sketch commented Jun 24, 2026

Copy link
Copy Markdown

… registered orchestrator

  • Implements update_orchestrator(env, user, new_orchestrator, name) function
  • Requires user authentication via user.require_auth()
  • Loads existing UserAccount and validates orchestrator is registered
  • Removes old OrchestratorOwner reverse-lookup entry from persistent storage
  • Sets new orchestrator address and updates reverse lookup
  • Emits UpdateOrchEvent with user, old_orchestrator, and new_orchestrator
  • Guards: panics if active_tasks_count > 0 (same as withdraw)
  • Guards: panics if no orchestrator is currently registered
  • Adds comprehensive tests covering:
    • Successful orchestrator rotation
    • Blocked when task is active
    • Blocked when no orchestrator registered
  • Uses #[contractevent] macro for UpdateOrchEvent

Fixes #8

Summary

What does this PR do, and why?

Related issue

Closes #

Changes

Testing

How did you verify this works? Include commands run and their output where
useful (e.g. cargo test, npm test, manual testnet transaction links).

Checklist

  • npm run lint passes
  • npm run typecheck passes
  • npm test passes
  • npm run format:check passes
  • If a contract changed: cargo fmt --check, cargo clippy, cargo test
    pass in contracts/<contract>
  • Docs updated if behavior, setup, or APIs changed

closes #8

Summary by CodeRabbit

  • New Features
    • Added a new event that notifies listeners when a user’s registered orchestrator changes.
    • The event includes the user address, the previous orchestrator address, and the updated orchestrator address.

… registered orchestrator

- Implements update_orchestrator(env, user, new_orchestrator, name) function
- Requires user authentication via user.require_auth()
- Loads existing UserAccount and validates orchestrator is registered
- Removes old OrchestratorOwner reverse-lookup entry from persistent storage
- Sets new orchestrator address and updates reverse lookup
- Emits UpdateOrchEvent with user, old_orchestrator, and new_orchestrator
- Guards: panics if active_tasks_count > 0 (same as withdraw)
- Guards: panics if no orchestrator is currently registered
- Adds comprehensive tests covering:
  - Successful orchestrator rotation
  - Blocked when task is active
  - Blocked when no orchestrator registered
- Uses #[contractevent] macro for UpdateOrchEvent

Fixes clevercon-protocol#8
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0256f52c-77dd-4f9f-b6bd-037178293b13

📥 Commits

Reviewing files that changed from the base of the PR and between 9be0d61 and f62efb5.

📒 Files selected for processing (1)
  • contracts/agent-vault/src/lib.rs

📝 Walkthrough

Walkthrough

Adds a new Soroban #[contractevent] struct UpdateOrchEvent to contracts/agent-vault/src/lib.rs. The event carries three fields: user, old_orchestrator, and new_orchestrator, all of type Address, with user marked as an indexed topic.

Changes

Orchestrator Update Event

Layer / File(s) Summary
UpdateOrchEvent struct
contracts/agent-vault/src/lib.rs
Defines UpdateOrchEvent as a #[contractevent] with user (indexed), old_orchestrator, and new_orchestrator address fields.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A rabbit hops in, quill in paw,
"Old orchestrator? Gone! Here's what I saw:
New address set, the old one erased,
An event emitted, no moment displaced!"
🐇✨ The vault now whispers every swap it has traced.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The only shown change is the new UpdateOrchEvent; the required update_orchestrator logic, guards, storage updates, and tests are not evident. Implement update_orchestrator with auth, storage updates, active-task/no-orchestrator guards, and the required tests.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly refers to the orchestrator update feature and matches the main intent of the changeset.
Out of Scope Changes check ✅ Passed The event addition is directly in scope for the orchestrator-update feature and no unrelated changes are shown.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contracts/agent-vault/src/lib.rs`:
- Around line 294-302: The account lookup in the user-orchestrator flow is
panicking too early with the "No account" expectation, which prevents first-time
users from reaching the intended no-orchestrator guidance. Update the logic
around the account retrieval in this path so a missing persisted UserAccount is
handled by the same guard flow as an unset orchestrator, and keep the "No
orchestrator registered. Use register_orchestrator instead." behavior reachable
through the existing user/orchestrator handling in this function.
- Around line 321-324: The reverse-lookup update in the orchestrator rotation
flow is overwriting an existing mapping without validation, which can let a
caller take over an address already associated with another owner. Update the
rotation logic around the DataKey::OrchestratorOwner write to first read the
current stored owner for the new orchestrator and only proceed if it is unset or
already belongs to the same user, otherwise reject the change. Use the existing
rotation path in this lib.rs section to keep orchestrator-to-owner resolution
consistent for authorization checks.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c787e8e1-431d-4c7c-845f-8815dd448a8e

📥 Commits

Reviewing files that changed from the base of the PR and between 9d5b4e4 and 9be0d61.

📒 Files selected for processing (2)
  • contracts/agent-vault/src/lib.rs
  • contracts/agent-vault/src/tests.rs

Comment thread contracts/agent-vault/src/lib.rs Outdated
Comment thread contracts/agent-vault/src/lib.rs Outdated
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.

[Task]: Allow users to update their registered orchestrator in CleverVault

2 participants