Skip to content

Commit

Permalink
style: format vyper code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoCentonze committed Aug 27, 2024
1 parent d2fe418 commit 2af4490
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 85 deletions.
1 change: 1 addition & 0 deletions contracts/fee_splitter/ControllerFactory.vyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
def controllers(index: uint256) -> address:
...


@external
@view
def n_collaterals() -> uint256:
Expand Down
4 changes: 4 additions & 0 deletions contracts/fee_splitter/ControllerMulticlaim.vy
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ controllers: public(DynArray[Controller, MAX_CONTROLLERS])
# maximum number of claims in a single transaction
MAX_CONTROLLERS: constant(uint256) = 100


@deploy
def __init__(_factory: ControllerFactory):
assert _factory.address != empty(address), "zeroaddr: factory"

factory = _factory


def claim_controller_fees(controllers: DynArray[Controller, MAX_CONTROLLERS]):
"""
@notice Claims admin fees from a list of controllers.
Expand All @@ -43,6 +45,7 @@ def claim_controller_fees(controllers: DynArray[Controller, MAX_CONTROLLERS]):
raise "controller: not in factory"
extcall c.collect_fees()


@nonreentrant
@external
def update_controllers():
Expand All @@ -60,6 +63,7 @@ def update_controllers():
self.allowed_controllers[c] = True
self.controllers.append(c)


@view
@external
def n_controllers() -> uint256:
Expand Down
1 change: 1 addition & 0 deletions contracts/fee_splitter/DynamicWeight.vyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
def supportsInterface(interface_id: bytes4) -> bool:
...


@view
@external
def weight() -> uint256:
Expand Down
36 changes: 29 additions & 7 deletions contracts/fee_splitter/FeeSplitter.vy
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,25 @@ initializes: multiclaim
initializes: ownable
exports: (ownable.__interface__, multiclaim.__interface__)


event SetWeights:
distribution_weight: uint256


event SetReceivers: pass


event FeeDispatched:
receiver: address
weight: uint256


struct Receiver:
addr: address
weight: uint256
addr: address
weight: uint256


version: public(constant(String[8])) = "0.1.0" # no guarantees on abi stability
version: public(constant(String[8])) = "0.1.0" # no guarantees on abi stability

# maximum number of splits
MAX_RECEIVERS: constant(uint256) = 100
Expand All @@ -48,8 +53,14 @@ receivers: public(DynArray[Receiver, MAX_RECEIVERS])

crvusd: immutable(IERC20)


@deploy
def __init__(_crvusd: IERC20, _factory: multiclaim.ControllerFactory, receivers: DynArray[Receiver, MAX_RECEIVERS], owner: address):
def __init__(
_crvusd: IERC20,
_factory: multiclaim.ControllerFactory,
receivers: DynArray[Receiver, MAX_RECEIVERS],
owner: address,
):
"""
@notice Contract constructor
@param _crvusd The address of the crvUSD token contract
Expand Down Expand Up @@ -87,13 +98,17 @@ def _is_dynamic(addr: address) -> bool:
response: Bytes[32] = b""
success, response = raw_call(
addr,
abi_encode(DYNAMIC_WEIGHT_EIP165_ID, method_id=method_id("supportsInterface(bytes4)")),
abi_encode(
DYNAMIC_WEIGHT_EIP165_ID,
method_id=method_id("supportsInterface(bytes4)"),
),
max_outsize=32,
is_static_call=True,
revert_on_failure=False
revert_on_failure=False,
)
return success and convert(response, bool) or len(response) > 32


def _set_receivers(receivers: DynArray[Receiver, MAX_RECEIVERS]):
assert len(receivers) > 0, "receivers: empty"
total_weight: uint256 = 0
Expand All @@ -107,9 +122,14 @@ def _set_receivers(receivers: DynArray[Receiver, MAX_RECEIVERS]):

log SetReceivers()


@nonreentrant
@external
def dispatch_fees(controllers: DynArray[multiclaim.Controller, multiclaim.MAX_CONTROLLERS]=[]):
def dispatch_fees(
controllers: DynArray[
multiclaim.Controller, multiclaim.MAX_CONTROLLERS
] = []
):
"""
@notice Claim fees from all controllers and distribute them
@param controllers The list of controllers to claim fees from (default: all)
Expand Down Expand Up @@ -160,6 +180,7 @@ def set_receivers(receivers: DynArray[Receiver, MAX_RECEIVERS]):

self._set_receivers(receivers)


@view
@external
def excess_receiver() -> address:
Expand All @@ -173,6 +194,7 @@ def excess_receiver() -> address:
receivers_length: uint256 = len(self.receivers)
return self.receivers[receivers_length - 1].addr


@view
@external
def n_receivers() -> uint256:
Expand Down
1 change: 1 addition & 0 deletions contracts/manual/IBribeLogic.vyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MAX_BRIBE_PAYLOAD_SIZE: constant(uint256) = 1024


@external
def bribe(gauge: address, amount: uint256, data: Bytes[MAX_BRIBE_PAYLOAD_SIZE]):
...
62 changes: 49 additions & 13 deletions contracts/manual/IncentivesManager.vy
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,46 @@

from ethereum.ercs import IERC20
from ethereum.ercs import IERC165

implements: IERC165

from snekmate.auth.interfaces import IAccessControl

implements: IAccessControl

import IBribeLogic

from snekmate.auth import access_control

initializes: access_control

exports: access_control.__interface__

version: public(constant(String[8])) = "0.1.0" # (no guarantees on ABI stability)
version: public(constant(String[8])) = "0.1.0" # no guarantees on abi stability


event SetGaugeCap:
gauge: address
cap: uint256


event SetBribeLogic:
bribe_logic: address


event UpdateIncentivesState:
locked: bool


struct IncentivePayload:
gauge: address
amount: uint256
data: Bytes[MAX_DATA_SIZE]
gauge: address
amount: uint256
data: Bytes[MAX_DATA_SIZE]

MAX_INCENTIVES_PER_GAUGE: public(constant(uint256)) = 10**23 # 100.000 tokens (crvUSD)

MAX_INCENTIVES_PER_GAUGE: public(constant(uint256)) = (
10**23
) # 100.000 tokens (crvUSD)
MAX_BRIBES: constant(uint256) = 1000
MAX_DATA_SIZE: constant(uint256) = 1024

Expand All @@ -68,7 +78,13 @@ incentives_locked: public(bool)


@deploy
def __init__(_managed_asset: IERC20, bribe_manager: address, bribe_proposer: address, token_rescuer: address, emergency_admin: address):
def __init__(
_managed_asset: IERC20,
bribe_manager: address,
bribe_proposer: address,
token_rescuer: address,
emergency_admin: address,
):
"""
@dev After this function is called ownership of the contract is
renounced making it impossible.
Expand Down Expand Up @@ -98,6 +114,7 @@ def __init__(_managed_asset: IERC20, bribe_manager: address, bribe_proposer: add
# revoke admin role from deployer
access_control._revoke_role(access_control.DEFAULT_ADMIN_ROLE, msg.sender)


@external
def set_gauge_cap(gauge: address, cap: uint256):
"""
Expand All @@ -121,6 +138,7 @@ def set_gauge_cap(gauge: address, cap: uint256):

log SetGaugeCap(gauge, cap)


@external
def set_bribe_logic(bribe_logic: address):
"""
Expand All @@ -139,6 +157,7 @@ def set_bribe_logic(bribe_logic: address):

log SetBribeLogic(bribe_logic)


@external
def update_incentives_batch(payloads: DynArray[IncentivePayload, MAX_BRIBES]):
"""
Expand All @@ -162,8 +181,12 @@ def update_incentives_batch(payloads: DynArray[IncentivePayload, MAX_BRIBES]):
self._update_incentive(i.gauge, i.amount, i.data)


def _update_incentive(gauge: address, amount: uint256, data: Bytes[MAX_DATA_SIZE]):
assert amount > 0 and amount <= self.gauge_caps[gauge], "manager: invalid bribe amount"
def _update_incentive(
gauge: address, amount: uint256, data: Bytes[MAX_DATA_SIZE]
):
assert (
amount > 0 and amount <= self.gauge_caps[gauge]
), "manager: invalid bribe amount"

self.pending_gauges.append(gauge)
self.total_incentives += amount
Expand All @@ -184,6 +207,7 @@ def confirm_batch():

log UpdateIncentivesState(True)


@external
def cancel_batch():
"""
Expand All @@ -197,6 +221,7 @@ def cancel_batch():

log UpdateIncentivesState(False)


@external
def post_incentives():
"""
Expand All @@ -205,17 +230,23 @@ def post_incentives():
as long as the `BRIBE_PROPOSER` has designated the incentives
and confirmed the batch.
"""
assert not access_control.hasRole[BRIBE_PROPOSER][msg.sender], "manager: proposer can't post"
assert not access_control.hasRole[BRIBE_PROPOSER][
msg.sender
], "manager: proposer can't post"
assert self.incentives_locked, "manager: batch yet to be confirmed"
extcall managed_asset.transfer(self.bribe_logic.address, self.total_incentives)
extcall managed_asset.transfer(
self.bribe_logic.address, self.total_incentives
)
for gauge: address in self.pending_gauges:
amount: uint256 = self.amount_for_gauge[gauge]
data: Bytes[MAX_DATA_SIZE] = self.data_for_gauge[gauge]
extcall self.bribe_logic.bribe(gauge, amount, data)
assert staticcall managed_asset.balanceOf(self.bribe_logic.address) == 0, "manager: bribe not fully spent"
assert (
staticcall managed_asset.balanceOf(self.bribe_logic.address) == 0
), "manager: bribe not fully spent"
self.incentives_locked = False
self.total_incentives = 0
Expand All @@ -232,10 +263,15 @@ def recover_erc20(token: address, receiver: address):
"""
access_control._check_role(TOKEN_RESCUER, msg.sender)
assert token != managed_asset.address, "manager: cannot recover managed asset"
assert (
token != managed_asset.address
), "manager: cannot recover managed asset"
balance: uint256 = staticcall IERC20(token).balanceOf(self)
assert extcall IERC20(token).transfer(receiver, balance, default_return_value=True)
assert extcall IERC20(token).transfer(
receiver, balance, default_return_value=True
)
@external
def emergency_migration(receiver: address):
Expand Down
14 changes: 8 additions & 6 deletions contracts/markets/PaladinQuest.vyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ def createRangedQuest(
maxRewardPerVote: uint256,
totalRewardAmount: uint256,
feeAmount: uint256,
voteType: uint8, # QuestDataTypes.QuestVoteType : 0 == normal, 1 == blacklist, 2 == whitelist
closeType: uint8, # QuestDataTypes.QuestCloseType : 0 == normal, 1 == rollover, 2 == distribute
voterList: DynArray[address, 10]) -> uint256:
voteType: uint8, # QuestDataTypes.QuestVoteType : 0 == normal, 1 == blacklist, 2 == whitelist
closeType: uint8, # QuestDataTypes.QuestCloseType : 0 == normal, 1 == rollover, 2 == distribute
voterList: DynArray[address, 10],
) -> uint256:
...


@external
def withdrawUnusedRewards(
questID: uint256,
recipient: address):
def withdrawUnusedRewards(questID: uint256, recipient: address):
...


@view
@external
def questWithdrawableAmount(questID: uint256) -> uint256:
...


@view
@external
def customPlatformFeeRatio(creator: address) -> uint256:
Expand Down
Loading

0 comments on commit 2af4490

Please sign in to comment.