Skip to content

Commit

Permalink
feat: add slippage control to quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
chefjackson committed Sep 19, 2024
1 parent f4cc9d8 commit 4142e67
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions apps/web/src/hooks/useBestAMMTrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@pancakeswap/smart-router'
import { BigintIsh } from '@pancakeswap/swap-sdk-core'
import { AbortControl } from '@pancakeswap/utils/abortControl'
import { useUserSlippage } from '@pancakeswap/utils/user'
import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query'
import qs from 'qs'
import { useCallback, useDeferredValue, useEffect, useMemo, useRef } from 'react'
Expand All @@ -28,6 +29,7 @@ import { useFeeDataWithGasPrice } from 'state/user/hooks'
import { tracker } from 'utils/datadog'
import { createViemPublicClientGetter } from 'utils/viem'
import { publicClient } from 'utils/wagmi'
import { basisPointsToPercent } from 'utils/exchange'

import useNativeCurrency from 'hooks/useNativeCurrency'
import { useUserXEnable } from 'state/user/smartRouter'
Expand Down Expand Up @@ -524,6 +526,7 @@ export function useBestTradeFromApi({
v2Swap,
v3Swap,
}: Options) {
const [slippage] = useUserSlippage()
const poolTypes = useMemo(() => {
const types: PoolType[] = []
if (v2Swap) {
Expand Down Expand Up @@ -569,6 +572,7 @@ export function useBestTradeFromApi({
maxHops,
maxSplits,
poolTypes,
slippage,
] as const,
queryFn: async ({ signal, queryKey }) => {
const [key] = queryKey
Expand All @@ -582,6 +586,7 @@ export function useBestTradeFromApi({
amount,
quoteCurrency: currency,
tradeType,
slippage: basisPointsToPercent(slippage),
amm: { maxHops, maxSplits, poolTypes, gasPriceWei: gasPrice },
x: {
useSyntheticQuotes: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Trade = SmartRouterTrade<TradeType> | V4Router.V4TradeWithoutGraph<TradeTyp
export const useAllTypeBestTrade = () => {
const [isQuotingPaused, setIsQuotingPaused] = useState(false)
const bestOrder = useSwapBestOrder()
const { isLoading, trade, refresh, syncing, isStale, error } = useSwapBestTrade()
const { isLoading, trade, refresh, syncing, isStale, error } = useSwapBestTrade({ maxHops: 3 })
const lockedAMMTrade = useRef<Trade | undefined>()
const lockedOrder = useRef<
| (InterfaceOrder<Currency, Currency> & {
Expand Down

0 comments on commit 4142e67

Please sign in to comment.