feature/simulations (#11)
this pull request: - creates a unit test that can take any scenario file (default: `out/scenario.json` and play it back on the deployment - during the playback a debug trace generated in `timeSeries.csv` - extracts the sentimenter into a separate upgradeable contract Co-authored-by: JulesCrown <admin@noip.localhost> Co-authored-by: giteadmin <gite@admin.com> Reviewed-on: http://gitea.loseyourip.com:4000/dark-meme-society/harb/pulls/11
This commit is contained in:
parent
38e1b65b94
commit
bb34d0725f
15 changed files with 1159 additions and 451 deletions
|
|
@ -6,57 +6,27 @@ import "@uniswap-v3-core/interfaces/IUniswapV3Factory.sol";
|
|||
import "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol";
|
||||
import "../src/Harberg.sol";
|
||||
import "../src/Stake.sol";
|
||||
import "../src/Sentimenter.sol";
|
||||
import "../src/helpers/UniswapHelpers.sol";
|
||||
import {LiquidityManager} from "../src/LiquidityManager.sol";
|
||||
import {ERC1967Proxy} from "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol";
|
||||
|
||||
uint24 constant FEE = uint24(10_000);
|
||||
|
||||
contract DeployScript is Script {
|
||||
using UniswapHelpers for IUniswapV3Pool;
|
||||
|
||||
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)) {
|
||||
|
|
@ -71,9 +41,12 @@ contract DeployScript is Script {
|
|||
harb.setStakingPool(address(stake));
|
||||
IUniswapV3Factory factory = IUniswapV3Factory(v3Factory);
|
||||
address liquidityPool = factory.createPool(weth, address(harb), FEE);
|
||||
initializePoolFor1Cent(liquidityPool);
|
||||
IUniswapV3Pool(liquidityPool).initializePoolFor1Cent(token0isWeth);
|
||||
harb.setLiquidityPool(liquidityPool);
|
||||
LiquidityManager liquidityManager = new LiquidityManager(v3Factory, weth, address(harb));
|
||||
Sentimenter sentimenter = new Sentimenter();
|
||||
bytes memory params = abi.encodeWithSignature("initialize(address,address)", address(harb),address(stake));
|
||||
ERC1967Proxy proxy = new ERC1967Proxy(address(sentimenter), params);
|
||||
LiquidityManager liquidityManager = new LiquidityManager(v3Factory, weth, address(harb), address(proxy));
|
||||
liquidityManager.setFeeDestination(feeDest);
|
||||
// note: this delayed initialization is not a security issue.
|
||||
harb.setLiquidityManager(address(liquidityManager));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue