From ccf44f452ddd02d7e4fe76791213618204b0087c Mon Sep 17 00:00:00 2001 From: Flocqst Date: Wed, 26 Jun 2024 11:49:31 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20prettify?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/Deploy.s.sol | 34 +++++++------ .../parameters/OptimismGoerliParameters.sol | 2 + .../utils/parameters/OptimismParameters.sol | 2 + src/KSXVault.sol | 11 ++-- src/interfaces/IKSXVault.sol | 2 + test/utils/Bootstrap.sol | 50 +++++++++++-------- test/utils/Constants.sol | 5 ++ test/utils/mocks/MockVaultUpgrade.sol | 6 +-- 8 files changed, 69 insertions(+), 43 deletions(-) diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol index f2f200b..834ba2d 100644 --- a/script/Deploy.s.sol +++ b/script/Deploy.s.sol @@ -20,14 +20,15 @@ import {Script} from "lib/forge-std/src/Script.sol"; /// @title Kwenta KSX deployment script /// @author Flocqst (florian@kwenta.io) contract Setup is Script { + function deploySystem( address token, address pDAO - ) public returns (KSXVault ksxVault) { - ksxVault = new KSXVault({ - _token: token, - _pDAO: pDAO - }); + ) + public + returns (KSXVault ksxVault) + { + ksxVault = new KSXVault({_token: token, _pDAO: pDAO}); // deploy ERC1967 proxy and set implementation to ksxVault Proxy proxy = new Proxy(address(ksxVault), ""); @@ -35,38 +36,41 @@ contract Setup is Script { // "wrap" proxy in IKSXVault interface ksxVault = KSXVault(address(proxy)); } + } /// @dev steps to deploy and verify on Optimism: /// (1) load the variables in the .env file via `source .env` -/// (2) run `forge script script/Deploy.s.sol:DeployOptimism --rpc-url $OPTIMISM_RPC_URL --etherscan-api-key $OPTIMISM_ETHERSCAN_API_KEY --broadcast --verify -vvvv` +/// (2) run `forge script script/Deploy.s.sol:DeployOptimism --rpc-url +/// $OPTIMISM_RPC_URL --etherscan-api-key $OPTIMISM_ETHERSCAN_API_KEY +/// --broadcast --verify -vvvv` contract DeployOptimism is Setup, OptimismParameters { + function run() public { uint256 privateKey = vm.envUint("PRIVATE_KEY"); vm.startBroadcast(privateKey); - Setup.deploySystem({ - token: KWENTA, - pDAO: PDAO - }); + Setup.deploySystem({token: KWENTA, pDAO: PDAO}); vm.stopBroadcast(); } + } /// @dev steps to deploy and verify on Optimism Goerli: /// (1) load the variables in the .env file via `source .env` -/// (2) run `forge script script/Deploy.s.sol:DeployOptimismGoerli --rpc-url $OPTIMISM_GOERLI_RPC_URL --etherscan-api-key $OPTIMISM_ETHERSCAN_API_KEY --broadcast --verify -vvvv` +/// (2) run `forge script script/Deploy.s.sol:DeployOptimismGoerli --rpc-url +/// $OPTIMISM_GOERLI_RPC_URL --etherscan-api-key $OPTIMISM_ETHERSCAN_API_KEY +/// --broadcast --verify -vvvv` contract DeployOptimismGoerli is Setup, OptimismGoerliParameters { + function run() public { uint256 privateKey = vm.envUint("PRIVATE_KEY"); vm.startBroadcast(privateKey); - Setup.deploySystem({ - token: KWENTA, - pDAO: PDAO - }); + Setup.deploySystem({token: KWENTA, pDAO: PDAO}); vm.stopBroadcast(); } + } diff --git a/script/utils/parameters/OptimismGoerliParameters.sol b/script/utils/parameters/OptimismGoerliParameters.sol index 672a8b0..02e381d 100644 --- a/script/utils/parameters/OptimismGoerliParameters.sol +++ b/script/utils/parameters/OptimismGoerliParameters.sol @@ -2,6 +2,7 @@ pragma solidity 0.8.25; contract OptimismGoerliParameters { + /// @dev this is an EOA used on testnet only address public constant PDAO = 0x1b4fCFE451A15218aEeC811B508B4aa3f2A35904; @@ -9,4 +10,5 @@ contract OptimismGoerliParameters { address public constant USDC = 0xe05606174bac4A6364B31bd0eCA4bf4dD368f8C6; address public constant KWENTA = 0x920Cf626a271321C151D027030D5d08aF699456b; + } diff --git a/script/utils/parameters/OptimismParameters.sol b/script/utils/parameters/OptimismParameters.sol index 225e663..341440e 100644 --- a/script/utils/parameters/OptimismParameters.sol +++ b/script/utils/parameters/OptimismParameters.sol @@ -2,6 +2,7 @@ pragma solidity 0.8.25; contract OptimismParameters { + address public constant PDAO = 0xe826d43961a87fBE71C91d9B73F7ef9b16721C07; // https://optimistic.etherscan.io/token/0x0b2c639c533813f4aa9d7837caf62653d097ff85 @@ -9,4 +10,5 @@ contract OptimismParameters { // https://optimistic.etherscan.io/token/0x920cf626a271321c151d027030d5d08af699456b address public constant KWENTA = 0x920Cf626a271321C151D027030D5d08aF699456b; + } diff --git a/src/KSXVault.sol b/src/KSXVault.sol index e30e1bd..0eed02e 100644 --- a/src/KSXVault.sol +++ b/src/KSXVault.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.25; -import {IKSXVault} from "src/interfaces/IKSXVault.sol"; +import {ERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {ERC4626} from "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol"; -import {ERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import {IKSXVault} from "src/interfaces/IKSXVault.sol"; import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol"; @@ -12,6 +12,7 @@ import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol"; /// @notice KSX ERC4626 Vault /// @author Flocqst (florian@kwenta.io) contract KSXVault is IKSXVault, ERC4626, UUPSUpgradeable { + /*////////////////////////////////////////////////////////////// IMMUTABLES //////////////////////////////////////////////////////////////*/ @@ -32,7 +33,10 @@ contract KSXVault is IKSXVault, ERC4626, UUPSUpgradeable { /// @param _token Kwenta token address /// @param _pDAO Kwenta owned/operated multisig address /// that can authorize upgrades - constructor(address _token, address _pDAO) + constructor( + address _token, + address _pDAO + ) ERC4626(IERC20(_token)) ERC20("KSX Vault", "KSX") { @@ -54,4 +58,5 @@ contract KSXVault is IKSXVault, ERC4626, UUPSUpgradeable { if (pDAO == address(0)) revert NonUpgradeable(); if (msg.sender != pDAO) revert OnlyPDAO(); } + } diff --git a/src/interfaces/IKSXVault.sol b/src/interfaces/IKSXVault.sol index 8e10106..8855b56 100644 --- a/src/interfaces/IKSXVault.sol +++ b/src/interfaces/IKSXVault.sol @@ -7,6 +7,7 @@ import "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol"; /// @title Kwenta KSXVault Interface /// @author Flocqst (florian@kwenta.io) interface IKSXVault { + /*////////////////////////////////////////////////////////////// ERRORS //////////////////////////////////////////////////////////////*/ @@ -20,4 +21,5 @@ interface IKSXVault { /// @dev the KSXVault is not upgradeable when /// the pDAO has been set to the zero address error NonUpgradeable(); + } diff --git a/test/utils/Bootstrap.sol b/test/utils/Bootstrap.sol index 2a65d79..5a4e891 100644 --- a/test/utils/Bootstrap.sol +++ b/test/utils/Bootstrap.sol @@ -1,21 +1,19 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity 0.8.25; -/** @PR:REVIEW remove any unused imports (except console bc it is helpful) **/ +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import {Test} from "lib/forge-std/src/Test.sol"; import {console2} from "lib/forge-std/src/console2.sol"; -import { - KSXVault -} from "src/KSXVault.sol"; -import {Constants} from "test/utils/Constants.sol"; import { OptimismGoerliParameters, OptimismParameters, Setup } from "script/Deploy.s.sol"; -import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import {Test} from "lib/forge-std/src/Test.sol"; +import {KSXVault} from "src/KSXVault.sol"; +import {Constants} from "test/utils/Constants.sol"; contract Bootstrap is Test, Constants { + using console2 for *; // pDAO address @@ -35,36 +33,44 @@ contract Bootstrap is Test, Constants { ksxVault = KSXVault(ksxVaultAddress); } - function initializeOptimism() internal { BootstrapOptimism bootstrap = new BootstrapOptimism(); - (address ksxVaultAddress, address _TokenAddress, address _pDAOAddress) = bootstrap.init(); - + (address ksxVaultAddress, address _TokenAddress, address _pDAOAddress) = + bootstrap.init(); + pDAO = _pDAOAddress; TOKEN = IERC20(_TokenAddress); ksxVault = KSXVault(ksxVaultAddress); } + } contract BootstrapLocal is Setup { + function init(address _token, address _pDAO) public returns (address) { - address ksxVaultAddress = address(new KSXVault(_token, _pDAO)); + (KSXVault ksxvault) = Setup.deploySystem({token: _token, pDAO: _pDAO}); - return ksxVaultAddress; + return (address(ksxvault)); } + } contract BootstrapOptimism is Setup, OptimismParameters { + function init() public returns (address, address, address) { - (KSXVault ksxvault) = Setup.deploySystem({ - token: KWENTA, - pDAO: PDAO - }); - - return ( - address(ksxvault), - KWENTA, - PDAO - ); + (KSXVault ksxvault) = Setup.deploySystem({token: KWENTA, pDAO: PDAO}); + + return (address(ksxvault), KWENTA, PDAO); } + +} + +contract BootstrapOptimismGoerli is Setup, OptimismGoerliParameters { + + function init() public returns (address, address, address) { + (KSXVault ksxvault) = Setup.deploySystem({token: KWENTA, pDAO: PDAO}); + + return (address(ksxvault), KWENTA, PDAO); + } + } diff --git a/test/utils/Constants.sol b/test/utils/Constants.sol index 4765adc..443a52a 100644 --- a/test/utils/Constants.sol +++ b/test/utils/Constants.sol @@ -3,9 +3,14 @@ pragma solidity 0.8.25; /// @title Contract for defining constants used in testing contract Constants { + uint256 public constant BASE_BLOCK_NUMBER = 8_225_680; address internal constant ACTOR = address(0xa1); address internal constant BAD_ACTOR = address(0xa2); + + address public constant PDAOADDR = + 0xe826d43961a87fBE71C91d9B73F7ef9b16721C07; + } diff --git a/test/utils/mocks/MockVaultUpgrade.sol b/test/utils/mocks/MockVaultUpgrade.sol index 20470f8..1add831 100644 --- a/test/utils/mocks/MockVaultUpgrade.sol +++ b/test/utils/mocks/MockVaultUpgrade.sol @@ -6,11 +6,11 @@ import {KSXVault} from "src/KSXVault.sol"; /// @title Example upgraded Vault contract for testing purposes /// @author Flocqst (florian@kwenta.io) contract MockVaultUpgrade is KSXVault { - constructor(address _token, address _pDAO) - KSXVault(_token, _pDAO) - {} + + constructor(address _token, address _pDAO) KSXVault(_token, _pDAO) {} function echo(string memory message) public pure returns (string memory) { return message; } + }