Skip to content

Commit

Permalink
Merge pull request #326 from EdgeApp/paul/dexSlippage
Browse files Browse the repository at this point in the history
Paul/dex slippage
  • Loading branch information
paullinator authored Jun 14, 2024
2 parents 3ac829c + 3e728b4 commit 7df73b1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- changed: Standardize DEX quotes to 5% slippage and estimate quote

## 2.4.3 (2024-06-03)

- added: (Exolix) Add Piratechain
Expand Down
4 changes: 2 additions & 2 deletions src/swap/defi/lifi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const asInitOptions = asObject({
integrator: asOptional(asString, 'edgeapp')
})

/** Allow up to 20% slippage even for variable rate quotes */
const MAX_SLIPPAGE = '0.2'
/** Allow up to 5% slippage even for variable rate quotes */
const MAX_SLIPPAGE = '0.05'
const LIFI_SERVERS_DEFAULT = ['https://li.quest']
const EXPIRATION_MS = 1000 * 60
const EXCHANGE_INFO_UPDATE_FREQ_MS = 60000
Expand Down
7 changes: 5 additions & 2 deletions src/swap/defi/thorchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ const calcSwapFrom = async ({
total_swap_seconds: maxFulfillmentSeconds
} = bestQuote

const canBePartial = streamingSwapBlocks > 1
const canBePartial = !isEstimate || streamingSwapBlocks > 1

let toThorAmountWithSpread: string
if (canBePartial) {
log(`volatilitySpreadStreamingFinal: ${volatilitySpreadStreamingFinal}`)
Expand Down Expand Up @@ -984,7 +985,9 @@ const calcSwapTo = async ({
total_swap_seconds: maxFulfillmentSeconds
} = bestQuote

const canBePartial = streamingSwapBlocks > 1
// If we get a streaming quote, this should be considered a fully executing
// transaction since we don't put a slippage limit
const canBePartial = !isEstimate || streamingSwapBlocks > 1

// Get the percent drop from the 'to' amount the user wanted compared to the
// 'to' amount returned by the API. Add that percent to the 'from' amount to
Expand Down
4 changes: 2 additions & 2 deletions src/swap/defi/thorchainDa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ const asThorSwapQuoteResponse = asObject({
routes: asArray(asThorSwapRoute)
})

/** Max slippage for 20% for estimated quotes */
const DA_VOLATILITY_SPREAD_DEFAULT = 0.2
/** Max slippage for 5% for estimated quotes */
const DA_VOLATILITY_SPREAD_DEFAULT = 0.05
const THORSWAP_DEFAULT_SERVERS = ['https://api.thorswap.net/aggregator']

type ExchangeInfo = ReturnType<typeof asExchangeInfo>
Expand Down
2 changes: 1 addition & 1 deletion src/swap/defi/uni-v2-based/plugins/spookySwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export function makeSpookySwapPlugin(
savedAction: {
actionType: 'swap',
swapInfo,
isEstimate: false,
isEstimate: true,
toAsset: {
pluginId: request.toWallet.currencyInfo.pluginId,
tokenId: request.toTokenId,
Expand Down
2 changes: 1 addition & 1 deletion src/swap/defi/uni-v2-based/plugins/tombSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export function makeTombSwapPlugin(
savedAction: {
actionType: 'swap',
swapInfo,
isEstimate: false,
isEstimate: true,
toAsset: {
pluginId: request.toWallet.currencyInfo.pluginId,
tokenId: request.toTokenId,
Expand Down
4 changes: 2 additions & 2 deletions src/swap/defi/uni-v2-based/plugins/velodrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export function makeVelodromePlugin(
savedAction: {
actionType: 'swap',
swapInfo,
isEstimate: false,
isEstimate: true,
toAsset: {
pluginId: request.toWallet.currencyInfo.pluginId,
tokenId: request.toTokenId,
Expand Down Expand Up @@ -267,7 +267,7 @@ export function makeVelodromePlugin(
savedAction: {
actionType: 'swap',
swapInfo,
isEstimate: false,
isEstimate: true,
toAsset: {
pluginId: request.toWallet.currencyInfo.pluginId,
tokenId: request.toTokenId,
Expand Down

0 comments on commit 7df73b1

Please sign in to comment.