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

feat: compile PositionManager without IR #416

Closed
wants to merge 5 commits into from
Closed
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
8 changes: 4 additions & 4 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
out = 'foundry-out'
solc_version = '0.8.26'
optimizer_runs = 44444444
via_ir = true
via_ir = false
ffi = true
fs_permissions = [{ access = "read-write", path = ".forge-snapshots/" }, { access = "read", path = "foundry-out/" }]
evm_version = "cancun"
Expand All @@ -11,14 +11,14 @@ fuzz_runs = 10_000
bytecode_hash = "none"

additional_compiler_profiles = [
{ name = "posm", via_ir = true, optimizer_runs = 30000 },
{ name = "posm", via_ir = false, optimizer_runs = 2000},
{ name = "descriptor", via_ir = true, optimizer_runs = 1 },
{ name = "test", via_ir = false }
]

compilation_restrictions = [
{ paths = "src/PositionManager.sol", optimizer_runs = 30000 },
{ paths = "src/PositionDescriptor.sol", optimizer_runs = 1 },
{ paths = "src/PositionManager.sol", via_ir = false, optimizer_runs = 2000},
{ paths = "src/PositionDescriptor.sol", via_ir = true, optimizer_runs = 1 },
{ paths = "test/**", via_ir = false }
]

Expand Down
80 changes: 40 additions & 40 deletions snapshots/PosMGasTest.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
{
"PositionManager_burn_empty": "51102",
"PositionManager_burn_empty_native": "51102",
"PositionManager_burn_nonEmpty_native_withClose": "127695",
"PositionManager_burn_nonEmpty_native_withTakePair": "127137",
"PositionManager_burn_nonEmpty_withClose": "134600",
"PositionManager_burn_nonEmpty_withTakePair": "134043",
"PositionManager_collect_native": "147732",
"PositionManager_collect_sameRange": "156364",
"PositionManager_collect_withClose": "156364",
"PositionManager_collect_withTakePair": "155679",
"PositionManager_decreaseLiquidity_native": "113681",
"PositionManager_decreaseLiquidity_withClose": "121933",
"PositionManager_decreaseLiquidity_withTakePair": "121248",
"PositionManager_decrease_burnEmpty": "137500",
"PositionManager_decrease_burnEmpty_native": "130595",
"PositionManager_decrease_sameRange_allLiquidity": "134649",
"PositionManager_decrease_take_take": "122490",
"PositionManager_increaseLiquidity_erc20_withClose": "160652",
"PositionManager_increaseLiquidity_erc20_withSettlePair": "159563",
"PositionManager_increaseLiquidity_native": "143532",
"PositionManager_increase_autocompoundExactUnclaimedFees": "138231",
"PositionManager_increase_autocompoundExcessFeesCredit": "179593",
"PositionManager_increase_autocompound_clearExcess": "149511",
"PositionManager_mint_native": "367550",
"PositionManager_mint_nativeWithSweep_withClose": "376153",
"PositionManager_mint_nativeWithSweep_withSettlePair": "375348",
"PositionManager_mint_onSameTickLower": "319298",
"PositionManager_mint_onSameTickUpper": "319940",
"PositionManager_mint_sameRange": "245522",
"PositionManager_mint_settleWithBalance_sweep": "420760",
"PositionManager_mint_warmedPool_differentRange": "325316",
"PositionManager_mint_withClose": "421910",
"PositionManager_mint_withSettlePair": "420939",
"PositionManager_multicall_initialize_mint": "458237",
"PositionManager_permit": "79175",
"PositionManager_permit_secondPosition": "62063",
"PositionManager_permit_twice": "44975",
"PositionManager_subscribe": "87968",
"PositionManager_unsubscribe": "62697",
"positionManager bytecode size": "23877"
"PositionManager_burn_empty": "50490",
"PositionManager_burn_empty_native": "50490",
"PositionManager_burn_nonEmpty_native_withClose": "127186",
"PositionManager_burn_nonEmpty_native_withTakePair": "126605",
"PositionManager_burn_nonEmpty_withClose": "134092",
"PositionManager_burn_nonEmpty_withTakePair": "133511",
"PositionManager_collect_native": "147259",
"PositionManager_collect_sameRange": "155891",
"PositionManager_collect_withClose": "155891",
"PositionManager_collect_withTakePair": "155177",
"PositionManager_decreaseLiquidity_native": "113303",
"PositionManager_decreaseLiquidity_withClose": "121460",
"PositionManager_decreaseLiquidity_withTakePair": "120746",
"PositionManager_decrease_burnEmpty": "137111",
"PositionManager_decrease_burnEmpty_native": "130205",
"PositionManager_decrease_sameRange_allLiquidity": "134176",
"PositionManager_decrease_take_take": "122135",
"PositionManager_increaseLiquidity_erc20_withClose": "159828",
"PositionManager_increaseLiquidity_erc20_withSettlePair": "158686",
"PositionManager_increaseLiquidity_native": "142853",
"PositionManager_increase_autocompoundExactUnclaimedFees": "137717",
"PositionManager_increase_autocompoundExcessFeesCredit": "179147",
"PositionManager_increase_autocompound_clearExcess": "149061",
"PositionManager_mint_native": "367155",
"PositionManager_mint_nativeWithSweep_withClose": "375927",
"PositionManager_mint_nativeWithSweep_withSettlePair": "375085",
"PositionManager_mint_onSameTickLower": "318686",
"PositionManager_mint_onSameTickUpper": "319328",
"PositionManager_mint_sameRange": "244910",
"PositionManager_mint_settleWithBalance_sweep": "420852",
"PositionManager_mint_warmedPool_differentRange": "324704",
"PositionManager_mint_withClose": "421370",
"PositionManager_mint_withSettlePair": "420354",
"PositionManager_multicall_initialize_mint": "456443",
"PositionManager_permit": "79572",
"PositionManager_permit_secondPosition": "62472",
"PositionManager_permit_twice": "45372",
"PositionManager_subscribe": "87949",
"PositionManager_unsubscribe": "62082",
"positionManager bytecode size": "23643"
}
26 changes: 13 additions & 13 deletions snapshots/QuoterTest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"Quoter_exactInputSingle_oneForZero_multiplePositions": "145902",
"Quoter_exactInputSingle_zeroForOne_multiplePositions": "152117",
"Quoter_exactOutputSingle_oneForZero": "79267",
"Quoter_exactOutputSingle_zeroForOne": "84512",
"Quoter_quoteExactInput_oneHop_1TickLoaded": "122728",
"Quoter_quoteExactInput_oneHop_initializedAfter": "147363",
"Quoter_quoteExactInput_oneHop_startingInitialized": "80638",
"Quoter_quoteExactInput_twoHops": "204942",
"Quoter_quoteExactOutput_oneHop_1TickLoaded": "122224",
"Quoter_quoteExactOutput_oneHop_2TicksLoaded": "152879",
"Quoter_quoteExactOutput_oneHop_initializedAfter": "122251",
"Quoter_quoteExactOutput_oneHop_startingInitialized": "98545",
"Quoter_quoteExactOutput_twoHops": "204670"
"Quoter_exactInputSingle_oneForZero_multiplePositions": "146722",
"Quoter_exactInputSingle_zeroForOne_multiplePositions": "152948",
"Quoter_exactOutputSingle_oneForZero": "80318",
"Quoter_exactOutputSingle_zeroForOne": "85565",
"Quoter_quoteExactInput_oneHop_1TickLoaded": "123940",
"Quoter_quoteExactInput_oneHop_initializedAfter": "148554",
"Quoter_quoteExactInput_oneHop_startingInitialized": "81829",
"Quoter_quoteExactInput_twoHops": "206923",
"Quoter_quoteExactOutput_oneHop_1TickLoaded": "123618",
"Quoter_quoteExactOutput_oneHop_2TicksLoaded": "154273",
"Quoter_quoteExactOutput_oneHop_initializedAfter": "123645",
"Quoter_quoteExactOutput_oneHop_startingInitialized": "99939",
"Quoter_quoteExactOutput_twoHops": "206951"
}
20 changes: 10 additions & 10 deletions snapshots/StateViewTest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"StateView_extsload_getFeeGrowthGlobals": "2203",
"StateView_extsload_getFeeGrowthInside": "7875",
"StateView_extsload_getLiquidity": "1439",
"StateView_extsload_getPositionInfo": "2761",
"StateView_extsload_getPositionLiquidity": "1691",
"StateView_extsload_getSlot0": "1486",
"StateView_extsload_getTickBitmap": "1432",
"StateView_extsload_getTickFeeGrowthOutside": "2490",
"StateView_extsload_getTickInfo": "2693",
"StateView_extsload_getTickLiquidity": "1686"
"StateView_extsload_getFeeGrowthGlobals": "2376",
"StateView_extsload_getFeeGrowthInside": "8455",
"StateView_extsload_getLiquidity": "1487",
"StateView_extsload_getPositionInfo": "2905",
"StateView_extsload_getPositionLiquidity": "1724",
"StateView_extsload_getSlot0": "1584",
"StateView_extsload_getTickBitmap": "1682",
"StateView_extsload_getTickFeeGrowthOutside": "2734",
"StateView_extsload_getTickInfo": "3068",
"StateView_extsload_getTickLiquidity": "1879"
}
40 changes: 20 additions & 20 deletions src/PositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,19 @@ contract PositionManager is
{
(PoolKey memory poolKey, PositionInfo info) = getPoolAndPositionInfo(tokenId);

(uint160 sqrtPriceX96,,,) = poolManager.getSlot0(poolKey.toId());

// Use the credit on the pool manager as the amounts for the mint.
uint256 liquidity = LiquidityAmounts.getLiquidityForAmounts(
sqrtPriceX96,
TickMath.getSqrtPriceAtTick(info.tickLower()),
TickMath.getSqrtPriceAtTick(info.tickUpper()),
_getFullCredit(poolKey.currency0),
_getFullCredit(poolKey.currency1)
);
uint256 liquidity;
{
(uint160 sqrtPriceX96,,,) = poolManager.getSlot0(poolKey.toId());

// Use the credit on the pool manager as the amounts for the mint.
liquidity = LiquidityAmounts.getLiquidityForAmounts(
sqrtPriceX96,
TickMath.getSqrtPriceAtTick(info.tickLower()),
TickMath.getSqrtPriceAtTick(info.tickUpper()),
_getFullCredit(poolKey.currency0),
_getFullCredit(poolKey.currency1)
);
}

// Note: The tokenId is used as the salt for this position, so every minted position has unique storage in the pool manager.
(BalanceDelta liquidityDelta, BalanceDelta feesAccrued) =
Expand Down Expand Up @@ -423,16 +426,13 @@ contract PositionManager is
if (liquidity > 0) {
BalanceDelta liquidityDelta;
// do not use _modifyLiquidity as we do not need to notify on modification for burns.
(liquidityDelta, feesAccrued) = poolManager.modifyLiquidity(
poolKey,
IPoolManager.ModifyLiquidityParams({
tickLower: info.tickLower(),
tickUpper: info.tickUpper(),
liquidityDelta: -(liquidity.toInt256()),
salt: bytes32(tokenId)
}),
hookData
);
IPoolManager.ModifyLiquidityParams memory params = IPoolManager.ModifyLiquidityParams({
tickLower: info.tickLower(),
tickUpper: info.tickUpper(),
liquidityDelta: -(liquidity.toInt256()),
salt: bytes32(tokenId)
});
(liquidityDelta, feesAccrued) = poolManager.modifyLiquidity(poolKey, params, hookData);
// Slippage checks should be done on the principal liquidityDelta which is the liquidityDelta - feesAccrued
(liquidityDelta - feesAccrued).validateMinOut(amount0Min, amount1Min);
}
Expand Down
Loading