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

Forked Deployments and V1 Vault Fixture Logic #69

Merged
merged 78 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
7397838
abstract deposit and harvest
0xrin1 Apr 27, 2023
c637dad
simulate profit
0xrin1 Apr 28, 2023
eca18b2
forge fmt
0xrin1 Apr 28, 2023
de04764
add deposits that have not been redeemed to fixtures
0xrin1 Apr 28, 2023
eae9c3a
merge main
0xrin1 May 4, 2023
2c2f255
just repay half to simulate profit so that LTV diverges by 50%
0xrin1 May 4, 2023
3ab4b62
console.log scWETH and scUSDC addresses
0xrin1 May 4, 2023
a4427ca
add newline for clarity
0xrin1 May 4, 2023
f0c203a
prevent newline from using variable spacing
0xrin1 May 4, 2023
7a6c726
merge main
0xrin1 May 25, 2023
445c721
remove GoerliConstants.sol
0xrin1 May 25, 2023
d169a50
[WIP] run testnet deployment and fixtures against forked node
0xrin1 May 26, 2023
fb30eb7
merge mainnet and testnet deployment
0xrin1 May 31, 2023
b322e78
working testnet deployment profit function
0xrin1 May 31, 2023
5ead1aa
address linting complaints
0xrin1 Jun 2, 2023
996c437
rename usdcContract to _scUSDC
0xrin1 Jun 2, 2023
fcd3f55
deposit rebalance and redeem in testnet fixture
0xrin1 Jun 4, 2023
ef5319a
remove comment
0xrin1 Jun 4, 2023
0db6fe0
merge main
0xrin1 Jun 4, 2023
04347da
0.8.20
0xrin1 Jun 4, 2023
17a08cb
scUSDC profit and rebalance
0xrin1 Jun 6, 2023
c57ea5a
forge fmt
0xrin1 Jun 6, 2023
e5d3658
remove rebalances that the backend should be doing
0xrin1 Jun 6, 2023
debcb6d
[WIP] set token balance with stdStore
0xrin1 Jun 6, 2023
1bc5c4d
_divergeLTV
0xrin1 Jun 6, 2023
d7861c7
setTokenBalance not erroring but not actually changing the balance value
0xrin1 Jun 6, 2023
27770fa
divergeLTV code is there in two forms but both dont work
0xrin1 Jun 7, 2023
56f8743
merge main
0xrin1 Jun 20, 2023
1adfdf7
fix merge
0xrin1 Jun 20, 2023
07672e9
add newline to constants file for clarity
0xrin1 Jun 20, 2023
70ce1aa
staking contract "notifyRewardAmount" fix (#85)
brkomir Jun 21, 2023
08c2218
refactor to improve code quality of the scip staking contracts (#86)
brkomir Jun 21, 2023
f433919
add fv report
0xBRM Jun 21, 2023
b34b0a0
rename
0xBRM Jun 21, 2023
7e7e3df
add visual assets
0xBRM Jun 21, 2023
4290a25
small edit
0xBRM Jun 21, 2023
5c18828
md doesnt render svg
0xBRM Jun 21, 2023
ac335be
fix path
0xBRM Jun 21, 2023
1e1bfc9
fix size
0xBRM Jun 21, 2023
67d0887
size
0xBRM Jun 21, 2023
8206812
text fixes
0xBRM Jun 21, 2023
0f430b9
consistency
0xBRM Jun 21, 2023
ee55000
Merge pull request #90 from lindy-labs/fv_report
0xBRM Jun 21, 2023
0e81ef4
moving all constant values to Constants.sol and removing duplicates (…
brkomir Jun 22, 2023
3f33104
merge main and resolve conflicts
0xrin1 Jun 22, 2023
c071cd8
remove swapWethForUsdc duplication
0xrin1 Jun 22, 2023
903e99b
renaming adapters to differentiate usage between scUSDCv2 & scWETHv2 …
brkomir Jul 4, 2023
7241406
document the decision of not including LQTY into total assets (#94)
brkomir Jul 5, 2023
b55a3dc
fix for the logic for maintaining the float balance on withdrawals (#92)
brkomir Jul 5, 2023
cf7903e
merge main
0xrin1 Jul 6, 2023
9a37e1e
newline console log
0xrin1 Jul 6, 2023
c745522
DeployLeveragedEth review style adjustments
0xrin1 Jul 6, 2023
d85cd4a
more code style review comment implementation
0xrin1 Jul 6, 2023
55b28d5
rename vaultToken to vault
0xrin1 Jul 6, 2023
f56671d
remove depositForUsers function
0xrin1 Jul 6, 2023
b06085d
use test constants for fixture deposit and funding amounts
0xrin1 Jul 6, 2023
368f736
INITAL_WETH_DEPOSIT
0xrin1 Jul 11, 2023
62f7a17
merge main
0xrin1 Jul 13, 2023
4a1e97b
INITIAL USDC and WETH WITHDRAW constant
0xrin1 Jul 13, 2023
f8ad6e4
move INITIAL test constants into test deployment script
0xrin1 Jul 19, 2023
b5a8018
review codestyle
0xrin1 Jul 19, 2023
b1c0b8d
remove LTV diverge logic
0xrin1 Jul 19, 2023
e17328d
pull main
0xrin1 Jul 19, 2023
8e10822
spacing
0xrin1 Jul 19, 2023
39f8d9a
move testing addresses to the bottom
0xrin1 Jul 19, 2023
f8184ec
forge fmt
0xrin1 Jul 19, 2023
bff2bc5
rename classes to match file name
0xrin1 Jul 19, 2023
f20d7e5
deployleveragedethtestnet comment
0xrin1 Jul 19, 2023
3ea8cf4
more comments
0xrin1 Jul 19, 2023
1c7821e
update scWeth targetLTV
0xrin1 Jul 19, 2023
1d59e5c
IPool instead of mock pool and remove unused imports
0xrin1 Jul 19, 2023
1c5f21f
comment clarification
0xrin1 Jul 19, 2023
b58a585
remove redundant deposits
0xrin1 Jul 19, 2023
b6d5563
rename testnet deploy script to forked deploy script
0xrin1 Jul 19, 2023
bd79656
rename sepolia staking script to just staking
0xrin1 Jul 19, 2023
82386d3
DeployStaking
0xrin1 Jul 19, 2023
69a37b7
adjust approve method
0xrin1 Jul 20, 2023
fd37bda
DeploymentConstants.sol
0xrin1 Jul 20, 2023
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
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[profile.default]
optimizer_runs = 1000000
verbosity = 1
solc = "0.8.19"
solc = "0.8.20"

[fuzz]
runs = 256
Expand Down
133 changes: 133 additions & 0 deletions script/DeployLeveragedEthForked.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.13;

import "forge-std/console2.sol";
import "forge-std/Test.sol";
import "forge-std/StdStorage.sol";

import {DeployLeveragedEth} from "./base/DeployLeveragedEth.sol";
import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol";
import {MockWETH} from "../test/mocks/MockWETH.sol";
import {MockUSDC} from "../test/mocks/MockUSDC.sol";
import {Constants as C} from "../src/lib/Constants.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";
import {sc4626} from "../src/sc4626.sol";
import {scWETH} from "../src/steth/scWETH.sol";
import {scUSDC} from "../src/steth/scUSDC.sol";

/**
* Deployment & Fixture exection script to be run against staging forked node.
* i.e.: ` forge script script/DeployLeveragedEthForked.s.sol
* --rpc-url=http://forked-node`
*/
contract DeployLeveragedEthForked is DeployLeveragedEth, Test {
using stdStorage for StdStorage;

uint256 public constant INITIAL_WETH_DEPOSIT = 10e18;
uint256 public constant INITIAL_WETH_WITHDRAW = 1e18;
uint256 public constant INITIAL_USDC_DEPOSIT = 100e6;
uint256 public constant INITIAL_USDC_WITHDRAW = 1e6;
uint256 public constant INITIAL_WETH_FUNDING = 100e18;
uint256 public constant INITIAL_USDC_FUNDING = 10000e6;

function run() external {
_deploy();
_fixtures();
}

function _fixtures() internal {
console2.log("\nexecuting steth fixtures");

_fund();

_deposit(weth, scWeth, alice, INITIAL_WETH_DEPOSIT);
_deposit(weth, scWeth, bob, INITIAL_WETH_DEPOSIT);
_deposit(usdc, scUsdc, alice, INITIAL_USDC_DEPOSIT);
_deposit(usdc, scUsdc, bob, INITIAL_USDC_DEPOSIT);

_rebalance(scWeth);

// double rebalance passes
_rebalance(scUsdc);
_rebalance(scUsdc);

_redeem(scWeth, alice);
_redeem(scWeth, bob);

_redeem(scUsdc, alice);
_redeem(scUsdc, bob);

_deposit(weth, scWeth, alice, INITIAL_WETH_DEPOSIT);
_deposit(weth, scWeth, bob, INITIAL_WETH_DEPOSIT);
_deposit(usdc, scUsdc, alice, INITIAL_USDC_DEPOSIT);
_deposit(usdc, scUsdc, bob, INITIAL_USDC_DEPOSIT);

_profit(); // create scUsdc profit scenario
}

function _fund() internal {
console2.log("funding");

// Dole out ETH
deal(alice, INITIAL_WETH_FUNDING);
deal(bob, INITIAL_WETH_FUNDING);
deal(keeper, INITIAL_WETH_FUNDING);

// Dole out WETH
deal(address(weth), INITIAL_WETH_FUNDING * 2);
deal(address(weth), alice, INITIAL_WETH_FUNDING);
deal(address(weth), bob, INITIAL_WETH_FUNDING);

// Dole out USDC
deal(address(usdc), alice, INITIAL_USDC_FUNDING);
deal(address(usdc), bob, INITIAL_USDC_FUNDING);
}

function _deposit(ERC20 _asset, sc4626 _vault, address _from, uint256 _amount) internal {
console2.log("depositing", _from);

vm.startPrank(_from);
_asset.approve(address(_vault), type(uint256).max);
_vault.deposit(_amount, _from);
vm.stopPrank();
}

function _rebalance(scWETH _vault) internal {
console2.log("rebalancing scWETH");

vm.startPrank(keeper);
_vault.harvest();
vm.stopPrank();
}

function _rebalance(scUSDC _vault) internal {
console2.log("rebalancing scUsdc");

vm.startPrank(keeper);
_vault.rebalance();
vm.stopPrank();
}

function _profit() internal {
console2.log("generate profit for scUsdc vault");

console2.log("scUsdc profit before", scUsdc.getProfit());
deal(address(weth), address(scWeth), INITIAL_WETH_FUNDING);
console2.log("scUsdc profit after", scUsdc.getProfit());
}

function _redeem(scWETH _vault, address _redeemer) internal {
console2.log("redeeming scWETh", _redeemer);

uint256 sharesToRedeem = _vault.convertToShares(INITIAL_WETH_WITHDRAW);
vm.prank(_redeemer);
_vault.redeem(sharesToRedeem, _redeemer, _redeemer);
}

function _redeem(scUSDC _vault, address _redeemer) internal {
console2.log("redeeming scUsdc", _redeemer);

vm.prank(_redeemer);
_vault.withdraw(INITIAL_USDC_WITHDRAW, _redeemer, _redeemer);
}
}
90 changes: 0 additions & 90 deletions script/DeployLeveragedEthLocal.s.sol

This file was deleted.

73 changes: 18 additions & 55 deletions script/DeployLeveragedEthMainnet.s.sol
Original file line number Diff line number Diff line change
@@ -1,73 +1,36 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.13;

import {CREATE3Script} from "./base/CREATE3Script.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";
import {WETH} from "solmate/tokens/WETH.sol";
import {IPool} from "aave-v3/interfaces/IPool.sol";
import {IAToken} from "aave-v3/interfaces/IAToken.sol";
import {IPoolDataProvider} from "aave-v3/interfaces/IPoolDataProvider.sol";
import "forge-std/console2.sol";

import {Constants as C} from "../src/lib/Constants.sol";
import {ICurvePool} from "../src/interfaces/curve/ICurvePool.sol";
import {ILido} from "../src/interfaces/lido/ILido.sol";
import {IwstETH} from "../src/interfaces/lido/IwstETH.sol";
import {AggregatorV3Interface} from "../src/interfaces/chainlink/AggregatorV3Interface.sol";
import {IVault} from "../src/interfaces/balancer/IVault.sol";
import {ISwapRouter} from "../src/interfaces/uniswap/ISwapRouter.sol";
import {DeployLeveragedEth} from "./base/DeployLeveragedEth.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";
import {Constants as C} from "../src/lib/Constants.sol";
import {ISwapRouter} from "../src/interfaces/uniswap/ISwapRouter.sol";

contract DeployScript is MainnetDeployBase {
function run() external returns (scWETH scWeth, scUSDC scUsdc) {
vm.startBroadcast(deployerPrivateKey);
contract DeployLeveragedEthMainnet is DeployLeveragedEth {
function run() external {
_deploy();

scWETH.ConstructorParams memory scWethParams = scWETH.ConstructorParams({
admin: deployerAddress,
keeper: keeper,
targetLtv: 0.7e18,
slippageTolerance: 0.99e18,
aavePool: IPool(C.AAVE_V3_POOL),
aaveAwstEth: IAToken(C.AAVE_V3_AWSTETH_TOKEN),
aaveVarDWeth: ERC20(C.AAVE_V3_VAR_DEBT_WETH_TOKEN),
curveEthStEthPool: ICurvePool(C.CURVE_ETH_STETH_POOL),
stEth: ILido(C.STETH),
wstEth: IwstETH(C.WSTETH),
weth: WETH(payable(C.WETH)),
stEthToEthPriceFeed: AggregatorV3Interface(C.CHAINLINK_STETH_ETH_PRICE_FEED),
balancerVault: IVault(C.BALANCER_VAULT)
});
_postDeployment();
}

scWeth = new scWETH(scWethParams);
function _postDeployment() internal {
vm.startBroadcast(deployerPrivateKey);

weth.deposit{value: 0.01 ether}(); // wrap 0.01 ETH into WETH
// scWETH
console2.log("eth deposited for weth");
_deposit(scWeth, 0.01 ether); // 0.01 WETH
console2.log("weth deposited into wethContract");

_transferAdminRoleToMultisig(scWeth, deployerAddress);

scUSDC.ConstructorParams memory scUsdcParams = scUSDC.ConstructorParams({
admin: deployerAddress,
keeper: keeper,
scWETH: scWeth,
usdc: usdc,
weth: WETH(payable(C.WETH)),
aavePool: IPool(C.AAVE_V3_POOL),
aavePoolDataProvider: IPoolDataProvider(C.AAVE_V3_POOL_DATA_PROVIDER),
aaveAUsdc: IAToken(C.AAVE_V3_AUSDC_TOKEN),
aaveVarDWeth: ERC20(C.AAVE_V3_VAR_DEBT_WETH_TOKEN),
uniswapSwapRouter: ISwapRouter(C.UNISWAP_V3_SWAP_ROUTER),
chainlinkUsdcToEthPriceFeed: AggregatorV3Interface(C.CHAINLINK_USDC_ETH_PRICE_FEED),
balancerVault: IVault(C.BALANCER_VAULT)
});

scUsdc = new scUSDC(scUsdcParams);

// scUSDC
console2.log("eth deposited for weth to swap for usdc");
_swapWethForUsdc(0.01 ether);
console2.log("eth swapped for USDC");
_deposit(scUsdc, usdc.balanceOf(address(deployerAddress))); // 0.01 ether worth of USDC

_transferAdminRoleToMultisig(scUsdc, deployerAddress);
console2.log("usdc deposited into usdcContract");

vm.stopBroadcast();
}
Expand Down
19 changes: 0 additions & 19 deletions script/DeployLeveragedEthTestnet.s.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {CREATE3Script} from "./base/CREATE3Script.sol";
import {RewardTracker} from "../src/staking/RewardTracker.sol";
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";

contract DeployScript is CREATE3Script {
contract DeployStaking is CREATE3Script {
bytes32 public constant DISTRIBUTOR = keccak256("DISTRIBUTOR");
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

Expand Down
Loading