ETH Price: $1,972.85 (+1.62%)
Gas: 0.06 Gwei
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Transfer Ownersh...242831942026-01-21 12:34:2326 days ago1768998863IN
0x7F3255Cd...92E2aD9AE
0 ETH0.000006420.22343976

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0x4e6cc601...0ec4A905C
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
SmartAccount

Compiler Version
v0.8.30+commit.73712a01

Optimization Enabled:
Yes with 200 runs

Other Settings:
prague EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

// SPDX-License-Identifier: MIT

pragma solidity 0.8.30;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";

import {
    RedundantOperationNotAllowed,
    InsufficientCurrencyBalance,
    OnlySciCanPerformOperation,
    OnlyProtocolCanPerformOperation,
    InsufficientNativeBalance,
    LowLevelCallFailed
} from "./common/Errors.sol";
import {
    WithdrawnNativeCurrency,
    WithdrawnExactCurrency,
    WithdrawnForDeal,
    WithdrawnNativeCurrencyForDeal,
    CommissionRefundedForDeal
} from "./common/Events.sol";
import {
    WithdrawExactCurrencyOptions,
    InitialSmartAccountOptions,
    WithdrawCurrencyForDealOptions,
    RefundCommissionForDealOptions,
    DelegatedPermission,
    PriceFeedMetadata
} from "./common/Structures.sol";

import {IUniBasedV2Pool} from "./interfaces/external/IUniBasedV2Pool.sol";
import {IPlatformManagement} from "./interfaces/IPlatformManagement.sol";
import {IPermissionsHandler} from "./interfaces/IPermissionsHandler.sol";
import {ISmartAccount} from "./interfaces/ISmartAccount.sol";

/**
 * @author lotos
 * @title The implementation of the ISmartAccount interface
 * @notice This contract allows manage users their smart accounts in the system
 * @custom:security-contact [email protected]
 */
contract SmartAccount is ISmartAccount, ReentrancyGuard, Ownable, Pausable {
    using SafeERC20 for IERC20;

    IPlatformManagement public platformManagement;
    IPermissionsHandler public permissionsHandler;

    modifier onlyInitiator() {
        if (!platformManagement.isSpecialCompanyInitiator(tx.origin)) {
            revert OnlySciCanPerformOperation();
        }

        _;
    }

    modifier onlyProtocol() {
        if (!platformManagement.isCompanyProtocol(msg.sender)) {
            revert OnlyProtocolCanPerformOperation();
        }

        _;
    }

    /**
     * @notice Once call when the contract is creating
     * @dev Helps to initialize system things once
     */
    constructor(InitialSmartAccountOptions memory options) Ownable(msg.sender) {
        platformManagement = IPlatformManagement(options.platformManagement);
        permissionsHandler = IPermissionsHandler(options.permissionsHandler);

        grantPermission(options.permission);
        _transferOwnership(options.initialOwner);
    }

    /**
     * @notice Allows the contract to receive native currency directly
     * @dev This function is automatically called when native currency is sent to the contract without any data
     * or when no other function matches the call signature. Required for the contract to accept plain
     * native currency transfers.
     */
    receive() external payable {}

    /**
     * @notice Pause the contract
     * @dev Helps temporary to stop all the contract functions
     */
    function pause() public onlyOwner whenNotPaused {
        _pause();
    }

    /**
     * @notice Unpause the contract
     * @dev Helps recover the contract from paused state
     */
    function unpause() public onlyOwner whenPaused {
        _unpause();
    }

    /**
     * @notice Grant permission to system to execute any automation operations
     * @dev Helps users to grant permission to the system to execute any automation operations on their behalf
     * @param permission The basic options to grant permission to the system to execute operations
     */
    function grantPermission(DelegatedPermission memory permission) public whenNotPaused onlyOwner {
        permissionsHandler.grant(permission);
    }

    /**
     * @notice Refresh permission to system to execute any automation operations
     * @dev Helps users to refresh permission to the system to execute any automation operations on their behalf
     * @param permission The basic options to refresh permission to the system to execute operations
     */
    function refreshPermission(DelegatedPermission memory permission) public whenNotPaused onlyOwner {
        permissionsHandler.refresh(permission);
    }

    /**
     * @notice Revoke permission to system to execute any automation operations
     * @dev Helps users to revoke permission to the system to execute any automation operations on their behalf
     */
    function revokePermission() public whenNotPaused onlyOwner {
        permissionsHandler.revoke();
    }

    /**
     * @notice Withdraw native currency from the smart account
     * @dev Helps the owner of the smart account to withdraw native currency from the smart account
     * @param amount The amount of native currency to withdraw from the smart account
     */
    function withdrawNativeCurrency(uint256 amount) external payable nonReentrant whenNotPaused onlyOwner {
        if (amount == 0) {
            revert RedundantOperationNotAllowed();
        }

        (bool isSuccess,) = payable(owner()).call{value: amount}("");

        if (isSuccess) {
            emit WithdrawnNativeCurrency(owner(), amount, address(this).balance);
        }
    }

    /**
     * @notice Withdraw exact token from the smart account
     * @dev Helps the owner of the smart account to withdraw owner exact token from the smart account
     * @param options The basic options to withdraw exact token from the smart account
     */
    function withdrawExactCurrency(WithdrawExactCurrencyOptions memory options) external whenNotPaused onlyOwner {
        if (options.amount == 0) {
            revert RedundantOperationNotAllowed();
        }

        IERC20(options.token).approve(owner(), options.amount);
        IERC20(options.token).safeTransfer(owner(), options.amount);

        emit WithdrawnExactCurrency(
            owner(), options.token, options.amount, IERC20(options.token).balanceOf(address(this))
        );
    }

    /**
     * @notice Withdraw tokens from the smart account
     * @dev Helps the owner of the smart account to withdraw tokens from the smart account
     * @param options The basic options to withdraw tokens from the smart account
     */
    function withdrawCurrencies(WithdrawExactCurrencyOptions[] memory options)
        external
        nonReentrant
        whenNotPaused
        onlyOwner
    {
        for (uint256 i = 0; i < options.length; ++i) {
            try ISmartAccount(address(this)).withdrawExactCurrency(options[i]) {} catch {}
        }
    }

    /**
     * @notice Withdraw native currency for performing a deal
     * @dev Helps the protocol to withdraw native currency from the smart account for performing a deal
     */
    function withdrawNativeCurrencyForDeal(uint256 amount) external payable whenNotPaused onlyInitiator onlyProtocol {
        if (amount == 0) {
            revert RedundantOperationNotAllowed();
        }

        uint256 currentBalance = address(this).balance;

        if (amount > currentBalance) {
            revert InsufficientNativeBalance(address(this), amount, currentBalance);
        }

        bool hasEnoughPermission = permissionsHandler.hasEnoughAuthorityForTradingOps(address(this), amount);

        if (hasEnoughPermission) {
            address protocolContract = msg.sender;

            (bool isSuccess,) = payable(protocolContract).call{value: amount}("");

            if (isSuccess) {
                emit WithdrawnNativeCurrencyForDeal(protocolContract, amount);
            }
        }
    }

    /**
     * @notice Withdraw tokens for performing a deal
     * @dev Helps the protocol to withdraw tokens from the smart account for performing a deal
     * @param options The basic options to withdraw tokens from the smart account for performing a deal
     */
    function withdrawCurrencyForDeal(WithdrawCurrencyForDealOptions memory options)
        external
        whenNotPaused
        onlyInitiator
        onlyProtocol
    {
        if (options.amount == 0) {
            revert RedundantOperationNotAllowed();
        }

        uint256 currentBalance = IERC20(options.token).balanceOf(address(this));

        if (options.amount > currentBalance) {
            revert InsufficientCurrencyBalance(address(this), options.token, options.amount, currentBalance);
        }

        bool hasEnoughPermission = permissionsHandler.hasEnoughAuthorityForTradingOps(address(this), options.amount);

        if (hasEnoughPermission) {
            address protocolContract = msg.sender;

            IERC20(options.token).safeTransfer(protocolContract, options.amount);

            emit WithdrawnForDeal(protocolContract, options.token, options.amount);
        }
    }

    /**
     * @notice Refund commission for processed deal
     * @dev Helps the protocol to refund commission to the initiator for processed deal
     * @param options The basic options to refund commission to the initiator for processed deal
     */
    function refundCommissionForDeal(RefundCommissionForDealOptions memory options)
        external
        whenNotPaused
        onlyInitiator
        onlyProtocol
    {
        if (options.totalFeeInNativeCurrency == 0) {
            revert RedundantOperationNotAllowed();
        }

        address initiator = tx.origin;
        PriceFeedMetadata memory metadata = platformManagement.getPriceFeedMetadata();

        bool isRelatedToCurrencyWrapper = options.token == metadata.currencyWrapper;
        (uint112 reserve0, uint112 reserve1,) = IUniBasedV2Pool(metadata.pool).getReserves();

        uint256 wrapperCurrencyReserve = uint256(metadata.wrapperCurrencyPosition == 0 ? reserve0 : reserve1);
        uint256 usdCurrencyReserve = uint256(metadata.usdCurrencyPosition == 0 ? reserve0 : reserve1);

        uint256 amountToRefund = isRelatedToCurrencyWrapper
            ? options.totalFeeInNativeCurrency
            : ((options.totalFeeInNativeCurrency * usdCurrencyReserve * 10 ** metadata.decimalsDifference)
                    / wrapperCurrencyReserve);

        bool hasEnoughPermission =
            permissionsHandler.hasEnoughAuthorityForRefundCommission(address(this), amountToRefund);

        if (hasEnoughPermission) {
            if (options.shouldRefundInNativeCurrency) {
                (bool isSuccess, bytes memory data) = payable(initiator).call{value: amountToRefund}("");

                if (!isSuccess) {
                    revert LowLevelCallFailed(isSuccess, data);
                }
            } else {
                IERC20(options.token).approve(initiator, amountToRefund);
                IERC20(options.token).safeTransfer(initiator, amountToRefund);
            }

            emit CommissionRefundedForDeal(
                initiator,
                options.totalFeeInNativeCurrency,
                amountToRefund,
                options.token,
                metadata,
                wrapperCurrencyReserve,
                usdCurrencyReserve
            );
        }
    }

    /**
     * @notice Emergency reset of token balances and permissions in the smart account
     * @dev Helps the owner of the smart account to emergency reset token balances and permissions in the smart account
     * @param tokens The list of token addresses to reset balances for
     */
    function emergencyReset(address[] memory tokens) external whenNotPaused onlyInitiator onlyProtocol {
        permissionsHandler.revoke();

        for (uint256 i = 0; i < tokens.length; ++i) {
            uint256 currentBalance = IERC20(tokens[i]).balanceOf(address(this));

            if (currentBalance > 0) {
                IERC20(tokens[i]).approve(owner(), currentBalance);
                IERC20(tokens[i]).safeTransfer(owner(), currentBalance);
            }
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// 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);
}

// 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)
        }
    }
}

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

pragma solidity ^0.8.20;

import {StorageSlot} from "./StorageSlot.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 *
 * IMPORTANT: Deprecated. This storage-based reentrancy guard will be removed and replaced
 * by the {ReentrancyGuardTransient} variant in v6.0.
 *
 * @custom:stateless
 */
abstract contract ReentrancyGuard {
    using StorageSlot for bytes32;

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant REENTRANCY_GUARD_STORAGE =
        0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    /**
     * @dev A `view` only version of {nonReentrant}. Use to block view functions
     * from being called, preventing reading from inconsistent contract state.
     *
     * CAUTION: This is a "view" modifier and does not change the reentrancy
     * status. Use it only on view functions. For payable or non-payable functions,
     * use the standard {nonReentrant} modifier instead.
     */
    modifier nonReentrantView() {
        _nonReentrantBeforeView();
        _;
    }

    function _nonReentrantBeforeView() private view {
        if (_reentrancyGuardEntered()) {
            revert ReentrancyGuardReentrantCall();
        }
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        _nonReentrantBeforeView();

        // Any calls to nonReentrant after this point will fail
        _reentrancyGuardStorageSlot().getUint256Slot().value = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _reentrancyGuardStorageSlot().getUint256Slot().value == ENTERED;
    }

    function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {
        return REENTRANCY_GUARD_STORAGE;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    bool private _paused;

    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

File 7 of 20 : Errors.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.30;

/**
 * @notice Thrown when a low-level call fails
 * @dev Used to indicate any exception that occurs during a low-level call
 * @param reason The reason for the call failure
 */
error CallFailed(string reason, bytes data);

/**
 * @notice Thrown when a low-level call fails with a boolean state and returned data
 * @dev Used to indicate any exception that occurs during a low-level call
 * @param state The boolean state indicating success or failure of the call
 * @param data The returned data from the call
 */
error LowLevelCallFailed(bool state, bytes data);

/**
 * @notice Thrown when attempting to perform an operation that is redundant or unnecessary
 * @dev Used to prevent duplicate or meaningless operations that would waste gas or cause unintended state changes
 */
error RedundantOperationNotAllowed();

/**
 * @notice Thrown when an operation is attempted with an zero address
 * @dev Used to ensure that addresses provided to functions are valid and not the zero address, which is often used as a sentinel value
 */
error ZeroAddressNotAllowed();

/**
 * @notice Thrown when an invalid fee percentage is provided
 * @dev Used to enforce constraints on fee percentages to ensure they remain within acceptable bounds
 * @param currentFeePercent The fee percentage that was attempted to be set
 * @param maxFeePercent The maximum allowable fee percentage
 */
error InvalidFeePercent(uint24 currentFeePercent, uint24 maxFeePercent);

/**
 * @notice Thrown when there is insufficient native currency balance for an operation
 * @dev Used to enforce balance requirements before performing transfers or other operations that require sufficient funds
 * @param sender The address attempting the operation
 * @param amount The amount that was required for the operation
 * @param available The actual available balance
 */
error InsufficientNativeBalance(address sender, uint256 amount, uint256 available);

/**
 * @notice Thrown when there is insufficient balance of a specific token for an operation
 * @dev Used to enforce balance requirements before performing transfers or other operations that require sufficient funds
 * @param sender The address attempting the operation
 * @param token The address of the token that has insufficient balance
 * @param amount The amount that was required for the operation
 * @param available The actual available balance
 */
error InsufficientCurrencyBalance(address sender, address token, uint256 amount, uint256 available);

/**
 * @notice Thrown when an operation is attempted by an not DAO address
 * @dev Used to restrict access to certain functions to specific roles or addresses
 */
error OnlyDaoCanPerformOperation();

/**
 * @notice Thrown when an operation is attempted by an not SCI address
 * @dev Used to restrict access to certain functions to specific roles or addresses
 */
error OnlySciCanPerformOperation();

/**
 * @notice Thrown when an operation is attempted by an not protocol contract address
 * @dev Used to restrict access to certain functions to specific roles or addresses
 */
error OnlyProtocolCanPerformOperation();

/**
 * @notice Thrown when a referral tries to link to a referrer when they already have one
 * @dev Used to prevent changing referrer relationships once established
 * @param referral The address of the referral attempting the operation
 * @param existingReferrer The address of the existing referrer already linked to the referral
 */
error ReferralAlreadyLinked(address referral, address existingReferrer);

/**
 * @notice Thrown when an operation is attempted without sufficient permissions
 * @dev Used to enforce permission checks before allowing certain operations to proceed
 * @param target The address attempting the operation
 * @param isEnoughAmount Indicating if the trading amount or native coin amount permission is sufficient
 * @param isEnoughOpsAmount Indicating if the operations amount permission is sufficient
 */
error NotEnoughPermissions(address target, bool isEnoughAmount, bool isEnoughOpsAmount);

/**
 * @notice Thrown when a swap operation cannot be performed
 * @dev Used to indicate that a swap operation failed due to unmet conditions or constraints
 */
error UnableToPerformSwapOperation();

/**
 * @notice Thrown when an operation is attempted with a zero amount
 * @dev Used to prevent operations that require a non-zero amount from proceeding with a zero value
 * @param token The address of the token involved in the operation
 */
error ZeroAmountNotAllowed(address token);

File 8 of 20 : Events.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.30;

import {PermissionStateHandler} from "./Enums.sol";
import {
    DelegatedPermission,
    SingleUniBasedSecondVersionSwapOptions,
    SingleUniBasedThirdVersionSwapOptions,
    PriceFeedMetadata
} from "./Structures.sol";

/**
 * @notice Emitted when the platform fee percentage is updated for a specific fee type
 * @dev This event is triggered whenever the protocol updates its fee structure
 * @param newFeePercent The new fee percentage that was set (in basis points or percentage)
 */
event PlatformFeePercentRefreshed(uint16 newFeePercent);

/**
 * @notice Emitted when a token's forbidden status is updated
 * @dev This event is triggered whenever the protocol updates the list of forbidden tokens
 * @param token The address of the token whose forbidden status was updated
 * @param isForbidden A boolean indicating whether the token is forbidden (true) or available (false)
 */
event ForbiddenTokenStateRefreshed(address token, bool isForbidden);

/**
 * @notice Emitted when a trading currency's active status is updated
 * @dev This event is triggered whenever the protocol updates the list of active trading currencies
 * @param currency The address of the currency whose active status was updated
 * @param isActive A boolean indicating whether the currency is active (true) or inactive (false)
 */
event TradingCurrencyStateRefreshed(address currency, bool isActive);

/**
 * @notice Emitted when a special company initiator wallet's active status is updated
 * @dev This event is triggered whenever the protocol updates the list of special company initiator wallets
 * @param wallet The address of the special company initiator wallet whose active status was updated
 * @param isActive A boolean indicating whether the wallet is active (true) or inactive (false)
 */
event SpecialCompanyInitiatorWalletRefreshed(address wallet, bool isActive);

/**
 * @notice Emitted when a protocol contract's active status is updated
 * @dev This event is triggered whenever the protocol updates the list of active protocol contracts
 * @param companyContract The address of the protocol contract whose active status was updated
 * @param isActive A boolean indicating whether the contract is active (true) or inactive (false)
 */
event ProtocolContractRefreshed(address companyContract, bool isActive);

/**
 * @notice Emitted when a user's permission state is updated
 * @dev This event is triggered whenever a user's permissions are refreshed, either granted or revoked
 * @param user The address of the user whose permission state was updated
 * @param state The new permission state of the user
 * @param permission The specific delegated permission that was updated for the user
 */
event PermissionState(address indexed user, PermissionStateHandler state, DelegatedPermission permission);

/**
 * @notice Emitted when a user withdraws native currency from their smart account
 * @dev This event is triggered whenever a user successfully withdraws native currency
 * @param user The address of the user who performed the withdrawal
 * @param amount The amount of native currency withdrawn from the user's smart account
 * @param balanceRemainder The remaining balance in the user's smart account after the withdrawal
 */
event WithdrawnNativeCurrency(address indexed user, uint256 amount, uint256 balanceRemainder);

/**
 * @notice Emitted when a user withdraws tokens from their smart account
 * @dev This event is triggered whenever a user successfully withdraws tokens
 * @param user The address of the user who performed the withdrawal
 * @param token The address of the token that was withdrawn
 * @param amount The amount withdrawn from the user's balance
 * @param balanceRemainder The remaining balance in the user's account after the withdrawal
 */
event WithdrawnExactCurrency(address indexed user, address indexed token, uint256 amount, uint256 balanceRemainder);

/**
 * @notice Emitted when a new referral relationship is established
 * @dev This event is triggered whenever a referral successfully links to a referrer
 * @param referral The address of the referral who established the relationship
 * @param referrer The address of the referrer who was linked to the referral
 */
event NewReferralRelation(address indexed referral, address indexed referrer);

/**
 * @notice Emitted when an existing referral relationship is refreshed or updated
 * @dev This event is triggered whenever a referral updates their referrer information
 * @param referral The address of the referral who updated their relationship
 * @param newReferrer The address of the new referrer who was linked to the referral
 */
event RefreshedReferralRelation(address indexed referral, address indexed newReferrer);

/**
 * @notice Emitted when native currency is withdrawn from a smart account for performing a deal
 * @dev This event is triggered whenever the protocol withdraws native currency from a smart account to facilitate a deal
 * @param protocolContract The address of the protocol contract that initiated the withdrawal
 * @param amount The amount of native currency that was withdrawn for the deal
 */
event WithdrawnNativeCurrencyForDeal(address protocolContract, uint256 amount);

/**
 * @notice Emitted when tokens are withdrawn from a smart account for performing a deal
 * @dev This event is triggered whenever the protocol withdraws tokens from a smart account to facilitate a deal
 * @param protocolContract The address of the protocol contract that initiated the withdrawal
 * @param token The address of the token that was withdrawn
 * @param amount The amount of tokens that were withdrawn for the deal
 */
event WithdrawnForDeal(address protocolContract, address token, uint256 amount);

/**
 * @notice Emitted when commission fees are refunded to an initiator for a specific deal
 * @dev This event is triggered whenever the protocol refunds commission fees to an initiator
 * @param initiator The address of the initiator who received the refund
 * @param totalFeeInNativeCurrency The total fee amount that was refunded, denominated in native currency
 * @param amount The amount of commission fees that were refunded
 * @param token The address of the token in which the refund was made
 * @param metadata The price feed metadata associated with the refund
 * @param wrapperCurrencyReserve The reserve amount of the currency wrapper in the liquidity pool
 * @param usdCurrencyReserve The reserve amount of the USD currency in the liquidity pool
 */
event CommissionRefundedForDeal(
    address initiator,
    uint256 totalFeeInNativeCurrency,
    uint256 amount,
    address token,
    PriceFeedMetadata metadata,
    uint256 wrapperCurrencyReserve,
    uint256 usdCurrencyReserve
);

/**
 * @notice Emitted when a commission refund fails for a specific deal
 * @dev This event is triggered whenever the protocol fails to refund commission fees to an initiator
 * @param index The index of the refund operation in the batch
 * @param stringReason The reason for the failure as a string
 * @param bytesReason The reason for the failure as bytes
 */
event CommissionRefundFailed(uint256 index, string stringReason, bytes bytesReason);

/**
 * @notice Emitted when a single uni-based second version swap is processed
 * @dev This event is triggered whenever a single swap operation is executed
 * @param options The options used for the swap operation
 * @param feeCurrency The address of the currency used to pay platform fees
 * @param tokenIn The address of the input token used in the swap
 * @param tokenOut The address of the output token received from the swap
 * @param amountIn The amount of input tokens used in the swap
 * @param amountOut The amount of output tokens received from the swap
 * @param platformFee The amount of platform fees deducted from the swap
 */
event SingleUniBasedSecondVersionSwapProcessed(
    SingleUniBasedSecondVersionSwapOptions options,
    address feeCurrency,
    address tokenIn,
    address tokenOut,
    uint256 amountIn,
    uint256 amountOut,
    uint256 platformFee
);

/**
 * @notice Emitted when a single uni-based third version swap is processed
 * @dev This event is triggered whenever a single swap operation is executed
 * @param options The options used for the swap operation
 * @param feeCurrency The address of the currency used to pay platform fees
 * @param tokenIn The address of the input token used in the swap
 * @param tokenOut The address of the output token received from the swap
 * @param amountIn The amount of input tokens used in the swap
 * @param amountOut The amount of output tokens received from the swap
 * @param platformFee The amount of platform fees deducted from the swap
 */
event SingleUniBasedThirdVersionSwapProcessed(
    SingleUniBasedThirdVersionSwapOptions options,
    address feeCurrency,
    address tokenIn,
    address tokenOut,
    uint256 amountIn,
    uint256 amountOut,
    uint256 platformFee
);

/**
 * @notice Emitted when a single uni-based second version swap in a batch completes with a result
 * @dev This event is triggered whenever a single swap operation in a batch completes with a result
 * @param index The index of the swap operation in the batch
 * @param isSuccess A boolean indicating whether the swap operation was successful (true) or failed (false)
 * @param failedReason The reason for failure if the swap operation failed
 * @param data The raw data returned from the swap operation
 */
event SingleUniBasedSwapInBatchResult(uint256 index, bool isSuccess, string failedReason, bytes data);

File 9 of 20 : Structures.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.30;

/**
 * @notice Metadata for a price feed based on a uni-based liquidity pool
 * @dev Used to identify and interact with specific uni-based pools for price data
 * @param pool The address of the uni-based liquidity pool
 * @param currencyWrapper The address of the currency wrapper used in the pool
 * @param wrapperCurrencyPosition The position index of the wrapper currency in the pool (0 or 1)
 * @param usdCurrencyPosition The position index of the USD currency in the pool (0 or 1)
 */
struct PriceFeedMetadata {
    address pool;
    address currencyWrapper;
    uint256 decimalsDifference;
    uint8 wrapperCurrencyPosition;
    uint8 usdCurrencyPosition;
}

/**
 * @notice Options for initializing the platform management contract
 * @dev Used to set up the platform management with necessary parameters during deployment
 * @param forbiddenTokens An array of token addresses that are forbidden in the protocol
 * @param tradingCurrencies An array of token addresses that are allowed as trading currencies in the protocol
 * @param initiators An array of addresses that are authorized as initiators in the protocol
 * @param platformFeePercent The default platform fee percentage applied to operations
 * @param priceFeedMetadata The metadata for the price feed based on a uni-based liquidity pool
 */
struct InitialPlatformManagementOptions {
    address[] forbiddenTokens;
    address[] tradingCurrencies;
    address[] initiators;
    uint16 platformFeePercent;
    PriceFeedMetadata priceFeedMetadata;
}

/**
 * @notice Options for initializing the permissions handler contract
 * @dev Used to set up the permissions handler with necessary parameters during deployment
 * @param platformManagement The address of the PlatformManagement contract
 */
struct InitialPermissionsHandlerOptions {
    address platformManagement;
}

/**
 * @notice Options for initializing the smart account contract
 * @dev Used to set up the smart account with necessary parameters during deployment
 * @param initialOwner The address of the initial owner of the smart account
 * @param platformManagement The address of the PlatformManagement contract
 * @param permissionsHandler The address of the PermissionsHandler contract
 * @param permission Represents the state of a user's permissions within the protocol
 */
struct InitialSmartAccountOptions {
    address initialOwner;
    address platformManagement;
    address permissionsHandler;
    DelegatedPermission permission;
}

/**
 * @notice Options for initializing the uni-based swapper contract
 * @dev Used to set up the swapper contract with necessary parameters during deployment
 * @param permissionsHandler The address of the PermissionsHandler contract
 * @param platformManagement The address of the PlatformManagement contract
 * @param initialOwner The address of the initial owner of the swapper contract
 */
struct InitialCommonSwapperOptions {
    address permissionsHandler;
    address platformManagement;
    address initialOwner;
}

/**
 * @notice Options for initializing the uni-based batcher contract
 * @dev Used to set up the swapper contract with necessary parameters during deployment
 * @param platformManagement The address of the PlatformManagement contract
 * @param uniBasedSecondVersionSwapper The address of the uni-based second version contract
 * @param uniBasedThirdVersionSwapper The address of the uni-based third version contract
 */
struct InitialUniBasedBatcherOptions {
    address platformManagement;
    address uniBasedSecondVersionSwapper;
    address uniBasedThirdVersionSwapper;
}

/**
 * @notice Represents platform fee and referral royalty calculations for a transaction
 * @dev Used to summarize the financial breakdown of a transaction involving fees and royalties
 * @param amount The amount involved in the transaction
 * @param platformFeeRemainder The portion of the total fee that goes to the platform
 */
struct PlatformCalculations {
    uint256 amount;
    uint256 platformFeeRemainder;
}

/**
 * @notice Options for checking if a swap operation can be performed
 * @dev Used to validate swap operations before execution
 * @param tokenIn The address of the input token for the swap
 * @param tokenOut The address of the output token for the swap
 * @param amount The amount of the input token to be swapped
 */
struct CanPerformSwapOperationOptions {
    address tokenIn;
    address tokenOut;
    uint256 amount;
}

/**
 * @notice Represents the state of a user's permissions within the protocol
 * @dev Used to manage and enforce user permissions for various operations
 * @param availableOpsAmount The number of operations the user is allowed to perform
 * @param exactAmountPerOperation The exact amount allowed per operation
 * @param maxCommissionPerOperation The maximum commission allowed per operation
 */
struct DelegatedPermission {
    uint16 availableOpsAmount;
    uint256 exactAmountPerOperation;
    uint256 maxCommissionPerOperation;
}

/**
 * @notice Options for withdrawing currency from a smart account
 * @dev Used by the owner of a smart account to withdraw funds
 * @param token The address of the token to be withdrawn
 * @param amount The amount of the token to be withdrawn
 */
struct WithdrawExactCurrencyOptions {
    address token;
    uint256 amount;
}

/**
 * @notice Options for withdrawing currency from a smart account for performing a deal
 * @dev Used by the protocol to withdraw necessary funds from a smart account to facilitate a deal
 * @param token The address of the token to be withdrawn
 * @param amount The amount of the token to be withdrawn
 */
struct WithdrawCurrencyForDealOptions {
    address token;
    uint256 amount;
}

/**
 * @notice Options for refunding commission fees to an initiator for a specific deal
 * @dev Used by the protocol to refund commission fees back to the initiator after a deal is completed
 * @param token The address of the token in which the commission fees are to be refunded
 * @param totalFeeInNativeCurrency The total fee amount to be refunded, denominated in native currency
 * @param shouldRefundInNativeCurrency A boolean indicating whether the refund should be made in native currency
 */
struct RefundCommissionForDealOptions {
    address token;
    uint256 totalFeeInNativeCurrency;
    bool shouldRefundInNativeCurrency;
}

/**
 * @notice Options for performing a single uni-based swap operation (version 2)
 * @dev Used to specify parameters for executing a token swap using uni-based contracts
 * @param router The address of the uni-based V2 router contract
 * @param receiver The address of the receiver of the currencies
 * @param path An array of token addresses representing the swap path
 * @param amountIn The amount of input tokens to be swapped
 * @param amountOutMin The minimum amount of output tokens expected from the swap
 * @param deadline The timestamp by which the swap must be completed
 * @param shouldUseNativeCurrency A boolean indicating whether to use native currency for the swap
 */
struct SingleUniBasedSecondVersionSwapOptions {
    address router;
    address receiver;
    address[] path;
    uint256 amountIn;
    uint256 amountOutMin;
    uint256 deadline;
    bool shouldUseNativeCurrency;
}

/**
 * @notice Options for performing a single uni-based swap operation (version 3)
 * @dev Used to specify parameters for executing a token swap using uni-based V3 contracts
 * @param router The address of the uni-based V3 router contract
 * @param receiver The address of the receiver of the currencies
 * @param path An array of token addresses representing the swap path
 * @param fees An array of fee tiers corresponding to each hop in the swap path
 * @param amountIn The amount of input tokens to be swapped
 * @param amountOutMin The minimum amount of output tokens expected from the swap
 * @param deadline The timestamp by which the swap must be completed
 */
struct SingleUniBasedThirdVersionSwapOptions {
    address router;
    address receiver;
    address[] path;
    uint24[] fees;
    uint256 amountIn;
    uint256 amountOutMin;
    uint256 deadline;
    bool shouldUseNativeCurrency;
}

File 10 of 20 : IUniBasedV2Pool.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.30;

/**
 * @author Uniswap
 * @title Abstract layer for working with pools based information on second version
 * @notice This interface is an abstract layer for working with pools based information on second version
 * @custom:security-contact [email protected]
 */
interface IUniBasedV2Pool {
    /**
     * @notice Get the reserves of the two tokens in the pool
     * @dev Returns the reserves of token0 and token1, along with the last block timestamp
     * @return reserve0 The reserve of token0
     * @return reserve1 The reserve of token1
     * @return blockTimestampLast The last block timestamp when the reserves were updated
     */
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.30;

import {PlatformCalculations, CanPerformSwapOperationOptions, PriceFeedMetadata} from "../common/Structures.sol";

/**
 * @author lotos
 * @title Abstract layer for PlatformManagement contract
 * @notice This interface is an abstract layer for the PlatformManagement contract, which allows for managing platform-related operations in the system
 * @custom:security-contact [email protected]
 */
interface IPlatformManagement {
    /**
     * @notice Allows to forbid the token for operations on the platform
     * @dev Helps to forbid the token for operations on the platform
     * @param token The address of the token to be forbidden for operations on the platform
     * @param isForbidden The boolean value to set the token as forbidden or not forbidden
     */
    function setForbiddenToken(address token, bool isForbidden) external;

    /**
     * @notice Allows to set the trading currency for operations on the platform
     * @dev Helps to set the trading currency for operations on the platform
     * @param currency The address of the currency to be set as a trading currency for operations on the platform
     * @param isActive The boolean value to set the currency as active or not active trading currency for operations on the platform
     */
    function setTradingCurrency(address currency, bool isActive) external;

    /**
     * @notice Allows to set the wallet addresses that represents company in order to execute any automation actions
     * @dev Helps to set the wallet addresses that represents company in order to execute any automation actions
     * @param wallet The address of the wallet to be set as a special company initiator
     * @param isActive The boolean value to set the wallet as active or inactive
     */
    function setSpecialCompanyInitiators(address wallet, bool isActive) external;

    /**
     * @notice Allows to set the contracts addresses that represents company in order to secure execute any automation actions
     * @dev Helps to set the contracts addresses that represents company in order to secure execute any automation actions
     * @param companyContract The address of the company contract to be set as a protocol address
     * @param isActive The boolean value to set the contract as active or inactive
     */
    function setProtocolContract(address companyContract, bool isActive) external;

    /**
     * @notice Allows to setup platform fees by their types for operations
     * @dev Helps to setup platform fees by their types for operations
     * @param platformFeePercent The platform fee percentage to be set
     */
    function setPlatformFee(uint16 platformFeePercent) external;

    /**
     * @notice Allows to enable or disable token to token swap operations on the platform
     * @dev Helps to enable or disable token to token swap operations on the platform
     * @param value The boolean value to enable or disable token to token swap operations on the platform
     */
    function setTokenToTokenOpsExecutionState(bool value) external;

    /**
     * @notice Allows to set price feed metadata
     * @dev Helps to set price feed metadata
     * @param metadata The price feed metadata to be set
     */
    function setPriceFeedMetadata(PriceFeedMetadata memory metadata) external;

    /**
     * @notice Get price feed metadata
     * @dev Helps to get price feed metadata
     * @return The structure with price feed metadata
     */
    function getPriceFeedMetadata() external view returns (PriceFeedMetadata memory);

    /**
     * @notice Allows to identify if the address is a special company initiator
     * @dev Helps to identify if the address is a special company initiator
     * @param wallet The address of the wallet to be checked
     * @return The boolean value, which shows if the address is a special company initiator or not
     */
    function isSpecialCompanyInitiator(address wallet) external view returns (bool);

    /**
     * @notice Allows to identify if the address is a company protocol contract
     * @dev Helps to identify if the address is a company protocol contract
     * @param companyContract The address of the contract to be checked
     * @return The boolean value, which shows if the address is a company protocol contract or not
     */
    function isCompanyProtocol(address companyContract) external view returns (bool);

    /**
     * @notice Allows to identify if the address is a forbidden token
     * @dev Helps to identify if the address is a forbidden token
     * @param token The address of the token to be checked
     * @return The boolean value, which shows if the address is a forbidden token or not
     */
    function isTokenForbidden(address token) external view returns (bool);

    /**
     * @notice Allows to identify if the address is a trading currency
     * @dev Helps to identify if the address is a trading currency
     * @param currency The address of the currency to be checked
     * @return The boolean value, which shows if the address is a trading currency or not
     */
    function isTradingCurrency(address currency) external view returns (bool);

    /**
     * @notice Get calculations considering platform fee and referral system royalties
     * @dev Helps to get calculations considering platform fee and referral system royalties
     * @param amount The initial amount to perform calculations
     * @return The structure with all calculations considering platform fee and referral system royalties
     */
    function getCalculationsConsideringFee(uint256 amount) external view returns (PlatformCalculations memory);

    /**
     * @notice Check if the swap operation can be performed
     * @dev Helps to check if the swap operation can be performed
     * @param options The basic options to check if the swap operation can be performed
     * @return The boolean value, which shows if the swap operation can be performed or not
     */
    function canPerformSwapOperation(CanPerformSwapOperationOptions memory options) external view returns (bool);

    /**
     * @notice Emergency reset of token balances and permissions in the smart accounts
     * @dev Helps the owner of the smart accounts to emergency reset token balances and permissions in the smart accounts
     * @param smartAccounts The list of smart account addresses to reset balances for
     * @param tokens The list of token addresses to reset balances for
     */
    function emergencyReset(address[] memory smartAccounts, address[] memory tokens) external;
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.30;

import {DelegatedPermission} from "../common/Structures.sol";

/**
 * @author lotos
 * @title Abstract layer for PermissionsHandler contract
 * @notice This interface is an abstract layer for the PermissionsHandler contract, which allows for managing users permissions in the system
 * @custom:security-contact [email protected]
 */
interface IPermissionsHandler {
    /**
     * @notice Grant permission to system to execute any automation operations
     * @dev Helps users to grant permission to the system to execute any automation operations on their behalf
     * @param permission The basic options to grant permission to the system to execute operations
     */
    function grant(DelegatedPermission memory permission) external;

    /**
     * @notice Refresh permission to system to execute any automation operations
     * @dev Helps users to refresh permission to the system to execute any automation operations on their behalf
     * @param permission The basic options to refresh permission to the system to execute operations
     */
    function refresh(DelegatedPermission memory permission) external;

    /**
     * @notice Revoke permission to system to execute any automation operations
     * @dev Helps users to revoke permission to the system to execute any automation operations on their behalf
     */
    function revoke() external;

    /**
     * @notice Decrease available operations amount for the target address
     * @dev Helps to decrease available operations amount for the target address
     * @param target The target address to decrease available operations amount
     */
    function decreaseAvailableOpsAmount(address target) external;

    /**
     * @notice Check if the target address has enough authority to perform the operation
     * @dev Helps to check if the target address has enough authority to perform the operation
     * @param target The target address to check permissions
     * @param amount The amount of tokens to check
     * @return The boolean value, which true if the target address has enough authority to perform the operation, otherwise false
     */
    function hasEnoughAuthorityForTradingOps(address target, uint256 amount) external returns (bool);

    /**
     * @notice Check if the target address has enough authority to perform the refund commission operation
     * @dev Helps to check if the target address has enough authority to perform the refund commission operation
     * @param target The target address to check permissions
     * @param amount The amount of native currency to check
     * @return The boolean value, which true if the target address has enough authority to perform the operation, otherwise false
     */
    function hasEnoughAuthorityForRefundCommission(address target, uint256 amount) external returns (bool);
}

// SPDX-License-Identifier: MIT

pragma solidity 0.8.30;

import {
    WithdrawExactCurrencyOptions,
    WithdrawCurrencyForDealOptions,
    RefundCommissionForDealOptions,
    DelegatedPermission
} from "../common/Structures.sol";

/**
 * @author lotos
 * @title Abstract layer for SmartAccount contract
 * @notice This interface is an abstract layer for the SmartAccount contract, which allows users to manage their smart accounts
 * @custom:security-contact [email protected]
 */
interface ISmartAccount {
    /**
     * @notice Pause the contract
     * @dev Helps temporary to stop all the contract functions
     */
    function pause() external;

    /**
     * @notice Unpause the contract
     * @dev Helps recover the contract from paused state
     */
    function unpause() external;

    /**
     * @notice Grant permission to system to execute any automation operations
     * @dev Helps users to grant permission to the system to execute any automation operations on their behalf
     * @param permission The basic options to grant permission to the system to execute operations
     */
    function grantPermission(DelegatedPermission memory permission) external;

    /**
     * @notice Refresh permission to system to execute any automation operations
     * @dev Helps users to refresh permission to the system to execute any automation operations on their behalf
     * @param permission The basic options to refresh permission to the system to execute operations
     */
    function refreshPermission(DelegatedPermission memory permission) external;

    /**
     * @notice Revoke permission to system to execute any automation operations
     * @dev Helps users to revoke permission to the system to execute any automation operations on their behalf
     */
    function revokePermission() external;

    /**
     * @notice Withdraw native currency from the smart account
     * @dev Helps the owner of the smart account to withdraw native currency from the smart account
     */
    function withdrawNativeCurrency(uint256 amount) external payable;

    /**
     * @notice Withdraw exact token from the smart account
     * @dev Helps the owner of the smart account to withdraw owner exact token from the smart account
     * @param options The basic options to withdraw exact token from the smart account
     */
    function withdrawExactCurrency(WithdrawExactCurrencyOptions memory options) external;

    /**
     * @notice Withdraw tokens from the smart account
     * @dev Helps the owner of the smart account to withdraw tokens from the smart account
     * @param options The basic options to withdraw tokens from the smart account
     */
    function withdrawCurrencies(WithdrawExactCurrencyOptions[] memory options) external;

    /**
     * @notice Withdraw native currency for performing a deal
     * @dev Helps the protocol to withdraw native currency from the smart account for performing a deal
     */
    function withdrawNativeCurrencyForDeal(uint256 amount) external payable;

    /**
     * @notice Withdraw tokens for performing a deal
     * @dev Helps the protocol to withdraw tokens from the smart account for performing a deal
     * @param options The basic options to withdraw tokens from the smart account for performing a deal
     */
    function withdrawCurrencyForDeal(WithdrawCurrencyForDealOptions memory options) external;

    /**
     * @notice Refund commission for processed deal
     * @dev Helps the protocol to refund commission to the initiator for processed deal
     * @param options The basic options to refund commission to the initiator for processed deal
     */
    function refundCommissionForDeal(RefundCommissionForDealOptions memory options) external;

    /**
     * @notice Emergency reset of token balances and permissions in the smart account
     * @dev Helps the owner of the smart account to emergency reset token balances and permissions in the smart account
     * @param tokens The list of token addresses to reset balances for
     */
    function emergencyReset(address[] memory tokens) external;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// 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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC-1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * TIP: Consider using this library along with {SlotDerivation}.
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct Int256Slot {
        int256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Int256Slot` with member `value` located at `slot`.
     */
    function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        assembly ("memory-safe") {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns a `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        assembly ("memory-safe") {
            r.slot := store.slot
        }
    }
}

File 17 of 20 : Enums.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.30;

/**
 * @notice Represents the state of permission for automation operations
 * @dev Used in PermissionsHandler contract and related events
 */
enum PermissionStateHandler {
    GRANTED,
    REFRESHED,
    REVOKED,
    DECREASED
}

File 18 of 20 : 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";

File 19 of 20 : 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";

// 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);
}

Settings
{
  "remappings": [
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/",
    "openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "prague",
  "viaIR": true
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"components":[{"internalType":"address","name":"initialOwner","type":"address"},{"internalType":"address","name":"platformManagement","type":"address"},{"internalType":"address","name":"permissionsHandler","type":"address"},{"components":[{"internalType":"uint16","name":"availableOpsAmount","type":"uint16"},{"internalType":"uint256","name":"exactAmountPerOperation","type":"uint256"},{"internalType":"uint256","name":"maxCommissionPerOperation","type":"uint256"}],"internalType":"struct DelegatedPermission","name":"permission","type":"tuple"}],"internalType":"struct InitialSmartAccountOptions","name":"options","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"available","type":"uint256"}],"name":"InsufficientCurrencyBalance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"available","type":"uint256"}],"name":"InsufficientNativeBalance","type":"error"},{"inputs":[{"internalType":"bool","name":"state","type":"bool"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"LowLevelCallFailed","type":"error"},{"inputs":[],"name":"OnlyProtocolCanPerformOperation","type":"error"},{"inputs":[],"name":"OnlySciCanPerformOperation","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"RedundantOperationNotAllowed","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"initiator","type":"address"},{"indexed":false,"internalType":"uint256","name":"totalFeeInNativeCurrency","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"components":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"currencyWrapper","type":"address"},{"internalType":"uint256","name":"decimalsDifference","type":"uint256"},{"internalType":"uint8","name":"wrapperCurrencyPosition","type":"uint8"},{"internalType":"uint8","name":"usdCurrencyPosition","type":"uint8"}],"indexed":false,"internalType":"struct PriceFeedMetadata","name":"metadata","type":"tuple"},{"indexed":false,"internalType":"uint256","name":"wrapperCurrencyReserve","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"usdCurrencyReserve","type":"uint256"}],"name":"CommissionRefundedForDeal","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"balanceRemainder","type":"uint256"}],"name":"WithdrawnExactCurrency","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"protocolContract","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawnForDeal","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"balanceRemainder","type":"uint256"}],"name":"WithdrawnNativeCurrency","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"protocolContract","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawnNativeCurrencyForDeal","type":"event"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"emergencyReset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint16","name":"availableOpsAmount","type":"uint16"},{"internalType":"uint256","name":"exactAmountPerOperation","type":"uint256"},{"internalType":"uint256","name":"maxCommissionPerOperation","type":"uint256"}],"internalType":"struct DelegatedPermission","name":"permission","type":"tuple"}],"name":"grantPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"permissionsHandler","outputs":[{"internalType":"contract IPermissionsHandler","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"platformManagement","outputs":[{"internalType":"contract IPlatformManagement","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint16","name":"availableOpsAmount","type":"uint16"},{"internalType":"uint256","name":"exactAmountPerOperation","type":"uint256"},{"internalType":"uint256","name":"maxCommissionPerOperation","type":"uint256"}],"internalType":"struct DelegatedPermission","name":"permission","type":"tuple"}],"name":"refreshPermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"totalFeeInNativeCurrency","type":"uint256"},{"internalType":"bool","name":"shouldRefundInNativeCurrency","type":"bool"}],"internalType":"struct RefundCommissionForDealOptions","name":"options","type":"tuple"}],"name":"refundCommissionForDeal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revokePermission","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct WithdrawExactCurrencyOptions[]","name":"options","type":"tuple[]"}],"name":"withdrawCurrencies","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct WithdrawCurrencyForDealOptions","name":"options","type":"tuple"}],"name":"withdrawCurrencyForDeal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct WithdrawExactCurrencyOptions","name":"options","type":"tuple"}],"name":"withdrawExactCurrency","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawNativeCurrency","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawNativeCurrencyForDeal","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]

0x608080604052346101da5780611b3b803803809161001d8285610227565b833981010360c081126101da5760405190608082016001600160401b03811183821017610213576040526100508361024a565b825261005e6020840161024a565b6020830190815260606100736040860161024a565b6040850190815292605f1901126101da5760405193606085016001600160401b038111868210176102135760405260608101519061ffff821682036101da5760a091865260808101516020870152015160408501526060830193845260017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00553315610200576101023361025e565b51600180546001600160a01b039283166001600160a01b0319918216179091559151600280549190921692168217905591515f5460ff60a082901c166101f157336001600160a01b03909116036101de57823b156101da57604060645f928383519687948593637c89966960e11b855261ffff815116600486015260208101516024860152015160448401525af19182156101cf576101b0926101bf575b50516001600160a01b031661025e565b60405161189690816102a58239f35b5f6101c991610227565b5f6101a0565b6040513d5f823e3d90fd5b5f80fd5b63118cdaa760e01b5f523360045260245ffd5b63d93c066560e01b5f5260045ffd5b631e4fbdf760e01b5f525f60045260245ffd5b634e487b7160e01b5f52604160045260245ffd5b601f909101601f19168101906001600160401b0382119082101761021357604052565b51906001600160a01b03821682036101da57565b5f80546001600160a01b039283166001600160a01b03198216811783559216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09080a356fe6080604052600436101561001a575b3615610018575f80fd5b005b5f5f3560e01c806311e78b121461149757806315f5254e146113f55780632b24f558146111225780633f4ba83a146110bf5780634debb5a8146110615780635ac7878a14610ea95780635c975abb14610e84578063602a87bb14610d325780636230c9d414610ca5578063715018a614610c4b5780638127b54f14610c225780638456cb5914610bb957806388c2efc514610b905780638da5cb5b14610b69578063b5d17c83146105ab578063cddc5b3014610421578063dfdacf8c146101735763f2fde38b146100eb575061000e565b34610170576020366003190112610170576101046115e7565b61010c611743565b6001600160a01b0316801561015c5781546001600160a01b03198116821783556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b631e4fbdf760e01b82526004829052602482fd5b80fd5b50346101705760403660031901126101705761018e36611611565b610196611726565b60015460405163ba0181af60e01b81523260048201526001600160a01b0390911690602081602481855afa908115610337578491610402575b50156103f35760206024916040519283809263fdd7ac6960e01b82523360048301525afa9081156103e85783916103c9575b50156103ba5760208101908151156103ab5780516040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa908115610337578491610375575b508251908082116103425750506002548251604051634efd8ccb60e11b81523060048201526024810191909152906020908290604490829088906001600160a01b03165af1908115610337578491610308575b506102a8578280f35b7f7141dc5542eadd36bf101b0051cc315334f4e0770d22db4ab0eb351c564c2e46916060916102e460018060a01b0382511683519033906117a1565b519051604080513381526001600160a01b039093166020840152820152a15f808280f35b61032a915060203d602011610330575b6103228183611572565b810190611689565b5f61029f565b503d610318565b6040513d86823e3d90fd5b60849260018060a01b039051169160405192633a1fa93b60e01b8452306004850152602484015260448301526064820152fd5b90506020813d6020116103a3575b8161039060209383611572565b8101031261039f57515f61024c565b5f80fd5b3d9150610383565b6390fe12ab60e01b8352600483fd5b630f9013db60e31b8252600482fd5b6103e2915060203d602011610330576103228183611572565b5f610201565b6040513d85823e3d90fd5b6304026a8f60e11b8352600483fd5b61041b915060203d602011610330576103228183611572565b5f6101cf565b50346101705760403660031901126101705761043c36611611565b610444611726565b61044c611743565b60208101908151156103ab5780518354835160405163095ea7b360e01b81526001600160a01b039283166004820152602481019190915291602091839160449183918991165af180156103375761058e575b508051835483516104bd9290916001600160a01b0390811691166117a1565b8254905191516040516370a0823160e01b81523060048201526001600160a01b039384169390921691602081602481875afa908115610583578591610531575b507fe2385497caa1b3a70f77d89029deb8e23d2a635cb49434291918d61a4ca22e3c9160409182519182526020820152a380f35b90506020813d60201161057b575b8161054c60209383611572565b8101031261039f57517fe2385497caa1b3a70f77d89029deb8e23d2a635cb49434291918d61a4ca22e3c6104fd565b3d915061053f565b6040513d87823e3d90fd5b6105a69060203d602011610330576103228183611572565b61049e565b503461017057606036600319011261017057604051906105ca82611526565b6105d26115e7565b8252602082016024358152604435908115158203610b6557604084019182526105f9611726565b60015460405163ba0181af60e01b81523260048201526001600160a01b0390911690602081602481855afa908115610583578591610b46575b5015610b375760405163fdd7ac6960e01b8152336004820152602081602481855afa908115610583578591610b18575b5015610b0957815115610afa579060a0600493926040519485809263ebfe259360e01b82525afa928315610337578493610a43575b5084516020840180518551604051630240bc6b60e21b81526001600160a01b03928316948316949094149693959493929160609187916004918391165afa938415610a3857879588956109d5575b50606083019360ff855116155f146109c6576001600160701b0380885b1697608086019760ff895116155f146109bf57505b169715610962578051915b600254604051638a1c027360e01b81523060048201526024810185905290602090829060449082908f906001600160a01b03165af1908115610957578b91610938575b5061076e578980f35b5115610871578880808085325af161078461164a565b90158061082a57505093604060ff9461016099979486947f48cca0a1da1051bb5fd74701e2a91c5bac463de75ee9c852ae1c4b35797fa22b9c9d9a985b519a518451328152602081019c909c528b8501919091526001600160a01b0390811660608c01528251811660808c015290511660a08a0152015160c0880152511660e08601525116610100840152610120830152610140820152a1805f80808080808080808980f35b60649060208c60405194859363add0f56d60e01b8552156004850152604060248501528051928391826044870152018585015e828201840152601f01601f19168101030190fd5b895160405163095ea7b360e01b815232600482015260248101849052999a9299919892979296929591949293928b916020908790604490829086906001600160a01b03165af193841561092d577f48cca0a1da1051bb5fd74701e2a91c5bac463de75ee9c852ae1c4b35797fa22b9b6101609b60ff98899760409650610910575b508b5161090b90839032906001600160a01b03166117a1565b6107c1565b6109289060203d602011610330576103228183611572565b6108f2565b6040513d84823e3d90fd5b610951915060203d602011610330576103228183611572565b5f610765565b6040513d8d823e3d90fd5b61096d8882516116ff565b6040850151604d81116109ab579061098891600a0a906116ff565b87156109975787900491610722565b634e487b7160e01b8a52601260045260248afd5b634e487b7160e01b8b52601160045260248bfd5b9050610717565b6001600160701b038087610702565b955093506060853d606011610a30575b816109f260609383611572565b81010312610a2c57610a03856116eb565b6040610a11602088016116eb565b96015163ffffffff811603610a285794935f6106e5565b8780fd5b8680fd5b3d91506109e5565b6040513d89823e3d90fd5b90925060a0813d60a011610af2575b81610a5f60a09383611572565b81010312610aee576040519060a0820182811067ffffffffffffffff821117610ada5760806004949392610acd92604052610a99816116c9565b8452610aa7602082016116c9565b602085015260408101516040850152610ac2606082016116dd565b6060850152016116dd565b6080820152929091610697565b634e487b7160e01b86526041600452602486fd5b8380fd5b3d9150610a52565b6390fe12ab60e01b8452600484fd5b630f9013db60e31b8452600484fd5b610b31915060203d602011610330576103228183611572565b5f610662565b6304026a8f60e11b8452600484fd5b610b5f915060203d602011610330576103228183611572565b5f610632565b8280fd5b5034610170578060031936011261017057546040516001600160a01b039091168152602090f35b50346101705780600319360112610170576002546040516001600160a01b039091168152602090f35b5034610170578060031936011261017057610bd2611743565b610bda611726565b610be2611726565b805460ff60a01b1916600160a01b1781556040513381527f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25890602090a180f35b50346101705780600319360112610170576001546040516001600160a01b039091168152602090f35b5034610170578060031936011261017057610c64611743565b80546001600160a01b03198116825581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b50346101705780610cb536611594565b610cbd611726565b610cc5611743565b6002546001600160a01b0316803b15610d2e57604080516301851c7d60e41b8152835161ffff16600482015260208401516024820152920151604483015282908290606490829084905af1801561092d57610d1d5750f35b81610d2791611572565b6101705780f35b5050fd5b50346101705760203660031901126101705760043567ffffffffffffffff8111610e2f5736602382011215610e2f578060040135610d6f816115cf565b91610d7d6040519384611572565b8183526024602084019260061b82010190368211610e8057602401915b818310610e4857505050610dac611769565b610db4611726565b610dbc611743565b815b8151811015610e335782610dd282846116a1565b51303b15610e2f57604051630cddc5b360e41b815281516001600160a01b031660048201526020909101516024820152818160448183305af1610e1a575b5050600101610dbe565b81610e2491611572565b610b6557825f610e10565b5080fd5b8260015f5160206118415f395f51905f525580f35b604083360312610e805760206040918251610e6281611556565b610e6b866115fd565b81528286013583820152815201920191610d9a565b8480fd5b503461017057806003193601126101705760ff6020915460a01c166040519015158152f35b50602036600319011261017057600435610ec1611726565b60015460405163ba0181af60e01b81523260048201526001600160a01b0390911690602081602481855afa908115610337578491611042575b50156103f35760206024916040519283809263fdd7ac6960e01b82523360048301525afa9081156103e8578391611023575b50156103ba5780156110145747808211610ffa5750600254604051634efd8ccb60e11b815230600482015260248101839052906020908290604490829087906001600160a01b03165af19081156103e8578391610fdb575b50610f8d575080f35b8180808084335af1610f9d61164a565b50610fa6575080f35b6040805133815260208101929092527fcb73d298683841a85d2bc59b28186adb96516a46c7dcf0dc4c9b7e5d4e55f73c91a180f35b610ff4915060203d602011610330576103228183611572565b5f610f84565b606492916305176aa160e21b835230600452602452604452fd5b6390fe12ab60e01b8252600482fd5b61103c915060203d602011610330576103228183611572565b5f610f2c565b61105b915060203d602011610330576103228183611572565b5f610efa565b503461017057806003193601126101705761107a611726565b611082611743565b60025481906001600160a01b0316803b156110bc5781809160046040518094819363b6549f7560e01b83525af1801561092d57610d1d5750f35b50fd5b50346101705780600319360112610170576110d8611743565b6110e0611822565b6110e8611822565b805460ff60a01b191681556040513381527f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa90602090a180f35b50346101705760203660031901126101705760043567ffffffffffffffff8111610e2f5736602382011215610e2f57806004013590611160826115cf565b9161116e6040519384611572565b8083526024602084019160051b83010191368311610e8057602401905b8282106113dd5750505061119d611726565b60015460405163ba0181af60e01b81523260048201526001600160a01b0390911690602081602481855afa9081156103375784916113be575b50156103f35760206024916040519283809263fdd7ac6960e01b82523360048301525afa9081156103e857839161139f575b50156103ba5760025482906001600160a01b0316803b15610e2f5781809160046040518094819363b6549f7560e01b83525af1801561092d5761138a575b505b81518110156113865760249060206001600160a01b0361126883866116a1565b5116604051938480926370a0823160e01b82523060048301525afa918215610337578492611353575b50816112a2575b6001915001611248565b6112f9916020816001600160a01b036112bb85886116a1565b51885460405163095ea7b360e01b81526001600160a01b03909116600482015260248101939093529195869291909116908290899082906044820190565b03925af19081156105835760019361133292611337575b50838060a01b0361132184876116a1565b5116848060a01b03875416906117a1565b611298565b61134e9060203d8111610330576103228183611572565b611310565b9091506020813d821161137e575b8161136e60209383611572565b8101031261039f5751905f611291565b3d9150611361565b8280f35b8161139491611572565b610e2f57815f611246565b6113b8915060203d602011610330576103228183611572565b5f611208565b6113d7915060203d602011610330576103228183611572565b5f6111d6565b602080916113ea846115fd565b81520191019061118b565b5060203660031901126101705760043561140d611769565b611415611726565b61141d611743565b801561101457818080808460018060a01b038254165af161143c61164a565b50611457575b5060015f5160206118415f395f51905f525580f35b7f17b49a4ef6d6967819bac7b307e1f8aa1e4adb66cf74f68d4173d15a795fe07e604060018060a01b03845416924782519182526020820152a25f611442565b503461039f576114a636611594565b6114ae611726565b6114b6611743565b6002546001600160a01b0316803b1561039f5760408051637c89966960e11b8152835161ffff1660048201526020840151602482015292015160448301525f908290606490829084905af1801561151b5761150f575080f35b61001891505f90611572565b6040513d5f823e3d90fd5b6060810190811067ffffffffffffffff82111761154257604052565b634e487b7160e01b5f52604160045260245ffd5b6040810190811067ffffffffffffffff82111761154257604052565b90601f8019910116810190811067ffffffffffffffff82111761154257604052565b606090600319011261039f576040516115ac81611526565b60043561ffff8116810361039f5781526024356020820152604435604082015290565b67ffffffffffffffff81116115425760051b60200190565b600435906001600160a01b038216820361039f57565b35906001600160a01b038216820361039f57565b604090600319011261039f576040519061162a82611556565b816004356001600160a01b038116810361039f5781526020602435910152565b3d15611684573d9067ffffffffffffffff82116115425760405191611679601f8201601f191660200184611572565b82523d5f602084013e565b606090565b9081602091031261039f5751801515810361039f5790565b80518210156116b55760209160051b010190565b634e487b7160e01b5f52603260045260245ffd5b51906001600160a01b038216820361039f57565b519060ff8216820361039f57565b51906001600160701b038216820361039f57565b8181029291811591840414171561171257565b634e487b7160e01b5f52601160045260245ffd5b60ff5f5460a01c1661173457565b63d93c066560e01b5f5260045ffd5b5f546001600160a01b0316330361175657565b63118cdaa760e01b5f523360045260245ffd5b60025f5160206118415f395f51905f5254146117925760025f5160206118415f395f51905f5255565b633ee5aeb560e01b5f5260045ffd5b916040519163a9059cbb60e01b5f5260018060a01b031660045260245260205f60448180865af19060015f5114821615611801575b604052156117e15750565b635274afe760e01b5f9081526001600160a01b0391909116600452602490fd5b90600181151661181957823b15153d151616906117d6565b503d5f823e3d90fd5b60ff5f5460a01c161561183157565b638dfc202b60e01b5f5260045ffdfe9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a264697066735822122021758d23f74aa87fb5f5c18cad6a8db8c5b8bc1ce2bb3ddc715b860aa2c4eae564736f6c634300081e0033000000000000000000000000dde266fa93635ad6506bedf4202ad0306a2e502a000000000000000000000000a01782e826c84bb3af9e11c4ea693166884d3b33000000000000000000000000eacddbcf1fdb627811135a2faa412cca203f087e000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

Deployed Bytecode

0x6080604052600436101561001a575b3615610018575f80fd5b005b5f5f3560e01c806311e78b121461149757806315f5254e146113f55780632b24f558146111225780633f4ba83a146110bf5780634debb5a8146110615780635ac7878a14610ea95780635c975abb14610e84578063602a87bb14610d325780636230c9d414610ca5578063715018a614610c4b5780638127b54f14610c225780638456cb5914610bb957806388c2efc514610b905780638da5cb5b14610b69578063b5d17c83146105ab578063cddc5b3014610421578063dfdacf8c146101735763f2fde38b146100eb575061000e565b34610170576020366003190112610170576101046115e7565b61010c611743565b6001600160a01b0316801561015c5781546001600160a01b03198116821783556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b631e4fbdf760e01b82526004829052602482fd5b80fd5b50346101705760403660031901126101705761018e36611611565b610196611726565b60015460405163ba0181af60e01b81523260048201526001600160a01b0390911690602081602481855afa908115610337578491610402575b50156103f35760206024916040519283809263fdd7ac6960e01b82523360048301525afa9081156103e85783916103c9575b50156103ba5760208101908151156103ab5780516040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa908115610337578491610375575b508251908082116103425750506002548251604051634efd8ccb60e11b81523060048201526024810191909152906020908290604490829088906001600160a01b03165af1908115610337578491610308575b506102a8578280f35b7f7141dc5542eadd36bf101b0051cc315334f4e0770d22db4ab0eb351c564c2e46916060916102e460018060a01b0382511683519033906117a1565b519051604080513381526001600160a01b039093166020840152820152a15f808280f35b61032a915060203d602011610330575b6103228183611572565b810190611689565b5f61029f565b503d610318565b6040513d86823e3d90fd5b60849260018060a01b039051169160405192633a1fa93b60e01b8452306004850152602484015260448301526064820152fd5b90506020813d6020116103a3575b8161039060209383611572565b8101031261039f57515f61024c565b5f80fd5b3d9150610383565b6390fe12ab60e01b8352600483fd5b630f9013db60e31b8252600482fd5b6103e2915060203d602011610330576103228183611572565b5f610201565b6040513d85823e3d90fd5b6304026a8f60e11b8352600483fd5b61041b915060203d602011610330576103228183611572565b5f6101cf565b50346101705760403660031901126101705761043c36611611565b610444611726565b61044c611743565b60208101908151156103ab5780518354835160405163095ea7b360e01b81526001600160a01b039283166004820152602481019190915291602091839160449183918991165af180156103375761058e575b508051835483516104bd9290916001600160a01b0390811691166117a1565b8254905191516040516370a0823160e01b81523060048201526001600160a01b039384169390921691602081602481875afa908115610583578591610531575b507fe2385497caa1b3a70f77d89029deb8e23d2a635cb49434291918d61a4ca22e3c9160409182519182526020820152a380f35b90506020813d60201161057b575b8161054c60209383611572565b8101031261039f57517fe2385497caa1b3a70f77d89029deb8e23d2a635cb49434291918d61a4ca22e3c6104fd565b3d915061053f565b6040513d87823e3d90fd5b6105a69060203d602011610330576103228183611572565b61049e565b503461017057606036600319011261017057604051906105ca82611526565b6105d26115e7565b8252602082016024358152604435908115158203610b6557604084019182526105f9611726565b60015460405163ba0181af60e01b81523260048201526001600160a01b0390911690602081602481855afa908115610583578591610b46575b5015610b375760405163fdd7ac6960e01b8152336004820152602081602481855afa908115610583578591610b18575b5015610b0957815115610afa579060a0600493926040519485809263ebfe259360e01b82525afa928315610337578493610a43575b5084516020840180518551604051630240bc6b60e21b81526001600160a01b03928316948316949094149693959493929160609187916004918391165afa938415610a3857879588956109d5575b50606083019360ff855116155f146109c6576001600160701b0380885b1697608086019760ff895116155f146109bf57505b169715610962578051915b600254604051638a1c027360e01b81523060048201526024810185905290602090829060449082908f906001600160a01b03165af1908115610957578b91610938575b5061076e578980f35b5115610871578880808085325af161078461164a565b90158061082a57505093604060ff9461016099979486947f48cca0a1da1051bb5fd74701e2a91c5bac463de75ee9c852ae1c4b35797fa22b9c9d9a985b519a518451328152602081019c909c528b8501919091526001600160a01b0390811660608c01528251811660808c015290511660a08a0152015160c0880152511660e08601525116610100840152610120830152610140820152a1805f80808080808080808980f35b60649060208c60405194859363add0f56d60e01b8552156004850152604060248501528051928391826044870152018585015e828201840152601f01601f19168101030190fd5b895160405163095ea7b360e01b815232600482015260248101849052999a9299919892979296929591949293928b916020908790604490829086906001600160a01b03165af193841561092d577f48cca0a1da1051bb5fd74701e2a91c5bac463de75ee9c852ae1c4b35797fa22b9b6101609b60ff98899760409650610910575b508b5161090b90839032906001600160a01b03166117a1565b6107c1565b6109289060203d602011610330576103228183611572565b6108f2565b6040513d84823e3d90fd5b610951915060203d602011610330576103228183611572565b5f610765565b6040513d8d823e3d90fd5b61096d8882516116ff565b6040850151604d81116109ab579061098891600a0a906116ff565b87156109975787900491610722565b634e487b7160e01b8a52601260045260248afd5b634e487b7160e01b8b52601160045260248bfd5b9050610717565b6001600160701b038087610702565b955093506060853d606011610a30575b816109f260609383611572565b81010312610a2c57610a03856116eb565b6040610a11602088016116eb565b96015163ffffffff811603610a285794935f6106e5565b8780fd5b8680fd5b3d91506109e5565b6040513d89823e3d90fd5b90925060a0813d60a011610af2575b81610a5f60a09383611572565b81010312610aee576040519060a0820182811067ffffffffffffffff821117610ada5760806004949392610acd92604052610a99816116c9565b8452610aa7602082016116c9565b602085015260408101516040850152610ac2606082016116dd565b6060850152016116dd565b6080820152929091610697565b634e487b7160e01b86526041600452602486fd5b8380fd5b3d9150610a52565b6390fe12ab60e01b8452600484fd5b630f9013db60e31b8452600484fd5b610b31915060203d602011610330576103228183611572565b5f610662565b6304026a8f60e11b8452600484fd5b610b5f915060203d602011610330576103228183611572565b5f610632565b8280fd5b5034610170578060031936011261017057546040516001600160a01b039091168152602090f35b50346101705780600319360112610170576002546040516001600160a01b039091168152602090f35b5034610170578060031936011261017057610bd2611743565b610bda611726565b610be2611726565b805460ff60a01b1916600160a01b1781556040513381527f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25890602090a180f35b50346101705780600319360112610170576001546040516001600160a01b039091168152602090f35b5034610170578060031936011261017057610c64611743565b80546001600160a01b03198116825581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b50346101705780610cb536611594565b610cbd611726565b610cc5611743565b6002546001600160a01b0316803b15610d2e57604080516301851c7d60e41b8152835161ffff16600482015260208401516024820152920151604483015282908290606490829084905af1801561092d57610d1d5750f35b81610d2791611572565b6101705780f35b5050fd5b50346101705760203660031901126101705760043567ffffffffffffffff8111610e2f5736602382011215610e2f578060040135610d6f816115cf565b91610d7d6040519384611572565b8183526024602084019260061b82010190368211610e8057602401915b818310610e4857505050610dac611769565b610db4611726565b610dbc611743565b815b8151811015610e335782610dd282846116a1565b51303b15610e2f57604051630cddc5b360e41b815281516001600160a01b031660048201526020909101516024820152818160448183305af1610e1a575b5050600101610dbe565b81610e2491611572565b610b6557825f610e10565b5080fd5b8260015f5160206118415f395f51905f525580f35b604083360312610e805760206040918251610e6281611556565b610e6b866115fd565b81528286013583820152815201920191610d9a565b8480fd5b503461017057806003193601126101705760ff6020915460a01c166040519015158152f35b50602036600319011261017057600435610ec1611726565b60015460405163ba0181af60e01b81523260048201526001600160a01b0390911690602081602481855afa908115610337578491611042575b50156103f35760206024916040519283809263fdd7ac6960e01b82523360048301525afa9081156103e8578391611023575b50156103ba5780156110145747808211610ffa5750600254604051634efd8ccb60e11b815230600482015260248101839052906020908290604490829087906001600160a01b03165af19081156103e8578391610fdb575b50610f8d575080f35b8180808084335af1610f9d61164a565b50610fa6575080f35b6040805133815260208101929092527fcb73d298683841a85d2bc59b28186adb96516a46c7dcf0dc4c9b7e5d4e55f73c91a180f35b610ff4915060203d602011610330576103228183611572565b5f610f84565b606492916305176aa160e21b835230600452602452604452fd5b6390fe12ab60e01b8252600482fd5b61103c915060203d602011610330576103228183611572565b5f610f2c565b61105b915060203d602011610330576103228183611572565b5f610efa565b503461017057806003193601126101705761107a611726565b611082611743565b60025481906001600160a01b0316803b156110bc5781809160046040518094819363b6549f7560e01b83525af1801561092d57610d1d5750f35b50fd5b50346101705780600319360112610170576110d8611743565b6110e0611822565b6110e8611822565b805460ff60a01b191681556040513381527f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa90602090a180f35b50346101705760203660031901126101705760043567ffffffffffffffff8111610e2f5736602382011215610e2f57806004013590611160826115cf565b9161116e6040519384611572565b8083526024602084019160051b83010191368311610e8057602401905b8282106113dd5750505061119d611726565b60015460405163ba0181af60e01b81523260048201526001600160a01b0390911690602081602481855afa9081156103375784916113be575b50156103f35760206024916040519283809263fdd7ac6960e01b82523360048301525afa9081156103e857839161139f575b50156103ba5760025482906001600160a01b0316803b15610e2f5781809160046040518094819363b6549f7560e01b83525af1801561092d5761138a575b505b81518110156113865760249060206001600160a01b0361126883866116a1565b5116604051938480926370a0823160e01b82523060048301525afa918215610337578492611353575b50816112a2575b6001915001611248565b6112f9916020816001600160a01b036112bb85886116a1565b51885460405163095ea7b360e01b81526001600160a01b03909116600482015260248101939093529195869291909116908290899082906044820190565b03925af19081156105835760019361133292611337575b50838060a01b0361132184876116a1565b5116848060a01b03875416906117a1565b611298565b61134e9060203d8111610330576103228183611572565b611310565b9091506020813d821161137e575b8161136e60209383611572565b8101031261039f5751905f611291565b3d9150611361565b8280f35b8161139491611572565b610e2f57815f611246565b6113b8915060203d602011610330576103228183611572565b5f611208565b6113d7915060203d602011610330576103228183611572565b5f6111d6565b602080916113ea846115fd565b81520191019061118b565b5060203660031901126101705760043561140d611769565b611415611726565b61141d611743565b801561101457818080808460018060a01b038254165af161143c61164a565b50611457575b5060015f5160206118415f395f51905f525580f35b7f17b49a4ef6d6967819bac7b307e1f8aa1e4adb66cf74f68d4173d15a795fe07e604060018060a01b03845416924782519182526020820152a25f611442565b503461039f576114a636611594565b6114ae611726565b6114b6611743565b6002546001600160a01b0316803b1561039f5760408051637c89966960e11b8152835161ffff1660048201526020840151602482015292015160448301525f908290606490829084905af1801561151b5761150f575080f35b61001891505f90611572565b6040513d5f823e3d90fd5b6060810190811067ffffffffffffffff82111761154257604052565b634e487b7160e01b5f52604160045260245ffd5b6040810190811067ffffffffffffffff82111761154257604052565b90601f8019910116810190811067ffffffffffffffff82111761154257604052565b606090600319011261039f576040516115ac81611526565b60043561ffff8116810361039f5781526024356020820152604435604082015290565b67ffffffffffffffff81116115425760051b60200190565b600435906001600160a01b038216820361039f57565b35906001600160a01b038216820361039f57565b604090600319011261039f576040519061162a82611556565b816004356001600160a01b038116810361039f5781526020602435910152565b3d15611684573d9067ffffffffffffffff82116115425760405191611679601f8201601f191660200184611572565b82523d5f602084013e565b606090565b9081602091031261039f5751801515810361039f5790565b80518210156116b55760209160051b010190565b634e487b7160e01b5f52603260045260245ffd5b51906001600160a01b038216820361039f57565b519060ff8216820361039f57565b51906001600160701b038216820361039f57565b8181029291811591840414171561171257565b634e487b7160e01b5f52601160045260245ffd5b60ff5f5460a01c1661173457565b63d93c066560e01b5f5260045ffd5b5f546001600160a01b0316330361175657565b63118cdaa760e01b5f523360045260245ffd5b60025f5160206118415f395f51905f5254146117925760025f5160206118415f395f51905f5255565b633ee5aeb560e01b5f5260045ffd5b916040519163a9059cbb60e01b5f5260018060a01b031660045260245260205f60448180865af19060015f5114821615611801575b604052156117e15750565b635274afe760e01b5f9081526001600160a01b0391909116600452602490fd5b90600181151661181957823b15153d151616906117d6565b503d5f823e3d90fd5b60ff5f5460a01c161561183157565b638dfc202b60e01b5f5260045ffdfe9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a264697066735822122021758d23f74aa87fb5f5c18cad6a8db8c5b8bc1ce2bb3ddc715b860aa2c4eae564736f6c634300081e0033

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.