Initial Commit
This commit is contained in:
91
scripts/deploy.js
Normal file
91
scripts/deploy.js
Normal file
@@ -0,0 +1,91 @@
|
||||
const { ethers, upgrades, run } = require("hardhat");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
// Define a file to store the deployed proxy address
|
||||
const deploymentFile = path.join(__dirname, "deployedAddresses.json");
|
||||
|
||||
async function main() {
|
||||
const impersonatedAddress = "0xfe5FD43b5DD5E9dA362901C5B24EF7aEdC3914B0";
|
||||
|
||||
// Impersonate the account
|
||||
await hre.network.provider.request({
|
||||
method: "hardhat_impersonateAccount",
|
||||
params: [impersonatedAddress],
|
||||
});
|
||||
|
||||
// Get the signer for the impersonated account
|
||||
const deployer = await ethers.getSigner(impersonatedAddress);
|
||||
console.log("Deploying contracts with the account:", deployer.address);
|
||||
|
||||
// Load existing deployment data if it exists
|
||||
let deploymentData = {};
|
||||
if (fs.existsSync(deploymentFile)) {
|
||||
deploymentData = JSON.parse(fs.readFileSync(deploymentFile, "utf8"));
|
||||
}
|
||||
|
||||
const contractName = "PacaFinanceWithBoostAndSchedule";
|
||||
|
||||
let proxyAddress;
|
||||
if (!deploymentData.proxyAddress) {
|
||||
// Deploy the proxy on the first run
|
||||
console.log("Deploying proxy...");
|
||||
|
||||
const Paca = await ethers.getContractFactory(contractName, deployer);
|
||||
|
||||
// Deploy the proxy with the implementation logic
|
||||
const proxy = await upgrades.deployProxy(Paca, [], {
|
||||
initializer: "initialize", // Define the initializer function
|
||||
});
|
||||
|
||||
await proxy.deployed();
|
||||
proxyAddress = proxy.address;
|
||||
console.log("Proxy deployed to:", proxyAddress);
|
||||
|
||||
// Save the proxy address for future upgrades
|
||||
deploymentData.proxyAddress = proxyAddress;
|
||||
fs.writeFileSync(deploymentFile, JSON.stringify(deploymentData, null, 2));
|
||||
} else {
|
||||
proxyAddress = deploymentData.proxyAddress;
|
||||
console.log("Upgrading proxy...");
|
||||
|
||||
const Paca = await ethers.getContractFactory(contractName, deployer);
|
||||
|
||||
// Upgrade the proxy to the new implementation
|
||||
await upgrades.upgradeProxy(proxyAddress, Paca);
|
||||
console.log("Proxy upgraded with new implementation.");
|
||||
}
|
||||
|
||||
// Verify the implementation contract
|
||||
const implementationAddress = await upgrades.erc1967.getImplementationAddress(proxyAddress);
|
||||
console.log("Verifying contracts...");
|
||||
|
||||
// Verify proxy (optional)
|
||||
console.log(`Verifying proxy at ${proxyAddress}...`);
|
||||
try {
|
||||
await run("verify:verify", {
|
||||
address: proxyAddress,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(`Failed to verify proxy: ${err.message}`);
|
||||
}
|
||||
|
||||
// Verify implementation
|
||||
console.log(`Verifying implementation at ${implementationAddress}...`);
|
||||
try {
|
||||
await run("verify:verify", {
|
||||
address: implementationAddress,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(`Failed to verify implementation: ${err.message}`);
|
||||
}
|
||||
|
||||
console.log("Verification complete.");
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user