Skip to content

Commit

Permalink
payable initializePool (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint authored Aug 31, 2024
1 parent d254c02 commit b11680c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/base/PoolInitializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
abstract contract PoolInitializer is ImmutableState {
function initializePool(PoolKey calldata key, uint160 sqrtPriceX96, bytes calldata hookData)
external
payable
returns (int24)
{
return poolManager.initialize(key, sqrtPriceX96, hookData);
Expand Down
39 changes: 39 additions & 0 deletions test/position-managers/PositionManager.multicall.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,45 @@ contract PositionManagerMulticallTest is Test, Permit2SignatureHelpers, PosmTest
assertGt(result.amount1(), 0);
}

function test_multicall_initializePool_mint_native() public {
key = PoolKey({
currency0: CurrencyLibrary.NATIVE,
currency1: currency1,
fee: 0,
tickSpacing: 10,
hooks: IHooks(address(0))
});

// Use multicall to initialize a pool and mint liquidity
bytes[] memory calls = new bytes[](2);
calls[0] = abi.encodeWithSelector(lpm.initializePool.selector, key, SQRT_PRICE_1_1, ZERO_BYTES);

config = PositionConfig({
poolKey: key,
tickLower: TickMath.minUsableTick(key.tickSpacing),
tickUpper: TickMath.maxUsableTick(key.tickSpacing)
});

Plan memory planner = Planner.init();
planner.add(
Actions.MINT_POSITION,
abi.encode(
config, 100e18, MAX_SLIPPAGE_INCREASE, MAX_SLIPPAGE_INCREASE, ActionConstants.MSG_SENDER, ZERO_BYTES
)
);
bytes memory actions = planner.finalizeModifyLiquidityWithClose(config.poolKey);

calls[1] = abi.encodeWithSelector(IPositionManager.modifyLiquidities.selector, actions, _deadline);

IMulticall_v4(address(lpm)).multicall{value: 1000 ether}(calls);

// test swap, doesn't revert, showing the pool was initialized
int256 amountSpecified = -1e18;
BalanceDelta result = swap(key, true, amountSpecified, ZERO_BYTES);
assertEq(result.amount0(), amountSpecified);
assertGt(result.amount1(), 0);
}

// charlie will attempt to decrease liquidity without approval
// posm's NotApproved(charlie) should bubble up through Multicall
function test_multicall_bubbleRevert() public {
Expand Down

0 comments on commit b11680c

Please sign in to comment.