diff --git a/src/components/swap-form.tsx b/src/components/swap-form.tsx index a91b566..a60788f 100644 --- a/src/components/swap-form.tsx +++ b/src/components/swap-form.tsx @@ -397,9 +397,9 @@ export function SwapForm() { Math.abs(swapAmounts[0].calculatedSlippage) > currentSlippage ) && (
-

⚠️ High Slippage Warning

+

⚠️ Slippage Exceeds Your Tolerance

- The estimated slippage for this swap is {Math.abs(swapAmounts[0].calculatedSlippage).toFixed(2)}%. You may lose money due to low liquidity in this pool. + The estimated slippage for this swap is {Math.abs(swapAmounts[0].calculatedSlippage).toFixed(2)}%, which exceeds your maximum slippage setting of {currentSlippage}%. This swap may result in less favorable pricing than expected due to low liquidity.

)} @@ -493,7 +493,7 @@ export function SwapForm() {

- Your transaction will revert if the price changes unfavorably by more than this percentage. + You will be warned if the slippage exceeds this setting, and you can choose whether to proceed with the trade.

diff --git a/src/contracts/IPartyInfoABI.ts b/src/contracts/IPartyInfoABI.ts index d7ead43..4b30395 100644 --- a/src/contracts/IPartyInfoABI.ts +++ b/src/contracts/IPartyInfoABI.ts @@ -183,8 +183,8 @@ const IPartyInfoABI = [ "outputs": [ { "name": "", - "type": "int128", - "internalType": "int128" + "type": "uint256", + "internalType": "uint256" } ], "stateMutability": "view" diff --git a/src/contracts/IPartyPoolABI.ts b/src/contracts/IPartyPoolABI.ts index e36b459..3b52665 100644 --- a/src/contracts/IPartyPoolABI.ts +++ b/src/contracts/IPartyPoolABI.ts @@ -415,6 +415,19 @@ const IPartyPoolABI = [ ], "stateMutability": "payable" }, + { + "type": "function", + "name": "mintImpl", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, { "type": "function", "name": "name", @@ -605,6 +618,19 @@ const IPartyPoolABI = [ ], "stateMutability": "view" }, + { + "type": "function", + "name": "swapImpl", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "address", + "internalType": "address" + } + ], + "stateMutability": "view" + }, { "type": "function", "name": "swapMint", diff --git a/src/hooks/usePartyPool.ts b/src/hooks/usePartyPool.ts index 5e73275..7b2dd59 100644 --- a/src/hooks/usePartyPool.ts +++ b/src/hooks/usePartyPool.ts @@ -120,18 +120,6 @@ export function useSwapAmounts( setLoading(true); const amountInTokenUnits = parseUnits(fromAmount, fromTokenDecimals); - // Calculate limit price based on slippage tolerance - // limitPrice in Q96 format = Q96 * (100 + slippage%) / 100 - // This represents the maximum acceptable price ratio (1 + slippage%) - const slippageBasisPoints = BigInt(Math.floor(slippagePercent * 100)); // Convert to basis points (0.5% = 50) - const limitPrice = (Q96 * (10000n + slippageBasisPoints)) / 10000n; - - console.log('Limit Price Calculation:', { - slippagePercent, - slippageBasisPoints: slippageBasisPoints.toString(), - limitPriceQ96: limitPrice.toString(), - Q96: Q96.toString(), - }); const results: SwapAmountResult[] = []; const chainId = await publicClient.getChainId(); @@ -146,8 +134,8 @@ export function useSwapAmounts( // Evaluate ALL routes for this token for (const route of token.swapRoutes) { try { - // Get swap amounts - const swapResult = await publicClient.readContract({ + // Get swap amounts with NO LIMIT + const [swapInputAmount, swapOutputAmount, inFee] = await publicClient.readContract({ address: route.poolAddress, abi: IPartyPoolABI, functionName: 'swapAmounts', @@ -155,12 +143,10 @@ export function useSwapAmounts( BigInt(route.inputTokenIndex), BigInt(route.outputTokenIndex), amountInTokenUnits, - limitPrice, + 0n, // NO LIMIT ], }) as readonly [bigint, bigint, bigint]; - const [amountIn, amountOut, fee] = swapResult; - // Get kappa for this pool const kappa = await publicClient.readContract({ address: route.poolAddress, @@ -172,19 +158,6 @@ export function useSwapAmounts( let calculatedSlippage: number | undefined; if (partyInfoAddress) { try { - // Get swap amounts with NO LIMIT (0 means no price limit) - const [swapInputAmount, swapOutputAmount, inFee] = await publicClient.readContract({ - address: route.poolAddress, - abi: IPartyPoolABI, - functionName: 'swapAmounts', - args: [ - BigInt(route.inputTokenIndex), - BigInt(route.outputTokenIndex), - amountInTokenUnits, - 0n, // NO LIMIT - ], - }) as readonly [bigint, bigint, bigint]; - // Get the current market price from PoolInfo const priceInt128 = await publicClient.readContract({ address: partyInfoAddress, @@ -193,7 +166,6 @@ export function useSwapAmounts( args: [route.poolAddress, BigInt(route.inputTokenIndex), BigInt(route.outputTokenIndex)], }) as bigint; - // Convert Q128 format to decimal (price = priceValue / 2^128) // Then apply decimal conversion: 10^18 / 10^outputTokenDecimals const priceQ128 = Number(priceInt128) / 2 ** 128; @@ -214,9 +186,9 @@ export function useSwapAmounts( routeResults.push({ tokenAddress: token.address, tokenSymbol: token.symbol, - amountIn, - amountOut, - fee, + amountIn: swapInputAmount, + amountOut: swapOutputAmount, + fee: inFee, poolAddress: route.poolAddress, kappa, inputTokenIndex: route.inputTokenIndex,