Skip to content
Verified contractPartialMIT

V4UniWrapper

Address0xa83e510ce97f3275aad05e24258844761bcafc88
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
No
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,477,526
Creation transaction
0x483404dc70…679f1a14ca

V4UniWrapper.sol

// SPDX-License-Identifier: MIT
  pragma solidity ^0.8.24;

  interface ISafeModuleExecutorV4Uni {
      function execTransactionFromModule(
          address to,
          uint256 value,
          bytes calldata data,
          uint8 operation
      ) external returns (bool success);
  }

  contract V4UniWrapper {
      bytes4 public constant MODIFY_LIQUIDITIES_SELECTOR = 0xdd46508f;
      uint8 public constant ACTION_DECREASE_LIQUIDITY = 0x01;
      uint8 public constant ACTION_TAKE_PAIR = 0x11;
      uint8 private constant SAFE_OPERATION_CALL = 0;

      address public immutable safe;
      address public immutable positionManager;
      address public botSigner;
      bool public emergencyStop;
      uint256 public maxDeadlineSeconds;

      mapping(uint256 => bool) public allowedTokenIds;

      bool private locked;

      event BotSignerSet(address indexed signer);
      event EmergencyStopSet(bool enabled);
      event MaxDeadlineSecondsSet(uint256 seconds_);
      event TokenAllowed(uint256 indexed tokenId, bool allowed);
      event EmergencyDecreaseExecuted(uint256 indexed tokenId, address indexed signer);
      event FeesCollected(uint256 indexed tokenId, address indexed signer);

      error OnlySafe();
      error OnlyBotSigner();
      error EmergencyStopped();
      error Reentrancy();
      error InvalidSelector();
      error InvalidActions();
      error InvalidParams();
      error TokenNotAllowed(uint256 tokenId);
      error InvalidRecipient(address recipient);
      error InvalidLiquidity();
      error InvalidFeeCollectLiquidity();
      error InvalidFeeCollectMinimums();
      error HookDataNotAllowed();
      error DeadlineExpired(uint256 deadline);
      error DeadlineTooFar(uint256 deadline, uint256 maxDeadline);
      error SafeExecutionFailed();

      constructor(address safe_, address positionManager_, address botSigner_, uint256 maxDeadlineSeconds_) {
          require(safe_ != address(0), "safe required");
          require(positionManager_ != address(0), "position manager required");
          require(botSigner_ != address(0), "bot signer required");
          safe = safe_;
          positionManager = positionManager_;
          botSigner = botSigner_;
          maxDeadlineSeconds = maxDeadlineSeconds_;
          emit BotSignerSet(botSigner_);
          emit MaxDeadlineSecondsSet(maxDeadlineSeconds_);
      }

      modifier onlySafe() {
          if (msg.sender != safe) revert OnlySafe();
          _;
      }

      modifier onlyBotSigner() {
          if (msg.sender != botSigner) revert OnlyBotSigner();
          _;
      }

      modifier nonReentrant() {
          if (locked) revert Reentrancy();
          locked = true;
          _;
          locked = false;
      }

      function setBotSigner(address signer) external onlySafe {
          require(signer != address(0), "bot signer required");
          botSigner = signer;
          emit BotSignerSet(signer);
      }

      function setEmergencyStop(bool enabled) external onlySafe {
          emergencyStop = enabled;
          emit EmergencyStopSet(enabled);
      }

      function setMaxDeadlineSeconds(uint256 seconds_) external onlySafe {
          maxDeadlineSeconds = seconds_;
          emit MaxDeadlineSecondsSet(seconds_);
      }

      function setTokenAllowed(uint256 tokenId, bool allowed) external onlySafe {
          allowedTokenIds[tokenId] = allowed;
          emit TokenAllowed(tokenId, allowed);
      }

      function emergencyDecrease(bytes calldata modifyLiquiditiesData)
          external
          onlyBotSigner
          nonReentrant
          returns (bool)
      {
          if (emergencyStop) revert EmergencyStopped();
          ModifyLiquiditiesCall memory call_ = _validateModifyLiquidities(modifyLiquiditiesData);
          if (call_.liquidity == 0) revert InvalidLiquidity();
          _execPositionManager(modifyLiquiditiesData);
          emit EmergencyDecreaseExecuted(call_.tokenId, msg.sender);
          return true;
      }

      function collectFees(bytes calldata modifyLiquiditiesData)
          external
          onlyBotSigner
          nonReentrant
          returns (bool)
      {
          if (emergencyStop) revert EmergencyStopped();
          ModifyLiquiditiesCall memory call_ = _validateModifyLiquidities(modifyLiquiditiesData);
          if (call_.liquidity != 0) revert InvalidFeeCollectLiquidity();
          if (call_.amount0Min != 0 || call_.amount1Min != 0) revert InvalidFeeCollectMinimums();
          _execPositionManager(modifyLiquiditiesData);
          emit FeesCollected(call_.tokenId, msg.sender);
          return true;
      }

      struct ModifyLiquiditiesCall {
          uint256 tokenId;
          uint256 liquidity;
          uint128 amount0Min;
          uint128 amount1Min;
          uint256 deadline;
      }

      function _validateModifyLiquidities(bytes calldata data)
          internal
          view
          returns (ModifyLiquiditiesCall memory call_)
      {
          if (data.length < 4 || bytes4(data[:4]) != MODIFY_LIQUIDITIES_SELECTOR) {
              revert InvalidSelector();
          }

          (bytes memory unlockData, uint256 deadline) = abi.decode(data[4:], (bytes, uint256));
          _validateDeadline(deadline);
          (bytes memory actions, bytes[] memory params) = abi.decode(unlockData, (bytes, bytes[]));

          if (
              actions.length != 2
                  || uint8(actions[0]) != ACTION_DECREASE_LIQUIDITY
                  || uint8(actions[1]) != ACTION_TAKE_PAIR
          ) {
              revert InvalidActions();
          }
          if (params.length != 2) revert InvalidParams();

          bytes memory hookData;
          (call_.tokenId, call_.liquidity, call_.amount0Min, call_.amount1Min, hookData) =
              abi.decode(params[0], (uint256, uint256, uint128, uint128, bytes));
          if (!allowedTokenIds[call_.tokenId]) revert TokenNotAllowed(call_.tokenId);
          if (hookData.length != 0) revert HookDataNotAllowed();

          (,, address recipient) = abi.decode(params[1], (address, address, address));
          if (recipient != safe) revert InvalidRecipient(recipient);

          call_.deadline = deadline;
      }

      function _validateDeadline(uint256 deadline) internal view {
          if (deadline < block.timestamp) revert DeadlineExpired(deadline);
          if (maxDeadlineSeconds == 0) return;
          uint256 maxDeadline = block.timestamp + maxDeadlineSeconds;
          if (deadline > maxDeadline) revert DeadlineTooFar(deadline, maxDeadline);
      }

      function _execPositionManager(bytes calldata modifyLiquiditiesData) internal {
          bool success = ISafeModuleExecutorV4Uni(safe).execTransactionFromModule(
              positionManager,
              0,
              modifyLiquiditiesData,
              SAFE_OPERATION_CALL
          );
          if (!success) revert SafeExecutionFailed();
      }
  }
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.