Skip to content

Commit

Permalink
allow two steps init in deploy template script
Browse files Browse the repository at this point in the history
  • Loading branch information
clemsos committed Dec 12, 2024
1 parent eb2b4e4 commit 9f73fc3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
50 changes: 30 additions & 20 deletions governance/scripts/deployments/publicLock.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,48 @@ const {
LOCK_MANAGER_ROLE,
} = require('@unlock-protocol/hardhat-helpers')

async function main({ publicLockVersion }) {
async function main({ publicLockVersion, publicLockAddress }) {
// fetch chain info
const [signer] = await ethers.getSigners()

if (!publicLockVersion) {
throw Error('Need to set --public-lock-version')
}

console.log(
`PUBLIC LOCK > Deploying lock template for released version ${publicLockVersion} with signer ${signer.address}`
)

let publicLock
const [qualifiedPath] = await copyAndBuildContractsAtVersion(__dirname, [
{ contractName: 'PublicLock', version: publicLockVersion },
])

const { contract: publicLock, address: publicLockAddress } =
await deployContract(qualifiedPath)
if (!publicLockAddress) {
console.log(
`PUBLIC LOCK > Deploying lock template for released version ${publicLockVersion} with signer ${signer.address}`
)
;({ contract: publicLock, address: publicLockAddress } =
await deployContract(qualifiedPath))

console.log(
`PUBLIC LOCK > deployed v${await publicLock.publicLockVersion()} to : ${publicLockAddress}`
)
} else {
const PublicLock = await ethers.getContractFactory(qualifiedPath)
publicLock = await PublicLock.attach(publicLockAddress)
}

console.log(
`PUBLIC LOCK > deployed v${await publicLock.publicLockVersion()} to : ${publicLockAddress}`
)
// initialize the template to prevent someone else from doing it
const { hash: txInitHash } = await publicLock.initialize(
signer.address,
0,
ADDRESS_ZERO,
0,
0,
''
)
console.log(`PUBLIC LOCK > Template initialized (tx: ${txInitHash})`)
try {
const { hash: txInitHash } = await publicLock.initialize(
signer.address,
0,
ADDRESS_ZERO,
0,
0,
''
)
console.log(`PUBLIC LOCK > Template initialized (tx: ${txInitHash})`)
} catch (error) {
// in case the template is already initialized but role is not revoked
console.log(error)
}

// renounce the manager role that was added during initilization
const { hash: txRenounceHash } = await publicLock.revokeRole(
Expand Down
10 changes: 7 additions & 3 deletions governance/tasks/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,14 @@ task('deploy:oracle', 'Deploy Uniswap Oracle contract')
})

task('deploy:template', 'Deploy PublicLock contract')
.addOptionalParam('publicLockVersion', 'the version of unlock to deploy')
.setAction(async ({ publicLockVersion }) => {
.addOptionalParam('publicLockVersion', 'the version of PublicLock to deploy')
.addOptionalParam(
'publicLockAddress',
'the address of a deployed PublicLock contract'
)
.setAction(async ({ publicLockVersion, publicLockAddress }) => {
const templateDeployer = require('../scripts/deployments/publicLock')
return await templateDeployer({ publicLockVersion })
return await templateDeployer({ publicLockVersion, publicLockAddress })
})

task('deploy:governor', 'Deploy governor contracts')
Expand Down

0 comments on commit 9f73fc3

Please sign in to comment.