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

View File

@@ -0,0 +1,186 @@
const { ethers } = require("hardhat");
async function main() {
console.log("🧪 BEFORE/AFTER Stakes Clearing Test");
console.log("=====================================");
console.log("Network: BSC Mainnet Fork");
const targetUser = "0x41970Ce76b656030A79E7C1FA76FC4EB93980255";
const pacaAddress = process.env.PROXY_ADDRESS_BSC || "0x3fF44D639a4982A4436f6d737430141aBE68b4E1";
console.log(`🎯 Target User: ${targetUser}`);
console.log(`🔗 PACA Contract: ${pacaAddress}`);
// Connect to existing PACA contract on the fork
const PacaFactory = await ethers.getContractFactory("PacaFinanceWithBoostAndScheduleBsc");
const paca = PacaFactory.attach(pacaAddress);
// Deploy BotManager
console.log("\n🚀 Deploying BotManager...");
const BotManagerFactory = await ethers.getContractFactory("PacaBotManager");
const botManager = await BotManagerFactory.deploy();
await botManager.waitForDeployment();
const botManagerAddress = await botManager.getAddress();
console.log(`✅ BotManager deployed: ${botManagerAddress}`);
// Impersonate the target user (who is the contract owner) to authorize the bot
console.log("\n🔑 Authorizing BotManager as bot...");
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [targetUser],
});
await hre.network.provider.send("hardhat_setBalance", [
targetUser,
"0x56BC75E2D630E0000", // 100 ETH for gas
]);
const userSigner = await ethers.getSigner(targetUser);
const addBotTx = await paca.connect(userSigner).addBot(botManagerAddress);
await addBotTx.wait();
console.log(`✅ BotManager authorized as bot`);
// ========================================
// PART 1: GET STAKES BEFORE CLEARING
// ========================================
console.log("\n" + "=".repeat(60));
console.log("📊 GETTING STAKES **BEFORE** CLEARING");
console.log("=".repeat(60));
const stakesBefore = await paca.getStakes(targetUser);
console.log(`\n📋 getStakes() returned ${stakesBefore.length} stakes BEFORE clearing:`);
let totalAmountBefore = 0n;
let activeStakesBefore = 0;
stakesBefore.forEach((stake, i) => {
const isActive = !stake.complete && stake.amount > 0n;
if (isActive) {
activeStakesBefore++;
totalAmountBefore += stake.amount;
}
console.log(`\n Stake ${i + 1} BEFORE:`);
console.log(` amount: ${ethers.formatEther(stake.amount)} ETH`);
console.log(` complete: ${stake.complete}`);
console.log(` status: ${isActive ? "🟢 ACTIVE" : "🔴 COMPLETED"}`);
});
console.log(`\n💎 SUMMARY BEFORE:`);
console.log(` Total Stakes: ${stakesBefore.length}`);
console.log(` Active Stakes: ${activeStakesBefore}`);
console.log(` Total Active Amount: ${ethers.formatEther(totalAmountBefore)} ETH`);
// ========================================
// PART 2: EXECUTE CLEARING
// ========================================
console.log("\n" + "=".repeat(60));
console.log("🔥 EXECUTING clearStakes() VIA BOTMANAGER");
console.log("=".repeat(60));
console.log("\n⚡ Calling botManager.clearStakes()...");
const [deployer] = await ethers.getSigners();
const clearTx = await botManager.connect(deployer).clearStakes(pacaAddress, targetUser);
const receipt = await clearTx.wait();
console.log(`✅ clearStakes() executed successfully!`);
console.log(`⛽ Gas used: ${receipt.gasUsed.toString()}`);
console.log(`🧾 Transaction: ${receipt.hash}`);
// ========================================
// PART 3: GET STAKES AFTER CLEARING
// ========================================
console.log("\n" + "=".repeat(60));
console.log("📊 GETTING STAKES **AFTER** CLEARING");
console.log("=".repeat(60));
const stakesAfter = await paca.getStakes(targetUser);
console.log(`\n📋 getStakes() returned ${stakesAfter.length} stakes AFTER clearing:`);
let totalAmountAfter = 0n;
let activeStakesAfter = 0;
let clearedStakes = 0;
stakesAfter.forEach((stake, i) => {
const isActive = !stake.complete && stake.amount > 0n;
const wasCleared = stake.complete && stake.amount === 0n;
if (isActive) {
activeStakesAfter++;
totalAmountAfter += stake.amount;
}
if (wasCleared) {
clearedStakes++;
}
console.log(`\n Stake ${i + 1} AFTER:`);
console.log(` amount: ${ethers.formatEther(stake.amount)} ETH`);
console.log(` complete: ${stake.complete}`);
console.log(` status: ${wasCleared ? "✅ CLEARED" : isActive ? "🟢 ACTIVE" : "❓ UNKNOWN"}`);
});
console.log(`\n💎 SUMMARY AFTER:`);
console.log(` Total Stakes: ${stakesAfter.length}`);
console.log(` Active Stakes: ${activeStakesAfter}`);
console.log(` Cleared Stakes: ${clearedStakes}`);
console.log(` Total Active Amount: ${ethers.formatEther(totalAmountAfter)} ETH`);
// ========================================
// PART 4: COMPARISON & VERIFICATION
// ========================================
console.log("\n" + "=".repeat(60));
console.log("🎯 BEFORE vs AFTER COMPARISON");
console.log("=".repeat(60));
console.log(`\n📊 STAKES COUNT:`);
console.log(` Before: ${stakesBefore.length} total`);
console.log(` After: ${stakesAfter.length} total`);
console.log(` Change: ${stakesAfter.length === stakesBefore.length ? "✅ SAME (expected)" : "❌ DIFFERENT"}`);
console.log(`\n🟢 ACTIVE STAKES:`);
console.log(` Before: ${activeStakesBefore} active`);
console.log(` After: ${activeStakesAfter} active`);
console.log(` Change: ${activeStakesBefore - activeStakesAfter} stakes cleared`);
console.log(`\n💰 TOTAL AMOUNT STAKED:`);
console.log(` Before: ${ethers.formatEther(totalAmountBefore)} ETH`);
console.log(` After: ${ethers.formatEther(totalAmountAfter)} ETH`);
console.log(` Cleared: ${ethers.formatEther(totalAmountBefore - totalAmountAfter)} ETH`);
// FINAL VERIFICATION
console.log(`\n🔍 VERIFICATION:`);
const allAmountsZeroed = stakesAfter.every(stake => stake.amount === 0n);
const allMarkedComplete = stakesAfter.every(stake => stake.complete === true);
const noActiveStakes = activeStakesAfter === 0;
console.log(` ✅ All amounts zeroed: ${allAmountsZeroed}`);
console.log(` ✅ All marked complete: ${allMarkedComplete}`);
console.log(` ✅ No active stakes remaining: ${noActiveStakes}`);
if (allAmountsZeroed && allMarkedComplete && noActiveStakes) {
console.log(`\n🎉 SUCCESS! Stakes cleared completely!`);
console.log(` - Cleared ${activeStakesBefore} active stakes`);
console.log(` - Zeroed out ${ethers.formatEther(totalAmountBefore)} ETH`);
console.log(` - All stakes marked as complete`);
} else {
console.log(`\n⚠️ PARTIAL SUCCESS or FAILURE:`);
console.log(` - Some stakes may not have been cleared properly`);
}
// Clean up
await hre.network.provider.request({
method: "hardhat_stopImpersonatingAccount",
params: [targetUser],
});
console.log("\n" + "=".repeat(60));
console.log("🏁 TEST COMPLETED");
console.log("=".repeat(60));
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error("💥 Test failed:", error);
process.exit(1);
});