Skip to content

feat(agent-vault): emit events when assets are added/removed from the whitelist (#37) - #54

Open
Itodo-S wants to merge 1 commit into
clevercon-protocol:mainfrom
Itodo-S:feat/whitelist-events-issue-37
Open

feat(agent-vault): emit events when assets are added/removed from the whitelist (#37)#54
Itodo-S wants to merge 1 commit into
clevercon-protocol:mainfrom
Itodo-S:feat/whitelist-events-issue-37

Conversation

@Itodo-S

@Itodo-S Itodo-S commented Jun 28, 2026

Copy link
Copy Markdown

Closes #37.

add_asset() and remove_asset() updated the asset whitelist in persistent storage with no on-chain event, forcing indexers/clients to poll is_supported_asset() per token to detect changes.

Changes (contracts/agent-vault/src/lib.rs — only add_asset/remove_asset)

  • Added two events (matching the issue's spec):
    #[contractevent] pub struct AddAssetEvent    { #[topic] pub asset: Address, pub admin: Address }
    #[contractevent] pub struct RemoveAssetEvent { #[topic] pub asset: Address, pub admin: Address }
  • add_asset() emits AddAssetEvent after writing to storage.
  • remove_asset() emits RemoveAssetEvent only if the asset key existed (the remove is otherwise a no-op), so a no-op remove emits nothing.

Tests (contracts/agent-vault/src/tests.rs)

  • test_add_asset_emits_event — verifies AddAssetEvent via env.events().all().
  • test_remove_asset_emits_event — verifies RemoveAssetEvent via env.events().all().
  • test_remove_nonexistent_asset_emits_no_event — verifies no event when the asset was never whitelisted.

Events are matched exactly (contract id, topics, and data) by reconstructing the expected event through the generated Event impl's topics()/data(), so the assertions can't drift from the macro output.

Acceptance criteria

  • AddAssetEvent and RemoveAssetEvent defined with #[contractevent]
  • add_asset() emits AddAssetEvent after writing to storage
  • remove_asset() emits RemoveAssetEvent after removal (only if the key existed)
  • Tests verify both events using env.events().all()
  • cargo test (52 passing) and cargo clippy --all-targets -- -D warnings pass

Summary by CodeRabbit

  • New Features

    • Asset whitelist updates now emit on-chain events when an asset is added or removed.
    • Admin actions are now easier to track with event details for the asset and admin involved.
  • Tests

    • Added coverage for event emission when assets are added or removed.
    • Verified that removing a non-whitelisted asset does not emit events.

…on-protocol#37)

add_asset() and remove_asset() updated persistent storage with no on-chain
event, so indexers/clients had to poll is_supported_asset() to detect whitelist
changes.

- Add AddAssetEvent and RemoveAssetEvent (#[contractevent], asset as #[topic],
  plus admin).
- add_asset() emits AddAssetEvent after writing to storage.
- remove_asset() emits RemoveAssetEvent only when the asset key existed (the
  remove is otherwise a no-op).
- Tests verify both events via env.events().all() (exact topics + data
  reconstructed from the generated Event impl), and that removing a
  non-whitelisted asset emits nothing.

cargo test (52 passing) and cargo clippy --all-targets -- -D warnings pass.
@coderabbitai

coderabbitai Bot commented Jun 28, 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: 80f7af7d-4b13-4d96-ad0f-24ac74966a6e

📥 Commits

Reviewing files that changed from the base of the PR and between 78efaba and 2d05ba0.

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

📝 Walkthrough

Walkthrough

Two new #[contractevent] structs, AddAssetEvent and RemoveAssetEvent, are defined in the agent-vault contract. add_asset now publishes AddAssetEvent and remove_asset publishes RemoveAssetEvent (only when the asset was whitelisted). Three new tests verify correct event emission and non-emission.

Asset Whitelist Events

Layer / File(s) Summary
Event structs, emission, and tests
contracts/agent-vault/src/lib.rs, contracts/agent-vault/src/tests.rs
AddAssetEvent and RemoveAssetEvent structs are defined with asset and admin fields; add_asset and remove_asset publish the respective events after storage writes; three tests assert correct topic/data for add, remove, and no-op remove cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • clevercon-protocol/clevercon#25: Introduced the add_asset/remove_asset whitelist functions that this PR now extends with event emission.
  • clevercon-protocol/clevercon#47: Modified the same add_asset and remove_asset entrypoints to return Result<_, VaultError>, directly affecting the functions where events are now emitted.

Poem

🐇 Hop hop, the whitelist speaks!
No more silent storage tweaks.
AddAssetEvent flies on-chain,
RemoveAssetEvent joins the game.
Indexers cheer, no more polling pain!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: emitting whitelist add/remove events in agent-vault.
Linked Issues check ✅ Passed The described changes match the issue: new events, emissions in add/remove paths, and tests for event output.
Out of Scope Changes check ✅ Passed All described changes are confined to whitelist event emission and its tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/whitelist-events-issue-37

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

@Bosun-Josh121

Copy link
Copy Markdown
Collaborator

LGTM. Please resolve small conflict in tests @Itodo-S

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]: Emit events when assets are added or removed from the whitelist

2 participants