-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(hardhatdeploy): poc hardhat-deploy integrate hardhat-deploy plugin to deploy test contract * feat(hardhat-deploy): integrate hardhat-deploy plugin deploy all Razor contracts using hardhat-deploy, update deploy.sh script * fix(hardhat-deploy): integrate hardhat-deploy plugin hotfix remove test contract * fix(hardhat-deploy): integrate hardhat-deploy plugin hotfix remove unnecessary changes * fix(hardhat-deploy): integrate hardhat-deploy plugin hotfix remove unnecessary changes * fix(hardhat-deploy): fix current post deployment wait for contract deployment file to updated * fix(hardhat-deploy): migrate contracts setup create shared folder for contracts initialisation and grant role * feat(hardhat-deploy): post deployment test add post deployment script test, 1 staker to vote for 1 epoch * feat(hardhat-deploy): clean up hotfix * fix: lint fix and yarn.lock * feat(hardhat-deploy): add deployment fixtures for tests * fix(hardhat-deploy): fix circleci errors * feat(hardhat-deploy): remove postdeployment test and deployment fixtures. Release hardhat-deploy * feat(hardhat-deploy): use common deploy func, code modularisation * feat(hardhat-deploy): circleci hotfix * fix: clean up functions,rename deploy_all * fix: postdeployment setup code clean up and fixes for failing init contract + same contract instance * fix: update grant role to promise * fix: add deploy readme * fix: move to root folder * fix: update content
- Loading branch information
1 parent
25d0cd1
commit bf8c93d
Showing
22 changed files
with
2,122 additions
and
1,779 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ deployed/local | |
deployments | ||
gasReporterOutput.json | ||
.vscode/ | ||
docs | ||
docs | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
## hardhat-deploy in a nutshell | ||
|
||
**hardhat-deploy** allows you to write `deploy scripts` in the `deploy` folder. Each of these files that look as follows will be executed in turn when you execute the following task: `hardhat --network <networkName> deploy` | ||
|
||
Note: `hre.deployments.deploy` function will by default only deploy a contract if the contract code has changed, making it easier to write idempotent scripts. | ||
|
||
### An example of a deploy script : | ||
|
||
``` | ||
module.exports = async ({ | ||
getNamedAccounts, | ||
deployments, | ||
getChainId, | ||
getUnnamedAccounts, | ||
}) => { | ||
const {deploy} = deployments; | ||
const {deployer} = await getNamedAccounts(); | ||
// the following will only deploy "GenericMetaTxProcessor" if the contract was never deployed or if the code changed since last deployment | ||
await deploy('GenericMetaTxProcessor', { | ||
from: deployer, | ||
gasLimit: 4000000, | ||
args: [], | ||
}); | ||
}; | ||
``` | ||
|
||
As you can see the HRE passed in has 4 new fields : | ||
|
||
- `getNamedAccounts` is a function that returns a promise to an object whose keys are names and values are addresses. It is parsed from the `namedAccounts` configuration. | ||
- `getUnnamedAccounts` is a function that return a promise to an array of accounts which were not named (see `namedAccounts` ). It is useful for tests where you want to be sure that the account has no speicifc role in the system (no token given, no admin access, etc...). | ||
- `getChainId` is a function which return a promise for the chainId, as convenience | ||
- `deployments` is an object which contains functions to access past deployments or to save new ones, as well as helpers functions. | ||
|
||
`deployments` contains for example the `deploy` function that allows you to deploy contract and save them. | ||
|
||
### **1. namedAccounts (ability to name addresses)** | ||
|
||
--- | ||
|
||
This plugin extends the `HardhatConfig`'s object with an optional `namedAccounts` field. | ||
|
||
`namedAccounts` allows you to associate names to addresses and have them configured per chain. | ||
This allows you to have meaningful names in your tests. | ||
|
||
``` | ||
{ | ||
namedAccounts: { | ||
deployer: { | ||
default: 0, // here this will by default take the first account as deployer | ||
1: 0, // similarly on mainnet it will take the first account as deployer. Note though that depending on how hardhat network are configured, the account 0 on one network can be different than on another | ||
4: '0xA296a3d5F026953e17F472B497eC29a5631FB51B', // but for rinkeby it will be a specific address | ||
"goerli": '0x84b9514E013710b9dD0811c9Fe46b837a4A0d8E0', //it can also specify a specific netwotk name (specified in hardhat.config.js) | ||
}, | ||
feeCollector:{ | ||
default: 1, // here this will by default take the second account as feeCollector (so in the test this will be a different account than the deployer) | ||
1: '0xa5610E1f289DbDe94F3428A9df22E8B518f65751', // on the mainnet the feeCollector could be a multi sig | ||
4: '0xa250ac77360d4e837a13628bC828a2aDf7BabfB3', // on rinkeby it could be another account | ||
} | ||
} | ||
} | ||
``` | ||
|
||
--- | ||
|
||
Furthermore you can also ensure these scripts are executed in test’s too by calling `await deployments.fixture(['MyContract'])` in your test. | ||
This is optimised, so if multiple tests use the same contract, the deployment will be executed once and each test will start with the exact same state. | ||
|
||
This is a huge benefit for testing since you are not required to replicate the deployment procedure in your tests. | ||
|
||
You can even group deploy scripts in different sub folder and ensure they are executed in their logical order. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { deployContractHH } = require('../migrations/migrationHelpers'); | ||
|
||
const deployGovernance = async () => { | ||
await deployContractHH('Governance'); | ||
}; | ||
|
||
module.exports = async () => { | ||
await deployGovernance(); | ||
}; | ||
module.exports.tags = ['Governance']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { deployContractHH } = require('../migrations/migrationHelpers'); | ||
|
||
const deployBlockManager = async () => { | ||
await deployContractHH('BlockManager'); | ||
}; | ||
|
||
module.exports = async () => { | ||
await deployBlockManager(); | ||
}; | ||
module.exports.tags = ['BlockManager']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { deployContractHH } = require('../migrations/migrationHelpers'); | ||
|
||
const deployCollectionManager = async () => { | ||
await deployContractHH('CollectionManager'); | ||
}; | ||
|
||
module.exports = async () => { | ||
await deployCollectionManager(); | ||
}; | ||
module.exports.tags = ['CollectionManager']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { deployContractHH } = require('../migrations/migrationHelpers'); | ||
|
||
const deployStakeManager = async () => { | ||
await deployContractHH('StakeManager'); | ||
}; | ||
|
||
module.exports = async () => { | ||
await deployStakeManager(); | ||
}; | ||
module.exports.tags = ['StakeManager']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { deployContractHH } = require('../migrations/migrationHelpers'); | ||
|
||
const deployRewardManager = async () => { | ||
await deployContractHH('RewardManager'); | ||
}; | ||
|
||
module.exports = async () => { | ||
await deployRewardManager(); | ||
}; | ||
module.exports.tags = ['RewardManager']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { deployContractHH } = require('../migrations/migrationHelpers'); | ||
|
||
const deployVoteManager = async () => { | ||
await deployContractHH('VoteManager'); | ||
}; | ||
|
||
module.exports = async () => { | ||
await deployVoteManager(); | ||
}; | ||
module.exports.tags = ['VoteManager']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { deployContractHH, readOldDeploymentFile, appendDeploymentFile } = require('../migrations/migrationHelpers'); | ||
|
||
const { DELEGATOR_ADDRESS } = process.env; | ||
|
||
const deployDelegator = async () => { | ||
if (DELEGATOR_ADDRESS === '' || !DELEGATOR_ADDRESS) { | ||
await deployContractHH('Delegator'); | ||
} else { | ||
const { Delegator } = await readOldDeploymentFile(); | ||
|
||
if (DELEGATOR_ADDRESS !== Delegator) { | ||
throw Error('Delegator instance address is different than what was deployed previously'); | ||
} | ||
// eslint-disable-next-line no-console | ||
console.log('Re-using Delegator instance deployed at', Delegator); | ||
await appendDeploymentFile({ Delegator }); | ||
} | ||
}; | ||
|
||
module.exports = async () => { | ||
await deployDelegator(); | ||
}; | ||
module.exports.tags = ['Delegator']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { deployContractHH, readOldDeploymentFile, appendDeploymentFile } = require('../migrations/migrationHelpers'); | ||
|
||
const { NETWORK, RAZOR_ADDRESS } = process.env; | ||
const { BigNumber } = ethers; | ||
const initialSupply = (BigNumber.from(10).pow(BigNumber.from(27))); | ||
|
||
const deployRAZOR = async () => { | ||
if (NETWORK !== 'mainnet' && RAZOR_ADDRESS === '') { | ||
await deployContractHH('RAZOR', [initialSupply]); | ||
} else { | ||
const { RAZOR } = await readOldDeploymentFile(); | ||
|
||
if (RAZOR !== RAZOR_ADDRESS) { | ||
throw Error('Razor instance address is different than that is deployed previously'); | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
console.log('Re-using Razor instance deployed at', RAZOR); | ||
await appendDeploymentFile({ RAZOR }); | ||
} | ||
}; | ||
|
||
module.exports = async () => { | ||
await deployRAZOR(); | ||
}; | ||
module.exports.tags = ['RAZOR']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { deployContractHH } = require('../migrations/migrationHelpers'); | ||
|
||
const deployStakedTokenFactory = async () => { | ||
await deployContractHH('StakedTokenFactory'); | ||
}; | ||
|
||
module.exports = async () => { | ||
await deployStakedTokenFactory(); | ||
}; | ||
module.exports.tags = ['StakedTokenFactory']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { deployContractHH } = require('../migrations/migrationHelpers'); | ||
|
||
const deployRandomNoManager = async () => { | ||
await deployContractHH('RandomNoManager'); | ||
}; | ||
|
||
module.exports = async () => { | ||
await deployRandomNoManager(); | ||
}; | ||
module.exports.tags = ['RandomNoManager']; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.