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

deploy: Delta production deployment scripts #631

Merged
merged 14 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions deploy/deploy_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ const func: DeployFunction = async function(hre: HardhatRuntimeEnvironment) {
proxy: true,
args: [Controller.address]
})
// tests expect it to be saved as AdjustableRoundsManager as well
await deployments.save("AdjustableRoundsManager", roundsManager)
yondonfu marked this conversation as resolved.
Show resolved Hide resolved
} else {
roundsManager = await contractDeployer.deployAndRegister({
contract: "RoundsManager",
Expand Down
75 changes: 42 additions & 33 deletions utils/deployer.ts
yondonfu marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,27 @@ export default class ContractDeployer {
deployments: DeploymentsExtension
controller: Controller | undefined

/**
* skipRegister is used to skip the registration on the protocol controller (`setContractInfo`) of contracts
* deployed with this deployer instance. It is used when the deployer account is not the controller owner, which is
* the case in prod networks. In production, the registration has to be done through proceeding governance actions.
*/
readonly skipRegister: boolean

constructor(
deploy: (name: string, options: DeployOptions) => Promise<DeployResult>,
deployer: string,
deployments: DeploymentsExtension
deployments: DeploymentsExtension,
skipRegister = false
) {
this.deploy = deploy
this.deployer = deployer
this.deployments = deployments
this.controller = undefined
this.skipRegister = skipRegister
}

private async getGitHeadCommitHash(): Promise<string> {
async getGitHeadCommitHash(): Promise<string> {
const {stdout, stderr} = await exec("git rev-parse HEAD")
if (stderr) {
throw new Error(stderr)
Expand Down Expand Up @@ -86,54 +95,54 @@ export default class ContractDeployer {
libraries?: Libraries | undefined
}): Promise<DeployResult> {
const {contract, name, proxy, args, libraries} = config
const targetName = `${name}Target`

const shouldRegister = this.controller && !this.skipRegister
yondonfu marked this conversation as resolved.
Show resolved Hide resolved
const gitHash = await this.getGitHeadCommitHash()

const target = await this.deploy(contract, {
// if there's no proxy, the target is just the contract itself
const targetName = proxy ? `${name}Target` : name
const target = await this.deploy(targetName, {
contract,
from: this.deployer,
log: true,
args: [...args],
libraries: libraries
})
if (shouldRegister) {
await this.controller!.setContractInfo(
this.contractId(targetName),
target.address,
gitHash
).then(tx => tx.wait())
}

if (proxy) {
await (
await this.controller?.setContractInfo(
this.contractId(targetName),
target.address,
gitHash
)
)?.wait()
} else {
await (
await this.controller?.setContractInfo(
this.contractId(name),
target.address,
gitHash
)
)?.wait()
await deployments.save(name, target)
if (!proxy) {
return target
}
if (!this.controller) {
throw new Error("Controller not initialized for proxy deploy")
}

// proxy == true, proceed with proxy deployment and registration
const managerProxy = await this.deploy("ManagerProxy", {
// proxy == true, proceed with proxy deployment and registration as the actual contract `name`
const managerProxy = await this.deploy(name, {
contract: "ManagerProxy",
from: this.deployer,
log: true,
args: [this.controller?.address, this.contractId(targetName)]
})

await (
await this.controller?.setContractInfo(
this.contractId(name),
managerProxy.address,
gitHash
)
)?.wait()
await deployments.save(`${contract}Target`, target)
await deployments.save(`${contract}Proxy`, managerProxy)
await deployments.save(contract, managerProxy)
if (shouldRegister) {
await this.controller
.setContractInfo(
this.contractId(name),
managerProxy.address,
gitHash
)
.then(tx => tx.wait())
}

// additionally, save the proxy deployment with a "Proxy" suffix
await deployments.save(`${name}Proxy`, managerProxy)

return managerProxy
}
Expand Down