Sepolia Testnet

Contract

0x4e86c7F59162b5FCb6c20Bc4E82296dCe49feD00

Overview

ETH Balance

0.999985 ETH

Multichain Info

N/A
Transaction Hash
Method
Block
From
To
Start Ping Pong59232822024-05-17 20:13:24207 days ago1715976804IN
0x4e86c7F5...Ce49feD00
0 ETH0.002704913.32951175
Start Ping Pong59232812024-05-17 20:13:12207 days ago1715976792IN
0x4e86c7F5...Ce49feD00
0 ETH0.0028189613.89159058
Start Ping Pong59232812024-05-17 20:13:12207 days ago1715976792IN
0x4e86c7F5...Ce49feD00
0 ETH0.0028189613.89159058
Start Ping Pong59232802024-05-17 20:13:00207 days ago1715976780IN
0x4e86c7F5...Ce49feD00
0 ETH0.0025932212.77914436
Start Ping Pong59221452024-05-17 16:03:24207 days ago1715961804IN
0x4e86c7F5...Ce49feD00
0 ETH0.03451478170.08557403
Start Ping Pong59221442024-05-17 16:03:12207 days ago1715961792IN
0x4e86c7F5...Ce49feD00
0 ETH0.03448113169.91976898
Start Ping Pong59221432024-05-17 16:03:00207 days ago1715961780IN
0x4e86c7F5...Ce49feD00
0 ETH0.0337588166.36016867
Start Ping Pong59035482024-05-14 21:14:36210 days ago1715721276IN
0x4e86c7F5...Ce49feD00
0 ETH0.003921919.32677187
Transfer59026702024-05-14 17:59:00210 days ago1715709540IN
0x4e86c7F5...Ce49feD00
1 ETH0.001171755.64980204
Add Interchain C...58962192024-05-13 18:55:00211 days ago1715626500IN
0x4e86c7F5...Ce49feD00
0 ETH0.0084988585.48438698
Set Execution Se...58962192024-05-13 18:55:00211 days ago1715626500IN
0x4e86c7F5...Ce49feD00
0 ETH0.0040534185.48438698
Set App Config V...58962192024-05-13 18:55:00211 days ago1715626500IN
0x4e86c7F5...Ce49feD00
0 ETH0.0041085585.48438698
Add Trusted Modu...58962192024-05-13 18:55:00211 days ago1715626500IN
0x4e86c7F5...Ce49feD00
0 ETH0.007877385.48438698
Link Remote App ...58962192024-05-13 18:55:00211 days ago1715626500IN
0x4e86c7F5...Ce49feD00
0 ETH0.0041139385.48438698

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
60137032024-05-31 16:58:12193 days ago1717174692
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59965482024-05-28 22:26:36196 days ago1716935196
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59965462024-05-28 22:26:12196 days ago1716935172
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59965372024-05-28 22:24:24196 days ago1716935064
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59965352024-05-28 22:24:00196 days ago1716935040
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59965332024-05-28 22:23:36196 days ago1716935016
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59965302024-05-28 22:23:00196 days ago1716934980
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59233052024-05-17 20:18:12207 days ago1715977092
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59233032024-05-17 20:17:48207 days ago1715977068
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59232942024-05-17 20:15:48207 days ago1715976948
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59232922024-05-17 20:15:24207 days ago1715976924
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59232862024-05-17 20:14:12207 days ago1715976852
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59232822024-05-17 20:13:24207 days ago1715976804
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59232812024-05-17 20:13:12207 days ago1715976792
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59232812024-05-17 20:13:12207 days ago1715976792
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59232802024-05-17 20:13:00207 days ago1715976780
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59221682024-05-17 16:08:12207 days ago1715962092
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59221632024-05-17 16:07:12207 days ago1715962032
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59221482024-05-17 16:04:00207 days ago1715961840
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59221452024-05-17 16:03:24207 days ago1715961804
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59221442024-05-17 16:03:12207 days ago1715961792
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59221432024-05-17 16:03:00207 days ago1715961780
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59035562024-05-14 21:16:12210 days ago1715721372
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59035482024-05-14 21:14:36210 days ago1715721276
0x4e86c7F5...Ce49feD00
0.0000006 ETH
59026922024-05-14 18:04:36210 days ago1715709876
0x4e86c7F5...Ce49feD00
0.0000006 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
PingPongApp

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 24 : PingPongApp.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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

import {APP_CONFIG_GUARD_DEFAULT} from "../../libs/AppConfig.sol";
import {InterchainTxDescriptor} from "../../libs/InterchainTransaction.sol";
import {OptionsV1} from "../../libs/Options.sol";

import {Address} from "@openzeppelin/contracts/utils/Address.sol";

/// @notice A simple app that sends a message to the remote PingPongApp, which will respond with a message back.
/// This app can be loaded with a native asset, which will be used to pay for the messages sent.
contract PingPongApp is ICAppV1 {
    uint256 internal constant DEFAULT_GAS_LIMIT = 500_000;
    uint256 public gasLimit;

    event GasLimitSet(uint256 gasLimit);
    event PingDisrupted(uint256 counter);
    event PingReceived(uint256 counter, uint64 dbNonce);
    event PingSent(uint256 counter, uint64 dbNonce);

    constructor(address admin) ICAppV1(admin) {
        _grantRole(IC_GOVERNOR_ROLE, admin);
        _setGasLimit(DEFAULT_GAS_LIMIT);
    }

    /// @notice Enables the contract to accept native asset.
    receive() external payable {}

    /// @notice Allows the Interchain Governor to set the gas limit for the interchain messages.
    function setGasLimit(uint256 gasLimit_) external onlyRole(IC_GOVERNOR_ROLE) {
        _setGasLimit(gasLimit_);
    }

    /// @notice Allows the Admin to withdraw the native asset from the contract.
    function withdraw() external onlyRole(DEFAULT_ADMIN_ROLE) {
        Address.sendValue(payable(msg.sender), address(this).balance);
    }

    /// @notice Starts the ping-pong message exchange with the remote PingPongApp.
    function startPingPong(uint64 dstChainId, uint256 counter) external {
        // Revert if the balance is lower than the message fee.
        _sendPingPongMessage(dstChainId, counter, true);
    }

    /// @notice Returns the fee to send a single ping message to the remote PingPongApp.
    function getPingFee(uint64 dstChainId) external view returns (uint256) {
        OptionsV1 memory options = OptionsV1({gasLimit: gasLimit, gasAirdrop: 0});
        bytes memory message = abi.encode(uint256(0));
        return _getInterchainFee(dstChainId, options.encodeOptionsV1(), message.length);
    }

    /// @dev Internal logic for receiving messages. At this point the validity of the message is already checked.
    function _receiveMessage(
        uint64 srcChainId,
        bytes32, // sender
        uint64 dbNonce,
        bytes calldata message
    )
        internal
        override
    {
        uint256 counter = abi.decode(message, (uint256));
        emit PingReceived(counter, dbNonce);
        if (counter > 0) {
            // Don't revert if the balance is low, just stop sending messages.
            _sendPingPongMessage({dstChainId: srcChainId, counter: counter - 1, lowBalanceRevert: false});
        }
    }

    /// @dev Sends a message to the PingPongApp on the remote chain.
    /// If `counter > 0`, the remote app will respond with a message to this app, decrementing the counter.
    /// Once the counter reaches 0, the remote app will not respond.
    function _sendPingPongMessage(uint64 dstChainId, uint256 counter, bool lowBalanceRevert) internal {
        OptionsV1 memory options = OptionsV1({gasLimit: gasLimit, gasAirdrop: 0});
        bytes memory message = abi.encode(counter);
        uint256 messageFee = _getMessageFee(dstChainId, options, message.length);
        if (address(this).balance < messageFee && !lowBalanceRevert) {
            emit PingDisrupted(counter);
            return;
        }
        InterchainTxDescriptor memory desc = _sendToLinkedApp(dstChainId, messageFee, options, message);
        emit PingSent(counter, desc.dbNonce);
    }

    /// @dev Sets the gas limit for the interchain messages.
    function _setGasLimit(uint256 gasLimit_) internal {
        gasLimit = gasLimit_;
        emit GasLimitSet(gasLimit_);
    }

    /// @dev Returns the guard flag and address in the app config.
    /// By default, the ICApp does not opt in for any guard, but it can be overridden in the derived contracts.
    /// PingPong app opts in for the default guard.
    function _getGuardConfig() internal pure override returns (uint8 guardFlag, address guard) {
        return (APP_CONFIG_GUARD_DEFAULT, address(0));
    }
}

File 2 of 24 : ICAppV1.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {AbstractICApp, InterchainTxDescriptor} from "./AbstractICApp.sol";

import {InterchainAppV1Events} from "../events/InterchainAppV1Events.sol";
import {IInterchainAppV1} from "../interfaces/IInterchainAppV1.sol";
import {AppConfigV1, APP_CONFIG_GUARD_DISABLED} from "../libs/AppConfig.sol";
import {OptionsV1} from "../libs/Options.sol";
import {TypeCasts} from "../libs/TypeCasts.sol";

import {AccessControlEnumerable} from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";

abstract contract ICAppV1 is AbstractICApp, AccessControlEnumerable, InterchainAppV1Events, IInterchainAppV1 {
    using EnumerableSet for EnumerableSet.AddressSet;
    using TypeCasts for address;
    using TypeCasts for bytes32;

    /// @notice Role to manage the Interchain setup of the app.
    bytes32 public constant IC_GOVERNOR_ROLE = keccak256("IC_GOVERNOR_ROLE");

    /// @dev Address of the latest Interchain Client, used for sending messages.
    /// Note: packed in a single storage slot with the `_requiredResponses` and `_optimisticSeconds`.
    address private _latestClient;
    /// @dev Required responses and optimistic period for the module responses.
    uint8 private _requiredResponses;
    uint48 private _optimisticSeconds;

    /// @dev Address of the linked app deployed on the remote chain.
    mapping(uint64 chainId => bytes32 remoteApp) private _linkedApp;
    /// @dev Interchain Clients allowed to send messages to this app.
    EnumerableSet.AddressSet private _interchainClients;
    /// @dev Trusted Interchain modules.
    EnumerableSet.AddressSet private _trustedModules;
    /// @dev Execution Service to use for sending messages.
    address private _executionService;

    constructor(address admin) {
        _grantRole(DEFAULT_ADMIN_ROLE, admin);
    }

    /// @notice Allows the governor to add the interchain client to the allowed clients set,
    /// and optionally set the latest client to this one.
    /// Note: only the allowed clients can send messages to this app.
    /// Note: the latest client is used for sending messages from this app.
    /// @param client       The address of the interchain client to add.
    /// @param updateLatest Whether to set the latest client to this one.
    function addInterchainClient(address client, bool updateLatest) external onlyRole(IC_GOVERNOR_ROLE) {
        _addClient(client, updateLatest);
    }

    /// @notice Allows the governor to remove the interchain client from the allowed clients set.
    /// If the client is the latest client, the latest client is set to the zero address.
    /// @param client       The address of the interchain client to remove.
    function removeInterchainClient(address client) external onlyRole(IC_GOVERNOR_ROLE) {
        _removeClient(client);
    }

    /// @notice Allows the governor to set the address of the latest interchain client.
    /// @dev The new latest client must be an allowed client or zero address.
    /// Setting the client to zero address effectively pauses the app ability to send messages,
    /// while allowing to receive them.
    /// @param client       The address of the latest interchain client.
    function setLatestInterchainClient(address client) external onlyRole(IC_GOVERNOR_ROLE) {
        _setLatestClient(client);
    }

    /// @notice Allows the governor to link the remote app for the given chain ID.
    /// - This address will be used as the receiver for the messages sent from this chain.
    /// - This address will be the only trusted sender for the messages sent to this chain.
    /// @param chainId      The remote chain ID.
    /// @param remoteApp    The address of the remote app to link.
    function linkRemoteApp(uint64 chainId, bytes32 remoteApp) external onlyRole(IC_GOVERNOR_ROLE) {
        _linkRemoteApp(chainId, remoteApp);
    }

    /// @notice Thin wrapper for `linkRemoteApp` to accept EVM address as a parameter.
    function linkRemoteAppEVM(uint64 chainId, address remoteApp) external onlyRole(IC_GOVERNOR_ROLE) {
        _linkRemoteApp(chainId, remoteApp.addressToBytes32());
    }

    /// @notice Allows the governor to add the module to the trusted modules set.
    /// - This set of modules will be used to verify both sent and received messages.
    function addTrustedModule(address module) external onlyRole(IC_GOVERNOR_ROLE) {
        if (module == address(0)) {
            revert InterchainApp__ModuleZeroAddress();
        }
        bool added = _trustedModules.add(module);
        if (!added) {
            revert InterchainApp__ModuleAlreadyAdded(module);
        }
        emit TrustedModuleAdded(module);
    }

    /// @notice Allows the governor to remove the module from the trusted modules set.
    function removeTrustedModule(address module) external onlyRole(IC_GOVERNOR_ROLE) {
        bool removed = _trustedModules.remove(module);
        if (!removed) {
            revert InterchainApp__ModuleNotAdded(module);
        }
        emit TrustedModuleRemoved(module);
    }

    /// @notice Allows the governor to set the app config for the current app. App config includes:
    /// - requiredResponses: the number of module responses required for accepting the message
    /// - optimisticSeconds: the minimum time after which the module responses are considered final
    function setAppConfigV1(uint256 requiredResponses, uint256 optimisticSeconds) external onlyRole(IC_GOVERNOR_ROLE) {
        if (requiredResponses == 0) {
            revert InterchainApp__AppConfigInvalid(requiredResponses, optimisticSeconds);
        }
        _requiredResponses = SafeCast.toUint8(requiredResponses);
        _optimisticSeconds = SafeCast.toUint48(optimisticSeconds);
        emit AppConfigV1Set(requiredResponses, optimisticSeconds);
    }

    /// @notice Allows the governor to set the address of the Execution Service.
    /// This address will be used to request execution of the messages sent from this chain,
    /// by supplying the Service's execution fee.
    function setExecutionService(address executionService) external onlyRole(IC_GOVERNOR_ROLE) {
        _executionService = executionService;
        emit ExecutionServiceSet(executionService);
    }

    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════

    /// @notice Returns the app config for the current app:
    /// - requiredResponses: the number of module responses required for accepting the message
    /// - optimisticSeconds: the minimum time after which the module responses are considered final
    /// - guardFlag: the flag indicating the guard type (0 - none, 1 - client's default, 2 - custom)
    /// - guard: the address of the guard contract (if the guardFlag is set to 2)
    function getAppConfigV1() public view returns (AppConfigV1 memory) {
        (uint8 guardFlag, address guard) = _getGuardConfig();
        return AppConfigV1({
            requiredResponses: _requiredResponses,
            optimisticSeconds: _optimisticSeconds,
            guardFlag: guardFlag,
            guard: guard
        });
    }

    /// @notice Returns the address of the Execution Service used by this app for sending messages.
    // solhint-disable-next-line ordering
    function getExecutionService() external view returns (address) {
        return _executionService;
    }

    /// @notice Returns the list of Interchain Clients allowed to send messages to this app.
    function getInterchainClients() external view returns (address[] memory) {
        return _interchainClients.values();
    }

    /// @notice Returns the address of the latest interchain client.
    /// This address is used for sending messages from this app.
    function getLatestInterchainClient() external view returns (address) {
        return _latestClient;
    }

    /// @notice Returns the linked app address (as bytes32) for the given chain ID.
    function getLinkedApp(uint64 chainId) external view returns (bytes32) {
        return _linkedApp[chainId];
    }

    /// @notice Thin wrapper for `getLinkedApp` to return the linked app address as EVM address.
    /// @dev Will revert if the linked app address is not an EVM address.
    function getLinkedAppEVM(uint64 chainId) external view returns (address linkedAppEVM) {
        bytes32 linkedApp = _linkedApp[chainId];
        linkedAppEVM = linkedApp.bytes32ToAddress();
        if (linkedAppEVM.addressToBytes32() != linkedApp) {
            revert InterchainApp__LinkedAppNotEVM(linkedApp);
        }
    }

    /// @notice Returns the list of Interchain Modules trusted by this app.
    /// This set of modules will be used to verify both sent and received messages.
    function getModules() external view returns (address[] memory) {
        return _trustedModules.values();
    }

    // ═══════════════════════════════════════════ INTERNAL: MANAGEMENT ════════════════════════════════════════════════

    /// @dev Links the remote app to the current app.
    /// Will revert if the chainId is the same as the chainId of the local app.
    /// Note: Should be guarded with permissions check.
    function _linkRemoteApp(uint64 chainId, bytes32 remoteApp) internal {
        if (chainId == block.chainid) {
            revert InterchainApp__ChainIdNotRemote(chainId);
        }
        if (remoteApp == 0) {
            revert InterchainApp__RemoteAppZeroAddress();
        }
        _linkedApp[chainId] = remoteApp;
        emit AppLinked(chainId, remoteApp);
    }

    /// @dev Stores the address of the latest Interchain Client.
    /// - The exact storage location is up to the implementation.
    /// - Must NOT be called directly: use `_setLatestClient` instead.
    /// - Should not emit any events: this is done in the calling function.
    function _storeLatestClient(address client) internal override {
        _latestClient = client;
    }

    /// @dev Toggle the state of the Interchain Client (allowed/disallowed to send messages to this app).
    /// - The client is checked to be in the opposite state before the change.
    /// - The exact storage location is up to the implementation.
    /// - Must NOT be called directly: use `_addClient` and `_removeClient` instead.
    /// - Should not emit any events: this is done in the calling functions.
    function _toggleClientState(address client, bool allowed) internal override {
        if (allowed) {
            _interchainClients.add(client);
        } else {
            _interchainClients.remove(client);
        }
    }

    // ════════════════════════════════════════════ INTERNAL: MESSAGING ════════════════════════════════════════════════

    /// @dev Thin wrapper around _sendInterchainMessage to send the message to the linked app.
    function _sendToLinkedApp(
        uint64 dstChainId,
        uint256 messageFee,
        OptionsV1 memory options,
        bytes memory message
    )
        internal
        returns (InterchainTxDescriptor memory)
    {
        bytes memory encodedOptions = options.encodeOptionsV1();
        return _sendInterchainMessage(dstChainId, _linkedApp[dstChainId], messageFee, encodedOptions, message);
    }

    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════

    /// @dev Returns the fee to send a message to the linked app on the remote chain.
    function _getMessageFee(
        uint64 dstChainId,
        OptionsV1 memory options,
        uint256 messageLen
    )
        internal
        view
        returns (uint256)
    {
        bytes memory encodedOptions = options.encodeOptionsV1();
        return _getInterchainFee(dstChainId, encodedOptions, messageLen);
    }

    /// @dev Returns the configuration of the app for validating the received messages.
    function _getAppConfig() internal view override returns (bytes memory) {
        return getAppConfigV1().encodeAppConfigV1();
    }

    /// @dev Returns the guard flag and address in the app config.
    /// By default, the ICApp does not opt in for any guard, but it can be overridden in the derived contracts.
    function _getGuardConfig() internal view virtual returns (uint8 guardFlag, address guard) {
        return (APP_CONFIG_GUARD_DISABLED, address(0));
    }

    /// @dev Returns the address of the Execution Service to use for sending messages.
    function _getExecutionService() internal view override returns (address) {
        return _executionService;
    }

    /// @dev Returns the latest Interchain Client. This is the Client that is used for sending messages.
    function _getLatestClient() internal view override returns (address) {
        return _latestClient;
    }

    /// @dev Returns the list of modules to use for sending messages, as well as validating the received messages.
    function _getModules() internal view override returns (address[] memory) {
        return _trustedModules.values();
    }

    /// @dev Checks if the sender is allowed to send messages to this app.
    function _isAllowedSender(uint64 srcChainId, bytes32 sender) internal view override returns (bool) {
        return _linkedApp[srcChainId] == sender;
    }

    /// @dev Checks if the caller is an Interchain Client.
    /// Both latest and legacy Interchain Clients are allowed to call `appReceive`.
    function _isInterchainClient(address caller) internal view override returns (bool) {
        return _interchainClients.contains(caller);
    }
}

File 3 of 24 : AppConfig.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {VersionedPayloadLib} from "./VersionedPayload.sol";

struct AppConfigV1 {
    uint8 requiredResponses;
    uint48 optimisticSeconds;
    uint8 guardFlag;
    address guard;
}

using AppConfigLib for AppConfigV1 global;

/// @dev Signals that the app opted out of using any Guard module.
uint8 constant APP_CONFIG_GUARD_DISABLED = 0;
/// @dev Signals that the app uses the default Guard module provided by InterchainClient contract.
uint8 constant APP_CONFIG_GUARD_DEFAULT = 1;
/// @dev Signals that the app uses a custom Guard module.
uint8 constant APP_CONFIG_GUARD_CUSTOM = 2;

library AppConfigLib {
    using VersionedPayloadLib for bytes;

    uint16 internal constant APP_CONFIG_V1 = 1;

    error AppConfigLib__VersionInvalid(uint16 version);

    /// @notice Decodes app config (V1 or higher) from a bytes format back into an AppConfigV1 struct.
    /// @param data         The app config data in bytes format.
    function decodeAppConfigV1(bytes memory data) internal view returns (AppConfigV1 memory) {
        uint16 version = data.getVersionFromMemory();
        if (version < APP_CONFIG_V1) {
            revert AppConfigLib__VersionInvalid(version);
        }
        // Structs of the same version will always be decoded correctly.
        // Following versions will be decoded correctly if they have the same fields as the previous version,
        // and new fields at the end: abi.decode ignores the extra bytes in the decoded payload.
        return abi.decode(data.getPayloadFromMemory(), (AppConfigV1));
    }

    /// @notice Encodes V1 app config into a bytes format.
    /// @param appConfig    The AppConfigV1 to encode.
    function encodeAppConfigV1(AppConfigV1 memory appConfig) internal pure returns (bytes memory) {
        return VersionedPayloadLib.encodeVersionedPayload(APP_CONFIG_V1, abi.encode(appConfig));
    }
}

File 4 of 24 : InterchainTransaction.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {MathLib} from "./Math.sol";
import {TypeCasts} from "./TypeCasts.sol";
import {VersionedPayloadLib} from "./VersionedPayload.sol";

import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";

type ICTxHeader is uint256;

struct InterchainTransaction {
    uint64 srcChainId;
    uint64 dstChainId;
    uint64 dbNonce;
    bytes32 srcSender;
    bytes32 dstReceiver;
    bytes options;
    bytes message;
}

struct InterchainTxDescriptor {
    bytes32 transactionId;
    uint64 dbNonce;
}

using InterchainTransactionLib for InterchainTransaction global;

library InterchainTransactionLib {
    using MathLib for uint256;
    using VersionedPayloadLib for bytes;

    function constructLocalTransaction(
        address srcSender,
        uint64 dstChainId,
        bytes32 dstReceiver,
        uint64 dbNonce,
        bytes memory options,
        bytes memory message
    )
        internal
        view
        returns (InterchainTransaction memory transaction)
    {
        return InterchainTransaction({
            srcChainId: SafeCast.toUint64(block.chainid),
            srcSender: TypeCasts.addressToBytes32(srcSender),
            dstChainId: dstChainId,
            dstReceiver: dstReceiver,
            dbNonce: dbNonce,
            options: options,
            message: message
        });
    }

    function encodeTransaction(InterchainTransaction memory transaction) internal pure returns (bytes memory) {
        return abi.encode(
            encodeTxHeader(transaction.srcChainId, transaction.dstChainId, transaction.dbNonce),
            transaction.srcSender,
            transaction.dstReceiver,
            transaction.options,
            transaction.message
        );
    }

    function decodeTransaction(bytes calldata transaction) internal pure returns (InterchainTransaction memory icTx) {
        ICTxHeader header;
        (header, icTx.srcSender, icTx.dstReceiver, icTx.options, icTx.message) =
            abi.decode(transaction, (ICTxHeader, bytes32, bytes32, bytes, bytes));
        (icTx.srcChainId, icTx.dstChainId, icTx.dbNonce) = decodeTxHeader(header);
    }

    function payloadSize(uint256 optionsLen, uint256 messageLen) internal pure returns (uint256) {
        // 2 bytes are reserved for the transaction version
        // + 5 fields * 32 bytes (3 values for static, 2 offsets for dynamic) + 2 * 32 bytes (lengths for dynamic) = 226
        // (srcChainId, dstChainId, dbNonce) are merged into a single 32 bytes field
        // Both options and message are dynamic fields, which are padded up to 32 bytes
        return 226 + optionsLen.roundUpToWord() + messageLen.roundUpToWord();
    }

    function encodeTxHeader(uint64 srcChainId, uint64 dstChainId, uint64 dbNonce) internal pure returns (ICTxHeader) {
        return ICTxHeader.wrap((uint256(srcChainId) << 128) | (uint256(dstChainId) << 64) | (uint256(dbNonce)));
    }

    function decodeTxHeader(ICTxHeader header)
        internal
        pure
        returns (uint64 srcChainId, uint64 dstChainId, uint64 dbNonce)
    {
        srcChainId = uint64(ICTxHeader.unwrap(header) >> 128);
        dstChainId = uint64(ICTxHeader.unwrap(header) >> 64);
        dbNonce = uint64(ICTxHeader.unwrap(header));
    }
}

File 5 of 24 : Options.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {VersionedPayloadLib} from "./VersionedPayload.sol";

/// @notice Struct to hold V1 of options data.
/// @dev Next versions have to use the fields from the previous version and add new fields at the end.
/// @param gasLimit The gas limit for the transaction.
/// @param gasAirdrop The amount of gas to airdrop.
struct OptionsV1 {
    uint256 gasLimit;
    uint256 gasAirdrop;
}

using OptionsLib for OptionsV1 global;

/// @title OptionsLib
/// @notice A library for encoding and decoding Interchain options related to interchain messages.
library OptionsLib {
    using VersionedPayloadLib for bytes;

    uint16 internal constant OPTIONS_V1 = 1;

    error OptionsLib__VersionInvalid(uint16 version);

    /// @notice Decodes options (V1 or higher) from a bytes format back into an OptionsV1 struct.
    /// @param data         The options data in bytes format.
    function decodeOptionsV1(bytes memory data) internal view returns (OptionsV1 memory) {
        uint16 version = data.getVersionFromMemory();
        if (version < OPTIONS_V1) {
            revert OptionsLib__VersionInvalid(version);
        }
        // Structs of the same version will always be decoded correctly.
        // Following versions will be decoded correctly if they have the same fields as the previous version,
        // and new fields at the end: abi.decode ignores the extra bytes in the decoded payload.
        return abi.decode(data.getPayloadFromMemory(), (OptionsV1));
    }

    /// @notice Encodes V1 options into a bytes format.
    /// @param options      The OptionsV1 to encode.
    function encodeOptionsV1(OptionsV1 memory options) internal pure returns (bytes memory) {
        return VersionedPayloadLib.encodeVersionedPayload(OPTIONS_V1, abi.encode(options));
    }
}

File 6 of 24 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}

File 7 of 24 : AbstractICApp.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {AbstractICAppEvents} from "../events/AbstractICAppEvents.sol";

import {IInterchainApp} from "../interfaces/IInterchainApp.sol";
import {IInterchainClientV1} from "../interfaces/IInterchainClientV1.sol";

import {InterchainTxDescriptor} from "../libs/InterchainTransaction.sol";
import {TypeCasts} from "../libs/TypeCasts.sol";

abstract contract AbstractICApp is AbstractICAppEvents, IInterchainApp {
    using TypeCasts for address;

    error InterchainApp__BalanceBelowMin(uint256 balance, uint256 minRequired);
    error InterchainApp__CallerNotInterchainClient(address caller);
    error InterchainApp__ChainIdNotRemote(uint64 chainId);
    error InterchainApp__InterchainClientAlreadyAdded(address client);
    error InterchainApp__InterchainClientAlreadyLatest(address client);
    error InterchainApp__InterchainClientZeroAddress();
    error InterchainApp__ReceiverZeroAddress(uint64 chainId);
    error InterchainApp__SrcSenderNotAllowed(uint64 srcChainId, bytes32 sender);

    /// @notice Allows the Interchain Client to pass the message to the Interchain App.
    /// @dev App is responsible for keeping track of interchain clients, and must verify the message sender.
    /// @param srcChainId   Chain ID of the source chain, where the message was sent from.
    /// @param sender       Sender address on the source chain, as a bytes32 value.
    /// @param dbNonce      The Interchain DB nonce of the message entry.
    /// @param message      The message being sent.
    function appReceive(uint64 srcChainId, bytes32 sender, uint64 dbNonce, bytes calldata message) external payable {
        if (!_isInterchainClient(msg.sender)) {
            revert InterchainApp__CallerNotInterchainClient(msg.sender);
        }
        if (srcChainId == block.chainid) {
            revert InterchainApp__ChainIdNotRemote(srcChainId);
        }
        if (!_isAllowedSender(srcChainId, sender)) {
            revert InterchainApp__SrcSenderNotAllowed(srcChainId, sender);
        }
        _receiveMessage(srcChainId, sender, dbNonce, message);
    }

    /// @notice Returns the verification configuration of the Interchain App.
    /// @dev This configuration is used by the Interchain Client to verify that message has been confirmed
    /// by the Interchain Modules on the destination chain.
    /// Note: V1 version of AppConfig includes the required responses count, and optimistic period after which
    /// the message is considered confirmed by the module. Following versions may include additional fields.
    /// @return appConfig    The versioned configuration of the Interchain App, encoded as bytes.
    /// @return modules      The list of Interchain Modules that app is trusting to confirm the messages.
    function getReceivingConfig() external view returns (bytes memory appConfig, address[] memory modules) {
        appConfig = _getAppConfig();
        modules = _getModules();
    }

    // ═══════════════════════════════════════════ INTERNAL: MANAGEMENT ════════════════════════════════════════════════

    /// @dev Performs necessary checks and adds an Interchain Client.
    /// Optionally sets the latest client to this one.
    /// Note: should be guarded with permission checks in the derived contracts.
    function _addClient(address client, bool updateLatest) internal {
        if (client == address(0)) {
            revert InterchainApp__InterchainClientZeroAddress();
        }
        if (_isInterchainClient(client)) {
            revert InterchainApp__InterchainClientAlreadyAdded(client);
        }
        _toggleClientState(client, true);
        emit InterchainClientAdded(client);
        if (updateLatest) {
            _setLatestClient(client);
        }
    }

    /// @dev Performs necessary checks and removes an Interchain Client. If this client is the latest one,
    /// the latest client is set to zero address (effectively pausing the app ability to send messages).
    /// Note: should be guarded with permission checks in the derived contracts.
    function _removeClient(address client) internal {
        if (!_isInterchainClient(client)) {
            revert InterchainApp__CallerNotInterchainClient(client);
        }
        _toggleClientState(client, false);
        emit InterchainClientRemoved(client);
        if (client == _getLatestClient()) {
            _setLatestClient(address(0));
        }
    }

    /// @dev Sets the latest Interchain Client to one of the allowed clients. Setting the client to zero address
    /// is allowed and effectively pauses the app ability to send messages (but still allows to receive them).
    /// Note: should be guarded with permission checks in the derived contracts.
    function _setLatestClient(address client) internal {
        // New latest client must be an allowed client or zero address.
        if (!_isInterchainClient(client) && client != address(0)) {
            revert InterchainApp__CallerNotInterchainClient(client);
        }
        if (client == _getLatestClient()) {
            revert InterchainApp__InterchainClientAlreadyLatest(client);
        }
        _storeLatestClient(client);
        emit LatestClientSet(client);
    }

    /// @dev Stores the address of the latest Interchain Client.
    /// - The exact storage location is up to the implementation.
    /// - Must NOT be called directly: use `_setLatestClient` instead.
    /// - Should not emit any events: this is done in the calling function.
    function _storeLatestClient(address client) internal virtual;

    /// @dev Toggle the state of the Interchain Client (allowed/disallowed to send messages to this app).
    /// - The client is checked to be in the opposite state before the change.
    /// - The exact storage location is up to the implementation.
    /// - Must NOT be called directly: use `_addClient` and `_removeClient` instead.
    /// - Should not emit any events: this is done in the calling functions.
    function _toggleClientState(address client, bool allowed) internal virtual;

    // ════════════════════════════════════════════ INTERNAL: MESSAGING ════════════════════════════════════════════════

    /// @dev Thin wrapper around _sendInterchainMessage to accept EVM address as a parameter.
    function _sendInterchainMessageEVM(
        uint64 dstChainId,
        address receiver,
        uint256 messageFee,
        bytes memory options,
        bytes memory message
    )
        internal
        returns (InterchainTxDescriptor memory desc)
    {
        return _sendInterchainMessage(dstChainId, receiver.addressToBytes32(), messageFee, options, message);
    }

    /// @dev Performs necessary checks and sends an interchain message.
    function _sendInterchainMessage(
        uint64 dstChainId,
        bytes32 receiver,
        uint256 messageFee,
        bytes memory options,
        bytes memory message
    )
        internal
        returns (InterchainTxDescriptor memory desc)
    {
        address client = _getLatestClient();
        if (client == address(0)) {
            revert InterchainApp__InterchainClientZeroAddress();
        }
        if (dstChainId == block.chainid) {
            revert InterchainApp__ChainIdNotRemote(dstChainId);
        }
        if (receiver == 0) {
            revert InterchainApp__ReceiverZeroAddress(dstChainId);
        }
        if (address(this).balance < messageFee) {
            revert InterchainApp__BalanceBelowMin({balance: address(this).balance, minRequired: messageFee});
        }
        return IInterchainClientV1(client).interchainSend{value: messageFee}(
            dstChainId, receiver, _getExecutionService(), _getModules(), options, message
        );
    }

    /// @dev Internal logic for receiving messages. At this point the validity of the message is already checked.
    function _receiveMessage(
        uint64 srcChainId,
        bytes32 sender,
        uint64 dbNonce,
        bytes calldata message
    )
        internal
        virtual;

    // ══════════════════════════════════════════════ INTERNAL VIEWS ═══════════════════════════════════════════════════

    /// @dev Returns the fee for sending an Interchain message.
    function _getInterchainFee(
        uint64 dstChainId,
        bytes memory options,
        uint256 messageLen
    )
        internal
        view
        returns (uint256)
    {
        address client = _getLatestClient();
        if (client == address(0)) {
            revert InterchainApp__InterchainClientZeroAddress();
        }
        return IInterchainClientV1(client).getInterchainFee(
            dstChainId, _getExecutionService(), _getModules(), options, messageLen
        );
    }

    /// @dev Returns the configuration of the app for validating the received messages.
    function _getAppConfig() internal view virtual returns (bytes memory);

    /// @dev Returns the address of the Execution Service to use for sending messages.
    function _getExecutionService() internal view virtual returns (address);

    /// @dev Returns the latest Interchain Client. This is the Client that is used for sending messages.
    function _getLatestClient() internal view virtual returns (address);

    /// @dev Returns the list of modules to use for sending messages, as well as validating the received messages.
    function _getModules() internal view virtual returns (address[] memory);

    /// @dev Checks if the sender is allowed to send messages to this app.
    function _isAllowedSender(uint64 srcChainId, bytes32 sender) internal view virtual returns (bool);

    /// @dev Checks if the caller is an Interchain Client.
    /// Both latest and legacy Interchain Clients are allowed to call `appReceive`.
    function _isInterchainClient(address caller) internal view virtual returns (bool);
}

File 8 of 24 : InterchainAppV1Events.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

abstract contract InterchainAppV1Events {
    /// @notice Emitted when the app configuration V1 is set.
    /// The V1 version of app config requests at least N confirmations that are at least T seconds old
    /// from trusted modules to execute a transaction.
    /// @param requiredResponses    The number of module responses required for a transaction to be executed.
    /// @param optimisticSeconds     The time period after which a module response is considered final.
    event AppConfigV1Set(uint256 requiredResponses, uint256 optimisticSeconds);

    /// @notice Emitted when a remote instance of the app is linked.
    /// This instance is the only one that can send messages to this app from the remote chain.
    /// @param chainId              The remote chain ID.
    /// @param remoteApp            The address of the remote app on that chain.
    event AppLinked(uint64 chainId, bytes32 remoteApp);

    /// @notice Emitted when the execution service is set.
    /// This service will be used for requesting the execution of transactions on the remote chain.
    /// @param executionService     The address of the execution service.
    event ExecutionServiceSet(address executionService);

    /// @notice Emitted when a trusted module is added.
    /// The trusted modules will be used to verify the messages coming from the remote chains,
    /// as well as request the verification of the sent messages on the remote chains.
    /// @param module               The address of the trusted module that was added.
    event TrustedModuleAdded(address module);

    /// @notice Emitted when a trusted module is removed.
    /// @param module               The address of the trusted module that was removed.
    event TrustedModuleRemoved(address module);
}

File 9 of 24 : IInterchainAppV1.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {AppConfigV1} from "../libs/AppConfig.sol";

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

interface IInterchainAppV1 is IInterchainApp {
    error InterchainApp__AppConfigInvalid(uint256 requiredResponses, uint256 optimisticSeconds);
    error InterchainApp__LinkedAppNotEVM(bytes32 linkedApp);
    error InterchainApp__ModuleAlreadyAdded(address module);
    error InterchainApp__ModuleNotAdded(address module);
    error InterchainApp__ModuleZeroAddress();
    error InterchainApp__RemoteAppZeroAddress();

    function addInterchainClient(address client, bool updateLatest) external;
    function removeInterchainClient(address client) external;
    function setLatestInterchainClient(address client) external;

    function linkRemoteApp(uint64 chainId, bytes32 remoteApp) external;
    function linkRemoteAppEVM(uint64 chainId, address remoteApp) external;

    function addTrustedModule(address module) external;
    function removeTrustedModule(address module) external;
    function setAppConfigV1(uint256 requiredResponses, uint256 optimisticSeconds) external;
    function setExecutionService(address executionService) external;

    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════

    function getAppConfigV1() external view returns (AppConfigV1 memory);
    function getExecutionService() external view returns (address);
    function getInterchainClients() external view returns (address[] memory);
    function getLatestInterchainClient() external view returns (address);
    function getLinkedApp(uint64 chainId) external view returns (bytes32);
    function getLinkedAppEVM(uint64 chainId) external view returns (address);
    function getModules() external view returns (address[] memory);
}

File 10 of 24 : TypeCasts.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

library TypeCasts {
    function addressToBytes32(address addr) internal pure returns (bytes32) {
        return bytes32(uint256(uint160(addr)));
    }

    function bytes32ToAddress(bytes32 b) internal pure returns (address) {
        return address(uint160(uint256(b)));
    }
}

File 11 of 24 : AccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/AccessControlEnumerable.sol)

pragma solidity ^0.8.20;

import {IAccessControlEnumerable} from "./IAccessControlEnumerable.sol";
import {AccessControl} from "../AccessControl.sol";
import {EnumerableSet} from "../../utils/structs/EnumerableSet.sol";

/**
 * @dev Extension of {AccessControl} that allows enumerating the members of each role.
 */
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
    using EnumerableSet for EnumerableSet.AddressSet;

    mapping(bytes32 role => EnumerableSet.AddressSet) private _roleMembers;

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view virtual returns (address) {
        return _roleMembers[role].at(index);
    }

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view virtual returns (uint256) {
        return _roleMembers[role].length();
    }

    /**
     * @dev Overload {AccessControl-_grantRole} to track enumerable memberships
     */
    function _grantRole(bytes32 role, address account) internal virtual override returns (bool) {
        bool granted = super._grantRole(role, account);
        if (granted) {
            _roleMembers[role].add(account);
        }
        return granted;
    }

    /**
     * @dev Overload {AccessControl-_revokeRole} to track enumerable memberships
     */
    function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) {
        bool revoked = super._revokeRole(role, account);
        if (revoked) {
            _roleMembers[role].remove(account);
        }
        return revoked;
    }
}

File 12 of 24 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position is the index of the value in the `values` array plus 1.
        // Position 0 is used to mean a value is not in the set.
        mapping(bytes32 value => uint256) _positions;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._positions[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We cache the value's position to prevent multiple reads from the same storage slot
        uint256 position = set._positions[value];

        if (position != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 valueIndex = position - 1;
            uint256 lastIndex = set._values.length - 1;

            if (valueIndex != lastIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the lastValue to the index where the value to delete is
                set._values[valueIndex] = lastValue;
                // Update the tracked position of the lastValue (that was just moved)
                set._positions[lastValue] = position;
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the tracked position for the deleted slot
            delete set._positions[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._positions[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 13 of 24 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.20;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

    /**
     * @dev An int value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedIntToUint(int256 value);

    /**
     * @dev Value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);

    /**
     * @dev An uint value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedUintToInt(uint256 value);

    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(248, value);
        }
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(240, value);
        }
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(232, value);
        }
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(224, value);
        }
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(216, value);
        }
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(208, value);
        }
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(200, value);
        }
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(192, value);
        }
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(184, value);
        }
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(176, value);
        }
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(168, value);
        }
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(160, value);
        }
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(152, value);
        }
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(144, value);
        }
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(136, value);
        }
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(128, value);
        }
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(120, value);
        }
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(112, value);
        }
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(104, value);
        }
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(96, value);
        }
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(88, value);
        }
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(80, value);
        }
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(72, value);
        }
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(64, value);
        }
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(56, value);
        }
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(48, value);
        }
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(40, value);
        }
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(32, value);
        }
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(24, value);
        }
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(16, value);
        }
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(8, value);
        }
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        if (value > uint256(type(int256).max)) {
            revert SafeCastOverflowedUintToInt(value);
        }
        return int256(value);
    }
}

File 14 of 24 : VersionedPayload.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

// solhint-disable no-inline-assembly
// solhint-disable ordering
library VersionedPayloadLib {
    /// @notice Amount of bytes reserved for the version (uint16) in the versioned payload
    uint256 internal constant VERSION_LENGTH = 2;

    error VersionedPayload__PayloadTooShort(bytes versionedPayload);
    error VersionedPayload__PrecompileFailed();

    /// @notice Encodes the versioned payload into a single bytes array.
    /// @param version  The payload's version.
    /// @param payload  The payload to encode.
    function encodeVersionedPayload(uint16 version, bytes memory payload) internal pure returns (bytes memory) {
        return abi.encodePacked(version, payload);
    }

    /// @notice Extracts the version from the versioned payload (calldata reference).
    /// @param versionedPayload     The versioned payload (calldata reference).
    function getVersion(bytes calldata versionedPayload) internal pure returns (uint16 version) {
        if (versionedPayload.length < VERSION_LENGTH) {
            revert VersionedPayload__PayloadTooShort(versionedPayload);
        }
        assembly {
            // We are only interested in the highest 16 bits of the loaded full 32 bytes word.
            version := shr(240, calldataload(versionedPayload.offset))
        }
    }

    /// @notice Extracts the payload from the versioned payload (calldata reference).
    /// @dev The extracted payload is also returned as a calldata reference.
    /// @param versionedPayload     The versioned payload.
    function getPayload(bytes calldata versionedPayload) internal pure returns (bytes calldata) {
        if (versionedPayload.length < VERSION_LENGTH) {
            revert VersionedPayload__PayloadTooShort(versionedPayload);
        }
        return versionedPayload[VERSION_LENGTH:];
    }

    /// @notice Extracts the version from the versioned payload (memory reference).
    /// @param versionedPayload     The versioned payload (memory reference).
    function getVersionFromMemory(bytes memory versionedPayload) internal pure returns (uint16 version) {
        if (versionedPayload.length < VERSION_LENGTH) {
            revert VersionedPayload__PayloadTooShort(versionedPayload);
        }
        assembly {
            // We are only interested in the highest 16 bits of the loaded full 32 bytes word.
            // We add 0x20 to skip the length of the bytes array.
            version := shr(240, mload(add(versionedPayload, 0x20)))
        }
    }

    /// @notice Extracts the payload from the versioned payload (memory reference).
    /// @dev The extracted payload is copied into a new memory location. Use `getPayload` when possible
    /// to avoid extra memory allocation.
    /// @param versionedPayload     The versioned payload (memory reference).
    function getPayloadFromMemory(bytes memory versionedPayload) internal view returns (bytes memory payload) {
        if (versionedPayload.length < VERSION_LENGTH) {
            revert VersionedPayload__PayloadTooShort(versionedPayload);
        }
        // Figure how many bytes to copy and allocate the memory for the extracted payload.
        uint256 toCopy;
        unchecked {
            toCopy = versionedPayload.length - VERSION_LENGTH;
        }
        payload = new bytes(toCopy);
        // Use identity precompile (0x04) to copy the payload. Unlike MCOPY, this is available on all EVM chains.
        bool res;
        assembly {
            // We add 0x20 to skip the length of the bytes array.
            // We add 0x02 to skip the 2 bytes reserved for the version.
            // Copy the payload to the previously allocated memory.
            res := staticcall(gas(), 0x04, add(versionedPayload, 0x22), toCopy, add(payload, 0x20), toCopy)
        }
        if (!res) {
            revert VersionedPayload__PrecompileFailed();
        }
    }
}

File 15 of 24 : Math.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

library MathLib {
    /// @notice Rounds up to the nearest multiple of 32.
    /// Note: Returns zero on overflows instead of reverting. This is fine for practical
    /// use cases, as this is used for determining the size of the payload in memory.
    function roundUpToWord(uint256 x) internal pure returns (uint256) {
        unchecked {
            return (x + 31) & ~uint256(31);
        }
    }
}

File 16 of 24 : AbstractICAppEvents.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

abstract contract AbstractICAppEvents {
    /// @notice Emitted when a new interchain client is added.
    /// This client will be able to send messages to the app.
    /// @param client   The address of the client.
    event InterchainClientAdded(address client);

    /// @notice Emitted when an interchain client is removed.
    /// @param client   The address of the client.
    event InterchainClientRemoved(address client);

    /// @notice Emitted when the latest interchain client is set.
    /// This client will be used by the app to send messages.
    /// @param client   The address of the client.
    event LatestClientSet(address client);
}

File 17 of 24 : IInterchainApp.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @notice Minimal interface for the Interchain App to work with the Interchain Client.
interface IInterchainApp {
    function appReceive(uint64 srcChainId, bytes32 sender, uint64 dbNonce, bytes calldata message) external payable;

    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════

    function getReceivingConfig() external view returns (bytes memory appConfig, address[] memory modules);
}

File 18 of 24 : IInterchainClientV1.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {InterchainTransaction, InterchainTxDescriptor} from "../libs/InterchainTransaction.sol";

interface IInterchainClientV1 {
    enum TxReadiness {
        Ready,
        AlreadyExecuted,
        EntryAwaitingResponses,
        EntryConflict,
        ReceiverNotICApp,
        TxWrongDstChainId,
        UndeterminedRevert
    }

    error InterchainClientV1__ChainIdNotLinked(uint64 chainId);
    error InterchainClientV1__ChainIdNotRemote(uint64 chainId);
    error InterchainClientV1__DstChainIdNotLocal(uint64 chainId);
    error InterchainClientV1__EntryConflict(address module);
    error InterchainClientV1__ExecutionServiceZeroAddress();
    error InterchainClientV1__FeeAmountBelowMin(uint256 feeAmount, uint256 minRequired);
    error InterchainClientV1__GasLeftBelowMin(uint256 gasLeft, uint256 minRequired);
    error InterchainClientV1__GuardZeroAddress();
    error InterchainClientV1__LinkedClientNotEVM(bytes32 client);
    error InterchainClientV1__ModuleZeroAddress();
    error InterchainClientV1__MsgValueMismatch(uint256 msgValue, uint256 required);
    error InterchainClientV1__ReceiverNotICApp(address receiver);
    error InterchainClientV1__ReceiverZeroAddress();
    error InterchainClientV1__ResponsesAmountBelowMin(uint256 responsesAmount, uint256 minRequired);
    error InterchainClientV1__TxAlreadyExecuted(bytes32 transactionId);
    error InterchainClientV1__TxNotExecuted(bytes32 transactionId);
    error InterchainClientV1__TxVersionMismatch(uint16 txVersion, uint16 required);

    function setDefaultGuard(address guard) external;
    function setDefaultModule(address module) external;
    function setLinkedClient(uint64 chainId, bytes32 client) external;

    function interchainSend(
        uint64 dstChainId,
        bytes32 receiver,
        address srcExecutionService,
        address[] calldata srcModules,
        bytes calldata options,
        bytes calldata message
    )
        external
        payable
        returns (InterchainTxDescriptor memory desc);

    function interchainSendEVM(
        uint64 dstChainId,
        address receiver,
        address srcExecutionService,
        address[] calldata srcModules,
        bytes calldata options,
        bytes calldata message
    )
        external
        payable
        returns (InterchainTxDescriptor memory desc);

    function interchainExecute(uint256 gasLimit, bytes calldata transaction) external payable;

    function writeExecutionProof(bytes32 transactionId) external returns (uint64 dbNonce);

    // ═══════════════════════════════════════════════════ VIEWS ═══════════════════════════════════════════════════════

    function isExecutable(bytes calldata transaction) external view returns (bool);
    function getTxReadinessV1(InterchainTransaction memory icTx)
        external
        view
        returns (TxReadiness status, bytes32 firstArg, bytes32 secondArg);

    function getInterchainFee(
        uint64 dstChainId,
        address srcExecutionService,
        address[] calldata srcModules,
        bytes calldata options,
        uint256 messageLen
    )
        external
        view
        returns (uint256);

    function getExecutor(bytes calldata transaction) external view returns (address);
    function getExecutorById(bytes32 transactionId) external view returns (address);
    function getLinkedClient(uint64 chainId) external view returns (bytes32);
    function getLinkedClientEVM(uint64 chainId) external view returns (address);
}

File 19 of 24 : IAccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/IAccessControlEnumerable.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
 */
interface IAccessControlEnumerable is IAccessControl {
    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}

File 20 of 24 : AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    mapping(bytes32 role => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual returns (bool) {
        return _roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        if (!hasRole(role, account)) {
            _roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        if (hasRole(role, account)) {
            _roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}

File 21 of 24 : IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)

pragma solidity ^0.8.20;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}

File 22 of 24 : Context.sol
// 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;
    }
}

File 23 of 24 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 24 of 24 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * 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[EIP 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/=node_modules/@openzeppelin/",
    "@synapsecns/=node_modules/@synapsecns/",
    "forge-std/=node_modules/forge-std/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "viaIR": false,
  "libraries": {}
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"admin","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[{"internalType":"uint256","name":"requiredResponses","type":"uint256"},{"internalType":"uint256","name":"optimisticSeconds","type":"uint256"}],"name":"InterchainApp__AppConfigInvalid","type":"error"},{"inputs":[{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"minRequired","type":"uint256"}],"name":"InterchainApp__BalanceBelowMin","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"InterchainApp__CallerNotInterchainClient","type":"error"},{"inputs":[{"internalType":"uint64","name":"chainId","type":"uint64"}],"name":"InterchainApp__ChainIdNotRemote","type":"error"},{"inputs":[{"internalType":"address","name":"client","type":"address"}],"name":"InterchainApp__InterchainClientAlreadyAdded","type":"error"},{"inputs":[{"internalType":"address","name":"client","type":"address"}],"name":"InterchainApp__InterchainClientAlreadyLatest","type":"error"},{"inputs":[],"name":"InterchainApp__InterchainClientZeroAddress","type":"error"},{"inputs":[{"internalType":"bytes32","name":"linkedApp","type":"bytes32"}],"name":"InterchainApp__LinkedAppNotEVM","type":"error"},{"inputs":[{"internalType":"address","name":"module","type":"address"}],"name":"InterchainApp__ModuleAlreadyAdded","type":"error"},{"inputs":[{"internalType":"address","name":"module","type":"address"}],"name":"InterchainApp__ModuleNotAdded","type":"error"},{"inputs":[],"name":"InterchainApp__ModuleZeroAddress","type":"error"},{"inputs":[{"internalType":"uint64","name":"chainId","type":"uint64"}],"name":"InterchainApp__ReceiverZeroAddress","type":"error"},{"inputs":[],"name":"InterchainApp__RemoteAppZeroAddress","type":"error"},{"inputs":[{"internalType":"uint64","name":"srcChainId","type":"uint64"},{"internalType":"bytes32","name":"sender","type":"bytes32"}],"name":"InterchainApp__SrcSenderNotAllowed","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"requiredResponses","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"optimisticSeconds","type":"uint256"}],"name":"AppConfigV1Set","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"chainId","type":"uint64"},{"indexed":false,"internalType":"bytes32","name":"remoteApp","type":"bytes32"}],"name":"AppLinked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"executionService","type":"address"}],"name":"ExecutionServiceSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"gasLimit","type":"uint256"}],"name":"GasLimitSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"client","type":"address"}],"name":"InterchainClientAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"client","type":"address"}],"name":"InterchainClientRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"client","type":"address"}],"name":"LatestClientSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"counter","type":"uint256"}],"name":"PingDisrupted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"counter","type":"uint256"},{"indexed":false,"internalType":"uint64","name":"dbNonce","type":"uint64"}],"name":"PingReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"counter","type":"uint256"},{"indexed":false,"internalType":"uint64","name":"dbNonce","type":"uint64"}],"name":"PingSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"module","type":"address"}],"name":"TrustedModuleAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"module","type":"address"}],"name":"TrustedModuleRemoved","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"IC_GOVERNOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"client","type":"address"},{"internalType":"bool","name":"updateLatest","type":"bool"}],"name":"addInterchainClient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"module","type":"address"}],"name":"addTrustedModule","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"srcChainId","type":"uint64"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"dbNonce","type":"uint64"},{"internalType":"bytes","name":"message","type":"bytes"}],"name":"appReceive","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"gasLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getAppConfigV1","outputs":[{"components":[{"internalType":"uint8","name":"requiredResponses","type":"uint8"},{"internalType":"uint48","name":"optimisticSeconds","type":"uint48"},{"internalType":"uint8","name":"guardFlag","type":"uint8"},{"internalType":"address","name":"guard","type":"address"}],"internalType":"struct AppConfigV1","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getExecutionService","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getInterchainClients","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLatestInterchainClient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"chainId","type":"uint64"}],"name":"getLinkedApp","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"chainId","type":"uint64"}],"name":"getLinkedAppEVM","outputs":[{"internalType":"address","name":"linkedAppEVM","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getModules","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"dstChainId","type":"uint64"}],"name":"getPingFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getReceivingConfig","outputs":[{"internalType":"bytes","name":"appConfig","type":"bytes"},{"internalType":"address[]","name":"modules","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"chainId","type":"uint64"},{"internalType":"bytes32","name":"remoteApp","type":"bytes32"}],"name":"linkRemoteApp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"chainId","type":"uint64"},{"internalType":"address","name":"remoteApp","type":"address"}],"name":"linkRemoteAppEVM","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"client","type":"address"}],"name":"removeInterchainClient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"module","type":"address"}],"name":"removeTrustedModule","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"requiredResponses","type":"uint256"},{"internalType":"uint256","name":"optimisticSeconds","type":"uint256"}],"name":"setAppConfigV1","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"executionService","type":"address"}],"name":"setExecutionService","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"gasLimit_","type":"uint256"}],"name":"setGasLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"client","type":"address"}],"name":"setLatestInterchainClient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"dstChainId","type":"uint64"},{"internalType":"uint256","name":"counter","type":"uint256"}],"name":"startPingPong","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60806040523480156200001157600080fd5b506040516200216738038062002167833981016040819052620000349162000207565b806200004260008262000087565b506200007190507f67458b9c8206fd7556afadce1bc8e28c7a8942ecb92d9d9fad69bb6c8cf75c848262000087565b50620000806207a120620000c4565b5062000232565b600080620000968484620000ff565b90508015620000bb576000848152600160205260409020620000b99084620001ad565b505b90505b92915050565b60098190556040518181527f336210500e2973a38a8d7b3f978ac5bf874a3326119f3dff68651e472a1ae7729060200160405180910390a150565b6000828152602081815260408083206001600160a01b038516845290915281205460ff16620001a4576000838152602081815260408083206001600160a01b03861684529091529020805460ff191660011790556200015b3390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a4506001620000be565b506000620000be565b6000620000bb836001600160a01b0384166000818152600183016020526040812054620001a457508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155620000be565b6000602082840312156200021a57600080fd5b81516001600160a01b0381168114620000bb57600080fd5b611f2580620002426000396000f3fe6080604052600436106101f25760003560e01c806390a92c161161010d578063ca15c873116100a0578063ed5ec8901161006f578063ed5ec890146105b8578063ee7d72b4146105d8578063f22ba23d146105f8578063f68016b714610618578063f6b266fd1461062e57600080fd5b8063ca15c87314610538578063cb5038fb14610558578063d547741f14610578578063eb53b44e1461059857600080fd5b8063b2494df3116100dc578063b2494df3146104c7578063b70c40b3146104dc578063bc0d912c146104fc578063c313c8071461051a57600080fd5b806390a92c161461045057806391d1485414610470578063a1aa5d6814610490578063a217fddf146104b257600080fd5b8063287bc05711610185578063496774b111610154578063496774b1146103a05780634e6427e7146103c05780637717a647146103f65780639010d07c1461041857600080fd5b8063287bc057146103285780632f2ff15d1461034b57806336568abe1461036b5780633ccfd60b1461038b57600080fd5b80631856ddfe116101c15780631856ddfe146102885780631c489e4f146102a85780631ec46e95146102d8578063248a9ca3146102f857600080fd5b806301ffc9a7146101fe5780630421a1f0146102335780630fb591561461024857806317d262861461026857600080fd5b366101f957005b600080fd5b34801561020a57600080fd5b5061021e6102193660046119d8565b61064e565b60405190151581526020015b60405180910390f35b610246610241366004611a17565b610679565b005b34801561025457600080fd5b50610246610263366004611ad1565b610738565b34801561027457600080fd5b50610246610283366004611aec565b61075d565b34801561029457600080fd5b506102466102a3366004611b18565b610769565b3480156102b457600080fd5b506102ca600080516020611ed083398151915281565b60405190815260200161022a565b3480156102e457600080fd5b506102466102f3366004611b4d565b610799565b34801561030457600080fd5b506102ca610313366004611b6f565b60009081526020819052604090206001015490565b34801561033457600080fd5b5061033d610870565b60405161022a929190611c1d565b34801561035757600080fd5b50610246610366366004611c42565b61088b565b34801561037757600080fd5b50610246610386366004611c42565b6108b6565b34801561039757600080fd5b506102466108e9565b3480156103ac57600080fd5b506102466103bb366004611ad1565b610901565b3480156103cc57600080fd5b506102ca6103db366004611c65565b6001600160401b031660009081526003602052604090205490565b34801561040257600080fd5b5061040b61096f565b60405161022a9190611c82565b34801561042457600080fd5b50610438610433366004611b4d565b6109d1565b6040516001600160a01b03909116815260200161022a565b34801561045c57600080fd5b5061043861046b366004611c65565b6109f0565b34801561047c57600080fd5b5061021e61048b366004611c42565b610a3c565b34801561049c57600080fd5b506104a5610a65565b60405161022a9190611cc6565b3480156104be57600080fd5b506102ca600081565b3480156104d357600080fd5b506104a5610a76565b3480156104e857600080fd5b506102466104f7366004611ad1565b610a82565b34801561050857600080fd5b506002546001600160a01b0316610438565b34801561052657600080fd5b506008546001600160a01b0316610438565b34801561054457600080fd5b506102ca610553366004611b6f565b610b0b565b34801561056457600080fd5b50610246610573366004611ad1565b610b22565b34801561058457600080fd5b50610246610593366004611c42565b610bd2565b3480156105a457600080fd5b506102466105b3366004611ad1565b610bf7565b3480156105c457600080fd5b506102ca6105d3366004611c65565b610c18565b3480156105e457600080fd5b506102466105f3366004611b6f565b610c64565b34801561060457600080fd5b50610246610613366004611cd9565b610c85565b34801561062457600080fd5b506102ca60095481565b34801561063a57600080fd5b50610246610649366004611aec565b610ca7565b60006001600160e01b03198216635a05180f60e01b1480610673575061067382610cc9565b92915050565b61068233610cfe565b6106a657604051633e336bbb60e01b81523360048201526024015b60405180910390fd5b46856001600160401b0316036106da57604051632c262dc960e11b81526001600160401b038616600482015260240161069d565b6001600160401b0385166000908152600360205260409020548414610724576040516377df34df60e01b81526001600160401b03861660048201526024810185905260440161069d565b6107318585858585610d0b565b5050505050565b600080516020611ed083398151915261075081610d81565b61075982610d8b565b5050565b61075982826001610e31565b600080516020611ed083398151915261078181610d81565b610794836001600160a01b038416610f38565b505050565b600080516020611ed08339815191526107b181610d81565b826000036107dc57604051636f2b4c2f60e11b8152600481018490526024810183905260440161069d565b6107e583610fdf565b600260146101000a81548160ff021916908360ff16021790555061080882611011565b6002805465ffffffffffff92909216600160a81b0265ffffffffffff60a81b1990921691909117905560408051848152602081018490527f156e53f21add5e964d33e39e015675e24d4568202b47744bd8cc6080f76deabf91015b60405180910390a1505050565b60608061087b611044565b9150610885610a76565b90509091565b6000828152602081905260409020600101546108a681610d81565b6108b08383611056565b50505050565b6001600160a01b03811633146108df5760405163334bd91960e11b815260040160405180910390fd5b610794828261108b565b60006108f481610d81565b6108fe33476110b8565b50565b600080516020611ed083398151915261091981610d81565b600880546001600160a01b0319166001600160a01b0384169081179091556040519081527f56f2046f579030345e1c12cfd7e2d297e4059c24d30ac1a5cb27a8ee1d53526e906020015b60405180910390a15050565b604080516080808201835260008083526020808401829052838501829052606093840182905284519283018552600254600160a01b810460ff168452600160a81b900465ffffffffffff16908301526001938201939093529081019190915290565b60008281526001602052604081206109e9908361114f565b9392505050565b6001600160401b038116600090815260036020526040902054806001600160a01b0381168114610a36576040516382a4102b60e01b81526004810182905260240161069d565b50919050565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6060610a71600461115b565b905090565b6060610a71600661115b565b600080516020611ed0833981519152610a9a81610d81565b6000610aa7600684611168565b905080610ad257604051635895247360e11b81526001600160a01b038416600482015260240161069d565b6040516001600160a01b03841681527f91071153b5721fdadecd5ab74cedca9c0faa62c94f02ef659df224160269838590602001610863565b60008181526001602052604081206106739061117d565b600080516020611ed0833981519152610b3a81610d81565b6001600160a01b038216610b6157604051635467061760e11b815260040160405180910390fd5b6000610b6e600684611187565b905080610b995760405163215b8e2b60e21b81526001600160a01b038416600482015260240161069d565b6040516001600160a01b03841681527f0f92a0308a1fb283891a96a4cf077b8499cca0159d8e6ccc8d12096a5011750990602001610863565b600082815260208190526040902060010154610bed81610d81565b6108b0838361108b565b600080516020611ed0833981519152610c0f81610d81565b6107598261119c565b604080518082018252600954815260006020808301829052835180820183905284518082039092018252840190935291610c5c84610c5584611286565b83516112c4565b949350505050565b600080516020611ed0833981519152610c7c81610d81565b61075982611398565b600080516020611ed0833981519152610c9d81610d81565b61079483836113cd565b600080516020611ed0833981519152610cbf81610d81565b6107948383610f38565b60006001600160e01b03198216637965db0b60e01b148061067357506301ffc9a760e01b6001600160e01b0319831614610673565b600061067360048361147c565b6000610d1982840184611b6f565b604080518281526001600160401b03871660208201529192507fc3d24d80f3729a777c08ca6b879a4a162aa5e25c4744c55841b1558c38c0233e910160405180910390a18015610d7957610d7986610d72600184611d15565b6000610e31565b505050505050565b6108fe813361149e565b610d9481610cfe565b610dbc57604051633e336bbb60e01b81526001600160a01b038216600482015260240161069d565b610dc78160006114d7565b6040516001600160a01b03821681527fc0d64f9e088893f1e4aea6d42c0e815f158ca62962029260f3c2b079d97feccc9060200160405180910390a16002546001600160a01b03166001600160a01b0316816001600160a01b0316036108fe576108fe600061119c565b60006040518060400160405280600954815260200160008152509050600083604051602001610e6291815260200190565b60405160208183030381529060405290506000610e81868484516114f3565b90508047108015610e90575083155b15610ed0576040518581527ff83d5148c4e705c82778f8aed1bb387ea5a8c0046cd647c807b70d65932210c29060200160405180910390a1505050505050565b6000610ede8783868661150c565b90507ff49ca760b7c158bf7657b69ea354b3c05e11991cc8688298400f98764aee2299868260200151604051610f279291909182526001600160401b0316602082015260400190565b60405180910390a150505050505050565b46826001600160401b031603610f6c57604051632c262dc960e11b81526001600160401b038316600482015260240161069d565b6000819003610f8e5760405163a72ac69d60e01b815260040160405180910390fd5b6001600160401b038216600081815260036020908152604091829020849055815192835282018390527f8991328923b5fe27cc7262398cb29b1b735f93970fd36a5a62a8a47545c9c5f79101610963565b600060ff82111561100d576040516306dfcc6560e41b8152600860048201526024810183905260440161069d565b5090565b600065ffffffffffff82111561100d576040516306dfcc6560e41b8152603060048201526024810183905260440161069d565b6060610a7161105161096f565b61155f565b6000806110638484611577565b905080156109e95760008481526001602052604090206110839084611187565b509392505050565b6000806110988484611609565b905080156109e95760008481526001602052604090206110839084611168565b804710156110db5760405163cd78605960e01b815230600482015260240161069d565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611128576040519150601f19603f3d011682016040523d82523d6000602084013e61112d565b606091505b505090508061079457604051630a12f52160e11b815260040160405180910390fd5b60006109e98383611674565b606060006109e98361169e565b60006109e9836001600160a01b0384166116fa565b6000610673825490565b60006109e9836001600160a01b0384166117ed565b6111a581610cfe565b1580156111ba57506001600160a01b03811615155b156111e357604051633e336bbb60e01b81526001600160a01b038216600482015260240161069d565b6002546001600160a01b03166001600160a01b0316816001600160a01b03160361122b57604051634542adbf60e11b81526001600160a01b038216600482015260240161069d565b600280546001600160a01b0319166001600160a01b0383161790556040516001600160a01b03821681527fd6c4ff3ce819d1fe47a30bb776376d847d8085a73ebf92dbf4058c36fdd5c169906020015b60405180910390a150565b60606106736001836040516020016112b09190815181526020918201519181019190915260400190565b604051602081830303815290604052611834565b6000806112d96002546001600160a01b031690565b90506001600160a01b038116611302576040516335f2562960e11b815260040160405180910390fd5b806001600160a01b031663cbb3c631866113246008546001600160a01b031690565b61132c610a76565b88886040518663ffffffff1660e01b815260040161134e959493929190611d36565b602060405180830381865afa15801561136b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061138f9190611d8e565b95945050505050565b60098190556040518181527f336210500e2973a38a8d7b3f978ac5bf874a3326119f3dff68651e472a1ae7729060200161127b565b6001600160a01b0382166113f4576040516335f2562960e11b815260040160405180910390fd5b6113fd82610cfe565b156114265760405163d497fddf60e01b81526001600160a01b038316600482015260240161069d565b6114318260016114d7565b6040516001600160a01b03831681527f9963c5d146abd18838e0638ea82ec86b9a726e15fd852cab94aeebcd8bf438d19060200160405180910390a18015610759576107598261119c565b6001600160a01b038116600090815260018301602052604081205415156109e9565b6114a88282610a3c565b6107595760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161069d565b80156114e857610794600483611187565b610794600483611168565b6000806114ff84611286565b905061138f8582856112c4565b6040805180820190915260008082526020820152600061152b84611286565b6001600160401b038716600090815260036020526040902054909150611555908790878487611860565b9695505050505050565b60606106736001836040516020016112b09190611c82565b60006115838383610a3c565b611601576000838152602081815260408083206001600160a01b03861684529091529020805460ff191660011790556115b93390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a4506001610673565b506000610673565b60006116158383610a3c565b15611601576000838152602081815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a4506001610673565b600082600001828154811061168b5761168b611da7565b9060005260206000200154905092915050565b6060816000018054806020026020016040519081016040528092919081815260200182805480156116ee57602002820191906000526020600020905b8154815260200190600101908083116116da575b50505050509050919050565b600081815260018301602052604081205480156117e357600061171e600183611d15565b855490915060009061173290600190611d15565b905080821461179757600086600001828154811061175257611752611da7565b906000526020600020015490508087600001848154811061177557611775611da7565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806117a8576117a8611dbd565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610673565b6000915050610673565b600081815260018301602052604081205461160157508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610673565b60608282604051602001611849929190611dd3565b604051602081830303815290604052905092915050565b604080518082019091526000808252602082015260006118886002546001600160a01b031690565b90506001600160a01b0381166118b1576040516335f2562960e11b815260040160405180910390fd5b46876001600160401b0316036118e557604051632c262dc960e11b81526001600160401b038816600482015260240161069d565b60008690036119125760405163cd256fe760e01b81526001600160401b038816600482015260240161069d565b8447101561193c57604051630849070b60e31b81524760048201526024810186905260440161069d565b806001600160a01b031663547efb848689896119606008546001600160a01b031690565b611968610a76565b8a8a6040518863ffffffff1660e01b815260040161198b96959493929190611e03565b604080518083038185885af11580156119a8573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906119cd9190611e6c565b979650505050505050565b6000602082840312156119ea57600080fd5b81356001600160e01b0319811681146109e957600080fd5b6001600160401b03811681146108fe57600080fd5b600080600080600060808688031215611a2f57600080fd5b8535611a3a81611a02565b9450602086013593506040860135611a5181611a02565b925060608601356001600160401b0380821115611a6d57600080fd5b818801915088601f830112611a8157600080fd5b813581811115611a9057600080fd5b896020828501011115611aa257600080fd5b9699959850939650602001949392505050565b80356001600160a01b0381168114611acc57600080fd5b919050565b600060208284031215611ae357600080fd5b6109e982611ab5565b60008060408385031215611aff57600080fd5b8235611b0a81611a02565b946020939093013593505050565b60008060408385031215611b2b57600080fd5b8235611b3681611a02565b9150611b4460208401611ab5565b90509250929050565b60008060408385031215611b6057600080fd5b50508035926020909101359150565b600060208284031215611b8157600080fd5b5035919050565b60005b83811015611ba3578181015183820152602001611b8b565b50506000910152565b60008151808452611bc4816020860160208601611b88565b601f01601f19169290920160200192915050565b60008151808452602080850194506020840160005b83811015611c125781516001600160a01b031687529582019590820190600101611bed565b509495945050505050565b604081526000611c306040830185611bac565b828103602084015261138f8185611bd8565b60008060408385031215611c5557600080fd5b82359150611b4460208401611ab5565b600060208284031215611c7757600080fd5b81356109e981611a02565b815160ff908116825260208084015165ffffffffffff1690830152604080840151909116908201526060918201516001600160a01b03169181019190915260800190565b6020815260006109e96020830184611bd8565b60008060408385031215611cec57600080fd5b611cf583611ab5565b915060208301358015158114611d0a57600080fd5b809150509250929050565b8181038181111561067357634e487b7160e01b600052601160045260246000fd5b6001600160401b03861681526001600160a01b038516602082015260a060408201819052600090611d6990830186611bd8565b8281036060840152611d7b8186611bac565b9150508260808301529695505050505050565b600060208284031215611da057600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b61ffff60f01b8360f01b16815260008251611df5816002850160208701611b88565b919091016002019392505050565b6001600160401b038716815285602082015260018060a01b038516604082015260c060608201526000611e3960c0830186611bd8565b8281036080840152611e4b8186611bac565b905082810360a0840152611e5f8185611bac565b9998505050505050505050565b600060408284031215611e7e57600080fd5b604051604081018181106001600160401b0382111715611eae57634e487b7160e01b600052604160045260246000fd5b604052825181526020830151611ec381611a02565b6020820152939250505056fe67458b9c8206fd7556afadce1bc8e28c7a8942ecb92d9d9fad69bb6c8cf75c84a26469706673582212205144082e64df68858087ff36b78149b08d859255819af186aa9357fe8a75450264736f6c63430008180033000000000000000000000000e7353bedc72d29f99d6ca5cde69f807cce5d57e4

Deployed Bytecode

0x6080604052600436106101f25760003560e01c806390a92c161161010d578063ca15c873116100a0578063ed5ec8901161006f578063ed5ec890146105b8578063ee7d72b4146105d8578063f22ba23d146105f8578063f68016b714610618578063f6b266fd1461062e57600080fd5b8063ca15c87314610538578063cb5038fb14610558578063d547741f14610578578063eb53b44e1461059857600080fd5b8063b2494df3116100dc578063b2494df3146104c7578063b70c40b3146104dc578063bc0d912c146104fc578063c313c8071461051a57600080fd5b806390a92c161461045057806391d1485414610470578063a1aa5d6814610490578063a217fddf146104b257600080fd5b8063287bc05711610185578063496774b111610154578063496774b1146103a05780634e6427e7146103c05780637717a647146103f65780639010d07c1461041857600080fd5b8063287bc057146103285780632f2ff15d1461034b57806336568abe1461036b5780633ccfd60b1461038b57600080fd5b80631856ddfe116101c15780631856ddfe146102885780631c489e4f146102a85780631ec46e95146102d8578063248a9ca3146102f857600080fd5b806301ffc9a7146101fe5780630421a1f0146102335780630fb591561461024857806317d262861461026857600080fd5b366101f957005b600080fd5b34801561020a57600080fd5b5061021e6102193660046119d8565b61064e565b60405190151581526020015b60405180910390f35b610246610241366004611a17565b610679565b005b34801561025457600080fd5b50610246610263366004611ad1565b610738565b34801561027457600080fd5b50610246610283366004611aec565b61075d565b34801561029457600080fd5b506102466102a3366004611b18565b610769565b3480156102b457600080fd5b506102ca600080516020611ed083398151915281565b60405190815260200161022a565b3480156102e457600080fd5b506102466102f3366004611b4d565b610799565b34801561030457600080fd5b506102ca610313366004611b6f565b60009081526020819052604090206001015490565b34801561033457600080fd5b5061033d610870565b60405161022a929190611c1d565b34801561035757600080fd5b50610246610366366004611c42565b61088b565b34801561037757600080fd5b50610246610386366004611c42565b6108b6565b34801561039757600080fd5b506102466108e9565b3480156103ac57600080fd5b506102466103bb366004611ad1565b610901565b3480156103cc57600080fd5b506102ca6103db366004611c65565b6001600160401b031660009081526003602052604090205490565b34801561040257600080fd5b5061040b61096f565b60405161022a9190611c82565b34801561042457600080fd5b50610438610433366004611b4d565b6109d1565b6040516001600160a01b03909116815260200161022a565b34801561045c57600080fd5b5061043861046b366004611c65565b6109f0565b34801561047c57600080fd5b5061021e61048b366004611c42565b610a3c565b34801561049c57600080fd5b506104a5610a65565b60405161022a9190611cc6565b3480156104be57600080fd5b506102ca600081565b3480156104d357600080fd5b506104a5610a76565b3480156104e857600080fd5b506102466104f7366004611ad1565b610a82565b34801561050857600080fd5b506002546001600160a01b0316610438565b34801561052657600080fd5b506008546001600160a01b0316610438565b34801561054457600080fd5b506102ca610553366004611b6f565b610b0b565b34801561056457600080fd5b50610246610573366004611ad1565b610b22565b34801561058457600080fd5b50610246610593366004611c42565b610bd2565b3480156105a457600080fd5b506102466105b3366004611ad1565b610bf7565b3480156105c457600080fd5b506102ca6105d3366004611c65565b610c18565b3480156105e457600080fd5b506102466105f3366004611b6f565b610c64565b34801561060457600080fd5b50610246610613366004611cd9565b610c85565b34801561062457600080fd5b506102ca60095481565b34801561063a57600080fd5b50610246610649366004611aec565b610ca7565b60006001600160e01b03198216635a05180f60e01b1480610673575061067382610cc9565b92915050565b61068233610cfe565b6106a657604051633e336bbb60e01b81523360048201526024015b60405180910390fd5b46856001600160401b0316036106da57604051632c262dc960e11b81526001600160401b038616600482015260240161069d565b6001600160401b0385166000908152600360205260409020548414610724576040516377df34df60e01b81526001600160401b03861660048201526024810185905260440161069d565b6107318585858585610d0b565b5050505050565b600080516020611ed083398151915261075081610d81565b61075982610d8b565b5050565b61075982826001610e31565b600080516020611ed083398151915261078181610d81565b610794836001600160a01b038416610f38565b505050565b600080516020611ed08339815191526107b181610d81565b826000036107dc57604051636f2b4c2f60e11b8152600481018490526024810183905260440161069d565b6107e583610fdf565b600260146101000a81548160ff021916908360ff16021790555061080882611011565b6002805465ffffffffffff92909216600160a81b0265ffffffffffff60a81b1990921691909117905560408051848152602081018490527f156e53f21add5e964d33e39e015675e24d4568202b47744bd8cc6080f76deabf91015b60405180910390a1505050565b60608061087b611044565b9150610885610a76565b90509091565b6000828152602081905260409020600101546108a681610d81565b6108b08383611056565b50505050565b6001600160a01b03811633146108df5760405163334bd91960e11b815260040160405180910390fd5b610794828261108b565b60006108f481610d81565b6108fe33476110b8565b50565b600080516020611ed083398151915261091981610d81565b600880546001600160a01b0319166001600160a01b0384169081179091556040519081527f56f2046f579030345e1c12cfd7e2d297e4059c24d30ac1a5cb27a8ee1d53526e906020015b60405180910390a15050565b604080516080808201835260008083526020808401829052838501829052606093840182905284519283018552600254600160a01b810460ff168452600160a81b900465ffffffffffff16908301526001938201939093529081019190915290565b60008281526001602052604081206109e9908361114f565b9392505050565b6001600160401b038116600090815260036020526040902054806001600160a01b0381168114610a36576040516382a4102b60e01b81526004810182905260240161069d565b50919050565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6060610a71600461115b565b905090565b6060610a71600661115b565b600080516020611ed0833981519152610a9a81610d81565b6000610aa7600684611168565b905080610ad257604051635895247360e11b81526001600160a01b038416600482015260240161069d565b6040516001600160a01b03841681527f91071153b5721fdadecd5ab74cedca9c0faa62c94f02ef659df224160269838590602001610863565b60008181526001602052604081206106739061117d565b600080516020611ed0833981519152610b3a81610d81565b6001600160a01b038216610b6157604051635467061760e11b815260040160405180910390fd5b6000610b6e600684611187565b905080610b995760405163215b8e2b60e21b81526001600160a01b038416600482015260240161069d565b6040516001600160a01b03841681527f0f92a0308a1fb283891a96a4cf077b8499cca0159d8e6ccc8d12096a5011750990602001610863565b600082815260208190526040902060010154610bed81610d81565b6108b0838361108b565b600080516020611ed0833981519152610c0f81610d81565b6107598261119c565b604080518082018252600954815260006020808301829052835180820183905284518082039092018252840190935291610c5c84610c5584611286565b83516112c4565b949350505050565b600080516020611ed0833981519152610c7c81610d81565b61075982611398565b600080516020611ed0833981519152610c9d81610d81565b61079483836113cd565b600080516020611ed0833981519152610cbf81610d81565b6107948383610f38565b60006001600160e01b03198216637965db0b60e01b148061067357506301ffc9a760e01b6001600160e01b0319831614610673565b600061067360048361147c565b6000610d1982840184611b6f565b604080518281526001600160401b03871660208201529192507fc3d24d80f3729a777c08ca6b879a4a162aa5e25c4744c55841b1558c38c0233e910160405180910390a18015610d7957610d7986610d72600184611d15565b6000610e31565b505050505050565b6108fe813361149e565b610d9481610cfe565b610dbc57604051633e336bbb60e01b81526001600160a01b038216600482015260240161069d565b610dc78160006114d7565b6040516001600160a01b03821681527fc0d64f9e088893f1e4aea6d42c0e815f158ca62962029260f3c2b079d97feccc9060200160405180910390a16002546001600160a01b03166001600160a01b0316816001600160a01b0316036108fe576108fe600061119c565b60006040518060400160405280600954815260200160008152509050600083604051602001610e6291815260200190565b60405160208183030381529060405290506000610e81868484516114f3565b90508047108015610e90575083155b15610ed0576040518581527ff83d5148c4e705c82778f8aed1bb387ea5a8c0046cd647c807b70d65932210c29060200160405180910390a1505050505050565b6000610ede8783868661150c565b90507ff49ca760b7c158bf7657b69ea354b3c05e11991cc8688298400f98764aee2299868260200151604051610f279291909182526001600160401b0316602082015260400190565b60405180910390a150505050505050565b46826001600160401b031603610f6c57604051632c262dc960e11b81526001600160401b038316600482015260240161069d565b6000819003610f8e5760405163a72ac69d60e01b815260040160405180910390fd5b6001600160401b038216600081815260036020908152604091829020849055815192835282018390527f8991328923b5fe27cc7262398cb29b1b735f93970fd36a5a62a8a47545c9c5f79101610963565b600060ff82111561100d576040516306dfcc6560e41b8152600860048201526024810183905260440161069d565b5090565b600065ffffffffffff82111561100d576040516306dfcc6560e41b8152603060048201526024810183905260440161069d565b6060610a7161105161096f565b61155f565b6000806110638484611577565b905080156109e95760008481526001602052604090206110839084611187565b509392505050565b6000806110988484611609565b905080156109e95760008481526001602052604090206110839084611168565b804710156110db5760405163cd78605960e01b815230600482015260240161069d565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611128576040519150601f19603f3d011682016040523d82523d6000602084013e61112d565b606091505b505090508061079457604051630a12f52160e11b815260040160405180910390fd5b60006109e98383611674565b606060006109e98361169e565b60006109e9836001600160a01b0384166116fa565b6000610673825490565b60006109e9836001600160a01b0384166117ed565b6111a581610cfe565b1580156111ba57506001600160a01b03811615155b156111e357604051633e336bbb60e01b81526001600160a01b038216600482015260240161069d565b6002546001600160a01b03166001600160a01b0316816001600160a01b03160361122b57604051634542adbf60e11b81526001600160a01b038216600482015260240161069d565b600280546001600160a01b0319166001600160a01b0383161790556040516001600160a01b03821681527fd6c4ff3ce819d1fe47a30bb776376d847d8085a73ebf92dbf4058c36fdd5c169906020015b60405180910390a150565b60606106736001836040516020016112b09190815181526020918201519181019190915260400190565b604051602081830303815290604052611834565b6000806112d96002546001600160a01b031690565b90506001600160a01b038116611302576040516335f2562960e11b815260040160405180910390fd5b806001600160a01b031663cbb3c631866113246008546001600160a01b031690565b61132c610a76565b88886040518663ffffffff1660e01b815260040161134e959493929190611d36565b602060405180830381865afa15801561136b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061138f9190611d8e565b95945050505050565b60098190556040518181527f336210500e2973a38a8d7b3f978ac5bf874a3326119f3dff68651e472a1ae7729060200161127b565b6001600160a01b0382166113f4576040516335f2562960e11b815260040160405180910390fd5b6113fd82610cfe565b156114265760405163d497fddf60e01b81526001600160a01b038316600482015260240161069d565b6114318260016114d7565b6040516001600160a01b03831681527f9963c5d146abd18838e0638ea82ec86b9a726e15fd852cab94aeebcd8bf438d19060200160405180910390a18015610759576107598261119c565b6001600160a01b038116600090815260018301602052604081205415156109e9565b6114a88282610a3c565b6107595760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161069d565b80156114e857610794600483611187565b610794600483611168565b6000806114ff84611286565b905061138f8582856112c4565b6040805180820190915260008082526020820152600061152b84611286565b6001600160401b038716600090815260036020526040902054909150611555908790878487611860565b9695505050505050565b60606106736001836040516020016112b09190611c82565b60006115838383610a3c565b611601576000838152602081815260408083206001600160a01b03861684529091529020805460ff191660011790556115b93390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a4506001610673565b506000610673565b60006116158383610a3c565b15611601576000838152602081815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a4506001610673565b600082600001828154811061168b5761168b611da7565b9060005260206000200154905092915050565b6060816000018054806020026020016040519081016040528092919081815260200182805480156116ee57602002820191906000526020600020905b8154815260200190600101908083116116da575b50505050509050919050565b600081815260018301602052604081205480156117e357600061171e600183611d15565b855490915060009061173290600190611d15565b905080821461179757600086600001828154811061175257611752611da7565b906000526020600020015490508087600001848154811061177557611775611da7565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806117a8576117a8611dbd565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610673565b6000915050610673565b600081815260018301602052604081205461160157508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610673565b60608282604051602001611849929190611dd3565b604051602081830303815290604052905092915050565b604080518082019091526000808252602082015260006118886002546001600160a01b031690565b90506001600160a01b0381166118b1576040516335f2562960e11b815260040160405180910390fd5b46876001600160401b0316036118e557604051632c262dc960e11b81526001600160401b038816600482015260240161069d565b60008690036119125760405163cd256fe760e01b81526001600160401b038816600482015260240161069d565b8447101561193c57604051630849070b60e31b81524760048201526024810186905260440161069d565b806001600160a01b031663547efb848689896119606008546001600160a01b031690565b611968610a76565b8a8a6040518863ffffffff1660e01b815260040161198b96959493929190611e03565b604080518083038185885af11580156119a8573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906119cd9190611e6c565b979650505050505050565b6000602082840312156119ea57600080fd5b81356001600160e01b0319811681146109e957600080fd5b6001600160401b03811681146108fe57600080fd5b600080600080600060808688031215611a2f57600080fd5b8535611a3a81611a02565b9450602086013593506040860135611a5181611a02565b925060608601356001600160401b0380821115611a6d57600080fd5b818801915088601f830112611a8157600080fd5b813581811115611a9057600080fd5b896020828501011115611aa257600080fd5b9699959850939650602001949392505050565b80356001600160a01b0381168114611acc57600080fd5b919050565b600060208284031215611ae357600080fd5b6109e982611ab5565b60008060408385031215611aff57600080fd5b8235611b0a81611a02565b946020939093013593505050565b60008060408385031215611b2b57600080fd5b8235611b3681611a02565b9150611b4460208401611ab5565b90509250929050565b60008060408385031215611b6057600080fd5b50508035926020909101359150565b600060208284031215611b8157600080fd5b5035919050565b60005b83811015611ba3578181015183820152602001611b8b565b50506000910152565b60008151808452611bc4816020860160208601611b88565b601f01601f19169290920160200192915050565b60008151808452602080850194506020840160005b83811015611c125781516001600160a01b031687529582019590820190600101611bed565b509495945050505050565b604081526000611c306040830185611bac565b828103602084015261138f8185611bd8565b60008060408385031215611c5557600080fd5b82359150611b4460208401611ab5565b600060208284031215611c7757600080fd5b81356109e981611a02565b815160ff908116825260208084015165ffffffffffff1690830152604080840151909116908201526060918201516001600160a01b03169181019190915260800190565b6020815260006109e96020830184611bd8565b60008060408385031215611cec57600080fd5b611cf583611ab5565b915060208301358015158114611d0a57600080fd5b809150509250929050565b8181038181111561067357634e487b7160e01b600052601160045260246000fd5b6001600160401b03861681526001600160a01b038516602082015260a060408201819052600090611d6990830186611bd8565b8281036060840152611d7b8186611bac565b9150508260808301529695505050505050565b600060208284031215611da057600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052603160045260246000fd5b61ffff60f01b8360f01b16815260008251611df5816002850160208701611b88565b919091016002019392505050565b6001600160401b038716815285602082015260018060a01b038516604082015260c060608201526000611e3960c0830186611bd8565b8281036080840152611e4b8186611bac565b905082810360a0840152611e5f8185611bac565b9998505050505050505050565b600060408284031215611e7e57600080fd5b604051604081018181106001600160401b0382111715611eae57634e487b7160e01b600052604160045260246000fd5b604052825181526020830151611ec381611a02565b6020820152939250505056fe67458b9c8206fd7556afadce1bc8e28c7a8942ecb92d9d9fad69bb6c8cf75c84a26469706673582212205144082e64df68858087ff36b78149b08d859255819af186aa9357fe8a75450264736f6c63430008180033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000e7353bedc72d29f99d6ca5cde69f807cce5d57e4

-----Decoded View---------------
Arg [0] : admin (address): 0xE7353BEdc72D29f99D6cA5CDE69F807cCE5d57e4

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000e7353bedc72d29f99d6ca5cde69f807cce5d57e4


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]
[ 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.