Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TypeChain in deployProxy function #535

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/plugin-hardhat/src/deploy-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ import {
getInitializerData,
} from './utils';

type InstanceOf<F extends ContractFactory> = ReturnType<F['attach']>;
frangio marked this conversation as resolved.
Show resolved Hide resolved

export interface DeployFunction {
(ImplFactory: ContractFactory, args?: unknown[], opts?: DeployProxyOptions): Promise<Contract>;
(ImplFactory: ContractFactory, opts?: DeployProxyOptions): Promise<Contract>;
<F extends ContractFactory>(ImplFactory: F, args?: unknown[], opts?: DeployProxyOptions): Promise<InstanceOf<F>>;
<F extends ContractFactory>(ImplFactory: F, opts?: DeployProxyOptions): Promise<InstanceOf<F>>;
}

export function makeDeployProxy(hre: HardhatRuntimeEnvironment): DeployFunction {
return async function deployProxy(
ImplFactory: ContractFactory,
return async function deployProxy<F extends ContractFactory>(
ImplFactory: F,
args: unknown[] | DeployProxyOptions = [],
opts: DeployProxyOptions = {},
) {
): Promise<InstanceOf<F>> {
if (!Array.isArray(args)) {
opts = args;
args = [];
Expand Down Expand Up @@ -78,7 +80,7 @@ export function makeDeployProxy(hre: HardhatRuntimeEnvironment): DeployFunction

await manifest.addProxy(proxyDeployment);

const inst = ImplFactory.attach(proxyDeployment.address);
const inst = ImplFactory.attach(proxyDeployment.address) as InstanceOf<F>;
// @ts-ignore Won't be readonly because inst was created through attach.
inst.deployTransaction = proxyDeployment.deployTransaction;
return inst;
Expand Down