Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Sep 12, 2024
1 parent 02a7d80 commit 8fa9cea
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions contracts/VaultFactory.vy
Original file line number Diff line number Diff line change
Expand Up @@ -170,33 +170,25 @@ def protocol_fee_config(vault: address = msg.sender) -> (uint16, address):
@return The protocol fee config for the msg sender.
"""
# If there is a custom protocol fee set we return it.
custom_data: uint256 = self.custom_protocol_fee_data[vault]
if custom_data & 1 == 1:
config_data: uint256 = self.custom_protocol_fee_data[vault]
if self._unpack_custom_flag(config_data):
# Always use the default fee recipient even with custom fees.
return (
self._unpack_protocol_fee(custom_data),
self._unpack_protocol_fee(config_data),
self._unpack_fee_recipient(self.default_protocol_fee_data)
)
else:
# Otherwise return the default config.
return self._default_protocol_fee_config(self.default_protocol_fee_data)
config_data = self.default_protocol_fee_data
return (
self._unpack_protocol_fee(config_data),
self._unpack_fee_recipient(config_data)
)

@view
@external
def use_custom_protocol_fee(vault: address) -> bool:
return self.custom_protocol_fee_data[vault] & 1 == 1

@view
@external
def custom_protocol_fee(vault: address) -> uint16:
return self._unpack_protocol_fee(self.custom_protocol_fee_data[vault])

@view
@internal
def _default_protocol_fee_config(config_data: uint256) -> (uint16, address):
fee: uint16 = self._unpack_protocol_fee(config_data)
recipient: address = self._unpack_fee_recipient(config_data)
return (fee, recipient)
return self._unpack_custom_flag(self.custom_protocol_fee_data[vault])

@view
@internal
Expand All @@ -208,6 +200,11 @@ def _unpack_protocol_fee(config_data: uint256) -> uint16:
def _unpack_fee_recipient(config_data: uint256) -> address:
return convert(shift(config_data, -24), address)

@view
@internal
def _unpack_custom_flag(config_data: uint256) -> bool:
return config_data & 1 == 1

@internal
def _pack_data(recipient: address, fee: uint16, custom: bool) -> uint256:
return shift(convert(recipient, uint256), 24) | shift(convert(fee, uint256), 8) | convert(custom, uint256)
Expand All @@ -230,7 +227,11 @@ def set_protocol_fee_bps(new_protocol_fee_bps: uint16):
assert recipient != empty(address), "no recipient"

# Set the new fee
self.default_protocol_fee_data = self._pack_data(recipient, new_protocol_fee_bps, False)
self.default_protocol_fee_data = self._pack_data(
recipient,
new_protocol_fee_bps,
False
)

log UpdateProtocolFeeBps(
self._unpack_protocol_fee(default_fee_data),
Expand All @@ -251,7 +252,11 @@ def set_protocol_fee_recipient(new_protocol_fee_recipient: address):
default_fee_data: uint256 = self.default_protocol_fee_data
old_recipient: address = self._unpack_fee_recipient(default_fee_data)

self.default_protocol_fee_data = self._pack_data(new_protocol_fee_recipient, self._unpack_protocol_fee(default_fee_data), False)
self.default_protocol_fee_data = self._pack_data(
new_protocol_fee_recipient,
self._unpack_protocol_fee(default_fee_data),
False
)

log UpdateProtocolFeeRecipient(
old_recipient,
Expand All @@ -273,7 +278,11 @@ def set_custom_protocol_fee_bps(vault: address, new_custom_protocol_fee: uint16)
assert new_custom_protocol_fee <= MAX_FEE_BPS, "fee too high"
assert self._unpack_fee_recipient(self.default_protocol_fee_data) != empty(address), "no recipient"

self.custom_protocol_fee_data[vault] = self._pack_data(empty(address), new_custom_protocol_fee, True)
self.custom_protocol_fee_data[vault] = self._pack_data(
empty(address),
new_custom_protocol_fee,
True
)

log UpdateCustomProtocolFee(vault, new_custom_protocol_fee)

Expand Down

0 comments on commit 8fa9cea

Please sign in to comment.