Commit before cuna

This commit is contained in:
2025-09-04 02:48:34 +02:00
parent 7e55515063
commit 8ef7f0b9f1
32 changed files with 4668 additions and 17 deletions

158
test_clear_zero_address.js Normal file
View File

@@ -0,0 +1,158 @@
const { ethers } = require("hardhat");
async function main() {
console.log("🔧 Testing clearAllSellStakes function on LOCAL SONIC FORK");
console.log("⚠️ THIS RUNS ON LOCAL FORK ONLY - NOT MAINNET");
// Contract address on Sonic mainnet
const SONIC_PACA_ADDRESS = "0xa26F8128Ecb2FF2FC5618498758cC82Cf1FDad5F";
// Owner address from the contract (from line 186 in sonic_paca.sol)
const OWNER_ADDRESS = "0x41970Ce76b656030A79E7C1FA76FC4EB93980255";
console.log("📍 Contract address:", SONIC_PACA_ADDRESS);
console.log("👑 Contract owner:", OWNER_ADDRESS);
// Impersonate the owner account
await ethers.provider.send("hardhat_impersonateAccount", [OWNER_ADDRESS]);
const owner = await ethers.getSigner(OWNER_ADDRESS);
// Give the owner some ETH for gas
await ethers.provider.send("hardhat_setBalance", [
OWNER_ADDRESS,
"0x1000000000000000000", // 1 ETH
]);
console.log("🔑 Impersonating owner:", owner.address);
console.log("💰 Owner balance:", ethers.formatEther(await ethers.provider.getBalance(owner.address)), "ETH");
// Get contract instance
const contractFactory = await ethers.getContractFactory("PacaFinanceWithBoostAndScheduleSonic");
const contract = contractFactory.attach(SONIC_PACA_ADDRESS).connect(owner);
console.log("\n📊 STEP 1: Querying current sellStakes...");
try {
// Query all sell stakes before clearing
const beforeData = await contract.getAllSellStakesWithKeys();
const totalBefore = beforeData[0].length;
console.log("📈 Total sellStakes before:", totalBefore);
if (totalBefore === 0) {
console.log(" No sellStakes found - contract may be empty");
return;
}
// Count zero address stakes
let zeroAddressCount = 0;
const zeroStakes = [];
for (let i = 0; i < beforeData[0].length; i++) {
const seller = beforeData[0][i];
const stakeId = beforeData[1][i];
const stakeData = beforeData[2][i];
if (seller === "0x0000000000000000000000000000000000000000") {
zeroAddressCount++;
zeroStakes.push({
index: i,
stakeId: stakeId.toString(),
amount: ethers.formatEther(stakeData.amount),
price: ethers.formatEther(stakeData.price)
});
}
}
console.log(`🔍 Found ${zeroAddressCount} zero address sellStakes:`);
zeroStakes.forEach((stake, idx) => {
console.log(` ${idx + 1}. StakeId: ${stake.stakeId}, Amount: ${stake.amount} ETH, Price: ${stake.price} ETH`);
});
if (zeroAddressCount === 0) {
console.log("✅ No zero address sellStakes found - test not needed");
return;
}
console.log("\n🧹 STEP 2: Executing clearAllSellStakes(address(0))...");
// Estimate gas first
try {
const gasEstimate = await contract.clearAllSellStakes.estimateGas("0x0000000000000000000000000000000000000000");
console.log("⛽ Estimated gas:", gasEstimate.toString());
} catch (gasError) {
console.log("⚠️ Gas estimation failed:", gasError.message);
}
// Call clearAllSellStakes for zero address
const tx = await contract.clearAllSellStakes("0x0000000000000000000000000000000000000000");
console.log("📝 Transaction hash:", tx.hash);
// Wait for transaction to be mined
console.log("⏳ Waiting 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());
// Parse events
console.log(`📢 Events emitted: ${receipt.logs.length}`);
for (let i = 0; i < receipt.logs.length; i++) {
try {
const parsedLog = contract.interface.parseLog(receipt.logs[i]);
if (parsedLog.name === "StakeSaleCancelled") {
console.log(` - StakeSaleCancelled: address=${parsedLog.args[0]}, stakeId=${parsedLog.args[1]}`);
}
} catch (e) {
// Ignore unparseable logs
}
}
console.log("\n📊 STEP 3: Querying sellStakes after clearing...");
// Query all sell stakes after clearing
const afterData = await contract.getAllSellStakesWithKeys();
const totalAfter = afterData[0].length;
console.log("📈 Total sellStakes after:", totalAfter);
// 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(` - Remaining zero address stake: stakeId=${afterData[1][i]}`);
}
}
console.log(`🔍 Zero address sellStakes remaining: ${zeroAddressCountAfter}`);
console.log("\n📋 FINAL SUMMARY:");
console.log("=" .repeat(50));
console.log(`📊 Total sellStakes: ${totalBefore}${totalAfter} (${totalAfter - totalBefore >= 0 ? '+' : ''}${totalAfter - totalBefore})`);
console.log(`🗑️ Zero address stakes: ${zeroAddressCount}${zeroAddressCountAfter} (${zeroAddressCountAfter - zeroAddressCount >= 0 ? '+' : ''}${zeroAddressCountAfter - zeroAddressCount})`);
console.log(`✨ Cleared: ${zeroAddressCount - zeroAddressCountAfter} zero address sellStakes`);
console.log("=" .repeat(50));
if (zeroAddressCountAfter === 0 && zeroAddressCount > 0) {
console.log("🎉 SUCCESS: All zero address sellStakes have been cleared!");
} else if (zeroAddressCount === 0) {
console.log(" INFO: No zero address sellStakes were found to clear");
} else {
console.log("⚠️ WARNING: Some zero address sellStakes may still remain");
}
} catch (error) {
console.error("❌ Error during test:", error.message);
if (error.reason) {
console.error("💡 Reason:", error.reason);
}
}
// Stop impersonating
await ethers.provider.send("hardhat_stopImpersonatingAccount", [OWNER_ADDRESS]);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error("❌ Script failed:", error);
process.exit(1);
});