Skip to main content

Overview

The OriginSettler contract is the entry point to Eco Routes Protocol via the ERC-7683 standard. It provides a standardized interface for creating cross-chain orders on the origin chain with enhanced security, replay protection, and proper validation. Contract Location: contracts/ERC7683/OriginSettler.sol

ERC-7683 Compliance

This contract implements the ERC-7683 Cross-Chain Intent Settlement standard, which defines a universal interface for cross-chain order creation and settlement. It supports both:
  • Onchain orders: User directly calls open() to create an intent
  • Gasless orders: Solver calls openFor() with user’s EIP-712 signature

Key Features

  • EIP-712 Signature Verification: Validates gasless orders using typed structured data hashing
  • Replay Protection: Prevents duplicate order execution through vault state checking
  • Comprehensive Validation: Checks deadlines, chain IDs, and origin settler addresses
  • Unified Funding Logic: Atomic intent creation and funding via _publishAndFund
  • ERC-7683 Standard Events: Emits Open event with resolved order data for off-chain solvers

Core Functions

open

function open(OnchainCrossChainOrder calldata order) external payable
Opens a cross-chain order directly on-chain. Called by the user to create and fund an intent atomically. Parameters:
order
OnchainCrossChainOrder
The cross-chain order containing:
  • fillDeadline: Timestamp by which order must be filled
  • orderDataType: Must equal ORDER_DATA_TYPEHASH
  • orderData: ABI-encoded OrderData struct
Emits:
  • Open(bytes32 indexed orderId, ResolvedCrossChainOrder resolvedOrder)
Reverts:
  • TypeSignatureMismatch(): If orderDataType doesn’t match expected hash
Usage Example:
OnchainCrossChainOrder memory order = OnchainCrossChainOrder({
    fillDeadline: uint32(block.timestamp + 1 hours),
    orderDataType: ORDER_DATA_TYPEHASH,
    orderData: abi.encode(orderData)
});

originSettler.open{value: rewardAmount}(order);

openFor

function openFor(
    GaslessCrossChainOrder calldata order,
    bytes calldata signature,
    bytes calldata originFillerData
) external payable
Opens a gasless cross-chain order on behalf of a user. Called by a solver using the user’s EIP-712 signature. Parameters:
order
GaslessCrossChainOrder
The gasless order containing:
  • originSettler: Must match this contract’s address
  • user: Address whose signature is verified
  • nonce: Replay protection nonce
  • originChainId: Must match current chain ID
  • openDeadline: Timestamp by which order must be opened
  • fillDeadline: Timestamp by which order must be filled
  • orderDataType: Must equal ORDER_DATA_TYPEHASH
  • orderData: ABI-encoded OrderData struct
signature
bytes
User’s EIP-712 signature authorizing the order creation
originFillerData
bytes
Optional filler-defined data (currently unused)
Emits:
  • Open(bytes32 indexed orderId, ResolvedCrossChainOrder resolvedOrder)
Reverts:
  • OpenDeadlinePassed(): If current timestamp exceeds openDeadline
  • InvalidOriginSettler(address expected, address actual): If originSettler doesn’t match this contract
  • InvalidOriginChainId(uint256 expected, uint256 actual): If originChainId doesn’t match current chain
  • TypeSignatureMismatch(): If orderDataType doesn’t match expected hash
  • InvalidSignature(): If signature verification fails
Replay Protection: The contract includes built-in replay protection:
  1. If intent is Withdrawn or Refunded, transaction fails
  2. If intent is Initial, it publishes and funds the intent
  3. If intent is Funded, it publishes but doesn’t double-fund

resolve

function resolve(
    OnchainCrossChainOrder calldata order
) public view returns (ResolvedCrossChainOrder memory)
Resolves an onchain order into ERC-7683 compliant ResolvedCrossChainOrder format for off-chain solvers. Parameters:
order
OnchainCrossChainOrder
The order to resolve
Returns:

resolveFor

function resolveFor(
    GaslessCrossChainOrder calldata order,
    bytes calldata originFillerData
) external view returns (ResolvedCrossChainOrder memory)
Resolves a gasless order into ERC-7683 compliant format. Parameters:
order
GaslessCrossChainOrder
The gasless order to resolve
originFillerData
bytes
Optional filler data (currently unused)
Returns:

domainSeparatorV4

function domainSeparatorV4() public view returns (bytes32)
Returns the EIP-712 domain separator used for signature verification. Returns:

Abstract Methods

_publishAndFund

function _publishAndFund(
    uint64 destination,
    bytes memory route,
    Reward memory reward,
    bool allowPartial,
    address funder
) internal virtual returns (bytes32 intentHash, address vault)
Core method for atomic intent creation and funding. Must be implemented by derived contracts. Parameters:
destination
uint64
Destination chain ID where the intent should be executed
route
bytes
Encoded route data containing execution instructions for destination chain
reward
Reward
Reward structure containing token amounts, creator, prover, and deadline
allowPartial
bool
Whether to accept partial funding if full funding is not possible
funder
address
Address providing the funding (msg.sender for open(), order.user for openFor())
Returns:
intentHash
bytes32
Unique identifier of the created or existing intent
vault
address
Address of the intent’s vault contract for reward escrow

Events

Open

event Open(bytes32 indexed orderId, ResolvedCrossChainOrder resolvedOrder)
Emitted when an order is successfully opened via open() or openFor(). Parameters:
orderId
bytes32 indexed
Unique identifier for the order (intent hash)
resolvedOrder
ResolvedCrossChainOrder
ERC-7683 compliant resolved order data for off-chain solvers

Errors

TypeSignatureMismatch

error TypeSignatureMismatch()
Thrown when orderDataType doesn’t match ORDER_DATA_TYPEHASH.

InvalidOriginChainId

error InvalidOriginChainId(uint256 expected, uint256 actual)
Thrown when the origin chain ID in the order doesn’t match the current chain.

OpenDeadlinePassed

error OpenDeadlinePassed()
Thrown when attempting to open an order after the openDeadline has passed.

InvalidSignature

error InvalidSignature()
Thrown when EIP-712 signature verification fails.

InvalidOriginSettler

error InvalidOriginSettler(address expected, address actual)
Thrown when the originSettler address in the order doesn’t match this contract.

InsufficientNativeRewardAmount

error InsufficientNativeRewardAmount()
Thrown when sent native token amount is less than required reward amount.

EIP-712 Type Hashes

GASLESS_CROSSCHAIN_ORDER_TYPEHASH

bytes32 public GASLESS_CROSSCHAIN_ORDER_TYPEHASH = keccak256(
    "GaslessCrossChainOrder(address originSettler,address user,uint256 nonce,uint256 originChainId,uint32 openDeadline,uint32 fillDeadline,bytes32 orderDataType,bytes32 orderDataHash)"
)
EIP-712 type hash for gasless cross-chain orders used in signature verification.

Implementation Notes

Security Features

  1. Replay Protection: The _publishAndFund method checks vault state to prevent duplicate funding
  2. Deadline Validation: Both open and fill deadlines are validated to ensure timely execution
  3. Chain ID Verification: Ensures orders are executed on the correct chain
  4. Signature Verification: Uses EIP-712 for secure off-chain authorization

Gas Optimization

  • Uses uint32 for timestamps (safe until year 2106)
  • Efficient ABI encoding/decoding of nested structs
  • Direct orderData.maxSpent usage instead of reconstruction

Integration Guide

To integrate with OriginSettler:
  1. Encode your OrderData with destination, route, reward, portal, deadline, and maxSpent
  2. For onchain orders: call open() with proper msg.value for native rewards
  3. For gasless orders: obtain user’s EIP-712 signature and call openFor()
  4. Listen for Open events to track order creation
  5. Use resolve() or resolveFor() to get standardized order format for solvers

Build docs developers (and LLMs) love