Skip to content

Commit cb2f0b2

Browse files
authored
fix: send adapter appCode for CoW quotes in CollateralSwap (aave#2629)
1 parent 0a7e1b6 commit cb2f0b2

5 files changed

Lines changed: 38 additions & 8 deletions

File tree

src/components/transactions/Switch/cowprotocol/cowprotocol.helpers.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ export const getPreSignTransaction = async ({
140140
throw new Error('No signer found in provider');
141141
}
142142

143-
const tradingSdk = new TradingSdk({ chainId, signer, appCode: HEADER_WIDGET_APP_CODE });
143+
const tradingSdk = new TradingSdk({
144+
chainId,
145+
signer,
146+
appCode: appCode || HEADER_WIDGET_APP_CODE,
147+
});
144148

145149
const isSmartContract = await isSmartContractWallet(user, provider);
146150
if (!isSmartContract) {
@@ -287,11 +291,12 @@ export const populateEthFlowTx = async (
287291
tokenToSymbol: string,
288292
slippageBps: number,
289293
smartSlippage: boolean,
290-
quoteId?: number
294+
quoteId?: number,
295+
appCode?: string
291296
): Promise<PopulatedTransaction> => {
292297
const metadataApi = new MetadataApi();
293298
const { appDataHex } = await metadataApi.getAppDataInfo(
294-
COW_APP_DATA(tokenFromSymbol, tokenToSymbol, slippageBps, smartSlippage)
299+
COW_APP_DATA(tokenFromSymbol, tokenToSymbol, slippageBps, smartSlippage, appCode)
295300
);
296301

297302
const orderData = {

src/components/transactions/Switch/switch.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type ProviderRatesParams = {
2121

2222
isInputTokenCustom?: boolean;
2323
isOutputTokenCustom?: boolean;
24+
appCode?: string;
2425

2526
setError?: (error: TxErrorType) => void;
2627
};

src/hooks/switch/cowprotocol.rates.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
import { BigNumber } from 'bignumber.js';
99
import {
1010
COW_PARTNER_FEE,
11-
HEADER_WIDGET_APP_CODE,
1211
isNativeToken,
1312
} from 'src/components/transactions/Switch/cowprotocol/cowprotocol.helpers';
1413
import { isChainIdSupportedByCoWProtocol } from 'src/components/transactions/Switch/switch.constants';
@@ -63,6 +62,7 @@ export async function getCowProtocolSellRates({
6362
setError,
6463
isInputTokenCustom,
6564
isOutputTokenCustom,
65+
appCode,
6666
}: ProviderRatesParams): Promise<SwitchRatesType> {
6767
const tradingSdk = new TradingSdk({ chainId });
6868

@@ -106,7 +106,7 @@ export async function getCowProtocolSellRates({
106106
buyToken: destTokenWrapped,
107107
buyTokenDecimals: destDecimals,
108108
signer,
109-
appCode: HEADER_WIDGET_APP_CODE, // todo: use ADAPTER_APP_CODE for contract adapters
109+
appCode: appCode,
110110
partnerFee: COW_PARTNER_FEE(inputSymbol, outputSymbol),
111111
})
112112
.catch((cowError) => {

src/hooks/switch/useMultiProviderSwitchRates.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { useQuery } from '@tanstack/react-query';
22
import { useMemo } from 'react';
3+
import {
4+
ADAPTER_APP_CODE,
5+
HEADER_WIDGET_APP_CODE,
6+
} from 'src/components/transactions/Switch/cowprotocol/cowprotocol.helpers';
37
import {
48
MultiProviderRatesParams,
59
SwitchRatesType,
@@ -71,6 +75,9 @@ export const useMultiProviderSwitchRates = ({
7175
: destUnderlyingToken;
7276
}, [destAToken, destUnderlyingToken, provider, modalType, shouldUseFlashloan]);
7377

78+
const appCode =
79+
modalType === ModalType.CollateralSwap ? ADAPTER_APP_CODE : HEADER_WIDGET_APP_CODE;
80+
7481
return useQuery<SwitchRatesType>({
7582
queryFn: async () => {
7683
if (!provider) {
@@ -95,6 +102,7 @@ export const useMultiProviderSwitchRates = ({
95102
outputSymbol,
96103
isInputTokenCustom,
97104
isOutputTokenCustom,
105+
appCode,
98106
});
99107
case 'paraswap':
100108
return await getParaswapSellRates({
@@ -111,7 +119,14 @@ export const useMultiProviderSwitchRates = ({
111119
});
112120
}
113121
},
114-
queryKey: queryKeysFactory.cowProtocolRates(chainId, amount, srcToken, destToken, user),
122+
queryKey: queryKeysFactory.cowProtocolRates(
123+
chainId,
124+
amount,
125+
srcToken,
126+
destToken,
127+
user,
128+
appCode
129+
),
115130
enabled: amount !== '0' && !isTxSuccess,
116131
retry: 0,
117132
throwOnError: false,

src/ui-config/queries.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,17 @@ export const queryKeysFactory = {
101101
amount: string,
102102
srcToken: string,
103103
destToken: string,
104-
user: string
105-
) => [...queryKeysFactory.user(user), chainId, amount, srcToken, destToken, 'cowProtocolRates'],
104+
user: string,
105+
appCode?: string
106+
) => [
107+
...queryKeysFactory.user(user),
108+
chainId,
109+
amount,
110+
srcToken,
111+
destToken,
112+
appCode,
113+
'cowProtocolRates',
114+
],
106115
gasPrices: (chainId: number) => [chainId, 'gasPrices'],
107116
poolReservesIncentiveDataHumanized: (marketData: MarketDataType) => [
108117
...queryKeysFactory.pool,

0 commit comments

Comments
 (0)