Skip to content

[Task]: Emit an InitEvent when CleverVault is initialized #63

Description

@grantfox-oss

init() is the single most important lifecycle moment for the contract — it sets the admin, records the USDC SAC address, and whitelists USDC. Yet it emits no event; it only writes a log! line, which is not part of the durable event stream that indexers and explorers consume. Every other state-changing entry point (deposit, withdraw, pause, update_admin, …) publishes a #[contractevent]. Initialization should too, so downstream tooling can detect deployment/init deterministically and capture the initial admin and asset without a separate get_admin() round-trip.

Add the event struct and publish it at the end of init:

#[contractevent]
pub struct InitEvent {
    #[topic]
    pub admin: Address,
    pub usdc_sac: Address,
}

// at the end of init(), before Ok(()):
InitEvent { admin: admin.clone(), usdc_sac: usdc_sac.clone() }.publish(&env);

Because init can only ever succeed once (guarded by AlreadyInitialized), the event is emitted exactly once per contract instance.

Acceptance criteria

  • InitEvent { admin, usdc_sac } is defined with #[contractevent], admin as a #[topic]
  • init publishes InitEvent on success
  • A test asserts the event is present in env.events() after init with the correct admin and asset
  • A second init still fails with AlreadyInitialized and emits no additional event
  • cargo test and cargo clippy --all-targets -- -D warnings pass

Relevant files

  • contracts/agent-vault/src/lib.rs (event struct + init)
  • contracts/agent-vault/src/tests.rs

Notes for contributors

If you'd like to work on this, comment below so we can assign it to you.
Questions welcome — see CONTRIBUTING.md for setup
and workflow.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions