Wardenswap routing
WardenSwap can route a token swap through one path or divide the input among paths across connected decentralized exchange (DEX) pools. For the same pair, input amount and network, splitting offers better quoted net value when its extra output value after applicable fees exceeds any extra gas cost.
- Single path
- The full input follows one path, which can pass through intermediate tokens.
- Split routing
- Parts of the input follow different paths. Each branch can also pass through intermediate tokens.
Pool depth and the value of an extra branch
A trade changes an automated market maker (AMM) pool’s token balances, which can move its price. Sending a large amount through a shallow pool can therefore worsen the average exchange rate. Splitting can reduce the price impact concentrated in that pool by allocating part of the input elsewhere.
Multi-hop routing changes the tokens along a path. An intermediate token can connect pools offering a better combined rate for the source and destination assets. Splitting and multi-hop routing can work together, so the number of branches alone doesn’t establish the output or gas cost.
WardenSwap’s June 17, 2022 Optimism governance proposal described the 2.0 Bloodstone upgrade as reducing the minimum split size from 10% to 1% of a trade. In that version, the search could allocate a smaller share of the input to an additional route. Finer allocation expands the choices available, while the economic benefit still depends on the output gained and the cost of execution.
Compare output and gas in the same unit
Quotes need to cover the same token pair, source amount and network under comparable market conditions. Establish which swap fees each quoted output already reflects. Subtracting an included fee again would understate that route’s value.
Gas and output tokens usually have different units. Value both in a common currency, or convert each route’s gas estimate into receiving-token equivalents using the same valuation. This makes the additional output and additional gas directly comparable. A small output improvement can disappear after execution costs, while a larger improvement may cover them.
The SDK’s gas-price input
The published
WardenBestRate
class reference documents a
gasPrice
input to
getQuote
: the price per gas unit, expressed in the native currency with 18 decimals. For the L2 chains covered by that reference, the parameter uses Ethereum L1 gas pricing. This is a convention for that SDK parameter; comparing complete route costs still requires a total transaction-fee estimate for the selected network.
Hypothetical comparison: Higher output with lower net value
All figures in this BNB Chain comparison are hypothetical. Both routes exchange the same source token and amount for the same receiving token. The assumed outputs already include swap fees, and the gas estimates have been converted to receiving-token equivalents using the same assumed valuation.
| Measure | Single path | Split route |
|---|---|---|
| Output after swap fees, in receiving-token units | 742.5 | 748.9 |
| Gas cost, in receiving-token-equivalent units | 1.4 | 8.1 |
| Net economic value after gas, in receiving-token-equivalent units | 741.1 | 740.8 |
Splitting adds
748.9 - 742.5 = 6.4
units of output, while its extra gas costs
8.1 - 1.4 = 6.7
units. The single path leaves 0.3 more units of net value. At these output amounts, splitting would win if its extra gas cost fell below 6.4 receiving-token-equivalent units; at 6.4, the routes would tie.
Gas remains payable in BNB. These net figures compare economic value after that separate cost; the quoted receiving-token amounts appear in the first row.
Keep the output floor separate
The documented
WardenBestRate.swap
method accepts both
quoteResult
and
minDestAmount
, the minimum destination-token amount. The quote provides the expected output used in the route comparison, while the minimum sets the output floor supplied to the swap. That destination-token floor doesn’t cap the gas cost.
Updated on