-
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 (#1463)
* feat: refactor upgradable interface * chore: apply lint * fix: add additional example and remove unnessecary file * fix: refactor code, adjust params and set proper version of that oz hardhat-upgradable plugin * fix: add defender v1 and redesign code * fix: compile missing contracts before verify * fix: update check for contracts update * fix: add paymaster params for proxy and implementation deployment * fix: add paymaster params for admin and add other custom data * fix: add verify for non zksync networks * fix: change custom data for proxy admin * fix: change custom data for proxy admin * fix: change paymaster params to PaymasterParams from zksync-ethers * feat: bump openzeppelin contracts to v5 * fix: revert oz contracts for basic example and update readme file * fix: revert manifest and storage layout * fix: remove unsafeAllow for uups proxies * chore: remove only from tests * chore: revert a mnemonic * chore: revert a mnemonic --------- Co-authored-by: nikola-bozin-txfusion <nikolabozin@txfusion.io> Co-authored-by: Marko Arambasic <makiarambasic@gmail.com>
- Loading branch information
1 parent
b4c111b
commit ebb668b
Showing
44 changed files
with
519 additions
and
974 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
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.