Skip to content
Verified contractPartialGPL-2.0-or-later

SwapExecutor

Address0x88291350efba59c6482b1f53d224ed8eee59a604
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.26

 

Same code

3 more contracts

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 2,000 runs
EVM version
cancun
Via IR
yes
License
GPL-2.0-or-later
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,995,503
Creation transaction
0x3d971dcf7c…f2c1884997

92 files

The source code is large: one file is shown at a time. Choose a file in the list.

src/SwapExecutor.sol

// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (C) 2024 PancakeSwap
pragma solidity ^0.8.26;

import {ISwapExecutor} from "./interfaces/ISwapExecutor.sol";
import {ImmutableState} from "./base/ImmutableState.sol";
import {UniV2StyledAdapter} from "./adapters/UniV2StyledAdapter.sol";
import {UniV3StyledAdapter} from "./adapters/UniV3StyledAdapter.sol";
import {InfinitySwapPoolAdapter} from "./adapters/InfinitySwapPoolAdapter.sol";
import {UniV4Adapter} from "./adapters/UniV4Adapter.sol";

/// @title SwapExecutor
/// @notice Hosts the adapters that used to be inlined into the Aggregator (UniV2/PCSV2 styled,
///         UniV3 styled, Infinity CL/Bin, UniV4) plus their swap callbacks. The Aggregator reaches
///         this contract exclusively via delegatecall, so all code here runs in the Aggregator
///         proxy's context: token approvals granted to the proxy, the proxy's ETH balance and the
///         proxy's transient storage all behave exactly as they did when the code was inlined.
/// @dev Split out of the Aggregator because the UUPS machinery pushed the combined bytecode over
///      the EIP-170 limit. This contract deliberately declares NO storage variables — everything it
///      needs is immutable (baked into its own code, which delegatecall reads) or transient — so it
///      can never corrupt the proxy's storage layout.
///
///      The swap entrypoints are guarded by `onlyDelegated`: called directly on this contract they
///      would run against the executor's own (empty) balances and approvals, which is useless but
///      also confusing, so they revert instead. The inherited callbacks need no such guard — each
///      one is already gated by its own origin check (transient pool slot / Vault / PoolManager).
contract SwapExecutor is ISwapExecutor, UniV2StyledAdapter, UniV3StyledAdapter, InfinitySwapPoolAdapter, UniV4Adapter {
    /// @dev The executor's own address, read through delegatecall to detect a direct call.
    address private immutable SELF;

    /// @notice Thrown when a swap entrypoint is called directly instead of via delegatecall
    error NotDelegated();

    modifier onlyDelegated() {
        if (address(this) == SELF) revert NotDelegated();
        _;
    }

    constructor(
        address _uniV3Factory,
        bytes32 _uniV3PoolInitCodeHash,
        address _pcsV3Deployer,
        bytes32 _pcsV3PoolInitCodeHash,
        address _infinityVault,
        address _infinityCLPoolManager,
        address _infinityBinPoolManager,
        address _uniV4PoolManager,
        address _slipstreamPoolFactory,
        bytes32 _slipstreamPoolInitCodeHash
    )
        ImmutableState(
            _uniV3Factory,
            _uniV3PoolInitCodeHash,
            _pcsV3Deployer,
            _pcsV3PoolInitCodeHash,
            _infinityVault,
            _infinityCLPoolManager,
            _infinityBinPoolManager,
            _uniV4PoolManager,
            _slipstreamPoolFactory,
            _slipstreamPoolInitCodeHash
        )
    {
        SELF = address(this);
    }

    /// @inheritdoc ISwapExecutor
    function uniV2Swap(address to, address pool, bool reverse, bool isPcsV2) external payable onlyDelegated {
        uint256 feeRatio = isPcsV2 ? PCSV2_EXCLUDING_FEE_RATIO : UNIV2_EXCLUDING_FEE_RATIO;
        if (reverse) {
            uniV2StyledSwapExactOneForZero(to, pool, feeRatio);
        } else {
            uniV2StyledSwapExactZeroForOne(to, pool, feeRatio);
        }
    }

    /// @inheritdoc ISwapExecutor
    function uniV3Swap(uint256 amountIn, address payer, address to, address refundTo, address pool, bytes calldata data)
        external
        payable
        onlyDelegated
    {
        uniV3StyledExactInSwap(amountIn, payer, to, refundTo, pool, data);
    }

    /// @inheritdoc ISwapExecutor
    function infinitySwap(
        uint256 amountIn,
        address payer,
        address to,
        address refundTo,
        address poolManager,
        bytes calldata data
    ) external payable onlyDelegated {
        infinityExactInSwap(amountIn, payer, to, refundTo, poolManager, data);
    }

    /// @inheritdoc ISwapExecutor
    function uniV4Swap(uint256 amountIn, address payer, address to, address refundTo, bytes calldata data)
        external
        payable
        onlyDelegated
    {
        uniV4ExactInSwap(amountIn, payer, to, refundTo, data);
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 2000,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "infinity-core/=lib/infinity-periphery/lib/infinity-core/",
    "uniswap-v4-core/=lib/v4-core/",
    "ds-test/=lib/infinity-periphery/lib/infinity-core/lib/forge-std/lib/ds-test/src/",
    "openzeppelin-contracts/=lib/infinity-periphery/lib/infinity-core/lib/openzeppelin-contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "solmate/=lib/infinity-periphery/lib/infinity-core/lib/solmate/",
    "lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/openzeppelin-contracts/:erc4626-tests/=lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/openzeppelin-contracts/:erc4626-tests/=lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/openzeppelin-contracts/:forge-std/=lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/openzeppelin-contracts/lib/forge-std/src/",
    "lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/openzeppelin-contracts/:forge-std/=lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/openzeppelin-contracts/lib/forge-std/src/",
    "lib/infinity-periphery/lib/infinity-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/infinity-periphery/lib/infinity-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/infinity-periphery/lib/infinity-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/infinity-periphery/lib/infinity-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/infinity-periphery/lib/infinity-core/lib/openzeppelin-contracts/:forge-std/=lib/infinity-periphery/lib/infinity-core/lib/openzeppelin-contracts/lib/forge-std/src/",
    "lib/infinity-periphery/lib/infinity-core/lib/openzeppelin-contracts/:forge-std/=lib/infinity-periphery/lib/infinity-core/lib/openzeppelin-contracts/lib/forge-std/src/",
    "lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/:forge-std/=lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/forge-std/",
    "lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/:forge-std/=lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/forge-std/",
    "lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/:forge-gas-snapshot/=lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/forge-gas-snapshot/src/",
    "lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/:forge-gas-snapshot/=lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/lib/forge-gas-snapshot/src/",
    "lib/infinity-periphery/lib/pancake-create3-factory/lib/openzeppelin-contracts/:erc4626-tests/=lib/infinity-periphery/lib/pancake-create3-factory/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/infinity-periphery/lib/pancake-create3-factory/lib/openzeppelin-contracts/:erc4626-tests/=lib/infinity-periphery/lib/pancake-create3-factory/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/infinity-periphery/lib/pancake-create3-factory/lib/openzeppelin-contracts/:forge-std/=lib/infinity-periphery/lib/pancake-create3-factory/lib/openzeppelin-contracts/lib/forge-std/src/",
    "lib/infinity-periphery/lib/pancake-create3-factory/lib/openzeppelin-contracts/:forge-std/=lib/infinity-periphery/lib/pancake-create3-factory/lib/openzeppelin-contracts/lib/forge-std/src/",
    "lib/infinity-periphery/lib/infinity-core/:forge-std/=lib/infinity-periphery/lib/infinity-core/lib/forge-std/src/",
    "lib/infinity-periphery/lib/infinity-core/:forge-std/=lib/infinity-periphery/lib/infinity-core/lib/forge-std/src/",
    "lib/infinity-periphery/lib/infinity-core/:pancake-create3-factory/=lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/",
    "lib/infinity-periphery/lib/infinity-core/:pancake-create3-factory/=lib/infinity-periphery/lib/infinity-core/lib/pancake-create3-factory/",
    "lib/infinity-periphery/lib/pancake-create3-factory/:forge-std/=lib/infinity-periphery/lib/pancake-create3-factory/lib/forge-std/",
    "lib/infinity-periphery/lib/pancake-create3-factory/:forge-std/=lib/infinity-periphery/lib/pancake-create3-factory/lib/forge-std/",
    "lib/infinity-periphery/lib/pancake-create3-factory/:forge-gas-snapshot/=lib/infinity-periphery/lib/pancake-create3-factory/lib/forge-gas-snapshot/src/",
    "lib/infinity-periphery/lib/pancake-create3-factory/:forge-gas-snapshot/=lib/infinity-periphery/lib/pancake-create3-factory/lib/forge-gas-snapshot/src/",
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:forge-std/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/forge-std/src/",
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:forge-std/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/forge-std/src/",
    "lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/v4-core/lib/openzeppelin-contracts/:forge-std/=lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/src/",
    "lib/v4-core/lib/openzeppelin-contracts/:forge-std/=lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/src/",
    "lib/infinity-periphery/:permit2/=lib/infinity-periphery/lib/permit2/",
    "lib/infinity-periphery/:permit2/=lib/infinity-periphery/lib/permit2/",
    "lib/infinity-periphery/:pancake-create3-factory/=lib/infinity-periphery/lib/pancake-create3-factory/",
    "lib/infinity-periphery/:pancake-create3-factory/=lib/infinity-periphery/lib/pancake-create3-factory/",
    "lib/openzeppelin-contracts-upgradeable/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "lib/openzeppelin-contracts-upgradeable/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "lib/openzeppelin-contracts-upgradeable/:forge-std/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/src/",
    "lib/openzeppelin-contracts-upgradeable/:forge-std/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/src/",
    "lib/v4-core/:forge-std/=lib/v4-core/lib/forge-std/src/",
    "lib/v4-core/:forge-std/=lib/v4-core/lib/forge-std/src/",
    "@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
    "@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/infinity-periphery/lib/infinity-core/lib/forge-gas-snapshot/src/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/infinity-periphery/lib/infinity-core/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "hardhat/=lib/v4-core/node_modules/hardhat/",
    "infinity-periphery/=lib/infinity-periphery/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "pancake-create3-factory/=lib/infinity-periphery/lib/pancake-create3-factory/",
    "permit2/=lib/infinity-periphery/lib/permit2/",
    "v4-core/=lib/v4-core/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.