Initial commit: CunaFinanceBsc smart contract

- Add upgradeable smart contract with vesting and staking functionality
- Include comprehensive deployment script for proxy deployments and upgrades
- Configure Hardhat with BSC testnet and verification support
- Successfully deployed to BSC testnet at 0x12d705781764b7750d5622727EdA2392b512Ca3d

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-10 02:15:20 +02:00
commit 8a802718d3
49 changed files with 7667 additions and 0 deletions

147
scripts/deploy.js Normal file
View File

@@ -0,0 +1,147 @@
const { ethers, upgrades } = require("hardhat");
const fs = require("fs");
const path = require("path");
// File to store deployment addresses
const DEPLOYMENT_FILE = path.join(__dirname, "deployments.json");
// Load existing deployments
function loadDeployments() {
if (fs.existsSync(DEPLOYMENT_FILE)) {
return JSON.parse(fs.readFileSync(DEPLOYMENT_FILE, "utf8"));
}
return {};
}
// Save deployment info
function saveDeployment(network, contractName, proxyAddress, implementationAddress) {
const deployments = loadDeployments();
if (!deployments[network]) {
deployments[network] = {};
}
deployments[network][contractName] = {
proxy: proxyAddress,
implementation: implementationAddress,
deployedAt: new Date().toISOString()
};
fs.writeFileSync(DEPLOYMENT_FILE, JSON.stringify(deployments, null, 2));
}
async function main() {
const network = hre.network.name;
console.log(`\n🚀 Deploying to network: ${network}\n`);
const [deployer] = await ethers.getSigners();
console.log(`📝 Deploying with account: ${deployer.address}`);
console.log(`💰 Account balance: ${ethers.formatEther(await deployer.provider.getBalance(deployer.address))} ETH\n`);
const contractName = "CunaFinanceBsc";
const deployments = loadDeployments();
const existingDeployment = deployments[network]?.[contractName];
try {
if (existingDeployment?.proxy) {
console.log(`🔄 Existing proxy found at: ${existingDeployment.proxy}`);
console.log("📦 Upgrading contract...\n");
// Get the contract factory
const CunaFinanceBsc = await ethers.getContractFactory(contractName);
// Upgrade the proxy
const upgraded = await upgrades.upgradeProxy(existingDeployment.proxy, CunaFinanceBsc);
await upgraded.waitForDeployment();
const newImplementationAddress = await upgrades.erc1967.getImplementationAddress(existingDeployment.proxy);
console.log(`✅ Contract upgraded successfully!`);
console.log(`📍 Proxy address: ${existingDeployment.proxy}`);
console.log(`📍 New implementation: ${newImplementationAddress}\n`);
// Save the new implementation address
saveDeployment(network, contractName, existingDeployment.proxy, newImplementationAddress);
// Verify the new implementation
if (network !== "hardhat" && network !== "localhost") {
console.log("🔍 Verifying new implementation...");
try {
await hre.run("verify:verify", {
address: newImplementationAddress,
constructorArguments: [],
});
console.log("✅ Implementation verified successfully!\n");
} catch (error) {
console.log(`⚠️ Verification failed: ${error.message}\n`);
}
}
} else {
console.log("🆕 No existing deployment found. Deploying fresh proxy...\n");
// Get the contract factory
const CunaFinanceBsc = await ethers.getContractFactory(contractName);
// Deploy the proxy
const proxy = await upgrades.deployProxy(CunaFinanceBsc, [], {
initializer: "initialize",
kind: "transparent"
});
await proxy.waitForDeployment();
const proxyAddress = await proxy.getAddress();
const implementationAddress = await upgrades.erc1967.getImplementationAddress(proxyAddress);
console.log(`✅ Contract deployed successfully!`);
console.log(`📍 Proxy address: ${proxyAddress}`);
console.log(`📍 Implementation: ${implementationAddress}\n`);
// Save deployment info
saveDeployment(network, contractName, proxyAddress, implementationAddress);
// Verify contracts
if (network !== "hardhat" && network !== "localhost") {
console.log("🔍 Verifying contracts...\n");
// Verify implementation
try {
await hre.run("verify:verify", {
address: implementationAddress,
constructorArguments: [],
});
console.log("✅ Implementation verified successfully!");
} catch (error) {
console.log(`⚠️ Implementation verification failed: ${error.message}`);
}
// Get proxy admin address for verification
try {
const adminAddress = await upgrades.erc1967.getAdminAddress(proxyAddress);
console.log(`📍 Proxy Admin: ${adminAddress}`);
// Verify proxy admin
await hre.run("verify:verify", {
address: adminAddress,
constructorArguments: [],
});
console.log("✅ Proxy Admin verified successfully!");
} catch (error) {
console.log(`⚠️ Proxy Admin verification failed: ${error.message}`);
}
}
}
console.log("\n🎉 Deployment/Upgrade completed successfully!");
console.log(`📄 Deployment info saved to: ${DEPLOYMENT_FILE}`);
} catch (error) {
console.error("\n❌ Deployment failed:", error.message);
process.exit(1);
}
}
// Execute the script
main()
.then(() => process.exit(0))
.catch((error) => {
console.error("\n❌ Script execution failed:", error);
process.exit(1);
});