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
The contract tracks cumulative deposits via
TotalDepositedbut has no equivalent counter for withdrawals. Off-chain reconciliation requiresexpected_balance = total_deposited - total_withdrawn. Withouttotal_withdrawnon-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
TotalWithdrawnstorage key and increment it on every successfulwithdrawcall.Implementation Notes
DataKey::TotalWithdrawnto instance storage; initialize to0_i128ininitwithdraw, after the token transfer succeeds, incrementTotalWithdrawnwith a checked addget_total_withdrawn(env) -> Result<i128, Error>view functionTotalWithdrawnin any future event payloadsAcceptance Criteria
get_total_withdrawnreturns 0 after initializationget_total_withdrawnreturns 100