Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ export const CollateralSwapActionsViaCowAdapters = ({
setState: Dispatch<Partial<SwapState>>;
trackingHandlers: TrackAnalyticsHandlers;
}) => {
const [user, currentMarket] = useRootStore(
useShallow((state) => [state.account, state.currentMarket])
);
const [user] = useRootStore(useShallow((state) => [state.account]));

const collateralsAmount = useCollateralsAmount();

Expand Down Expand Up @@ -85,7 +83,6 @@ export const CollateralSwapActionsViaCowAdapters = ({
validTo,
type: AaveFlashLoanType.CollateralSwap,
state,
market: currentMarket,
})
.catch((error) => {
console.error('calculateInstanceAddress error', error);
Expand All @@ -110,7 +107,6 @@ export const CollateralSwapActionsViaCowAdapters = ({
state.slippage,
state.orderType,
state.chainId,
currentMarket,
]);

// Approval is aToken ERC20 Approval
Expand Down Expand Up @@ -207,8 +203,7 @@ export const CollateralSwapActionsViaCowAdapters = ({
partnerFee: COW_PARTNER_FEE(
state.sellAmountToken.symbol,
state.buyAmountToken.symbol,
state.swapType,
currentMarket
state.swapType
),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ export const DebtSwapActionsViaCoW = ({
setState: Dispatch<Partial<SwapState>>;
trackingHandlers: TrackAnalyticsHandlers;
}) => {
const [user, currentMarket] = useRootStore(
useShallow((state) => [state.account, state.currentMarket])
);
const [user] = useRootStore(useShallow((state) => [state.account]));

const debtAmount = useCollateralsAmount();

Expand Down Expand Up @@ -94,7 +92,6 @@ export const DebtSwapActionsViaCoW = ({
validTo,
type: AaveFlashLoanType.DebtSwap,
state,
market: currentMarket,
})
.catch((error) => {
console.error('calculateInstanceAddress error', error);
Expand Down Expand Up @@ -122,7 +119,6 @@ export const DebtSwapActionsViaCoW = ({
APP_CODE_PER_SWAP_TYPE[state.swapType],
approvalTxState.loading,
approvalTxState.success,
currentMarket,
]);

const amountToApprove = useMemo(() => {
Expand Down Expand Up @@ -234,8 +230,7 @@ export const DebtSwapActionsViaCoW = ({
partnerFee: COW_PARTNER_FEE(
state.sellAmountToken.symbol,
state.buyAmountToken.symbol,
state.swapType,
currentMarket
state.swapType
),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ export const RepayWithCollateralActionsViaCoW = ({
setState: Dispatch<Partial<SwapState>>;
trackingHandlers: TrackAnalyticsHandlers;
}) => {
const [user, currentMarket] = useRootStore(
useShallow((state) => [state.account, state.currentMarket])
);
const [user] = useRootStore(useShallow((state) => [state.account]));

const collateralsAmount = useCollateralsAmount();

Expand Down Expand Up @@ -94,7 +92,6 @@ export const RepayWithCollateralActionsViaCoW = ({
validTo,
type: AaveFlashLoanType.RepayCollateral,
state,
market: currentMarket,
})
.catch((error) => {
console.error('calculateInstanceAddress error', error);
Expand Down Expand Up @@ -122,7 +119,6 @@ export const RepayWithCollateralActionsViaCoW = ({
APP_CODE_PER_SWAP_TYPE[state.swapType],
approvalTxState.loading,
approvalTxState.success,
currentMarket,
]);

// Approval is aToken ERC20 Approval
Expand Down Expand Up @@ -232,8 +228,7 @@ export const RepayWithCollateralActionsViaCoW = ({
partnerFee: COW_PARTNER_FEE(
state.sellAmountToken.symbol,
state.buyAmountToken.symbol,
state.swapType,
currentMarket
state.swapType
),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,8 @@ export const SwapActionsViaCoW = ({
setState: Dispatch<Partial<SwapState>>;
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 } =
Expand Down Expand Up @@ -192,7 +187,6 @@ export const SwapActionsViaCoW = ({
appCode,
state.orderType,
params.swapType,
currentMarket,
state.swapRate.quoteId
);
const txWithGasEstimation = await estimateGasLimit(ethFlowTx, state.chainId);
Expand Down Expand Up @@ -228,7 +222,6 @@ export const SwapActionsViaCoW = ({
orderType: state.orderType,
validTo,
swapType: params.swapType,
market: currentMarket,
});
const calculatedOrderId = await calculateUniqueOrderId(state.chainId, unsignerOrder);

Expand All @@ -242,8 +235,7 @@ export const SwapActionsViaCoW = ({
smartSlippage,
state.orderType,
APP_CODE_PER_SWAP_TYPE[params.swapType],
params.swapType,
currentMarket
params.swapType
)
),
state.chainId
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -347,7 +338,6 @@ export const SwapActionsViaCoW = ({
smartSlippage,
orderType: state.orderType,
swapType: params.swapType,
market: currentMarket,
kind:
state.orderType === OrderType.MARKET
? OrderKind.SELL
Expand Down
17 changes: 4 additions & 13 deletions src/components/transactions/Swap/constants/cow.constants.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -158,16 +156,10 @@ const PARTNER_FEE_BPS_BY_SWAP_TYPE: Partial<Record<SwapType, number>> = {
[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;

Expand All @@ -178,7 +170,7 @@ export const COW_PARTNER_FEE = (

return {
volumeBps: swapTypeBps !== undefined ? swapTypeBps : defaultBps,
recipient: getPartnerFeeRecipient(market),
recipient: COW_EVM_RECIPIENT,
};
};

Expand All @@ -191,8 +183,7 @@ export const COW_APP_DATA = (
smartSlippage: boolean,
orderType: OrderType,
appCode: string,
swapType: SwapType,
market: CustomMarket,
swapType?: SwapType,
hooks?: Record<string, unknown>
) => ({
appCode: appCode,
Expand All @@ -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,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
FlashLoanHookAmounts,
HASH_ZERO,
} from '@cowprotocol/sdk-flash-loans';
import { CustomMarket } from 'src/ui-config/marketsConfig';

import {
COW_PARTNER_FEE,
Expand All @@ -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 (
Expand Down Expand Up @@ -86,8 +83,7 @@ export const calculateInstanceAddress = async ({
partnerFee: COW_PARTNER_FEE(
state.sellAmountToken.symbol,
state.buyAmountToken.symbol,
state.swapType,
market
state.swapType
),
};

Expand Down
23 changes: 6 additions & 17 deletions src/components/transactions/Swap/helpers/cow/orders.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -75,8 +74,7 @@ export type CowProtocolActionParams = {
signatureParams?: SignedParams;
estimateGasLimit?: (tx: PopulatedTransaction, chainId?: number) => Promise<PopulatedTransaction>;
validTo: number;
swapType: SwapType;
market: CustomMarket;
swapType?: SwapType;
};

export const getPreSignTransaction = async ({
Expand All @@ -98,7 +96,6 @@ export const getPreSignTransaction = async ({
kind,
validTo,
swapType,
market,
}: CowProtocolActionParams) => {
if (!isChainIdSupportedByCoWProtocol(chainId)) {
throw new Error('Chain not supported.');
Expand Down Expand Up @@ -131,8 +128,7 @@ export const getPreSignTransaction = async ({
smartSlippage,
orderType,
appCode,
swapType,
market
swapType
),
additionalParams: {
signingScheme: SigningScheme.PRESIGN,
Expand Down Expand Up @@ -173,7 +169,6 @@ export const sendOrder = async ({
estimateGasLimit,
validTo,
swapType,
market,
}: CowProtocolActionParams) => {
const signer = provider?.getSigner();

Expand Down Expand Up @@ -209,7 +204,6 @@ export const sendOrder = async ({
orderType,
appCode,
swapType,
market,
hooks
);

Expand Down Expand Up @@ -301,7 +295,6 @@ export const getUnsignerOrder = async ({
srcToken,
receiver,
swapType,
market,
}: {
sellAmount: string;
buyAmount: string;
Expand All @@ -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(
Expand All @@ -329,8 +321,7 @@ export const getUnsignerOrder = async ({
smartSlippage,
orderType,
appCode,
swapType,
market
swapType
)
);

Expand Down Expand Up @@ -370,8 +361,7 @@ export const populateEthFlowTx = async (
smartSlippage: boolean,
appCode: string,
orderType: OrderType,
swapType: SwapType,
market: CustomMarket,
swapType?: SwapType,
quoteId?: number
): Promise<PopulatedTransaction> => {
const appDataHex = await hashAppData(
Expand All @@ -382,8 +372,7 @@ export const populateEthFlowTx = async (
smartSlippage,
orderType,
appCode,
swapType,
market
swapType
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export async function getCowProtocolSellRates({
isInputTokenCustom,
isOutputTokenCustom,
appCode,
market,
setError,
side = 'sell',
invertedQuoteRoute = false,
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading