From cfa01538450127902a0fc3310a235fea0501883e Mon Sep 17 00:00:00 2001 From: ashu Date: Sun, 26 May 2024 21:37:36 +0800 Subject: [PATCH] refactor: deploy scripts (#29) --- .env.example | 15 ++++++++-- Makefile | 16 ++++++++-- README.md | 22 +++++++++----- scripts/Base.s.sol | 50 +++++++++++++++++++++++++++++++ scripts/Deploy.s.sol | 63 +++++++++------------------------------- scripts/DeployAave.s.sol | 45 ++++++++++++++++++++++++++++ 6 files changed, 148 insertions(+), 63 deletions(-) create mode 100644 scripts/Base.s.sol create mode 100644 scripts/DeployAave.s.sol diff --git a/.env.example b/.env.example index 203f50f..4584249 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,15 @@ -ETHERSCAN_API_KEY= +# Used by the multi-chain deployment script + +# General PRIVATE_KEY= + +# RPC URLs OPTIMISM_SEPOLIA_RPC= -OPTIMISM_MAINNET_RPC= \ No newline at end of file +OPTIMISM_MAINNET_RPC= + +CYBER_SEPOLIA_RPC= +CYBER_MAINNET_RPC= + +# Etherscan API keys +ETHEREUM_ETHERSCAN_API_KEY= +OPTIMISM_ETHERSCAN_API_KEY= \ No newline at end of file diff --git a/Makefile b/Makefile index 8e40490..e045e26 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,17 @@ -.PHONY: deploy-testnet deploy-mainnet +.PHONY: deploy-testnet deploy-mainnet deploy-aave + +DEPLOY_CMD=source .env && forge script scripts/Deploy.s.sol:DeployScript +DEPLOY_AAVE_CMD=source .env && forge script scripts/DeployAave.s.sol:DeployAaveScript +VERIFY_CMD=--etherscan-api-key $$OPTIMISM_ETHERSCAN_API_KEY --verify deploy-testnet: - source .env && forge script scripts/Deploy.s.sol:DeployScript --rpc-url $$OPTIMISM_SEPOLIA_RPC --broadcast --verify -vvvv + ${DEPLOY_CMD} --rpc-url $$OPTIMISM_TESTNET_RPC --broadcast ${VERIFY_CMD} -vvvv + ${DEPLOY_CMD} --rpc-url $$CYBER_TESTNET_RPC --broadcast -vvvv deploy-mainnet: - source .env && forge script scripts/Deploy.s.sol:DeployScript --rpc-url $$OPTIMISM_MAINNET_RPC --broadcast --verify -vvvv \ No newline at end of file + ${DEPLOY_CMD} --rpc-url $$OPTIMISM_MAINNET_RPC --broadcast ${VERIFY_CMD} -vvvv + ${DEPLOY_CMD} --rpc-url $$CYBER_MAINNET_RPC --broadcast -vvvv + +deploy-aave: + ${DEPLOY_AAVE_CMD} --rpc-url $$OPTIMISM_TESTNET_RPC --broadcast ${VERIFY_CMD} -vvvv + ${DEPLOY_AAVE_CMD} --rpc-url $$OPTIMISM_MAINNET_RPC --broadcast ${VERIFY_CMD} -vvvv \ No newline at end of file diff --git a/README.md b/README.md index a7564b0..ce96456 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ - Value4Value + Time4Value

- A NEW WAY TO PAY.
- Payment via the bonding curve and yield farming. -
+ A NEW WAY TO PAY.
+ Payment via the bonding curve and yield farming.
+ Sell your cryptocurrency time, and buy something with value.
@@ -28,7 +28,7 @@ The contract uses a sigmoid bonding curve for dynamic pricing. When you buy, it -## Why it is better? +## Why is it better?
| Features | V4V | Friendtech | Patreon | Coinbase Commerce | @@ -50,7 +50,9 @@ The contract uses a sigmoid bonding curve for dynamic pricing. When you buy, it | Network | Address | |------------------|--------------------------------------------| | Optimism Mainnet | N/A | -| Optimism Sepolia | 0x07cB2490DfBFd63613318F87156D935ddAcb62F4 | +| Optimism Sepolia | 0x4aCF2aF23f51b7008dF3518A1511871F87083C38 | +| Cyber Mainnet | N/A | +| Cyber Sepolia | 0x552d348657fafd661372f5864093dd9555a2ef06 | ### Shares @@ -59,7 +61,9 @@ The contract uses a sigmoid bonding curve for dynamic pricing. When you buy, it | Network | Address | |------------------|--------------------------------------------| | Optimism Mainnet | N/A | -| Optimism Sepolia | 0x5F31921A68eA5b350baF141536933Cc7d70EBAEa | +| Optimism Sepolia | 0x9F94C75341D23EAb48793b2879F6062a400132e3 | +| Cyber Mainnet | N/A | +| Cyber Sepolia | 0x1b05f188388b49ee9053914d3109119d228060b5 | ### Yield @@ -68,7 +72,9 @@ The contract uses a sigmoid bonding curve for dynamic pricing. When you buy, it | Network | Address | |------------------|--------------------------------------------| | Optimism Mainnet | N/A | -| Optimism Sepolia | 0x2c1414c3F442AA7a4E531E2891009Dd1a8744b59 | +| Optimism Sepolia | 0xc1eB8f8119De78Da6852F2607d5525d849FCBaaE | +| Cyber Mainnet | N/A | +| Cyber Sepolia | 0xba2553060e90551c797bebd48ee04909606bb04f | ## Test and Deploy diff --git a/scripts/Base.s.sol b/scripts/Base.s.sol new file mode 100644 index 0000000..9684466 --- /dev/null +++ b/scripts/Base.s.sol @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: UNLICENSED + +pragma solidity 0.8.25; + +import { Script } from "forge-std/Script.sol"; + +contract BaseScript is Script { + // TEMPORARY + // It will be replaced with multi-sig wallet. + address public OWNER = 0xdA1d0C7f174effBA98Ea1E31424418DC9aeaEa22; + + uint256 public constant OPTIMISM_MAINNET = 10; + uint256 public constant OPTIMISM_TESTNET = 11155420; + uint256 public constant CYBER_MAINNET = 7560; + uint256 public constant CYBER_TESTNET = 111557560; + + mapping(uint chainid => address shares_factory) public SHARES_FACTORY; + mapping(uint chainid => address weth) public WETH; + mapping(uint chainid => address aave_pool) public AAVE_POOL; + mapping(uint chainid => address aave_weth_gateway) public AAVE_WETH_GATEWAY; + + constructor() { + // Optimism Sepolia + SHARES_FACTORY[OPTIMISM_TESTNET] = 0x9F94C75341D23EAb48793b2879F6062a400132e3; + WETH[OPTIMISM_TESTNET] = 0x4200000000000000000000000000000000000006; + AAVE_POOL[OPTIMISM_TESTNET] = 0xb50201558B00496A145fE76f7424749556E326D8; + AAVE_WETH_GATEWAY[OPTIMISM_TESTNET] = 0x589750BA8aF186cE5B55391B0b7148cAD43a1619; + + // Optimism Mainnet + SHARES_FACTORY[OPTIMISM_MAINNET] = address(0); + WETH[OPTIMISM_MAINNET] = 0x4200000000000000000000000000000000000006; + AAVE_POOL[OPTIMISM_MAINNET] = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; + AAVE_WETH_GATEWAY[OPTIMISM_MAINNET] = 0xe9E52021f4e11DEAD8661812A0A6c8627abA2a54; + + // Cyber Sepolia + WETH[CYBER_TESTNET] = 0x4200000000000000000000000000000000000006; + SHARES_FACTORY[CYBER_TESTNET] = address(0); + + // Cyber Mainnet + WETH[CYBER_MAINNET] = address(0); + SHARES_FACTORY[CYBER_MAINNET] = address(0); + } + + modifier broadcast() { + uint256 broadcaster = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(broadcaster); + _; + vm.stopBroadcast(); + } +} \ No newline at end of file diff --git a/scripts/Deploy.s.sol b/scripts/Deploy.s.sol index 626bc96..5b3a4b2 100644 --- a/scripts/Deploy.s.sol +++ b/scripts/Deploy.s.sol @@ -2,63 +2,35 @@ pragma solidity 0.8.25; -import { Script } from "forge-std/Script.sol"; +import { BaseScript } from "./Base.s.sol"; import { SharesFactoryV1 } from "contracts/core/SharesFactoryV1.sol"; import { SharesERC1155 } from "contracts/core/SharesERC1155.sol"; -import { AaveYieldAggregator } from "contracts/core/aggregator/AaveYieldAggregator.sol"; import { BlankYieldAggregator } from "contracts/core/aggregator/BlankYieldAggregator.sol"; -import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import { IAavePool } from "contracts/interface/IAave.sol"; -contract DeployScript is Script { +contract DeployScript is BaseScript { SharesFactoryV1 public sharesFactory; SharesERC1155 public sharesNFT; - - AaveYieldAggregator public aaveYieldAggregator; BlankYieldAggregator public blankYieldAggregator; - // Optimism Sepolia - address public OWNER = 0xdA1d0C7f174effBA98Ea1E31424418DC9aeaEa22; - address public WETH = 0x4200000000000000000000000000000000000006; - address public AAVE_POOL = 0xb50201558B00496A145fE76f7424749556E326D8; - address public AAVE_WETH_GATEWAY = 0x589750BA8aF186cE5B55391B0b7148cAD43a1619; - - // Optimism Mainnet - // address public OWNER = 0xdA1d0C7f174effBA98Ea1E31424418DC9aeaEa22; - // address public WETH = 0x4200000000000000000000000000000000000006; - // address public AAVE_POOL = 0x794a61358D6845594F94dc1DB02A252b5b4814aD; - // address public AAVE_WETH_GATEWAY = 0xe9E52021f4e11DEAD8661812A0A6c8627abA2a54; - - IERC20 public aWETH = IERC20(IAavePool(AAVE_POOL).getReserveData(WETH).aTokenAddress); - string public constant BASE_URI = "https://vv.meme/shares/uri/"; - uint256 public constant BASE_PRICE = 5000000000000000; // 0.005 ETH as base price - uint256 public constant INFLECTION_POINT = 1500; - uint256 public constant INFLECTION_PRICE = 102500000000000000; - uint256 public constant LINEAR_PRICE_SLOPE = 0; + uint96 public constant BASE_PRICE = 0.005 ether; + uint32 public constant INFLECTION_POINT = 1500; + uint128 public constant INFLECTION_PRICE = 0.1025 ether; + uint128 public constant LINEAR_PRICE_SLOPE = 0; - function run() public virtual { - uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); - vm.startBroadcast(deployerPrivateKey); + function run() public virtual broadcast() { + require(WETH[block.chainid] != address(0), "WETH not set"); sharesNFT = new SharesERC1155(BASE_URI); - - sharesFactory = new SharesFactoryV1( - address(sharesNFT), - BASE_PRICE, - INFLECTION_POINT, - INFLECTION_PRICE, - LINEAR_PRICE_SLOPE - ); - - aaveYieldAggregator = new AaveYieldAggregator(address(sharesFactory), WETH, AAVE_POOL, AAVE_WETH_GATEWAY); - blankYieldAggregator = new BlankYieldAggregator(address(sharesFactory), WETH); + sharesFactory = new SharesFactoryV1(address(sharesNFT), BASE_PRICE, INFLECTION_POINT, INFLECTION_PRICE, LINEAR_PRICE_SLOPE); + blankYieldAggregator = new BlankYieldAggregator(address(sharesFactory), WETH[block.chainid]); + // initialize sharesFactory.resetYield(address(blankYieldAggregator)); sharesNFT.setFactory(address(sharesFactory)); + // ownership sharesNFT.transferOwnership(OWNER); - aaveYieldAggregator.transferOwnership(OWNER); /* ******************************************************************************** @@ -66,18 +38,9 @@ contract DeployScript is Script { ******************************************************************************** */ - // Note: SharesFactory transfer ownership with 2-step process + // Note: Transfer sharesFactory ownership with 2-step process // sharesFactory.transferOwnership(owner); // vm.prank(owner); // sharesFactory.acceptOwnership(); - - // Note: Migrate yield from BlankYieldAggregator to AaveYieldAggregator with 3 days delay - // vm.startPrank(owner); - // sharesFactory.queueMigrateYield(address(aaveYieldAggregator)); - // vm.warp(block.timestamp + 3 days); - // sharesFactory.executeMigrateYield(); - // vm.stopPrank(); - - vm.stopBroadcast(); } } diff --git a/scripts/DeployAave.s.sol b/scripts/DeployAave.s.sol new file mode 100644 index 0000000..6f5275a --- /dev/null +++ b/scripts/DeployAave.s.sol @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: UNLICENSED + +pragma solidity 0.8.25; + +import { BaseScript } from "./Base.s.sol"; +import { AaveYieldAggregator } from "contracts/core/aggregator/AaveYieldAggregator.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import { IAavePool } from "contracts/interface/IAave.sol"; + +contract DeployAaveScript is BaseScript { + AaveYieldAggregator public aaveYieldAggregator; + + function run() public virtual broadcast { + require(SHARES_FACTORY[block.chainid] != address(0), "SAHRES_FACTORY not set"); + require(WETH[block.chainid] != address(0), "WETH not set"); + require(AAVE_POOL[block.chainid] != address(0), "AAVE_POOL not set"); + require(AAVE_WETH_GATEWAY[block.chainid] != address(0), "AAVE_WETH_GATEWAY not set"); + + if ( + block.chainid == OPTIMISM_MAINNET || + block.chainid == OPTIMISM_TESTNET + ) { + aaveYieldAggregator = new AaveYieldAggregator( + SHARES_FACTORY[block.chainid], + WETH[block.chainid], + AAVE_POOL[block.chainid], + AAVE_WETH_GATEWAY[block.chainid] + ); + aaveYieldAggregator.transferOwnership(OWNER); + } + + /* + ******************************************************************************** + * Mauunal steps to be executed after deploying this script + ******************************************************************************** + */ + + // Note: Migrate to AaveYieldAggregator with 3 days delay + // vm.startPrank(owner); + // sharesFactory.queueMigrateYield(address(aaveYieldAggregator)); + // vm.warp(block.timestamp + 3 days); + // sharesFactory.executeMigrateYield(); + // vm.stopPrank(); + } +}