Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local deployment [do not merge] #112

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const config: HardhatUserConfig = {
local: {
url: 'http://127.0.0.1:8545',
timeout: 100000,
accounts: [process.env.PRIVATE_KEY!, Wallet.createRandom()._signingKey().privateKey],
},
hardhat: {
forking: {
Expand Down
89 changes: 57 additions & 32 deletions scripts/common/deploy-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,42 @@ export interface DeploySystemArgs {
addressOverrides?: Partial<AddressRegistry>
}

const createServiceRegistry = (utils: HardhatUtils, serviceRegistry: ServiceRegistry, overwrite: string[] = []) => {
const createServiceRegistry = (
utils: HardhatUtils,
serviceRegistry: ServiceRegistry,
overwrite: string[],
logDebug = false,
) => {
return async (hash: string, address: string): Promise<void> => {
if (address === constants.AddressZero) {
console.log(`WARNING: attempted to add zero address to ServiceRegistry. Hash: ${hash}. Skipping...`)
logDebug &&
console.log(`WARNING: attempted to add zero address to ServiceRegistry. Hash: ${hash}. Skipping...`)
return
}

const existingAddress = await serviceRegistry.getServiceAddress(hash)

if (existingAddress.toLowerCase() === address.toLowerCase()) {
return
}

const gasSettings = await utils.getGasSettings()
if (existingAddress === constants.AddressZero) {
await (await serviceRegistry.addNamedService(hash, address, gasSettings)).wait()
} else if (overwrite.includes(hash)) {
logDebug && console.log(`Successfully added service registry entry. Hash: ${hash}. Address: ${address}`)
return
}

if (overwrite.includes(hash)) {
await (await serviceRegistry.updateNamedService(hash, address, gasSettings)).wait()
} else {
logDebug && console.log(`Successfully updated service registry entry. Hash: ${hash}. Address: ${address}`)
return
}

logDebug &&
console.log(
`WARNING: attempted to change service registry entry, but overwrite is not allowed. Hash: ${hash}. Address: ${address}`,
)
}
}
}

Expand All @@ -76,21 +94,21 @@ export async function deploySystem({
const { ethers } = utils.hre
const addresses = { ...utils.addresses, ...addressOverrides }

if (logDebug) console.log('Deploying ServiceRegistry....')
logDebug && console.log('Deploying ServiceRegistry....')
const ServiceRegistryInstance: ServiceRegistry = await utils.deployContract(
ethers.getContractFactory('ServiceRegistry'),
[delay],
)

if (logDebug) console.log('Deploying McdUtils....')
logDebug && console.log('Deploying McdUtils....')
const McdUtilsInstance: McdUtils = await utils.deployContract(ethers.getContractFactory('McdUtils'), [
ServiceRegistryInstance.address,
addresses.DAI,
addresses.DAI_JOIN,
addresses.MCD_JUG,
])

if (logDebug) console.log('Deploying AutomationBot....')
logDebug && console.log('Deploying AutomationBot....')
const AutomationBotInstance: AutomationBot = await utils.deployContract(
ethers.getContractFactory('AutomationBot'),
[ServiceRegistryInstance.address],
Expand All @@ -105,7 +123,7 @@ export async function deploySystem({
[],
)

if (logDebug) console.log('Deploying AutomationExecutor....')
logDebug && console.log('Deploying AutomationExecutor....')
const AutomationExecutorInstance: AutomationExecutor = await utils.deployContract(
ethers.getContractFactory('AutomationExecutor'),
[
Expand All @@ -116,7 +134,7 @@ export async function deploySystem({
],
)

if (logDebug) console.log('Deploying AutomationSwap....')
logDebug && console.log('Deploying AutomationSwap....')
const AutomationSwapInstance: AutomationSwap = await utils.deployContract(
ethers.getContractFactory('AutomationSwap'),
[AutomationExecutorInstance.address, addresses.DAI],
Expand All @@ -135,17 +153,17 @@ export async function deploySystem({
: await ethers.getContractAt('McdView', addresses.AUTOMATION_MCD_VIEW, ethers.provider.getSigner(0))

if (addCommands) {
if (logDebug) console.log('Deploying CloseCommand....')
logDebug && console.log('Deploying CloseCommand....')
CloseCommandInstance = (await utils.deployContract(ethers.getContractFactory('CloseCommand'), [
ServiceRegistryInstance.address,
])) as CloseCommand

if (logDebug) console.log('Deploying BasicBuy....')
logDebug && console.log('Deploying BasicBuy....')
BasicBuyInstance = (await utils.deployContract(ethers.getContractFactory('BasicBuyCommand'), [
ServiceRegistryInstance.address,
])) as BasicBuyCommand

if (logDebug) console.log('Deploying BasicSell....')
logDebug && console.log('Deploying BasicSell....')
BasicSellInstance = (await utils.deployContract(ethers.getContractFactory('BasicSellCommand'), [
ServiceRegistryInstance.address,
])) as BasicSellCommand
Expand Down Expand Up @@ -192,7 +210,7 @@ export async function configureRegistryEntries(
overwrite: string[] = [],
logDebug = false,
) {
const ensureServiceRegistryEntry = createServiceRegistry(utils, system.serviceRegistry, overwrite)
const ensureServiceRegistryEntry = createServiceRegistry(utils, system.serviceRegistry, overwrite, logDebug)
const ensureMcdViewWhitelist = async (address: string) => {
const isWhitelisted = await system.mcdView.whitelisted(address)
if (!isWhitelisted) {
Expand All @@ -201,79 +219,86 @@ export async function configureRegistryEntries(
}

if (system.closeCommand && system.closeCommand.address !== constants.AddressZero) {
if (logDebug) console.log('Adding CLOSE_TO_COLLATERAL command to ServiceRegistry....')
logDebug && console.log('Adding CLOSE_TO_COLLATERAL command to ServiceRegistry....')
await ensureServiceRegistryEntry(getCommandHash(TriggerType.CLOSE_TO_COLLATERAL), system.closeCommand.address)

if (logDebug) console.log('Adding CLOSE_TO_DAI command to ServiceRegistry....')
logDebug && console.log('Adding CLOSE_TO_DAI command to ServiceRegistry....')
await ensureServiceRegistryEntry(getCommandHash(TriggerType.CLOSE_TO_DAI), system.closeCommand.address)

if (logDebug) console.log('Whitelisting CloseCommand on McdView....')
logDebug && console.log('Whitelisting CloseCommand on McdView....')
await ensureMcdViewWhitelist(system.closeCommand.address)
}

if (system.basicBuy && system.basicBuy.address !== constants.AddressZero) {
if (logDebug) console.log(`Adding BASIC_BUY command to ServiceRegistry....`)
logDebug && console.log(`Adding BASIC_BUY command to ServiceRegistry....`)
await ensureServiceRegistryEntry(getCommandHash(TriggerType.BASIC_BUY), system.basicBuy.address)

if (logDebug) console.log('Whitelisting BasicBuyCommand on McdView....')
logDebug && console.log('Whitelisting BasicBuyCommand on McdView....')
await ensureMcdViewWhitelist(system.basicBuy.address)
}

if (system.basicSell && system.basicSell.address !== constants.AddressZero) {
if (logDebug) console.log(`Adding BASIC_SELL command to ServiceRegistry....`)
logDebug && console.log(`Adding BASIC_SELL command to ServiceRegistry....`)
await ensureServiceRegistryEntry(getCommandHash(TriggerType.BASIC_SELL), system.basicSell.address)

if (logDebug) console.log('Whitelisting BasicSellCommand on McdView....')
logDebug && console.log('Whitelisting BasicSellCommand on McdView....')
await ensureMcdViewWhitelist(system.basicSell.address)
}

if (logDebug) console.log('Adding CDP_MANAGER to ServiceRegistry....')
logDebug && console.log('Adding CDP_MANAGER to ServiceRegistry....')
await ensureServiceRegistryEntry(getServiceNameHash(AutomationServiceName.CDP_MANAGER), addresses.CDP_MANAGER)

if (logDebug) console.log('Adding MCD_VAT to ServiceRegistry....')
logDebug && console.log('Adding MCD_VAT to ServiceRegistry....')
await ensureServiceRegistryEntry(getServiceNameHash(AutomationServiceName.MCD_VAT), addresses.MCD_VAT)

if (logDebug) console.log('Adding MCD_SPOT to ServiceRegistry....')
logDebug && console.log('Adding MCD_SPOT to ServiceRegistry....')
await ensureServiceRegistryEntry(getServiceNameHash(AutomationServiceName.MCD_SPOT), addresses.MCD_SPOT)

if (logDebug) console.log('Adding AUTOMATION_BOT to ServiceRegistry....')
logDebug && console.log('Adding AUTOMATION_BOT to ServiceRegistry....')
await ensureServiceRegistryEntry(
getServiceNameHash(AutomationServiceName.AUTOMATION_BOT),
system.automationBot.address,
)

if (logDebug) console.log('Adding AUTOMATION_BOT_AGGREGATOR to ServiceRegistry....')
logDebug && console.log('Adding AUTOMATION_BOT_AGGREGATOR to ServiceRegistry....')
await ensureServiceRegistryEntry(
getServiceNameHash(AutomationServiceName.AUTOMATION_BOT_AGGREGATOR),
system.automationBotAggregator.address,
)
if (logDebug) console.log('Adding CONSTANT_MULTIPLE_VALIDATOR to ServiceRegistry....')

logDebug && console.log('Adding CLOSE_TO_COLLATERAL command to ServiceRegistry....')
await ensureServiceRegistryEntry(
getValidatorHash(TriggerGroupType.CONSTANT_MULTIPLE),
system.constantMultipleValidator.address,
)

logDebug && console.log('Adding CONSTANT_MULTIPLE_VALIDATOR to ServiceRegistry....')
await ensureServiceRegistryEntry(
getValidatorHash(TriggerGroupType.CONSTANT_MULTIPLE),
system.constantMultipleValidator.address,
)

if (logDebug) console.log('Adding MCD_VIEW to ServiceRegistry....')
logDebug && console.log('Adding MCD_VIEW to ServiceRegistry....')
await ensureServiceRegistryEntry(getServiceNameHash(AutomationServiceName.MCD_VIEW), system.mcdView.address)

if (logDebug) console.log('Adding MULTIPLY_PROXY_ACTIONS to ServiceRegistry....')
logDebug && console.log('Adding MULTIPLY_PROXY_ACTIONS to ServiceRegistry....')
await ensureServiceRegistryEntry(
getServiceNameHash(AutomationServiceName.MULTIPLY_PROXY_ACTIONS),
addresses.MULTIPLY_PROXY_ACTIONS,
)

if (logDebug) console.log('Adding AUTOMATION_EXECUTOR to ServiceRegistry....')
logDebug && console.log('Adding AUTOMATION_EXECUTOR to ServiceRegistry....')
await ensureServiceRegistryEntry(
getServiceNameHash(AutomationServiceName.AUTOMATION_EXECUTOR),
system.automationExecutor.address,
)

if (logDebug) console.log('Adding AUTOMATION_SWAP to ServiceRegistry....')
logDebug && console.log('Adding AUTOMATION_SWAP to ServiceRegistry....')
await ensureServiceRegistryEntry(
getServiceNameHash(AutomationServiceName.AUTOMATION_SWAP),
system.automationSwap.address,
)

if (logDebug) console.log('Adding MCD_UTILS command to ServiceRegistry....')
logDebug && console.log('Adding MCD_UTILS command to ServiceRegistry....')
await ensureServiceRegistryEntry(getServiceNameHash(AutomationServiceName.MCD_UTILS), system.mcdUtils.address)
}
9 changes: 7 additions & 2 deletions scripts/deployment/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// When running the script with `npx hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
import hre from 'hardhat'
import { HardhatUtils } from '../common'
import { HardhatUtils, isLocalNetwork } from '../common'
import { deploySystem } from '../common/deploy-system'

async function main() {
Expand All @@ -15,7 +15,12 @@ async function main() {
console.log(`Deployer address: ${await signer.getAddress()}`)
console.log(`Network: ${network}`)

await deploySystem({ utils, addCommands: true, deployMcdView: false, logDebug: true })
await deploySystem({
utils,
addCommands: true,
deployMcdView: isLocalNetwork(network) ? true : false,
logDebug: true,
})
}

// We recommend this pattern to be able to use async/await everywhere
Expand Down