Contract-fillable Liquidity Made Simple

Swap tokens at the best prices with Asset Swapper

Tap into 0x’s networked liquidity pool with Asset Swapper to bring programmatic token exchange to your DeFi project!

Since June 2019, there has been a significant increase in liquidity flowing into the 0x Network. 0x relayers like Radar Relay now have the lowest slippage compared to other DEXs (like Uniswap, Kyber, IDEX, etc.) for $10k trades on popular pairs like ETH/DAI, ETH/USDC, and DAI/USDC. This is primarily due to liquidity providers growing the number of standing orders as part of our Market Making Program. We have also seen a rapid influx of DeFi projects filling those orders by leveraging contract-fillable liquidity (CFL), which describes the ability for smart contracts to programmatically swap tokens through decentralized exchanges.

After working with CFL integrators like dYdX, we discovered that it was too complex sourcing liquidity from 0x via existing smart contract architectures. In response, we released Asset Swapper, a powerful tool that enables DeFi projects to automatically find liquidity, pass it into their smart contracts, and fill orders at the best prices.

Asset Swapper is a convenience package that provides a simple way for smart contracts to exchange Ethereum-based tokens. Developers can flexibly use Asset Swapper to swap tokens in a single line of code or build custom integrations for more advanced token trades.

In addition to brand new documentation, we built a landing page to make it even easier integrating Asset Swapper. The page surfaces real-time slippage data for popular trading pairs and features a code demo that shows developers how to integrate with their smart contracts. Asset Swapper greatly reduces the friction in exchanging tokens and enables capital to flow seamlessly between crypto protocols, allowing for the creation of markets that couldn’t exist in the traditional financial system. We are excited to see how teams utilize this tool to launch new financial products that grow the DeFi pie!

Use Cases within Open Finance

DeFi projects ranging from decentralized lending platforms to crypto trading bots need an easy way to consume liquidity. Developers and businesses can use Asset Swapper with their existing smart contract infrastructure to improve their product UX, execute new trading strategies, and create a variety of novel financial markets. Some of the use cases we have explored so far include:

Administering convenience functions, such as wrapping ETH or setting allowances, before function execution. dYdX utilizes this type of contract when users enter and exit positions. 0x Instant also uses a similar technique with the Forwarder contract to abstract away the process of wrapping ETH when sourcing orders and performing market buys in the 0x Network.

Executing arbitrary transactions in order to combine multiple actions together atomically for improved UX. When closing a Maker CDP, for example, smart contracts buy and burn MKR. Taking it a step further, services built on MakerDAO like DeFi Saver aim to abstract away even the usage of MKR to interact with CDPs by deploying contracts that swap ETH or DAI for MKR when topping up positions.

Performing risk-free atomic arbitrage across exchanges. We have observed a plethora of arbitrage bots swapping tokens systematically between various DEXs and CEXs through these contracts.

Pre-baking terms of an asset sale into a smart contract so they can be trustlessly executed in the future. These contracts can swap out tokens custodied in the smart contract after a prompt by a third-party who may or may not be the taker. Set uses this functionality when rebalancing TokenSet index funds. Loan issuance platforms can also use these types of contracts when re-collateralizing loans.

Accessing CFL with Asset Swapper

Programmatically executing orders through 0x requires 3 steps: Sourcing orders from 0x’s networked liquidity pool, passing orders through integrators’ smart contracts, and filling orders via the 0x Exchange Contract.

0x orders can be found by querying a 0x relayer via the Standard Relayer API specification (or 0x Mesh in the near future). Interactions with the API occur entirely off-chain, meaning Ethereum transactions are not involved yet. Asset Swapper provides a simple interface to fetch orders from a provided Standard Relayer API and give a price quote for the desired token swap.

Once orders are found, they need to be passed through the integrator’s smart contracts. Up until now, all interactions with 0x protocol have been off-chain. To consume the output fetched off-chain in a smart contract, it needs to be transmitted on-chain. To then pass 0x orders on-chain, integrators provide additional parameters for smart contract calls. Asset Swapper includes a SwapQuoteConsumer utility tool that converts quotes provided by SwapQuoter to formats that are well-suited for contract calls.

Once the orders have been passed, integrators can automatically fill orders by calling the 0x Exchange Contract. To learn more about how to use Asset Swapper, check out this technical guide. If you have any questions or need assistance integrating, do not hesitate to reach out to our engineers on our Discord server.



Get started sourcing token liquidity for your decentralized application at 0x.org/asset-swapper and join the dozens of projects already building on 0x!