Skip to content

Commit

Permalink
refactor: deploy scripts (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xashu authored May 26, 2024
1 parent f99f2ff commit cfa0153
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 63 deletions.
15 changes: 13 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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=
OPTIMISM_MAINNET_RPC=

CYBER_SEPOLIA_RPC=
CYBER_MAINNET_RPC=

# Etherscan API keys
ETHEREUM_ETHERSCAN_API_KEY=
OPTIMISM_ETHERSCAN_API_KEY=
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
${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
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<samp>
<sub><em>Value4Value</em></sub>
<sub><em>Time4Value</em></sub>

<div align="center">
<br />
<em>A NEW WAY TO PAY.</em> <br />
<em>Payment via the bonding curve and yield farming.</em>
<br />
A NEW WAY TO PAY. <br />
Payment via the bonding curve and yield farming. <br />
Sell your cryptocurrency time, and buy something with value. <br />
</div>
</samp>

Expand All @@ -28,7 +28,7 @@ The contract uses a sigmoid bonding curve for dynamic pricing. When you buy, it
<img src="images/curve.gif" width="80%">
</div>

## Why it is better?
## Why is it better?
<div align="center">

| Features | V4V | Friendtech | Patreon | Coinbase Commerce |
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
50 changes: 50 additions & 0 deletions scripts/Base.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
63 changes: 13 additions & 50 deletions scripts/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,45 @@

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);

/*
********************************************************************************
* Mauunal steps to be executed after deploying this 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();
}
}
45 changes: 45 additions & 0 deletions scripts/DeployAave.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit cfa0153

Please sign in to comment.