A capstone vault combines everything: `HashMap` balances, `@nonreentrant` withdrawals, owner-gated admin functions, events for indexers, and careful checks-effects-interactions ordering.
balances: public(HashMap[address, uint256])
owner: public(address)
event Deposited:
user: indexed(address)
amount: uint256
@deploy
def __init__():
self.owner = msg.sender
@external
@payable
def deposit():
self.balances[msg.sender] += msg.value
log Deposited(user=msg.sender, amount=msg.value)
@external
@nonreentrant("withdraw")
def withdraw(amount: uint256):
assert self.balances[msg.sender] >= amount, "insufficient balance"
self.balances[msg.sender] -= amount
send(msg.sender, amount)
@external
def sweep_fees(to: address):
assert msg.sender == self.owner, "not owner"
send(to, self.balance)Every piece here maps back to an earlier topic: events for observability, HashMap for per-user accounting, nonreentrant plus checks-effects-interactions for safety, and an explicit owner check for admin actions — this is the shape of most production Vyper contracts.