Skip to content

Commit

Permalink
[Part 2 of 3] Increase optimizer runs (s41) (#75)
Browse files Browse the repository at this point in the history
* feat: increase optimizer runs

* [Part 3 of 3] Code factoring (s43, s48, s50) (#76)

* s43: interface doc update

* s48: use directive with global

* s50: use internal keyword to make visibility obvious
  • Loading branch information
ChefMist authored Jan 27, 2025
1 parent 8d22bfe commit 69ce492
Show file tree
Hide file tree
Showing 69 changed files with 127 additions and 137 deletions.
10 changes: 9 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
src = 'src'
out = 'foundry-out'
solc_version = '0.8.26'
optimizer_runs = 9000
optimizer_runs = 1_000_000
via_ir = true
ffi = true
gas_limit = "3000000000"
Expand All @@ -15,6 +15,14 @@ fs_permissions = [
evm_version = 'cancun'
bytecode_hash = "none"

additional_compiler_profiles = [
{ name = "clPosm", optimizer_runs = 9000 }
]

compilation_restrictions = [
{ paths = "src/pool-cl/CLPositionManager.sol", optimizer_runs = 9000 }
]

[fuzz]
runs = 5 # change this for higher number of fuzz runs locally

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 @@
{
"mock10commands": "82833"
"mock10commands": "82785"
}
6 changes: 3 additions & 3 deletions snapshots/BinMigratorFromPancakeswapV2Test.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"testMigrateFromV2IncludingInit": "1180066",
"testMigrateFromV2WithoutInit": "1049481",
"testMigrateFromV2WithoutNativeToken": "1090203"
"testMigrateFromV2IncludingInit": "1176442",
"testMigrateFromV2WithoutInit": "1046490",
"testMigrateFromV2WithoutNativeToken": "1087310"
}
8 changes: 4 additions & 4 deletions snapshots/BinMigratorFromPancakeswapV3Test.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"BinMigratorBytecode size": "12601",
"testMigrateFromV3IncludingInit": "1252393",
"testMigrateFromV3WithoutInit": "1121789",
"testMigrateFromV3WithoutNativeToken": "1156506"
"BinMigratorBytecode size": "15187",
"testMigrateFromV3IncludingInit": "1248658",
"testMigrateFromV3WithoutInit": "1118687",
"testMigrateFromV3WithoutNativeToken": "1153511"
}
6 changes: 3 additions & 3 deletions snapshots/BinMigratorFromUniswapV2Test.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"testMigrateFromV2IncludingInit": "1180066",
"testMigrateFromV2WithoutInit": "1049481",
"testMigrateFromV2WithoutNativeToken": "1090203"
"testMigrateFromV2IncludingInit": "1176442",
"testMigrateFromV2WithoutInit": "1046490",
"testMigrateFromV2WithoutNativeToken": "1087310"
}
8 changes: 4 additions & 4 deletions snapshots/BinMigratorFromUniswapV3Test.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"BinMigratorBytecode size": "12601",
"testMigrateFromV3IncludingInit": "1250375",
"testMigrateFromV3WithoutInit": "1119771",
"testMigrateFromV3WithoutNativeToken": "1154488"
"BinMigratorBytecode size": "15187",
"testMigrateFromV3IncludingInit": "1246640",
"testMigrateFromV3WithoutInit": "1116669",
"testMigrateFromV3WithoutNativeToken": "1151493"
}
2 changes: 1 addition & 1 deletion snapshots/BinPositionManagerTest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"BinPositionManagerBytecode size": "15154"
"BinPositionManagerBytecode size": "17435"
}
10 changes: 5 additions & 5 deletions snapshots/BinPositionManager_ModifyLiquidityTest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"test_addLiquidity_OutsideActiveId": "294827",
"test_addLiquidity_SingleBin": "533778",
"test_addLiquidity_ThreeBins": "908043",
"test_decreaseLiquidity_threeBins": "186051",
"test_decreaseLiquidity_threeBins_half": "205238"
"test_addLiquidity_OutsideActiveId": "292694",
"test_addLiquidity_SingleBin": "532073",
"test_addLiquidity_ThreeBins": "905930",
"test_decreaseLiquidity_threeBins": "184859",
"test_decreaseLiquidity_threeBins_half": "203748"
}
6 changes: 3 additions & 3 deletions snapshots/BinPositionManager_NativeTokenTest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"test_addLiquidity": "849375",
"test_addLiquidity_excessEth": "851136",
"test_decreaseLiquidity": "192695"
"test_addLiquidity": "847340",
"test_addLiquidity_excessEth": "849077",
"test_decreaseLiquidity": "191515"
}
2 changes: 1 addition & 1 deletion snapshots/BinQuoterTest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"BinQuoterBytecode size": "6299"
"BinQuoterBytecode size": "6839"
}
14 changes: 7 additions & 7 deletions snapshots/BinSwapRouterTest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"testExactInputSingle_DifferentRecipient": "137214",
"testExactInputSingle_EthPool_SwapEthForToken": "125543",
"testExactInputSingle_EthPool_SwapTokenForEth": "111288",
"testExactInput_MultiHopDifferentRecipient": "168754",
"testExactOutputSingle_DifferentRecipient": "141480",
"testExactOutput_MultiHopDifferentRecipient": "172390",
"testExactOutput_SingleHop": "143161"
"testExactInputSingle_DifferentRecipient": "136133",
"testExactInputSingle_EthPool_SwapEthForToken": "124501",
"testExactInputSingle_EthPool_SwapTokenForEth": "110210",
"testExactInput_MultiHopDifferentRecipient": "166964",
"testExactOutputSingle_DifferentRecipient": "140509",
"testExactOutput_MultiHopDifferentRecipient": "170820",
"testExactOutput_SingleHop": "142184"
}
2 changes: 1 addition & 1 deletion snapshots/CLPositionDescriptorOffChainTest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"CLPositionDescriptorOffChain size": "2568"
"CLPositionDescriptorOffChain size": "2958"
}
2 changes: 1 addition & 1 deletion snapshots/CLQuoterTest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"CLQuoterBytecode size": "6458"
"CLQuoterBytecode size": "6998"
}
8 changes: 4 additions & 4 deletions snapshots/CLSwapRouterTest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"testExactInputSingle_gas": "169788",
"testExactInput_gas": "234192",
"testExactOutputSingle_gas": "169491",
"testExactOutput_gas": "233092"
"testExactInputSingle_gas": "168817",
"testExactInput_gas": "232455",
"testExactOutputSingle_gas": "168510",
"testExactOutput_gas": "231337"
}
2 changes: 2 additions & 0 deletions src/interfaces/IBaseMigrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {PoolKey} from "pancake-v4-core/src/types/PoolKey.sol";
import {IMulticall_v4} from "./IMulticall_v4.sol";
import {ISelfPermitERC721} from "./ISelfPermitERC721.sol";

/// @title IBaseMigrator
/// @notice Interface for the BaseMigrator contract
interface IBaseMigrator is IMulticall_v4, ISelfPermitERC721 {
error TOKEN_NOT_MATCH();
error INVALID_ETHER_SENDER();
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/IImmutableState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pragma solidity ^0.8.0;

import {IVault} from "pancake-v4-core/src/interfaces/IVault.sol";

/// @title Interface for ImmutableState
/// @title IImmutableState
/// @notice Interface for the ImmutableState contract
interface IImmutableState {
/// @notice The Pancakeswap v4 Vault contract
function vault() external view returns (IVault);
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/IPoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity ^0.8.24;

import {IVault} from "pancake-v4-core/src/interfaces/IVault.sol";

/// @title IPoolManager
/// @notice Interface for the PoolManager contract
interface IPoolManager {
/// @notice Returns the vault contract
/// @return IVault The address of the vault
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/IPositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity ^0.8.24;

import {IImmutableState} from "./IImmutableState.sol";

/// @title IPositionManager
/// @notice Interface for the PositionManager contract
interface IPositionManager is IImmutableState {
/// @notice Thrown when the block.timestamp exceeds the user-provided deadline
error DeadlinePassed(uint256 deadline);
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/IPositionManagerPermit2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pragma solidity ^0.8.0;

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

/// @title IPositionManagerPermit2
/// @notice Interface for the IPositionManagerPermit2 contract
interface IPositionManagerPermit2 {
function permit2() external view returns (IAllowanceTransfer);
}
2 changes: 1 addition & 1 deletion src/interfaces/IQuoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {PathKey} from "../libraries/PathKey.sol";
import {PoolKey} from "pancake-v4-core/src/types/PoolKey.sol";
import {PoolId} from "pancake-v4-core/src/types/PoolId.sol";

/// @title IQuoter Interface
/// @title IQuoter
/// @notice Supports quoting the delta amounts from exact input or exact output swaps.
/// @dev These functions are not marked view because they rely on calling non-view functions and reverting
/// to compute the result. They are also not gas efficient and should not be called on-chain.
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/ISelfPermit.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title Self Permit
/// @title ISelfPermit
/// @notice Functionality to call permit on any EIP-2612-compliant token for use in the route
interface ISelfPermit {
/// @notice Permits this contract to spend a given token from `msg.sender`
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/ISelfPermitERC721.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title Self Permit For ERC721
/// @title ISelfPermitERC721
/// @notice Functionality to call permit on any EIP-2612-compliant token
/// This is for PancakeSwapV3 styled Nonfungible Position Manager which supports permit extension
interface ISelfPermitERC721 {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/external/IERC20PermitAllowed.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @title Interface for permit
/// @title IERC20PermitAllowed
/// @notice Interface used by DAI/CHAI for permit
interface IERC20PermitAllowed {
/// @notice Approve the spender to spend some tokens via the holder signature
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/external/IPancakeFactory.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;

/// @title IPancakeFactory
/// @notice Interface for the PancakeFactory contract
interface IPancakeFactory {
function getPair(address tokenA, address tokenB) external view returns (address pair);
function createPair(address tokenA, address tokenB) external returns (address pair);
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/external/IPancakePair.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;

/// @notice Copying from PancakeSwap V2 Pair
/// @title IPancakePair
/// @notice Interface for the PancakeSwap V2 Pair
/// https://github.com/pancakeswap/pancake-swap-core-v2/blob/master/contracts/interfaces/IPancakePair.sol
interface IPancakePair {
event Approval(address indexed owner, address indexed spender, uint256 value);
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/external/IPancakeV3Factory.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @title IPancakeV3Factory
/// @notice Interface for the PancakeV3Factory contract
interface IPancakeV3Factory {
/// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
/// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/external/IPancakeV3Pool.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @title IPancakeV3Pool
/// @notice Interface for the PancakeV3Pool contract
interface IPancakeV3Pool {
/// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
/// when accessed externally.
Expand Down
5 changes: 3 additions & 2 deletions src/interfaces/external/IPancakeV3SwapCallback.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @title Callback for IPancakeV3PoolActions#swap
/// @notice Any contract that calls IPancakeV3PoolActions#swap must implement this interface
/// @title IPancakeV3SwapCallback
/// @notice Callback for IPancakeV3PoolActions#swap
/// @dev Any contract that calls IPancakeV3PoolActions#swap must implement this interface.
interface IPancakeV3SwapCallback {
/// @notice Called to `msg.sender` after executing a swap via IPancakeV3Pool#swap.
/// @dev In the implementation you must pay the pool tokens owed for the swap.
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/external/IStableSwap.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @title IStableSwap
/// @notice Interface for the StableSwap contract
interface IStableSwap {
// solium-disable-next-line mixedcase
function get_dy(uint256 i, uint256 j, uint256 dx) external view returns (uint256 dy);
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/external/IStableSwapFactory.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @title IStableSwapFactory
/// @notice Interface for the StableSwapFactory contract
interface IStableSwapFactory {
struct StableSwapPairInfo {
address swapContract;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/external/IV3NonfungiblePositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import {IERC721Permit} from "../../pool-cl/interfaces/IERC721Permit.sol";

/// @title Non-fungible token for positions
/// @title IV3NonfungiblePositionManager
/// @notice Wraps PancakeSwap V3 positions in a non-fungible token interface which allows for them to be transferred
/// and authorized. Copying from PancakeSwap-V3
/// https://github.com/pancakeswap/pancake-v3-contracts/blob/main/projects/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/external/IWETH9.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pragma solidity ^0.8.0;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/// @title Interface for WETH9
/// @title IWETH9
/// @notice Interface for WETH9
interface IWETH9 is IERC20 {
/// @notice Deposit ether to get wrapped ether
function deposit() external payable;
Expand Down
Loading

0 comments on commit 69ce492

Please sign in to comment.