Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SB-L73: payable initializePool #320

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading