Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ NEXT_PUBLIC_ENABLE_STAKING=true
NEXT_PUBLIC_ENABLE_GOVERNANCE=true
NEXT_PUBLIC_API_BASEURL=https://aave-api-v2.aave.com
NEXT_PUBLIC_SUBGRAPH_API_KEY=
FAMILY_API_KEY=
FAMILY_API_URL=
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ LINEA_RPC_API_KEY=
SONIC_RPC_API_KEY=
CELO_RPC_API_KEY=
MONAD_RPC_API_KEY=
FAMILY_API_KEY=
FAMILY_API_URL=
COINGECKO_API_KEY=
# TokenLogic REST API (api.tokenlogic.xyz), used by /api/protocol-totals for whole-protocol figures
TL_API_KEY=
Expand Down
80 changes: 0 additions & 80 deletions pages/api/prices-proxy.md

This file was deleted.

79 changes: 0 additions & 79 deletions pages/api/prices-proxy.ts

This file was deleted.

40 changes: 3 additions & 37 deletions src/components/transactions/Swap/helpers/cow/rates.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { ChainId } from '@aave/contract-helpers';
import { OrderKind, QuoteAndPost, WRAPPED_NATIVE_CURRENCIES } from '@cowprotocol/cow-sdk';
import { BigNumber } from 'bignumber.js';
import { getEthersProvider } from 'src/libs/web3-data-provider/adapters/EthersAdapter';
import { CoWProtocolPricesService } from 'src/services/CoWProtocolPricesService';
import { FamilyPricesService } from 'src/services/FamilyPricesService';
import { getErrorTextFromError, TxAction } from 'src/ui-config/errorMapping';
import { wagmiConfig } from 'src/ui-config/wagmiConfig';
import { getNetworkConfig } from 'src/utils/marketsAndNetworksConfig';

import { COW_PARTNER_FEE, isChainIdSupportedByCoWProtocol } from '../../constants/cow.constants';
import { isNativeToken } from '../../helpers/cow';
Expand All @@ -15,33 +12,6 @@ import { getAppDataForQuote } from './adapters.helpers';
import { getCowTradingSdkByChainIdAndAppCode } from './env.helpers';
import { getSlippageSuggestion } from './orders.helpers';

export const getTokenUsdPrice = async (
chainId: number,
tokenAddress: string,
isTokenCustom: boolean,
isMainnet: boolean
) => {
const cowProtocolPricesService = new CoWProtocolPricesService();
const familyPricesService = new FamilyPricesService();

try {
let price;

if (!isTokenCustom && isMainnet) {
price = await familyPricesService.getTokenUsdPrice(chainId, tokenAddress);
}

if (price) {
return price;
}

return await cowProtocolPricesService.getTokenUsdPrice(chainId, tokenAddress);
} catch (familyError) {
console.error(familyError);
return undefined;
}
};

export async function getCowProtocolSellRates({
chainId,
amount,
Expand All @@ -53,15 +23,14 @@ export async function getCowProtocolSellRates({
swapType,
inputSymbol,
outputSymbol,
isInputTokenCustom,
isOutputTokenCustom,
appCode,
market,
setError,
side = 'sell',
invertedQuoteRoute = false,
}: ProviderRatesParams): Promise<CowProtocolRatesType> {
const tradingSdk = await getCowTradingSdkByChainIdAndAppCode(chainId, appCode);
const cowProtocolPricesService = new CoWProtocolPricesService();
let orderBookQuote: QuoteAndPost | undefined;
let srcTokenPriceUsd: string | undefined;
let destTokenPriceUsd: string | undefined;
Expand All @@ -83,9 +52,6 @@ export async function getCowProtocolSellRates({

const provider = await getEthersProvider(wagmiConfig, { chainId });
const signer = provider?.getSigner();
const isMainnet =
!getNetworkConfig(chainId as unknown as ChainId).isTestnet &&
!getNetworkConfig(chainId as unknown as ChainId).isFork;

if (!inputSymbol || !outputSymbol) {
throw new Error('No input or output symbol provided');
Expand Down Expand Up @@ -130,8 +96,8 @@ export async function getCowProtocolSellRates({
'Failed to get quote from CoW Protocol';
throw new Error(errorMessage);
}),
getTokenUsdPrice(chainId, srcTokenWrapped, isInputTokenCustom ?? false, isMainnet),
getTokenUsdPrice(chainId, destTokenWrapped, isOutputTokenCustom ?? false, isMainnet),
cowProtocolPricesService.getTokenUsdPrice(chainId, srcTokenWrapped),
cowProtocolPricesService.getTokenUsdPrice(chainId, destTokenWrapped),
]);

if (!srcTokenPriceUsd || !destTokenPriceUsd) {
Expand Down
46 changes: 12 additions & 34 deletions src/components/transactions/Swap/hooks/useSwapQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
SwapQuoteType as SwapQuoteType,
SwapState,
SwapType,
TokenType,
} from '../types';

interface TokenSelectionParams {
Expand All @@ -29,8 +28,6 @@ interface TokenSelectionParams {
destDecimals: number;
inputSymbol: string;
outputSymbol: string;
isInputTokenCustom: boolean;
isOutputTokenCustom: boolean;
side: 'buy' | 'sell';
}

Expand Down Expand Up @@ -68,12 +65,6 @@ const getTokenSelectionForQuote = (
const outputSymbol = invertedQuoteRoute
? state.sourceToken.symbol
: state.destinationToken.symbol;
const isInputTokenCustom = invertedQuoteRoute
? state.destinationToken.tokenType === TokenType.USER_CUSTOM
: state.sourceToken.tokenType === TokenType.USER_CUSTOM;
const isOutputTokenCustom = invertedQuoteRoute
? state.sourceToken.tokenType === TokenType.USER_CUSTOM
: state.destinationToken.tokenType === TokenType.USER_CUSTOM;
const side = invertedQuoteRoute ? (state.side === 'buy' ? 'sell' : 'buy') : state.side;

return {
Expand All @@ -83,8 +74,6 @@ const getTokenSelectionForQuote = (
destDecimals,
inputSymbol,
outputSymbol,
isInputTokenCustom,
isOutputTokenCustom,
side,
};
};
Expand Down Expand Up @@ -309,27 +298,18 @@ const useMultiProviderSwapQuoteQuery = ({

const appCode = APP_CODE_PER_SWAP_TYPE[params.swapType];

const {
srcToken,
destToken,
srcDecimals,
destDecimals,
inputSymbol,
outputSymbol,
isInputTokenCustom,
isOutputTokenCustom,
side,
} = useMemo(
() => getTokenSelectionForQuote(requiresQuoteInverted, provider, state),
[
provider,
state.sourceToken,
state.destinationToken,
state.side,
requiresQuoteInverted,
state.useFlashloan,
]
);
const { srcToken, destToken, srcDecimals, destDecimals, inputSymbol, outputSymbol, side } =
useMemo(
() => getTokenSelectionForQuote(requiresQuoteInverted, provider, state),
[
provider,
state.sourceToken,
state.destinationToken,
state.side,
requiresQuoteInverted,
state.useFlashloan,
]
);

return useQuery<SwapQuoteType | null>({
queryFn: async () => {
Expand Down Expand Up @@ -378,8 +358,6 @@ const useMultiProviderSwapQuoteQuery = ({
destDecimals,
inputSymbol,
outputSymbol,
isInputTokenCustom,
isOutputTokenCustom,
appCode,
market: currentMarket,
setError,
Expand Down
2 changes: 0 additions & 2 deletions src/components/transactions/Swap/types/quote.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export type ProviderRatesParams = {
inputSymbol?: string;
outputSymbol?: string;

isInputTokenCustom?: boolean;
isOutputTokenCustom?: boolean;
appCode: string;
market: CustomMarket;

Expand Down
Loading
Loading