-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
_fetchOrDeploySurrogate
an abstract method (#74)
* Make deploy and fetching surrogate an abstract contract
- Loading branch information
1 parent
bc46ac2
commit a90fb14
Showing
3 changed files
with
59 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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"; | ||
|
||
/// @title GovernaceStakerDelegateSurrogateVotes | ||
/// @author [ScopeLift](https://scopelift.co) | ||
/// @notice This contract extension adds delegation surrogates to the GovernanceStaker base | ||
/// contract, allowing staked tokens to be delegated to a specific delegate. | ||
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; | ||
|
||
/// @inheritdoc GovernanceStaker | ||
function surrogates(address _delegatee) public view override returns (DelegationSurrogate) { | ||
return storedSurrogates[_delegatee]; | ||
} | ||
|
||
/// @inheritdoc GovernanceStaker | ||
function _fetchOrDeploySurrogate(address _delegatee) | ||
internal | ||
virtual | ||
override | ||
returns (DelegationSurrogate _surrogate) | ||
{ | ||
_surrogate = storedSurrogates[_delegatee]; | ||
|
||
if (address(_surrogate) == address(0)) { | ||
_surrogate = new DelegationSurrogateVotes(STAKE_TOKEN, _delegatee); | ||
storedSurrogates[_delegatee] = _surrogate; | ||
emit SurrogateDeployed(_delegatee, address(_surrogate)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters