Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x9251C6B5f4e2CEE34269400CBB43AD5C813606F6
Balance 0 ETH
Nonce 1
Code Size 6514 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

6514 bytes
0x60806040526004361061009c5760003560e01c8063bc0dd44711610064578063bc0dd4471461014c578063c85e0be21461016c578063d0fff3661461018c578063dd92a316146101a7578063ef2b528d146101c7578063f437bc59146101da57600080fd5b80630bc37bab146100a15780630fee32ce146100c3578063108bc1dd146100e357806344ab20f814610116578063b2a01bf514610131575b600080fd5b3480156100ad57600080fd5b506100c16100bc366004610f83565b610207565b005b3480156100cf57600080fd5b506100c16100de366004610fda565b610259565b3480156100ef57600080fd5b506101036100fe36600461105d565b6102c3565b6040519081526020015b60405180910390f35b34801561012257600080fd5b506100c16100bc3660046112ec565b34801561013d57600080fd5b506100c16100bc366004611494565b34801561015857600080fd5b506100c16101673660046114f4565b610361565b34801561017857600080fd5b506100c1610187366004611535565b6103c8565b34801561019857600080fd5b506100c16100bc366004611552565b3480156101b357600080fd5b506101036101c2366004611586565b6104f4565b6100c16101d5366004611648565b61058d565b3480156101e657600080fd5b506101ef610898565b6040516001600160a01b03909116815260200161010d565b61020f610898565b6001600160a01b0316336001600160a01b03161461024057604051637bf6a16f60e01b815260040160405180910390fd5b6040516302cbc79f60e01b815260040160405180910390fd5b6001546001600160a01b0316331461028457604051637bf6a16f60e01b815260040160405180910390fd5b805160c001516040517ffb087b3ffbbb0fc922dccf872508671a7605859423eb90eb014c56fdba1484dc916102b891611743565b60405180910390a150565b60006102cd610898565b8251604051632008f60560e11b81526001600160a01b039290921691634011ec0a916102fb91600401611743565b602060405180830381865afa158015610318573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061033c9190611756565b82604001515161034c9190611785565b826080015161035b919061179c565b92915050565b6001546001600160a01b0316331461038c57604051637bf6a16f60e01b815260040160405180910390fd5b7f23a99ef8c0b546a4ee377190389c8d74eefe167ac90afd2e492efea72252bf656103ba60c08301836117af565b6040516102b89291906117fc565b6000546001600160a01b031633146103f2576040516282b42960e81b815260040160405180910390fd5b806001600160a01b031663647846a56040518163ffffffff1660e01b8152600401602060405180830381865afa158015610430573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610454919061182b565b60405163095ea7b360e01b81526001600160a01b0383811660048301526000196024830152919091169063095ea7b3906044016020604051808303816000875af11580156104a6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104ca9190611848565b50600180546001600160a01b039092166001600160a01b0319928316179055600080549091169055565b60006104fe610898565b825151604051632008f60560e11b81526001600160a01b039290921691634011ec0a9161052d91600401611743565b602060405180830381865afa15801561054a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061056e9190611756565b82602001515161057e9190611785565b826060015161035b919061179c565b60006040518060c0016040528083600001518152602001306040516020016105cd919060609190911b6bffffffffffffffffffffffff1916815260140190565b60405160208183030381529060405281526020018360200151815260200183606001516001600160401b0316815260200183604001518152602001306001600160a01b0316815250905060008034111561069d5760015460405163b8f3e8f560e01b81526001600160a01b039091169063b8f3e8f590349061065390869060040161186a565b60206040518083038185885af1158015610671573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906106969190611756565b9050610856565b60008360200151516020116106b7578360200151516106ba565b60205b60408086015160015487519251632008f60560e11b8152939450600093919285926001600160a01b0390921691634011ec0a916106f991600401611743565b602060405180830381865afa158015610716573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061073a9190611756565b6107449190611785565b61074e919061179c565b90506107de333083600160009054906101000a90046001600160a01b03166001600160a01b031663647846a56040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107cd919061182b565b6001600160a01b031692919061097a565b60015460405163b8f3e8f560e01b81526001600160a01b039091169063b8f3e8f59061080e90879060040161186a565b6020604051808303816000875af115801561082d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108519190611756565b925050505b7ff03a276780bf6f754f747a73a06ecac504adc5857934b6dc016f68e2768e3e6c83602001518260405161088b9291906118fe565b60405180910390a1505050565b60004662aa36a781146108d85762066eee81146108f35762aa37dc811461090e5762014a3481146109295760618114610944576127d8811461095f575090565b7327b0c6960b792a8dcb01f0652bde48015cd5f23e91505090565b73fd7e2b2ad0b29ec817dc7d406881b225b81dbfcf91505090565b7330e3af1747b155f37f935e0ec995de5ea4e6758691505090565b730d7037bd9ceaef25e5215f808d309add0a65cdb991505090565b734cb0f5750f6fe14d4b86aca6fe126943bda3c8c491505090565b7311eb87c745d97a4fa8aec805359837459d240d1b91505090565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526109d49085906109da565b50505050565b6000610a2f826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610ab69092919063ffffffff16565b805190915015610ab15780806020019051810190610a4d9190611848565b610ab15760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084015b60405180910390fd5b505050565b6060610ac58484600085610acd565b949350505050565b606082471015610b2e5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610aa8565b600080866001600160a01b03168587604051610b4a9190611920565b60006040518083038185875af1925050503d8060008114610b87576040519150601f19603f3d011682016040523d82523d6000602084013e610b8c565b606091505b5091509150610b9d87838387610ba8565b979650505050505050565b60608315610c17578251600003610c10576001600160a01b0385163b610c105760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610aa8565b5081610ac5565b610ac58383815115610c2c5781518083602001fd5b8060405162461bcd60e51b8152600401610aa89190611743565b634e487b7160e01b600052604160045260246000fd5b60405160e081016001600160401b0381118282101715610c7e57610c7e610c46565b60405290565b604080519081016001600160401b0381118282101715610c7e57610c7e610c46565b60405160c081016001600160401b0381118282101715610c7e57610c7e610c46565b60405161010081016001600160401b0381118282101715610c7e57610c7e610c46565b60405160a081016001600160401b0381118282101715610c7e57610c7e610c46565b604051608081016001600160401b0381118282101715610c7e57610c7e610c46565b604051601f8201601f191681016001600160401b0381118282101715610d5757610d57610c46565b604052919050565b600082601f830112610d7057600080fd5b81356001600160401b03811115610d8957610d89610c46565b610d9c601f8201601f1916602001610d2f565b818152846020838601011115610db157600080fd5b816020850160208301376000918101602001919091529392505050565b80356001600160401b0381168114610de557600080fd5b919050565b600060e08284031215610dfc57600080fd5b610e04610c5c565b905081356001600160401b0380821115610e1d57600080fd5b610e2985838601610d5f565b83526020840135915080821115610e3f57600080fd5b610e4b85838601610d5f565b6020840152610e5c60408501610dce565b60408401526060840135915080821115610e7557600080fd5b610e8185838601610d5f565b60608401526080840135915080821115610e9a57600080fd5b610ea685838601610d5f565b6080840152610eb760a08501610dce565b60a084015260c0840135915080821115610ed057600080fd5b50610edd84828501610d5f565b60c08301525092915050565b600060608284031215610efb57600080fd5b604051606081016001600160401b038282108183111715610f1e57610f1e610c46565b816040528293508435915080821115610f3657600080fd5b610f4286838701610dea565b83526020850135915080821115610f5857600080fd5b50610f6585828601610d5f565b602083015250610f7760408401610dce565b60408201525092915050565b600060208284031215610f9557600080fd5b81356001600160401b03811115610fab57600080fd5b610ac584828501610ee9565b6001600160a01b0381168114610fcc57600080fd5b50565b8035610de581610fb7565b600060208284031215610fec57600080fd5b81356001600160401b038082111561100357600080fd5b908301906040828603121561101757600080fd5b61101f610c84565b82358281111561102e57600080fd5b61103a87828601610dea565b8252506020830135925061104d83610fb7565b6020810192909252509392505050565b60006020828403121561106f57600080fd5b81356001600160401b038082111561108657600080fd5b9083019060c0828603121561109a57600080fd5b6110a2610ca6565b8235828111156110b157600080fd5b6110bd87828601610d5f565b8252506020830135828111156110d257600080fd5b6110de87828601610d5f565b6020830152506040830135828111156110f657600080fd5b61110287828601610d5f565b60408301525061111460608401610dce565b60608201526080830135608082015261112f60a08401610fcf565b60a082015295945050505050565b60006001600160401b0382111561115657611156610c46565b5060051b60200190565b600082601f83011261117157600080fd5b813560206111866111818361113d565b610d2f565b82815260059290921b840181019181810190868411156111a557600080fd5b8286015b848110156111e45780356001600160401b038111156111c85760008081fd5b6111d68986838b0101610d5f565b8452509183019183016111a9565b509695505050505050565b6000610100828403121561120257600080fd5b61120a610cc8565b905081356001600160401b038082111561122357600080fd5b61122f85838601610d5f565b8352602084013591508082111561124557600080fd5b61125185838601610d5f565b602084015261126260408501610dce565b604084015261127360608501610fcf565b606084015261128460808501610dce565b608084015260a084013591508082111561129d57600080fd5b6112a985838601611160565b60a08401526112ba60c08501610dce565b60c084015260e08401359150808211156112d357600080fd5b506112e084828501610d5f565b60e08301525092915050565b6000602082840312156112fe57600080fd5b6001600160401b03808335111561131457600080fd5b823583016040818603121561132857600080fd5b611330610c84565b828235111561133e57600080fd5b813582016040818803121561135257600080fd5b61135a610c84565b848235111561136857600080fd5b61137588833584016111ef565b8152846020830135111561138857600080fd5b60208201358201915087601f8301126113a057600080fd5b6113ad611181833561113d565b82358082526020808301929160051b8501018a8111156113cc57600080fd5b602085015b8181101561146b5788813511156113e757600080fd5b803586016040818e03601f190112156113ff57600080fd5b611407610c84565b8a6020830135111561141857600080fd5b61142a8e602080850135850101610d5f565b81528a6040830135111561143d57600080fd5b6114508e60206040850135850101610d5f565b602082015280865250506020840193506020810190506113d1565b50508060208401525050808352505061148660208301610fcf565b602082015295945050505050565b6000602082840312156114a657600080fd5b81356001600160401b03808211156114bd57600080fd5b90830190604082860312156114d157600080fd5b6114d9610c84565b8235828111156114e857600080fd5b61103a87828601610ee9565b60006020828403121561150657600080fd5b81356001600160401b0381111561151c57600080fd5b820160e0818503121561152e57600080fd5b9392505050565b60006020828403121561154757600080fd5b813561152e81610fb7565b60006020828403121561156457600080fd5b81356001600160401b0381111561157a57600080fd5b610ac5848285016111ef565b60006020828403121561159857600080fd5b81356001600160401b03808211156115af57600080fd5b9083019060a082860312156115c357600080fd5b6115cb610ceb565b8235828111156115da57600080fd5b6115e687828601610dea565b8252506020830135828111156115fb57600080fd5b61160787828601610d5f565b60208301525061161960408401610dce565b6040820152606083013560608201526080830135925061163883610fb7565b6080810192909252509392505050565b60006020828403121561165a57600080fd5b81356001600160401b038082111561167157600080fd5b908301906080828603121561168557600080fd5b61168d610d0d565b82358281111561169c57600080fd5b6116a887828601610d5f565b8252506020830135828111156116bd57600080fd5b6116c987828601610d5f565b602083015250604083013560408201526116e560608401610dce565b606082015295945050505050565b60005b8381101561170e5781810151838201526020016116f6565b50506000910152565b6000815180845261172f8160208601602086016116f3565b601f01601f19169290920160200192915050565b60208152600061152e6020830184611717565b60006020828403121561176857600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761035b5761035b61176f565b8082018082111561035b5761035b61176f565b6000808335601e198436030181126117c657600080fd5b8301803591506001600160401b038211156117e057600080fd5b6020019150368190038213156117f557600080fd5b9250929050565b60208152816020820152818360408301376000818301604090810191909152601f909201601f19160101919050565b60006020828403121561183d57600080fd5b815161152e81610fb7565b60006020828403121561185a57600080fd5b8151801515811461152e57600080fd5b602081526000825160c0602084015261188660e0840182611717565b90506020840151601f19808584030160408601526118a48383611717565b92506040860151915080858403016060860152506118c28282611717565b9150506001600160401b036060850151166080840152608084015160a084015260018060a01b0360a08501511660c08401528091505092915050565b6040815260006119116040830185611717565b90508260208301529392505050565b600082516119328184602087016116f3565b919091019291505056fea264697066735822122008374faacbee6259edc488757c2595c34e37462be2d93756d4042a62257621a964736f6c63430008140033

Verified Source Code Full Match

Compiler: v0.8.20+commit.a1b79de6 EVM: paris Optimization: Yes (200 runs)
Inscriptions.sol 87 lines
// SPDX-License-Identifier: UNLICENSED
// A Sample ISMP solidity contract for unit tests

pragma solidity ^0.8.17;

import {BaseIsmpModule, IncomingPostRequest} from "@polytope-labs/ismp-solidity/IIsmpModule.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {DispatchPost, IDispatcher, PostRequest} from "@polytope-labs/ismp-solidity/IDispatcher.sol";

struct CrossChainMessage {
    bytes dest;
    bytes message;
    uint256 relayerFee;
    uint64 timeout;
}

contract CrossChainInscription is BaseIsmpModule {
    using SafeERC20 for IERC20;

    // An inscription has been received
    event PostReceived(string message);

    // An inscription has been received
    event PostDispatched(string message, bytes32 commitment);

    // An inscription has been received
    event PostTimedOut(string message);

    // Call is unauthorized
    error Unauthorized();

    address private _admin;
    address private _host;

    constructor(address admin) {
        _admin = admin;
    }

    function setHost(address host) public {
        if (msg.sender != _admin) revert Unauthorized();
        // infinite approval to save on gas
        IERC20(IDispatcher(host).feeToken()).approve(
            host,
            type(uint256).max
        );

        _host = host;
        _admin = address(0);
    }

    function inscribe(CrossChainMessage memory params) public payable {
        DispatchPost memory request = DispatchPost({
            body: params.message,
            dest: params.dest,
            timeout: params.timeout,
            // instance of this pallet on another chain.
            to: abi.encodePacked(address(this)),
            fee: params.relayerFee,
            payer: address(this)
        });

        bytes32 commitment;
        if (msg.value > 0) {
            // there's some native tokens left to pay for request dispatch
            commitment = IDispatcher(_host).dispatch{value: msg.value}(request);
        } else {
            // try to pay for dispatch with fee token
            uint256 length = 32 > params.message.length ? 32 : params.message.length;
            uint256 fee = (IDispatcher(_host).perByteFee(params.dest) * length) + params.relayerFee;
            IERC20(IDispatcher(_host).feeToken()).safeTransferFrom(msg.sender, address(this), fee);
            commitment = IDispatcher(_host).dispatch(request);
        }

        emit PostDispatched(string(params.message), commitment);
    }

    function onAccept(IncomingPostRequest memory incoming) external override {
        if (msg.sender != _host) revert UnauthorizedCall();
        emit PostReceived(string(incoming.request.body));
    }

    function onPostRequestTimeout(PostRequest calldata request) external override {
        if (msg.sender != _host) revert UnauthorizedCall();
        emit PostTimedOut(string(request.body));
    }
}
IIsmpModule.sol 167 lines
// Copyright (C) Polytope Labs Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// 	http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pragma solidity ^0.8.17;

import {PostRequest, PostResponse, GetResponse, GetRequest} from "./Message.sol";
import {DispatchPost, DispatchPostResponse, DispatchGet, IDispatcher} from "./IDispatcher.sol";

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

struct IncomingPostRequest {
	// The Post request
	PostRequest request;
	// Relayer responsible for delivering the request
	address relayer;
}

struct IncomingPostResponse {
	// The Post response
	PostResponse response;
	// Relayer responsible for delivering the response
	address relayer;
}

struct IncomingGetResponse {
	// The Get response
	GetResponse response;
	// Relayer responsible for delivering the response
	address relayer;
}

interface IIsmpModule {
	/**
	 * @dev Called by the `IsmpHost` to notify a module of a new request the module may choose to respond immediately, or in a later block
	 * @param incoming post request
	 */
	function onAccept(IncomingPostRequest memory incoming) external;

	/**
	 * @dev Called by the `IsmpHost` to notify a module of a post response to a previously sent out request
	 * @param incoming post response
	 */
	function onPostResponse(IncomingPostResponse memory incoming) external;

	/**
	 * @dev Called by the `IsmpHost` to notify a module of a get response to a previously sent out request
	 * @param incoming get response
	 */
	function onGetResponse(IncomingGetResponse memory incoming) external;

	/**
	 * @dev Called by the `IsmpHost` to notify a module of post requests that were previously sent but have now timed-out
	 * @param request post request
	 */
	function onPostRequestTimeout(PostRequest memory request) external;

	/**
	 * @dev Called by the `IsmpHost` to notify a module of post requests that were previously sent but have now timed-out
	 * @param request post request
	 */
	function onPostResponseTimeout(PostResponse memory request) external;

	/**
	 * @dev Called by the `IsmpHost` to notify a module of get requests that were previously sent but have now timed-out
	 * @param request get request
	 */
	function onGetTimeout(GetRequest memory request) external;
}

// @notice Abstract contract to make implementing `IIsmpModule` easier.
abstract contract BaseIsmpModule is IIsmpModule {
	// @notice Call was not expected
	error UnexpectedCall();

	// @notice Account is unauthorized
	error UnauthorizedCall();

	// @dev restricts caller to the local `IsmpHost`
	modifier onlyHost() {
		if (msg.sender != host()) revert UnauthorizedCall();
		_;
	}

	constructor() {
		address hostAddr = host();
		if (hostAddr != address(0)) {
			// approve the host infintely
			IERC20(IDispatcher(hostAddr).feeToken()).approve(hostAddr, type(uint256).max);
		}
	}

	// @dev Returns the `IsmpHost` address for the current chain.
	// The `IsmpHost` is an immutable contract that will never change.
	function host() public view returns (address h) {
		assembly {
			switch chainid()
			// Ethereum Sepolia
			case 11155111 {
				h := 0x27B0c6960B792a8dCb01F0652bDE48015cd5f23e
			}
			// Arbitrum Sepolia
			case 421614 {
				h := 0xfd7E2b2ad0b29Ec817dC7d406881b225B81dbFCf
			}
			// Optimism Sepolia
			case 11155420 {
				h := 0x30e3af1747B155F37F935E0EC995De5EA4e67586
			}
			// Base Sepolia
			case 84532 {
				h := 0x0D7037bd9CEAEF25e5215f808d309ADD0A65Cdb9
			}
			// Binance Smart Chain Testnet
			case 97 {
				h := 0x4cB0f5750f6fE14d4B86acA6fe126943bdA3c8c4
			}
			// Gnosis Chiado Testnet
			case 10200 {
				h := 0x11EB87c745D97a4Fa8Aec805359837459d240d1b
			}
		}
	}

	// @dev returns the quoted fee for a dispatch
	function quote(DispatchPost memory post) public view returns (uint256) {
		return post.fee + (post.body.length * IDispatcher(host()).perByteFee(post.dest));
	}

	// @dev returns the quoted fee for a dispatch
	function quote(DispatchPostResponse memory res) public view returns (uint256) {
		return res.fee + (res.response.length * IDispatcher(host()).perByteFee(res.request.source));
	}

	function onAccept(IncomingPostRequest calldata) external virtual onlyHost {
		revert UnexpectedCall();
	}

	function onPostRequestTimeout(PostRequest memory) external virtual onlyHost {
		revert UnexpectedCall();
	}

	function onPostResponse(IncomingPostResponse memory) external virtual onlyHost {
		revert UnexpectedCall();
	}

	function onPostResponseTimeout(PostResponse memory) external virtual onlyHost {
		revert UnexpectedCall();
	}

	function onGetResponse(IncomingGetResponse memory) external virtual onlyHost {
		revert UnexpectedCall();
	}

	function onGetTimeout(GetRequest memory) external virtual onlyHost {
		revert UnexpectedCall();
	}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";

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

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
IDispatcher.sol 183 lines
// Copyright (C) Polytope Labs Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// 	http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pragma solidity ^0.8.17;

import {PostRequest, StateMachineHeight} from "./Message.sol";

// @notice An object for dispatching post requests to the Hyperbridge
struct DispatchPost {
	// bytes representation of the destination state machine
	bytes dest;
	// the destination module
	bytes to;
	// the request body
	bytes body;
	// timeout for this request in seconds
	uint64 timeout;
	// the amount put up to be paid to the relayer,
	// this is charged in `IIsmpHost.feeToken` to `msg.sender`
	uint256 fee;
	// who pays for this request?
	address payer;
}

// @notice An object for dispatching get requests to the Hyperbridge
struct DispatchGet {
	// bytes representation of the destination state machine
	bytes dest;
	// height at which to read the state machine
	uint64 height;
	// storage keys to read
	bytes[] keys;
	// timeout for this request in seconds
	uint64 timeout;
	// Hyperbridge protocol fees for processing this request.
	uint256 fee;
	// Some application-specific metadata relating to this request
	bytes context;
}

struct DispatchPostResponse {
	// The request that initiated this response
	PostRequest request;
	// bytes for post response
	bytes response;
	// timeout for this response in seconds
	uint64 timeout;
	// the amount put up to be paid to the relayer,
	// this is charged in `IIsmpHost.feeToken` to `msg.sender`
	uint256 fee;
	// who pays for this request?
	address payer;
}

/*
 * @title The Ismp Dispatcher
 * @author Polytope Labs ([email protected])
 *
 * @notice The IDispatcher serves as the interface requests & response messages.
 */
interface IDispatcher {
	/**
	 * @dev Returns the address for the Uniswap V2 Router implementation used for swaps
	 * @return routerAddress - The address to the in-use RouterV02 implementation
	 */
	function uniswapV2Router() external view returns (address);

	/**
	 * @dev Returns the nonce immediately available for requests
	 * @return the `nonce`
	 */
	function nonce() external view returns (uint256);

	/**
	 * @dev Returns the address of the ERC-20 fee token contract configured for this state machine.
	 *
	 * @notice Hyperbridge collects it's dispatch fees in the provided token denomination. This will typically be in stablecoins.
	 *
	 * @return feeToken - The ERC20 contract address for fees.
	 */
	function feeToken() external view returns (address);

	/**
	 * @dev Returns the address of the per byte fee configured for the destination state machine.
	 *
	 * @notice Hyperbridge collects it's dispatch fees per every byte of the outgoing message.
	 *
	 * @param dest - The destination chain for the per byte fee.
	 * @return perByteFee - The per byte fee for outgoing messages.
	 */
	function perByteFee(bytes memory dest) external view returns (uint256);

	/**
	 * @dev Dispatch a POST request to Hyperbridge
	 *
	 * @notice Payment for the request can be made with either the native token or the IIsmpHost.feeToken.
	 * If native tokens are supplied, it will perform a swap under the hood using the local uniswap router.
	 * Will revert if enough native tokens are not provided.
	 *
	 * If no native tokens are provided then it will try to collect payment from the calling contract in
	 * the IIsmpHost.feeToken.
	 *
	 * @param request - post request
	 * @return commitment - the request commitment
	 */
	function dispatch(DispatchPost memory request) external payable returns (bytes32 commitment);

	/**
	 * @dev Dispatch a GET request to Hyperbridge
	 *
	 * @notice Payment for the request can be made with either the native token or the IIsmpHost.feeToken.
	 * If native tokens are supplied, it will perform a swap under the hood using the local uniswap router.
	 * Will revert if enough native tokens are not provided.
	 *
	 * If no native tokens are provided then it will try to collect payment from the calling contract in
	 * the IIsmpHost.feeToken.
	 *
	 * @param request - get request
	 * @return commitment - the request commitment
	 */
	function dispatch(DispatchGet memory request) external payable returns (bytes32 commitment);

	/**
	 * @dev Dispatch a POST response to Hyperbridge
	 *
	 * @notice Payment for the request can be made with either the native token or the IIsmpHost.feeToken.
	 * If native tokens are supplied, it will perform a swap under the hood using the local uniswap router.
	 * Will revert if enough native tokens are not provided.
	 *
	 * If no native tokens are provided then it will try to collect payment from the calling contract in
	 * the IIsmpHost.feeToken.
	 *
	 * @param response - post response
	 * @return commitment - the request commitment
	 */
	function dispatch(DispatchPostResponse memory response) external payable returns (bytes32 commitment);

	/**
	 * @dev Increase the relayer fee for a previously dispatched request.
	 * This is provided for use only on pending requests, such that when they timeout,
	 * the user can recover the entire relayer fee.
	 *
	 * @notice Payment can be made with either the native token or the IIsmpHost.feeToken.
	 * If native tokens are supplied, it will perform a swap under the hood using the local uniswap router.
	 * Will revert if enough native tokens are not provided.
	 *
	 * If no native tokens are provided then it will try to collect payment from the calling contract in
	 * the IIsmpHost.feeToken.
	 *
	 * If called on an already delivered request, these funds will be seen as a donation to the hyperbridge protocol.
	 * @param commitment - The request commitment
	 * @param amount - The amount provided in `IIsmpHost.feeToken()`
	 */
	function fundRequest(bytes32 commitment, uint256 amount) external payable;

	/**
	 * @dev Increase the relayer fee for a previously dispatched response.
	 * This is provided for use only on pending responses, such that when they timeout,
	 * the user can recover the entire relayer fee.
	 *
	 * @notice Payment can be made with either the native token or the IIsmpHost.feeToken.
	 * If native tokens are supplied, it will perform a swap under the hood using the local uniswap router.
	 * Will revert if enough native tokens are not provided.
	 *
	 * If no native tokens are provided then it will try to collect payment from the calling contract in
	 * the IIsmpHost.feeToken.
	 *
	 * If called on an already delivered response, these funds will be seen as a donation to the hyperbridge protocol.
	 * @param commitment - The response commitment
	 * @param amount - The amount to be provided in `IIsmpHost.feeToken()`
	 */
	function fundResponse(bytes32 commitment, uint256 amount) external payable;
}
Message.sol 266 lines
// Copyright (C) Polytope Labs Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// 	http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pragma solidity ^0.8.17;

import {StorageValue} from "@polytope-labs/solidity-merkle-trees/src/Types.sol";

// Identifies some state machine height. We allow for a state machine identifier here
// as some consensus clients may track multiple, concurrent state machines.
struct StateMachineHeight {
	// the state machine identifier
	uint256 stateMachineId;
	// height of this state machine
	uint256 height;
}

struct PostRequest {
	// the source state machine of this request
	bytes source;
	// the destination state machine of this request
	bytes dest;
	// request nonce
	uint64 nonce;
	// Module Id of this request origin
	bytes from;
	// destination module id
	bytes to;
	// timestamp by which this request times out.
	uint64 timeoutTimestamp;
	// request body
	bytes body;
}

struct GetRequest {
	// the source state machine of this request
	bytes source;
	// the destination state machine of this request
	bytes dest;
	// request nonce
	uint64 nonce;
	// Module Id of this request origin
	address from;
	// timestamp by which this request times out.
	uint64 timeoutTimestamp;
	// Storage keys to read.
	bytes[] keys;
	// height at which to read destination state machine
	uint64 height;
	// Some application-specific metadata relating to this request
	bytes context;
}

struct GetResponse {
	// The request that initiated this response
	GetRequest request;
	// storage values for get response
	StorageValue[] values;
}

struct PostResponse {
	// The request that initiated this response
	PostRequest request;
	// bytes for post response
	bytes response;
	// timestamp by which this response times out.
	uint64 timeoutTimestamp;
}

// A post request as a leaf in a merkle tree
struct PostRequestLeaf {
	// The request
	PostRequest request;
	// It's index in the mmr leaves
	uint256 index;
	// it's k-index
	uint256 kIndex;
}

// A post response as a leaf in a merkle tree
struct PostResponseLeaf {
	// The response
	PostResponse response;
	// It's index in the mmr leaves
	uint256 index;
	// it's k-index
	uint256 kIndex;
}

// A get response as a leaf in a merkle mountain range tree
struct GetResponseLeaf {
	// The response
	GetResponse response;
	// It's index in the mmr leaves
	uint256 index;
	// it's k-index
	uint256 kIndex;
}

// A merkle mountain range proof.
struct Proof {
	// height of the state machine
	StateMachineHeight height;
	// the multi-proof
	bytes32[] multiproof;
	// The total number of leaves in the mmr for this proof.
	uint256 leafCount;
}

// A message for handling incoming requests
struct PostRequestMessage {
	// proof for the requests
	Proof proof;
	// The requests, contained in the merkle mountain range tree
	PostRequestLeaf[] requests;
}

// A message for handling incoming GET responses
struct GetResponseMessage {
	// proof for the responses
	Proof proof;
	// The responses, contained in the merkle mountain range tree
	GetResponseLeaf[] responses;
}

struct GetTimeoutMessage {
	// requests which have timed-out
	GetRequest[] timeouts;
	// the height of the state machine proof
	StateMachineHeight height;
	// non-membership proof of the requests
	bytes[] proof;
}

struct PostRequestTimeoutMessage {
	// requests which have timed-out
	PostRequest[] timeouts;
	// the height of the state machine proof
	StateMachineHeight height;
	// non-membership proof of the requests
	bytes[] proof;
}

struct PostResponseTimeoutMessage {
	// responses which have timed-out
	PostResponse[] timeouts;
	// the height of the state machine proof
	StateMachineHeight height;
	// non-membership proof of the requests
	bytes[] proof;
}

// A message for handling incoming responses
struct PostResponseMessage {
	// proof for the responses
	Proof proof;
	// the responses, contained in a merkle tree leaf
	PostResponseLeaf[] responses;
}

library Message {
	/**
	 * @dev Calculates the absolute timeout value for a PostRequest
	 */
	function timeout(PostRequest memory req) internal pure returns (uint64) {
		if (req.timeoutTimestamp == 0) {
			return type(uint64).max;
		} else {
			return req.timeoutTimestamp;
		}
	}

	/**
	 * @dev Calculates the absolute timeout value for a GetRequest
	 */
	function timeout(GetRequest memory req) internal pure returns (uint64) {
		if (req.timeoutTimestamp == 0) {
			return type(uint64).max;
		} else {
			return req.timeoutTimestamp;
		}
	}

	/**
	 * @dev Calculates the absolute timeout value for a PostResponse
	 */
	function timeout(PostResponse memory res) internal pure returns (uint64) {
		if (res.timeoutTimestamp == 0) {
			return type(uint64).max;
		} else {
			return res.timeoutTimestamp;
		}
	}

	/**
	 * @dev Encode the given post request for commitment
	 */
	function encode(PostRequest memory req) internal pure returns (bytes memory) {
		return abi.encodePacked(req.source, req.dest, req.nonce, req.timeoutTimestamp, req.from, req.to, req.body);
	}

	/**
	 * @dev Encode the given get request for commitment
	 */
	function encode(GetRequest memory req) internal pure returns (bytes memory) {
		bytes memory keysEncoding = bytes("");
		uint256 len = req.keys.length;
		for (uint256 i = 0; i < len; i++) {
			keysEncoding = bytes.concat(keysEncoding, req.keys[i]);
		}

		return
			abi.encodePacked(
				req.source,
				req.dest,
				req.nonce,
				req.height,
				req.timeoutTimestamp,
				abi.encodePacked(req.from),
				keysEncoding,
				req.context
			);
	}

	/**
	 * @dev Returns the commitment for the given post response
	 */
	function hash(PostResponse memory res) internal pure returns (bytes32) {
		return keccak256(bytes.concat(encode(res.request), abi.encodePacked(res.response, res.timeoutTimestamp)));
	}

	/**
	 * @dev Returns the commitment for the given post request
	 */
	function hash(PostRequest memory req) internal pure returns (bytes32) {
		return keccak256(encode(req));
	}

	/**
	 * @dev Returns the commitment for the given get request
	 */
	function hash(GetRequest memory req) internal pure returns (bytes32) {
		return keccak256(encode(req));
	}

	/**
	 * @dev Returns the commitment for the given get response
	 */
	function hash(GetResponse memory res) internal pure returns (bytes32) {
		bytes memory response = bytes("");
		uint256 len = res.values.length;
		for (uint256 i = 0; i < len; i++) {
			response = bytes.concat(response, bytes.concat(res.values[i].key, res.values[i].value));
		}
		return keccak256(bytes.concat(encode(res.request), response));
	}
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @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, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * 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.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @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`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage);
        }
    }
}
Types.sol 34 lines
pragma solidity ^0.8.17;

// SPDX-License-Identifier: Apache2

// Outcome of a successfully verified merkle-patricia proof
struct StorageValue {
    // the storage key
    bytes key;
    // the encoded value
    bytes value;
}

/// @title A representation of a Merkle tree node
struct Node {
    // Distance of the node to the leftmost node
    uint256 k_index;
    // A hash of the node itself
    bytes32 node;
}

/// @title A representation of a MerkleMountainRange leaf
struct MmrLeaf {
    // the leftmost index of a node
    uint256 k_index;
    // The position in the tree
    uint256 leaf_index;
    // The hash of the position in the tree
    bytes32 hash;
}

struct Iterator {
    uint256 offset;
    bytes32[] data;
}

Read Contract

host 0xf437bc59 → address
quote 0x0183639e → uint256
quote 0x0183639e → uint256

Write Contract 8 functions

These functions modify contract state and require a wallet transaction to execute.

inscribe 0x658e580e
tuple params
onAccept 0x2ad6a370
tuple incoming
onGetResponse 0xde95bb0e
tuple
onGetTimeout 0x3c11584d
tuple
onPostRequestTimeout 0x8638b50f
tuple request
onPostResponse 0x0c6fab51
tuple
onPostResponseTimeout 0xcefbc1a8
tuple
setHost 0xc85e0be2
address host

Recent Transactions

No transactions found for this address