title | description |
---|---|
Smart Swap |
This page introduces the Smart Swap functionality provided by the Skip API to improve swap speed, price, and customization. |
Smart Swap refers to a broad range of functionality we're building out to improve swap speed, price, and customization.
At this time, the main use case for smart swap is improving trade execution price by enabling third-party routers (e.g. Hallswap) and trade splitting. But much more is on the way!
This doc covers:
- All the different features Smart Swap enables
- Describes how to use each of them
If you're using the @skip-router
library, you must use v4.0.0 or later to use Smart Swap.
All Smart Swap features are controlled with a single configuration object:
@skip-router
library:smartSwapOptions
object passed inSkipRouter.route
optionsSkipRouter.msgsDirect
options- REST API:
smart_swap_options
parameter passed in/v2/fungible/route
and/v2/fungible/msgs_direct
Read on for more info about the individual features and how to use each of them.
(For the rest of this doc, examples will show how to use Smart Swap with the @skip-router
library by configuring it on SkipRouter.route
. The only changes you'll notice between this context and the REST API is naming conventions)
The Skip API searches over multiple 1st and 3rd-party routers to find the route that gives you best execution. This has a chance of improving the price at which your user's swap executes.
The swap routers currently supported are:
- Skip API's in-house Router
- Hallswap's Dex Aggregator
- Osmosis's Sidecar Query Service (SQS) (Used in the Osmosis frontend)
Just pass the smartSwapOptions
object into your route request. You're not required to activate a particular flag.
const route = await skipClient.route({
smartSwapOptions: {}, // smart swap object
sourceAssetDenom: "uusdc",
sourceAssetChainID: "noble-1",
destAssetDenom: "utia",
destAssetChainID: "celestia",
amountIn: "1000000", // 1 uusdc
cumulativeAffiliateFeeBPS: "0"
}
That's it! Skip API will now consider all routers we have available and give your user the best one.
Route splitting is a technique in swap optimization where a user's trade is split into several parts and swapped through separate pools. It can help lower price impact and increase output for the user, compared to swapping with a single route. This technique is especially effective when one or both of the tokens the user is swapping is a commonly paired asset on a DEX (e.g. OSMO is paired with almost everything on Osmosis).
Just pass the splitRoutes
flag in the smartSwapOptions
object.
const route = await skipClient.route({
smartSwapOptions: {
splitRoutes: true
}, // smart swap object
sourceAssetDenom: "uusdc",
sourceAssetChainID: "noble-1",
destAssetDenom: "utia",
destAssetChainID: "celestia",
amountIn: "1000000", // 1 uusdc
cumulativeAffiliateFeeBPS: "0"
}
The API supports swapping on an EVM chain, followed by a CCTP/Axelar transfer over to the Cosmos ecosystem. This allows a user to onboard on to your IBC connected chain in 1 transaction from a broad range of EVM assets, including the memecoins retail loves to hold!
Currently, the API supports swapping on official Uniswap V3 deployments on the following chains (and their respective chain IDs):
- Ethereum (1)
- Polygon (137)
- Optimism (10)
- Arbitrum One (42161)
- Base (8453)
- BNB Chain (56)
- Avalanche (43114)
- Blast (81457)
- Celo (42220) - SOON
Just set the evmSwaps
flag to true in the smartSwapOptions
object. If using the @skip-router
library, you must be on version 5.1.0 or above.
{
"amount_in": "10000000000000000000",
"source_asset_denom": "arbitrum-native",
"source_asset_chain_id": "42161",
"dest_asset_denom": "ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5",
"dest_asset_chain_id": "dydx-mainnet-1",
"cumulative_affiliate_fee_bps": "0",
"allow_multi_tx": true,
"smart_relay": true,
"smart_swap_options": {
"evm_swaps": true
},
}
When an EVM swap occurs in a route, a new operation type evm_swap
is returned in the array of operations
in the v2/route
and v2/msgs_direct
responses. If your API usage follows the v2/route
then v2/msgs
call pattern, this new operation type must be passed to the v2/msgs
endpoint, so make sure you are on the latest router SDK version and/or are decoding the operation properly. The evm_swap
operation type is as follows:
export type EvmSwap = {
inputToken: string;
amountIn: string;
swapCalldata: string;
amountOut: string;
fromChainID: string;
denomIn: string;
denomOut: string;
swapVenues: SwapVenue[];
}
{
"evm_swap": {
"input_token": "ox", // string (token contract address if an ERC20 token, blank if native)
"amount_in": "100", // string
"swap_calldata": "0x", // string
"amount_out": "123", // string
"from_chain_id": "1", // string
"denom_in": "0x", // string
"denom_out": "0x", // string
"swap_venues": [], // []swap_venue
}
}
Nothing new in particular! The msg_type
used for EVM swaps is the same evm_tx
type used for all of our EVM transactions. Similarly, there is no new transfer_event
type to be aware of, since the swap is atomic with the bridging action (Axelar or CCTP), the same types are used (axelar_transfer_info
and cctp_transfer_info
respectively).
We've added a new swapType
called SmartSwapExactCoinIn
you can expect to be returned in the routeResponse
and msgsDirectResponse
to take advantage of the new capabilities Smart Swaps offers! This new swap type has fields that allow for multiple routes, across multiple swap venues.
- Note: this new
SmartSwapExactCoinIn
type will currently only be returned if the route provided back is a split route.
export type SmartSwapExactCoinIn = {
swapVenue: SwapVenue;
swapRoutes: SwapRoute[];
};
export type SwapRoute = {
swapAmountIn: string;
denomIn: string;
swapOperations: SwapOperation[];
};
You can reach us easily by joining our Discord and grabbing the "Skip API Developer" role.