Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: removals #189

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 7 additions & 69 deletions contracts/VaultV3.vy
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ event RoleSet:
account: indexed(address)
role: indexed(Roles)

event RoleStatusChanged:
role: indexed(Roles)
status: indexed(RoleStatusChange)

# STORAGE MANAGEMENT EVENTS
event UpdateRoleManager:
role_manager: indexed(address)
Expand Down Expand Up @@ -204,10 +200,6 @@ enum Rounding:
ROUND_DOWN
ROUND_UP

enum RoleStatusChange:
OPENED
CLOSED

# IMMUTABLE #
# Underlying token used by the vault.
ASSET: immutable(ERC20)
Expand All @@ -224,14 +216,14 @@ default_queue: public(DynArray[address, MAX_QUEUE])
# Should the vault use the default_queue regardless whats passed in.
use_default_queue: public(bool)

### ACCOUNTING ###
# ERC20 - amount of shares per account
balance_of: HashMap[address, uint256]
# ERC20 - owner -> (spender -> amount)
allowance: public(HashMap[address, HashMap[address, uint256]])
# Total amount of shares that are currently minted including those locked.
# NOTE: To get the ERC20 compliant version user totalSupply().
total_supply: public(uint256)

# Total amount of assets that has been deposited in strategies.
total_debt: uint256
# Current assets held in the vault contract. Replacing balanceOf(this) to avoid price_per_share manipulation.
Expand All @@ -240,16 +232,18 @@ total_idle: uint256
minimum_total_idle: public(uint256)
# Maximum amount of tokens that the vault can accept. If totalAssets > deposit_limit, deposits will revert.
deposit_limit: public(uint256)

### PERIPHERY ###
# Contract that charges fees and can give refunds.
accountant: public(address)
# Contract to control the deposit limit.
deposit_limit_module: public(address)
# Contract to control the withdraw limit.
withdraw_limit_module: public(address)

### ROLES ###
# HashMap mapping addresses to their roles
roles: public(HashMap[address, Roles])
# HashMap mapping roles to their permissioned state. If false, the role is not open to the public.
open_roles: public(HashMap[Roles, bool])
# Address that can add and remove roles to addresses.
role_manager: public(address)
# Temporary variable to store the address of the next role_manager until the role is accepted.
Expand Down Expand Up @@ -343,20 +337,6 @@ def _approve(owner: address, spender: address, amount: uint256) -> bool:
log Approval(owner, spender, amount)
return True

@internal
def _increase_allowance(owner: address, spender: address, amount: uint256) -> bool:
new_allowance: uint256 = self.allowance[owner][spender] + amount
self.allowance[owner][spender] = new_allowance
log Approval(owner, spender, new_allowance)
return True

@internal
def _decrease_allowance(owner: address, spender: address, amount: uint256) -> bool:
new_allowance: uint256 = self.allowance[owner][spender] - amount
self.allowance[owner][spender] = new_allowance
log Approval(owner, spender, new_allowance)
return True

@internal
def _permit(
owner: address,
Expand Down Expand Up @@ -1471,8 +1451,8 @@ def setProfitMaxUnlockTime(new_profit_max_unlock_time: uint256):
# ROLE MANAGEMENT #
@internal
def _enforce_role(account: address, role: Roles):
# Make sure the sender either holds the role or it has been opened.
assert role in self.roles[account] or self.open_roles[role], "not allowed"
# Make sure the sender holds the role.
assert role in self.roles[account], "not allowed"

@external
def set_role(account: address, role: Roles):
Expand Down Expand Up @@ -1515,28 +1495,6 @@ def remove_role(account: address, role: Roles):
self.roles[account] = self.roles[account] & ~role

log RoleSet(account, self.roles[account])

@external
def set_open_role(role: Roles):
"""
@notice Set a role to be open.
@param role The role to set.
"""
assert msg.sender == self.role_manager
self.open_roles[role] = True

log RoleStatusChanged(role, RoleStatusChange.OPENED)

@external
def close_open_role(role: Roles):
"""
@notice Close a opened role.
@param role The role to close.
"""
assert msg.sender == self.role_manager
self.open_roles[role] = False

log RoleStatusChanged(role, RoleStatusChange.CLOSED)

@external
def transfer_role_manager(role_manager: address):
Expand Down Expand Up @@ -1852,26 +1810,6 @@ def transferFrom(sender: address, receiver: address, amount: uint256) -> bool:
return self._transfer_from(sender, receiver, amount)

## ERC20+4626 compatibility
@external
def increaseAllowance(spender: address, amount: uint256) -> bool:
"""
@notice Increase the allowance for a spender.
@param spender The address to increase the allowance for.
@param amount The amount to increase the allowance by.
@return True if the increase was successful.
"""
return self._increase_allowance(msg.sender, spender, amount)

@external
def decreaseAllowance(spender: address, amount: uint256) -> bool:
"""
@notice Decrease the allowance for a spender.
@param spender The address to decrease the allowance for.
@param amount The amount to decrease the allowance by.
@return True if the decrease was successful.
"""
return self._decrease_allowance(msg.sender, spender, amount)

@external
def permit(
owner: address,
Expand Down
37 changes: 0 additions & 37 deletions tests/unit/vault/test_erc20.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,43 +55,6 @@ def test_approve__with_amount__approve(fish, fish_amount, bunny, asset, create_v
assert vault.allowance(fish, bunny) == fish_amount


def test_increase_allowance__with_amount__approve(
fish, fish_amount, bunny, asset, create_vault
):
vault = create_vault(asset)

tx = vault.increaseAllowance(bunny.address, fish_amount, sender=fish)
event = list(tx.decode_logs(vault.Approval))

assert len(event) == 1
assert event[0].owner == fish
assert event[0].spender == bunny
assert event[0].value == fish_amount

assert vault.allowance(fish, bunny) == fish_amount


def test_decrease_allowance__with_amount__approve(
fish, fish_amount, bunny, asset, create_vault
):
vault = create_vault(asset)
decrease_amount = fish_amount // 2
final_allowance = fish_amount - decrease_amount

vault.approve(bunny.address, fish_amount, sender=fish)
assert vault.allowance(fish, bunny) == fish_amount

tx = vault.decreaseAllowance(bunny.address, decrease_amount, sender=fish)
event = list(tx.decode_logs(vault.Approval))

assert len(event) == 1
assert event[0].owner == fish
assert event[0].spender == bunny
assert event[0].value == final_allowance

assert vault.allowance(fish, bunny) == final_allowance


def test_transfer_from__with_approval__transfer(
fish, fish_amount, bunny, doggie, asset, create_vault, user_deposit
):
Expand Down
Loading
Loading