Skip to content

Commit

Permalink
Merge pull request #260 from pods-finance/develop
Browse files Browse the repository at this point in the history
Deployment scripts
  • Loading branch information
Robsonsjre authored May 31, 2021
2 parents bfec0e3 + bc4f0e6 commit 374fbde
Show file tree
Hide file tree
Showing 37 changed files with 431 additions and 393 deletions.
6 changes: 0 additions & 6 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ require('solidity-coverage')
require('hardhat-contract-sizer')

require('./tasks/index')
require('./tasks/utils/index')
require('./tasks/Amm/index')
require('./tasks/configuration/index')
require('./tasks/option/index')
require('./tasks/local/index')
require('./tasks/oracle/index')

module.exports = {
networks: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"hardhat-spdx-license-identifier": "2.0.3",
"husky": "4.2.5",
"mocha": "7.2.0",
"parse-duration": "1.0.0",
"prettier": "2.0.5",
"prettier-plugin-solidity": "1.0.0-alpha.54",
"solhint": "3.0.0",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ task('deployNewOptionAMMPool', 'Deploy a New AMM Pool')
const content = await fsPromises.readFile(_filePath)
const contentJSON = JSON.parse(content)

const { OptionAMMFactory: optionAMMFactory, ConfigurationManager: configurationManager } = contentJSON
const { ConfigurationManager: configurationManagerAddress } = contentJSON

const OptionAMMFactory = await ethers.getContractAt('OptionAMMFactory', optionAMMFactory)
const configurationManager = await ethers.getContractAt('ConfigurationManager', configurationManagerAddress)
const OptionAMMFactory = await ethers.getContractAt('OptionAMMFactory', await configurationManager.getAMMFactory())
const tokenBContract = await ethers.getContractAt('MintableERC20', tokenb)

const txIdNewPool = await OptionAMMFactory.createPool(option, tokenb, initialiv)
Expand All @@ -54,8 +55,7 @@ task('deployNewOptionAMMPool', 'Deploy a New AMM Pool')
const newPoolObj = Object.assign({}, currentPools, { [poolAddress]: poolObj })

if (cap != null && parseFloat(cap) > 0) {
const cm = await ethers.getContractAt('ConfigurationManager', configurationManager)
const capProvider = await ethers.getContractAt('CapProvider', await cm.getCapProvider())
const capProvider = await ethers.getContractAt('CapProvider', await configurationManager.getCapProvider())

const capValue = toBigNumber(cap).mul(toBigNumber(10 ** await tokenBContract.decimals()))
const tx = await capProvider.setCap(poolAddress, capValue)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
55 changes: 18 additions & 37 deletions tasks/configuration/deployConfigurationManager.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,38 @@
const saveJSON = require('../utils/saveJSON')
const verifyContract = require('../utils/verify')

task('deployConfigurationManager', 'Deploy a new instance of ConfigurationManager + Emergency + Cap and link them')
.addFlag('verify', 'if true, it should verify the contract after the deployment')
.setAction(async ({ verify }, hre) => {
hre.run('compile')
console.log('----Start Deploy ConfiguratorManager + Emergency + Cap----')

const [ConfigurationManager, EmergencyStop, CapProvider] = await Promise.all([
ethers.getContractFactory('ConfigurationManager'),
ethers.getContractFactory('EmergencyStop'),
ethers.getContractFactory('CapProvider')
])

const configurationManager = await ConfigurationManager.deploy()
await configurationManager.deployed()
const configurationManagerAddress = configurationManager.address
console.log('configurationManager Address', configurationManager.address)
const configurationManagerAddress = await hre.run('deploy', {
name: 'ConfigurationManager',
save: true,
verify
})

const emergencyStop = await EmergencyStop.deploy()
await emergencyStop.deployed()
console.log('emergencyStop Address', emergencyStop.address)
const emergencyStopAddress = await hre.run('deploy', {
name: 'EmergencyStop',
save: true,
verify
})

await hre.run('linkConfigurationManager', {
address: configurationManagerAddress,
setter: 'setEmergencyStop',
newContract: emergencyStop.address
newContract: emergencyStopAddress
})

const capProvider = await CapProvider.deploy()
await capProvider.deployed()
console.log('capProvider Address', capProvider.address)
const capProviderAddress = await hre.run('deploy', {
name: 'CapProvider',
save: true,
verify
})

await hre.run('linkConfigurationManager', {
address: configurationManagerAddress,
setter: 'setCapProvider',
newContract: capProvider.address
newContract: capProviderAddress
})

const saveObj = {
ConfigurationManager: configurationManager.address,
EmergencyStop: emergencyStop.address,
CapProvider: capProvider.address
}

await saveJSON(`../../deployments/${hre.network.name}.json`, saveObj)

if (verify) {
await verifyContract(hre, configurationManager.address)
await verifyContract(hre, emergencyStop.address)
await verifyContract(hre, capProvider.address)
}

console.log('----End Deploy ConfiguratorManager + Emergency + Cap----')
return configurationManager.address
return configurationManagerAddress
})
18 changes: 7 additions & 11 deletions tasks/configuration/emergencyStop.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
const { getDeployments } = require('../utils/deployment')
const validateAddress = require('../utils/validateAddress')

task('emergencyStop', 'Interact with a EmergencyStop connected to a ConfigurationManager')
.addOptionalParam('address', 'An address of a deployed ConfigurationManager, defaults to current `deployments` json file')
.addPositionalParam('command', 'The command to send. stop, resume, isStopped')
.addPositionalParam('contract', 'The contract address to interact')
.setAction(async ({ address, command, contract }, hre) => {
const filePath = `../../deployments/${hre.network.name}.json`

if (!address) {
const json = require(filePath)
address = json.ConfigurationManager
const deployment = getDeployments()
address = deployment.ConfigurationManager
}

if (!ethers.utils.isAddress(address)) {
throw new Error(`\`address\` is not an address. Received: ${address}`)
}

if (!ethers.utils.isAddress(contract)) {
throw new Error(`\`contract\` is not an address. Received: ${contract}`)
}
validateAddress(address, 'address')
validateAddress(contract, 'contract')

const configurationManager = await ethers.getContractAt('ConfigurationManager', address)
const emergencyStop = await ethers.getContractAt('EmergencyStop', await configurationManager.getEmergencyStop())
Expand Down
21 changes: 10 additions & 11 deletions tasks/configuration/getParameters.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
const { getDeployments } = require('../utils/deployment')
const validateAddress = require('../utils/validateAddress')

task('getParameter', 'Get a ConfigurationManager parameter')
.addPositionalParam('parameter', 'Parameter name')
.addOptionalParam('configurator', 'An address of a deployed ConfigurationManager, defaults to current `deployments` json file')
.setAction(async ({ configurator, parameter }, bre) => {
const filePath = `../../deployments/${bre.network.name}.json`

if (!configurator) {
const json = require(filePath)
configurator = json.configurationManager
.addOptionalParam('configuration', 'An address of a deployed ConfigurationManager, defaults to current `deployments` json file')
.setAction(async ({ configuration, parameter }, hre) => {
if (!configuration) {
const deployment = getDeployments()
configuration = deployment.ConfigurationManager
}

if (!ethers.utils.isAddress(configurator)) {
throw new Error(`\`configurator\` is not an address. Received: ${configurator}`)
}
validateAddress(configuration, 'configuration')

const configurationManager = await ethers.getContractAt('ConfigurationManager', configurator)
const configurationManager = await ethers.getContractAt('ConfigurationManager', configuration)

const parameterName = ethers.utils.formatBytes32String(parameter)
const currentValue = (await configurationManager.getParameter(parameterName)).toString()
Expand Down
21 changes: 10 additions & 11 deletions tasks/configuration/increaseCap.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
const { getDeployments } = require('../utils/deployment')
const validateAddress = require('../utils/validateAddress')

task('increaseCap', 'Increase an option or pool cap')
.addParam('contract', 'An address of a target address to increase cap (either option or pool')
.addOptionalParam('value', 'new cap number')
.addOptionalParam('configurator', 'An address of a deployed ConfigurationManager, defaults to current `deployments` json file')
.addFlag('max', 'set pool cap to the max')
.setAction(async ({ contract, value, configurator, max }, bre) => {
.setAction(async ({ contract, value, configuration, max }, bre) => {
console.log('======== START MODIFY CONTRACT CAP ==========')
const filePath = `../../deployments/${bre.network.name}.json`

if (!configurator) {
const json = require(filePath)
configurator = json.ConfigurationManager
if (!configuration) {
const deployment = getDeployments()
configuration = deployment.ConfigurationManager
}

if (!ethers.utils.isAddress(contract)) {
throw new Error(`\`address\` is not an address. Received: ${configurator}`)
}
validateAddress(configuration, 'configuration')

const configurationManager = await ethers.getContractAt('ConfigurationManager', configurator)
const capProviderAddress = await configurationManager.getCapProvider()
const capContract = await ethers.getContractAt('CapProvider', capProviderAddress)
const configurationManager = await ethers.getContractAt('ConfigurationManager', configuration)
const capContract = await ethers.getContractAt('CapProvider', await configurationManager.getCapProvider())
const valueToSend = max ? 0 : value

const tx = await capContract.setCap(contract, valueToSend)
Expand Down
15 changes: 7 additions & 8 deletions tasks/configuration/inspectConfigurationManager.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
const { getDeployments } = require('../utils/deployment')
const validateAddress = require('../utils/validateAddress')

task('inspectConfigurationManager', 'Checks the contracts associated with a ConfigurationManager instance')
.addOptionalPositionalParam('address', 'An address of a deployed ConfigurationManager, defaults to current `deployments` json file')
.setAction(async ({ address }, bre) => {
const filePath = `../../deployments/${bre.network.name}.json`

.setAction(async ({ address }, hre) => {
if (!address) {
const json = require(filePath)
address = json.ConfigurationManager
const deployment = getDeployments()
address = deployment.ConfigurationManager
}

if (!ethers.utils.isAddress(address)) {
throw new Error(`\`address\` is not an address. Received: ${address}`)
}
validateAddress(address, 'address')

const configurationManager = await ethers.getContractAt('ConfigurationManager', address)

Expand Down
18 changes: 7 additions & 11 deletions tasks/configuration/linkConfigurationManager.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
const { getDeployments } = require('../utils/deployment')
const validateAddress = require('../utils/validateAddress')

task('linkConfigurationManager', 'Link a contract with a ConfigurationManager')
.addOptionalParam('address', 'An address of a deployed ConfigurationManager, defaults to current `deployments` json file')
.addPositionalParam('setter', 'The setter to interact with')
.addPositionalParam('newContract', 'The new contract address to set')
.setAction(async ({ address, setter, newContract }, bre) => {
const filePath = `../../deployments/${bre.network.name}.json`

if (!address) {
const json = require(filePath)
address = json.ConfigurationManager
const deployment = getDeployments()
address = deployment.ConfigurationManager
}

if (!ethers.utils.isAddress(address)) {
throw new Error(`\`address\` is not an address. Received: ${address}`)
}

if (!ethers.utils.isAddress(newContract)) {
throw new Error(`\`newContract\` is not an address. Received: ${newContract}`)
}
validateAddress(address, 'address')
validateAddress(newContract, 'newContract')

const configurationManager = await ethers.getContractAt('ConfigurationManager', address)

Expand Down
21 changes: 10 additions & 11 deletions tasks/configuration/setParameter.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
const { getDeployments } = require('../utils/deployment')
const validateAddress = require('../utils/validateAddress')

task('setParameter', 'Set a ConfigurationManager parameter')
.addPositionalParam('parameter', 'Parameter name')
.addPositionalParam('value', 'New value')
.addOptionalParam('configurator', 'An address of a deployed ConfigurationManager, defaults to current `deployments` json file')
.addOptionalParam('configuration', 'An address of a deployed ConfigurationManager, defaults to current `deployments` json file')
.addFlag('noUpdate', 'Specifies if the param change should trigger update on dependent contract, defaults to true')
.setAction(async ({ configurator, parameter, value, noUpdate }, bre) => {
const filePath = `../../deployments/${bre.network.name}.json`

if (!configurator) {
const json = require(filePath)
configurator = json.configurationManager
.setAction(async ({ configuration, parameter, value, noUpdate }, bre) => {
if (!configuration) {
const deployment = getDeployments()
configuration = deployment.ConfigurationManager
}

if (!ethers.utils.isAddress(configurator)) {
throw new Error(`\`configurator\` is not an address. Received: ${configurator}`)
}
validateAddress(configuration, 'configuration')

const configurationManager = await ethers.getContractAt('ConfigurationManager', configurator)
const configurationManager = await ethers.getContractAt('ConfigurationManager', configuration)

const parameterName = ethers.utils.formatBytes32String(parameter)
const parameterValue = ethers.BigNumber.from(value)
Expand Down
28 changes: 15 additions & 13 deletions tasks/deployOptionHelper.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
const saveJSON = require('./utils/saveJSON')
const verifyContract = require('./utils/verify')
const { getDeployments } = require('./utils/deployment')
const validateAddress = require('./utils/validateAddress')

task('deployOptionHelper', 'Deploy new option helper using provider')
.addParam('configuration', 'Address of the factory to pass to initialize')
.addOptionalParam('configuration', 'An address of a deployed ConfigurationManager, defaults to current `deployments` json file')
.addFlag('verify', 'if true, it should verify the contract after the deployment')
.setAction(async ({ configuration, verify }, hre) => {
console.log('----Start Deploy OptionHelper----')
const path = `../../deployments/${hre.network.name}.json`
const OptionHelper = await ethers.getContractFactory('OptionHelper')
const optionHelper = await OptionHelper.deploy(configuration)
console.log('Option Helper Address: ', optionHelper.address)
if (!configuration) {
const deployment = getDeployments()
configuration = deployment.ConfigurationManager
}

await saveJSON(path, { optionHelper: optionHelper.address })
validateAddress(configuration, 'configuration')

if (verify) {
await verifyContract(hre, optionHelper.address, [configuration])
}
const address = await hre.run('deploy', {
name: 'OptionHelper',
args: [configuration],
verify,
save: true
})

return optionHelper.address
return address
})
Loading

0 comments on commit 374fbde

Please sign in to comment.