From 5efff509b8b217bdff4f398e4fbdd5698572e8c8 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 29 Aug 2022 12:55:54 +0200 Subject: [PATCH] add hardhat ethers extension --- .../src/lib/hardhat-ethers-extension.ts | 34 +++++++++++++++++++ libs/remix-ui/editor/src/lib/web-types.ts | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 libs/remix-ui/editor/src/lib/hardhat-ethers-extension.ts diff --git a/libs/remix-ui/editor/src/lib/hardhat-ethers-extension.ts b/libs/remix-ui/editor/src/lib/hardhat-ethers-extension.ts new file mode 100644 index 0000000000..13cfaf0066 --- /dev/null +++ b/libs/remix-ui/editor/src/lib/hardhat-ethers-extension.ts @@ -0,0 +1,34 @@ +export const hardhatEthersExtension = +` +interface Libraries { + [libraryName: string]: string; +} + +interface FactoryOptions { + signer?: Signer; + libraries?: Libraries; +} + +export declare function getContractFactory(name: string, signer?: Signer): Promise; + +export declare function getContractFactory(name: string, factoryOptions: FactoryOptions): Promise; + +export declare function getContractFactory(abi: any[], bytecode: utils.BytesLike, signer?: Signer): Promise; + +export declare function getContractAt(name: string, address: string, signer?: Signer): Promise; + +export declare function getContractAt(abi: any[], address: string, signer?: Signer): Promise; + +export declare function getSigners() => Promise; + +export declare function getSigner(address: string) => Promise; + +export declare function getImpersonatedSigner(address: string) => Promise; + +export declare function getContractFactoryFromArtifact(artifact: Artifact, signer?: Signer): Promise; + +export declare function getContractFactoryFromArtifact(artifact: Artifact, factoryOptions: FactoryOptions): Promise; + +export declare function getContractAtFromArtifact(artifact: Artifact, address: string, signer?: Signer): Promise; +` + diff --git a/libs/remix-ui/editor/src/lib/web-types.ts b/libs/remix-ui/editor/src/lib/web-types.ts index c4fe61933c..0ba400d460 100644 --- a/libs/remix-ui/editor/src/lib/web-types.ts +++ b/libs/remix-ui/editor/src/lib/web-types.ts @@ -1,4 +1,5 @@ import { remixTypes } from './remix-plugin-types' +import { hardhatEthersExtension } from './hardhat-ethers-extension' export const loadTypes = async (monaco) => { // ethers.js @@ -169,6 +170,7 @@ export const loadTypes = async (monaco) => { ethers.default = ethers.default.replace(/.\/_version/g, '_version-ethers-lib') ethers.default = ethers.default.replace(/.\/ethers/g, 'ethers-lib') ethers.default = ethers.default.replace(/@ethersproject\//g, '@ethersproject_') + ethers.default = ethers.default + '\n' + hardhatEthersExtension monaco.languages.typescript.typescriptDefaults.addExtraLib(ethers.default, `file:///node_modules/@types/ethers-lib/index.d.ts`) // @ts-ignore