Skip to content

Feature: add get_total_withdrawn view function and running withdrawal counter #114

Description

@leojay-net

The contract tracks cumulative deposits via TotalDeposited but has no equivalent counter for withdrawals. Off-chain reconciliation requires expected_balance = total_deposited - total_withdrawn. Without total_withdrawn on-chain, operators must replay all withdrawal events or query the token balance directly, which does not account for fee collection or other outflows.

Proposed Solution

Add a TotalWithdrawn storage key and increment it on every successful withdraw call.

Implementation Notes

  • Add DataKey::TotalWithdrawn to instance storage; initialize to 0_i128 in init
  • In withdraw, after the token transfer succeeds, increment TotalWithdrawn with a checked add
  • Add get_total_withdrawn(env) -> Result<i128, Error> view function
  • Include TotalWithdrawn in any future event payloads

Acceptance Criteria

  • get_total_withdrawn returns 0 after initialization
  • After a 100-token withdrawal get_total_withdrawn returns 100
  • Multiple withdrawals accumulate correctly
  • A test verifies the counter after a sequence of deposits and withdrawals

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programcomplexity: trivial100 points - small bounded changeenhancementNew feature or requestsmart-contractSoroban / Rust contract work

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions