Skip to content

Commit

Permalink
Move surrogates
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkeating committed Nov 6, 2024
1 parent 760014e commit 7671cb1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
12 changes: 5 additions & 7 deletions src/GovernanceStaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,6 @@ abstract contract GovernanceStaker is INotifiableRewardReceiver, Multicall, EIP7
/// @notice Stores the metadata associated with a given deposit.
mapping(DepositIdentifier depositId => Deposit deposit) public deposits;

/// @notice Maps the account of each governance delegate with the surrogate contract which holds
/// the staked tokens from deposits which assign voting weight to said delegate.
mapping(address delegatee => DelegationSurrogate surrogate) public surrogates;

/// @notice Time at which rewards distribution will complete if there are no new rewards.
uint256 public rewardEndTime;

Expand Down Expand Up @@ -313,6 +309,8 @@ abstract contract GovernanceStaker is INotifiableRewardReceiver, Multicall, EIP7
_setClaimFeeParameters(_params);
}

function surrogates(address _delegatee) public view virtual returns (DelegationSurrogate);

/// @notice Timestamp representing the last time at which rewards have been distributed, which is
/// either the current timestamp (because rewards are still actively being streamed) or the time
/// at which the reward duration ended (because all rewards to date have already been streamed).
Expand Down Expand Up @@ -838,7 +836,7 @@ abstract contract GovernanceStaker is INotifiableRewardReceiver, Multicall, EIP7
_checkpointGlobalReward();
_checkpointReward(deposit);

DelegationSurrogate _surrogate = surrogates[deposit.delegatee];
DelegationSurrogate _surrogate = surrogates(deposit.delegatee);

uint256 _newBalance = deposit.balance + _amount;
uint256 _newEarningPower =
Expand Down Expand Up @@ -866,7 +864,7 @@ abstract contract GovernanceStaker is INotifiableRewardReceiver, Multicall, EIP7
address _newDelegatee
) internal virtual {
_revertIfAddressZero(_newDelegatee);
DelegationSurrogate _oldSurrogate = surrogates[deposit.delegatee];
DelegationSurrogate _oldSurrogate = surrogates(deposit.delegatee);
uint256 _newEarningPower =
earningPowerCalculator.getEarningPower(deposit.balance, deposit.owner, _newDelegatee);

Expand Down Expand Up @@ -934,7 +932,7 @@ abstract contract GovernanceStaker is INotifiableRewardReceiver, Multicall, EIP7

deposit.balance = _newBalance.toUint96();
deposit.earningPower = _newEarningPower.toUint96();
_stakeTokenSafeTransferFrom(address(surrogates[deposit.delegatee]), deposit.owner, _amount);
_stakeTokenSafeTransferFrom(address(surrogates(deposit.delegatee)), deposit.owner, _amount);
emit StakeWithdrawn(deposit.owner, _depositId, _amount, deposit.balance);
}

Expand Down
12 changes: 10 additions & 2 deletions src/GovernanceStakerDelegateSurrogateVotes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ abstract contract GovernanceStakerDelegateSurrogateVotes is GovernanceStaker {
/// @notice Emitted when a surrogate contract is deployed.
event SurrogateDeployed(address indexed delegatee, address indexed surrogate);

/// @notice Maps the account of each governance delegate with the surrogate contract which holds
/// the staked tokens from deposits which assign voting weight to said delegate.
mapping(address delegatee => DelegationSurrogate surrogate) private storedSurrogates;

function surrogates(address _delegatee) public view override returns (DelegationSurrogate) {
return storedSurrogates[_delegatee];
}

/// @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.
Expand All @@ -19,11 +27,11 @@ abstract contract GovernanceStakerDelegateSurrogateVotes is GovernanceStaker {
override
returns (DelegationSurrogate _surrogate)
{
_surrogate = surrogates[_delegatee];
_surrogate = storedSurrogates[_delegatee];

if (address(_surrogate) == address(0)) {
_surrogate = new DelegationSurrogateVotes(STAKE_TOKEN, _delegatee);
surrogates[_delegatee] = _surrogate;
storedSurrogates[_delegatee] = _surrogate;
emit SurrogateDeployed(_delegatee, address(_surrogate));
}
}
Expand Down
6 changes: 5 additions & 1 deletion test/harnesses/GovernanceStakerHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {IERC20Delegates} from "src/interfaces/IERC20Delegates.sol";
import {IEarningPowerCalculator} from "src/interfaces/IEarningPowerCalculator.sol";
import {DelegationSurrogate} from "src/DelegationSurrogate.sol";

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

0 comments on commit 7671cb1

Please sign in to comment.