Skip to content

Commit

Permalink
feat: deposit limit module events (#43)
Browse files Browse the repository at this point in the history
* feat: added deposit limit events

* test: adding unit tests for events
  • Loading branch information
heswithme authored Oct 24, 2024
1 parent 7008ce2 commit 9d904c0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
41 changes: 38 additions & 3 deletions contracts/DepositLimitModule.vy
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,48 @@

"""
@title Temporary Deposit Limit Module for yearn vaults
@notice This contract temporarily controls deposits into a yearn vault and manages roles (admin and security_agent).
@dev Admins can appoint new admins and security_agents, while security_agents can pause or resume deposits.
This module will be removed once the vault is battle-tested and proven stable.
@notice This contract temporarily controls deposits into a yearn vault and
manages roles (admin and security_agent).
@dev Admins can appoint new admins and security_agents, while security_agents
can pause or resume deposits. This module will be removed once the vault is
battle-tested and proven stable.
@license Copyright (c) Curve.Fi, 2020-2024 - all rights reserved
@author curve.fi
@custom:security [email protected]
"""


################################################################
# INTERFACES #
################################################################


from interfaces import IVault


################################################################
# EVENTS #
################################################################


event DepositsPaused:
status: bool


event DepositLimitChanged:
new_deposit_limit: uint256


################################################################
# STORAGE #
################################################################


# Two main roles: admin and security_agent
is_admin: public(HashMap[address, bool])
is_security_agent: public(HashMap[address, bool])
Expand All @@ -31,10 +57,12 @@ max_deposit_limit: public(uint256)
# Stablecoin/Vault addresses
vault: public(immutable(IVault))


################################################################
# CONSTRUCTOR #
################################################################


@deploy
def __init__(
_vault: IVault,
Expand All @@ -56,6 +84,7 @@ def __init__(
# INTERNAL FUNCTIONS #
################################################################


@internal
def _set_admin(_address: address, is_admin: bool):
"""
Expand Down Expand Up @@ -84,6 +113,8 @@ def _set_deposits_paused(is_paused: bool):
"""
self.deposits_paused = is_paused

log DepositsPaused(is_paused)


@internal
def _set_deposit_limit(new_limit: uint256):
Expand All @@ -93,11 +124,14 @@ def _set_deposit_limit(new_limit: uint256):
"""
self.max_deposit_limit = new_limit

log DepositLimitChanged(new_limit)


################################################################
# EXTERNAL FUNCTIONS #
################################################################


@external
def set_admin(new_admin: address, is_admin: bool):
"""
Expand Down Expand Up @@ -148,6 +182,7 @@ def set_deposit_limit(new_limit: uint256):
# VIEW FUNCTIONS #
################################################################


@view
@external
def available_deposit_limit(receiver: address) -> uint256:
Expand Down
4 changes: 4 additions & 0 deletions tests/unitary/deposit_limit_module/test_set_deposit_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def test_default_behavior(deposit_limit_module, dev_multisig):
with boa.env.prank(dev_multisig):
deposit_limit_module.set_deposit_limit(new_limit)

# Verify event emission
events = deposit_limit_module.get_logs()
assert f"DepositLimitChanged(new_deposit_limit={new_limit}" in repr(events)

# Verify that max_deposit_limit has been updated correctly
assert deposit_limit_module.max_deposit_limit() == new_limit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def test_default_behavior(
with boa.env.prank(dev_multisig):
deposit_limit_module.set_deposits_paused(True)

# Verify event emission
events = deposit_limit_module.get_logs()
assert f"DepositsPaused(status={True}" in repr(events)

# Verify that deposits are paused
assert deposit_limit_module.deposits_paused()

Expand Down

0 comments on commit 9d904c0

Please sign in to comment.