Fees
Understanding how fees are calculated.
Overview
There are 4 different fees the user should know about.
Inbound Fee (sourceChain: gasRate * txSize)
Affiliate Fee (affiliateFee * swapAmount)
Liquidity Fee (swapSlip * swapAmount)
Outbound Fee (destinationChain: gasRate * txSize)
Terms
SourceChain: the chain the user is swapping from
DestinationChain: the chain the user is swapping to txSize: the size of the transaction in bytes (or units)
gasRate: the current gas rate of the external network
swapAmount: the amount the user is swapping swapSlip: the slip created by the
swapAmount, as a function of poolDepth
affiliateFee: optional fee set by interface in basis points
Fees Detail
Inbound Fee
This is the fee the user pays to make a transaction on the source chain, which the user pays directly themselves. The gas rate recommended to use is fast
where the tx is guaranteed to be committed in the next block. Any longer and the user will be waiting a long time for their swap and their price will be invalid (thus they may get an unnecessary refund).
Always use a "fast" or "fastest" fee, if the transaction is not confirmed in time, it could be abandoned by the network or failed due to old prices. You should allow your users to cancel or re-try with higher fees.
Liquidity Fee
This is simply the slip created by the transaction multiplied by its amount. It is priced and deducted from the destination amount automatically by the protocol.
Affiliate Fee
In the swap transaction you build for your users you can include an affiliate fee for your exchange (accepted in $CACAOor a synthetic asset, so you will need a $CACAO address).
The affiliate fee is in basis points (0-500) and will be deducted from the inbound swap amount from the user.
If the inbound swap asset is a native MAYAChain asset ($CACAO or synth) the affiliate fee amount will be deducted directly from the transaction amount.
If the inbound swap asset is on any other chain the network will submit a swap to $CACAO with the destination address as your affiliate fee address.
If the affiliate is added to an ADDLP tx, then the affiliate is included in the network as an LP.
SWAP:CHAIN.ASSET:DESTINATION:LIMIT:AFFILIATE:FEE
Preferred Asset for Affiliate Fees
How it Works
Configuring a Preferred Asset for a MAYAName
Set your preferred asset's chain alias (the address you'll be paid out to), and your preferred asset. Note: your preferred asset must be currently supported by MAYAChain.
For example, if you wanted to be paid out in USDC you would:
Post a
MsgDeposit
to the MAYAChain network with the appropriate memo to register your MAYAName, set your preferred asset as USDC, and set your Ethereum network address alias. Assuming the following info:MAYAChain address:
maya1g8dzs4ywxhf8hynaddw4mhwzlwzjfccakkfch7
MAYAName:
wr
ETH payout address:
0x6621d872f17109d6601c49edba526ebcfd332d5d
The full memo would look like:
The response should look like:
Your MAYAName is now properly configured and any affiliate fees will begin accruing in the AffiliateCollector module. You can verify that fees are being collected by checking the affiliate_collector_rune
value of the above endpoint.
Outbound Fee
This is the fee the Network pays on behalf of the user to send the outbound transaction. To adequately pay for network resources (TSS, compute, state storage) the fee is marked up from what nodes actually pay on-chain by an "Outbound Fee Multiplier" (OFM).
The minimum Outbound Layer1 Fee the network will charge is on /mayachain/mimir
and is priced in USD (based on MAYAChain's USD pool prices). This means really cheap chains still pay their fair share. It is currently set to 10000000000
= $1.00
Fee Ordering for Swaps
Fees are taken in the following order when conducting a swap.
Inbound Fee (user wallet controlled, not MAYAChain controlled)
Affiliate Fee (if any) - skimmed from the input.
Swap Fee (denoted in output asset)
Outbound Fee (taken from the swap output)
To work out the total fees, fees should be converted to a common asset (e.g. CACAO or USD) then added up. Total fees should be less than the input else it is likely to result in a refund.
Refunds and Minimum Swappable Amount
If a transaction fails, it is refunded, thus it will pay the outboundFee
for the SourceChain not the DestinationChain. Thus devs should always swap an amount that is a maximum of the following, multiplier by a buffer of at least 4x to allow for sudden gas spikes:
The Destination Chain outbound_fee
The Source Chain outbound_fee
$1.00 (the minimum)
Remember, if the swap limit is not met or the swap is otherwise refunded the outbound_fee of the Source Chain will be deducted from the input amount, so give your users enough room.
Understanding gas_rate
The gas_rate
property can be used to estimate network fees for each chain the swap interacts with. For example, if the swap is BTC -> ETH
the swap will incur fees on the bitcoin network and Ethereum network. The gas_rate
property works differently on each chain "type" (e.g. EVM, UTXO, COSMOS).
The gas_rate_units
explain what the rate is for chain, as a prompt to the developer.
The outbound_tx_size
is what MAYAChain internally budgets as a typical transaction size for each chain.
Fee Calculation by Chain
MAYAChain (Cacao)
CACAO is the only asset expressed in 1e10 format. All other asset are expressed in 1e8 format.
UTXO Chains like Bitcoin
For UXTO chains link Bitcoin, gas_rate
is denoted in Satoshis. The gas_rate
is calculated by looking at the average previous block fee seen by the MAYANodes.
All MAYAChain transactions use BECH32 so a standard tx size of 250 bytes can be used. The standard UTXO fee is then gas_rate
* 250.
EVM Chains like Ethereum
For EVM chains like Ethereum, gas_rate
is denoted in GWEI. The gas_rate
is calculated by looking at the average previous block fee seen by the MAYANodes
An Ether Tx fee is: gasRate * 10^9 (GWEI) * 21000 (units).
An ERC20 Tx is larger: gasRate * 10^9 (GWEI) * 70000 (units)
Last updated
Was this helpful?