File tree Expand file tree Collapse file tree 5 files changed +34
-14
lines changed
src/components/transactions/Swap Expand file tree Collapse file tree 5 files changed +34
-14
lines changed Original file line number Diff line number Diff line change @@ -59,9 +59,12 @@ export const RepayWithCollateralDetails = ({
5959 const displayAmountAfterRepayInUsd = debtAmountAfterRepay . multipliedBy (
6060 state . sourceReserve . reserve . priceInUSD
6161 ) ;
62- const collateralAmountAfterRepay = tokenToRepayWithBalance
62+ const rawCollateralAmountAfterRepay = tokenToRepayWithBalance
6363 ? valueToBigNumber ( tokenToRepayWithBalance ) . minus ( state . sellAmountFormatted ?? '0' )
6464 : valueToBigNumber ( '0' ) ;
65+ const collateralAmountAfterRepay = rawCollateralAmountAfterRepay . isNegative ( )
66+ ? valueToBigNumber ( '0' )
67+ : rawCollateralAmountAfterRepay ;
6568 const collateralAmountAfterRepayUSD = collateralAmountAfterRepay . multipliedBy (
6669 state . destinationReserve . reserve . priceInUSD
6770 ) ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
1111 QuoteAndPost ,
1212 SellTokenSource ,
1313 SigningScheme ,
14+ SlippageToleranceRequest ,
1415 SupportedChainId ,
1516 WRAPPED_NATIVE_CURRENCIES ,
1617} from '@cowprotocol/cow-sdk' ;
@@ -494,6 +495,32 @@ export const getPermitHook = async ({
494495 } ;
495496} ;
496497
498+ // This function is used to get the slippage suggestion for a token pair on the respective chain based on the pair volatility.
499+ export const getSlippageSuggestion = async ( request : SlippageToleranceRequest ) => {
500+ const { sellToken, buyToken } = request ;
501+
502+ try {
503+ if ( request . chainId && sellToken && buyToken ) {
504+ const chainSlug = request . chainId ; // e.g., 42161 for Arbitrum
505+ const sell = sellToken . toLowerCase ( ) ;
506+ const buy = buyToken . toLowerCase ( ) ;
507+ const url = `https://bff.cow.fi/${ chainSlug } /markets/${ sell } -${ buy } /slippageTolerance` ;
508+
509+ const res = await fetch ( url ) ;
510+
511+ if ( res . ok ) {
512+ const result = await res . json ( ) ;
513+ // The endpoint returns { slippageBps: number }
514+ // This is expected by the CoW SDK within the Slippage logic.
515+ return result ;
516+ }
517+ }
518+ } catch ( e ) {
519+ console . error ( 'Error fetching slippage suggestion:' , e ) ;
520+ return undefined ;
521+ }
522+ } ;
523+
497524export const addOrderTypeToAppData = (
498525 orderType : OrderType ,
499526 appData ?: AppDataParams
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import { isNativeToken } from '../../helpers/cow';
1313import { CowProtocolRatesType , ProviderRatesParams , SwapProvider } from '../../types' ;
1414import { getAppDataForQuote } from './adapters.helpers' ;
1515import { getCowTradingSdkByChainIdAndAppCode } from './env.helpers' ;
16- import { priceQualityToUse } from './orders.helpers' ;
16+ import { getSlippageSuggestion , priceQualityToUse } from './orders.helpers' ;
1717
1818export const getTokenUsdPrice = async (
1919 chainId : number ,
@@ -119,6 +119,7 @@ export async function getCowProtocolSellRates({
119119 destToken,
120120 destDecimals,
121121 } ) ,
122+ getSlippageSuggestion,
122123 }
123124 )
124125 . catch ( ( cowError ) => {
Original file line number Diff line number Diff line change @@ -392,22 +392,11 @@ const useMultiProviderSwapQuoteQuery = ({
392392 state . user
393393 ) ,
394394 enabled : ( ( ) => {
395- console . log ( 'state.side' , state . side ) ;
396- console . log ( 'state.debouncedInputAmount' , state . debouncedInputAmount ) ;
397- console . log ( 'state.debouncedOutputAmount' , state . debouncedOutputAmount ) ;
398-
399- console . log (
400- 'limit' ,
401- ( state . orderType === OrderType . LIMIT && ! state . swapRate ) ||
402- state . orderType === OrderType . MARKET
403- ) ;
404-
405395 // Allow fetch when user has entered a positive amount, even if normalization rounded to '0'
406396 const hasPositiveUserAmount =
407397 state . side === 'sell'
408398 ? Number ( state . debouncedInputAmount || '0' ) > 0
409399 : Number ( state . debouncedOutputAmount || '0' ) > 0 ;
410- console . log ( 'hasPositiveUserAmount' , hasPositiveUserAmount ) ;
411400
412401 // Basic pre-blockers to avoid provider requests
413402 const isSameTokenPair =
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ export const RepayWithCollateralModalContent = ({
8989 interestMode,
9090 resultScreenTokensFromTitle : 'Repay' ,
9191 resultScreenTokensToTitle : 'With' ,
92- resultScreenTitleItems : 'repay ' ,
92+ resultScreenTitleItems : ' and repaid ' ,
9393 customReceivedTitle : 'Repaid' ,
9494
9595 // Note: Repay With Collateral order is inverted
You can’t perform that action at this time.
0 commit comments