adding unstake basket page
This commit is contained in:
@@ -630,7 +630,6 @@ export function useBurnSwap() {
|
||||
deadline: deadline.toString(),
|
||||
unwrap,
|
||||
});
|
||||
|
||||
// STEP 3: Execute the burnSwap transaction
|
||||
const hash = await walletClient.writeContract({
|
||||
address: poolAddress,
|
||||
@@ -709,4 +708,162 @@ export function useBurnSwap() {
|
||||
burnSwapHash,
|
||||
burnSwapError,
|
||||
};
|
||||
}
|
||||
|
||||
export interface ActualBurnAmounts {
|
||||
lpBurned: bigint;
|
||||
withdrawAmounts: bigint[];
|
||||
}
|
||||
|
||||
export function useBurn() {
|
||||
const publicClient = usePublicClient();
|
||||
const { data: walletClient } = useWalletClient();
|
||||
const [isBurning, setIsBurning] = useState(false);
|
||||
const [burnHash, setBurnHash] = useState<`0x${string}` | null>(null);
|
||||
const [burnError, setBurnError] = useState<string | null>(null);
|
||||
|
||||
const executeBurn = async (
|
||||
poolAddress: `0x${string}`,
|
||||
lpAmount: bigint,
|
||||
unwrap: boolean = false
|
||||
) => {
|
||||
if (!walletClient || !publicClient) {
|
||||
setBurnError('Wallet not connected');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setIsBurning(true);
|
||||
setBurnError(null);
|
||||
setBurnHash(null);
|
||||
|
||||
const userAddress = walletClient.account.address;
|
||||
|
||||
// STEP 1: Approve the pool to spend the LP tokens
|
||||
console.log('🔐 Approving LP token spend for burn...');
|
||||
console.log('LP token (pool) to approve:', poolAddress);
|
||||
console.log('Spender (pool):', poolAddress);
|
||||
console.log('Amount:', lpAmount.toString());
|
||||
|
||||
const approvalHash = await walletClient.writeContract({
|
||||
address: poolAddress,
|
||||
abi: [
|
||||
{
|
||||
name: 'approve',
|
||||
type: 'function',
|
||||
stateMutability: 'nonpayable',
|
||||
inputs: [
|
||||
{ name: 'spender', type: 'address' },
|
||||
{ name: 'amount', type: 'uint256' }
|
||||
],
|
||||
outputs: [{ name: '', type: 'bool' }]
|
||||
}
|
||||
],
|
||||
functionName: 'approve',
|
||||
args: [poolAddress, lpAmount],
|
||||
account: userAddress,
|
||||
});
|
||||
|
||||
console.log('✅ Approval transaction submitted:', approvalHash);
|
||||
await publicClient.waitForTransactionReceipt({ hash: approvalHash });
|
||||
console.log('✅ Approval confirmed');
|
||||
|
||||
// STEP 2: Calculate deadline (20 minutes from now)
|
||||
const deadline = BigInt(Math.floor(Date.now() / 1000) + 1200); // 20 minutes = 1200 seconds
|
||||
|
||||
console.log('🚀 Executing burn with params:', {
|
||||
pool: poolAddress,
|
||||
payer: userAddress,
|
||||
receiver: userAddress,
|
||||
lpAmount: lpAmount.toString(),
|
||||
deadline: deadline.toString(),
|
||||
unwrap,
|
||||
});
|
||||
|
||||
// Log details for cast call
|
||||
console.log('\n=== CAST CALL DETAILS FOR BURN ===');
|
||||
console.log('Contract Address:', poolAddress);
|
||||
console.log('Function: burn(address,address,uint256,uint256,bool)');
|
||||
console.log('Parameters:');
|
||||
console.log(' - payer (address):', userAddress);
|
||||
console.log(' - receiver (address):', userAddress);
|
||||
console.log(' - lpAmount (uint256):', lpAmount.toString());
|
||||
console.log(' - deadline (uint256):', deadline.toString());
|
||||
console.log(' - unwrap (bool):', unwrap);
|
||||
console.log('\nCast command:');
|
||||
console.log(`cast call ${poolAddress} "burn(address,address,uint256,uint256,bool)" ${userAddress} ${userAddress} ${lpAmount.toString()} ${deadline.toString()} ${unwrap} --from ${userAddress}`);
|
||||
console.log('=====================================\n');
|
||||
|
||||
// STEP 3: Execute the burn transaction
|
||||
const hash = await walletClient.writeContract({
|
||||
address: poolAddress,
|
||||
abi: IPartyPoolABI,
|
||||
functionName: 'burn',
|
||||
args: [
|
||||
userAddress, // payer
|
||||
userAddress, // receiver
|
||||
lpAmount,
|
||||
deadline,
|
||||
unwrap,
|
||||
],
|
||||
account: userAddress,
|
||||
});
|
||||
|
||||
setBurnHash(hash);
|
||||
console.log('✅ Burn transaction submitted:', hash);
|
||||
|
||||
// Wait for transaction confirmation
|
||||
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
||||
console.log('✅ Burn transaction confirmed:', receipt);
|
||||
|
||||
// Parse the Burn event from the receipt logs
|
||||
let actualBurnAmounts: ActualBurnAmounts | null = null;
|
||||
for (const log of receipt.logs) {
|
||||
try {
|
||||
const decodedLog = decodeEventLog({
|
||||
abi: IPartyPoolABI,
|
||||
data: log.data,
|
||||
topics: log.topics,
|
||||
});
|
||||
|
||||
if (decodedLog.eventName === 'Burn') {
|
||||
const { amounts, lpBurned } = decodedLog.args as {
|
||||
amounts: bigint[];
|
||||
lpBurned: bigint;
|
||||
};
|
||||
|
||||
actualBurnAmounts = {
|
||||
lpBurned,
|
||||
withdrawAmounts: amounts,
|
||||
};
|
||||
|
||||
console.log('📊 Actual burn amounts from event:', {
|
||||
lpBurned: lpBurned.toString(),
|
||||
withdrawAmounts: amounts.map(a => a.toString()),
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (err) {
|
||||
// Skip logs that don't match our ABI
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return { receipt, actualBurnAmounts };
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : 'Burn failed';
|
||||
setBurnError(errorMessage);
|
||||
console.error('❌ Burn error:', err);
|
||||
throw err;
|
||||
} finally {
|
||||
setIsBurning(false);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
executeBurn,
|
||||
isBurning,
|
||||
burnHash,
|
||||
burnError,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user