From 426b55f33641835bbac434e6abe61b7b5beb4161 Mon Sep 17 00:00:00 2001 From: chopan123 Date: Sun, 17 Nov 2024 11:04:30 -0300 Subject: [PATCH] console logging paths creations --- next-env.d.ts | 2 +- src/configs/protocols.config.json | 2 +- src/functions/generateRoute.ts | 43 ++++++++++++++++++------------- src/state/swap/hooks.tsx | 1 + 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/next-env.d.ts b/next-env.d.ts index 4f11a03d..a4a7b3f5 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. +// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. diff --git a/src/configs/protocols.config.json b/src/configs/protocols.config.json index b1c48992..140198c2 100644 --- a/src/configs/protocols.config.json +++ b/src/configs/protocols.config.json @@ -6,7 +6,7 @@ }, { "key": "soroswap", - "value": true + "value": false }, { "key": "phoenix", diff --git a/src/functions/generateRoute.ts b/src/functions/generateRoute.ts index a94e0d7f..d723a066 100644 --- a/src/functions/generateRoute.ts +++ b/src/functions/generateRoute.ts @@ -64,28 +64,29 @@ export const useRouterSDK = () => { const getPairsFns = useMemo(() => { const routerProtocols = [] - if(shouldUseBackend) return undefined + if (shouldUseBackend) return undefined // here you should add your new supported aggregator protocols - for(let protocol of protocolsStatus){ - if(protocol.key === Protocol.SOROSWAP && protocol.value === true){ - routerProtocols.push({protocol: Protocol.SOROSWAP, fn: async () => fetchAllSoroswapPairs(network)}); + for (let protocol of protocolsStatus) { + if (protocol.key === Protocol.SOROSWAP && protocol.value === true) { + routerProtocols.push({ protocol: Protocol.SOROSWAP, fn: async () => fetchAllSoroswapPairs(network) }); } - if(protocol.key === Protocol.PHOENIX && protocol.value === true){ - routerProtocols.push({protocol: Protocol.PHOENIX, fn: async () => fetchAllPhoenixPairs(network)}); + if (protocol.key === Protocol.PHOENIX && protocol.value === true) { + routerProtocols.push({ protocol: Protocol.PHOENIX, fn: async () => fetchAllPhoenixPairs(network) }); } } + console.log('routerProtocols:', routerProtocols); return routerProtocols; }, [network, protocolsStatus]); const getProtocols = useMemo(() => { const newProtocols = []; - for(let protocol of protocolsStatus){ - if(protocol.key != PlatformType.STELLAR_CLASSIC && protocol.value === true){ + for (let protocol of protocolsStatus) { + if (protocol.key != PlatformType.STELLAR_CLASSIC && protocol.value === true) { newProtocols.push(protocol.key); } } return newProtocols as Protocol[]; - },[protocolsStatus]); + }, [protocolsStatus]); const router = useMemo(() => { return new Router({ @@ -117,6 +118,7 @@ export const useRouterSDK = () => { tradeType, currentProtocolsStatus, }: GenerateRouteProps) => { + console.log('generateRoute:', amountAsset, quoteAsset, amount, tradeType, currentProtocolsStatus); if (!factory) throw new Error('Factory address not found'); const currencyAmount = fromAddressAndAmountToCurrencyAmount( amountAsset.currency.contract, @@ -124,9 +126,9 @@ export const useRouterSDK = () => { ); const quoteCurrency = fromAddressToToken(quoteAsset.contract); - const isHorizonEnabled = currentProtocolsStatus.find((p) => p.key === PlatformType.STELLAR_CLASSIC)?.value; + const isHorizonEnabled = currentProtocolsStatus.find((p) => p.key === PlatformType.STELLAR_CLASSIC)?.value; - const isSoroswapEnabled = currentProtocolsStatus.find((p) => p.key === Protocol.SOROSWAP)?.value; + const isSoroswapEnabled = currentProtocolsStatus.find((p) => p.key === Protocol.SOROSWAP)?.value; const horizonProps = { assetFrom: amountAsset.currency, @@ -136,10 +138,11 @@ export const useRouterSDK = () => { }; let horizonPath: BuildTradeRoute | undefined; - if(isHorizonEnabled){ + if (isHorizonEnabled) { horizonPath = (await getHorizonBestPath(horizonProps, sorobanContext)) as BuildTradeRoute; } - + console.log('horizonPath:', horizonPath); + let sorobanPath: BuildTradeRoute | undefined; if (isAggregator) { sorobanPath = (await router @@ -149,10 +152,14 @@ export const useRouterSDK = () => { const result = { ...response, platform: PlatformType.AGGREGATOR, - }; + quoteCurrency: CurrencyAmount.fromRawAmount(quoteCurrency, '0') + } as BuildTradeRoute; return result; - })) as BuildTradeRoute; - } else if(isSoroswapEnabled){ + }).catch((e) => { + console.error('error while generating soroban path:', e); + return undefined; + })) as BuildTradeRoute | undefined; + } else if (isSoroswapEnabled) { sorobanPath = (await router .route(currencyAmount, quoteCurrency, tradeType, factory, sorobanContext as any) .then((response) => { @@ -164,9 +171,9 @@ export const useRouterSDK = () => { return result; })) as BuildTradeRoute; } - + console.log('sorobanPath:', sorobanPath); const bestPath = getBestPath(horizonPath, sorobanPath, tradeType); - + console.log('bestPath:', bestPath); return bestPath; }; diff --git a/src/state/swap/hooks.tsx b/src/state/swap/hooks.tsx index 24d9e03c..13925d91 100644 --- a/src/state/swap/hooks.tsx +++ b/src/state/swap/hooks.tsx @@ -130,6 +130,7 @@ export function useDerivedSwapInfo(state: SwapState) { (isExactIn ? outputCurrency : inputCurrency) ?? undefined, account, ); + console.log('trade:', trade); const currencyBalances = useMemo( () => ({