diff --git a/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaCoWAdapters.tsx b/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaCoWAdapters.tsx index 07e1f32d15..011ed0b0bb 100644 --- a/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaCoWAdapters.tsx +++ b/src/components/transactions/Swap/actions/CollateralSwap/CollateralSwapActionsViaCoWAdapters.tsx @@ -54,9 +54,7 @@ export const CollateralSwapActionsViaCowAdapters = ({ setState: Dispatch>; trackingHandlers: TrackAnalyticsHandlers; }) => { - const [user, currentMarket] = useRootStore( - useShallow((state) => [state.account, state.currentMarket]) - ); + const [user] = useRootStore(useShallow((state) => [state.account])); const collateralsAmount = useCollateralsAmount(); @@ -85,7 +83,6 @@ export const CollateralSwapActionsViaCowAdapters = ({ validTo, type: AaveFlashLoanType.CollateralSwap, state, - market: currentMarket, }) .catch((error) => { console.error('calculateInstanceAddress error', error); @@ -110,7 +107,6 @@ export const CollateralSwapActionsViaCowAdapters = ({ state.slippage, state.orderType, state.chainId, - currentMarket, ]); // Approval is aToken ERC20 Approval @@ -207,8 +203,7 @@ export const CollateralSwapActionsViaCowAdapters = ({ partnerFee: COW_PARTNER_FEE( state.sellAmountToken.symbol, state.buyAmountToken.symbol, - state.swapType, - currentMarket + state.swapType ), }; diff --git a/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaCoW.tsx b/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaCoW.tsx index 9eb7782c2c..1a5866fd51 100644 --- a/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaCoW.tsx +++ b/src/components/transactions/Swap/actions/DebtSwap/DebtSwapActionsViaCoW.tsx @@ -60,9 +60,7 @@ export const DebtSwapActionsViaCoW = ({ setState: Dispatch>; trackingHandlers: TrackAnalyticsHandlers; }) => { - const [user, currentMarket] = useRootStore( - useShallow((state) => [state.account, state.currentMarket]) - ); + const [user] = useRootStore(useShallow((state) => [state.account])); const debtAmount = useCollateralsAmount(); @@ -94,7 +92,6 @@ export const DebtSwapActionsViaCoW = ({ validTo, type: AaveFlashLoanType.DebtSwap, state, - market: currentMarket, }) .catch((error) => { console.error('calculateInstanceAddress error', error); @@ -122,7 +119,6 @@ export const DebtSwapActionsViaCoW = ({ APP_CODE_PER_SWAP_TYPE[state.swapType], approvalTxState.loading, approvalTxState.success, - currentMarket, ]); const amountToApprove = useMemo(() => { @@ -234,8 +230,7 @@ export const DebtSwapActionsViaCoW = ({ partnerFee: COW_PARTNER_FEE( state.sellAmountToken.symbol, state.buyAmountToken.symbol, - state.swapType, - currentMarket + state.swapType ), }; diff --git a/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaCoW.tsx b/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaCoW.tsx index b7e9051466..93dba1ba9a 100644 --- a/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaCoW.tsx +++ b/src/components/transactions/Swap/actions/RepayWithCollateral/RepayWithCollateralActionsViaCoW.tsx @@ -60,9 +60,7 @@ export const RepayWithCollateralActionsViaCoW = ({ setState: Dispatch>; trackingHandlers: TrackAnalyticsHandlers; }) => { - const [user, currentMarket] = useRootStore( - useShallow((state) => [state.account, state.currentMarket]) - ); + const [user] = useRootStore(useShallow((state) => [state.account])); const collateralsAmount = useCollateralsAmount(); @@ -94,7 +92,6 @@ export const RepayWithCollateralActionsViaCoW = ({ validTo, type: AaveFlashLoanType.RepayCollateral, state, - market: currentMarket, }) .catch((error) => { console.error('calculateInstanceAddress error', error); @@ -122,7 +119,6 @@ export const RepayWithCollateralActionsViaCoW = ({ APP_CODE_PER_SWAP_TYPE[state.swapType], approvalTxState.loading, approvalTxState.success, - currentMarket, ]); // Approval is aToken ERC20 Approval @@ -232,8 +228,7 @@ export const RepayWithCollateralActionsViaCoW = ({ partnerFee: COW_PARTNER_FEE( state.sellAmountToken.symbol, state.buyAmountToken.symbol, - state.swapType, - currentMarket + state.swapType ), }; diff --git a/src/components/transactions/Swap/actions/SwapActions/SwapActionsViaCoW.tsx b/src/components/transactions/Swap/actions/SwapActions/SwapActionsViaCoW.tsx index b15cff96c7..0ad3501a80 100644 --- a/src/components/transactions/Swap/actions/SwapActions/SwapActionsViaCoW.tsx +++ b/src/components/transactions/Swap/actions/SwapActions/SwapActionsViaCoW.tsx @@ -68,13 +68,8 @@ export const SwapActionsViaCoW = ({ setState: Dispatch>; trackingHandlers: TrackAnalyticsHandlers; }) => { - const [user, estimateGasLimit, addTransaction, currentMarket] = useRootStore( - useShallow((state) => [ - state.account, - state.estimateGasLimit, - state.addTransaction, - state.currentMarket, - ]) + const [user, estimateGasLimit, addTransaction] = useRootStore( + useShallow((state) => [state.account, state.estimateGasLimit, state.addTransaction]) ); const { mainTxState, loadingTxns, setMainTxState, setTxError, approvalTxState } = @@ -192,7 +187,6 @@ export const SwapActionsViaCoW = ({ appCode, state.orderType, params.swapType, - currentMarket, state.swapRate.quoteId ); const txWithGasEstimation = await estimateGasLimit(ethFlowTx, state.chainId); @@ -228,7 +222,6 @@ export const SwapActionsViaCoW = ({ orderType: state.orderType, validTo, swapType: params.swapType, - market: currentMarket, }); const calculatedOrderId = await calculateUniqueOrderId(state.chainId, unsignerOrder); @@ -242,8 +235,7 @@ export const SwapActionsViaCoW = ({ smartSlippage, state.orderType, APP_CODE_PER_SWAP_TYPE[params.swapType], - params.swapType, - currentMarket + params.swapType ) ), state.chainId @@ -300,7 +292,6 @@ export const SwapActionsViaCoW = ({ orderBookQuote: state.swapRate?.orderBookQuote, orderType: state.orderType, swapType: params.swapType, - market: currentMarket, kind: state.orderType === OrderType.MARKET ? OrderKind.SELL @@ -347,7 +338,6 @@ export const SwapActionsViaCoW = ({ smartSlippage, orderType: state.orderType, swapType: params.swapType, - market: currentMarket, kind: state.orderType === OrderType.MARKET ? OrderKind.SELL diff --git a/src/components/transactions/Swap/constants/cow.constants.ts b/src/components/transactions/Swap/constants/cow.constants.ts index cbf12a4153..efe1c5bb09 100644 --- a/src/components/transactions/Swap/constants/cow.constants.ts +++ b/src/components/transactions/Swap/constants/cow.constants.ts @@ -1,7 +1,5 @@ import { CowEnv, OrderClass, SupportedChainId } from '@cowprotocol/cow-sdk'; import { AaveFlashLoanType } from '@cowprotocol/sdk-flash-loans'; -import { CustomMarket } from 'src/ui-config/marketsConfig'; -import { marketsData } from 'src/utils/marketsAndNetworksConfig'; import { getAssetGroup } from '../helpers/shared/assetCorrelation.helpers'; import { OrderType, SwapType } from '../types'; @@ -158,16 +156,10 @@ const PARTNER_FEE_BPS_BY_SWAP_TYPE: Partial> = { [SwapType.DebtSwap]: 0, }; -const getPartnerFeeRecipient = (market: CustomMarket): string => { - const collector = marketsData[market]?.addresses?.COLLECTOR; - return collector || COW_EVM_RECIPIENT; -}; - export const COW_PARTNER_FEE = ( tokenFromSymbol: string, tokenToSymbol: string, - swapType: SwapType, - market: CustomMarket + swapType?: SwapType ) => { const swapTypeBps = swapType !== undefined ? PARTNER_FEE_BPS_BY_SWAP_TYPE[swapType] : undefined; @@ -178,7 +170,7 @@ export const COW_PARTNER_FEE = ( return { volumeBps: swapTypeBps !== undefined ? swapTypeBps : defaultBps, - recipient: getPartnerFeeRecipient(market), + recipient: COW_EVM_RECIPIENT, }; }; @@ -191,8 +183,7 @@ export const COW_APP_DATA = ( smartSlippage: boolean, orderType: OrderType, appCode: string, - swapType: SwapType, - market: CustomMarket, + swapType?: SwapType, hooks?: Record ) => ({ appCode: appCode, @@ -205,7 +196,7 @@ export const COW_APP_DATA = ( ? { quote: { slippageBips, smartSlippage } } : // Slippage is not used in limit orders {}), - partnerFee: COW_PARTNER_FEE(tokenFromSymbol, tokenToSymbol, swapType, market), + partnerFee: COW_PARTNER_FEE(tokenFromSymbol, tokenToSymbol, swapType), hooks, }, }); diff --git a/src/components/transactions/Swap/helpers/cow/adapters.helpers.ts b/src/components/transactions/Swap/helpers/cow/adapters.helpers.ts index b8e78231cf..15cbe42284 100644 --- a/src/components/transactions/Swap/helpers/cow/adapters.helpers.ts +++ b/src/components/transactions/Swap/helpers/cow/adapters.helpers.ts @@ -14,7 +14,6 @@ import { FlashLoanHookAmounts, HASH_ZERO, } from '@cowprotocol/sdk-flash-loans'; -import { CustomMarket } from 'src/ui-config/marketsConfig'; import { COW_PARTNER_FEE, @@ -40,13 +39,11 @@ export const calculateInstanceAddress = async ({ validTo, type, state, - market, }: { user: string; validTo: number; type: AaveFlashLoanType; state: SwapState; - market: CustomMarket; }) => { if (!user) return; if ( @@ -86,8 +83,7 @@ export const calculateInstanceAddress = async ({ partnerFee: COW_PARTNER_FEE( state.sellAmountToken.symbol, state.buyAmountToken.symbol, - state.swapType, - market + state.swapType ), }; diff --git a/src/components/transactions/Swap/helpers/cow/orders.helpers.ts b/src/components/transactions/Swap/helpers/cow/orders.helpers.ts index 361a791ec2..5decda32c7 100644 --- a/src/components/transactions/Swap/helpers/cow/orders.helpers.ts +++ b/src/components/transactions/Swap/helpers/cow/orders.helpers.ts @@ -19,7 +19,6 @@ import { AnyAppDataDocVersion, AppDataParams, MetadataApi } from '@cowprotocol/s import { JsonRpcProvider } from '@ethersproject/providers'; import { BigNumber, ethers, PopulatedTransaction } from 'ethers'; import { isSmartContractWallet } from 'src/helpers/provider'; -import { CustomMarket } from 'src/ui-config/marketsConfig'; import { SignedParams } from '../../actions/approval/useSwapTokenApproval'; import { @@ -75,8 +74,7 @@ export type CowProtocolActionParams = { signatureParams?: SignedParams; estimateGasLimit?: (tx: PopulatedTransaction, chainId?: number) => Promise; validTo: number; - swapType: SwapType; - market: CustomMarket; + swapType?: SwapType; }; export const getPreSignTransaction = async ({ @@ -98,7 +96,6 @@ export const getPreSignTransaction = async ({ kind, validTo, swapType, - market, }: CowProtocolActionParams) => { if (!isChainIdSupportedByCoWProtocol(chainId)) { throw new Error('Chain not supported.'); @@ -131,8 +128,7 @@ export const getPreSignTransaction = async ({ smartSlippage, orderType, appCode, - swapType, - market + swapType ), additionalParams: { signingScheme: SigningScheme.PRESIGN, @@ -173,7 +169,6 @@ export const sendOrder = async ({ estimateGasLimit, validTo, swapType, - market, }: CowProtocolActionParams) => { const signer = provider?.getSigner(); @@ -209,7 +204,6 @@ export const sendOrder = async ({ orderType, appCode, swapType, - market, hooks ); @@ -301,7 +295,6 @@ export const getUnsignerOrder = async ({ srcToken, receiver, swapType, - market, }: { sellAmount: string; buyAmount: string; @@ -317,8 +310,7 @@ export const getUnsignerOrder = async ({ validTo: number; srcToken?: string; receiver?: string; - swapType: SwapType; - market: CustomMarket; + swapType?: SwapType; }) => { const metadataApi = new MetadataApi(); const { appDataHex } = await metadataApi.getAppDataInfo( @@ -329,8 +321,7 @@ export const getUnsignerOrder = async ({ smartSlippage, orderType, appCode, - swapType, - market + swapType ) ); @@ -370,8 +361,7 @@ export const populateEthFlowTx = async ( smartSlippage: boolean, appCode: string, orderType: OrderType, - swapType: SwapType, - market: CustomMarket, + swapType?: SwapType, quoteId?: number ): Promise => { const appDataHex = await hashAppData( @@ -382,8 +372,7 @@ export const populateEthFlowTx = async ( smartSlippage, orderType, appCode, - swapType, - market + swapType ) ); diff --git a/src/components/transactions/Swap/helpers/cow/rates.helpers.ts b/src/components/transactions/Swap/helpers/cow/rates.helpers.ts index bee66d93db..a433249e5b 100644 --- a/src/components/transactions/Swap/helpers/cow/rates.helpers.ts +++ b/src/components/transactions/Swap/helpers/cow/rates.helpers.ts @@ -56,7 +56,6 @@ export async function getCowProtocolSellRates({ isInputTokenCustom, isOutputTokenCustom, appCode, - market, setError, side = 'sell', invertedQuoteRoute = false, @@ -104,7 +103,7 @@ export async function getCowProtocolSellRates({ buyTokenDecimals: destDecimals, signer, appCode: appCode, - partnerFee: COW_PARTNER_FEE(inputSymbol, outputSymbol, swapType, market), + partnerFee: COW_PARTNER_FEE(inputSymbol, outputSymbol, swapType), }, { // Price Quality is set to OPTIMAL by default diff --git a/src/components/transactions/Swap/hooks/useSwapOrderAmounts.ts b/src/components/transactions/Swap/hooks/useSwapOrderAmounts.ts index 9f9e2c18e6..a7a84eb119 100644 --- a/src/components/transactions/Swap/hooks/useSwapOrderAmounts.ts +++ b/src/components/transactions/Swap/hooks/useSwapOrderAmounts.ts @@ -1,7 +1,6 @@ import { normalize, normalizeBN, valueToBigNumber } from '@aave/math-utils'; import { OrderKind } from '@cowprotocol/cow-sdk'; import { Dispatch, useEffect } from 'react'; -import { useRootStore } from 'src/store/root'; import { COW_PARTNER_FEE, FLASH_LOAN_FEE_BPS } from '../constants/cow.constants'; import { PARASWAP_FLASH_LOAN_FEE_BPS } from '../constants/paraswap.constants'; @@ -49,8 +48,6 @@ export const useSwapOrderAmounts = ({ state: SwapState; setState: Dispatch>; }) => { - const currentMarket = useRootStore((state) => state.currentMarket); - useEffect(() => { if ( !state.swapRate?.afterFeesAmount || @@ -82,12 +79,8 @@ export const useSwapOrderAmounts = ({ let networkFeeAmountInBuyFormatted = '0'; const partnetFeeBps = state.provider === SwapProvider.COW_PROTOCOL - ? COW_PARTNER_FEE( - state.sourceToken.symbol, - state.destinationToken.symbol, - state.swapType, - currentMarket - ).volumeBps + ? COW_PARTNER_FEE(state.sourceToken.symbol, state.destinationToken.symbol, state.swapType) + .volumeBps : 0; const partnerFeeAmount = state.side === 'sell' diff --git a/src/components/transactions/Swap/hooks/useSwapQuote.ts b/src/components/transactions/Swap/hooks/useSwapQuote.ts index aeba71f4f1..962f59059b 100644 --- a/src/components/transactions/Swap/hooks/useSwapQuote.ts +++ b/src/components/transactions/Swap/hooks/useSwapQuote.ts @@ -2,7 +2,6 @@ import { normalizeBN } from '@aave/math-utils'; import { useQuery } from '@tanstack/react-query'; import { Dispatch, useEffect, useMemo } from 'react'; import { useModalContext } from 'src/hooks/useModal'; -import { useRootStore } from 'src/store/root'; import { isTxErrorType, TxErrorType } from 'src/ui-config/errorMapping'; import { queryKeysFactory } from 'src/ui-config/queries'; @@ -290,7 +289,6 @@ const useMultiProviderSwapQuoteQuery = ({ requiresQuoteInverted: boolean; }) => { const { approvalTxState } = useModalContext(); - const currentMarket = useRootStore((state) => state.currentMarket); // Amount to quote depends on side (sell uses input amount, buy uses output amount) const amount = useMemo(() => { @@ -384,7 +382,6 @@ const useMultiProviderSwapQuoteQuery = ({ isInputTokenCustom, isOutputTokenCustom, appCode, - market: currentMarket, setError, side, invertedQuoteRoute: requiresQuoteInverted, @@ -401,7 +398,6 @@ const useMultiProviderSwapQuoteQuery = ({ destDecimals, side, appCode, - market: currentMarket, options: { partner: appCode, }, @@ -420,8 +416,7 @@ const useMultiProviderSwapQuoteQuery = ({ requiresQuoteInverted, srcToken, destToken, - state.user, - currentMarket + state.user ), enabled: (() => { // Allow fetch when user has entered a positive amount, even if normalization rounded to '0' diff --git a/src/components/transactions/Swap/types/quote.types.ts b/src/components/transactions/Swap/types/quote.types.ts index 3fc4152fdc..1af26369dc 100644 --- a/src/components/transactions/Swap/types/quote.types.ts +++ b/src/components/transactions/Swap/types/quote.types.ts @@ -1,7 +1,6 @@ import { OrderParameters, QuoteAmountsAndCosts, QuoteAndPost } from '@cowprotocol/cow-sdk'; import { OptimalRate } from '@paraswap/core'; import { TxErrorType } from 'src/ui-config/errorMapping'; -import { CustomMarket } from 'src/ui-config/marketsConfig'; import { SwapProvider, SwapType } from './shared.types'; @@ -30,7 +29,6 @@ export type ProviderRatesParams = { isInputTokenCustom?: boolean; isOutputTokenCustom?: boolean; appCode: string; - market: CustomMarket; setError?: (error: Error | TxErrorType) => void; }; diff --git a/src/ui-config/queries.ts b/src/ui-config/queries.ts index 0931847c60..418c9cf05f 100644 --- a/src/ui-config/queries.ts +++ b/src/ui-config/queries.ts @@ -98,8 +98,7 @@ export const queryKeysFactory = { requiresQuoteInverted: boolean, srcToken: string, destToken: string, - user: string, - market?: string + user: string ) => [ ...queryKeysFactory.user(user), chainId, @@ -108,7 +107,6 @@ export const queryKeysFactory = { requiresQuoteInverted, srcToken, destToken, - market, 'swapQuote', ], gasPrices: (chainId: number) => [chainId, 'gasPrices'],