Wardenswap routing

Updated on

WardenSwap’s decentralized exchange aggregator can divide a swap among connected liquidity pools. Splitting helps when the combined output improves enough to cover any extra execution cost; the result depends on the input amount, available liquidity, and gas costs.

Browse the sections
Route scope
Connected pools on the selected network, with intermediate-token paths where they improve the trade.
Settlement
The routed pool swaps execute on-chain within one atomic transaction.

When does splitting improve a swap?

An automated market maker (AMM) calculates prices from its pool’s liquidity. A trade can move that price as it changes the pool’s balances. Sending the entire input through a shallow pool can therefore produce a worse average execution price than distributing it among pools with better combined liquidity.

WardenSwap can allocate different portions of the input to different routes. Equal portions aren’t required: the useful allocation depends on how each pool prices its portion of the trade. Splitting helps only when those combined quotes improve the overall result after costs.

In its Optimism funding proposal published June 17, 2022, WardenSwap described the 2.0 Bloodstone upgrade as permitting split allocations as small as 1% of the trade, compared with 10% previously.

How do split routes differ from extra hops?

Split trading
Different portions of the source amount travel along different routes, contributing to the combined destination-token output.
Deep routing
A path includes an intermediate token when that additional connection improves the trade. The intermediate exchange can use a different pool.

These mechanisms can work together. A split route can contain several pool swaps, so the number of routes and the number of pools used needn’t match. Each additional hop changes the path’s output and execution work, which affects whether that path is worthwhile.

Wardenswap routing: How do split routes differ from extra hops? - diagram
Illustration: How do split routes differ from extra hops?

View image file

How does gas affect route selection?

A route with a higher token output can also cost more to execute. Comparing the output gain with the additional network cost requires a common unit of value. The number of pools alone doesn’t establish which route gives the better net result.

The documented WardenBestRate.getQuote interface takes source and destination token addresses, amountIn , and gasPrice . Its quote is therefore tied to a particular input amount and gas-price assumption. The reference specifies gasPrice as a price per gas unit in native currency with 18 decimal places; for its documented L2 quote mode, that input is the Ethereum L1 gas price.

For its Optimism deployment, the June 17, 2022 proposal also described an Address Table and Data Serialization to make calldata smaller. That optimization targeted the cost of publishing transaction data to Ethereum, alongside the separate task of finding favorable pool prices.

A split that covers its extra gas cost

A split beats the single-pool quote here while its additional gas cost is worth less than 11 destination-token units. Every amount, allocation, quote, and gas valuation in this comparison is hypothetical. Both options use the same tokens, network, input amount, and pool state, and their quoted outputs already include all swap fees.

Input: 264 source-token units. The single-pool quote is 391 destination-token units before gas. The split assigns 110 source-token units to one route and 154 to another, with quoted outputs of 168 and 234 destination-token units respectively.

The split’s combined quoted output is 168 + 234 = 402 destination-token units, an improvement of 11. Assume its additional network cost is valued at 4 destination-token units. Its net advantage is (168 + 234 - 391) - 4 = 7 destination-token units of value.

The gas valuation is a comparison measure; gas is paid in the network’s native asset. The 402-unit figure remains a quoted token output, and the 7-unit figure measures the cost-adjusted advantage. A change in trade size, pool state, or gas valuation requires a new comparison.

What does atomic execution establish?

The pool operations within WardenSwap’s routed swap succeed or revert together. Atomic execution keeps those operations in one transaction, while the quote reflects the market state used to calculate it. Pool conditions can change before execution, so a favorable split quote alone doesn’t establish a completed swap or guarantee that its quoted output will be received.