Commit before cuna
This commit is contained in:
89
scripts/createUpgradeScript.js
Normal file
89
scripts/createUpgradeScript.js
Normal file
@@ -0,0 +1,89 @@
|
||||
const { ethers, upgrades } = require("hardhat");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const deploymentFile = path.join(__dirname, "deployedAddresses.json");
|
||||
|
||||
async function main() {
|
||||
console.log("Creating upgrade script for storage layout fix...");
|
||||
|
||||
// Get deployment data
|
||||
let deploymentData = {};
|
||||
if (fs.existsSync(deploymentFile)) {
|
||||
deploymentData = JSON.parse(fs.readFileSync(deploymentFile, "utf8"));
|
||||
console.log("Current proxy address:", deploymentData.proxyAddress);
|
||||
console.log("Current implementation:", deploymentData.implementationAddress);
|
||||
}
|
||||
|
||||
const network = "localhost"; // Default for testing
|
||||
console.log("Network:", network);
|
||||
|
||||
const contractName = network === "mainnet"
|
||||
? "PacaFinanceWithBoostAndScheduleUSDT"
|
||||
: "PacaFinanceWithBoostAndScheduleUSDC";
|
||||
|
||||
console.log("Contract name:", contractName);
|
||||
|
||||
try {
|
||||
// Get the contract factory
|
||||
const ContractFactory = await ethers.getContractFactory(contractName);
|
||||
console.log("✅ Contract factory created successfully");
|
||||
|
||||
// Validate contract compilation
|
||||
const bytecode = ContractFactory.bytecode;
|
||||
const bytecodeSize = bytecode.length / 2;
|
||||
console.log(`Contract size: ${bytecodeSize} bytes (limit: 24576 bytes)`);
|
||||
|
||||
if (bytecodeSize > 24576) {
|
||||
console.log("❌ Contract exceeds size limit");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("✅ Contract size within limits");
|
||||
|
||||
// Validate interface
|
||||
const interface = ContractFactory.interface;
|
||||
|
||||
const criticalFunctions = [
|
||||
"sellStakes",
|
||||
"getAllSellStakesWithKeys",
|
||||
"sellStake",
|
||||
"buySellStake",
|
||||
"cancelSellStake"
|
||||
];
|
||||
|
||||
for (const func of criticalFunctions) {
|
||||
try {
|
||||
interface.getFunction(func);
|
||||
console.log(`✅ ${func} function available`);
|
||||
} catch (error) {
|
||||
console.log(`❌ ${func} function missing`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("\n=== Upgrade Summary ===");
|
||||
console.log("Storage layout fix applied:");
|
||||
console.log("- Moved withdrawVesting mapping from slot 139 to slot 147");
|
||||
console.log("- Moved withdrawVestingCounter from slot 140 to slot 148");
|
||||
console.log("- Restored sellStakes mapping to original slot 141");
|
||||
console.log("- All other storage variables maintain their positions");
|
||||
|
||||
console.log("\n=== Next Steps ===");
|
||||
console.log("1. Deploy this upgraded implementation using deployProxy.js");
|
||||
console.log("2. The existing proxy will automatically use the new implementation");
|
||||
console.log("3. sellStakes functionality will be restored");
|
||||
console.log("4. All existing data will remain intact");
|
||||
|
||||
console.log("\n✅ Storage layout fix ready for deployment!");
|
||||
|
||||
} catch (error) {
|
||||
console.error("❌ Error:", error.message);
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user