
Flash Swaps
2.4 Flash Swaps
In DEX Raiden v1, a user purchasing QWE with XYZ needs to send the XYZ to the contract before they could receive the QWE.
This is inconvenient if that user needs the QWE they are buying in order to obtain the XYZ they are paying with. For example, the user might be using that QWE to purchase XYZ in some other contract in order to arbitrage a price difference from DEX Raiden, or they could be unwinding a position on Maker or Compound by selling the collateral to repay DEX Raiden.
DEX Raiden v1.1 adds a new feature that allows a user to receive and use an asset before paying for it, as long as they make the payment within the same atomic transaction.
The swap function makes a call to an optional user-specified callback contract in between transferring out the tokens requested by the user and enforcing the invariant. Once the callback is complete, the contract checks the new balances and confirms that the invariant is satisfied (after adjusting for fees on the amounts paid in). If the contract does not have sufficient funds, it reverts the entire transaction. A user can also repay the DEX Raiden pool using the same token, rather than completing the swap. This is effectively the same as letting anyone flash-borrow any of assets stored in a DEX Raiden pool (for the same 0.30% fee as DEX Raiden charges for trading).

Last updated