slippage for swaps

This commit is contained in:
2025-12-03 16:53:57 -04:00
parent 4523195b78
commit d07ff55c13
2 changed files with 39 additions and 9 deletions

View File

@@ -99,6 +99,8 @@ export interface SwapRoute {
poolAddress: `0x${string}`;
inputTokenIndex: number;
outputTokenIndex: number;
inputTokenDecimal: number;
outputTokenDecimal: number;
}
export interface AvailableToken {
@@ -234,11 +236,29 @@ export function useGetPoolsByToken(tokenAddress: `0x${string}` | undefined, offs
functionName: 'symbol',
}).catch(() => null);
// Skip tokens with the same symbol as the selected token
const inputTokenDecimal = await publicClient.readContract({
address: tokenAddress,
abi: ERC20ABI,
functionName: 'decimals',
}).catch(() => null);
const outputTokenDecimal = await publicClient.readContract({
address: outputTokenAddress,
abi: ERC20ABI,
functionName: 'decimals',
}).catch(() => null);
// Skip tokens with the same symbol as the selected token
if (!outputTokenSymbol || outputTokenSymbol === selectedTokenSymbol) {
continue;
}
// Skip tokens if decimals failed to load
if (inputTokenDecimal === null || outputTokenDecimal === null) {
console.error(`Failed to load decimals for token ${outputTokenAddress} or ${tokenAddress}`);
continue;
}
// Create or update the available token entry
const tokenKey = outputTokenAddress.toLowerCase();
if (!tokenRoutesMap.has(tokenKey)) {
@@ -254,6 +274,8 @@ export function useGetPoolsByToken(tokenAddress: `0x${string}` | undefined, offs
poolAddress,
inputTokenIndex,
outputTokenIndex,
inputTokenDecimal,
outputTokenDecimal,
});
}
} catch (err) {
@@ -505,6 +527,8 @@ export function useGetAllPools(offset: number = 0, limit: number = 100) {
// Calculate TVL (approximate by getting first token balance and multiplying by 3)
const tokenBalance = Number(balance) / Math.pow(10, decimals);
console.log('tokenBalance', tokenBalance);
const approximateTVL = tokenBalance * 3;
tvlStr = formatTVL(approximateTVL);
}