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,196 @@
const { ethers } = require("hardhat");
async function main() {
console.log("🔧 Testing clearStakes for Real User");
console.log("===================================");
const targetUser = "0x41970Ce76b656030A79E7C1FA76FC4EB93980255";
console.log(`🎯 Target user: ${targetUser}`);
// Get deployer account
const [deployer] = await ethers.getSigners();
console.log(`📍 Deployer: ${deployer.address}`);
// Connect to the existing BSC PACA contract
const pacaAddress = process.env.PROXY_ADDRESS_BSC || "0x7b00A99882cF35Fa084dEBf797968B0ddEc9F957";
console.log(`🔗 Using PACA contract at: ${pacaAddress}`);
// Get contract factory and connect to existing contract
const PacaFactory = await ethers.getContractFactory("PacaFinanceWithBoostAndScheduleBsc");
const paca = PacaFactory.attach(pacaAddress);
// Deploy BotManager
console.log("\n🤖 Deploying PacaBotManager...");
const BotManagerFactory = await ethers.getContractFactory("PacaBotManager");
const botManager = await BotManagerFactory.deploy();
await botManager.waitForDeployment();
const botManagerAddress = await botManager.getAddress();
console.log(`✅ BotManager deployed: ${botManagerAddress}`);
// Add BotManager as authorized bot (using deployer as owner)
console.log("\n🔗 Adding BotManager as authorized bot...");
try {
const addBotTx = await paca.addBot(botManagerAddress);
await addBotTx.wait();
console.log("✅ BotManager authorized as bot");
} catch (error) {
console.log(`⚠️ Could not add bot directly: ${error.message}`);
console.log(" This might be expected if deployer is not the owner");
// Try with the target user as owner (they might be the contract owner)
console.log(" Trying with target user as owner...");
await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [targetUser],
});
await hre.network.provider.send("hardhat_setBalance", [
targetUser,
"0x56BC75E2D630E0000", // 100 ETH
]);
const userSigner = await ethers.getSigner(targetUser);
const addBotTx2 = await paca.connect(userSigner).addBot(botManagerAddress);
await addBotTx2.wait();
console.log("✅ BotManager authorized as bot (via user account)");
await hre.network.provider.request({
method: "hardhat_stopImpersonatingAccount",
params: [targetUser],
});
}
// Check if bot is authorized
const isBotAuthorized = await paca.authorizedBots(botManagerAddress);
console.log(`🔍 Bot authorization verified: ${isBotAuthorized}`);
// Get stakes BEFORE clearing
console.log(`\n📊 Getting stakes for ${targetUser} BEFORE clearing:`);
console.log("=" * 60);
let stakesBefore;
try {
stakesBefore = await paca.getStakes(targetUser);
console.log(`📈 User has ${stakesBefore.length} stakes BEFORE clearing`);
if (stakesBefore.length > 0) {
let totalStakedBefore = 0n;
let activeStakes = 0;
for (let i = 0; i < stakesBefore.length; i++) {
const stake = stakesBefore[i];
const isActive = !stake.complete && stake.amount > 0;
if (isActive) activeStakes++;
console.log(` Stake ${i + 1}:`);
console.log(` Amount: ${ethers.formatEther(stake.amount)} ETH`);
console.log(` Complete: ${stake.complete}`);
console.log(` Active: ${isActive ? "YES" : "NO"}`);
console.log("");
totalStakedBefore += stake.amount;
}
console.log(`💎 BEFORE - Total staked: ${ethers.formatEther(totalStakedBefore)} ETH`);
console.log(`🔥 BEFORE - Active stakes: ${activeStakes} out of ${stakesBefore.length}`);
} else {
console.log("📭 No stakes found for this user");
console.log("⚠️ This might mean:");
console.log(" 1. User has no stakes");
console.log(" 2. We're not connected to the right network/contract");
console.log(" 3. Contract doesn't have a getStakes function");
}
} catch (error) {
console.log(`❌ Error getting stakes: ${error.message}`);
stakesBefore = [];
}
// Execute clearStakes via BotManager
console.log(`\n🚀 Executing clearStakes via BotManager...`);
try {
const clearTx = await botManager.clearStakes(pacaAddress, targetUser);
const receipt = await clearTx.wait();
console.log(`✅ clearStakes executed successfully!`);
console.log(`⛽ Gas used: ${receipt.gasUsed.toString()}`);
console.log(`🧾 Transaction hash: ${receipt.hash}`);
} catch (error) {
console.log(`❌ Failed to execute clearStakes: ${error.message}`);
if (error.data) {
console.log(`🔍 Error data: ${error.data}`);
}
return;
}
// Get stakes AFTER clearing
console.log(`\n📊 Getting stakes for ${targetUser} AFTER clearing:`);
console.log("=" * 60);
try {
const stakesAfter = await paca.getStakes(targetUser);
console.log(`📉 User has ${stakesAfter.length} stakes AFTER clearing`);
if (stakesAfter.length > 0) {
let totalStakedAfter = 0n;
let activeStakes = 0;
let clearedStakes = 0;
for (let i = 0; i < stakesAfter.length; i++) {
const stake = stakesAfter[i];
const isActive = !stake.complete && stake.amount > 0;
const wasCleared = stake.complete && stake.amount === 0n;
if (isActive) activeStakes++;
if (wasCleared) clearedStakes++;
console.log(` Stake ${i + 1}:`);
console.log(` Amount: ${ethers.formatEther(stake.amount)} ETH`);
console.log(` Complete: ${stake.complete}`);
console.log(` Status: ${wasCleared ? "CLEARED ✅" : isActive ? "ACTIVE ⚡" : "UNKNOWN ❓"}`);
console.log("");
totalStakedAfter += stake.amount;
}
console.log(`💎 AFTER - Total staked: ${ethers.formatEther(totalStakedAfter)} ETH`);
console.log(`🔥 AFTER - Active stakes: ${activeStakes} out of ${stakesAfter.length}`);
console.log(`✅ AFTER - Cleared stakes: ${clearedStakes} out of ${stakesAfter.length}`);
// Summary
console.log(`\n🎯 CLEARING RESULTS:`);
if (totalStakedAfter === 0n && clearedStakes === stakesAfter.length) {
console.log(`🎉 SUCCESS! All stakes cleared completely!`);
} else if (totalStakedAfter === 0n) {
console.log(`✅ SUCCESS! All stake amounts zeroed!`);
} else if (clearedStakes > 0) {
console.log(`⚡ PARTIAL! ${clearedStakes} stakes cleared, ${activeStakes} still active`);
} else {
console.log(`❌ NO CHANGE! Stakes were not cleared`);
}
} else {
console.log("📭 No stakes found after clearing");
}
} catch (error) {
console.log(`❌ Error getting stakes after clearing: ${error.message}`);
}
console.log("\n📋 Test Summary");
console.log("===============");
console.log(`🎯 Target User: ${targetUser}`);
console.log(`🔧 PACA Contract: ${pacaAddress}`);
console.log(`🤖 BotManager: ${botManagerAddress}`);
console.log(`✅ Bot Authorized: ${isBotAuthorized}`);
console.log(`📊 Stakes Before: ${stakesBefore?.length || 0}`);
console.log("🎉 Test completed!");
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error("💥 Test failed:", error);
process.exit(1);
});