Skip to content

Commit

Permalink
✨ prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
Flocqst committed Jun 26, 2024
1 parent 12bfa07 commit ccf44f4
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 43 deletions.
34 changes: 19 additions & 15 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,57 @@ import {Script} from "lib/forge-std/src/Script.sol";
/// @title Kwenta KSX deployment script
/// @author Flocqst ([email protected])
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), "");

// "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();
}

}
2 changes: 2 additions & 0 deletions script/utils/parameters/OptimismGoerliParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
pragma solidity 0.8.25;

contract OptimismGoerliParameters {

/// @dev this is an EOA used on testnet only
address public constant PDAO = 0x1b4fCFE451A15218aEeC811B508B4aa3f2A35904;

// https://developers.circle.com/stablecoins/docs/usdc-on-test-networks#usdc-on-op-goerli
address public constant USDC = 0xe05606174bac4A6364B31bd0eCA4bf4dD368f8C6;

address public constant KWENTA = 0x920Cf626a271321C151D027030D5d08aF699456b;

}
2 changes: 2 additions & 0 deletions script/utils/parameters/OptimismParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
pragma solidity 0.8.25;

contract OptimismParameters {

address public constant PDAO = 0xe826d43961a87fBE71C91d9B73F7ef9b16721C07;

// https://optimistic.etherscan.io/token/0x0b2c639c533813f4aa9d7837caf62653d097ff85
address public constant USDC = 0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85;

// https://optimistic.etherscan.io/token/0x920cf626a271321c151d027030d5d08af699456b
address public constant KWENTA = 0x920Cf626a271321C151D027030D5d08aF699456b;

}
11 changes: 8 additions & 3 deletions src/KSXVault.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// 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";

/// @title KSXVault Contract
/// @notice KSX ERC4626 Vault
/// @author Flocqst ([email protected])
contract KSXVault is IKSXVault, ERC4626, UUPSUpgradeable {

/*//////////////////////////////////////////////////////////////
IMMUTABLES
//////////////////////////////////////////////////////////////*/
Expand All @@ -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")
{
Expand All @@ -54,4 +58,5 @@ contract KSXVault is IKSXVault, ERC4626, UUPSUpgradeable {
if (pDAO == address(0)) revert NonUpgradeable();
if (msg.sender != pDAO) revert OnlyPDAO();
}

}
2 changes: 2 additions & 0 deletions src/interfaces/IKSXVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
/// @title Kwenta KSXVault Interface
/// @author Flocqst ([email protected])
interface IKSXVault {

/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
Expand All @@ -20,4 +21,5 @@ interface IKSXVault {
/// @dev the KSXVault is not upgradeable when
/// the pDAO has been set to the zero address
error NonUpgradeable();

}
50 changes: 28 additions & 22 deletions test/utils/Bootstrap.sol
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}

}
5 changes: 5 additions & 0 deletions test/utils/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
6 changes: 3 additions & 3 deletions test/utils/mocks/MockVaultUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {KSXVault} from "src/KSXVault.sol";
/// @title Example upgraded Vault contract for testing purposes
/// @author Flocqst ([email protected])
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;
}

}

0 comments on commit ccf44f4

Please sign in to comment.