Skip to content

Commit

Permalink
Merge pull request privacy-scaling-explorations#1773 from privacy-sca…
Browse files Browse the repository at this point in the history
…ling-explorations/feature/maci-factories

feat(contracts): support custom factories for maci test deployment
  • Loading branch information
0xmad authored Aug 15, 2024
2 parents 7b98e58 + 156f523 commit dda41cf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/contracts/tests/PollFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("pollFactory", () => {

before(async () => {
signer = await getDefaultSigner();
pollFactory = (await deployPollFactory(signer, true)) as BaseContract as PollFactory;
pollFactory = (await deployPollFactory(signer, undefined, true)) as BaseContract as PollFactory;
});

describe("deployment", () => {
Expand Down
20 changes: 16 additions & 4 deletions packages/contracts/ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ export const deployContractWithLinkedLibraries = async <T extends BaseContract>(
* @param quiet - whether to suppress console output
* @returns the deployed Poll Factory contract
*/
export const deployPollFactory = async (signer: Signer, quiet = false): Promise<PollFactory> => {
export const deployPollFactory = async (
signer: Signer,
factory: typeof PollFactoryFactory | undefined,
quiet = false,
): Promise<PollFactory> => {
const poseidonContracts = await deployPoseidonContracts(signer, {}, quiet);
const [poseidonT3Contract, poseidonT4Contract, poseidonT5Contract, poseidonT6Contract] = await Promise.all([
poseidonContracts.PoseidonT3Contract.getAddress(),
Expand All @@ -245,9 +249,11 @@ export const deployPollFactory = async (signer: Signer, quiet = false): Promise<
poseidonContracts.PoseidonT6Contract.getAddress(),
]);

const pollFactory = factory || PollFactoryFactory;

const contractFactory = await createContractFactory(
PollFactoryFactory.abi,
PollFactoryFactory.linkBytecode({
pollFactory.abi,
pollFactory.linkBytecode({
"contracts/crypto/PoseidonT3.sol:PoseidonT3": poseidonT3Contract,
"contracts/crypto/PoseidonT4.sol:PoseidonT4": poseidonT4Contract,
"contracts/crypto/PoseidonT5.sol:PoseidonT5": poseidonT5Contract,
Expand All @@ -270,6 +276,7 @@ export const deployMaci = async ({
signer,
poseidonAddresses,
stateTreeDepth = 10,
factories,
quiet = true,
}: IDeployMaciArgs): Promise<IDeployedMaci> => {
const emptyBallotRoots = genEmptyBallotRoots(stateTreeDepth);
Expand All @@ -289,7 +296,12 @@ export const deployMaci = async ({
poseidonT6,
}));

const contractsToLink = [MACIFactory, PollFactoryFactory, MessageProcessorFactoryFactory, TallyFactoryFactory];
const contractsToLink = factories || [
MACIFactory,
PollFactoryFactory,
MessageProcessorFactoryFactory,
TallyFactoryFactory,
];

// Link Poseidon contracts to MACI
const linkedContractFactories = await Promise.all(
Expand Down
14 changes: 14 additions & 0 deletions packages/contracts/ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import type {
ConstantInitialVoiceCreditProxy,
FreeForAllGatekeeper,
MACI,
MACI__factory as MACIFactory,
MessageProcessorFactory__factory as MessageProcessorFactoryFactory,
MockVerifier,
PollFactory,
PollFactory__factory as PollFactoryFactory,
PoseidonT3,
PoseidonT4,
PoseidonT5,
PoseidonT6,
TallyFactory__factory as TallyFactoryFactory,
VkRegistry,
} from "../typechain-types";
import type { BigNumberish, Signer } from "ethers";
Expand Down Expand Up @@ -144,6 +148,16 @@ export interface IDeployMaciArgs {
poseidonT6: string;
}>;

/**
* Custom user defined factories
*/
factories?: [
typeof MACIFactory,
typeof PollFactoryFactory,
typeof MessageProcessorFactoryFactory,
typeof TallyFactoryFactory,
];

/**
* The depth of the state tree
*/
Expand Down

0 comments on commit dda41cf

Please sign in to comment.