LogoLogo
  • Entangle
    • Overview
    • Security Audits
  • Universal Interoperability Protocol
    • Overview
    • Architecture
      • Scalability and Network Stability
        • L2 Utility Blockchains
        • Transmitter Groups
      • Security and Consensus Mechanism
      • Finality
      • Execution Latency
      • Compatibility and Interoperability
    • Developer Guides
      • Getting Started
      • Solidity
        • Simple Abstract Messenger Example
        • Deploying Your Custom EVM Protocol
        • Bridging Tokens with UIP
        • Become an EVM Transmitter
      • Solana
        • Simple Abstract Messenger Example
        • Deploying Your Custom Solana Protocol
        • Become a Solana Transmitter
      • Calculate Cross-Chain Transaction Cost
      • Customizable Message Transmission Options
      • How to Debug Sent Messages
      • SDK Setup
      • Revenue Sharing for Transmitters
      • How to Become a Super Transmitter
    • Endpoints
  • Universal Data Feeds
    • Overview
    • Architecture
      • Data Delivery Methods
        • Pull Model
        • Push Model
      • Oracle Contract & User Interaction
    • Developer Guides
      • Custom Data Feeds
      • Fetch Data via Pull Model (PAYG)
        • EVM Smart Contracts
        • Solana Smart Contracts
      • Fetch Data via Pull Model (Subscriptions)
        • EVM Smart Contracts
        • Solana Smart Contracts
      • Fetch Data via Push Model
        • EVM Smart Contracts
        • Solana Smart Contracts
    • User Guides
      • Accessing Feeds
      • Subscribe to a Data Feed
      • Check Subscription
      • Manage Subscription
      • Renew Subscription
    • Data Endpoints
  • Universal Token Standard
    • Overview
    • Architecture
      • Fee Components
    • Developer Guides
      • Manual Deploy
        • Token Deployment Types
        • Create a Custom Token
        • Factory Blueprint Deployment
        • Examples
          • Initial Setup
          • UTS Connector
            • Mint & Burn Connector Scheme
            • Lock & Unlock Connector Scheme
            • Connector Over Native Currency
          • UTS Token
            • Simple Token
            • Token with Messages
      • Bridge SDK
      • Token Verification
      • Fees Calculation & Gas Estimation Logic
      • Estimations
    • User Guides
      • Launch Universal Token
      • Create a Liquidity Pool
      • Expand Existing Token
      • Transfer Liquidity to Connector
      • Bridging
    • Contract Addresses
  • Entangle Interoperable Blockchain
    • Overview
    • Architecture
    • Developer Guides
      • Set up a Validator Node
      • Delegating to Validators
      • Undelegating from Validators
      • Supported Accounts
  • More
    • Media Kit
    • FAQ
    • Report an Issue
    • Become a Partner
Powered by GitBook
On this page
  • Base Transaction Fee
  • Base Fee Calculation
  • Payload Cost Calculation
  • Final Calculation
  • Optimization of Calculations

Was this helpful?

Export as PDF
  1. Universal Token Standard
  2. Developer Guides

Fees Calculation & Gas Estimation Logic

PreviousToken VerificationNextEstimations

Last updated 1 month ago

Was this helpful?

Fee calculation and gas estimation help you understand the costs involved in cross-chain transactions and deployments. These processes account for things like gas limits, payload size, and currency prices on the source and destination chains to ensure your operations run smoothly. Entangle provides to estimate fees for bridging and deploying tokens, making it easier to plan and execute your transactions.

This page explains the logic for calculating transaction fees and estimating gas costs for cross-chain operations, including base fees, payload costs, and optimization strategies handled off-chain by the backend.

Base Transaction Fee

  • dstGasLimit: User-defined gas limit to be used on the destination network during the redeem transaction.

  • dstGasPriceInWei: Stored in the contract and updated by the backend; represents the gas price on the destination network based on chainId.

  • dstNativePriceInUSDe18: Stored in the contract and updated by the backend; indicates the USD price of the native currency on the destination network, depending on chainId.

  • curNativePriceInUSDe18: Stored in the contract and updated by the backend; reflects the USD price of the native currency on the source network.

Base Fee Calculation

To calculate the base fee in terms of the current native currency:

baseFeeAtCurrentNative = dstGasLimit * dstGasPriceInWei * dstNativePriceInUSDe18 / curNativePriceInUSDe18

This formula determines the amount of native currency required on the source network to execute the transaction (excluding payload), which is then compared to msg.value.

Payload Cost Calculation

To calculate the cost related to the payload, use these parameters:

  • payloadLength: User-defined length of the payload in bytes.

  • dstPricePerByteInWei: Cost per byte of payload in the native currency on the destination network.

  • dstNativePriceInUSDe18: Represents the USD price of the native currency on the destination network.

  • curNativePriceInUSDe18: Represents the USD price of the native currency on the source network.

The payload cost calculation in the current native currency is:

payloadPriceAtCurrentNative = payloadLength * dstPricePerByteInWei * dstNativePriceInUSDe18 / curNativePriceInUSDe18

This formula calculates how much native currency is needed on the source network to cover the payload cost, which is also compared to msg.value.

Final Calculation

To determine the total required amount, sum baseFeeAtCurrentNative and payloadPriceAtCurrentNative, then compare to msg.value. Note that users may incur small losses if dstGasLimit exceeds the actual gas consumed.

Optimization of Calculations

To optimize the process, the backend handles calculations off-chain to minimize contract updates across different destination networks:

  • dstGasPriceInWei

  • dstPricePerByteInWei

  • dstNativePriceInUSDe18

  • curNativePriceInUSDe18

Using these parameters, the backend performs these calculations:

  • Calculate dstGasPriceAtCurrentNative:

    dstGasPriceAtCurrentNative = dstGasPriceInWei * dstNativePriceInUSDe18 / curNativePriceInUSDe18
  • Calculate dstPayloadPriceAtCurrentNative:

    dstPayloadPriceAtCurrentNative = dstPricePerByteInWei * dstNativePriceInUSDe18 / curNativePriceInUSDe18

The backend then sends only the dstGasPriceAtCurrentNative value to the contract. Optionally, it can also send dstPayloadPriceAtCurrentNative if a dynamic price per byte is preferred; otherwise, a static price is more efficient.

APIs