Skip to Content
DocumentationAnalog GMPOverviewFee Management

Fee Management

Analog GMP offers developers a simple, one-time fee model. Pay once in the source chain's native token to cover all costs for message delivery and execution on any destination chain.

Fee Components

The total fee you pay via msg.value when you submit a message is an aggregate of three distinct costs:

  • Destination Execution Cost: Gas required to run your onGmpReceived function on the destination chain.
  • Protocol & Network Fee: A fee paid to the Analog network for cross-chain verification and security.
  • Relayer (Chronicle) Compensation: Incentive for the off-chain actor submitting the transaction.

The Fee Lifecycle

The process involves estimating the cost, paying it on the source chain, and the subsequent use of those funds to compensate the relayer on the destination chain.

Step 1: Estimate the Fee on the Source Chain

To send a message, first calculate the required fee by calling the estimateMessageCost function on the source chain's Gateway contract.

estimateMessageCost

function estimateMessageCost( uint16 network, uint16 messageSize, uint64 gasLimit ) external view returns (uint256);

The calculation is a two-part process:

A. Calculating an Abstract Gas Cost

First, the protocol computes a normalized gas amount that accounts for both the message payload overhead and the execution gas limit you specify.

The formula is:

TotalGas=(messageSize×gasCoef1)+gasCoef0+gasLimit

Where:

  • gasLimit: The gas you want to reserve for your onGmpReceived function's execution.
  • messageSize: The size of your message payload in bytes.
  • gasCoef0 & gasCoef1: Route-specific constants that represent the fixed and variable overhead gas costs for that particular cross-chain route.

B. Converting Gas to a Token Fee

Next, this abstract TotalGas is converted into a fee in the source chain's native token.

The formula is:

Fee=relativeGasPriceDenominator(TotalGas∗relativeGasPriceNumerator)+baseFeeFee= relativeGasPriceDenominator (TotalGas*relativeGasPriceNumerator) +baseFee

Where:

  • relativeGasPriceNumerator/relativeGasPriceDenominatorrelativeGasPriceNumerator / relativeGasPriceDenominator: This ratio acts as an exchange rate between the destination and source chain gas prices, handling price volatility and differences.
  • baseFeebaseFee: A flat protocol fee for the service, denominated in the source chain's native token.

The resulting FeeFee is the amount you must attach to your submitMessage call.

Step 2: Paying the Fee on the Source Chain

When you call submitMessage, you provide the calculated fee as the msg.value. The Gateway contract validates if the payment is sufficient:

uint256 fee = route.estimateCost(gas); require(msg.value >= fee, "insufficient tx value");

If the payment is sufficient, your message is accepted, a GmpCreated event is emitted, and the fee is held by the Gateway contract on the source chain.

Step 3: Relayer Compensation and Gas Refund on the Destination Chain

  1. Chronicle (relayer):

  2. Refund Mechanism in execute():

    uint256 initialGas = gasleft(); // Start gas tracking // ... executes onGmpReceived ... uint256 gasUsed = initialGas - gasleft(); uint256 refund = (gasUsed * tx.gasprice).min(address(this).balance); // Send refund to relayer (bool success,) = caller().call{value: refund}("");
    • The execute function calculates how much gas was consumed from start to finish.
    • It multiplies the gasUsed by the transaction's gas price (tx.gasprice) to get the total cost the Chronicle paid for the transaction in the destination chain's native currency.
    • It then transfers this refund amount from the Gateway contract's balance to the Chronicle (caller()).