Skip to content

Commit

Permalink
refactor: modify deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
venkateshv1266 committed Jul 9, 2024
1 parent 4f36d02 commit 9e8521b
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 90 deletions.
189 changes: 111 additions & 78 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,117 @@ const {
BSCSCAN_API_KEY,
ARBISCAN_API_KEY,
OPTIMISTIC_ETHERSCAN_API_KEY,
ZKSYNC_EXPLORER_API_KEY
ZKSYNC_EXPLORER_API_KEY,
NETWORK_NAME
} = process.env;

if (!NETWORK_NAME) {
console.error(
'Error: No network specified. Please specify the network name in environment variable "NETWORK_NAME"'
);
process.exit(1);
}

interface NetworkConfig {
url: string;
accounts: string[];
}

interface ApiKeyConfig {
[key: string]: string;
}

const networkConfigs: { [key: string]: NetworkConfig } = {
eth: {
url: `https://ethereum-rpc.publicnode.com`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
},
hteth: {
url: `https://rpc.holesky.ethpandaops.io/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`]
},
polygon: {
url: `https://polygon-rpc.com/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
},
tpolygon: {
// https://polygon-amoy.g.alchemy.com
url: `https://polygon-amoy-bor-rpc.publicnode.com`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
},
bsc: {
url: `https://bsc-dataseed1.binance.org/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
},
tbsc: {
url: `https://data-seed-prebsc-1-s1.binance.org:8545/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
},
tarbeth: {
url: `${QUICKNODE_ARBITRUM_SEPOLIA_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
},
arbeth: {
url: `${QUICKNODE_ARBITRUM_ONE_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
},
topeth: {
url: `${QUICKNODE_OPTIMISM_SEPOLIA_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
},
opeth: {
url: `${QUICKNODE_OPTIMISM_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
},
tzketh: {
url: `${QUICKNODE_ZKSYNC_SEPOLIA_API_KEY}`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
}
};

const apiKeyConfigs: ApiKeyConfig = {
eth: `${ETHERSCAN_API_KEY}`,
hteth: `${ETHERSCAN_API_KEY}`,
polygon: `${POLYGONSCAN_API_KEY}`,
tpolygon: `${POLYGONSCAN_API_KEY}`,
bsc: `${BSCSCAN_API_KEY}`,
tbsc: `${BSCSCAN_API_KEY}`,
arbeth: `${ARBISCAN_API_KEY}`,
tarbeth: `${ARBISCAN_API_KEY}`,
opeth: `${OPTIMISTIC_ETHERSCAN_API_KEY}`,
topeth: `${OPTIMISTIC_ETHERSCAN_API_KEY}`,
zksync: `${ZKSYNC_EXPLORER_API_KEY}`,
tzksync: `${ZKSYNC_EXPLORER_API_KEY}`
};

const getNetworkConfig = (network: string): NetworkConfig => {
return networkConfigs[network];
};

const getApiKeyConfig = (network: string): string => {
return apiKeyConfigs[network];
};

const createDynamicNetworkConfig = (
network: string
): { [key: string]: NetworkConfig } => {
const dynamicNetwork: { [key: string]: NetworkConfig } = {};
dynamicNetwork[network] = getNetworkConfig(network);
return dynamicNetwork;
};

const config: HardhatUserConfig = {
solidity: {
compilers: [
Expand Down Expand Up @@ -65,89 +173,14 @@ const config: HardhatUserConfig = {
})),
loggingEnabled: false
},
eth: {
url: `https://ethereum-rpc.publicnode.com`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
},
hteth: {
url: `https://rpc.holesky.ethpandaops.io/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`]
},
matic: {
url: `https://polygon-rpc.com/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
},
tmatic: {
// https://polygon-amoy.g.alchemy.com
url: `https://polygon-amoy-bor-rpc.publicnode.com`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
},
bsc: {
url: `https://bsc-dataseed1.binance.org/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
},
tbsc: {
url: `https://data-seed-prebsc-1-s1.binance.org:8545/`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
},
tarbeth: {
url: `${QUICKNODE_ARBITRUM_SEPOLIA_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
},
arbeth: {
url: `${QUICKNODE_ARBITRUM_ONE_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
},
topeth: {
url: `${QUICKNODE_OPTIMISM_SEPOLIA_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
},
opeth: {
url: `${QUICKNODE_OPTIMISM_API_KEY}`,
accounts: [
`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`,
`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP}`
]
},
tzketh: {
url: `${QUICKNODE_ZKSYNC_SEPOLIA_API_KEY}`,
accounts: [`${PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT}`]
}
...createDynamicNetworkConfig(NETWORK_NAME.toLowerCase())
},
gasReporter: {
enabled: process.env.REPORT_GAS !== undefined,
currency: 'USD'
},
etherscan: {
apiKey: {
//ethereum
mainnet: `${ETHERSCAN_API_KEY}`,
goerli: `${ETHERSCAN_API_KEY}`,
holesky: `${ETHERSCAN_API_KEY}`,
//polygon
polygon: `${POLYGONSCAN_API_KEY}`,
polygonAmoy: `${POLYGONSCAN_API_KEY}`,
bscTestnet: `${BSCSCAN_API_KEY}`,
bsc: `${BSCSCAN_API_KEY}`,
// arbitrum
arbitrumOne: `${ARBISCAN_API_KEY}`,
arbitrumSepolia: `${ARBISCAN_API_KEY}`,
// optimism
optimisticEthereum: `${OPTIMISTIC_ETHERSCAN_API_KEY}`,
optimisticSepolia: `${OPTIMISTIC_ETHERSCAN_API_KEY}`,
// zksync
zksync: `${ZKSYNC_EXPLORER_API_KEY}`,
zksyncSepolia: `${ZKSYNC_EXPLORER_API_KEY}`
},
apiKey: getApiKeyConfig(NETWORK_NAME.toLowerCase()),
customChains: [
{
network: 'holesky',
Expand Down
41 changes: 29 additions & 12 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@ async function main() {
forwarderFactory: ''
};

const version = await new Promise((resolve) => {
console.log(
'In case of new coins like arbeth, opeth, zketh, use version v4. \n' +
'If we have to deploy contracts for the older coins like eth, avax, polygon, use version v1 or v2'
);
const stdin = process.openStdin();
console.log('Choose the version (v1/v2/v4): ');
stdin.addListener('data', function (d) {
const answer = d.toString().trim();
if (answer.toLowerCase() === 'v1') {
resolve('v1');
} else if (answer.toLowerCase() === 'v2') {
resolve('v2');
} else if (answer.toLowerCase() === 'v2') {
resolve('v4');
} else {
console.error('Please select the correct version');
process.exit(1);
}
stdin.removeAllListeners('data');
});
});

const feeData = await ethers.provider.getFeeData();
const gasParams = {
gasPrice: feeData.gasPrice
Expand All @@ -20,8 +43,12 @@ async function main() {

let walletImplementationContractName = '';
let walletFactoryContractName = 'WalletFactory';
let forwarderContractName = 'Forwarder';
let forwarderFactoryContractName = 'ForwarderFactory';
let forwarderContractName =
version === 'v1' || version === 'v2' ? 'Forwarder' : 'ForwarderV4';
let forwarderFactoryContractName =
version === 'v1' || version === 'v2'
? 'ForwarderFactory'
: 'ForwarderFactoryV4';
let contractPath = `contracts/WalletSimple.sol:WalletSimple`;
const chainId = await deployer.getChainId();
switch (chainId) {
Expand All @@ -31,44 +58,34 @@ async function main() {
//hteth
case 17000:
walletImplementationContractName = 'WalletSimple';
forwarderContractName = 'ForwarderV4';
forwarderFactoryContractName = 'ForwarderFactoryV4';
contractPath = `contracts/${walletImplementationContractName}.sol:${walletImplementationContractName}`;
break;
//matic
case 137:
//tmatic
case 80002:
walletImplementationContractName = 'WalletSimple';
forwarderContractName = 'ForwarderV4';
forwarderFactoryContractName = 'ForwarderFactoryV4';
contractPath = `contracts/${walletImplementationContractName}.sol:${walletImplementationContractName}`;
break;
// bsc
case 56:
// tbsc
case 97:
walletImplementationContractName = 'WalletSimple';
forwarderContractName = 'ForwarderV4';
forwarderFactoryContractName = 'ForwarderFactoryV4';
contractPath = `contracts/${walletImplementationContractName}.sol:${walletImplementationContractName}`;
break;
// arbeth
case 42161:
// tarbeth
case 421614:
walletImplementationContractName = 'WalletSimple';
forwarderContractName = 'Forwarder';
forwarderFactoryContractName = 'ForwarderFactory';
contractPath = `contracts/${walletImplementationContractName}.sol:${walletImplementationContractName}`;
break;
// opeth
case 10:
// topeth
case 11155420:
walletImplementationContractName = 'WalletSimple';
forwarderContractName = 'Forwarder';
forwarderFactoryContractName = 'ForwarderFactory';
contractPath = `contracts/${walletImplementationContractName}.sol:${walletImplementationContractName}`;
break;
// zketh
Expand Down
Empty file added scripts/deployDynamic.ts
Empty file.

0 comments on commit 9e8521b

Please sign in to comment.