-
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.
- Loading branch information
Showing
10 changed files
with
158 additions
and
14 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,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
import { BaseScript } from "./Base.s.sol"; | ||
import { DeploymentConfig } from "./DeploymentConfig.s.sol"; | ||
import { VaultFactory } from "../src/VaultFactory.sol"; | ||
|
||
contract DeployVaultFactoryScript is BaseScript { | ||
function run() public returns (VaultFactory, DeploymentConfig) { | ||
DeploymentConfig deploymentConfig = new DeploymentConfig(broadcaster); | ||
(address deployer,) = deploymentConfig.activeNetworkConfig(); | ||
|
||
address stakeManager = vm.envOr({ name: "STAKE_MANAGER_ADDRESS", defaultValue: address(0) }); | ||
vm.startBroadcast(deployer); | ||
VaultFactory vaultFactory = new VaultFactory(deployer, stakeManager); | ||
vm.stopBroadcast(); | ||
|
||
return (vaultFactory, deploymentConfig); | ||
} | ||
} |
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,19 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
import { BaseScript } from "./Base.s.sol"; | ||
import { DeploymentConfig } from "./DeploymentConfig.s.sol"; | ||
import { XPToken } from "../src/XPToken.sol"; | ||
|
||
contract DeployXPTokenScript is BaseScript { | ||
function run() public returns (XPToken, DeploymentConfig) { | ||
DeploymentConfig deploymentConfig = new DeploymentConfig(broadcaster); | ||
(address deployer,) = deploymentConfig.activeNetworkConfig(); | ||
|
||
vm.startBroadcast(deployer); | ||
XPToken xpToken = new XPToken(); | ||
vm.stopBroadcast(); | ||
|
||
return (xpToken, deploymentConfig); | ||
} | ||
} |
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,13 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
|
||
contract TransparentProxy is ERC1967Proxy { | ||
constructor(address _implementation, bytes memory _data) ERC1967Proxy(_implementation, _data) { } | ||
|
||
function implementation() external view returns (address) { | ||
return _implementation(); | ||
} | ||
} | ||
|
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,69 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.26; | ||
|
||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import { Clones } from "@openzeppelin/contracts/proxy/Clones.sol"; | ||
import { IStakeManagerProxy } from "./interfaces/IStakeManagerProxy.sol"; | ||
import { IStakeVaultClone } from "./interfaces/IStakeVaultClone.sol"; | ||
import { StakeVault } from "./StakeVault.sol"; | ||
|
||
/** | ||
* @title VaultFactory | ||
* @author 0x-r4bbit | ||
* | ||
* This contract is reponsible for creating staking vaults for users. | ||
* A user of the staking protocol is able to create multiple vaults to facilitate | ||
* different strategies. For example, a user may want to create a vault for | ||
* a long-term lock period, while also creating a vault that has no lock period | ||
* at all. | ||
* | ||
* @notice This contract is used by users to create staking vaults. | ||
* @dev This contract will be deployed by Status, making Status the owner of the contract. | ||
* @dev A contract address for a `StakeManager` has to be provided to create this contract. | ||
* @dev Reverts with {VaultFactory__InvalidStakeManagerAddress} if the provided | ||
* `StakeManager` address is zero. | ||
* @dev The `StakeManager` contract address can be changed by the owner. | ||
*/ | ||
contract VaultFactory is Ownable { | ||
error VaultFactory__InvalidStakeManagerAddress(); | ||
|
||
event VaultCreated(address indexed vault, address indexed owner); | ||
event StakeManagerAddressChanged(address indexed newStakeManagerAddress); | ||
|
||
/// @dev Address of the `StakeManager` contract instance. | ||
IStakeManagerProxy public stakeManager; | ||
address public vaultImplementation; | ||
|
||
/// @param _stakeManager Address of the `StakeManager` contract instance. | ||
constructor(address _owner, address _stakeManager) Ownable(_owner) { | ||
if (_stakeManager == address(0)) { | ||
revert VaultFactory__InvalidStakeManagerAddress(); | ||
} | ||
stakeManager = IStakeManagerProxy(_stakeManager); | ||
vaultImplementation = address(new StakeVault(stakeManager.STAKING_TOKEN())); | ||
} | ||
|
||
/// @notice Sets the `StakeManager` contract address. | ||
/// @dev Only the owner can call this function. | ||
/// @dev Reverts if the provided `StakeManager` address is zero. | ||
/// @dev Emits a {StakeManagerAddressChanged} event. | ||
/// @param _stakeManager Address of the `StakeManager` contract instance. | ||
function setStakeManager(address _stakeManager) external onlyOwner { | ||
if (_stakeManager == address(0) || _stakeManager == address(stakeManager)) { | ||
revert VaultFactory__InvalidStakeManagerAddress(); | ||
} | ||
stakeManager = IStakeManagerProxy(_stakeManager); | ||
emit StakeManagerAddressChanged(_stakeManager); | ||
} | ||
|
||
/// @notice Creates an instance of a `StakeVault` contract. | ||
/// @dev Anyone can call this function. | ||
/// @dev Emits a {VaultCreated} event. | ||
function createVault() external returns (StakeVault) { | ||
StakeVault clone = StakeVault(Clones.clone(vaultImplementation)); | ||
clone.initialize(msg.sender, address(stakeManager)); | ||
emit VaultCreated(address(clone), msg.sender); | ||
return clone; | ||
} | ||
} |
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,8 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
import { IStakeVault } from "./IStakeVault.sol"; | ||
import { ITransparentProxy } from "./ITransparentProxy.sol"; | ||
|
||
interface IStakeVaultClone is IStakeVault, ITransparentProxy {} | ||
|
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,7 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.26; | ||
|
||
interface ITransparentProxy { | ||
function implementation() 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