Skip to content

Commit

Permalink
Remove unused dontCheckLimits and hardcoded MIN_USD_SWAP
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Nov 23, 2023
1 parent f1f530c commit 6199faf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# edge-exchange-plugins

## Unreleased

- fixed: Return proper min amount error with Thorchain

## 1.1.0 (2023-11-20)

- added: RUNE support for Thorchain swaps
Expand Down
39 changes: 3 additions & 36 deletions src/swap/defi/thorchain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { add, div, gt, lt, mul, round, sub } from 'biggystring'
import { add, div, gt, mul, round, sub } from 'biggystring'
import {
asArray,
asBoolean,
Expand Down Expand Up @@ -283,7 +283,6 @@ interface CalcSwapParams {
affiliateFeeBasis: string
streamingInterval: number
streamingQuantity: number
dontCheckLimits?: boolean
}

interface CalcSwapResponse {
Expand Down Expand Up @@ -767,8 +766,7 @@ const calcSwapFrom = async ({
volatilitySpreadStreamingFinal,
affiliateFeeBasis,
streamingInterval,
streamingQuantity,
dontCheckLimits = false
streamingQuantity
}: CalcSwapParams): Promise<CalcSwapResponse> => {
const fromNativeAmount = nativeAmount

Expand All @@ -780,36 +778,6 @@ const calcSwapFrom = async ({

log(`fromExchangeAmount: ${fromExchangeAmount}`)

// Check minimums if we can
if (!dontCheckLimits) {
const srcInUsd = mul(sourcePool.assetPriceUSD, fromExchangeAmount)
let fromMinNativeAmount
if (lt(srcInUsd, MIN_USD_SWAP)) {
const minExchangeAmount = div(
MIN_USD_SWAP,
sourcePool.assetPriceUSD,
DIVIDE_PRECISION
)
fromMinNativeAmount = await fromWallet.denominationToNative(
minExchangeAmount,
fromCurrencyCode
)
}

if (minAmount != null && lt(fromExchangeAmount, minAmount.minInputAmount)) {
const tempNativeMin = await fromWallet.denominationToNative(
minAmount.minInputAmount,
fromCurrencyCode
)
if (gt(tempNativeMin, fromMinNativeAmount ?? '0')) {
fromMinNativeAmount = tempNativeMin
}
}
if (fromMinNativeAmount != null) {
throw new SwapBelowLimitError(swapInfo, fromMinNativeAmount, 'from')
}
}

const fromThorAmount = mul(fromExchangeAmount, THOR_LIMIT_UNITS)

const noStreamParams = {
Expand Down Expand Up @@ -914,8 +882,7 @@ const calcSwapTo = async ({
volatilitySpreadStreamingFinal,
affiliateFeeBasis,
streamingInterval,
streamingQuantity,
dontCheckLimits = false
streamingQuantity
}: CalcSwapParams): Promise<CalcSwapResponse> => {
const toNativeAmount = nativeAmount

Expand Down

0 comments on commit 6199faf

Please sign in to comment.