Skip to content

Commit

Permalink
feat(contracts): deploy v1 wallet factory contracts
Browse files Browse the repository at this point in the history
Ticket: COIN-114
  • Loading branch information
mullapudipruthvik committed May 24, 2024
1 parent 5e4e835 commit 234941e
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/deploy_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT: ${{ secrets.TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT }}
PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT: ${{ secrets.PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT }}
PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP: ${{ secrets.PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP }}
PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT: ${{ secrets.PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT }}
QUICKNODE_ETH_MAINNET_API_KEY: ${{ secrets.QUICKNODE_ETH_MAINNET_API_KEY }}
QUICKNODE_ETH_HOLESKY_API_KEY: ${{ secrets.QUICKNODE_ETH_HOLESKY_API_KEY }}
QUICKNODE_ARBITRUM_SEPOLIA_API_KEY: ${{ secrets.QUICKNODE_ARBITRUM_SEPOLIA_API_KEY }}
Expand Down Expand Up @@ -70,6 +71,7 @@ jobs:
TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT: ${{ secrets.TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT }}
PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT: ${{ secrets.PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT }}
PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP: ${{ secrets.PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP }}
PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT: ${{ secrets.PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT }}
QUICKNODE_ETH_HOLESKY_API_KEY: ${{ secrets.QUICKNODE_ETH_HOLESKY_API_KEY }}
QUICKNODE_ARBITRUM_SEPOLIA_API_KEY: ${{ secrets.QUICKNODE_ARBITRUM_SEPOLIA_API_KEY }}
QUICKNODE_OPTIMISM_SEPOLIA_API_KEY: ${{ secrets.QUICKNODE_OPTIMISM_SEPOLIA_API_KEY }}
Expand Down Expand Up @@ -128,6 +130,7 @@ jobs:
TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT: ${{ secrets.TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT }}
PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT: ${{ secrets.PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT }}
PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP: ${{ secrets.PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP }}
PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT: ${{ secrets.PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT }}
QUICKNODE_ETH_MAINNET_API_KEY: ${{ secrets.QUICKNODE_ETH_MAINNET_API_KEY }}
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
ALCHEMY_POLYGON_API_KEY: ${{ secrets.ALCHEMY_POLYGON_API_KEY }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT: ${{ secrets.TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT }}
PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT: ${{ secrets.PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT }}
PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP: ${{ secrets.PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP }}
PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT: ${{ secrets.PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT }}
QUICKNODE_ETH_MAINNET_API_KEY: ${{ secrets.QUICKNODE_ETH_MAINNET_API_KEY }}
QUICKNODE_ETH_HOLESKY_API_KEY: ${{ secrets.QUICKNODE_ETH_HOLESKY_API_KEY }}
QUICKNODE_ARBITRUM_SEPOLIA_API_KEY: ${{ secrets.QUICKNODE_ARBITRUM_SEPOLIA_API_KEY }}
Expand Down
3 changes: 2 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT,
QUICKNODE_ETH_MAINNET_API_KEY,
PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT_BACKUP,
PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT,
QUICKNODE_ARBITRUM_SEPOLIA_API_KEY,
QUICKNODE_OPTIMISM_SEPOLIA_API_KEY,
QUICKNODE_ARBITRUM_ONE_API_KEY,
Expand Down Expand Up @@ -99,7 +100,7 @@ const config: HardhatUserConfig = {
},
topeth: {
url: `${QUICKNODE_OPTIMISM_SEPOLIA_API_KEY}`,
accounts: [`${TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT}`]
accounts: [`${PRIVATE_KEY_FOR_V1_WALLET_CONTRACT_DEPLOYMENT}`]
},
opeth: {
url: `${QUICKNODE_OPTIMISM_API_KEY}`,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"scripts": {
"deploy-prod": "hardhat run scripts/deploy.ts --network",
"deploy-test": "hardhat run scripts/deployV1Forwarder.ts --network",
"deploy-test": "hardhat run scripts/deployV1Wallet.ts --network",
"test": "hardhat test",
"coverage": "hardhat coverage",
"solhint": "./node_modules/.bin/solhint --fix 'contracts/**/*.sol'",
Expand Down
113 changes: 113 additions & 0 deletions scripts/deployV1Wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { ethers } from 'hardhat';
const hre = require('hardhat');
const fs = require('fs');

async function main() {
const output = {
walletImplementation: '',
walletFactory: ''
};

const feeData = await ethers.provider.getFeeData();
const gasParams = {
gasPrice: feeData.gasPrice!
};
const [deployer] = await ethers.getSigners();
const selfTransactions = 2;

for (let i = 0; i < selfTransactions; i++) {
const tx = await deployer.sendTransaction({
to: deployer.address,
value: ethers.utils.parseEther('0'),
gasPrice: gasParams.gasPrice
});
await tx.wait();
console.log(`Self transaction with nonce: ${i} complete`);
}

const walletImplementationContractName = 'WalletSimple';
const walletFactoryContractName = 'WalletFactory';

const WalletImplementation = await ethers.getContractFactory(
walletImplementationContractName
);
const walletImplementation = await WalletImplementation.deploy(gasParams);
await walletImplementation.deployed();
output.walletImplementation = walletImplementation.address;
console.log(
`${walletImplementationContractName} deployed at ` +
walletImplementation.address
);

const WalletFactory = await ethers.getContractFactory(
walletFactoryContractName
);
const walletFactory = await WalletFactory.deploy(
walletImplementation.address,
gasParams
);
await walletFactory.deployed();
output.walletFactory = walletFactory.address;
console.log(
`${walletFactoryContractName} deployed at ` + walletFactory.address
);

fs.writeFileSync('output.json', JSON.stringify(output));

// Wait 5 minutes. It takes some time for the etherscan backend to index the transaction and store the contract.
console.log('Waiting for 5 minutes before verifying....');
await new Promise((r) => setTimeout(r, 1000 * 300));

// We have to wait for a minimum of 10 block confirmations before we can call the etherscan api to verify

await walletImplementation.deployTransaction.wait(10);
await walletFactory.deployTransaction.wait(10);

console.log('Done waiting, verifying');
await verifyContract(
walletImplementationContractName,
walletImplementation.address,
[]
);
await verifyContract('WalletFactory', walletFactory.address, [
walletImplementation.address
]);

console.log('Contracts verified');
}

async function verifyContract(
contractName: string,
contractAddress: string,
constructorArguments: string[],
contract?: string
) {
try {
const verifyContractArgs: {
address: string;
constructorArguments: string[];
contract?: string;
} = {
address: contractAddress,
constructorArguments: constructorArguments
};

if (contract) {
verifyContractArgs.contract = contract;
}

await hre.run('verify:verify', verifyContractArgs);
} catch (e) {
// @ts-ignore
// We get a failure API response if the source code has already been uploaded, don't throw in this case.
if (!e.message.includes('Reason: Already Verified')) {
throw e;
}
}
console.log(`Verified ${contractName} on Etherscan!`);
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

0 comments on commit 234941e

Please sign in to comment.