harb/onchain/script/Deploy.sol
2024-06-25 10:33:33 +02:00

77 lines
3.1 KiB
Solidity

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/Harb.sol";
import "../src/Stake.sol";
import {BaseLineLP} from "../src/BaseLineLP.sol";
address constant WETH = 0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14; //Sepolia
address constant V3_FACTORY = 0x0227628f3F023bb0B980b67D528571c95c6DaC1c; //Sepolia
address constant TWABC = 0x64ddA11815B883C589AFeD914666ef2D63C8C338; //new TwabController(60 * 60 * 24, uint32(block.timestamp));
uint24 constant FEE = uint24(10_000);
contract SepoliaScript is Script {
bool token0isWeth;
function setUp() public {}
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);
TwabController tc = TwabController(TWABC);
//TwabController tc = new TwabController(60 * 60, uint32(block.timestamp));
Harb harb = new Harb("Harberger Tax", "HARB", tc);
token0isWeth = address(WETH) < address(harb);
Stake stake = new Stake(address(harb));
harb.setStakingPool(address(stake));
IUniswapV3Factory factory = IUniswapV3Factory(V3_FACTORY);
address liquidityPool = factory.createPool(WETH, address(harb), FEE);
initializePoolFor1Cent(liquidityPool);
harb.setLiquidityPool(liquidityPool);
BaseLineLP liquidityManager = new BaseLineLP(V3_FACTORY, WETH, address(harb));
harb.setLiquidityManager(address(liquidityManager));
//TODO: send some eth and call slide
(bool sent, ) = address(liquidityManager).call{value: 0.1 ether}("");
require(sent, "Failed to send Ether");
vm.stopBroadcast();
}
}