slippage for swaps
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user