feat(contract): add bounded withdrawal limits and anti-drain policy (#77) - #87
Open
woahwhattheheck wants to merge 1 commit into
Open
woahwhattheheck wants to merge 1 commit into
woahwhattheheck wants to merge 1 commit into
Conversation
…ieldVault-Org#77) Add per-operation and rolling-period underlying-asset caps shared by withdraw and withdraw_batch, plus admin reset and emergency override with auditable events. Defaults stay unlimited (0) until configured. Bump on-chain version to 3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #77.
Adds bounded withdrawal / anti-drain controls so a compromised caller or integration bug cannot drain a vault faster than operators can respond.
Behavior
u128).0for either cap means unlimited (default), so existing flows stay permissive until configured.max_per_op): each singlewithdrawand eachwithdraw_batchleg must redeem ≤ this amount.max_per_period+period_secs): aggregate redeemed assets in the current ledger-timestamp window; window auto-rolls when elapsed ≥period_secs.withdraw_batch: validates every leg and the sum against the period aggregate before any burn/transfer, so splitting cannot bypass the period limit. Empty batch →EmptyBatch.set_withdraw_limits(max_per_op, max_per_period, period_secs)→wd_limitsreset_withdraw_period()→wd_reset(clears usage, starts window at now)set_withdraw_limits_override(enabled)→wd_override(skips checks; does not record usage)WithdrawLimitExceeded/WithdrawPeriodLimitExceeded.version()bumped to 3 (same major bump as sibling PRs; does not regress below 3).Design tradeoff
Kept the change thin and high-confidence: shared
enforce_withdraw_limits+ one batch entrypoint, rather than a custody redesign or per-user rate limiter. Defaults remain unlimited so integrators opt in by setting caps.Tests
Coverage added for: default unlimited, per-op boundary, period aggregate + window roll, batch cannot bypass period, batch per-op leg + empty batch, concurrent users sharing period budget, admin reset/override events + auth path, invalid period config, version 3.
Compatibility
Additive API + four new error codes. Happy-path withdraws with default (unlimited) limits behave as before. Integrators that configure caps must handle the new errors;
version()is now 3.