refactor: deployment script to accept argument inputs (#146)

This commit is contained in:
Felipe Mendes 2023-03-07 08:23:34 -03:00 committed by GitHub
parent c8a63b8618
commit 8e309ee04c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 28 deletions

View File

@ -3,6 +3,7 @@
## Folder Structure
Inside contracts you are going to find:
- [contracts](./contracts): all the developed contracts
- [deployments](./deployments): resultant ABI and info for deployments (each network will have a nested folder)
- [lib](./lib): external modules used by Foundry
@ -23,7 +24,7 @@ The contracts present in this project are based in [Solidity](https://github.com
> ⚠️ Before starting developing make sure you Solidity, Node.js and yarn correctly installed in your environment
Also, make sure you run `yarn` at the root directory to get some required tools. The rest of these steps assume you are in the [contracts folder](./).
Also, make sure you run `yarn` at the root directory to get some required tools. The rest of these steps assume you are in the [contracts folder](./).
Follow the steps:
@ -153,6 +154,23 @@ $ yarn deploy:mumbai
to deploy the contract on the testnet. Please note that your wallet needs to hold enough Mumbai MATIC for the deployment to be successful. To reach more in-depth information about how to deploy contract checkout [this guide](https://wiki.polygon.technology/docs/develop/alchemy).
### **Deploy arguments**
For any of the deploy scripts above you are able to input arguments to change the date sent during the deployment. They are:
| Argument | Description | Example | Default |
| -------------------- | ----------------------------------------- | -------------------------- | --------- |
| --new-proxy-instance | Force to deploy a new proxy instance | --new-proxy-instance | false |
| --name | The collection name | --name "Fleek NFAs" | FleekNFAs |
| --symbol | The collection symbol | --symbol "FKNFA" | FLKNFA |
| --billing | The billing values in an array of numbers | --billing "[10000, 20000]" | [] |
Appending all of them together would be like:
```
$ yarn deploy:hardhat --new-proxy-instance --name "Fleek NFAs" --symbol "FKNFA" --billing "[10000, 20000]"
```
<!-- TODO: add this section after the mainnet setup is done and tested
**Polygon main-net**
@ -188,4 +206,4 @@ The project should provide a way for interacting with the contract as owner with
> 🛠️ Work in progress...
-->
-->

View File

@ -8,6 +8,8 @@ import 'hardhat-contract-sizer';
import '@openzeppelin/hardhat-upgrades';
import * as dotenv from 'dotenv';
import { HardhatUserConfig } from 'hardhat/types';
import { task, types } from 'hardhat/config';
import deploy from './scripts/deploy';
dotenv.config();
@ -65,3 +67,16 @@ const config: HardhatUserConfig = {
};
export default config;
// npx hardhat deploy --network mumbai --new-proxy-instance --name "FleekNFAs" --symbol "FLKNFA" --billing "[10000, 20000]"
task('deploy', 'Deploy the contracts')
.addFlag('newProxyInstance', 'Force to deploy a new proxy instance')
.addOptionalParam('name', 'The collection name', 'FleekNFAs', types.string)
.addOptionalParam('symbol', 'The collection symbol', 'FLKNFA', types.string)
.addOptionalParam(
'billing',
'The billing values in an array of numbers like "[10000, 20000]"',
[],
types.json
)
.setAction(deploy);

View File

@ -9,8 +9,8 @@
"test:hardhat": "hardhat test",
"format": "prettier --write \"./**/*.{js,json,sol,ts}\"",
"node:hardhat": "hardhat node",
"deploy:hardhat": "hardhat run scripts/deploy.js --network hardhat",
"deploy:mumbai": "hardhat run scripts/deploy.js --network mumbai",
"deploy:hardhat": "hardhat deploy --network hardhat",
"deploy:mumbai": "hardhat deploy --network mumbai",
"compile": "hardhat compile",
"verify:mumbai": "npx hardhat run ./scripts/verify-polyscan.js --network mumbai"
},

View File

@ -4,22 +4,14 @@ const {
} = require('./utils/deploy-store');
const { getProxyAddress, proxyStore } = require('./utils/proxy-store');
// --- Inputs ---
const ARGUMENTS = [
'FleekNFAs', // Collection name
'FLKNFA', // Collection symbol
[], // Billing values
];
// --- Script Settings ---
const CONTRACT_NAME = 'FleekERC721';
const NETWORK = hre.network.name;
const DEFAULT_PROXY_SETTINGS = {
unsafeAllow: ['external-library-linking'],
};
const LIBRARIES_TO_DEPLOY = ['FleekSVG'];
const libraryDeployment = async () => {
const libraryDeployment = async (hre) => {
console.log('Deploying Libraries...');
const libraries = {};
@ -33,7 +25,7 @@ const libraryDeployment = async () => {
const libContract = await hre.ethers.getContractFactory(lib);
const libInstance = await libContract.deploy();
await libInstance.deployed();
deployStore(NETWORK, lib, libInstance);
deployStore(hre.network.name, lib, libInstance);
console.log(`Library "${lib}" deployed at ${libInstance.address}`);
libraries[lib] = libInstance.address;
}
@ -41,55 +33,70 @@ const libraryDeployment = async () => {
return libraries;
};
const main = async () => {
console.log(':: Starting Deployment ::');
console.log('Network:', NETWORK);
console.log('Contract:', CONTRACT_NAME);
module.exports = async (taskArgs, hre) => {
const { newProxyInstance, name, symbol, billing } = taskArgs;
const network = hre.network.name;
const libraries = await libraryDeployment();
console.log(':: Starting Deployment ::');
console.log('Network:', network);
console.log('Contract:', CONTRACT_NAME);
console.log(':: Arguments ::');
console.log(taskArgs);
console.log();
const arguments = [name, symbol, billing];
const libraries = await libraryDeployment(hre);
const Contract = await ethers.getContractFactory(CONTRACT_NAME, {
libraries,
});
const proxyAddress = await getProxyAddress(CONTRACT_NAME, NETWORK);
const proxyAddress = await getProxyAddress(CONTRACT_NAME, network);
let deployResult;
try {
if (!proxyAddress) throw new Error('No proxy address found');
if (!proxyAddress || newProxyInstance)
throw new Error('new-proxy-instance');
console.log(`Trying to upgrade proxy contract at: "${proxyAddress}"`);
deployResult = await upgrades.upgradeProxy(
proxyAddress,
Contract,
DEFAULT_PROXY_SETTINGS
);
console.log('\x1b[32m');
console.log(
`Contract ${CONTRACT_NAME} upgraded at "${deployResult.address}" by account "${deployResult.signer.address}"`
);
await deployStore(NETWORK, CONTRACT_NAME, deployResult);
console.log('\x1b[0m');
await deployStore(network, CONTRACT_NAME, deployResult);
} catch (e) {
if (
e.message === 'No proxy address found' ||
e.message === 'new-proxy-instance' ||
e.message.includes("doesn't look like an ERC 1967 proxy")
) {
console.log(`Failed to upgrade proxy contract: "${e.message?.trim()}"`);
console.log('Creating new proxy contract...');
deployResult = await upgrades.deployProxy(
Contract,
ARGUMENTS,
arguments,
DEFAULT_PROXY_SETTINGS
);
await deployResult.deployed();
await proxyStore(CONTRACT_NAME, deployResult.address, hre.network.name);
await proxyStore(CONTRACT_NAME, deployResult.address, network);
console.log('\x1b[32m');
console.log(
`Contract ${CONTRACT_NAME} deployed at "${deployResult.address}" by account "${deployResult.signer.address}"`
);
console.log('\x1b[0m');
} else {
throw e;
}
try {
await deployStore(NETWORK, CONTRACT_NAME, deployResult);
await deployStore(network, CONTRACT_NAME, deployResult);
} catch (e) {
console.error('Could not write deploy files', e);
}
@ -97,5 +104,3 @@ const main = async () => {
return deployResult;
};
main();