Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing deploy community CLI script #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ const hhconfig: HardhatUserConfig = {
network: "base_testnet",
chainId: 84532,
urls: {
apiURL: "https://api.basescan.org/api",
browserURL: "https://basescan.org",
apiURL: "https://api-sepolia.basescan.org/api",
browserURL: "https://sepolia.basescan.org/",
},
},
{
Expand Down
231 changes: 144 additions & 87 deletions scripts/deploy-community-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ import { ethers, upgrades, run } from "hardhat";
import "@nomicfoundation/hardhat-toolbox";
import { config } from "dotenv";

/**
* @notice This script deploys the following contracts:
* - Profile (unless process.env.PROFILE_ADDR is set, or a custom address is provided at the prompt)
* - Paymaster (unless process.env.PAYMASTER_ADDR is set)
* - TokenEntryPoint (unless process.env.TOKEN_ENTRYPOINT_ADDR is set)
* - AccountFactory (unless process.env.ACCOUNT_FACTORY_ADDR is set)
*/

async function main() {

const whiteListedAddresses = [];
const { COMMUNITY_TOKEN_ADDRESS } = process.env;
if (COMMUNITY_TOKEN_ADDRESS && COMMUNITY_TOKEN_ADDRESS.startsWith("0x")) {
whiteListedAddresses.push(COMMUNITY_TOKEN_ADDRESS);
const { TOKEN_ADDR } = process.env;
if (TOKEN_ADDR && TOKEN_ADDR.startsWith("0x")) {
whiteListedAddresses.push(TOKEN_ADDR);
}

console.log("🏃🏻‍♂️ Running...\n");
console.log("️ Running...\n");
config();

if (
Expand All @@ -22,46 +28,55 @@ async function main() {
throw Error("ENTRYPOINT_ADDR is not set");
}

const profileResponse = new Promise<string | undefined>((resolve) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

rl.question(
"Custom profile contract address (leave empty if you want to create a new one): ",
(answer) => {
if (answer === "" || answer === undefined || !answer.startsWith("0x")) {
resolve(undefined);
}

resolve(answer);
rl.close();
}
);
});

const customProfile = await profileResponse;

console.log("\n");

if (whiteListedAddresses.length === 0) {
const addressResponse = new Promise<string>((resolve) => {
const profileResponse = async () => {
return new Promise<string | undefined>((resolve) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

rl.question(
"Community Token Address: ",
"Custom profile contract address (leave empty if you want to create a new one): ",
(answer) => {
resolve(answer.trim());
if (
answer === "" ||
answer === undefined ||
!answer.startsWith("0x")
) {
resolve(undefined);
}

resolve(answer);
rl.close();
}
);
});
const contractAddress = await addressResponse;
whiteListedAddresses.push(contractAddress);
};

const customProfile = process.env.PROFILE_ADDR
? process.env.PROFILE_ADDR
: await profileResponse();

console.log("\n");

if (whiteListedAddresses.length === 0) {
if (process.env.TOKEN_ADDR) {
whiteListedAddresses.push(process.env.TOKEN_ADDR);
} else {
const addressResponse = new Promise<string>((resolve) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

rl.question("Community Token Address: ", (answer) => {
resolve(answer.trim());
rl.close();
});
});
const contractAddress = await addressResponse;
whiteListedAddresses.push(contractAddress);
}
}

console.log("\n");
Expand All @@ -74,11 +89,15 @@ async function main() {

const profileFactory = await ethers.getContractFactory("Profile");

const profile = await upgrades.deployProxy(profileFactory, [], {
kind: "uups",
initializer: "initialize",
timeout: 999999,
});
const profile = await upgrades.deployProxy(
profileFactory,
[process.env.DEPLOYER_ADDRESS],
{
kind: "uups",
initializer: "initialize",
timeout: 999999,
}
);

console.log("🚀 request sent...");
await profile.deployed();
Expand All @@ -102,68 +121,103 @@ async function main() {
console.log("\n");
}

console.log("⚙️ deploying Paymaster...");

const paymasterFactory = await ethers.getContractFactory("Paymaster");

const paymaster = await upgrades.deployProxy(
paymasterFactory,
[sponsor.address],
{
kind: "uups",
initializer: "initialize",
timeout: 999999,
}
);
let paymaster;
if (process.env.PAYMASTER_ADDR) {
paymaster = {
address: process.env.PAYMASTER_ADDR,
};
console.log(
`✅ Using Paymaster contract deployed at: ${paymaster.address}`
);
} else {
console.log("⚙️ deploying Paymaster...");

const paymasterFactory = await ethers.getContractFactory("Paymaster");

paymaster = await upgrades.deployProxy(
paymasterFactory,
[sponsor.address],
{
kind: "uups",
initializer: "initialize",
timeout: 999999,
}
);

console.log("🚀 request sent...");
console.log("🚀 request sent...");

await paymaster.deployed();
await paymaster.deployed();

console.log(`✅ Paymaster contract deployed to: ${paymaster.address}`);
console.log(`✅ Paymaster contract deployed to: ${paymaster.address}`);
}

console.log("\n");

console.log("⚙️ deploying TokenEntryPoint...");
let tokenEntryPoint;
if (process.env.TOKEN_ENTRYPOINT_ADDR) {
tokenEntryPoint = { address: process.env.TOKEN_ENTRYPOINT_ADDR };
console.log(
`✅ Using TokenEntryPoint deployed at: ${tokenEntryPoint.address}`
);
} else {
console.log("⚙️ deploying TokenEntryPoint...");

const tokenEntryPointFactory = await ethers.getContractFactory(
"TokenEntryPoint"
);
const tokenEntryPoint = await upgrades.deployProxy(
tokenEntryPointFactory,
[
sponsor.address,
paymaster.address,
[...whiteListedAddresses, profileAddress],
],
{
kind: "uups",
initializer: "initialize",
constructorArgs: [process.env.ENTRYPOINT_ADDR],
timeout: 999999,
}
);
const tokenEntryPointFactory = await ethers.getContractFactory(
"TokenEntryPoint"
);
tokenEntryPoint = await upgrades.deployProxy(
tokenEntryPointFactory,
[
sponsor.address,
paymaster.address,
[...whiteListedAddresses, profileAddress],
],
{
kind: "uups",
initializer: "initialize",
constructorArgs: [process.env.ENTRYPOINT_ADDR],
timeout: 999999,
}
);

console.log("🚀 request sent...");
console.log("🚀 request sent...");

await tokenEntryPoint.deployed();
await tokenEntryPoint.deployed();

console.log(`✅ TokenEntryPoint deployed to: ${tokenEntryPoint.address}`);
console.log(`✅ TokenEntryPoint deployed to: ${tokenEntryPoint.address}`);
}

console.log("\n");

console.log("⚙️ deploying AccountFactory...");

const accFactory = await ethers.deployContract("AccountFactory", [
process.env.ENTRYPOINT_ADDR,
tokenEntryPoint.address,
]);
let accFactory;
if (process.env.ACCOUNT_FACTORY_ADDR) {
accFactory = { address: process.env.ACCOUNT_FACTORY_ADDR };
console.log(`✅ Account Factory deployed at: ${accFactory.address}`);
} else {
console.log("⚙️ deploying AccountFactory...");

const accountFactory = await ethers.getContractFactory("AccountFactory");
accFactory = await upgrades.deployProxy(
accountFactory,
[
process.env.ENTRYPOINT_ADDR,
process.env.TOKEN_ENTRYPOINT_ADDR,
tokenEntryPoint.address,
],
{
kind: "uups",
initializer: "initialize",
constructorArgs: [],
timeout: 999999,
}
);

console.log("🚀 request sent...");
console.log("🚀 request sent...");

await accFactory.deployed();
await accFactory.deployed();

console.log(`✅ Account Factory deployed to: ${accFactory.address}`);
console.log(`✅ Account Factory deployed to: ${accFactory.address}`);
}

console.log("\n");

Expand Down Expand Up @@ -287,10 +341,13 @@ async function main() {
console.log("DEPLOYMENT COMPLETE 🎉");
console.log(" ");
console.log(" ");
console.log("Community token address: ", COMMUNITY_TOKEN_ADDRESS);
console.log("Community token address: ", TOKEN_ADDR);
console.log(" ");
console.log("Paymaster contract address: ", paymaster.address);
console.log("Paymaster sponsor address (EOA to top up to sponsor gas fees): ", sponsor.address);
console.log(
"Paymaster sponsor address (EOA to top up to sponsor gas fees): ",
sponsor.address
);
console.log(
"Paymaster sponsor private key: ",
sponsor.privateKey.replace("0x", "")
Expand Down
26 changes: 17 additions & 9 deletions scripts/deploy-community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function deployCommunityEntrypoint(
deployedContractAddress: string
) {
execSync(
`HARDHAT_NETWORK=${networkName} COMMUNITY_TOKEN_ADDRESS=${deployedContractAddress} npx hardhat run ./scripts/deploy-community-entrypoint.ts`,
`HARDHAT_NETWORK=${networkName} TOKEN_ADDR=${deployedContractAddress} npx hardhat run ./scripts/deploy-community-entrypoint.ts`,
{ stdio: "inherit" }
);
}
Expand Down Expand Up @@ -91,6 +91,7 @@ const nativeCurrencySymbols: { [chainId: number]: string } = {
137: "MATIC", // Polygon Mainnet
8453: "ETH", // Base
84531: "ETH", // Base
84532: "ETH", // Base Testnet
80001: "MATIC", // Polygon Mumbai Testnet
42220: "CELO", // Celo Mainnet
44787: "CELO", // Alfajores Testnet (Celo)
Expand Down Expand Up @@ -134,7 +135,9 @@ async function main() {
const wallet = new ethers.Wallet(pk!, ethers.provider);
const balanceWei = await wallet.getBalance();
term(
`The balance of the deployer wallet on ${networkName} is: ${ethers.utils.formatEther(
`The balance of the deployer wallet (${
wallet.address
}) on ${networkName} is: ${ethers.utils.formatEther(
balanceWei
)} ${nativeCurrencySymbol}\n\n`
);
Expand Down Expand Up @@ -235,13 +238,18 @@ async function main() {
contractName,
networkName
);
deployedContractAddress = await deployContract(
contractName,
minter1,
minter2,
tokenName,
tokenSymbol
);
try {
deployedContractAddress = await deployContract(
contractName,
minter1,
minter2,
tokenName,
tokenSymbol
);
} catch (e) {
console.log("Error deploying contract: ", e?.reason);
process.exit();
}
}
}

Expand Down
Loading