-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bump openzeppelin contracts to v5
- Loading branch information
Showing
46 changed files
with
526 additions
and
1,002 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,28 @@ | ||
import chalk from 'chalk'; | ||
import type { HardhatRuntimeEnvironment } from 'hardhat/types'; | ||
import { getAdminAddress } from '@openzeppelin/upgrades-core'; | ||
import { Wallet, Contract } from 'zksync-ethers'; | ||
import { Manifest } from './core/manifest'; | ||
import { getAdminFactory } from './proxy-deployment/deploy-proxy-admin'; | ||
import { ZkSyncUpgradablePluginError } from './errors'; | ||
import { Wallet } from 'zksync-ethers'; | ||
import { attachProxyAdminV4 } from './utils/attach-abi'; | ||
|
||
export type ChangeAdminFunction = (proxyAddress: string, newAdmin: string, wallet: Wallet) => Promise<void>; | ||
export type TransferProxyAdminOwnershipFunction = (newOwner: string, wallet: Wallet) => Promise<void>; | ||
export type GetInstanceFunction = (wallet: Wallet) => Promise<Contract>; | ||
export type TransferProxyAdminOwnershipFunction = ( | ||
proxyAddress: string, | ||
newOwner: string, | ||
wallet: Wallet, | ||
) => Promise<void>; | ||
|
||
export function makeChangeProxyAdmin(hre: HardhatRuntimeEnvironment): ChangeAdminFunction { | ||
export function makeChangeProxyAdmin(): ChangeAdminFunction { | ||
return async function changeProxyAdmin(proxyAddress, newAdmin, wallet: Wallet) { | ||
const proxyAdminManifest = await getManifestAdmin(hre, wallet); | ||
|
||
const proxyAdminAddress = await getAdminAddress(wallet.provider, proxyAddress); | ||
|
||
if ((await proxyAdminManifest.getAddress()) !== proxyAdminAddress) { | ||
throw new ZkSyncUpgradablePluginError('Proxy admin is not the one registered in the network manifest'); | ||
} else if ((await proxyAdminManifest.getAddress()) !== newAdmin) { | ||
await proxyAdminManifest.changeProxyAdmin(proxyAddress, newAdmin); | ||
} | ||
const admin = await attachProxyAdminV4(proxyAdminAddress, wallet); | ||
await admin.changeProxyAdmin(proxyAddress, newAdmin); | ||
}; | ||
} | ||
|
||
export function makeTransferProxyAdminOwnership(hre: HardhatRuntimeEnvironment): TransferProxyAdminOwnershipFunction { | ||
return async function transferProxyAdminOwnership(newOwner, wallet: Wallet) { | ||
const admin = await getManifestAdmin(hre, wallet); | ||
export function makeTransferProxyAdminOwnership(): TransferProxyAdminOwnershipFunction { | ||
return async function transferProxyAdminOwnership(proxyAddress: string, newOwner, wallet: Wallet) { | ||
const proxyAdminAddress = await getAdminAddress(wallet.provider, proxyAddress); | ||
|
||
const admin = await attachProxyAdminV4(proxyAdminAddress, wallet); | ||
await admin.transferOwnership(newOwner); | ||
|
||
const manifest = await Manifest.forNetwork(wallet.provider); | ||
const { proxies } = await manifest.read(); | ||
for (const { address, kind } of proxies) { | ||
if ((await admin.getAddress()) === (await getAdminAddress(wallet.provider, address))) { | ||
console.info(chalk.green(`${address} (${kind}) proxy ownership transfered through admin proxy`)); | ||
} else { | ||
console.info(chalk.red(`${address} (${kind}) proxy ownership not affected by admin proxy`)); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
export function makeGetInstanceFunction(hre: HardhatRuntimeEnvironment): GetInstanceFunction { | ||
return async function getInstance(wallet: Wallet) { | ||
return await getManifestAdmin(hre, wallet); | ||
}; | ||
} | ||
|
||
export async function getManifestAdmin(hre: HardhatRuntimeEnvironment, wallet: Wallet): Promise<Contract> { | ||
const manifest = await Manifest.forNetwork(wallet.provider); | ||
const manifestAdmin = await manifest.getAdmin(); | ||
const proxyAdminAddress = manifestAdmin?.address; | ||
|
||
if (proxyAdminAddress === undefined) { | ||
throw new ZkSyncUpgradablePluginError('No ProxyAdmin was found in the network manifest'); | ||
} | ||
|
||
const adminFactory = await getAdminFactory(hre, wallet); | ||
return adminFactory.attach(proxyAdminAddress); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.