-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move vault registrations into dedicated registry contract
- Loading branch information
Showing
9 changed files
with
220 additions
and
169 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,48 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import { IStakeVaultRegistry } from "./interfaces/IStakeVaultRegistry.sol"; | ||
import { IStakeVault } from "./interfaces/IStakeVault.sol"; | ||
|
||
contract StakeVaultRegistry is IStakeVaultRegistry, Ownable { | ||
error StakeManagerVaultRegistry__NotAuthorized(); | ||
error StakeManagerVaultRegistry__VaultAlreadyRegistered(); | ||
error StakeManagerVaultRegistry__InvalidVault(); | ||
|
||
address public stakeManager; | ||
|
||
mapping(address owner => address[] vault) public vaults; | ||
mapping(address vault => address owner) public vaultOwners; | ||
|
||
modifier onlyStakeManager() { | ||
if (msg.sender != stakeManager) { | ||
revert StakeManagerVaultRegistry__NotAuthorized(); | ||
} | ||
_; | ||
} | ||
|
||
constructor(address _owner) Ownable(_owner) { } | ||
|
||
function setStakeManager(address _stakeManager) external onlyOwner { | ||
stakeManager = _stakeManager; | ||
} | ||
|
||
function register(address owner, address vault) external onlyStakeManager { | ||
if (vaultOwners[vault] != address(0)) { | ||
revert StakeManagerVaultRegistry__VaultAlreadyRegistered(); | ||
} | ||
|
||
// Verify this is a legitimate vault by checking it points to stakeManager | ||
if (address(IStakeVault(vault).stakeManager()) != stakeManager) { | ||
revert StakeManagerVaultRegistry__InvalidVault(); | ||
} | ||
|
||
vaultOwners[vault] = owner; | ||
vaults[owner].push(vault); | ||
} | ||
|
||
function vaultsOf(address owner) external view returns (address[] memory) { | ||
return vaults[owner]; | ||
} | ||
} |
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,8 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
interface IStakeVaultRegistry { | ||
function register(address owner, address vault) external; | ||
function vaultsOf(address owner) external view returns (address[] memory); | ||
function vaultOwners(address vault) external view returns (address); | ||
} |
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
Oops, something went wrong.