Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/configs/default.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"maxHops": 1,
"slippageTolerance": 1
}
5 changes: 3 additions & 2 deletions src/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { PlatformType, Protocol } from 'state/routing/types';
import defaultSettings from 'configs/default.settings.json';

type ConnectWalletModalType = {
isConnectWalletModalOpen: boolean;
Expand Down Expand Up @@ -68,13 +69,13 @@ export const AppContext = React.createContext<AppContextType>({
setSnackbarType: () => {},
},
Settings: {
maxHops: 2,
maxHops: defaultSettings.maxHops,
setMaxHops: () => {},
protocolsStatus: [],
setProtocolsStatus: () => {},
isAggregatorState: false,
setAggregatorStatus: () => {},
aggregatorAddress: '',
setAggregatorAddress: () => {}
setAggregatorAddress: () => {},
},
});
10 changes: 8 additions & 2 deletions src/functions/generateRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { getExpectedAmount } from './getExpectedAmount';
import { Networks } from '@stellar/stellar-sdk';
import { getSwapRoute, getSwapSplitRoute } from 'services/soroswapApi';
import { passphraseToBackendNetworkName } from 'services/pairs';
import { DEFAULT_SLIPPAGE_INPUT_VALUE } from 'components/Settings/MaxSlippageSettings';
import { useUserSlippageToleranceWithDefault } from 'state/user/hooks';

export interface GenerateRouteProps {
amountAsset: AmountAsset;
Expand All @@ -36,6 +38,8 @@ const shouldUseDirectPath = process.env.NEXT_PUBLIC_DIRECT_PATH_ENABLED === 'tru
export const useSoroswapApi = () => {
const sorobanContext = useSorobanReact();
const { Settings } = useContext(AppContext);
const allowedSlippage = useUserSlippageToleranceWithDefault(DEFAULT_SLIPPAGE_INPUT_VALUE);


const { factory } = useFactory(sorobanContext);

Expand Down Expand Up @@ -176,8 +180,9 @@ export const useSoroswapApi = () => {
tradeType: tradeType,
protocols: getProtocols,
parts: 10,
slippageTolerance: '0.01',
slippageTolerance: allowedSlippage.toString(),
assetList: ['SOROSWAP'],
maxHops: maxHops,
};

try {
Expand All @@ -194,8 +199,9 @@ export const useSoroswapApi = () => {
assetOut: tradeType === TradeType.EXACT_INPUT ? quoteAsset.contract : amountAsset.currency.contract,
amount: amount,
tradeType: tradeType,
slippageTolerance: '0.01',
slippageTolerance: allowedSlippage.toString(),
assetList: ['SOROSWAP'],
maxHops: maxHops,
};

try {
Expand Down
17 changes: 16 additions & 1 deletion src/helpers/aggregator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,23 @@ export function poolHashesToScVal(poolHashes?: string[]): xdr.ScVal {
}

export const dexDistributionParser = (dexDistributionRaw: DexDistribution[]): xdr.ScVal => {


console.log("🚀 ~ dexDistributionRaw:", dexDistributionRaw)
const dexDistributionScVal = dexDistributionRaw.map((distribution) => {

let protocol_id_num;
if (distribution.protocol_id === 'soroswap') {
protocol_id_num = 0;
}
else if (distribution.protocol_id === 'phoenix') {
protocol_id_num = 1;
} else if (distribution.protocol_id === 'aqua') {
protocol_id_num = 2;
} else {
throw new Error(`Unknown protocol_id: ${distribution.protocol_id}`);
}

return xdr.ScVal.scvMap([
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol('bytes'),
Expand All @@ -80,7 +95,7 @@ export const dexDistributionParser = (dexDistributionRaw: DexDistribution[]): xd
}),
new xdr.ScMapEntry({
key: xdr.ScVal.scvSymbol('protocol_id'),
val: xdr.ScVal.scvString(distribution.protocol_id),
val: nativeToScVal(protocol_id_num, {type: 'u32'}),
}),
]);
});
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useBestTrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ExactOutBuildTradeReturn,
ExactOutSplitBuildTradeReturn,
InterfaceTrade,
QuoteState,
QuoteState,
TradeState,
TradeType,
} from 'state/routing/types';
Expand Down Expand Up @@ -41,6 +41,7 @@ export function useBestTrade(
} {
const { generateRoute, resetRouterSdkCache, maxHops } = useSoroswapApi();
const { protocolsStatus } = useContext(AppContext).Settings;

/**
* Custom hook that fetches the best trade based on the specified amount and trade type.
*
Expand Down
2 changes: 2 additions & 0 deletions src/state/routing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type SwapRouteRequest = {
tradeType: string;
slippageTolerance: string;
assetList?: string[];
maxHops?: number;
};

export type SwapRouteSplitRequest = {
Expand All @@ -59,6 +60,7 @@ export type SwapRouteSplitRequest = {
parts: number;
slippageTolerance: string;
assetList?: string[];
maxHops?: number;
};

interface CommonBuildTradeReturnFields {
Expand Down
Loading