adding actual amounts and fees to confirmation pages for swap, stake and unstake
This commit is contained in:
@@ -448,6 +448,11 @@ export interface SwapMintAmounts {
|
||||
lpMinted: bigint;
|
||||
}
|
||||
|
||||
export interface BurnSwapAmounts {
|
||||
amountOut: bigint;
|
||||
outFee: bigint;
|
||||
}
|
||||
|
||||
export function useSwapMintAmounts(
|
||||
poolAddress: `0x${string}` | undefined,
|
||||
inputTokenIndex: number | undefined,
|
||||
@@ -531,7 +536,7 @@ export function useBurnSwapAmounts(
|
||||
) {
|
||||
const publicClient = usePublicClient();
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [burnSwapAmounts, setBurnSwapAmounts] = useState<bigint | null>(null);
|
||||
const [burnSwapAmounts, setBurnSwapAmounts] = useState<BurnSwapAmounts | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
@@ -567,15 +572,43 @@ export function useBurnSwapAmounts(
|
||||
return;
|
||||
}
|
||||
|
||||
// Call burnSwapAmounts function
|
||||
// Log inputs
|
||||
console.log('🔍 burnSwapAmounts INPUTS:', {
|
||||
chainId: chainId.toString(),
|
||||
rpcUrl: publicClient.transport?.url || 'Unknown',
|
||||
poolAddress,
|
||||
lpAmount: lpAmount.toString(),
|
||||
inputTokenIndex,
|
||||
viewerAddress,
|
||||
});
|
||||
|
||||
// Call burnSwapAmounts function - returns [amountOut, outFee]
|
||||
const result = await publicClient.readContract({
|
||||
address: viewerAddress as `0x${string}`,
|
||||
abi: IPartyPoolViewerABI,
|
||||
functionName: 'burnSwapAmounts',
|
||||
args: [poolAddress, lpAmount, BigInt(inputTokenIndex)],
|
||||
}) as bigint;
|
||||
}) as readonly [bigint, bigint];
|
||||
|
||||
setBurnSwapAmounts(result);
|
||||
// Log raw result
|
||||
console.log('📊 burnSwapAmounts RAW RESULT:', {
|
||||
resultArray: result,
|
||||
amountOut: result[0].toString(),
|
||||
outFee: result[1].toString(),
|
||||
});
|
||||
|
||||
const parsedAmounts = {
|
||||
amountOut: result[0],
|
||||
outFee: result[1],
|
||||
};
|
||||
|
||||
// Log parsed result
|
||||
console.log('✅ burnSwapAmounts PARSED:', {
|
||||
amountOut: parsedAmounts.amountOut.toString(),
|
||||
outFee: parsedAmounts.outFee.toString(),
|
||||
});
|
||||
|
||||
setBurnSwapAmounts(parsedAmounts);
|
||||
} catch (err) {
|
||||
console.error('Error calling burnSwapAmounts:', err);
|
||||
setError(err instanceof Error ? err.message : 'Failed to fetch burn swap amounts');
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { usePublicClient, useWalletClient } from 'wagmi';
|
||||
import { decodeEventLog } from 'viem';
|
||||
import IPartyPoolABI from '@/contracts/IPartyPoolABI';
|
||||
import chainInfo from '../../../lmsr-amm/liqp-deployments.json';
|
||||
import type { AvailableToken } from './usePartyPlanner';
|
||||
@@ -189,6 +190,27 @@ export interface GasEstimate {
|
||||
estimatedCostUsd: string;
|
||||
}
|
||||
|
||||
export interface ActualSwapAmounts {
|
||||
amountIn: bigint;
|
||||
amountOut: bigint;
|
||||
lpFee: bigint;
|
||||
protocolFee: bigint;
|
||||
}
|
||||
|
||||
export interface ActualSwapMintAmounts {
|
||||
amountInUsed: bigint;
|
||||
lpMinted: bigint;
|
||||
lpFee: bigint;
|
||||
protocolFee: bigint;
|
||||
}
|
||||
|
||||
export interface ActualBurnSwapAmounts {
|
||||
amountIn: bigint;
|
||||
amountOut: bigint;
|
||||
lpFee: bigint;
|
||||
protocolFee: bigint;
|
||||
}
|
||||
|
||||
export function useSwap() {
|
||||
const { data: walletClient } = useWalletClient();
|
||||
const publicClient = usePublicClient();
|
||||
@@ -338,7 +360,46 @@ export function useSwap() {
|
||||
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
||||
console.log('✅ Swap transaction confirmed:', receipt);
|
||||
|
||||
return receipt;
|
||||
// Parse the Swap event from the receipt logs
|
||||
let actualSwapAmounts: ActualSwapAmounts | null = null;
|
||||
for (const log of receipt.logs) {
|
||||
try {
|
||||
const decodedLog = decodeEventLog({
|
||||
abi: IPartyPoolABI,
|
||||
data: log.data,
|
||||
topics: log.topics,
|
||||
});
|
||||
|
||||
if (decodedLog.eventName === 'Swap') {
|
||||
const { amountIn, amountOut, lpFee, protocolFee } = decodedLog.args as {
|
||||
amountIn: bigint;
|
||||
amountOut: bigint;
|
||||
lpFee: bigint;
|
||||
protocolFee: bigint;
|
||||
};
|
||||
|
||||
actualSwapAmounts = {
|
||||
amountIn,
|
||||
amountOut,
|
||||
lpFee,
|
||||
protocolFee,
|
||||
};
|
||||
|
||||
console.log('📊 Actual swap amounts from event:', {
|
||||
amountIn: amountIn.toString(),
|
||||
amountOut: amountOut.toString(),
|
||||
lpFee: lpFee.toString(),
|
||||
protocolFee: protocolFee.toString(),
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
// Skip logs that don't match our ABI
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return { receipt, actualSwapAmounts };
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : 'Swap failed';
|
||||
setSwapError(errorMessage);
|
||||
@@ -446,7 +507,46 @@ export function useSwapMint() {
|
||||
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
||||
console.log('✅ SwapMint transaction confirmed:', receipt);
|
||||
|
||||
return receipt;
|
||||
// Parse the SwapMint event from the receipt logs
|
||||
let actualSwapMintAmounts: ActualSwapMintAmounts | null = null;
|
||||
for (const log of receipt.logs) {
|
||||
try {
|
||||
const decodedLog = decodeEventLog({
|
||||
abi: IPartyPoolABI,
|
||||
data: log.data,
|
||||
topics: log.topics,
|
||||
});
|
||||
|
||||
if (decodedLog.eventName === 'SwapMint') {
|
||||
const { amountIn, amountOut, lpFee, protocolFee } = decodedLog.args as {
|
||||
amountIn: bigint;
|
||||
amountOut: bigint;
|
||||
lpFee: bigint;
|
||||
protocolFee: bigint;
|
||||
};
|
||||
|
||||
actualSwapMintAmounts = {
|
||||
amountInUsed: amountIn,
|
||||
lpMinted: amountOut,
|
||||
lpFee,
|
||||
protocolFee,
|
||||
};
|
||||
|
||||
console.log('📊 Actual swap mint amounts from event:', {
|
||||
amountInUsed: amountIn.toString(),
|
||||
lpMinted: amountOut.toString(),
|
||||
lpFee: lpFee.toString(),
|
||||
protocolFee: protocolFee.toString(),
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
// Skip logs that don't match our ABI
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return { receipt, actualSwapMintAmounts };
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : 'SwapMint failed';
|
||||
setSwapMintError(errorMessage);
|
||||
@@ -553,7 +653,46 @@ export function useBurnSwap() {
|
||||
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
||||
console.log('✅ BurnSwap transaction confirmed:', receipt);
|
||||
|
||||
return receipt;
|
||||
// Parse the BurnSwap event from the receipt logs
|
||||
let actualBurnSwapAmounts: ActualBurnSwapAmounts | null = null;
|
||||
for (const log of receipt.logs) {
|
||||
try {
|
||||
const decodedLog = decodeEventLog({
|
||||
abi: IPartyPoolABI,
|
||||
data: log.data,
|
||||
topics: log.topics,
|
||||
});
|
||||
|
||||
if (decodedLog.eventName === 'BurnSwap') {
|
||||
const { amountIn, amountOut, lpFee, protocolFee } = decodedLog.args as {
|
||||
amountIn: bigint;
|
||||
amountOut: bigint;
|
||||
lpFee: bigint;
|
||||
protocolFee: bigint;
|
||||
};
|
||||
|
||||
actualBurnSwapAmounts = {
|
||||
amountIn,
|
||||
amountOut,
|
||||
lpFee,
|
||||
protocolFee,
|
||||
};
|
||||
|
||||
console.log('📊 Actual burn swap amounts from event:', {
|
||||
amountIn: amountIn.toString(),
|
||||
amountOut: amountOut.toString(),
|
||||
lpFee: lpFee.toString(),
|
||||
protocolFee: protocolFee.toString(),
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
// Skip logs that don't match our ABI
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return { receipt, actualBurnSwapAmounts };
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : 'BurnSwap failed';
|
||||
setBurnSwapError(errorMessage);
|
||||
|
||||
Reference in New Issue
Block a user