new deployment scripts

This commit is contained in:
JulesCrown 2024-09-17 15:48:59 +02:00
parent 18a57c0ead
commit b4dfb03590
5 changed files with 54 additions and 31 deletions

View file

@ -0,0 +1,85 @@
pragma solidity ^0.8.19;
import "forge-std/Script.sol";
import {TwabController} from "pt-v5-twab-controller/TwabController.sol";
import "@uniswap-v3-core/interfaces/IUniswapV3Factory.sol";
import "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol";
import "../src/Harberg.sol";
import "../src/Stake.sol";
import {LiquidityManager} from "../src/LiquidityManager.sol";
uint24 constant FEE = uint24(10_000);
contract DeployScript is Script {
bool token0isWeth;
address feeDest;
address weth;
address v3Factory;
address twabc;
function sqrt(uint256 y) internal pure returns (uint256 z) {
if (y > 3) {
z = y;
uint256 x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
// z is now the integer square root of y, or the closest integer to the square root of y.
}
function initializePoolFor1Cent(address _pool) public {
uint256 price;
if (token0isWeth) {
// ETH as token0, so we are setting the price of 1 ETH in terms of token1 (USD cent)
price = 3000 * 10**20; // 1 ETH = 3700 USD, scaled by 10^18 for precision
} else {
// Token (valued at 1 USD cent) as token0, ETH as token1
// We invert the logic to represent the price of 1 token in terms of ETH
price = uint256(10**16) / 3700; // Adjust for 18 decimal places
}
uint160 sqrtPriceX96 = uint160(sqrt(price) * 2**96 / 10**9); // Adjust sqrt value to 96-bit precision
console.log(uint160(sqrt(3000 * 10**20) * 2**96 / 10**9));
// Initialize pool with the calculated sqrtPriceX96
IUniswapV3Pool(_pool).initialize(sqrtPriceX96);
}
function run() public {
string memory seedPhrase = vm.readFile(".secret");
uint256 privateKey = vm.deriveKey(seedPhrase, 0);
vm.startBroadcast(privateKey);
address sender = vm.addr(privateKey);
console.log(sender);
TwabController tc;
if (twabc == address(0)) {
tc = TwabController(twabc);
} else {
// in case you want to deploy an new TwabController
tc = new TwabController(60 * 60, uint32(block.timestamp));
}
Harberg harb = new Harberg("Harbergerger Tax", "HARB", tc);
token0isWeth = address(weth) < address(harb);
Stake stake = new Stake(address(harb));
harb.setStakingPool(address(stake));
IUniswapV3Factory factory = IUniswapV3Factory(v3Factory);
address liquidityPool = factory.createPool(weth, address(harb), FEE);
initializePoolFor1Cent(liquidityPool);
harb.setLiquidityPool(liquidityPool);
LiquidityManager liquidityManager = new LiquidityManager(v3Factory, weth, address(harb));
liquidityManager.setFeeDestination(feeDest);
// note: this delayed initialization is not a security issue.
harb.setLiquidityManager(address(liquidityManager));
(bool sent, ) = address(liquidityManager).call{value: 0.1 ether}("");
require(sent, "Failed to send Ether");
//TODO: wait few minutes and call recenter
vm.stopBroadcast();
}
}