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

add compilation restrictions #402

Merged
merged 22 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 21 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
16 changes: 14 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
[profile.default]
out = 'foundry-out'
solc_version = '0.8.26'
optimizer_runs = 1
optimizer_runs = 44444444
via_ir = true
ffi = true
fs_permissions = [{ access = "read-write", path = ".forge-snapshots/"}]
fs_permissions = [{ access = "read-write", path = ".forge-snapshots/" }, { access = "read", path = "foundry-out/" }]
evm_version = "cancun"
gas_limit = "3000000000"
fuzz_runs = 10_000
bytecode_hash = "none"

additional_compiler_profiles = [
{ name = "posm", via_ir = true, optimizer_runs = 30000 },
{ 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 = "test/**", via_ir = false }
]

[profile.debug]
via_ir = false
optimizer_runs = 200
Expand Down
17 changes: 5 additions & 12 deletions script/DeployPosm.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import "forge-std/console2.sol";
import "forge-std/Script.sol";

import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {StateView} from "../src/lens/StateView.sol";
import {PositionManager} from "../src/PositionManager.sol";
import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol";
import {IPositionDescriptor} from "../src/interfaces/IPositionDescriptor.sol";
import {PositionDescriptor} from "../src/PositionDescriptor.sol";
import {Deploy, IPositionDescriptor, IPositionManager} from "../test/shared/Deploy.sol";
import {IWETH9} from "../src/interfaces/external/IWETH9.sol";

contract DeployPosmTest is Script {
Expand All @@ -21,18 +18,14 @@ contract DeployPosmTest is Script {
uint256 unsubscribeGasLimit,
address wrappedNative,
string memory nativeCurrencyLabel
) public returns (PositionDescriptor positionDescriptor, PositionManager posm) {
) public returns (IPositionDescriptor positionDescriptor, IPositionManager posm) {
vm.startBroadcast();

positionDescriptor = new PositionDescriptor(IPoolManager(poolManager), wrappedNative, nativeCurrencyLabel);
positionDescriptor = Deploy.positionDescriptor(poolManager, wrappedNative, nativeCurrencyLabel, hex"00");
console2.log("PositionDescriptor", address(positionDescriptor));

posm = new PositionManager{salt: hex"03"}(
IPoolManager(poolManager),
IAllowanceTransfer(permit2),
unsubscribeGasLimit,
IPositionDescriptor(address(positionDescriptor)),
IWETH9(wrappedNative)
posm = Deploy.positionManager(
poolManager, permit2, unsubscribeGasLimit, address(positionDescriptor), wrappedNative, hex"03"
);
console2.log("PositionManager", address(posm));

Expand Down
7 changes: 3 additions & 4 deletions script/DeployStateView.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ pragma solidity ^0.8.20;
import "forge-std/console2.sol";
import "forge-std/Script.sol";

import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {StateView} from "../src/lens/StateView.sol";
import {Deploy, IStateView} from "../test/shared/Deploy.sol";

contract DeployStateView is Script {
function setUp() public {}

function run(address poolManager) public returns (StateView state) {
function run(address poolManager) public returns (IStateView state) {
vm.startBroadcast();

// forge script --broadcast --sig 'run(address)' --rpc-url <RPC_URL> --private-key <PRIV_KEY> --verify script/DeployStateView.s.sol:DeployStateView <POOL_MANAGER_ADDR>
state = new StateView(IPoolManager(poolManager));
state = Deploy.stateView(poolManager, hex"00");
console2.log("StateView", address(state));
console2.log("PoolManager", address(state.poolManager()));

Expand Down
7 changes: 3 additions & 4 deletions script/DeployV4Quoter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ pragma solidity ^0.8.20;
import "forge-std/console2.sol";
import "forge-std/Script.sol";

import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {V4Quoter} from "../src/lens/V4Quoter.sol";
import {Deploy, IV4Quoter} from "../test/shared/Deploy.sol";

contract DeployV4Quoter is Script {
function setUp() public {}

function run(address poolManager) public returns (V4Quoter state) {
function run(address poolManager) public returns (IV4Quoter state) {
vm.startBroadcast();

// forge script --broadcast --sig 'run(address)' --rpc-url <RPC_URL> --private-key <PRIV_KEY> --verify script/DeployV4Quoter.s.sol:DeployV4Quoter <POOL_MANAGER_ADDR>
state = new V4Quoter(IPoolManager(poolManager));
state = Deploy.v4Quoter(poolManager, hex"00");
console2.log("V4Quoter", address(state));
console2.log("PoolManager", address(state.poolManager()));

Expand Down
2 changes: 1 addition & 1 deletion snapshots/BaseActionsRouterTest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"BaseActionsRouter_mock10commands": "61332"
"BaseActionsRouter_mock10commands": "63076"
}
8 changes: 4 additions & 4 deletions snapshots/PaymentsTests.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Payments_swap_settleFromCaller_takeAllToMsgSender": "132997",
"Payments_swap_settleFromCaller_takeAllToSpecifiedAddress": "134973",
"Payments_swap_settleWithBalance_takeAllToMsgSender": "127102",
"Payments_swap_settleWithBalance_takeAllToSpecifiedAddress": "127212"
"Payments_swap_settleFromCaller_takeAllToMsgSender": "133006",
"Payments_swap_settleFromCaller_takeAllToSpecifiedAddress": "134475",
"Payments_swap_settleWithBalance_takeAllToMsgSender": "126957",
"Payments_swap_settleWithBalance_takeAllToSpecifiedAddress": "127095"
}
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": "51576",
"PositionManager_burn_empty_native": "51576",
"PositionManager_burn_nonEmpty_native_withClose": "128316",
"PositionManager_burn_nonEmpty_native_withTakePair": "127696",
"PositionManager_burn_nonEmpty_withClose": "135236",
"PositionManager_burn_nonEmpty_withTakePair": "134615",
"PositionManager_collect_native": "148571",
"PositionManager_collect_sameRange": "157220",
"PositionManager_collect_withClose": "157220",
"PositionManager_collect_withTakePair": "156456",
"PositionManager_decreaseLiquidity_native": "114165",
"PositionManager_decreaseLiquidity_withClose": "122555",
"PositionManager_decreaseLiquidity_withTakePair": "121791",
"PositionManager_decrease_burnEmpty": "138177",
"PositionManager_decrease_burnEmpty_native": "131258",
"PositionManager_decrease_sameRange_allLiquidity": "135218",
"PositionManager_decrease_take_take": "123169",
"PositionManager_increaseLiquidity_erc20_withClose": "162419",
"PositionManager_increaseLiquidity_erc20_withSettlePair": "161283",
"PositionManager_increaseLiquidity_native": "145296",
"PositionManager_increase_autocompoundExactUnclaimedFees": "138010",
"PositionManager_increase_autocompoundExcessFeesCredit": "180194",
"PositionManager_increase_autocompound_clearExcess": "150782",
"PositionManager_mint_native": "369623",
"PositionManager_mint_nativeWithSweep_withClose": "378280",
"PositionManager_mint_nativeWithSweep_withSettlePair": "377364",
"PositionManager_mint_onSameTickLower": "321205",
"PositionManager_mint_onSameTickUpper": "321875",
"PositionManager_mint_sameRange": "247444",
"PositionManager_mint_settleWithBalance_sweep": "423280",
"PositionManager_mint_warmedPool_differentRange": "327236",
"PositionManager_mint_withClose": "423986",
"PositionManager_mint_withSettlePair": "422936",
"PositionManager_multicall_initialize_mint": "460558",
"PositionManager_permit": "79259",
"PositionManager_permit_secondPosition": "62159",
"PositionManager_permit_twice": "45035",
"PositionManager_subscribe": "88475",
"PositionManager_unsubscribe": "63253",
"positionManager bytecode size": "19060"
"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"
}
2 changes: 1 addition & 1 deletion snapshots/PositionDescriptorTest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"positionDescriptor bytecode size": "24179"
"positionDescriptor bytecode size": "24110"
}
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": "146317",
"Quoter_exactInputSingle_zeroForOne_multiplePositions": "151973",
"Quoter_exactOutputSingle_oneForZero": "80048",
"Quoter_exactOutputSingle_zeroForOne": "84626",
"Quoter_quoteExactInput_oneHop_1TickLoaded": "122994",
"Quoter_quoteExactInput_oneHop_initializedAfter": "147949",
"Quoter_quoteExactInput_oneHop_startingInitialized": "81420",
"Quoter_quoteExactInput_twoHops": "205421",
"Quoter_quoteExactOutput_oneHop_1TickLoaded": "122296",
"Quoter_quoteExactOutput_oneHop_2TicksLoaded": "152648",
"Quoter_quoteExactOutput_oneHop_initializedAfter": "122364",
"Quoter_quoteExactOutput_oneHop_startingInitialized": "98875",
"Quoter_quoteExactOutput_twoHops": "204897"
"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"
}
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": "2367",
"StateView_extsload_getFeeGrowthInside": "8444",
"StateView_extsload_getLiquidity": "1480",
"StateView_extsload_getPositionInfo": "2973",
"StateView_extsload_getPositionLiquidity": "1750",
"StateView_extsload_getSlot0": "1548",
"StateView_extsload_getTickBitmap": "1476",
"StateView_extsload_getTickFeeGrowthOutside": "2672",
"StateView_extsload_getTickInfo": "2896",
"StateView_extsload_getTickLiquidity": "1748"
"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"
}
48 changes: 24 additions & 24 deletions snapshots/V4RouterTest.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"V4Router_Bytecode": "5137",
"V4Router_ExactIn1Hop_nativeIn": "121819",
"V4Router_ExactIn1Hop_nativeOut": "120826",
"V4Router_ExactIn1Hop_oneForZero": "129715",
"V4Router_ExactIn1Hop_zeroForOne": "135623",
"V4Router_ExactIn2Hops": "191979",
"V4Router_ExactIn2Hops_nativeIn": "178175",
"V4Router_ExactIn3Hops": "248385",
"V4Router_ExactIn3Hops_nativeIn": "234581",
"V4Router_ExactInputSingle": "134546",
"V4Router_ExactInputSingle_nativeIn": "120742",
"V4Router_ExactInputSingle_nativeOut": "119714",
"V4Router_ExactOut1Hop_nativeIn_sweepETH": "128078",
"V4Router_ExactOut1Hop_nativeOut": "121895",
"V4Router_ExactOut1Hop_oneForZero": "130784",
"V4Router_ExactOut1Hop_zeroForOne": "134905",
"V4Router_ExactOut2Hops": "190319",
"V4Router_ExactOut2Hops_nativeIn": "183492",
"V4Router_ExactOut3Hops": "245811",
"V4Router_ExactOut3Hops_nativeIn": "238984",
"V4Router_ExactOut3Hops_nativeOut": "224567",
"V4Router_ExactOutputSingle": "133809",
"V4Router_ExactOutputSingle_nativeIn_sweepETH": "126982",
"V4Router_ExactOutputSingle_nativeOut": "120876"
"V4Router_Bytecode": "8975",
"V4Router_ExactIn1Hop_nativeIn": "121653",
"V4Router_ExactIn1Hop_nativeOut": "120119",
"V4Router_ExactIn1Hop_oneForZero": "128991",
"V4Router_ExactIn1Hop_zeroForOne": "135517",
"V4Router_ExactIn2Hops": "192843",
"V4Router_ExactIn2Hops_nativeIn": "178979",
"V4Router_ExactIn3Hops": "250218",
"V4Router_ExactIn3Hops_nativeIn": "236354",
"V4Router_ExactInputSingle": "134001",
"V4Router_ExactInputSingle_nativeIn": "120137",
"V4Router_ExactInputSingle_nativeOut": "118581",
"V4Router_ExactOut1Hop_nativeIn_sweepETH": "127940",
"V4Router_ExactOut1Hop_nativeOut": "121329",
"V4Router_ExactOut1Hop_oneForZero": "130201",
"V4Router_ExactOut1Hop_zeroForOne": "134858",
"V4Router_ExactOut2Hops": "191291",
"V4Router_ExactOut2Hops_nativeIn": "184373",
"V4Router_ExactOut3Hops": "247788",
"V4Router_ExactOut3Hops_nativeIn": "240870",
"V4Router_ExactOut3Hops_nativeOut": "224943",
"V4Router_ExactOutputSingle": "133337",
"V4Router_ExactOutputSingle_nativeIn_sweepETH": "126419",
"V4Router_ExactOutputSingle_nativeOut": "119821"
}
12 changes: 2 additions & 10 deletions src/PositionDescriptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ contract PositionDescriptor is IPositionDescriptor {
using CurrencyLibrary for Currency;
using PositionInfoLibrary for PositionInfo;

error InvalidTokenId(uint256 tokenId);

// mainnet addresses
address private constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
address private constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
Expand Down Expand Up @@ -87,18 +85,12 @@ contract PositionDescriptor is IPositionDescriptor {
);
}

/// @notice Returns true if currency0 has higher priority than currency1
/// @param currency0 The first currency address
/// @param currency1 The second currency address
/// @return flipRatio True if currency0 has higher priority than currency1
/// @inheritdoc IPositionDescriptor
function flipRatio(address currency0, address currency1) public view returns (bool) {
return currencyRatioPriority(currency0) > currencyRatioPriority(currency1);
}

/// @notice Returns the priority of a currency.
/// For certain currencies on mainnet, the smaller the currency, the higher the priority
/// @param currency The currency address
/// @return priority The priority of the currency
/// @inheritdoc IPositionDescriptor
function currencyRatioPriority(address currency) public view returns (int256) {
// Currencies in order of priority on mainnet: USDC, USDT, DAI, (ETH, WETH), TBTC, WBTC
// wrapped native is different address on different chains. passed in constructor
Expand Down
1 change: 1 addition & 0 deletions src/base/BaseV4Quoter.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
Expand Down
18 changes: 5 additions & 13 deletions src/base/Permit2Forwarder.sol
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol";
import {IPermit2Forwarder, IAllowanceTransfer} from "../interfaces/IPermit2Forwarder.sol";

/// @notice PermitForwarder allows permitting this contract as a spender on permit2
/// @notice Permit2Forwarder allows permitting this contract as a spender on permit2
/// @dev This contract does not enforce the spender to be this contract, but that is the intended use case
contract Permit2Forwarder {
contract Permit2Forwarder is IPermit2Forwarder {
/// @notice the Permit2 contract to forward approvals
IAllowanceTransfer public immutable permit2;

constructor(IAllowanceTransfer _permit2) {
permit2 = _permit2;
}

/// @notice allows forwarding a single permit to permit2
/// @dev this function is payable to allow multicall with NATIVE based actions
/// @param owner the owner of the tokens
/// @param permitSingle the permit data
/// @param signature the signature of the permit; abi.encodePacked(r, s, v)
/// @inheritdoc IPermit2Forwarder
function permit(address owner, IAllowanceTransfer.PermitSingle calldata permitSingle, bytes calldata signature)
external
payable
Expand All @@ -30,11 +26,7 @@ contract Permit2Forwarder {
}
}

/// @notice allows forwarding batch permits to permit2
/// @dev this function is payable to allow multicall with NATIVE based actions
/// @param owner the owner of the tokens
/// @param _permitBatch a batch of approvals
/// @param signature the signature of the permit; abi.encodePacked(r, s, v)
/// @inheritdoc IPermit2Forwarder
function permitBatch(address owner, IAllowanceTransfer.PermitBatch calldata _permitBatch, bytes calldata signature)
external
payable
Expand Down
Loading
Loading