🍔Swap Aggregation
How Rango batch multiple transactions into a single transaction?
Last updated
How Rango batch multiple transactions into a single transaction?
Last updated
In Rango, we batch multiple transactions in a single transaction whenever possible.
For example, imagine the user wants to swap its MATIC on Polygon to USDC on Osmosis. The usual route would be to first swap MATIC to AXLUSDC and then bridge it using Satellite (Axelar) to Osmosis.
But Rango can aggregate these two steps in a single step, enabling to swap and bridge in the same transaction as it can be seen in image below:
To enable this feature, Rango uses smart contracts. Also message passing protocols are used to batch three step transactions into a single transaction.
For example, in the case below, IBC+Osmosis+IBC steps are batched into a single transaction. IBC protocol is used for both bridging and message passing. As a result, the user can convert its native ATOM to native JUNO in a single transaction using trust-less protocols.
Since aggregations batch multiple transactions into a single transaction, the slippage could be applied at each step. There is a trade-off between slippage and transaction failure rate in the case of on-chain swaps. To reduce failure rate without exposing the user to higher slippage, in case of three-step aggregations, we try to use half the slippage for the initial step to leave enough room for the third step transaction.
For example if the user sets max slippage tolerance of 3% for a batch of swap+bridge+swap aggregation, on the first swap we only use 1.5% slippage tolerance. This both helps prevent MEV in the first step and also reduce error rates in the third step.
In Solana aggregation, two cases occur:
1. When an on-chain swap is executed in Solana, and one side is SOL, all WSOL balance in wallet will be converted to SOL. This behavior is inherent to the Jupiter aggregator, and we don't have any control over it.
2. When a token is swapped and then bridged from Solana to other blockchains, there might be a residual amount of tokens left in the user's wallet because the aggregation in AllBridge and DeBridge performs the swap but the bridge transaction is executed with minimum expected output.