Mdex trading fees connect quoted output with final account cost
last updated
Mdex trading fees are embedded in the swap calculation, while the completed trade also consumes network gas and may execute against reserves that changed after the quote. A quote expresses expected output after the route-level pool calculations, not a final account statement. The wallet separately estimates execution cost in the network's native asset. Before signing, confirm that the native balance covers the wallet's current estimate. Token transfer rules can also affect balance changes on supported routes. Reconcile a completed swap with the original quote, transaction receipt, and before-and-after balances. That comparison separates the pool charge from price impact, gas, and token-level deductions. If a required approval was submitted first, treat its gas as a separate cost.
The short version: Compare the signed quote with the receipt and final balances to separate pool charges, gas, price movement, and token deductions.
Assemble the comparison from quote, wallet, and receipt
Three records answer different cost questions: the quote describes the proposed exchange, the wallet prices transaction execution, and the receipt records what the network processed.
Save enough information to compare the same action after confirmation. The route and quoted output show what was proposed. The minimum output and deadline show the signed execution boundaries. The wallet request identifies whether the call is an approval or a swap. Finally, the receipt status, gas fields, and balance changes reveal the completed account state.
- Record the input amount, expected output, and route shown with the quote.
- Note the minimum output and deadline encoded for the swap.
- Keep the wallet's native-asset execution estimate separate from token amounts.
- After confirmation, read the receipt status and actual network cost.
- Compare the input, output, and native-asset balances around the transaction.
Price impact belongs in this comparison, but it is not another transfer to a fee collector. It describes how the trade size and pool reserves affect the exchange rate. Adding it to a displayed pool percentage would count different effects as though they were the same charge.
The route carries the pool charge into the quote
Mdex calculates output along the selected pool path, applying the applicable pair fee and reserve relationship at every hop. The displayed output should therefore be treated as a net route estimate, not as a gross amount followed by a second wallet debit for the pool charge.
Fee configuration belongs to the pair
The factory implementation contains a default fee setting and a mechanism for supported pairs to use their own configured value. Its output calculation reduces the effective input by that fee before applying the reserve formula. A single percentage cannot describe every possible pair configuration, so the value associated with the quoted route matters more than a rate copied from another market or period.
Route length changes the calculation
A path can pass through one pool or several connected pools. Each hop turns its output into the next hop's input, so its reserve state and applicable fee influence the final quote.
Direct pool
A direct route uses one pair calculation. Its simplicity does not guarantee the best output because available liquidity and trade size still shape price impact.
Multi-pool path
A multi-pool route repeats the calculation across its hops. Extra hops can improve access to liquidity, yet each one introduces another reserve state and pair fee into the output. Compare the final quoted output rather than judging a route only by its hop count.
Why can the final received amount differ from the quote?
The final amount can differ because a quote reads pool reserves before submission, while execution uses the reserves present when the transaction reaches the chain. Other confirmed swaps may change those reserves during the interval.
For an exact-input swap, the input stays fixed and the output can move within the signed limit. The router checks the calculated or measured output against the minimum accepted amount. If execution would fall below that boundary, the swap should revert rather than settle at the poorer amount. A successful transaction may still deliver less than the earlier estimate while remaining above the minimum.
The quote age, route, trade size, and pool depth all affect that gap. Refreshing a quote provides a new output estimate before signing; it does not change a transaction that has already been broadcast.
Approval and swap calls spend gas separately
An approval changes how much of an input token a router may transfer, while the swap performs the exchange. When the existing allowance is insufficient, those actions normally produce separate transactions and separate network costs.
A confirmed approval does not prove that the later swap succeeded. It can remain in effect after a failed or abandoned swap, depending on the allowance that was granted and any subsequent spending. Reconciliation should therefore match each receipt to its function. Count approval gas only when that approval was actually submitted, and do not label it as a pool trading fee.
Minimum output defines the execution boundary
The minimum output converts the selected slippage tolerance into a contract condition. Widening that tolerance does not lower the pair fee; it permits execution across a broader range below the displayed quote.
A narrow boundary offers less room for reserve movement but may make a transaction more likely to revert. A broad boundary increases the difference that the signed call can accept. The deadline provides another limit: an expired call cannot execute through the router even if the pool later returns to the earlier price. Both fields belong beside the quote when judging the final result.
A hypothetical quote-to-balance reconciliation
All amounts, rates, quotes, limits, gas values, and account balances in this example are hypothetical. A reader enters 1,248 input units. The route shows a 0.28% pair fee, quotes 736.4 output units, sets a 725.4-unit minimum, and carries a 0.0042 native-unit gas estimate.
Normal path
The illustrative pool charge is 1,248 × 0.0028, or 3.4944 input units. That amount is already reflected in the route calculation; it is not an extra 3.4944-unit wallet transfer after the swap. The account holds 0.0200 native units, so the stated prerequisite is present before submission.
The receipt later shows success and an actual execution cost of 0.0048 native units. The output balance increases by 729.8 units. Since 729.8 exceeds the signed minimum of 725.4, the execution condition held even though the earlier quote was higher. The final account changes are 1,248 input units spent, 729.8 output units received, and 0.0048 native units consumed.
Edge case: The native balance is missing
Keep the same proposed swap but change the hypothetical native balance to 0.0038 units. It does not cover the 0.0042-unit estimate, so the account is not ready to submit. Reducing the token input may alter the quote, but it does not turn that token into native gas. The account needs enough native balance to cover a fresh wallet estimate. Until it does, leave the swap unsigned.
The receipt records the network execution cost
The receipt replaces the wallet estimate with transaction evidence. Read its status first, then use the gas consumed and effective gas price to derive the paid execution cost in the network's native unit.
The wallet may have displayed a maximum or provisional amount before signing. That number helps with readiness, but it is not necessarily the final debit. The receipt also ties the cost to a transaction hash and block, which prevents an approval estimate, a swap estimate, and a confirmed charge from being mixed together.
Token rules can alter balance-level results
Some tokens deduct amounts during transfers, so a nominal input or output may not equal the balance change observed by the receiving contract or account. This behavior is separate from the pair fee and from network gas.
Mdex router code includes swap functions that measure the recipient's balance increase before enforcing the minimum output for fee-on-transfer tokens. The selected function and token behavior therefore matter. A standard quote alone may not expose every token-level deduction. After confirmation, compare actual balances and preserve the signed minimum as the acceptance boundary instead of inferring the received amount from the input debit.
Failed and pending transactions require different accounting
A pending transaction has no final receipt, so its execution cost and swap result are not yet settled. The interface may show an estimate or pending state, but neither establishes a completed exchange.
A reverted transaction has a receipt with a failed status. Its attempted state changes are rolled back, yet the network still charges for computation already performed. The input and output token balances should not be reconciled as a successful trade, while the native-asset gas debit remains relevant.
A separately confirmed approval is unaffected by a later swap failure. If another transaction replaces the pending call, use the confirmed replacement's receipt and resulting balances. This distinction prevents a failed swap, an earlier approval, and a replacement transaction from being merged into one supposed fee.
When is a fresh quote the safer choice?
A fresh quote is warranted when the route, input amount, pool state, fee setting, or deadline no longer matches the proposed transaction. A changed native balance calls for a fresh wallet estimate and readiness check.
Do not use an old output estimate to explain a newly constructed call. Requote after an expiry, a material delay, a route change, or any edit to the input. Then inspect the new minimum and wallet estimate before signing. Once a transaction confirms, stop comparing proposals and reconcile its own receipt with the resulting balances. That final account state determines whether the swap completed within the accepted boundary and what each cost component actually consumed.
Answers to common questions
Can all Mdex swap costs be added into one number?
Only after choosing a common valuation unit and a consistent valuation time. The pool charge uses the input token, execution gas uses the network's native asset, and an output difference uses the output token. Converting them can produce an economic-cost estimate, but that estimate is not a single on-chain fee because the conversion prices introduce another assumption.
Does a wider slippage setting reduce the fee charged by a pool?
No. Slippage tolerance changes the minimum output that the transaction will accept; it does not change the pair fee used in the route calculation. A wider setting may allow execution after a larger adverse reserve change, while a narrower setting may cause the swap to revert sooner. The applicable fee and accepted output boundary remain separate inputs.
What can change a wallet gas estimate before signing?
The transaction data, selected route, token behavior, and network fee conditions can change the estimate. An approval and a swap also execute different contract calls, so their gas estimates should not be compared as interchangeable charges. Treat each estimate as provisional until that exact transaction confirms and produces a receipt.
Will a fee-on-transfer token always make the swap fail?
No. Success depends on whether the selected router function supports that token behavior and whether the resulting output satisfies the minimum. A transfer deduction can change the effective pool input or received output. If the measured result falls below the signed boundary, the transaction can revert instead of settling at that amount.
Why can a smaller trade have a higher cost percentage?
Network execution cost does not fall in direct proportion to the token amount being swapped. When similar gas is divided by a smaller trade value, it represents a larger percentage of that value. Pool price impact may decrease with the smaller input, so the gas percentage and pool impact can move in opposite directions.
Where is the final cost of a completed Mdex swap recorded?
No single field necessarily contains every component. The receipt records transaction status and network execution data, while the route calculation embeds the pool fee in the token output. Before-and-after balances show what left and entered the account. Read those records together, keeping native-asset gas separate from token-denominated amounts.