const { ethers } = require("hardhat"); async function main() { console.log("๐Ÿ”ง Testing clearAllSellStakes function on LOCAL FORK"); console.log("โš ๏ธ THIS RUNS ON LOCAL FORK ONLY - NOT MAINNET"); // Contract address on Sonic mainnet (we'll query this via fork) const SONIC_PACA_ADDRESS = "0xa26F8128Ecb2FF2FC5618498758cC82Cf1FDad5F"; // Proxy address from deployedAddresses.json // Get signers const [owner] = await ethers.getSigners(); console.log("๐Ÿ”‘ Testing with account:", owner.address); // Get contract ABI - we'll need to compile first const contractFactory = await ethers.getContractFactory("PacaFinanceWithBoostAndScheduleSonic"); const contract = contractFactory.attach(SONIC_PACA_ADDRESS); console.log("\n๐Ÿ“Š BEFORE: Querying current sellStakes..."); try { // Query all sell stakes before clearing const beforeData = await contract.getAllSellStakesWithKeys(); console.log("๐Ÿ“ˆ Total sellStakes before:", beforeData[0].length); // Count zero address stakes let zeroAddressCount = 0; for (let i = 0; i < beforeData[0].length; i++) { if (beforeData[0][i] === "0x0000000000000000000000000000000000000000") { zeroAddressCount++; console.log(` - Zero address stake ${i}: stakeId=${beforeData[1][i]}, amount=${beforeData[2][i].amount}`); } } console.log(`๐Ÿ” Found ${zeroAddressCount} zero address sellStakes`); if (zeroAddressCount === 0) { console.log("โœ… No zero address sellStakes found - test not needed"); return; } console.log("\n๐Ÿงน EXECUTING: clearAllSellStakes(address(0))..."); // Call clearAllSellStakes for zero address const tx = await contract.clearAllSellStakes("0x0000000000000000000000000000000000000000"); console.log("๐Ÿ“ Transaction hash:", tx.hash); // Wait for transaction to be mined const receipt = await tx.wait(); console.log("โœ… Transaction mined in block:", receipt.blockNumber); console.log("โ›ฝ Gas used:", receipt.gasUsed.toString()); // Check events const events = receipt.logs; console.log(`๐Ÿ“ข Events emitted: ${events.length}`); console.log("\n๐Ÿ“Š AFTER: Querying sellStakes again..."); // Query all sell stakes after clearing const afterData = await contract.getAllSellStakesWithKeys(); console.log("๐Ÿ“ˆ Total sellStakes after:", afterData[0].length); // Count zero address stakes after let zeroAddressCountAfter = 0; for (let i = 0; i < afterData[0].length; i++) { if (afterData[0][i] === "0x0000000000000000000000000000000000000000") { zeroAddressCountAfter++; } } console.log(`๐Ÿ” Zero address sellStakes remaining: ${zeroAddressCountAfter}`); console.log("\n๐Ÿ“‹ SUMMARY:"); console.log(` - Before: ${zeroAddressCount} zero address sellStakes`); console.log(` - After: ${zeroAddressCountAfter} zero address sellStakes`); console.log(` - Cleared: ${zeroAddressCount - zeroAddressCountAfter} sellStakes`); console.log(` - Total sellStakes before: ${beforeData[0].length}`); console.log(` - Total sellStakes after: ${afterData[0].length}`); if (zeroAddressCountAfter === 0) { console.log("โœ… SUCCESS: All zero address sellStakes cleared!"); } else { console.log("โŒ WARNING: Some zero address sellStakes remain"); } } catch (error) { console.error("โŒ Error during test:", error.message); } } main() .then(() => process.exit(0)) .catch((error) => { console.error("โŒ Script failed:", error); process.exit(1); });