Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy script for v2 vaults #83

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 8 additions & 47 deletions script/DeployLeveragedEthMainnet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,10 @@ import {ISwapRouter} from "../src/interfaces/uniswap/ISwapRouter.sol";
import {scWETH} from "../src/steth/scWETH.sol";
import {scUSDC} from "../src/steth/scUSDC.sol";
import {sc4626} from "../src/sc4626.sol";
import {MainnetDeployBase} from "./base/MainnetDeployBase.sol";

contract DeployScript is CREATE3Script {
bytes32 constant DEFAULT_ADMIN_ROLE = 0x00;

WETH weth = WETH(payable(C.WETH));
ERC20 usdc = ERC20(C.USDC);
ISwapRouter uniswapRouter = ISwapRouter(C.UNISWAP_V3_SWAP_ROUTER);
uint256 deployerPrivateKey = uint256(vm.envBytes32("PRIVATE_KEY"));
address deployerAddress = vm.addr(deployerPrivateKey);

constructor() CREATE3Script(vm.envString("VERSION")) {}

contract DeployScript is MainnetDeployBase {
function run() external returns (scWETH scWeth, scUSDC scUsdc) {
address keeper = vm.envAddress("KEEPER");

vm.startBroadcast(deployerPrivateKey);

scWETH.ConstructorParams memory scWethParams = scWETH.ConstructorParams({
Expand All @@ -54,11 +43,9 @@ contract DeployScript is CREATE3Script {
scWeth = new scWETH(scWethParams);

weth.deposit{value: 0.01 ether}(); // wrap 0.01 ETH into WETH
deposit(scWeth, 0.01 ether); // 0.01 WETH
_deposit(scWeth, 0.01 ether); // 0.01 WETH

// transfer DEFAULT_ADMIN_ROLE to multisig
scWeth.grantRole(DEFAULT_ADMIN_ROLE, C.MULTISIG);
scWeth.revokeRole(DEFAULT_ADMIN_ROLE, deployerAddress);
_transferAdminRoleToMultisig(scWeth, deployerAddress);

scUSDC.ConstructorParams memory scUsdcParams = scUSDC.ConstructorParams({
admin: deployerAddress,
Expand All @@ -70,44 +57,18 @@ contract DeployScript is CREATE3Script {
aavePoolDataProvider: IPoolDataProvider(C.AAVE_POOL_DATA_PROVIDER),
aaveAUsdc: IAToken(C.AAVE_AUSDC_TOKEN),
aaveVarDWeth: ERC20(C.AAVAAVE_VAR_DEBT_WETH_TOKEN),
uniswapSwapRouter: uniswapRouter,
uniswapSwapRouter: ISwapRouter(C.UNISWAP_V3_SWAP_ROUTER),
chainlinkUsdcToEthPriceFeed: AggregatorV3Interface(C.CHAINLINK_USDC_ETH_PRICE_FEED),
balancerVault: IVault(C.BALANCER_VAULT)
});

scUsdc = new scUSDC(scUsdcParams);

swapETHForUSDC(0.01 ether);
deposit(scUsdc, usdc.balanceOf(address(deployerAddress))); // 0.01 ether worth of USDC
_swapWethForUsdc(0.01 ether);
_deposit(scUsdc, usdc.balanceOf(address(deployerAddress))); // 0.01 ether worth of USDC

// transfer DEFAULT_ADMIN_ROLE to multisig
scUsdc.grantRole(DEFAULT_ADMIN_ROLE, C.MULTISIG);
scUsdc.revokeRole(DEFAULT_ADMIN_ROLE, deployerAddress);
_transferAdminRoleToMultisig(scUsdc, deployerAddress);

vm.stopBroadcast();
}

function deposit(sc4626 vault, uint256 amount) internal {
vault.asset().approve(address(vault), amount);
vault.deposit(amount, deployerAddress);
}

function swapETHForUSDC(uint256 amount) internal {
weth.deposit{value: amount}();

weth.approve(address(uniswapRouter), amount);

ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
tokenIn: address(weth),
tokenOut: address(usdc),
fee: 500, // 0.05%
recipient: deployerAddress,
deadline: block.timestamp + 1000,
amountIn: amount,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});

uniswapRouter.exactInputSingle(params);
}
}
60 changes: 60 additions & 0 deletions script/base/MainnetDeployBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.13;

import "forge-std/console2.sol";
import {CREATE3Script} from "../base/CREATE3Script.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";
import {WETH} from "solmate/tokens/WETH.sol";
import {AccessControl} from "openzeppelin-contracts/access/AccessControl.sol";

import {Constants as C} from "../../src/lib/Constants.sol";
import {ISwapRouter} from "../../src/interfaces/uniswap/ISwapRouter.sol";
import {sc4626} from "../../src/sc4626.sol";
import {scWETHv2} from "../../src/steth/scWETHv2.sol";
import {scUSDCv2} from "../../src/steth/scUSDCv2.sol";
import {Swapper} from "../../src/steth/Swapper.sol";
import {PriceConverter} from "../../src/steth/PriceConverter.sol";
import {AaveV3Adapter as scWethAaveV3Adapter} from "../../src/steth/scWethV2-adapters/AaveV3Adapter.sol";
import {CompoundV3Adapter as scWethCompoundV3Adapter} from "../../src/steth/scWethV2-adapters/CompoundV3Adapter.sol";
import {AaveV3Adapter as scUsdcAaveV3Adapter} from "../../src/steth/scUsdcV2-adapters/AaveV3Adapter.sol";
import {AaveV2Adapter as scUsdcAaveV2Adapter} from "../../src/steth/scUsdcV2-adapters/AaveV2Adapter.sol";

abstract contract MainnetDeployBase is CREATE3Script {
uint256 deployerPrivateKey = uint256(vm.envBytes32("PRIVATE_KEY"));
address deployerAddress = vm.addr(deployerPrivateKey);
address keeper = vm.envAddress("KEEPER");

WETH weth = WETH(payable(C.WETH));
ERC20 usdc = ERC20(C.USDC);

constructor() CREATE3Script(vm.envString("VERSION")) {}

function _transferAdminRoleToMultisig(AccessControl _contract, address _currentAdmin) internal {
_contract.grantRole(_contract.DEFAULT_ADMIN_ROLE(), C.MULTISIG);
_contract.revokeRole(_contract.DEFAULT_ADMIN_ROLE(), _currentAdmin);
}

function _deposit(sc4626 _vault, uint256 _amount) internal {
_vault.asset().approve(address(_vault), _amount);
_vault.deposit(_amount, deployerAddress);
}

function _swapWethForUsdc(uint256 _amount) internal {
weth.deposit{value: _amount}();

weth.approve(C.UNISWAP_V3_SWAP_ROUTER, _amount);

ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
tokenIn: address(weth),
tokenOut: address(usdc),
fee: 500, // 0.05%
recipient: deployerAddress,
deadline: block.timestamp + 1000,
amountIn: _amount,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});

ISwapRouter(C.UNISWAP_V3_SWAP_ROUTER).exactInputSingle(params);
}
}
83 changes: 83 additions & 0 deletions script/v2/DeployV2LeveragedEthMainnet.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.13;

import "forge-std/console2.sol";
import {CREATE3Script} from "../base/CREATE3Script.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";
import {WETH} from "solmate/tokens/WETH.sol";
import {AccessControl} from "openzeppelin-contracts/access/AccessControl.sol";

import {Constants as C} from "../../src/lib/Constants.sol";
import {ISwapRouter} from "../../src/interfaces/uniswap/ISwapRouter.sol";
import {sc4626} from "../../src/sc4626.sol";
import {scWETHv2} from "../../src/steth/scWETHv2.sol";
import {scUSDCv2} from "../../src/steth/scUSDCv2.sol";
import {Swapper} from "../../src/steth/Swapper.sol";
import {PriceConverter} from "../../src/steth/PriceConverter.sol";
import {AaveV3Adapter as scWethAaveV3Adapter} from "../../src/steth/scWethV2-adapters/AaveV3Adapter.sol";
import {CompoundV3Adapter as scWethCompoundV3Adapter} from "../../src/steth/scWethV2-adapters/CompoundV3Adapter.sol";
import {AaveV3Adapter as scUsdcAaveV3Adapter} from "../../src/steth/scUsdcV2-adapters/AaveV3Adapter.sol";
import {AaveV2Adapter as scUsdcAaveV2Adapter} from "../../src/steth/scUsdcV2-adapters/AaveV2Adapter.sol";
import {MainnetDeployBase} from "../base/MainnetDeployBase.sol";

contract DeployScript is MainnetDeployBase {
function run() external returns (scWETHv2 scWethV2, scUSDCv2 scUsdcV2) {
vm.startBroadcast(deployerPrivateKey);

Swapper swapper = new Swapper();
console2.log("Swapper:", address(swapper));
PriceConverter priceConverter = new PriceConverter(deployerAddress);
console2.log("PriceConverter:", address(priceConverter));

_transferAdminRoleToMultisig(priceConverter, deployerAddress);

scWethV2 = _deployScWethV2(priceConverter, swapper);

scUsdcV2 = _deployScUsdcV2(scWethV2, priceConverter, swapper);

vm.stopBroadcast();
}

function _deployScWethV2(PriceConverter _priceConverter, Swapper _swapper) internal returns (scWETHv2 vault) {
vault = new scWETHv2(deployerAddress, keeper, 0.99e18, weth, _swapper, _priceConverter);

// deploy & add adapters
scWethAaveV3Adapter aaveV3Adapter = new scWethAaveV3Adapter();
vault.addAdapter(aaveV3Adapter);

scWethCompoundV3Adapter compoundV3Adapter = new scWethCompoundV3Adapter();
vault.addAdapter(compoundV3Adapter);

weth.deposit{value: 0.01 ether}(); // wrap 0.01 ETH into WETH
_deposit(vault, 0.01 ether); // 0.01 WETH

_transferAdminRoleToMultisig(vault, deployerAddress);

console2.log("scWethV2 vault:", address(vault));
console2.log("scWethV2 AaveV3Adapter:", address(aaveV3Adapter));
console2.log("scWETHV2 CompoundV3Adapter:", address(compoundV3Adapter));
}

function _deployScUsdcV2(scWETHv2 _wethVault, PriceConverter _priceConveter, Swapper _swapper)
internal
returns (scUSDCv2 vault)
{
vault = new scUSDCv2(deployerAddress, keeper, _wethVault, _priceConveter, _swapper);

// deploy & add adapters
scUsdcAaveV3Adapter aaveV3Adapter = new scUsdcAaveV3Adapter();
vault.addAdapter(aaveV3Adapter);

scUsdcAaveV2Adapter aaveV2Adapter = new scUsdcAaveV2Adapter();
vault.addAdapter(aaveV2Adapter);

_swapWethForUsdc(0.01 ether);
_deposit(vault, usdc.balanceOf(deployerAddress)); // 0.01 ether worth of USDC

_transferAdminRoleToMultisig(vault, deployerAddress);

console2.log("scUSDCv2 vault:", address(vault));
console2.log("scUSDCv2 AaveV3Adapter:", address(aaveV3Adapter));
console2.log("scUSDCv2 CompoundV3Adapter:", address(aaveV2Adapter));
}
}
2 changes: 1 addition & 1 deletion src/steth/scWethV2-adapters/MorphoAaveV3Adapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract MorphoAaveV3Adapter is IAdapter {
return morpho.borrowBalance(C.WETH, _account);
}

function getMaxLtv() external view override returns (uint256) {
function getMaxLtv() external pure override returns (uint256) {
// same as the maxLtv for aave v3 on eMode
return 0.9e18;
}
Expand Down