Skip to content
Verified contractExactMIT

WanelHotWallet

Address0x83271d4e26aafbe8457e6165e162ad9d569f42da
Balance

0 ETH

 

Transactions

9

 

Compiler

solc 0.8.28

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
No
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,431,884
Creation transaction
0xcc4cdef449…fa8f5a87de

261117_WanelHotWallet/WanelHotWallet.sol

// SPDX-License-Identifier: MIT
pragma solidity =0.8.28;

// src/WanelHotWallet.sol

interface IERC20 {
    function balanceOf(address account) external view returns (uint256);

    function transfer(address to, uint256 amount) external returns (bool);
}

/// @notice Owner-managed token payout wallet with observer confirmation checks.
contract WanelHotWallet {
    struct ReceiverPayment {
        address receiver;
        uint256 amount;
    }

    struct PayoutRequest {
        bytes32 payoutNonce;
        bytes32 intentHash;
        bytes32 sourceEventHash;
        address token;
        ReceiverPayment[] receivers;
        uint256 deadline;
    }

    address public owner;
    mapping(address => bool) public observerEnabledMap;
    mapping(address => uint256) public largeAmountThreshold;
    mapping(bytes32 => bool) public usedNonce;

    string public constant EIP712_NAME = "WanelHotWallet";
    string public constant EIP712_VERSION = "1";
    bytes32 public constant HASHED_NAME = keccak256("WanelHotWallet");
    bytes32 public constant HASHED_VERSION = keccak256("1");
    bytes32 public constant EIP712_DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
    bytes32 public constant RECEIVER_PAYMENT_TYPEHASH = keccak256("ReceiverPayment(address receiver,uint256 amount)");
    bytes32 public constant PAYOUT_TYPEHASH = keccak256("Payout(bytes32 payoutNonce,bytes32 intentHash,bytes32 sourceEventHash,address token,bytes32 receiversHash,uint256 deadline)");
    bytes32 public immutable DOMAIN_SEPARATOR;

    event PayoutExecuted(
        bytes32 indexed payoutNonce,
        bytes32 payoutDigest,
        bytes32 indexed intentHash,
        address indexed token,
        uint256 totalAmount,
        uint256 requiredConfirmations
    );
    event ObserverUpdated(address indexed observer, bool enabled);
    event LargeAmountThresholdUpdated(address indexed token, uint256 threshold);
    event TokenWithdrawn(address indexed token, address indexed owner, uint256 amount);
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    constructor(address initialOwner) {
        require(initialOwner != address(0), "zero owner");
        owner = initialOwner;
        DOMAIN_SEPARATOR = keccak256(abi.encode(EIP712_DOMAIN_TYPEHASH, HASHED_NAME, HASHED_VERSION,
            block.chainid, address(this)));
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "only owner");
        _;
    }

    function setObserver(address observer, bool enabled) external onlyOwner {
        require(observer != address(0), "zero observer");
        observerEnabledMap[observer] = enabled;
        emit ObserverUpdated(observer, enabled);
    }

    function setLargeAmountThreshold(address token, uint256 threshold) external onlyOwner {
        largeAmountThreshold[token] = threshold;
        emit LargeAmountThresholdUpdated(token, threshold);
    }

    /// @notice Transfers the wallet's entire balance of a token to the owner.
    function withdrawToken(address token) external onlyOwner {
        uint256 amount = IERC20(token).balanceOf(address(this));
        _safeTransfer(token, owner, amount);
        emit TokenWithdrawn(token, owner, amount);
    }

    function transferOwnership(address newOwner) external onlyOwner {
        require(newOwner != address(0), "zero owner");
        emit OwnershipTransferred(owner, newOwner);
        owner = newOwner;
    }

    /// @notice Executes a signed token payout to all requested receivers.
    function payout(PayoutRequest calldata request, bytes[] calldata signatures) external {
        require(block.timestamp <= request.deadline, "deadline expired");
        require(request.payoutNonce != bytes32(0), "zero payout nonce");
        require(request.receivers.length != 0, "empty receivers");
        require(!usedNonce[request.payoutNonce], "payout already used");

        bytes32 payoutDigest = calculatePayoutDigest(request);
        uint256 validObserverCount = _countValidObservers(payoutDigest, signatures);
        uint256 balanceBefore = IERC20(request.token).balanceOf(address(this));
        usedNonce[request.payoutNonce] = true;

        for (uint256 i; i < request.receivers.length; ++i) {
            ReceiverPayment calldata receiverPayment = request.receivers[i];
            _safeTransfer(request.token, receiverPayment.receiver, receiverPayment.amount);
        }

        uint256 balanceAfter = IERC20(request.token).balanceOf(address(this));
        uint256 actualSpent = balanceBefore - balanceAfter;
        uint256 requiredConfirmations = actualSpent >= largeAmountThreshold[request.token] ? 3 : 2;
        require(validObserverCount >= requiredConfirmations, "insufficient observer signatures");

        emit PayoutExecuted(request.payoutNonce, payoutDigest, request.intentHash, request.token, actualSpent, requiredConfirmations);
    }

    /// @dev Accepts ERC20 transfers that either return true or return no data, but rejects false and revert.
    function _safeTransfer(address token, address to, uint256 amount) private {
        (bool success, bytes memory returndata) =
            token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, amount));
        require(success, "transfer failed");
        if (returndata.length != 0) {
            require(abi.decode(returndata, (bool)), "transfer failed");
        }
    }

    function domainSeparator() public view returns (bytes32) {
        return DOMAIN_SEPARATOR;
    }

    function hashReceiver(ReceiverPayment calldata receiver) public pure returns (bytes32) {
        return keccak256(abi.encode(RECEIVER_PAYMENT_TYPEHASH, receiver.receiver, receiver.amount));
    }

    function hashReceivers(ReceiverPayment[] calldata receivers) public pure returns (bytes32) {
        bytes32[] memory hashes = new bytes32[](receivers.length);
        for (uint256 i; i < receivers.length; ++i) hashes[i] = hashReceiver(receivers[i]);
        return keccak256(abi.encodePacked(hashes));
    }

    function calculatePayoutStructHash(PayoutRequest calldata request) public pure returns (bytes32) {
        return keccak256(abi.encode(PAYOUT_TYPEHASH, request.payoutNonce, request.intentHash, request.sourceEventHash,
            request.token, hashReceivers(request.receivers), request.deadline));
    }

    function calculatePayoutDigest(PayoutRequest calldata request) public view returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator(), calculatePayoutStructHash(request)));
    }

    function _countValidObservers(bytes32 digest, bytes[] calldata signatures) private view returns (uint256 count) {
        address[] memory countedObservers = new address[](signatures.length);

        for (uint256 i; i < signatures.length; ++i) {
            address recoveredObserver = _recover(digest, signatures[i]);
            if (!observerEnabledMap[recoveredObserver]) {
                continue;
            }

            bool alreadyCounted;
            for (uint256 j; j < count; ++j) {
                if (countedObservers[j] == recoveredObserver) {
                    alreadyCounted = true;
                    break;
                }
            }

            if (!alreadyCounted) {
                countedObservers[count] = recoveredObserver;
                ++count;
            }
        }
    }

    function _recover(bytes32 digest, bytes calldata signature) private pure returns (address) {
        if (signature.length != 65) {
            return address(0);
        }

        bytes32 r;
        bytes32 s;
        uint8 v;
        assembly ("memory-safe") {
            r := calldataload(signature.offset)
            s := calldataload(add(signature.offset, 32))
            v := byte(0, calldataload(add(signature.offset, 64)))
        }

        if (v < 27) {
            v += 27;
        }
        if (v != 27 && v != 28) {
            return address(0);
        }

        return ecrecover(digest, v, r, s);
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.