-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: amm trade add shadow request 1% #10931
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
6 Skipped Deployments
|
|
65587c4
to
3ff07d3
Compare
export const QUOTING_API_PREFIX_ORIGINAL = 'https://pcsx-order-price-api-test-master-viosr.ondigitalocean.app' | ||
|
||
export const QUOTING_API_PREFIX_OPTIMIZED = 'https://pcsx-order-price-api-test-branch-nfu7y.ondigitalocean.app' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessarily to put them in constants as they're mainly for testing purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
useBestTradeFromApiShadow(bestTradeOptions, 'quote-api-ori') | ||
useBestTradeFromApiShadow(bestTradeOptions, 'quote-api-opt') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's enable for all chains. Previously the api is only enabled on arb and eth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
export function useTradeApiPrefetchShadow( | ||
{ currencyA, currencyB, poolTypes, enabled = true }: PrefetchParams, | ||
prefix: string, | ||
queryType: string, | ||
) { | ||
return useQuery({ | ||
enabled: !!(currencyA && currencyB && poolTypes?.length && enabled), | ||
queryKey: [`${queryType}-prefetch`, currencyA?.chainId, currencyA?.symbol, currencyB?.symbol, poolTypes] as const, | ||
queryFn: async ({ signal }) => { | ||
if (!currencyA || !currencyB || !poolTypes?.length) { | ||
throw new Error('Invalid prefetch params') | ||
} | ||
|
||
const serverRes = await fetch( | ||
`${prefix}/_pools/${currencyA.chainId}/${getCurrencyIdentifierForApi(currencyA)}/${getCurrencyIdentifierForApi( | ||
currencyB, | ||
)}?${qs.stringify({ protocols: poolTypes.map(getPoolTypeKey) })}`, | ||
{ | ||
method: 'GET', | ||
signal, | ||
}, | ||
) | ||
const res = await serverRes.json() | ||
if (!res.success) { | ||
throw new Error(res.message) | ||
} | ||
return res | ||
}, | ||
staleTime: currencyA?.chainId ? POOLS_FAST_REVALIDATE[currencyA.chainId] : 0, | ||
refetchInterval: currencyA?.chainId ? POOLS_FAST_REVALIDATE[currencyA.chainId] : 0, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need a new hook. Let's reuse useTradeApiPrefetch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cuz it's not used right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
useEffect(() => { | ||
if (featureFlag && !!(amount && currency)) { | ||
poolPreFetch.refetch() | ||
} | ||
}, [amount?.currency, currency]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need refetch for prefetch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
PR-Codex overview
This PR introduces a new experimental feature for optimized AMM trading, updates hooks for trade fetching, and enhances trade API interactions with shadow querying.
Detailed summary
OPTIMIZED_AMM_TRADE
toEXPERIMENTAL_FEATURES
.useBestTradeFromApiShadow
for optimized AMM trade fetching.useSwapBestOrder
to utilizeuseBestTradeFromApiShadow
.useTradeApiPrefetch
to acceptprefix
andqueryType
parameters.