视频摘要这里有一段视频 对下文内容进行了总结。
衡量报价质量的不同方式
slippage:这是 Skip 预估的交换执行价格与实际可接受的最差执行价格之间的最大允许差值。如果交换的实际价格比滑点容忍度允许的更差,整个交换都会回滚。slippage不考虑用户这笔交换本身带来的影响,因为这一点已经计入预估结果。如果你在一个低流动性的池子里进行大额交换,即使slippage很低,仍然可能拿到“差价格”,因为你的交易本身会推动价格变化。因此,你应该把slippage理解为实际价格与报价价格之间偏差的容忍度,而不是判断报价是否“好”的指标。usd_estimate_in和usd_estimate_out:它们分别是输入数量和输出数量的美元价值预估。这些预估使用的是 Coingecko 的价格数据,数据最多可能有 5 分钟延迟。这些值并不总是可用,因为并非所有代币都在 Coingecko 上线(例如某些 meme 币或新币通常没有价格源)。它非常适合用来对价格是否“合理”做一次基本校验,并在预估输入与输出美元价值之间的差额占输入金额的比例超过某个阈值时提醒用户。(例如,我们建议当用户输入的美元价值是 50\ 时进行提示。这表明他们由于某些原因拿到了很差的价格。)price_impact:它衡量的是用户预期执行价格与执行时链上当前现货价格之间的差异。只要底层 DEX 支持计算链上现货价格,这个值就可用。当usd_estimate_in或usd_estimate_out不可用时,它尤其有帮助。较高的price_impact意味着用户的交换规模相对于可用链上流动性来说过大,正在显著推动价格变化。和美元预估一样,我们建议当这个值超过某个阈值时向用户发出警告(例如 10%)。
关于 slippage 与 price_impact 的更多说明
有些人会问,为什么 slippage 和 price_impact 都有必要存在。原因在于,它们试图描述的是两个本质不同的概念:
slippage= 从 API 给出报价到交易实际执行这段时间内,外部环境 / 流动性发生变化的容忍度(0slippage= “我希望拿到的输出数量与 Skip 预估的完全一致”)。当然,如果price_impact很高,或者usd_amount_in与usd_amount_out的差距很大,这仍然可能是一个差价格。与其把slippage理解为执行质量的预估,不如把它理解为对波动性的容忍度。price_impact= 衡量你的交易会在多大程度上推动链上价格变化。有些人会用“滑点”这个词来描述price_impact。它旨在表达你对低流动性和糟糕定价的容忍程度。
price_impact 很低,也仍然可能出现较高的 slippage。
通过 SAFE 界面保护用户
如果你想知道应该如何利用这些值来帮助用户避免糟糕的执行价格,我们专门写了一份关于如何构建安全交换界面的完整指南:SAFE Swapping:如何保护用户避免进行糟糕交易!欢迎查看。有问题或反馈?欢迎帮助我们做得更好!加入我们的 Discord,并选择 “Skip Go Developer” 角色来分享你的问题和反馈。
Video SummaryHere’s a video that summarizes the content below.
Different ways to measure quote quality
slippage: This is the maximum allowable difference between what Skip estimates the price of the swap will execute at and the worst price it can execute at. If the price of the swap turns out to be worse than the slippage tolerance allows, the swap will revert entirely. Slippage does not account for the impact of the user’s swap itself because this is incorporated in the estimate. You can still get a “bad price” with low slippage if you make a big swap against a low liquidity pool because your swap itself will move the price. As a result, you should think of slippage as tolerance for difference between actual price and quoted price, not a measure of whether the quoted price is “good”.usd_estimate_inandusd_estimate_out: These are estimates of the dollar-value of the amount in and amount out. These use coingecko prices that can be a maximum of 5 minutes stale. These values aren’t always available because not all tokens are listed on Coingecko (e.g. some meme coins or new coins won’t have feeds). This is really useful for providing a sanity check on whether a price is “good” and flagging to users when the difference between estimated input and output dollar values exceeds some threshold as a percentage of the input amount. (For example, we recommend you flag the user when their input dollar value is 50. This indicates they’re receiving a bad price for some reason.)price_impact: This measures how much the user’s expected execution price differs from the current on-chain spot price at time of execution. This is available whenever the underlying DEX makes it feasible to calculate on-chain spot price. This is especially useful whenusd_estimate_inorusd_estimate_outisn’t available. A high price impact means the user’s swap size is large relative to the available on chain liquidity that they’re swapping against, and they’re moving the price significantly a lot. Like with USD estimate, we recommend warning users when this exceeds some threshold (e.g. 10%).
More on slippage vs price_impact
Some people have asked why are both slippage and price_impact necessary. The reason is that they are trying to capture fundamentally different concepts:
- slippage = tolerance to the world / liquidity changing between when the API gives you a quote and when the transaction gets executed (0 slippage = “I want to get exactly the amount out that Skip estimates”). Of course, this could still be a bad price if there’s high price_impact, or if the difference between
usd_amount_inandusd_amount_outis large. Slippage is better understood as a tolerance to volatility, rather than an estimate of execution quality. - price impact = A measure of how much you’re going to move the on-chain price with your trade. Some folks use the word “slippage” to describe price impact. This is intended to capture your tolerance to low liquidity and bad pricing.
Protecting users with SAFE interfaces
If you’re wondering how you should use these values to help protect your users from poor execution prices, we have a whole guide written about how to build a safe swapping interface: SAFE Swapping: How to Protect Users from Bad Trades! Check it out!Have questions or feedback? Help us get better!Join our Discord and select the “Skip Go Developer” role to share your questions and feedback.