Skip to content

Commit

Permalink
Added admin.instance
Browse files Browse the repository at this point in the history
  • Loading branch information
pinglamb committed Jan 7, 2021
1 parent 4f39c81 commit 0c8f474
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/plugin-hardhat/src/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getProxyAdminFactory } from './proxy-factory';

export type ChangeAdminFunction = (proxyAddress: string, newAdmin: string) => Promise<void>;
export type TransferProxyAdminOwnershipFunction = (newOwner: string) => Promise<void>;
export type DeployedProxyAdminFunction = () => Promise<Contract>;

export function makeChangeProxyAdmin(hre: HardhatRuntimeEnvironment): ChangeAdminFunction {
return async function changeProxyAdmin(proxyAddress, newAdmin) {
Expand All @@ -26,6 +27,12 @@ export function makeTransferProxyAdminOwnership(hre: HardhatRuntimeEnvironment):
};
}

export function makeDeployedProxyAdmin(hre: HardhatRuntimeEnvironment): DeployedProxyAdminFunction {
return async function deployedProxyAdmin() {
return await getManifestAdmin(hre);
};
}

export async function getManifestAdmin(hre: HardhatRuntimeEnvironment): Promise<Contract> {
const manifest = await Manifest.forNetwork(hre.network.provider);
const manifestAdmin = await manifest.getAdmin();
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-hardhat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { writeValidations } from './validations';
import type { silenceWarnings } from '@openzeppelin/upgrades-core';
import type { DeployFunction } from './deploy-proxy';
import type { UpgradeFunction, PrepareUpgradeFunction } from './upgrade-proxy';
import type { ChangeAdminFunction, TransferProxyAdminOwnershipFunction } from './admin';
import type { ChangeAdminFunction, TransferProxyAdminOwnershipFunction, DeployedProxyAdminFunction } from './admin';

export interface HardhatUpgrades {
deployProxy: DeployFunction;
upgradeProxy: UpgradeFunction;
prepareUpgrade: PrepareUpgradeFunction;
silenceWarnings: typeof silenceWarnings;
admin: {
deployedProxyAdmin: DeployedProxyAdminFunction;
changeProxyAdmin: ChangeAdminFunction;
transferProxyAdminOwnership: TransferProxyAdminOwnershipFunction;
};
Expand All @@ -45,7 +46,7 @@ subtask(TASK_COMPILE_SOLIDITY_COMPILE, async (args: RunCompilerArgs, hre, runSup
extendEnvironment(hre => {
hre.upgrades = lazyObject(
(): HardhatUpgrades => {
const { makeChangeProxyAdmin, makeTransferProxyAdminOwnership } = require('./admin');
const { makeChangeProxyAdmin, makeTransferProxyAdminOwnership, makeDeployedProxyAdmin } = require('./admin');
const { makeDeployProxy } = require('./deploy-proxy');
const { makeUpgradeProxy, makePrepareUpgrade } = require('./upgrade-proxy');
const { silenceWarnings } = require('@openzeppelin/upgrades-core');
Expand All @@ -56,6 +57,7 @@ extendEnvironment(hre => {
upgradeProxy: makeUpgradeProxy(hre),
prepareUpgrade: makePrepareUpgrade(hre),
admin: {
deployedProxyAdmin: makeDeployedProxyAdmin(hre),
changeProxyAdmin: makeChangeProxyAdmin(hre),
transferProxyAdminOwnership: makeTransferProxyAdminOwnership(hre),
},
Expand Down
14 changes: 14 additions & 0 deletions packages/plugin-hardhat/test/admin-instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const test = require('ava');

const { ethers, upgrades } = require('hardhat');

test.before(async t => {
t.context.Greeter = await ethers.getContractFactory('Greeter');
});

test('admin.deployedProxyAdmin', async t => {
const { Greeter } = t.context;
await upgrades.deployProxy(Greeter, ['Hola admin!']);
const proxyAdmin = await upgrades.admin.deployedProxyAdmin();
t.assert(proxyAdmin);
});

0 comments on commit 0c8f474

Please sign in to comment.