Skip to content

Commit

Permalink
👷 Include access restriction to the upgrade mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Flocqst committed Jun 12, 2024
1 parent a7c7f32 commit d9d57a2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/KSXVault.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.25;

import {IKSXVault} from "src/interfaces/IKSXVault.sol";
import {ERC4626} from
"@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
import {ERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Expand All @@ -10,7 +11,7 @@ import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
/// @title KSXVault Contract
/// @notice KSX ERC4626 Vault
/// @author Flocqst ([email protected])
contract KSXVault is ERC4626, UUPSUpgradeable {
contract KSXVault is IKSXVault, ERC4626, UUPSUpgradeable {
/*//////////////////////////////////////////////////////////////
IMMUTABLES
//////////////////////////////////////////////////////////////*/
Expand All @@ -26,7 +27,7 @@ contract KSXVault is ERC4626, UUPSUpgradeable {
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/

/// @notice Constructs the KSXVault contract
/// @param _token Kwenta token address
/// @param _pDAO Kwenta owned/operated multisig address
Expand All @@ -45,9 +46,12 @@ contract KSXVault is ERC4626, UUPSUpgradeable {
//////////////////////////////////////////////////////////////*/

/// @inheritdoc UUPSUpgradeable
function _authorizeUpgrade(address newImplementation)
function _authorizeUpgrade(address /* _newImplementation */ )
internal
virtual
view
override
{}
{
if (pDAO == address(0)) revert NonUpgradeable();
if (msg.sender != pDAO) revert OnlyPDAO();
}
}
23 changes: 23 additions & 0 deletions src/interfaces/IKSXVault.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.25;

import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";

/// @title Kwenta KSXVault Interface
/// @author Flocqst ([email protected])
interface IKSXVault {
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/

/// @notice thrown when attempting to update
/// the KSXVault when caller is not the Kwenta pDAO
error OnlyPDAO();

/// @notice thrown when attempting to upgrade
/// the KSXVault when the KSXVault is not upgradeable
/// @dev the KSXVault is not upgradeable when
/// the pDAO has been set to the zero address
error NonUpgradeable();
}

0 comments on commit d9d57a2

Please sign in to comment.