Skip to content

Commit

Permalink
Change for generalization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkeating committed Nov 1, 2024
1 parent 63bbf23 commit eb6f833
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
18 changes: 1 addition & 17 deletions src/GovernanceStaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ abstract contract GovernanceStaker is INotifiableRewardReceiver, Multicall, EIP7
/// @notice Emitted when a reward notifier address is enabled or disabled.
event RewardNotifierSet(address indexed account, bool isEnabled);

/// @notice Emitted when a surrogate contract is deployed.
event SurrogateDeployed(address indexed delegatee, address indexed surrogate);

/// @notice Thrown when an account attempts a call for which it lacks appropriate permission.
/// @param reason Human readable code explaining why the call is unauthorized.
/// @param caller The address that attempted the unauthorized call.
Expand Down Expand Up @@ -822,23 +819,10 @@ abstract contract GovernanceStaker is INotifiableRewardReceiver, Multicall, EIP7
_useNonce(msg.sender);
}

/// @notice Internal method which finds the existing surrogate contract—or deploys a new one if
/// none exists—for a given delegatee.
/// @param _delegatee Account for which a surrogate is sought.
/// @return _surrogate The address of the surrogate contract for the delegatee.
function _fetchOrDeploySurrogate(address _delegatee)
internal
virtual
returns (DelegationSurrogate _surrogate)
{
_surrogate = surrogates[_delegatee];

if (address(_surrogate) == address(0)) {
_surrogate = new DelegationSurrogateVotes(STAKE_TOKEN, _delegatee);
surrogates[_delegatee] = _surrogate;
emit SurrogateDeployed(_delegatee, address(_surrogate));
}
}
returns (DelegationSurrogate _surrogate);

/// @notice Internal convenience method which calls the `transferFrom` method on the stake token
/// contract and reverts on failure.
Expand Down
30 changes: 30 additions & 0 deletions src/GovernanceStakerDelegateSurrogateVotes.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.23;

import {DelegationSurrogate} from "src/DelegationSurrogate.sol";
import {DelegationSurrogateVotes} from "src/DelegationSurrogateVotes.sol";
import {GovernanceStaker} from "src/GovernanceStaker.sol";

abstract contract GovernanceStakerDelegateSurrogateVotes is GovernanceStaker {
/// @notice Emitted when a surrogate contract is deployed.
event SurrogateDeployed(address indexed delegatee, address indexed surrogate);

/// @notice Internal method which finds the existing surrogate contract—or deploys a new one if
/// none exists—for a given delegatee.
/// @param _delegatee Account for which a surrogate is sought.
/// @return _surrogate The address of the surrogate contract for the delegatee.
function _fetchOrDeploySurrogate(address _delegatee)
internal
virtual
override
returns (DelegationSurrogate _surrogate)
{
_surrogate = surrogates[_delegatee];

if (address(_surrogate) == address(0)) {
_surrogate = new DelegationSurrogateVotes(STAKE_TOKEN, _delegatee);
surrogates[_delegatee] = _surrogate;
emit SurrogateDeployed(_delegatee, address(_surrogate));
}
}
}
4 changes: 3 additions & 1 deletion test/harnesses/GovernanceStakerHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity ^0.8.23;

import {DelegationSurrogateVotes} from "src/DelegationSurrogateVotes.sol";
import {GovernanceStaker} from "src/GovernanceStaker.sol";
import {GovernanceStakerDelegateSurrogateVotes} from
"src/GovernanceStakerDelegateSurrogateVotes.sol";

import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";
import {SafeERC20} from "openzeppelin/token/ERC20/utils/SafeERC20.sol";
Expand All @@ -11,7 +13,7 @@ import {IERC20Delegates} from "src/interfaces/IERC20Delegates.sol";
import {IEarningPowerCalculator} from "src/interfaces/IEarningPowerCalculator.sol";
import {DelegationSurrogate} from "src/DelegationSurrogate.sol";

contract GovernanceStakerHarness is GovernanceStaker {
contract GovernanceStakerHarness is GovernanceStaker, GovernanceStakerDelegateSurrogateVotes {
constructor(
IERC20 _rewardsToken,
IERC20Delegates _stakeToken,
Expand Down

0 comments on commit eb6f833

Please sign in to comment.