Skip to content

Commit

Permalink
remove initialize router
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Mar 13, 2024
1 parent cf95602 commit 9fe830e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
8 changes: 3 additions & 5 deletions script/01a_CreatePool.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "forge-std/console.sol";
import {PoolInitializeTest} from "v4-core/src/test/PoolInitializeTest.sol";
import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";
import {IHooks} from "v4-core/src/interfaces/IHooks.sol";
import {PoolKey} from "v4-core/src/types/PoolKey.sol";
import {CurrencyLibrary, Currency} from "v4-core/src/types/Currency.sol";
Expand All @@ -13,13 +13,11 @@ contract CreatePoolScript is Script {
using CurrencyLibrary for Currency;

//addresses with contracts deployed
address constant POOL_INITIALIZE_ROUTER = address(0x0); // TODO: Update once deployed
address constant POOL_MANAGER = address(0x0); // TODO: Update once deployed
address constant MUNI_ADDRESS = address(0xbD97BF168FA913607b996fab823F88610DCF7737); //mUNI deployed to GOERLI -- insert your own contract address here
address constant MUSDC_ADDRESS = address(0xa468864e673a807572598AB6208E49323484c6bF); //mUSDC deployed to GOERLI -- insert your own contract address here
address constant HOOK_ADDRESS = address(0x3CA2cD9f71104a6e1b67822454c725FcaeE35fF6); //address of the hook contract deployed to goerli -- you can use this hook address or deploy your own!

PoolInitializeTest initializeRouter = PoolInitializeTest(POOL_INITIALIZE_ROUTER);

function run() external {
// sort the tokens!
address token0 = uint160(MUSDC_ADDRESS) < uint160(MUNI_ADDRESS) ? MUSDC_ADDRESS : MUNI_ADDRESS;
Expand Down Expand Up @@ -48,6 +46,6 @@ contract CreatePoolScript is Script {
console.logBytes32(bytes32(idBytes));

vm.broadcast();
initializeRouter.initialize(pool, startingPrice, hookData);
IPoolManager(POOL_MANAGER).initialize(pool, startingPrice, hookData);
}
}
11 changes: 4 additions & 7 deletions script/Anvil.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {IHooks} from "v4-core/src/interfaces/IHooks.sol";
import {Hooks} from "v4-core/src/libraries/Hooks.sol";
import {PoolManager} from "v4-core/src/PoolManager.sol";
import {IPoolManager} from "v4-core/src/interfaces/IPoolManager.sol";
import {PoolInitializeTest} from "v4-core/src/test/PoolInitializeTest.sol";
import {PoolModifyLiquidityTest} from "v4-core/src/test/PoolModifyLiquidityTest.sol";
import {PoolSwapTest} from "v4-core/src/test/PoolSwapTest.sol";
import {PoolDonateTest} from "v4-core/src/test/PoolDonateTest.sol";
Expand Down Expand Up @@ -48,13 +47,13 @@ contract CounterScript is Script {

// Additional helpers for interacting with the pool
vm.startBroadcast();
(PoolInitializeTest initializeRouter, PoolModifyLiquidityTest lpRouter, PoolSwapTest swapRouter,) =
(PoolModifyLiquidityTest lpRouter, PoolSwapTest swapRouter,) =
deployRouters(manager);
vm.stopBroadcast();

// test the lifecycle (create pool, add liquidity, swap)
vm.startBroadcast();
testLifecycle(address(counter), initializeRouter, lpRouter, swapRouter);
testLifecycle(manager, address(counter), lpRouter, swapRouter);
vm.stopBroadcast();
}

Expand All @@ -68,13 +67,11 @@ contract CounterScript is Script {
function deployRouters(IPoolManager manager)
internal
returns (
PoolInitializeTest initializeRouter,
PoolModifyLiquidityTest lpRouter,
PoolSwapTest swapRouter,
PoolDonateTest donateRouter
)
{
initializeRouter = new PoolInitializeTest(manager);
lpRouter = new PoolModifyLiquidityTest(manager);
swapRouter = new PoolSwapTest(manager);
donateRouter = new PoolDonateTest(manager);
Expand All @@ -93,8 +90,8 @@ contract CounterScript is Script {
}

function testLifecycle(
IPoolManager manager,
address hook,
PoolInitializeTest initializeRouter,
PoolModifyLiquidityTest lpRouter,
PoolSwapTest swapRouter
) internal {
Expand All @@ -108,7 +105,7 @@ contract CounterScript is Script {
int24 tickSpacing = 60;
PoolKey memory poolKey =
PoolKey(Currency.wrap(address(token0)), Currency.wrap(address(token1)), 3000, tickSpacing, IHooks(hook));
initializeRouter.initialize(poolKey, Constants.SQRT_RATIO_1_1, ZERO_BYTES);
manager.initialize(poolKey, Constants.SQRT_RATIO_1_1, ZERO_BYTES);

// approve the tokens to the routers
token0.approve(address(lpRouter), type(uint256).max);
Expand Down
4 changes: 1 addition & 3 deletions src/Counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ contract Counter is BaseHook {
beforeSwap: true,
afterSwap: true,
beforeDonate: false,
afterDonate: false,
noOp: false,
accessLock: false
afterDonate: false
});
}

Expand Down
2 changes: 1 addition & 1 deletion test/Counter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract CounterTest is Test, Deployers {
// Create the pool
key = PoolKey(currency0, currency1, 3000, 60, IHooks(address(counter)));
poolId = key.toId();
initializeRouter.initialize(key, SQRT_RATIO_1_1, ZERO_BYTES);
manager.initialize(key, SQRT_RATIO_1_1, ZERO_BYTES);

// Provide liquidity to the pool
modifyLiquidityRouter.modifyLiquidity(key, IPoolManager.ModifyLiquidityParams(-60, 60, 10 ether), ZERO_BYTES);
Expand Down

0 comments on commit 9fe830e

Please sign in to comment.