Skip to content

Commit

Permalink
fix: remove hack - seems to be better without it?
Browse files Browse the repository at this point in the history
  • Loading branch information
alfetopito committed Jan 9, 2025
1 parent a89667d commit 9371767
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TokenWithLogo, USDC } from '@cowprotocol/common-const'
import { USDC } from '@cowprotocol/common-const'
import { getWrappedToken, tryParseCurrencyAmount } from '@cowprotocol/common-utils'
import { SupportedChainId } from '@cowprotocol/cow-sdk'
import { Currency, CurrencyAmount } from '@uniswap/sdk-core'
import { Currency } from '@uniswap/sdk-core'

import { useUsdPrice } from 'modules/usdAmount'

Expand All @@ -15,19 +15,11 @@ export function useConvertUsdToTokenValue(
const usdcToken = USDC[currencyUsdcPrice.currency.chainId as SupportedChainId]
const usdAmount = tryParseCurrencyAmount(typedValue, usdcToken)

const tokenAmount = currencyUsdcPrice.price.invert().quote(hackyAdjustAmountDust(usdAmount))
const tokenAmount = currencyUsdcPrice.price.invert().quote(usdAmount)

return tokenAmount.toExact()
}

return typedValue
}
}

/**
* TODO: this is a hacky way to adjust the amount to avoid dust
* For some reason, when you enter for example $366, price.quote() returns 365,9999999999
*/
function hackyAdjustAmountDust(amount: CurrencyAmount<TokenWithLogo>): typeof amount {
return amount.add(tryParseCurrencyAmount('0.000001', amount.currency))
}

0 comments on commit 9371767

Please sign in to comment.