Skip to content

Commit

Permalink
Work in progress deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
zmanian committed Aug 23, 2024
1 parent fd93c2e commit d6979fb
Show file tree
Hide file tree
Showing 2 changed files with 231 additions and 12 deletions.
24 changes: 12 additions & 12 deletions resources/PeggyJVContractDeploymentNames.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ contract ContractDeploymentNames {
string public convexCurveAdaptorName = "PJV Convex Curve Adaptor V 0.0";

// Vault Names
string public realYieldUsdName = "Real Yield USD V0.0";
string public realYieldEthName = "Real Yield ETH V0.1";
string public realYieldMaticName = "Real Yield MATIC V0.0";
string public realYieldAvaxName = "Real Yield AVAX V0.0";
string public turboRSETHName = "Turbo RSETH V0.0";
string public turboEZETHName = "Turbo EZETH V0.0";
string public realYieldUsdName = "PJV2 Real Yield USD V0.0";
string public realYieldEthName = "PJV2 Real Yield ETH V0.1";
string public realYieldMaticName = "PJV2 Real Yield MATIC V0.0";
string public realYieldAvaxName = "PJV2 Real Yield AVAX V0.0";
string public turboRSETHName = " PJV2 Turbo RSETH V0.0";
string public turboEZETHName = "PJV2 Turbo EZETH V0.0";

// Share Price Oracle Names
string public realYieldUsdSharePriceOracleName = "Real Yield USD Share Price Oracle V0.0";
string public realYieldEthSharePriceOracleName = "Real Yield ETH Share Price Oracle V0.1";
string public realYieldMaticSharePriceOracleName = "Real Yield MATIC Share Price Oracle V0.0";
string public realYieldAvaxSharePriceOracleName = "Real Yield AVAX Share Price Oracle V0.0";
string public realYieldUsdSharePriceOracleName = "PJV Real Yield USD Share Price Oracle V0.0";
string public realYieldEthSharePriceOracleName = "PJV Real Yield ETH Share Price Oracle V0.1";
string public realYieldMaticSharePriceOracleName = "PJV Real Yield MATIC Share Price Oracle V0.0";
string public realYieldAvaxSharePriceOracleName = "PJV Real Yield AVAX Share Price Oracle V0.0";

// Cellar Staking Contracts
string public realYieldUsdStakingName = "Real Yield USD Staking V0.0";
string public realYieldEthStakingName = "Real Yield ETH Staking V0.1";
string public realYieldUsdStakingName = "PJV Real Yield USD Staking V0.0";
string public realYieldEthStakingName = "PJV Real Yield ETH Staking V0.1";
// Mainnet
// TODO morpho adaptors
// aave v2 adaptors
Expand Down
219 changes: 219 additions & 0 deletions script/Arbitrum/peggyjv_production/DeployTestCellar.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.21;

import { Deployer } from "src/Deployer.sol";
import { Registry } from "src/Registry.sol";
import { PriceRouter } from "src/modules/price-router/PriceRouter.sol";
import { SequencerPriceRouter } from "src/modules/price-router/permutations/SequencerPriceRouter.sol";
import { ArbitrumAddresses } from "test/resources/Arbitrum/ArbitrumAddressesPeggyJV.sol";
import { ContractDeploymentNames } from "resources/PeggyJVContractDeploymentNames.sol";
import { SafeTransferLib } from "@solmate/utils/SafeTransferLib.sol";
import { ERC20 } from "@solmate/tokens/ERC20.sol";

import { CellarWithOracleWithBalancerFlashLoansWithMultiAssetDeposit } from "src/base/permutations/advanced/CellarWithOracleWithBalancerFlashLoansWithMultiAssetDeposit.sol";
import { CellarWithOracleWithBalancerFlashLoansWithMultiAssetDepositWithNativeSupport } from "src/base/permutations/advanced/CellarWithOracleWithBalancerFlashLoansWithMultiAssetDepositWithNativeSupport.sol";
import { ERC4626SharePriceOracle } from "src/base/ERC4626SharePriceOracle.sol";

import { PositionIds } from "resources/PositionIds.sol";
import { Math } from "src/utils/Math.sol";

import "forge-std/Script.sol";
import "forge-std/StdJson.sol";

/**
* source .env && forge script script/Arbitrum/production/DeployTestCellar.s.sol:DeployRealYieldProductsScript --evm-version london --with-gas-price 100000000 --slow --broadcast --etherscan-api-key $ARBISCAN_KEY --verify
* If you need to verify contracts after deployment run the following command
* source .env && forge script script/Arbitrum/production/DeployTestCellar.s.sol:DeployRealYieldProductsScript --evm-version london --etherscan-api-key $ARBISCAN_KEY --verify --resume --rpc-url $ARBITRUM_RPC_URL
* @dev Optionally can change `--with-gas-price` to something more reasonable
*/
contract DeployRealYieldProductsScript is Script, ArbitrumAddresses, ContractDeploymentNames, PositionIds {
using SafeTransferLib for ERC20;
using Math for uint256;
using stdJson for string;

address public cellarOwner = dev0Address;
uint256 public privateKey;
Deployer public deployer = Deployer(deployerAddress);
Registry public registry;
PriceRouter public priceRouter;
address public erc20Adaptor;
address public swapWithUniswapAdaptor;
address public uniswapV3Adaptor;
address public aaveV3ATokenAdaptor;
address public aaveV3DebtTokenAdaptor;
address public erc4626Adaptor;
address public oneInchAdaptor;
address public zeroXAdaptor;

CellarWithOracleWithBalancerFlashLoansWithMultiAssetDeposit public RYUSD;
CellarWithOracleWithBalancerFlashLoansWithMultiAssetDepositWithNativeSupport public RYE;

function setUp() external {
privateKey = vm.envUint("PRIVATE_KEY");
vm.createSelectFork("arbitrum");
registry = Registry(deployer.getAddress(registryName));
priceRouter = PriceRouter(deployer.getAddress(priceRouterName));
erc20Adaptor = deployer.getAddress(erc20AdaptorName);
swapWithUniswapAdaptor = deployer.getAddress(swapWithUniswapAdaptorName);
uniswapV3Adaptor = deployer.getAddress(uniswapV3AdaptorName);
aaveV3ATokenAdaptor = deployer.getAddress(aaveV3ATokenAdaptorName);
aaveV3DebtTokenAdaptor = deployer.getAddress(aaveV3DebtTokenAdaptorName);
erc4626Adaptor = deployer.getAddress(erc4626AdaptorName);
oneInchAdaptor = deployer.getAddress(oneInchAdaptorName);
zeroXAdaptor = deployer.getAddress(zeroXAdaptorName);
}

function run() external {
ERC4626SharePriceOracle.ConstructorArgs memory args;
args._heartbeat = 1 days;
args._deviationTrigger = 0.005e4;
args._gracePeriod = 1 days / 3;
args._observationsToUse = 4;
args._automationRegistry = automationRegistry;
args._automationRegistrar = automationRegistrar;
args._automationAdmin = devStrategist;
args._link = address(LINK);
args._startingAnswer = 1e18;
args._allowedAnswerChangeLower = 0.75e4;
args._allowedAnswerChangeUpper = 1.25e4;
args._sequencerUptimeFeed = ARB_SEQUENCER_UPTIME_FEED;
args._sequencerGracePeriod = 3_600;
vm.startBroadcast(privateKey);

// Deploy RYE.
RYE = _createCellarWithNativeSupport(
realYieldEthName,
"Test PJV2 Real Yield ETH",
"RYETEST",
WETH,
ERC20_WETH_POSITION,
abi.encode(true),
0.0001e18,
0.8e18
);

// Setup Real Yield ETH.
RYE.addAdaptorToCatalogue(swapWithUniswapAdaptor);
RYE.addAdaptorToCatalogue(uniswapV3Adaptor);
RYE.addAdaptorToCatalogue(aaveV3ATokenAdaptor);
RYE.addAdaptorToCatalogue(aaveV3DebtTokenAdaptor);
RYE.addAdaptorToCatalogue(erc4626Adaptor);
RYE.addAdaptorToCatalogue(oneInchAdaptor);
RYE.addAdaptorToCatalogue(zeroXAdaptor);
RYE.addPositionToCatalogue(ERC20_WETH_POSITION);
RYE.addPositionToCatalogue(ERC20_WSTETH_POSITION);
RYE.addPositionToCatalogue(ERC20_RETH_POSITION);
RYE.addPositionToCatalogue(AAVE_V3_LOW_HF_A_WETH_POSITION);
RYE.addPositionToCatalogue(AAVE_V3_LOW_HF_A_WSTETH_POSITION);
RYE.addPositionToCatalogue(AAVE_V3_LOW_HF_A_RETH_POSITION);
RYE.addPositionToCatalogue(AAVE_V3_LOW_HF_DEBT_WETH_POSITION);
RYE.addPositionToCatalogue(AAVE_V3_LOW_HF_DEBT_WSTETH_POSITION);
RYE.addPositionToCatalogue(AAVE_V3_LOW_HF_DEBT_RETH_POSITION);
RYE.addPositionToCatalogue(UNISWAP_V3_WETH_WSTETH_POSITION);
RYE.addPositionToCatalogue(UNISWAP_V3_WETH_RETH_POSITION);
RYE.addPositionToCatalogue(UNISWAP_V3_WSTETH_RETH_POSITION);

// Create Share Price Oracle for RYE.
args._target = RYE;
_createSharePriceOracle(realYieldEthSharePriceOracleName, args);

// Also Create a dummy Share Price Oracles for RYUSD and RYE.
args._heartbeat = 300; // 5 min.
args._gracePeriod = 30 days;
args._allowedAnswerChangeLower = 0.1e4;
args._allowedAnswerChangeUpper = 10e4;

args._target = RYE;
_createSharePriceOracle("Test PJV RYE Share Price Oracle V 0.0", args);

vm.stopBroadcast();
}

function _createSharePriceOracle(
string memory _name,
ERC4626SharePriceOracle.ConstructorArgs memory args
) internal returns (ERC4626SharePriceOracle) {
bytes memory creationCode;
bytes memory constructorArgs;
creationCode = type(ERC4626SharePriceOracle).creationCode;
constructorArgs = abi.encode(args);

return ERC4626SharePriceOracle(deployer.deployContract(_name, creationCode, constructorArgs, 0));
}

function _createCellarNoNativeSupport(
string memory deploymentName,
string memory cellarName,
string memory cellarSymbol,
ERC20 holdingAsset,
uint32 holdingPosition,
bytes memory holdingPositionConfig,
uint256 initialDeposit,
uint64 platformCut
) internal returns (CellarWithOracleWithBalancerFlashLoansWithMultiAssetDeposit) {
// Approve new cellar to spend assets.
string memory nameToUse = deploymentName;
address cellarAddress = deployer.getAddress(nameToUse);
holdingAsset.safeApprove(cellarAddress, initialDeposit);

bytes memory creationCode;
bytes memory constructorArgs;
creationCode = type(CellarWithOracleWithBalancerFlashLoansWithMultiAssetDeposit).creationCode;
constructorArgs = abi.encode(
cellarOwner,
registry,
holdingAsset,
cellarName,
cellarSymbol,
holdingPosition,
holdingPositionConfig,
initialDeposit,
platformCut,
type(uint192).max,
address(vault)
);

return
CellarWithOracleWithBalancerFlashLoansWithMultiAssetDeposit(
deployer.deployContract(nameToUse, creationCode, constructorArgs, 0)
);
}

function _createCellarWithNativeSupport(
string memory deploymentName,
string memory cellarName,
string memory cellarSymbol,
ERC20 holdingAsset,
uint32 holdingPosition,
bytes memory holdingPositionConfig,
uint256 initialDeposit,
uint64 platformCut
) internal returns (CellarWithOracleWithBalancerFlashLoansWithMultiAssetDepositWithNativeSupport) {
// Approve new cellar to spend assets.
string memory nameToUse = deploymentName;
address cellarAddress = deployer.getAddress(nameToUse);
holdingAsset.safeApprove(cellarAddress, initialDeposit);

bytes memory creationCode;
bytes memory constructorArgs;
creationCode = type(CellarWithOracleWithBalancerFlashLoansWithMultiAssetDepositWithNativeSupport).creationCode;
constructorArgs = abi.encode(
cellarOwner,
registry,
holdingAsset,
cellarName,
cellarSymbol,
holdingPosition,
holdingPositionConfig,
initialDeposit,
platformCut,
type(uint192).max,
address(vault)
);

return
CellarWithOracleWithBalancerFlashLoansWithMultiAssetDepositWithNativeSupport(
payable(deployer.deployContract(nameToUse, creationCode, constructorArgs, 0))
);
}
}

0 comments on commit d6979fb

Please sign in to comment.