-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactor code and fix signer to support impersonated signers
- Loading branch information
Showing
8 changed files
with
143 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types'; | ||
import { ZkSyncGenerator } from './extension-generator'; | ||
import { EthersGenerator } from './hardhat-ethers/extension-generator'; | ||
|
||
export class ExtensionGenerator { | ||
constructor(private _hre: HardhatRuntimeEnvironment) {} | ||
|
||
public populatedExtension(): any { | ||
if (this._hre.network.zksync) { | ||
const zkSyncGenerator = new ZkSyncGenerator(this._hre); | ||
return zkSyncGenerator.populateExtension(); | ||
} | ||
|
||
const ethersGenerators = new EthersGenerator(this._hre); | ||
return ethersGenerators.populateExtension(); | ||
} | ||
} | ||
|
||
export interface Generator { | ||
populateExtension(): any; | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/hardhat-zksync-ethers/src/hardhat-ethers/extension-generator.ts
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { lazyObject } from 'hardhat/plugins'; | ||
import { HardhatRuntimeEnvironment } from 'hardhat/types'; | ||
import { Generator } from '../generator'; | ||
|
||
export class EthersGenerator implements Generator { | ||
constructor(private _hre: HardhatRuntimeEnvironment) {} | ||
|
||
public populateExtension(): any { | ||
return lazyObject(() => { | ||
const hardhatEthersHelpers = require('@nomiclabs/hardhat-ethers/internal/helpers'); | ||
const { createProviderProxy } = require('@nomiclabs/hardhat-ethers/internal/provider-proxy'); | ||
const { ethers } = require('ethers'); | ||
const provider = new createProviderProxy(this._hre.network.provider); | ||
return { | ||
...ethers, | ||
provider, | ||
getSigner: (address: string) => hardhatEthersHelpers.getSigner(this._hre, address), | ||
getSigners: () => hardhatEthersHelpers.getSigners(this._hre), | ||
getImpersonatedSigner: (address: string) => | ||
hardhatEthersHelpers.getImpersonatedSigner(this._hre, address), | ||
getContractFactory: hardhatEthersHelpers.getContractFactory.bind(null, this._hre) as any, | ||
getContractFactoryFromArtifact: hardhatEthersHelpers.getContractFactoryFromArtifact.bind( | ||
null, | ||
this._hre, | ||
), | ||
getContractAt: hardhatEthersHelpers.getContractAt.bind(null, this._hre), | ||
getContractAtFromArtifact: hardhatEthersHelpers.getContractAtFromArtifact.bind(null, this._hre), | ||
deployContract: hardhatEthersHelpers.deployContract.bind(null, this._hre) as any, | ||
}; | ||
}); | ||
} | ||
} |
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