Skip to content
Verified contractExactMIT

UniswapLock

Address0x4b7812d978a00bd9a8ba75f42eef72a613061097
Balance

0 ETH

 

Transactions

26

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 200 runs
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,356,122
Creation transaction
0x36e40f5a3c…21f4e5c91e

1123.sol

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

interface IERC20Lock {
    function balanceOf(address account) external view returns (uint256);
    function totalSupply() external view returns (uint256);
    function transfer(address to, uint256 amount) external returns (bool);
}

interface IBurnableLock is IERC20Lock {
    function burn(uint256 amount) external;
}

interface IWETHLock is IERC20Lock {
    function withdraw(uint256 amount) external;
}

interface IERC721ReceiverLock {
    function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data)
        external returns (bytes4);
}

interface INonfungiblePositionManagerLock {
    struct CollectParams {
        uint256 tokenId;
        address recipient;
        uint128 amount0Max;
        uint128 amount1Max;
    }

    function ownerOf(uint256 tokenId) external view returns (address);
    function safeTransferFrom(address from, address to, uint256 tokenId) external;
    function positions(uint256 tokenId) external view returns (
        uint96 nonce, address operator, address token0, address token1, uint24 fee,
        int24 tickLower, int24 tickUpper, uint128 liquidity,
        uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128,
        uint128 tokensOwed0, uint128 tokensOwed1
    );
    function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);
}

contract UniswapLock is IERC721ReceiverLock {
    address public constant POSITION_MANAGER = 0xC36442b4a4522E871399CD717aBDD847Ab11FE88;
    address public constant BURN_TOKEN = 0xE330Bd3141BE4893274D65Ab301278A200000000;
    address public constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
    uint24 public constant POOL_FEE = 10000;
    uint256 public constant POSITION_ID = 1398512;

    address public owner;
    address public pendingOwner;
    address public feeRecipient;
    mapping(address => bool) public recipientWhitelist;
    bool public nftWithdrawalsPermanentlyDisabled;
    uint256 private _entered = 1;

    error Unauthorized();
    error InvalidAddress();
    error WrongChain();
    error ReentrantCall();
    error OwnershipRenunciationDisabled();
    error NFTWithdrawalsDisabled();
    error UnsupportedPosition();
    error PositionNotHeld();
    error InvalidNFTSender();
    error InvalidAmount();
    error InsufficientETHAndWETH();
    error ETHTransferFailed();
    error BurnVerificationFailed();
    error WrongPositionId();
    error EmptyLiquidity();
    error RecipientNotWhitelisted();
    error ActiveRecipientCannotBeRemoved();

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
    event OwnershipTransferCancelled(address indexed cancelledOwner);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    event NFTReceived(address indexed from, uint256 indexed tokenId);
    event NFTWithdrawn(uint256 indexed tokenId, address indexed recipient);
    event NFTWithdrawalsPermanentlyDisabled(address indexed owner);
    event FeesCollected(uint256 indexed tokenId, uint256 wethAmount, uint256 tokenAmount);
    event TokensBurned(uint256 amount);
    event ETHWithdrawn(address indexed recipient, uint256 amount);

    event RecipientWhitelistUpdated(address indexed recipient, bool allowed);
    event FeeRecipientUpdated(address indexed previousRecipient, address indexed newRecipient);

    modifier onlyOwner() {
        if (msg.sender != owner) revert Unauthorized();
        _;
    }

    modifier nonReentrant() {
        if (_entered != 1) revert ReentrantCall();
        _entered = 2;
        _;
        _entered = 1;
    }

    constructor(address initialOwner, address initialFeeRecipient) {
        if (block.chainid != 1) revert WrongChain();
        _checkRecipient(initialOwner);
        _checkRecipient(initialFeeRecipient);
        owner = initialOwner;
        recipientWhitelist[initialFeeRecipient] = true;
        feeRecipient = initialFeeRecipient;
        emit OwnershipTransferred(address(0), initialOwner);
        emit RecipientWhitelistUpdated(initialFeeRecipient, true);
        emit FeeRecipientUpdated(address(0), initialFeeRecipient);
    }

    receive() external payable {}

    function setRecipientWhitelist(address recipient, bool allowed) external onlyOwner nonReentrant {
        _checkRecipient(recipient);
        if (!allowed && recipient == feeRecipient) revert ActiveRecipientCannotBeRemoved();
        recipientWhitelist[recipient] = allowed;
        emit RecipientWhitelistUpdated(recipient, allowed);
    }

    function setFeeRecipient(address newRecipient) external onlyOwner nonReentrant {
        _checkRecipient(newRecipient);
        if (!recipientWhitelist[newRecipient]) revert RecipientNotWhitelisted();
        address previous = feeRecipient;
        feeRecipient = newRecipient;
        emit FeeRecipientUpdated(previous, newRecipient);
    }

    function transferOwnership(address newOwner) external onlyOwner nonReentrant {
        _checkRecipient(newOwner);
        if (newOwner == owner) revert InvalidAddress();
        pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner, newOwner);
    }

    function cancelOwnershipTransfer() external onlyOwner nonReentrant {
        address cancelled = pendingOwner;
        pendingOwner = address(0);
        emit OwnershipTransferCancelled(cancelled);
    }

    function acceptOwnership() external nonReentrant {
        if (msg.sender != pendingOwner) revert Unauthorized();
        address previous = owner;
        owner = msg.sender;
        pendingOwner = address(0);
        emit OwnershipTransferred(previous, msg.sender);
    }

    function renounceOwnership() external view onlyOwner {
        revert OwnershipRenunciationDisabled();
    }

    function permanentlyDisableNFTWithdrawals() external onlyOwner nonReentrant {
        if (nftWithdrawalsPermanentlyDisabled) revert NFTWithdrawalsDisabled();
        _requirePositionHeld();
        if (_validatePosition() == 0) revert EmptyLiquidity();
        nftWithdrawalsPermanentlyDisabled = true;
        emit NFTWithdrawalsPermanentlyDisabled(owner);
    }

    function depositNFT() external onlyOwner nonReentrant {
        _validatePosition();
        INonfungiblePositionManagerLock(POSITION_MANAGER).safeTransferFrom(msg.sender, address(this), POSITION_ID);
    }

    function onERC721Received(address, address from, uint256 tokenId, bytes calldata)
        external override returns (bytes4)
    {
        if (msg.sender != POSITION_MANAGER) revert InvalidNFTSender();
        if (tokenId != POSITION_ID) revert WrongPositionId();
        _requirePositionHeld();
        _validatePosition();
        emit NFTReceived(from, tokenId);
        return IERC721ReceiverLock.onERC721Received.selector;
    }

    function withdrawNFT(address recipient) external onlyOwner nonReentrant {
        if (nftWithdrawalsPermanentlyDisabled) revert NFTWithdrawalsDisabled();
        _checkRecipient(recipient);
        INonfungiblePositionManagerLock(POSITION_MANAGER).safeTransferFrom(address(this), recipient, POSITION_ID);
        emit NFTWithdrawn(POSITION_ID, recipient);
    }

    function collectFees() external nonReentrant
        returns (uint256 wethAmount, uint256 tokenAmount, uint256 burnedAmount)
    {
        (wethAmount, tokenAmount) = _collect();
        burnedAmount = _burnAllTokens();
        _distributeWETH(wethAmount);
    }

    function burnHeldTokens() external nonReentrant returns (uint256 burnedAmount) {
        burnedAmount = _burnAllTokens();
    }

    function withdrawETH(uint256 amount) external onlyOwner nonReentrant {
        if (amount == 0) revert InvalidAmount();
        uint256 nativeBalance = address(this).balance;
        if (nativeBalance < amount) {
            uint256 deficit = amount - nativeBalance;
            if (IERC20Lock(WETH).balanceOf(address(this)) < deficit) revert InsufficientETHAndWETH();
            IWETHLock(WETH).withdraw(deficit);
        }
        _sendETH(payable(feeRecipient), amount);
    }

    function withdrawAllETH() external onlyOwner nonReentrant {
        uint256 wethBalance = IERC20Lock(WETH).balanceOf(address(this));
        if (wethBalance != 0) IWETHLock(WETH).withdraw(wethBalance);
        uint256 amount = address(this).balance;
        if (amount == 0) revert InvalidAmount();
        _sendETH(payable(feeRecipient), amount);
    }

    function _validatePosition() private view returns (uint128 liquidity) {
        (,, address token0, address token1, uint24 fee,,, uint128 positionLiquidity,,,,) =
            INonfungiblePositionManagerLock(POSITION_MANAGER).positions(POSITION_ID);
        if (token0 != WETH || token1 != BURN_TOKEN || fee != POOL_FEE) revert UnsupportedPosition();
        return positionLiquidity;
    }

    function _requirePositionHeld() private view {
        if (INonfungiblePositionManagerLock(POSITION_MANAGER).ownerOf(POSITION_ID) != address(this)) {
            revert PositionNotHeld();
        }
    }

    function _collect() private returns (uint256 wethAmount, uint256 tokenAmount) {
        INonfungiblePositionManagerLock manager = INonfungiblePositionManagerLock(POSITION_MANAGER);
        _requirePositionHeld();
        _validatePosition();
        (wethAmount, tokenAmount) = manager.collect(INonfungiblePositionManagerLock.CollectParams({
            tokenId: POSITION_ID,
            recipient: address(this),
            amount0Max: type(uint128).max,
            amount1Max: type(uint128).max
        }));
        emit FeesCollected(POSITION_ID, wethAmount, tokenAmount);
    }

    function _burnAllTokens() private returns (uint256 amount) {
        IBurnableLock token = IBurnableLock(BURN_TOKEN);
        amount = token.balanceOf(address(this));
        if (amount == 0) return 0;
        uint256 supplyBefore = token.totalSupply();
        if (supplyBefore < amount) revert BurnVerificationFailed();
        token.burn(amount);
        if (token.balanceOf(address(this)) != 0 || token.totalSupply() != supplyBefore - amount) {
            revert BurnVerificationFailed();
        }
        emit TokensBurned(amount);
    }

    function _sendETH(address payable recipient, uint256 amount) private {
        if (!recipientWhitelist[recipient]) revert RecipientNotWhitelisted();
        (bool ok,) = recipient.call{value: amount}("");
        if (!ok) revert ETHTransferFailed();
        emit ETHWithdrawn(recipient, amount);
    }

    function _checkRecipient(address recipient) private view {
        if (recipient == address(0) || recipient == address(this) || recipient == WETH
            || recipient == BURN_TOKEN || recipient == POSITION_MANAGER) revert InvalidAddress();
    }

    function _distributeWETH(uint256 amount) private {
        if (amount == 0) return;
        IWETHLock(WETH).withdraw(amount);
        _sendETH(payable(feeRecipient), amount);
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.