Skip to content

Commit

Permalink
Merge pull request privacy-scaling-explorations#1484 from privacy-sca…
Browse files Browse the repository at this point in the history
…ling-explorations/chore/get-contract-without-hre

feat: allow getContract without hardhat environment
  • Loading branch information
0xmad authored May 20, 2024
2 parents c18c43e + a2ce5e1 commit 1f8d1ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion contracts/tasks/helpers/Deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,14 @@ export class Deployment {
* @param {IGetContractParams} params - params
* @returns contract wrapper
*/
async getContract<T extends BaseContract>({ name, key, address, signer }: IGetContractParams): Promise<T> {
async getContract<T extends BaseContract>({ name, key, address, abi, signer }: IGetContractParams): Promise<T> {
const deployer = signer || (await this.getDeployer());
const contractAddress = address || this.storage.mustGetAddress(name, this.hre!.network.name, key);

if (abi) {
return new BaseContract(contractAddress, abi, deployer) as unknown as T;
}

const factory = await this.hre?.ethers.getContractAt(name.toString(), contractAddress, deployer);

if (!factory) {
Expand Down
16 changes: 15 additions & 1 deletion contracts/tasks/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import type { AccQueue, MACI, MessageProcessor, Poll, Tally, Verifier, VkRegistry } from "../../typechain-types";
import type { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
import type { BaseContract, BigNumberish, Fragment, JsonFragment, Signer, ContractFactory } from "ethers";
import type {
BaseContract,
BigNumberish,
Fragment,
JsonFragment,
Signer,
ContractFactory,
Interface,
InterfaceAbi,
} from "ethers";
import type { Libraries, TaskArguments } from "hardhat/types";
import type { Poll as PollWrapper } from "maci-core";
import type { Keypair, PrivKey } from "maci-domainobjs";
Expand Down Expand Up @@ -362,6 +371,11 @@ export interface IGetContractParams {
*/
address?: string;

/**
* Contract abi
*/
abi?: Interface | InterfaceAbi;

/**
* Eth signer
*/
Expand Down

0 comments on commit 1f8d1ff

Please sign in to comment.