Skip to content

Commit

Permalink
chore: renaming and code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrung committed Jan 10, 2025
1 parent 3aca028 commit 8054e39
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 106 deletions.
20 changes: 8 additions & 12 deletions contracts/FixedRewards.vy
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"""

interface RewardManager:
def send_reward_token(_reward_receiver: address, _amount: uint256): nonpayable
def send_reward_token(_receiving_gauge: address, _amount: uint256): nonpayable

# State Variables
managers: public(DynArray[address, 3]) # Changed from owner to managers
reward_manager_address: public(address)
reward_receiver_address: public(address)
receiving_gauge_address: public(address)
min_epoch_duration: public(uint256)

is_setup_complete: public(bool)
Expand All @@ -30,7 +30,7 @@ VERSION: constant(String[8]) = "0.9.0"

event SetupCompleted:
reward_manager_address: address
reward_receiver_address: address
receiving_gauge_address: address
min_epoch_duration: uint256
timestamp: uint256

Expand All @@ -54,34 +54,31 @@ def __init__(_managers: DynArray[address, 3]):
self.min_epoch_duration = WEEK

@external
def setup(_reward_manager_address: address, _reward_receiver_address: address, _min_epoch_duration: uint256) -> bool:
def setup(_reward_manager_address: address, _receiving_gauge_address: address, _min_epoch_duration: uint256):
"""
@notice Set the reward manager and receiver addresses (can only be set once)
@param _reward_manager_address Address of the RewardManager contract
@param _reward_receiver_address Address of the RewardReceiver contract
@param _receiving_gauge_address Address of the RewardReceiver contract
@param _min_epoch_duration Minimum epoch duration in seconds
@return bool Setup success
"""
assert msg.sender in self.managers, "only managers can call this function"
assert not self.is_setup_complete, "Setup already completed"
assert 3 * WEEK / 7 <= _min_epoch_duration and _min_epoch_duration <= WEEK * 4 * 12, 'epoch duration must be between 3 days and a year'

self.reward_manager_address = _reward_manager_address
self.reward_receiver_address = _reward_receiver_address
self.receiving_gauge_address = _receiving_gauge_address
self.min_epoch_duration = _min_epoch_duration

self.is_setup_complete = True

log SetupCompleted(_reward_manager_address, _reward_receiver_address, _min_epoch_duration, block.timestamp)
log SetupCompleted(_reward_manager_address, _receiving_gauge_address, _min_epoch_duration, block.timestamp)

return True

@external
def set_reward_epochs(_reward_epochs: DynArray[uint256, 52]):
"""
@notice Set the reward epochs in reverse order: last value is the first to be distributed, first value is the last to be distributed
@param _reward_epochs List of reward amounts ordered from first to last epoch
@return bool Setting success
"""
assert msg.sender in self.managers, "only managers can call this function"
assert not self.is_reward_epochs_set, "Reward epochs can only be set once"
Expand All @@ -97,7 +94,6 @@ def set_reward_epochs(_reward_epochs: DynArray[uint256, 52]):
def distribute_reward():
"""
@notice Distribute rewards for the current epoch if conditions are met
@return bool Distribution success
"""
assert msg.sender in self.managers, "only managers can call this function"
assert self.is_setup_complete, "Setup not completed"
Expand All @@ -119,7 +115,7 @@ def distribute_reward():
self.last_reward_distribution_time = block.timestamp

# Call reward manager to send reward
RewardManager(self.reward_manager_address).send_reward_token(self.reward_receiver_address, current_reward_amount)
RewardManager(self.reward_manager_address).send_reward_token(self.receiving_gauge_address, current_reward_amount)

log RewardDistributed(
current_reward_amount,
Expand Down
24 changes: 12 additions & 12 deletions contracts/RewardManager.vy
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,42 @@ VERSION: constant(String[8]) = "0.9.0"

managers: public(DynArray[address, 30])
reward_token: public(address)
reward_receivers: public(DynArray[address, 20])
receiving_gauges: public(DynArray[address, 20])
recovery_address: public(address)


@external
def __init__(_managers: DynArray[address, 30], _reward_token: address, _reward_receivers: DynArray[address, 20], _recovery_address: address):
def __init__(_managers: DynArray[address, 30], _reward_token: address, _receiving_gauges: DynArray[address, 20], _recovery_address: address):
"""
@notice Contract constructor
@param _managers set managers who can send reward token to gauges
@param _reward_token set reward token address
@param _reward_receivers allowed gauges to receiver reward
@param _receiving_gauges allowed gauges to receiver reward
@param _recovery_address set recovery address
"""
self.managers = _managers
self.reward_token = _reward_token
self.reward_receivers = _reward_receivers
self.receiving_gauges = _receiving_gauges
self.recovery_address = _recovery_address

@external
def send_reward_token(_reward_receiver: address, _amount: uint256, _epoch: uint256 = WEEK):
def send_reward_token(_receiving_gauge: address, _amount: uint256, _epoch: uint256 = WEEK):
"""
@notice send reward token from contract to gauge
@param _reward_receiver gauges to receiver reward
@param _receiving_gauge gauges to receiver reward
@param _amount The amount of reward token being sent
@param _epoch The duration the rewards are distributed across in seconds. Between 3 days and a year, week by default
"""
assert msg.sender in self.managers, 'only reward managers can call this function'
assert _reward_receiver in self.reward_receivers, 'only reward receiver which are allowed'
assert _receiving_gauge in self.receiving_gauges, 'only reward receiver which are allowed'
assert 3 * WEEK / 7 <= _epoch and _epoch <= WEEK * 4 * 12, 'epoch duration must be between 3 days and a year'
assert ERC20(self.reward_token).approve(_reward_receiver, _amount, default_return_value=True)
assert ERC20(self.reward_token).approve(_receiving_gauge, _amount, default_return_value=True)
# legacy gauges have no epoch parameter
# new deposit_reward_token has epoch parameter default to WEEK
if _epoch == WEEK:
LegacyGauge(_reward_receiver).deposit_reward_token(self.reward_token, _amount)
LegacyGauge(_receiving_gauge).deposit_reward_token(self.reward_token, _amount)
else:
Gauge(_reward_receiver).deposit_reward_token(self.reward_token, _amount, _epoch)
Gauge(_receiving_gauge).deposit_reward_token(self.reward_token, _amount, _epoch)


@external
Expand All @@ -79,9 +79,9 @@ def get_all_managers() -> DynArray[address, 30]:

@external
@view
def get_all_reward_receivers() -> DynArray[address, 20]:
def get_all_receiving_gauges() -> DynArray[address, 20]:
"""
@notice Get all reward receivers
@return DynArray[address, 20] list containing all reward receivers
"""
return self.reward_receivers
return self.receiving_gauges
4 changes: 2 additions & 2 deletions contracts/RecoveryGauge.vy → contracts/TestGauge.vy
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# @version 0.3.10
"""
@title RecoveryGauge
@title TestGauge
@author martinkrung for curve.fi
@license MIT
@notice test gauge for testing and to recover token
@notice test gauge for testing
"""

from vyper.interfaces import ERC20
Expand Down
2 changes: 1 addition & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export GAUGE_CRVUSD_USDC="0x00000.."
export GAUGE_ALLOWLIST="$GAUGE_CRVUSD_USDT,GAUGE_CRVUSD_USDC" # comma seperated addresses, no "," at the end, up to 20


export EXISTING_RECOVERY_GAUGE="0x00000.."
export EXISTING_TEST_GAUGE="0x00000.."


# alchemy
Expand Down
8 changes: 4 additions & 4 deletions scripts/deploy_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
REWARD_MANAGERS = os.getenv('REWARD_MANAGERS')
REWARD_TOKEN = os.getenv('REWARD_TOKEN')
RECOVERY_ADDRESS = os.getenv('RECOVERY_ADDRESS')
# EXISTING_RECOVERY_GAUGE = os.getenv('EXISTING_RECOVERY_GAUGE')
# EXISTING_TEST_GAUGE = os.getenv('EXISTING_TEST_GAUGE')

REWARD_TOKEN_TESTNET = os.getenv('REWARD_TOKEN_TESTNET')
GAUGE_ALLOWLIST = os.getenv('GAUGE_ALLOWLIST')
Expand All @@ -35,10 +35,10 @@ def info(ecosystem, provider, account, network):
@account_option()
def deploy(network, provider, account):
"""
if EXISTING_RECOVERY_GAUGE is None:
recovery_gauge = account.deploy(project.RecoveryGauge, REWARD_TOKEN, RECOVERY_ADDRESS, max_priority_fee="1000 wei", max_fee="0.1 gwei", gas_limit="100000")
if EXISTING_TEST_GAUGE is None:
test_gauge = account.deploy(project.TestGauge, REWARD_TOKEN, RECOVERY_ADDRESS, max_priority_fee="1000 wei", max_fee="0.1 gwei", gas_limit="100000")
else:
recovery_gauge = EXISTING_RECOVERY_GAUGE
test_gauge = EXISTING_TEST_GAUGE
gauges.append(recovery_gauge)
"""
Expand Down
11 changes: 5 additions & 6 deletions tests/FixedRewards/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ def lost_token(project, alice, charlie):
print(balance)
return lost_token


@pytest.fixture(scope="module")
def recovery_gauge(project, alice, charlie, diana, reward_token):
def test_gauge(project, alice, charlie, diana, reward_token):
# bob manager address
# diana is recovery address
gauge = alice.deploy(project.RecoveryGauge, reward_token, diana)
gauge = alice.deploy(project.TestGauge, reward_token, diana)
return gauge

@pytest.fixture(scope="module")
Expand All @@ -36,15 +35,15 @@ def fixed_rewards(project, alice, bob, charlie):
return contract

@pytest.fixture(scope="module")
def reward_manager(project, alice, bob, charlie, diana, reward_token, recovery_gauge, fixed_rewards):
def reward_manager(project, alice, bob, charlie, diana, reward_token, test_gauge, fixed_rewards):
# bob manager address
# diana is recovery address
print(fixed_rewards)
reward_manager_contract = alice.deploy(project.RewardManager, [bob, charlie, fixed_rewards], reward_token, [recovery_gauge], diana)
reward_manager_contract = alice.deploy(project.RewardManager, [bob, charlie, fixed_rewards], reward_token, [test_gauge], diana)
reward_token.approve(reward_manager_contract, 10 ** 19, sender=bob)
print(reward_manager_contract)
# Setup the reward manager and receiver
#fixed_rewards.setup(reward_manager.address, recovery_gauge.address, sender=alice)
#fixed_rewards.setup(reward_manager.address, test_gauge.address, sender=alice)

amount = 10 ** 19
reward_token.transfer(reward_manager_contract, amount, sender=bob)
Expand Down
Loading

0 comments on commit 8054e39

Please sign in to comment.