Skip to content

Commit

Permalink
console logging paths creations
Browse files Browse the repository at this point in the history
  • Loading branch information
chopan123 committed Nov 17, 2024
1 parent 64d20a4 commit 426b55f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// 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.
2 changes: 1 addition & 1 deletion src/configs/protocols.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"key": "soroswap",
"value": true
"value": false
},
{
"key": "phoenix",
Expand Down
43 changes: 25 additions & 18 deletions src/functions/generateRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -117,16 +118,17 @@ 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,
amount,
);
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,
Expand All @@ -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
Expand All @@ -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) => {
Expand All @@ -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;
};

Expand Down
1 change: 1 addition & 0 deletions src/state/swap/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export function useDerivedSwapInfo(state: SwapState) {
(isExactIn ? outputCurrency : inputCurrency) ?? undefined,
account,
);
console.log('trade:', trade);

const currencyBalances = useMemo(
() => ({
Expand Down

0 comments on commit 426b55f

Please sign in to comment.