Skip to content
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

Merged
merged 12 commits into from
Nov 14, 2024
Merged

Conversation

chef-ryan
Copy link
Contributor

@chef-ryan chef-ryan commented Nov 8, 2024


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

  • Added OPTIMIZED_AMM_TRADE to EXPERIMENTAL_FEATURES.
  • Introduced a new function useBestTradeFromApiShadow for optimized AMM trade fetching.
  • Updated useSwapBestOrder to utilize useBestTradeFromApiShadow.
  • Modified useTradeApiPrefetch to accept prefix and queryType parameters.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

vercel bot commented Nov 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 8:27am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
aptos-web ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 8:27am
blog ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 8:27am
bridge ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 8:27am
games ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 8:27am
gamification ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 8:27am
uikit ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 8:27am

Copy link

changeset-bot bot commented Nov 8, 2024

⚠️ No Changeset found

Latest commit: 2a1db36

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chef-ryan chef-ryan changed the title Feat/amm trade shadow request feat: amm trade add shadow request 1% Nov 8, 2024
@chef-ryan chef-ryan force-pushed the feat/amm-trade-shadow-request branch from 65587c4 to 3ff07d3 Compare November 8, 2024 07:54
Comment on lines 103 to 105
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'
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +63 to +64
useBestTradeFromApiShadow(bestTradeOptions, 'quote-api-ori')
useBestTradeFromApiShadow(bestTradeOptions, 'quote-api-opt')
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 951 to 982
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,
})
}
Copy link
Collaborator

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

Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 726 to 730
useEffect(() => {
if (featureFlag && !!(amount && currency)) {
poolPreFetch.refetch()
}
}, [amount?.currency, currency])
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@chef-ryan chef-ryan merged commit e1f5592 into develop Nov 14, 2024
20 checks passed
@chef-ryan chef-ryan deleted the feat/amm-trade-shadow-request branch November 14, 2024 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants