UNPKG

@openzeppelin/hardhat-upgrades

Version:

[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://docs.openzeppelin.com/upgrades-plugins/hardhat-upgrades) [![NPM Package](https://img.shields.io/npm/v/@openzeppelin/hardhat-upgrades.svg)](https://www.npmjs.org/package/@openzeppelin/h

43 lines • 1.9 kB
import chalk from 'chalk'; import { Manifest, getAdminAddress } from '@openzeppelin/upgrades-core'; import { proxyAdminV4Abi } from './artifacts.js'; const SUCCESS_CHECK = chalk.green('✔') + ' '; /** * Client-neutral orchestration of `admin.changeProxyAdmin`. Only compatible with v4 admins. */ export async function changeProxyAdmin(binding, proxyAddress, newAdmin) { const provider = binding.provider; const proxyAdminAddress = await getAdminAddress(provider, proxyAddress); await binding.sendTransaction({ to: proxyAdminAddress, data: binding.encodeFunctionData(proxyAdminV4Abi, 'changeProxyAdmin', [proxyAddress, newAdmin]), }); } /** * Client-neutral orchestration of `admin.transferProxyAdminOwnership`. Compatible with both v4 * and v5 admins since they both have `transferOwnership`. */ export async function transferProxyAdminOwnership(binding, proxyAddress, newOwner, opts) { const provider = binding.provider; const proxyAdminAddress = await getAdminAddress(provider, proxyAddress); await binding.sendTransaction({ to: proxyAdminAddress, data: binding.encodeFunctionData(proxyAdminV4Abi, 'transferOwnership', [newOwner]), }); if (!opts.silent) { const manifest = await Manifest.forNetwork(provider); const { proxies } = await manifest.read(); const affected = []; for (const proxy of proxies) { const controller = await getAdminAddress(provider, proxy.address); if (controller === proxyAdminAddress) { affected.push(proxy); } } if (affected.length > 0) { console.log(SUCCESS_CHECK + `${affected.length} proxies ownership transferred through proxy admin`); affected.forEach(proxy => console.log(` - ${proxy.address} (${proxy.kind})`)); } } } //# sourceMappingURL=admin.js.map