Gas Compensation

Overview

MTX is processed on SL-Chain and executed in the destination execution environment. SL-Chain is the application-specific sequencing layer for dApps that processes MTX based on the Verifiable Sequencing Rules and Verifiable Aggregation Rules. The processed MTX is executed in the destination execution environment where the dApp is deployed.

Processing MTX on SL-Chain consumes computational and storage resources, and submitting MTX to SL-Chain will incur gas costs.

  • Testnet Stage: To cover SL-Chain costs, the Semantic Layer provides a faucet allowing users and dApps to obtain free gas tokens.
  • Mainnet Stage: TBD, with the possibility to use Semantic Layer token as a gas token.

The following sections focus on gas costs incurred on the destination execution environment.

Types of Gas Costs

Gas costs on the destination chain are categorized as follows:

  1. ERC-4337 User Operations: Costs for executing user operations.
  2. dApp Operations: Costs for executing dApp operations, if provided in the UserMTX.
  3. Solver Operations: Costs for executing solver operations.

The MTX executor submitting the final PackedMTX for on-chain execution on the destination execution environment must cover the upfront transaction costs. The SL execution contract calculates the gas used for each operation, deducts the costs from the responsible accounts, and transfers the funds to the PackedMTX.beneficiary address (usually the MTX executor address) to reimburse its gas costs.

Since user operations are managed by the ERC-4337 contract, gas costs for these operations are handled by the ERC-4337 entry point contracts. The SL node provides the PackedMTX.beneficiary as the ERC-4337 beneficiary address when sending user operations for execution, allowing the SL node to receive gas reimbursement from the ERC-4337 contract.

Calculating Gas Costs

Gas costs for each operation are calculated by comparing gasleft() before and after the operation is executed.

    uint256 preGas = gasleft();

    // some operations

    uint256 afterGas = gasleft();
    uint256 gasUsed = preGas - afterGas;

SL Deposit Manager

The SL execution contract includes an SL deposit manager to handle gas reimbursement for dApp and solver operations.

dApp developers and solvers can deposit funds into this contract in advance to cover gas costs for their own dApp and solver operations. Note for dApp operations, it is also optional to let user pay for dApp operations, as dApp operations are nested within UserMTX. See section “Gas Costs for dApp Operations” for details.

In addition to depositing in advance, dApp developers and solvers can sign a permit authorizing the SL execution contract to transfer funds from their EOA address to cover gas costs on demand.

Gas costs for dApp and solver operations are calculated separately. The SL execution contract deducts funds from deposited balances, and the total deducted amount is sent to the PackedMTX.beneficiary address.

Gas Costs for ERC-4337 User Operations

Semantic Layer supports ERC-4337 and uses the ERC-4337 entry point contract for executing user operations. Therefore, gas estimation and costs are handled by the ERC-4337 contract. User operations are sent to the ERC-4337 contract with the beneficiary address set to PackedMTX.beneficiary, and the ERC-4337 contract sends the gas compensation to this address.

Gas costs are deducted from the user's ERC-4337 smart contract wallet. If dApps wish to sponsor these costs, dApp developers can implement an ERC-4337 paymaster contract. Gas costs are first deducted from the paymaster, and any remaining costs are deducted from the user's wallet if the paymaster does not cover the full amount.

Gas Costs for dApp Operations

The UserMTX.from address is responsible for covering gas costs for dApp operations by default. Under default, the user pays for dApp operations.

dApps can also sponsor dApp operations. A sponsor and maximum sponsorship amount can be specified in the UserMTX. If sponsorship is specified, the SL execution contract verifies whether the sponsor allows sponsorship for the UserMTX.from address. If allowed, gas costs are first deducted from the sponsor's balance in the SL deposit manager, and any remaining funds are deducted from UserMTX.from if sponsorship does not fully cover the gas costs.

Gas Costs for Solver Operations

The SolverMTX.from address is responsible for covering gas costs for solver operations.

Solver operations often involve complex executions and are typically for the solver's own benefit only, thus solver operations cannot be sponsored. The solver operations costs must be fully covered by the SolverMTX.from address. However, if dApps want to incentivize solvers, dApps can include a payment to the solver as part of its dApp operations.