Commit df6da1e4 authored by James Kim's avatar James Kim

update deploy to be idempotent

parent b1e9c0e2
import config from './hardhat'
// uses the same config as hardhat.ts
export default config
...@@ -18,7 +18,7 @@ type ProxyConfig = { ...@@ -18,7 +18,7 @@ type ProxyConfig = {
const setupProxyContract = async ( const setupProxyContract = async (
proxyContract: ethers.Contract, proxyContract: ethers.Contract,
proxyOwnerSigner: ethers.Signer, signer: ethers.Signer,
{ {
targetImplAddress, targetImplAddress,
targetProxyOwnerAddress, targetProxyOwnerAddress,
...@@ -29,13 +29,7 @@ const setupProxyContract = async ( ...@@ -29,13 +29,7 @@ const setupProxyContract = async (
.connect(ethers.constants.AddressZero) .connect(ethers.constants.AddressZero)
.callStatic.admin() .callStatic.admin()
// The proxy owner signer needs to be the current admin, otherwise we don't have permission const signerAddress = await signer.getAddress()
// to update the implmentation or admin
const proxyOwnerSignerAddress = await proxyOwnerSigner.getAddress()
assert(
proxyOwnerSignerAddress === currentAdmin,
'proxyOwnerSigner is not the admin'
)
// Gets the current implementation address the proxy is pointing to. // Gets the current implementation address the proxy is pointing to.
// callStatic is used since the `Proxy.implementation()` is not a view function and ethers will // callStatic is used since the `Proxy.implementation()` is not a view function and ethers will
...@@ -54,15 +48,20 @@ const setupProxyContract = async ( ...@@ -54,15 +48,20 @@ const setupProxyContract = async (
console.log('implementation not set to correct contract') console.log('implementation not set to correct contract')
console.log(`Setting implementation to ${targetImplAddress}`) console.log(`Setting implementation to ${targetImplAddress}`)
// The signer needs to be the current admin, otherwise we don't have permission
// to update the implmentation or admin
assert(
signerAddress === currentAdmin,
'the passed signer is not the admin, cannot update implementation'
)
let tx: ethers.providers.TransactionResponse let tx: ethers.providers.TransactionResponse
if (!postUpgradeCallCalldata) { if (!postUpgradeCallCalldata) {
console.log( console.log(
'postUpgradeCallCalldata is not provided. Using Proxy.upgrade()' 'postUpgradeCallCalldata is not provided. Using Proxy.upgrade()'
) )
// Point the proxy to the target implementation // Point the proxy to the target implementation
tx = await proxyContract tx = await proxyContract.connect(signer).upgradeTo(targetImplAddress)
.connect(proxyOwnerSigner)
.upgradeTo(targetImplAddress)
} else { } else {
console.log( console.log(
'postUpgradeCallCalldata is provided. Using Proxy.upgradeAndCall()' 'postUpgradeCallCalldata is provided. Using Proxy.upgradeAndCall()'
...@@ -70,7 +69,7 @@ const setupProxyContract = async ( ...@@ -70,7 +69,7 @@ const setupProxyContract = async (
// Point the proxy to the target implementation, // Point the proxy to the target implementation,
// and call function in the proxy's context // and call function in the proxy's context
tx = await proxyContract tx = await proxyContract
.connect(proxyOwnerSigner) .connect(signer)
.upgradeToAndCall(targetImplAddress, postUpgradeCallCalldata) .upgradeToAndCall(targetImplAddress, postUpgradeCallCalldata)
} }
...@@ -89,9 +88,16 @@ const setupProxyContract = async ( ...@@ -89,9 +88,16 @@ const setupProxyContract = async (
console.log('detected admin is not set correctly') console.log('detected admin is not set correctly')
console.log(`Setting admin to ${targetProxyOwnerAddress}`) console.log(`Setting admin to ${targetProxyOwnerAddress}`)
// The signer needs to be the current admin, otherwise we don't have permission
// to update the implmentation or admin
assert(
signerAddress === currentAdmin,
'proxyOwnerSigner is not the admin, cannot update admin'
)
// change admin to the l2ProxyOwnerAddress // change admin to the l2ProxyOwnerAddress
const tx = await proxyContract const tx = await proxyContract
.connect(proxyOwnerSigner) .connect(signer)
.changeAdmin(targetProxyOwnerAddress) .changeAdmin(targetProxyOwnerAddress)
const receipt = await tx.wait() const receipt = await tx.wait()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment