Skip to content

Emit an event when a provider's balance in an asset returns to zero via withdrawalΒ #139

Description

@Jagadeeshftw

πŸ“Œ Description

do_withdraw decrements pool.providers when a provider's remaining balance reaches zero β€” the mirror image of do_provide's first-contribution increment β€” but unlike the existing ("withdraw", provider, asset) event (which fires on every withdrawal regardless of size), there is no distinct signal for "this provider has now fully exited this asset's pool." Off-chain systems tracking active-provider counts per pool currently have to compare balances before and after each withdrawal event rather than reacting to a dedicated signal.

🧩 Requirements and context

  • Add an events::provider_exited helper in src/events.rs, mirroring the asset-onboarded event's pattern above but for the withdrawal side.
  • Call it from do_withdraw in src/lib.rs specifically when remaining == 0 (the same condition that decrements pool.providers).
  • Add a regression test confirming the event fires only on a full exit, not a partial withdrawal, and fires again correctly if the same provider re-enters and exits again later.

πŸ› οΈ Suggested execution

  • Add the event helper to src/events.rs.
  • Update do_withdraw in src/lib.rs to conditionally emit it alongside the existing liquidity_withdrawn event.
  • Add src/test.rs coverage and document the new topic in the README events list.

βœ… Acceptance criteria

  • A dedicated event fires when, and only when, a provider's balance in an asset reaches exactly zero via a withdrawal.
  • A partial withdrawal that leaves a nonzero balance does not fire the exit event.
  • The existing withdraw event continues to fire on every withdrawal as before.

πŸ”’ Security notes

Accurate provider-exit signaling helps off-chain risk monitoring detect a pool rapidly losing distinct liquidity providers (a leading indicator of a liquidity crunch) faster than reconstructing that signal from raw withdrawal amounts alone.

πŸ“‹ Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial Campaign | FWC26GrantFox official campaign issueenhancementNew feature or improvementsmart-contractSoroban/Rust smart contract work

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions