介绍

Smart Swap 是一组用于提升兑换速度、价格表现和控制能力的功能。 当前支持:
如果你正在使用已弃用的 @skip-router 库,则必须使用 v4.0.0 及以上版本才能启用 Smart Swap。我们强烈建议使用正在积极维护的 @skip-go/client TypeScript 包。
本文其余部分将展示如何配合 @skip-go/client 库使用 Smart Swap。你会发现它与 REST API 的唯一区别是命名约定。

Smart Swap 功能

在你的 skipClient 函数调用或 REST API 请求体中设置 Smart Swap 配置。

功能:使用外部路由以优化价格执行

Skip Go API 会综合多个内部和外部路由器,以找到价格执行效果最佳的路由。 当前支持的外部兑换路由器:
  1. Skip Go API 自研路由器
  2. Hallswap 的 DEX 聚合器
  3. Osmosis 的 Sidecar Query Service(SQS,Osmosis 前端正在使用)

用法

将一个空的 smartSwapOptions 对象传入路由请求。
const route = await skipClient.route({
  smartSwapOptions: {}, // You're not required to activate a particular flag for this feature
  sourceAssetDenom: "uusdc",
  sourceAssetChainID: "noble-1",
  destAssetDenom: "utia",
  destAssetChainID: "celestia",
  amountIn: "1000000", // 1 uusdc
  cumulativeAffiliateFeeBPS: "0"
}
就这么简单。Skip Go API 现在会考虑受支持的外部路由器,并返回当前可用的最佳选项。

功能:路由拆分

路由拆分指将用户的一笔交易分成多个部分,并通过不同的资金池进行兑换。这样可以降低价格冲击,并且相比只使用单一路由,可能提高用户最终得到的输出数量。当待兑换的一个或两个代币在 DEX 上经常与其他资产配对时(例如 Osmosis 上的 OSMO),这一功能尤其有效。

用法

在 smartSwapOptions 对象中传入 splitRoutes 标志。
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"
}

使用拆分路由时的响应变化

我们新增了一种名为 SmartSwapExactCoinIn 的 swapType。当返回的路由为拆分路由时,它会出现在 routeResponse 和 msgsDirectResponse 中。这个新的 swapType 包含允许跨多个兑换场所使用多条路由的字段。
export type SmartSwapExactCoinIn = {
  swapVenue: SwapVenue;
  swapRoutes: SwapRoute[];
};

export type SwapRoute = {
  swapAmountIn: string;
  denomIn: string;
  swapOperations: SwapOperation[];
};

功能:EVM 兑换

Smart Swap 支持双向 EVM 兑换:你可以从任意 EVM 链上的任意资产兑换到任意 Cosmos 链上的任意资产,也可以反向兑换回来。借助 EVM 兑换,用户只需 1 笔交易,就能从广泛的 EVM 资产接入你的 IBC 互联链,其中也包括散户偏爱持有的 memecoin。 目前,API 支持在 Velodrome(Optimism)和 Aerodrome(Base)上进行 EVM 兑换,也支持在以下链上的官方 Uniswap V3 部署上进行兑换:
网络链 ID
以太坊1
Polygon137
Optimism10
Arbitrum One42161
Base8453
BNB Chain56
Avalanche43114
Blast81457
Celo42220

用法

在 smartSwapOptions 对象中将 evmSwaps 标志设置为 true。如果你使用已弃用的 @skip-router 库,则必须使用 v5.1.0 及以上版本(我们强烈建议尽快迁移到 @skip-go/client)。
const route = await skipClient.route({
  sourceAssetDenom: "arbitrum-native",
  sourceAssetChainID: "42161",
  destAssetDenom: "ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5",
  destAssetChainID: "dydx-mainnet-1",
  amountIn: "10000000000000000000",
  cumulativeAffiliateFeeBPS: "0",
  smartRelay: true,
  smartSwapOptions: {
    evmSwaps: true
  },
}

EVM 兑换会如何改变 route 响应?

当路由中发生 EVM 兑换时,v2/route 和 v2/msgs_direct 响应里的 operations 数组中会返回一个新的 evm_swap 类型操作。
如果你的 API 使用方式遵循 v2/route 然后 v2/msgs 的调用模式,则必须将这个新操作类型传递给 v2/msgs 端点,因此请确保你使用最新的 Skip Go Client 版本 并正确解码该操作。
evm_swap 操作类型如下:
export type EvmSwap = {
  inputToken: string;
  amountIn: string;
  swapCalldata: string;
  amountOut: string;
  fromChainID: string;
  denomIn: string;
  denomOut: string;
  swapVenues: SwapVenue[];
}

这会如何改变 /msgs 和 /status 响应?

没有特别的新变化。用于 EVM 兑换的 msg_type 与我们所有 EVM 交易使用的 evm_tx 类型相同。同样,也没有新的 transfer_event 类型;兑换与桥接操作(Axelar 或 CCTP)是原子完成的,因此仍分别使用相同的类型(axelar_transfer_info 和 cctp_transfer_info)。
有问题或反馈?欢迎帮助我们做得更好!加入我们的 Discord,并选择“Skip Go Developer”角色来分享你的问题和反馈。

Introduction

Smart Swap refers to a feature set that improves swap speed, price, and control. It currently allows for:
If you’re using the deprecated @skip-router library, you must use version v4.0.0+ to enable Smart Swap.We strongly recommend using the @skip-go/client TypeScript package, which is actively maintained.
The rest of this document will show you how to use Smart Swap with the @skip-go/client library. The only changes you’ll notice between this context and the REST API are naming conventions.

Smart Swap Features

Set your Smart Swap settings in your skipClient function call or REST API request body.

Feature: Use External Routers to Improve Price Execution

The Skip Go API considers multiple internal and external routers to find the route with the best price execution. Currently supported external swap routers:
  1. Skip Go API’s in-house Router
  2. Hallswap’s Dex Aggregator
  3. Osmosis’s Sidecar Query Service (SQS) (Used in the Osmosis frontend)

Usage

Pass an empty smartSwapOptions object into your route request.
const route = await skipClient.route({
  smartSwapOptions: {}, // You're not required to activate a particular flag for this feature
  sourceAssetDenom: "uusdc",
  sourceAssetChainID: "noble-1",
  destAssetDenom: "utia",
  destAssetChainID: "celestia",
  amountIn: "1000000", // 1 uusdc
  cumulativeAffiliateFeeBPS: "0"
}
That’s it! Skip Go API will now consider supported external routers and return the best available option.

Feature: Route Splitting

Route splitting involves dividing a user’s trade into multiple parts and swapping them through different pools. This reduces price impact and can increase the user’s output compared to using a single route. It works especially well when one or both tokens being swapped are commonly paired with other assets on a DEX (e.g., OSMO on Osmosis).

Usage

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"
}

Response Changes when using Split Routes

We’ve added a new swapType called SmartSwapExactCoinIn that’s returned in the routeResponse and msgsDirectResponse when the provided route is a split route. This new swapType has fields that allow for multiple routes, across multiple swap venues.
export type SmartSwapExactCoinIn = {
  swapVenue: SwapVenue;
  swapRoutes: SwapRoute[];
};

export type SwapRoute = {
  swapAmountIn: string;
  denomIn: string;
  swapOperations: SwapOperation[];
};

Feature: EVM Swaps

Smart Swap supports bidirectional EVM swaps: go from any asset on an EVM chain to any asset on a Cosmos chain and back again. With EVM swaps, users can onboard 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 EVM swapping on Velodrome (Optimism) & Aerodrome (Base), and swapping on official Uniswap V3 deployments on the following chains:
NetworkChain ID
Ethereum1
Polygon137
Optimism10
Arbitrum One42161
Base8453
BNB Chain56
Avalanche43114
Blast81457
Celo42220

Usage

Set the evmSwaps flag to true in the smartSwapOptions object. If using the deprecated @skip-router library, you must be on v5.1.0+ (we strongly recommend migrating to @skip-go/client as soon as possible).
const route = await skipClient.route({
  sourceAssetDenom: "arbitrum-native",
  sourceAssetChainID: "42161",
  destAssetDenom: "ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5",
  destAssetChainID: "dydx-mainnet-1",
  amountIn: "10000000000000000000",
  cumulativeAffiliateFeeBPS: "0",
  smartRelay: true,
  smartSwapOptions: {
    evmSwaps: true
  },
}

How do EVM Swaps Change the route Response?

When an EVM swap occurs in a route, a new operation of type evm_swap is returned in the array of operations in the v2/route and v2/msgs_direct response.
If your API use 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 use the latest Skip Go Client version and decode 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[];
}

How does this Change the /msgs and /status Response?

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; the swap is atomic with the bridging action (Axelar or CCTP), so the same types are used (axelar_transfer_info and cctp_transfer_info respectively).
Have questions or feedback? Help us get better!Join our Discord and select the “Skip Go Developer” role to share your questions and feedback.