Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinsoza committed Jun 21, 2024
2 parents ac49b71 + 5e4d0e4 commit 91c8795
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"react-virtualized-auto-sizer": "^1.0.20",
"react-window": "^1.8.9",
"redux": "^4.2.1",
"soroswap-router-sdk": "1.2.6",
"soroswap-router-sdk": "^1.2.8",
"swr": "^2.2.0",
"typescript": "5.3.3",
"use-resize-observer": "^9.1.0"
Expand Down
27 changes: 18 additions & 9 deletions src/functions/generateRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useSorobanReact } from '@soroban-react/core';
import { AppContext } from 'contexts';
import { useFactory } from 'hooks';
import { useContext, useMemo } from 'react';
import { fetchAllSoroswapPairs } from 'services/pairs';
import { CurrencyAmount, Networks, Protocols, Router, Token, TradeType } from 'soroswap-router-sdk';
import { fetchAllPhoenixPairs, fetchAllSoroswapPairs } from 'services/pairs';

export interface GenerateRouteProps {
amountTokenAddress: string;
Expand All @@ -18,6 +18,8 @@ const queryNetworkDict: { [x: string]: 'MAINNET' | 'TESTNET' } = {
[Networks.TESTNET]: 'TESTNET',
};

const shouldUseBackend = process.env.NEXT_PUBLIC_SOROSWAP_BACKEND_ENABLED === 'true';

export const useRouterSDK = () => {
const sorobanContext = useSorobanReact();
const { factory } = useFactory(sorobanContext);
Expand All @@ -29,13 +31,20 @@ export const useRouterSDK = () => {

const router = useMemo(() => {
return new Router({
getPairsFn: async () => {
const data = await fetchAllSoroswapPairs(network);

return data;
},
getPairsFns: shouldUseBackend
? [
{
protocol: Protocols.SOROSWAP,
fn: async () => fetchAllSoroswapPairs(network),
},
// {
// protocol: Protocols.PHOENIX,
// fn: async () => fetchAllPhoenixPairs(network),
// },
]
: undefined,
pairsCacheInSeconds: 60,
protocols: [Protocols.SOROSWAP],
protocols: [Protocols.SOROSWAP], //, Protocols.PHOENIX],
network,
maxHops,
});
Expand All @@ -59,15 +68,15 @@ export const useRouterSDK = () => {
quoteTokenAddress,
amount,
tradeType,
isAggregator
isAggregator,
}: GenerateRouteProps) => {
if (!factory) throw new Error('Factory address not found');
const currencyAmount = fromAddressAndAmountToCurrencyAmount(amountTokenAddress, amount);
const quoteCurrency = fromAddressToToken(quoteTokenAddress);

if (isAggregator) {
return router.routeSplit(currencyAmount, quoteCurrency, tradeType);
}
}

return router.route(currencyAmount, quoteCurrency, tradeType, factory, sorobanContext as any);
};
Expand Down
14 changes: 14 additions & 0 deletions src/services/pairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,17 @@ export const fetchAllSoroswapPairs = async (networkPassphrase: string) => {
});
return data;
};

export const fetchAllPhoenixPairs = async (networkPassphrase: string) => {
const networkName = passphraseToBackendNetworkName[networkPassphrase];

const { data } = await axios.get<MercuryPair[]>(
`https://info.soroswap.finance/api/pairs/phoenix`,
{
params: {
network: networkName,
},
},
);
return data;
};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8324,10 +8324,10 @@ [email protected]:
stellar-base v10.0.0-beta.4
urijs "^1.19.1"

[email protected].6:
version "1.2.6"
resolved "https://registry.yarnpkg.com/soroswap-router-sdk/-/soroswap-router-sdk-1.2.6.tgz#40633e8a9d028263a80a504b325b6ec068dea5b4"
integrity sha512-i2IkVoFWlf+gxsoR1egiXWEagKC8UJj0Wj+3Z/tBZvRgvbdyoMVTv2LefB4xWrRoCC4nPiLQxcej4qPLqcrNAQ==
soroswap-router-sdk@^1.2.8:
version "1.2.8"
resolved "https://registry.yarnpkg.com/soroswap-router-sdk/-/soroswap-router-sdk-1.2.8.tgz#17d5a6e69b39ce61aa6ca312f4f0f6dd28d8ec73"
integrity sha512-m8kHw5EGStNlYyE4eTBP5o5475yCNTAE+zyGUWW3uScQsLWinm7yRxq6U2biWMocMmj5Eo2rDQUmhJyrUpDanw==
dependencies:
"@stellar/stellar-sdk" "^11.3.0"
axios "^1.6.5"
Expand Down

0 comments on commit 91c8795

Please sign in to comment.