93 lines
4.0 KiB
JavaScript
93 lines
4.0 KiB
JavaScript
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);
|
|
}); |