Skip to content

feat: per-vault deposit cap / max-TVL guard [NF-04] - #128

Merged
wumibals merged 9 commits into
LadderMine:mainfrom
soundsng:feat/nf-04-per-vault-deposit-cap-max-tvl
Jul 20, 2026
Merged

feat: per-vault deposit cap / max-TVL guard [NF-04]#128
wumibals merged 9 commits into
LadderMine:mainfrom
soundsng:feat/nf-04-per-vault-deposit-cap-max-tvl

Conversation

@soundsng

Copy link
Copy Markdown
Contributor

Summary

Adds a governance-controlled TVL cap to each tier vault (vault_l3, vault_l6, vault_l12) and a corresponding set_max_tvl / vault_capacity passthrough in VaultRouter.

Changes per vault (vault_l3, vault_l6, vault_l12)

  • Added DepositCapExceeded = 5 and Unauthorized = 6 to VaultError
  • Added DataKey::MaxTvl, DataKey::TotalBalance, and DataKey::Governance
  • initialize() now takes a governance: Address and max_tvl: i128 argument; defaults to 1,000,000 USDC if zero
  • deposit() now tracks TotalBalance and rejects with DepositCapExceeded if total_balance + amount > max_tvl
  • Added set_max_tvl(new_cap) — only callable by the registered Governance address
  • Added max_tvl() -> i128 and remaining_capacity() -> i128 read-only queries
  • withdraw() and early_exit() decrement TotalBalance on position close

VaultRouter changes

  • initialize() now takes governance: Address
  • Added set_max_tvl(tier, new_cap) — gates on Governance auth, then passes through to the tier vault
  • Added vault_capacity(tier) -> VaultCapacity { max_tvl, remaining } — frontend capacity indicators
  • error.rs gains DepositCapExceeded = 5

Tests

Each vault has new tests covering:

  • test_deposit_exactly_at_cap_succeeds
  • test_deposit_above_cap_rejected (#[should_panic(expected = "DepositCapExceeded")])
  • test_remaining_capacity_decreases_on_deposit
  • test_set_max_tvl_by_governance
  • test_set_max_tvl_non_governance_rejected (#[should_panic])
  • test_lower_cap_does_not_evict_existing_depositor

Acceptance Criteria

  • Deposits above max_tvl rejected with DepositCapExceeded
  • set_max_tvl only callable by Governance address
  • remaining_capacity() returns accurate value
  • Lowering cap does not affect existing depositors
  • Unit tests cover all boundary cases

closes #79

@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

@soundsng is attempting to deploy a commit to the wumibals' projects Team on Vercel.

A member of the Team first needs to authorize it.

…t-deposit-cap-max-tvl

# Conflicts:
#	contracts/vault_l12/src/lib.rs
#	contracts/vault_l12/src/test.rs
#	contracts/vault_l3/src/lib.rs
#	contracts/vault_l3/src/test.rs
#	contracts/vault_l6/src/lib.rs
#	contracts/vault_l6/src/test.rs
#	contracts/vault_router/src/error.rs
#	contracts/vault_router/src/lib.rs

@Leothosine Leothosine left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job

@wumibals
wumibals merged commit 352d912 into LadderMine:main Jul 20, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NF-04] [CONTRACT] Per-Vault Deposit Cap / Max-TVL Guard

4 participants