added proxy contract and deployment script

This commit is contained in:
Vaibhav Khanna 2022-04-15 18:09:20 +05:30
parent 660ce7e585
commit 0ffd63080d
2 changed files with 111 additions and 5 deletions

View File

@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../infiniteProxy/proxy.sol";
contract Example is Proxy {
constructor(address admin_, address dummyImplementation_)
Proxy(admin_, dummyImplementation_)
{}
}

View File

@ -4,6 +4,17 @@
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
import { ethers } from "hardhat";
import { Contract } from "ethers";
const hre = require("hardhat");
const UserModuleSigs = [
"supply(uint256)",
"withdraw(uint256)"
].map((a) => ethers.utils.id(a).slice(0, 10));
const ReadModuleSigs = [
"userBalance(address)"
].map((a) => ethers.utils.id(a).slice(0, 10));
async function main() {
// Hardhat always runs the compile task when running scripts with its command
@ -14,12 +25,97 @@ async function main() {
// await hre.run('compile');
// We get the contract to deploy
const Greeter = await ethers.getContractFactory("Greeter");
const greeter = await Greeter.deploy("Hello, Hardhat!");
let proxy: Contract,
userModule: Contract,
readModule: Contract,
dummyImplementation: Contract
await greeter.deployed();
const proxyAdmin = '0x85B40eb65e49eB61De78a3a989752249f8837fc5'
console.log("Greeter deployed to:", greeter.address);
const UserModule = await ethers.getContractFactory(
"contracts/example/module1/main.sol:UserModule"
);
userModule = await UserModule.deploy();
await userModule.deployed();
console.log("User module deployed to: ", userModule.address);
const ReadModule = await ethers.getContractFactory(
"contracts/example/module2/main.sol:ReadModule"
);
readModule = await ReadModule.deploy();
await readModule.deployed();
console.log("Read module deployed to: ", readModule.address);
const DummyImplementation = await ethers.getContractFactory(
"contracts/example/dummyImplementation.sol:DummyImplementation"
);
dummyImplementation = await DummyImplementation.deploy();
await dummyImplementation.deployed();
console.log(
"Dummy Implementation deployed to: ",
dummyImplementation.address
);
const Proxy = await ethers.getContractFactory(
"contracts/example/proxy.sol:Example"
);
proxy = await Proxy.deploy(proxyAdmin, dummyImplementation.address);
await proxy.deployed();
console.log("Proxy deployed to: ", proxy.address);
let tx = await proxy.addImplementation(userModule.address, UserModuleSigs);
await tx.wait();
console.log("User Module implementation enabled!");
tx = await proxy.addImplementation(readModule.address, ReadModuleSigs);
await tx.wait();
console.log("Read Module implementation enabled!");
try {
await hre.run("verify:verify", {
address: userModule.address,
constructorArguments: [],
contract: "contracts/example/module1/main.sol:UserModule",
});
} catch (error) {
console.log("Failed to verify User Module");
console.log(error);
console.log();
}
try {
await hre.run("verify:verify", {
address: readModule.address,
constructorArguments: [],
contract: "contracts/example/module2/main.sol:ReadModule",
});
} catch (error) {
console.log("Failed to verify Read Module");
console.log(error);
console.log();
}
try {
await hre.run("verify:verify", {
address: dummyImplementation.address,
constructorArguments: [],
contract:
"contracts/example/dummyImplementation.sol:DummyImplementation",
});
} catch (error) {
console.log("Failed to verify Dummy Implementation");
console.log(error);
console.log();
}
try {
await hre.run("verify:verify", {
address: proxy.address,
constructorArguments: [proxyAdmin, dummyImplementation.address],
contract: "contracts/example/proxy.sol:Example",
});
} catch (error) {
console.log("Failed to verify Proxy");
console.log(error);
console.log();
}
}
// We recommend this pattern to be able to use async/await everywhere