Tx Fee calculation

BTC series

Supported Chain

BTC, BCH, LTC, DOGECOIN

Calculation

  • Tx Unit Price = Max((Suggested Price + PREMIUM_AMOUNT), (Suggested Price * FEE_FACTOR))

  • Restrictions

    • Tx Unit Price < MAX_SATOSHI_PER_BYTE

    • Tx Fee = Tx Unit Price * vbyte of a transaction < FEE_LIMIT

Suggested Price comes from BlockChair and mempool.space API.

Parameters

Parameters
Descriptions

XXX_MAX_SATOSHI_PER_BYTE

Maximum Satoshi per vbyte

XXX_FEE_LIMIT

Miner fee limit of one transaction

XXX_WITHDRAW_FEE_FACTOR

Fee factor to adjust withdraw tx price at higher price.

XXX_WITHDRAW_FEE_PREMIUM_AMOUNT

Premium amount to adjust withdraw tx price at lower price.

XXX_SWEEP_FEE_FACTOR

Fee factor to adjust sweep tx price at a higher price.

XXX_SWEEP_FEE_PREMIUM_AMOUNT

Premium amount to adjust sweep tx price at a lower price.

XXX is the place holder of chain name. eg. BTC/BCH/LTC/DOGE

Ethereum series

Legacy

Support Chains

BSC, OKC

Calculation

  • Gas Limit

    • Native Token Transfer (Withdraw and sweep): 21000

    • ERC20 Token Transfer (Withdraw) : 100000

    • ERC20 Token Transfer (Sweep) :

      • Zero balance destination: 100000

      • Non-zero balance destination: 70000

  • Gas Price = Get from historical record or API

  • Transaction Fee = Gas Price * Gas Used

EIP1559

Support Chain

Ethereum, Polygon(Matic), Avalanche C-Chain

Calculation

  • Base Fee: Get from historical record or API

  • Priority Fee: Get from historical record or API

  • Withdraw Max Gas Price Max Gas Price = Base Fee * Online Base Fee Factor + Priority Fee

  • Sweep Max Gas Price Max Gas Price = Base Fee * Offline Base Fee Factor + Priority Fee

  • Max Gas Price < Gas Price Limit

  • Gas Limit

    • Native Token Transfer (Withdraw and sweep): 21000

    • ERC20 Token Transfer (Withdraw): 100000

    • ERC20 Token Transfer (Sweep) :

      • Zero balance destination: 100000

      • Non-zero balance destination: 70000

  • Transaction Fee = Gas Price * Gas Used

Parameters

Parameters
Descriptions

ETH_TRANSFER_GAS

Gas limit used in ETH transfer (21,000)

ETHEREUM_DEFAULT_GAS_LIMIT

Gas limit used in ERC20 transfer (100,000)

ETHEREUM_MAX_BASE_PLUS_PRIORITY_GWEI

Gas price limit

ONLINE_BASE_FEE_FACTOR

Base fee factor while preparing online sign tx.

OFFLINE_BASE_FEE_FACTOR

Base fee factor while preparing offline sign tx.

Base Fee * Base Fee Factor + Priority Fee < Gas Price Limit

If violates this rule, the transaction will be prepared failed and need to be processed manually.

Tron

Bandwidth

  • Unit price: 1000 sun.

  • Bandwidth point: tranaction bytes.

Energy

Only apply to TRC20 Transfer

Calculation

TRX consumed = Bandwidth * Bandwidth Unit Price + (Base Energy * ( 1 + Max Energy Factory )) * Energy Unit Price

# USDT transfer to new address
# https://tronscan.org/#/transaction/f9d3693a7d6b9a6a75d85b536392d8afeb4a7ef7e45da81521217ffbe5591f02
345 * 1000 + (29,650 * (1 + 1.2)* 420 = 27741600 = 27.741600 TRX

# USDT transfer to old address
# https://tronscan.org/#/transaction/601c3325abd5ccff7e5bdef331e54bb6c2ff7b3f470f2f230776567f0ae8d504
345 * 1000 + (14,650 * (1 + 1.2)* 420 = 13881600 = 13.881600 TRX

Parameters

Parameters
Descriptions

TRX_FEE_LIMIT

Max tx fee. 45 TRX

XRP

Calculation

  • Get current_queue_size , max_queue_size, minimum_fee, median_fee , open_ledger_fee from API fee | XRPL.org

  • Get queue occupancy rate : current_queue_size / max_queue_size

  • The lowest fee (queue size is empty) : round(min( max(minimum_fee * 1.5, round(max(median_fee, open_ledger_fee) / 500)), 1000, ), )

  • Get possible_fee_medium

    • if queue occupancy rate is over 0.1 :

      • possible_fee_medium : round((minimum_fee + median_fee + open_ledger_fee) / 3,)

    • if queue occupancy rate is lower or equal to 0.1:

      • possible_fee _medium : max(10 * minimum_fee, round((minimum_fee + median_fee) / 2),)

  • Transaction Fee:

    • if queue occupancy rate is 0:

      • Transaction Fee : the lowest fee

    • if queue occupancy rate is bigger than 0 and smaller than 1:

      • Transaction Fee : round( min( possible_fee_medium, fee_low * 15, 10000,),)

    • if queue occupancy rate is 1:

      • Transaction Fee : round( min( max(10 * minimum_fee, round(max(median_fee, open_ledger_fee)* 1.1)), 100000, ),)

Fee Limit

2 XRP

Solana

Fee is deterministic in Solana, and is determined by the number of signatures in a transaction + extra compute budget + prioritization fee.Deterministic Transaction Fees | Solana Docs

Calculation

  • (S) Fee Per Signature: 5000 lamports (fixed by network, and is likely to decrease in the future)

  • (N) Number of Signatures:

    • Withdraw: hot wallet + nonce authority = 2

    • Sweep: ceil(accountCount / 5) * 2 + accountCount

      • each transaction can container ~5 transfers + 1 nonce authority + 1 invoker

      • e.g. for sweeping 100 accounts, it will create ~20 txs, and the number of signatures will be (100 / 5) * 2 + 100 = 140

  • (C) Extra compute budget: 0 (we do not need to use extra compute budget)

  • (P) Prioritization Fee: 0 (we do not use prioritization)

  • Final fee = (S * N) + C + P

ADA

Calculation

  • call epoch/latest/parameters API Blockfrost.io ~ API Documentation

  • calculate the maximum transmission fee

    • max_tx_fee = (max_tx_size*min_fee_a) + (min_fee_b) + (max_tx_ex_steps * price_step) + (max_block_ex_mem * price_mem)

    • max_tx_size / min_fee_a / min_fee_b/max_tx_ex_steps/price_step/max_block_ex_mem/price_mem are the value from parameters api response

  • calculate the minimum transmission fee

    • min_tx_fee = ((the length of signed transaction CBOR bytes)*min_fee_a) + (min_fee_b)

  • if min_tx_fee is smaller than or equal to max_tx_fee , use min_tx_fee as transaction fee

Last updated