feat: Use routing-api or URA for price fetches behind feature flag (#6740)

use routing-api or URA for price fetches behind feature flag
This commit is contained in:
Tina 2023-06-09 15:07:53 -04:00 committed by GitHub
parent 4235b57cd8
commit 04e4335cc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 7 deletions

@ -1,6 +1,7 @@
import { BaseVariant, FeatureFlag, featureFlagSettings, useUpdateFlag } from 'featureFlags' import { BaseVariant, FeatureFlag, featureFlagSettings, useUpdateFlag } from 'featureFlags'
import { useNativeUSDCArbitrumFlag } from 'featureFlags/flags/nativeUsdcArbitrum' import { useNativeUSDCArbitrumFlag } from 'featureFlags/flags/nativeUsdcArbitrum'
import { DetailsV2Variant, useDetailsV2Flag } from 'featureFlags/flags/nftDetails' import { DetailsV2Variant, useDetailsV2Flag } from 'featureFlags/flags/nftDetails'
import { useRoutingAPIForPriceFlag } from 'featureFlags/flags/priceRoutingApi'
import { TraceJsonRpcVariant, useTraceJsonRpcFlag } from 'featureFlags/flags/traceJsonRpc' import { TraceJsonRpcVariant, useTraceJsonRpcFlag } from 'featureFlags/flags/traceJsonRpc'
import { UnifiedRouterVariant, useRoutingAPIV2Flag } from 'featureFlags/flags/unifiedRouter' import { UnifiedRouterVariant, useRoutingAPIV2Flag } from 'featureFlags/flags/unifiedRouter'
import { useUpdateAtom } from 'jotai/utils' import { useUpdateAtom } from 'jotai/utils'
@ -221,6 +222,12 @@ export default function FeatureFlagModal() {
featureFlag={FeatureFlag.nativeUsdcArbitrum} featureFlag={FeatureFlag.nativeUsdcArbitrum}
label="Enable Circle native USDC on Arbitrum" label="Enable Circle native USDC on Arbitrum"
/> />
<FeatureFlagOption
variant={BaseVariant}
value={useRoutingAPIForPriceFlag()}
featureFlag={FeatureFlag.routingAPIPrice}
label="Use the URA or routing-api for price fetches"
/>
<FeatureFlagGroup name="Debug"> <FeatureFlagGroup name="Debug">
<FeatureFlagOption <FeatureFlagOption
variant={TraceJsonRpcVariant} variant={TraceJsonRpcVariant}

@ -0,0 +1,9 @@
import { BaseVariant, FeatureFlag, useBaseFlag } from '../index'
export function useRoutingAPIForPriceFlag(): BaseVariant {
return useBaseFlag(FeatureFlag.routingAPIPrice)
}
export function useRoutingAPIForPrice(): boolean {
return useRoutingAPIForPriceFlag() === BaseVariant.Enabled
}

@ -13,6 +13,7 @@ export enum FeatureFlag {
uraEnabled = 'ura_enabled', uraEnabled = 'ura_enabled',
debounceSwapQuote = 'debounce_swap_quote', debounceSwapQuote = 'debounce_swap_quote',
nativeUsdcArbitrum = 'web_usdc_arbitrum', nativeUsdcArbitrum = 'web_usdc_arbitrum',
routingAPIPrice = 'routing_api_price',
} }
interface FeatureFlagsContextType { interface FeatureFlagsContextType {

@ -1,4 +1,5 @@
import { Currency, CurrencyAmount, TradeType } from '@uniswap/sdk-core' import { Currency, CurrencyAmount, TradeType } from '@uniswap/sdk-core'
import { useRoutingAPIForPrice } from 'featureFlags/flags/priceRoutingApi'
import { useMemo } from 'react' import { useMemo } from 'react'
import { GetQuoteArgs, INTERNAL_ROUTER_PREFERENCE_PRICE, RouterPreference } from 'state/routing/slice' import { GetQuoteArgs, INTERNAL_ROUTER_PREFERENCE_PRICE, RouterPreference } from 'state/routing/slice'
import { currencyAddressForSwapQuote } from 'state/routing/utils' import { currencyAddressForSwapQuote } from 'state/routing/utils'
@ -21,6 +22,7 @@ export function useRoutingAPIArguments({
tradeType: TradeType tradeType: TradeType
routerPreference: RouterPreference | typeof INTERNAL_ROUTER_PREFERENCE_PRICE routerPreference: RouterPreference | typeof INTERNAL_ROUTER_PREFERENCE_PRICE
}): GetQuoteArgs | undefined { }): GetQuoteArgs | undefined {
const isRoutingAPIPrice = useRoutingAPIForPrice()
return useMemo( return useMemo(
() => () =>
!tokenIn || !tokenOut || !amount || tokenIn.equals(tokenOut) || tokenIn.wrapped.equals(tokenOut.wrapped) !tokenIn || !tokenOut || !amount || tokenIn.equals(tokenOut) || tokenIn.wrapped.equals(tokenOut.wrapped)
@ -37,7 +39,8 @@ export function useRoutingAPIArguments({
tokenOutSymbol: tokenOut.wrapped.symbol, tokenOutSymbol: tokenOut.wrapped.symbol,
routerPreference, routerPreference,
tradeType, tradeType,
isRoutingAPIPrice,
}, },
[amount, routerPreference, tokenIn, tokenOut, tradeType] [amount, routerPreference, tokenIn, tokenOut, tradeType, isRoutingAPIPrice]
) )
} }

@ -40,6 +40,7 @@ export interface GetQuoteArgs {
amount: string amount: string
routerPreference: RouterPreference | typeof INTERNAL_ROUTER_PREFERENCE_PRICE routerPreference: RouterPreference | typeof INTERNAL_ROUTER_PREFERENCE_PRICE
tradeType: TradeType tradeType: TradeType
isRoutingAPIPrice?: boolean
} }
enum QuoteState { enum QuoteState {
@ -83,7 +84,7 @@ export const routingApi = createApi({
) )
}, },
async queryFn(args, _api, _extraOptions, fetch) { async queryFn(args, _api, _extraOptions, fetch) {
if (shouldUseAPIRouter(args.routerPreference)) { if (shouldUseAPIRouter(args)) {
try { try {
const { tokenInAddress, tokenInChainId, tokenOutAddress, tokenOutChainId, amount, tradeType } = args const { tokenInAddress, tokenInChainId, tokenOutAddress, tokenOutChainId, amount, tradeType } = args
const type = isExactInput(tradeType) ? 'exactIn' : 'exactOut' const type = isExactInput(tradeType) ? 'exactIn' : 'exactOut'

@ -187,8 +187,11 @@ export function currencyAddressForSwapQuote(currency: Currency): string {
return currency.address return currency.address
} }
export function shouldUseAPIRouter( export function shouldUseAPIRouter(args: GetQuoteArgs): boolean {
routerPreference?: RouterPreference | typeof INTERNAL_ROUTER_PREFERENCE_PRICE const { routerPreference, isRoutingAPIPrice } = args
): boolean { if (routerPreference === INTERNAL_ROUTER_PREFERENCE_PRICE && isRoutingAPIPrice) {
return true
}
return routerPreference === RouterPreference.API || routerPreference === RouterPreference.AUTO return routerPreference === RouterPreference.API || routerPreference === RouterPreference.AUTO
} }

@ -54,8 +54,7 @@ export const routingApiV2 = createApi({
) )
}, },
async queryFn(args: GetQuoteArgs, _api, _extraOptions, fetch) { async queryFn(args: GetQuoteArgs, _api, _extraOptions, fetch) {
const routerPreference = args.routerPreference if (shouldUseAPIRouter(args)) {
if (shouldUseAPIRouter(routerPreference)) {
try { try {
const { tokenInAddress, tokenInChainId, tokenOutAddress, tokenOutChainId, amount, tradeType } = args const { tokenInAddress, tokenInChainId, tokenOutAddress, tokenOutChainId, amount, tradeType } = args
const type = isExactInput(tradeType) ? 'EXACT_INPUT' : 'EXACT_OUTPUT' const type = isExactInput(tradeType) ? 'EXACT_INPUT' : 'EXACT_OUTPUT'