@maci-protocol/coordinator 0.0.0-ci.5209133
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/LICENSE +22 -0
- package/README.md +42 -0
- package/build/hardhat.config.cjs +31 -0
- package/build/hardhat.config.cjs.map +1 -0
- package/build/hardhat.config.d.cts +24 -0
- package/build/hardhat.config.d.cts.map +1 -0
- package/build/scripts/generateKeypair.d.ts +2 -0
- package/build/scripts/generateKeypair.d.ts.map +1 -0
- package/build/scripts/generateKeypair.js +25 -0
- package/build/scripts/generateKeypair.js.map +1 -0
- package/build/scripts/generateMaciKeyPair.d.ts +2 -0
- package/build/scripts/generateMaciKeyPair.d.ts.map +1 -0
- package/build/scripts/generateMaciKeyPair.js +3 -0
- package/build/scripts/generateMaciKeyPair.js.map +1 -0
- package/build/scripts/getAuthHeader.d.ts +2 -0
- package/build/scripts/getAuthHeader.d.ts.map +1 -0
- package/build/scripts/getAuthHeader.js +31 -0
- package/build/scripts/getAuthHeader.js.map +1 -0
- package/build/tests/constants.d.ts +8 -0
- package/build/tests/constants.d.ts.map +1 -0
- package/build/tests/constants.js +10 -0
- package/build/tests/constants.js.map +1 -0
- package/build/tests/e2e.aa.test.d.ts +2 -0
- package/build/tests/e2e.aa.test.d.ts.map +1 -0
- package/build/tests/e2e.aa.test.js +103 -0
- package/build/tests/e2e.aa.test.js.map +1 -0
- package/build/tests/e2e.deploy.test.d.ts +2 -0
- package/build/tests/e2e.deploy.test.d.ts.map +1 -0
- package/build/tests/e2e.deploy.test.js +234 -0
- package/build/tests/e2e.deploy.test.js.map +1 -0
- package/build/tests/utils.d.ts +14 -0
- package/build/tests/utils.d.ts.map +1 -0
- package/build/tests/utils.js +44 -0
- package/build/tests/utils.js.map +1 -0
- package/build/ts/app.module.d.ts +3 -0
- package/build/ts/app.module.d.ts.map +1 -0
- package/build/ts/app.module.js +36 -0
- package/build/ts/app.module.js.map +1 -0
- package/build/ts/auth/AccountSignatureGuard.service.d.ts +44 -0
- package/build/ts/auth/AccountSignatureGuard.service.d.ts.map +1 -0
- package/build/ts/auth/AccountSignatureGuard.service.js +96 -0
- package/build/ts/auth/AccountSignatureGuard.service.js.map +1 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.d.ts +2 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.d.ts.map +1 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.js +113 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.js.map +1 -0
- package/build/ts/common/__tests__/common.test.d.ts +2 -0
- package/build/ts/common/__tests__/common.test.d.ts.map +1 -0
- package/build/ts/common/__tests__/common.test.js +79 -0
- package/build/ts/common/__tests__/common.test.js.map +1 -0
- package/build/ts/common/accountAbstraction.d.ts +55 -0
- package/build/ts/common/accountAbstraction.d.ts.map +1 -0
- package/build/ts/common/accountAbstraction.js +110 -0
- package/build/ts/common/accountAbstraction.js.map +1 -0
- package/build/ts/common/errors.d.ts +33 -0
- package/build/ts/common/errors.d.ts.map +1 -0
- package/build/ts/common/errors.js +34 -0
- package/build/ts/common/errors.js.map +1 -0
- package/build/ts/common/index.d.ts +4 -0
- package/build/ts/common/index.d.ts.map +1 -0
- package/build/ts/common/index.js +4 -0
- package/build/ts/common/index.js.map +1 -0
- package/build/ts/common/networks.d.ts +29 -0
- package/build/ts/common/networks.d.ts.map +1 -0
- package/build/ts/common/networks.js +70 -0
- package/build/ts/common/networks.js.map +1 -0
- package/build/ts/common/types.d.ts +9 -0
- package/build/ts/common/types.d.ts.map +1 -0
- package/build/ts/common/types.js +2 -0
- package/build/ts/common/types.js.map +1 -0
- package/build/ts/crypto/__tests__/crypto.service.test.d.ts +2 -0
- package/build/ts/crypto/__tests__/crypto.service.test.d.ts.map +1 -0
- package/build/ts/crypto/__tests__/crypto.service.test.js +26 -0
- package/build/ts/crypto/__tests__/crypto.service.test.js.map +1 -0
- package/build/ts/crypto/crypto.module.d.ts +3 -0
- package/build/ts/crypto/crypto.module.d.ts.map +1 -0
- package/build/ts/crypto/crypto.module.js +18 -0
- package/build/ts/crypto/crypto.module.js.map +1 -0
- package/build/ts/crypto/crypto.service.d.ts +31 -0
- package/build/ts/crypto/crypto.service.d.ts.map +1 -0
- package/build/ts/crypto/crypto.service.js +68 -0
- package/build/ts/crypto/crypto.service.js.map +1 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.d.ts +2 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.d.ts.map +1 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.js +84 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.js.map +1 -0
- package/build/ts/deployer/__tests__/deployer.service.test.d.ts +2 -0
- package/build/ts/deployer/__tests__/deployer.service.test.d.ts.map +1 -0
- package/build/ts/deployer/__tests__/deployer.service.test.js +425 -0
- package/build/ts/deployer/__tests__/deployer.service.test.js.map +1 -0
- package/build/ts/deployer/__tests__/utils.d.ts +36 -0
- package/build/ts/deployer/__tests__/utils.d.ts.map +1 -0
- package/build/ts/deployer/__tests__/utils.js +96 -0
- package/build/ts/deployer/__tests__/utils.js.map +1 -0
- package/build/ts/deployer/constants.d.ts +13 -0
- package/build/ts/deployer/constants.d.ts.map +1 -0
- package/build/ts/deployer/constants.js +13 -0
- package/build/ts/deployer/constants.js.map +1 -0
- package/build/ts/deployer/deployer.controller.d.ts +34 -0
- package/build/ts/deployer/deployer.controller.d.ts.map +1 -0
- package/build/ts/deployer/deployer.controller.js +89 -0
- package/build/ts/deployer/deployer.controller.js.map +1 -0
- package/build/ts/deployer/deployer.module.d.ts +3 -0
- package/build/ts/deployer/deployer.module.d.ts.map +1 -0
- package/build/ts/deployer/deployer.module.js +23 -0
- package/build/ts/deployer/deployer.module.js.map +1 -0
- package/build/ts/deployer/deployer.service.d.ts +112 -0
- package/build/ts/deployer/deployer.service.d.ts.map +1 -0
- package/build/ts/deployer/deployer.service.js +628 -0
- package/build/ts/deployer/deployer.service.js.map +1 -0
- package/build/ts/deployer/dto.d.ts +46 -0
- package/build/ts/deployer/dto.d.ts.map +1 -0
- package/build/ts/deployer/dto.js +117 -0
- package/build/ts/deployer/dto.js.map +1 -0
- package/build/ts/deployer/types.d.ts +306 -0
- package/build/ts/deployer/types.d.ts.map +1 -0
- package/build/ts/deployer/types.js +2 -0
- package/build/ts/deployer/types.js.map +1 -0
- package/build/ts/deployer/utils.d.ts +8 -0
- package/build/ts/deployer/utils.d.ts.map +1 -0
- package/build/ts/deployer/utils.js +9 -0
- package/build/ts/deployer/utils.js.map +1 -0
- package/build/ts/file/__tests__/file.service.test.d.ts +2 -0
- package/build/ts/file/__tests__/file.service.test.d.ts.map +1 -0
- package/build/ts/file/__tests__/file.service.test.js +76 -0
- package/build/ts/file/__tests__/file.service.test.js.map +1 -0
- package/build/ts/file/file.module.d.ts +3 -0
- package/build/ts/file/file.module.d.ts.map +1 -0
- package/build/ts/file/file.module.js +18 -0
- package/build/ts/file/file.module.js.map +1 -0
- package/build/ts/file/file.service.d.ts +62 -0
- package/build/ts/file/file.service.d.ts.map +1 -0
- package/build/ts/file/file.service.js +115 -0
- package/build/ts/file/file.service.js.map +1 -0
- package/build/ts/file/types.d.ts +36 -0
- package/build/ts/file/types.d.ts.map +1 -0
- package/build/ts/file/types.js +2 -0
- package/build/ts/file/types.js.map +1 -0
- package/build/ts/jest/setup.d.ts +8 -0
- package/build/ts/jest/setup.d.ts.map +1 -0
- package/build/ts/jest/setup.js +2 -0
- package/build/ts/jest/setup.js.map +1 -0
- package/build/ts/jest/transform.d.ts +8 -0
- package/build/ts/jest/transform.d.ts.map +1 -0
- package/build/ts/jest/transform.js +10 -0
- package/build/ts/jest/transform.js.map +1 -0
- package/build/ts/main.d.ts +2 -0
- package/build/ts/main.d.ts.map +1 -0
- package/build/ts/main.js +46 -0
- package/build/ts/main.js.map +1 -0
- package/build/ts/proof/__tests__/proof.controller.test.d.ts +2 -0
- package/build/ts/proof/__tests__/proof.controller.test.d.ts.map +1 -0
- package/build/ts/proof/__tests__/proof.controller.test.js +89 -0
- package/build/ts/proof/__tests__/proof.controller.test.js.map +1 -0
- package/build/ts/proof/__tests__/proof.gateway.test.d.ts +2 -0
- package/build/ts/proof/__tests__/proof.gateway.test.d.ts.map +1 -0
- package/build/ts/proof/__tests__/proof.gateway.test.js +61 -0
- package/build/ts/proof/__tests__/proof.gateway.test.js.map +1 -0
- package/build/ts/proof/__tests__/proof.service.test.d.ts +2 -0
- package/build/ts/proof/__tests__/proof.service.test.d.ts.map +1 -0
- package/build/ts/proof/__tests__/proof.service.test.js +128 -0
- package/build/ts/proof/__tests__/proof.service.test.js.map +1 -0
- package/build/ts/proof/dto.d.ts +73 -0
- package/build/ts/proof/dto.d.ts.map +1 -0
- package/build/ts/proof/dto.js +255 -0
- package/build/ts/proof/dto.js.map +1 -0
- package/build/ts/proof/proof.controller.d.ts +46 -0
- package/build/ts/proof/proof.controller.d.ts.map +1 -0
- package/build/ts/proof/proof.controller.js +135 -0
- package/build/ts/proof/proof.controller.js.map +1 -0
- package/build/ts/proof/proof.gateway.d.ts +35 -0
- package/build/ts/proof/proof.gateway.d.ts.map +1 -0
- package/build/ts/proof/proof.gateway.js +93 -0
- package/build/ts/proof/proof.gateway.js.map +1 -0
- package/build/ts/proof/proof.module.d.ts +3 -0
- package/build/ts/proof/proof.module.d.ts.map +1 -0
- package/build/ts/proof/proof.module.js +24 -0
- package/build/ts/proof/proof.module.js.map +1 -0
- package/build/ts/proof/proof.service.d.ts +54 -0
- package/build/ts/proof/proof.service.d.ts.map +1 -0
- package/build/ts/proof/proof.service.js +246 -0
- package/build/ts/proof/proof.service.js.map +1 -0
- package/build/ts/proof/types.d.ts +140 -0
- package/build/ts/proof/types.d.ts.map +1 -0
- package/build/ts/proof/types.js +11 -0
- package/build/ts/proof/types.js.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.d.ts +2 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.d.ts.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.js +44 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.js.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.d.ts +2 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.d.ts.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.js +61 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.js.map +1 -0
- package/build/ts/sessionKeys/__tests__/utils.d.ts +25 -0
- package/build/ts/sessionKeys/__tests__/utils.d.ts.map +1 -0
- package/build/ts/sessionKeys/__tests__/utils.js +64 -0
- package/build/ts/sessionKeys/__tests__/utils.js.map +1 -0
- package/build/ts/sessionKeys/dto.d.ts +11 -0
- package/build/ts/sessionKeys/dto.d.ts.map +1 -0
- package/build/ts/sessionKeys/dto.js +29 -0
- package/build/ts/sessionKeys/dto.js.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.controller.d.ts +26 -0
- package/build/ts/sessionKeys/sessionKeys.controller.d.ts.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.controller.js +74 -0
- package/build/ts/sessionKeys/sessionKeys.controller.js.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.module.d.ts +3 -0
- package/build/ts/sessionKeys/sessionKeys.module.d.ts.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.module.js +23 -0
- package/build/ts/sessionKeys/sessionKeys.module.js.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.service.d.ts +50 -0
- package/build/ts/sessionKeys/sessionKeys.service.d.ts.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.service.js +104 -0
- package/build/ts/sessionKeys/sessionKeys.service.js.map +1 -0
- package/build/ts/sessionKeys/types.d.ts +11 -0
- package/build/ts/sessionKeys/types.d.ts.map +1 -0
- package/build/ts/sessionKeys/types.js +2 -0
- package/build/ts/sessionKeys/types.js.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.d.ts +2 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.d.ts.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.js +50 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.js.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.d.ts +2 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.d.ts.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.js +83 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.js.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.d.ts +2 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.d.ts.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.js +58 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.js.map +1 -0
- package/build/ts/subgraph/dto.d.ts +27 -0
- package/build/ts/subgraph/dto.d.ts.map +1 -0
- package/build/ts/subgraph/dto.js +83 -0
- package/build/ts/subgraph/dto.js.map +1 -0
- package/build/ts/subgraph/subgraph.controller.d.ts +24 -0
- package/build/ts/subgraph/subgraph.controller.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.controller.js +66 -0
- package/build/ts/subgraph/subgraph.controller.js.map +1 -0
- package/build/ts/subgraph/subgraph.gateway.d.ts +35 -0
- package/build/ts/subgraph/subgraph.gateway.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.gateway.js +93 -0
- package/build/ts/subgraph/subgraph.gateway.js.map +1 -0
- package/build/ts/subgraph/subgraph.module.d.ts +3 -0
- package/build/ts/subgraph/subgraph.module.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.module.js +23 -0
- package/build/ts/subgraph/subgraph.module.js.map +1 -0
- package/build/ts/subgraph/subgraph.service.d.ts +20 -0
- package/build/ts/subgraph/subgraph.service.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.service.js +106 -0
- package/build/ts/subgraph/subgraph.service.js.map +1 -0
- package/build/ts/subgraph/types.d.ts +93 -0
- package/build/ts/subgraph/types.d.ts.map +1 -0
- package/build/ts/subgraph/types.js +24 -0
- package/build/ts/subgraph/types.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +124 -0
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var DeployerService_1;
|
|
11
|
+
import { PubKey, VerifyingKey } from "@maci-protocol/domainobjs";
|
|
12
|
+
import { ConstantInitialVoiceCreditProxy__factory as ConstantInitialVoiceCreditProxyFactory, ContractStorage, EPolicies, FreeForAllPolicy__factory as FreeForAllPolicyFactory, EASPolicy__factory as EASPolicyFactory, ZupassPolicy__factory as ZupassPolicyFactory, HatsPolicy__factory as HatsPolicyFactory, SemaphorePolicy__factory as SemaphorePolicyFactory, GitcoinPassportPolicy__factory as GitcoinPassportPolicyFactory, Verifier__factory as VerifierFactory, PoseidonT3__factory as PoseidonT3Factory, PoseidonT4__factory as PoseidonT4Factory, PoseidonT5__factory as PoseidonT5Factory, PoseidonT6__factory as PoseidonT6Factory, VkRegistry__factory as VkRegistryFactory, TallyFactory__factory as TallyFactoryFactory, PollFactory__factory as PollFactoryFactory, MessageProcessorFactory__factory as MessageProcessorFactoryFactory, MessageProcessor__factory as MessageProcessorFactory, ERC20VotesPolicy__factory as ERC20VotesPolicyFactory, ERC20Policy__factory as ERC20PolicyFactory, Tally__factory as TallyFactory, Poll__factory as PollFactory, MACI__factory as MACIFactory, EContracts, EInitialVoiceCreditProxies, EMode, deployPoll, extractAllVks, extractVk, genEmptyBallotRoots, } from "@maci-protocol/sdk";
|
|
13
|
+
import { Injectable, Logger } from "@nestjs/common";
|
|
14
|
+
import { BaseContract } from "ethers";
|
|
15
|
+
import { encodeFunctionData } from "viem";
|
|
16
|
+
import path from "path";
|
|
17
|
+
import { ErrorCodes } from "../common";
|
|
18
|
+
import { getBundlerClient, getDeployedContractAddress, getPublicClient } from "../common/accountAbstraction";
|
|
19
|
+
import { FileService } from "../file/file.service";
|
|
20
|
+
import { SessionKeysService } from "../sessionKeys/sessionKeys.service";
|
|
21
|
+
import { MAX_GAS_LIMIT } from "./constants";
|
|
22
|
+
import { estimateExtraGasLimit } from "./utils";
|
|
23
|
+
/**
|
|
24
|
+
* DeployerService is responsible for deploying contracts.
|
|
25
|
+
*/
|
|
26
|
+
let DeployerService = DeployerService_1 = class DeployerService {
|
|
27
|
+
sessionKeysService;
|
|
28
|
+
fileService;
|
|
29
|
+
/**
|
|
30
|
+
* Logger
|
|
31
|
+
*/
|
|
32
|
+
logger = new Logger(DeployerService_1.name);
|
|
33
|
+
/**
|
|
34
|
+
* Contract storage instance
|
|
35
|
+
*/
|
|
36
|
+
storage;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new instance of DeployerService
|
|
39
|
+
*
|
|
40
|
+
* @param fileService - file service
|
|
41
|
+
*/
|
|
42
|
+
constructor(sessionKeysService, fileService) {
|
|
43
|
+
this.sessionKeysService = sessionKeysService;
|
|
44
|
+
this.fileService = fileService;
|
|
45
|
+
this.logger = new Logger(DeployerService_1.name);
|
|
46
|
+
this.storage = ContractStorage.getInstance(path.join(process.cwd(), "deployed-contracts.json"));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get the policy abi and bytecode based on the policy type
|
|
50
|
+
* and also check if there is already an instance deployed
|
|
51
|
+
*
|
|
52
|
+
* @param policyType - the policy type
|
|
53
|
+
* @param network - the network
|
|
54
|
+
* @param args - the policy args
|
|
55
|
+
* @returns - the policy abi and bytecode
|
|
56
|
+
*/
|
|
57
|
+
getPolicyData(policyType, network, args) {
|
|
58
|
+
const address = this.storage.getAddress(policyType, network);
|
|
59
|
+
let storedArgs;
|
|
60
|
+
let isAlreadyDeployed;
|
|
61
|
+
// based on the policy type, we need to deploy the correct policy
|
|
62
|
+
switch (policyType) {
|
|
63
|
+
case EPolicies.FreeForAll: {
|
|
64
|
+
return {
|
|
65
|
+
address,
|
|
66
|
+
abi: FreeForAllPolicyFactory.abi,
|
|
67
|
+
bytecode: FreeForAllPolicyFactory.bytecode,
|
|
68
|
+
alreadyDeployed: !!address,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
case EPolicies.EAS: {
|
|
72
|
+
storedArgs = this.storage.getContractArgs(policyType, network);
|
|
73
|
+
isAlreadyDeployed =
|
|
74
|
+
!!storedArgs &&
|
|
75
|
+
storedArgs.length === 3 &&
|
|
76
|
+
storedArgs[0] === args.easAddress &&
|
|
77
|
+
storedArgs[1] === args.schema &&
|
|
78
|
+
storedArgs[2] === args.attester;
|
|
79
|
+
return {
|
|
80
|
+
address: isAlreadyDeployed ? address : undefined,
|
|
81
|
+
abi: EASPolicyFactory.abi,
|
|
82
|
+
bytecode: EASPolicyFactory.bytecode,
|
|
83
|
+
alreadyDeployed: isAlreadyDeployed,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
case EPolicies.Zupass: {
|
|
87
|
+
storedArgs = this.storage.getContractArgs(policyType, network);
|
|
88
|
+
isAlreadyDeployed =
|
|
89
|
+
!!storedArgs &&
|
|
90
|
+
storedArgs.length === 4 &&
|
|
91
|
+
storedArgs[0] === args.signer1 &&
|
|
92
|
+
storedArgs[1] === args.signer2 &&
|
|
93
|
+
storedArgs[2] === args.eventId &&
|
|
94
|
+
storedArgs[3] === args.zupassVerifier;
|
|
95
|
+
return {
|
|
96
|
+
address: isAlreadyDeployed ? address : undefined,
|
|
97
|
+
abi: ZupassPolicyFactory.abi,
|
|
98
|
+
bytecode: ZupassPolicyFactory.bytecode,
|
|
99
|
+
alreadyDeployed: isAlreadyDeployed,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
case EPolicies.Hats: {
|
|
103
|
+
storedArgs = this.storage.getContractArgs(policyType, network);
|
|
104
|
+
isAlreadyDeployed =
|
|
105
|
+
!!storedArgs &&
|
|
106
|
+
storedArgs.length === 2 &&
|
|
107
|
+
storedArgs[0] === args.hatsProtocolAddress &&
|
|
108
|
+
JSON.stringify(storedArgs[1]) === JSON.stringify(args.critrionHats);
|
|
109
|
+
return {
|
|
110
|
+
address: isAlreadyDeployed ? address : undefined,
|
|
111
|
+
abi: HatsPolicyFactory.abi,
|
|
112
|
+
bytecode: HatsPolicyFactory.bytecode,
|
|
113
|
+
alreadyDeployed: isAlreadyDeployed,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
case EPolicies.Semaphore: {
|
|
117
|
+
storedArgs = this.storage.getContractArgs(policyType, network);
|
|
118
|
+
isAlreadyDeployed =
|
|
119
|
+
!!storedArgs &&
|
|
120
|
+
storedArgs.length === 2 &&
|
|
121
|
+
storedArgs[0] === args.semaphoreContract &&
|
|
122
|
+
storedArgs[1] === args.groupId;
|
|
123
|
+
return {
|
|
124
|
+
address: isAlreadyDeployed ? address : undefined,
|
|
125
|
+
abi: SemaphorePolicyFactory.abi,
|
|
126
|
+
bytecode: SemaphorePolicyFactory.bytecode,
|
|
127
|
+
alreadyDeployed: isAlreadyDeployed,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
case EPolicies.GitcoinPassport: {
|
|
131
|
+
storedArgs = this.storage.getContractArgs(policyType, network);
|
|
132
|
+
isAlreadyDeployed =
|
|
133
|
+
!!storedArgs &&
|
|
134
|
+
storedArgs.length === 2 &&
|
|
135
|
+
storedArgs[0] === args.decoderAddress &&
|
|
136
|
+
storedArgs[1] === args.passingScore;
|
|
137
|
+
return {
|
|
138
|
+
address: isAlreadyDeployed ? address : undefined,
|
|
139
|
+
abi: GitcoinPassportPolicyFactory.abi,
|
|
140
|
+
bytecode: GitcoinPassportPolicyFactory.bytecode,
|
|
141
|
+
alreadyDeployed: isAlreadyDeployed,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
case EPolicies.ERC20Votes: {
|
|
145
|
+
storedArgs = this.storage.getContractArgs(policyType, network);
|
|
146
|
+
isAlreadyDeployed =
|
|
147
|
+
!!storedArgs &&
|
|
148
|
+
storedArgs.length === 3 &&
|
|
149
|
+
storedArgs[0] === args.token &&
|
|
150
|
+
storedArgs[1] === args.factor &&
|
|
151
|
+
storedArgs[2] === args.snapshotBlock;
|
|
152
|
+
return {
|
|
153
|
+
address: isAlreadyDeployed ? address : undefined,
|
|
154
|
+
abi: ERC20VotesPolicyFactory.abi,
|
|
155
|
+
bytecode: ERC20VotesPolicyFactory.bytecode,
|
|
156
|
+
alreadyDeployed: isAlreadyDeployed,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
case EPolicies.ERC20: {
|
|
160
|
+
storedArgs = this.storage.getContractArgs(policyType, network);
|
|
161
|
+
isAlreadyDeployed =
|
|
162
|
+
!!storedArgs &&
|
|
163
|
+
storedArgs.length === 2 &&
|
|
164
|
+
storedArgs[0] === args.token &&
|
|
165
|
+
storedArgs[1] === args.threshold;
|
|
166
|
+
return {
|
|
167
|
+
address: isAlreadyDeployed ? address : undefined,
|
|
168
|
+
abi: ERC20PolicyFactory.abi,
|
|
169
|
+
bytecode: ERC20PolicyFactory.bytecode,
|
|
170
|
+
alreadyDeployed: isAlreadyDeployed,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
default:
|
|
174
|
+
throw new Error(ErrorCodes.UNSUPPORTED_POLICY.toString());
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Get the voice credit proxy abi and bytecode based on the voice credit proxy type
|
|
179
|
+
* and also check if there is already an instance deployed
|
|
180
|
+
*
|
|
181
|
+
* @param voiceCreditProxyType - the voice credit proxy type
|
|
182
|
+
* @param network - the network
|
|
183
|
+
* @param args - the voice credit proxy args
|
|
184
|
+
* @returns - the voice credit proxy abi and bytecode
|
|
185
|
+
*/
|
|
186
|
+
getVoiceCreditProxyData(voiceCreditProxyType, network, args) {
|
|
187
|
+
let storedArgs;
|
|
188
|
+
let isAlreadyDeployed;
|
|
189
|
+
const address = this.storage.getAddress(voiceCreditProxyType, network);
|
|
190
|
+
switch (voiceCreditProxyType) {
|
|
191
|
+
case EInitialVoiceCreditProxies.Constant: {
|
|
192
|
+
storedArgs = this.storage.getContractArgs(voiceCreditProxyType, network);
|
|
193
|
+
isAlreadyDeployed = !!storedArgs && storedArgs[0] === args.amount;
|
|
194
|
+
return {
|
|
195
|
+
address: isAlreadyDeployed ? address : undefined,
|
|
196
|
+
abi: ConstantInitialVoiceCreditProxyFactory.abi,
|
|
197
|
+
bytecode: ConstantInitialVoiceCreditProxyFactory.bytecode,
|
|
198
|
+
alreadyDeployed: isAlreadyDeployed,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
default:
|
|
202
|
+
throw new Error(ErrorCodes.UNSUPPORTED_VOICE_CREDIT_PROXY.toString());
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* @param abi - the abi
|
|
207
|
+
* @param bytecode - the bytecode
|
|
208
|
+
* @param args - the args
|
|
209
|
+
* @param publicClient - the public client
|
|
210
|
+
* @returns - the address
|
|
211
|
+
*/
|
|
212
|
+
async deployAndGetAddress(kernelClient, abi, bytecode, args, bundlerClient, publicClient) {
|
|
213
|
+
const deployCallData = await kernelClient.account.encodeDeployCallData({
|
|
214
|
+
abi,
|
|
215
|
+
args,
|
|
216
|
+
bytecode,
|
|
217
|
+
});
|
|
218
|
+
const gasPrice = await kernelClient.getUserOperationGasPrice();
|
|
219
|
+
const opEstimate = await kernelClient.prepareUserOperation({
|
|
220
|
+
callData: deployCallData,
|
|
221
|
+
sender: kernelClient.account.address,
|
|
222
|
+
maxFeePerGas: gasPrice.maxFeePerGas,
|
|
223
|
+
maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas,
|
|
224
|
+
});
|
|
225
|
+
const callGasLimitMultiplier = estimateExtraGasLimit(opEstimate.callGasLimit);
|
|
226
|
+
const tx = await kernelClient.sendUserOperation({
|
|
227
|
+
callData: deployCallData,
|
|
228
|
+
sender: kernelClient.account.address,
|
|
229
|
+
maxFeePerGas: gasPrice.maxFeePerGas,
|
|
230
|
+
maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas,
|
|
231
|
+
callGasLimit: opEstimate.callGasLimit + callGasLimitMultiplier < MAX_GAS_LIMIT
|
|
232
|
+
? opEstimate.callGasLimit + callGasLimitMultiplier
|
|
233
|
+
: MAX_GAS_LIMIT,
|
|
234
|
+
});
|
|
235
|
+
const receipt = await bundlerClient.waitForUserOperationReceipt({
|
|
236
|
+
hash: tx,
|
|
237
|
+
});
|
|
238
|
+
const txReceipt = await publicClient.getTransactionReceipt({
|
|
239
|
+
hash: receipt.receipt.transactionHash,
|
|
240
|
+
});
|
|
241
|
+
return getDeployedContractAddress(txReceipt);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Deploy a contract and store the address
|
|
245
|
+
*
|
|
246
|
+
* @param contract - the contract to deploy
|
|
247
|
+
* @param args - the args
|
|
248
|
+
* @param abi - the abi
|
|
249
|
+
* @param bytecode - the bytecode
|
|
250
|
+
* @param kernelClient - the kernel client
|
|
251
|
+
* @param publicClient - the public client
|
|
252
|
+
* @param chain - the chain
|
|
253
|
+
* @returns - the address of the deployed contract
|
|
254
|
+
*/
|
|
255
|
+
async deployAndStore(contract, args, abi, bytecode, kernelClient, bundlerClient, publicClient, chain) {
|
|
256
|
+
let address = this.storage.getAddress(contract, chain);
|
|
257
|
+
if (!address) {
|
|
258
|
+
address = await this.deployAndGetAddress(kernelClient, abi, bytecode, args, bundlerClient, publicClient);
|
|
259
|
+
if (!address) {
|
|
260
|
+
this.logger.error(`Failed to deploy contract: ${contract}`);
|
|
261
|
+
throw new Error(`${ErrorCodes.FAILED_TO_DEPLOY_CONTRACT} ${contract}`);
|
|
262
|
+
}
|
|
263
|
+
await this.storage.register({
|
|
264
|
+
id: contract,
|
|
265
|
+
contract: new BaseContract(address, abi),
|
|
266
|
+
args: args.map((arg) => {
|
|
267
|
+
if (Array.isArray(arg)) {
|
|
268
|
+
return arg.map((a) => String(a));
|
|
269
|
+
}
|
|
270
|
+
return String(arg);
|
|
271
|
+
}),
|
|
272
|
+
network: chain,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return address;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Estimate gas, add a bit extra and send the user operation (aka. transaction)
|
|
279
|
+
* @param to - the to address of the user operation
|
|
280
|
+
* @param value - the value of the user operation
|
|
281
|
+
* @param abi - the abi
|
|
282
|
+
* @param functionName - the function name
|
|
283
|
+
* @param args - the args
|
|
284
|
+
* @param errorMessage - the error message
|
|
285
|
+
* @param kernelClient - the kernel client
|
|
286
|
+
* @param bundlerClient - the bundler client
|
|
287
|
+
*/
|
|
288
|
+
async estimateGasAndSend(to, value, abi, functionName, args, errorMessage, kernelClient, bundlerClient) {
|
|
289
|
+
const gasEstimates = await kernelClient.getUserOperationGasPrice();
|
|
290
|
+
const userOperation = {
|
|
291
|
+
sender: kernelClient.account.address,
|
|
292
|
+
maxFeePerGas: gasEstimates.maxFeePerGas,
|
|
293
|
+
maxPriorityFeePerGas: gasEstimates.maxPriorityFeePerGas,
|
|
294
|
+
callData: await kernelClient.account.encodeCalls([
|
|
295
|
+
{
|
|
296
|
+
to,
|
|
297
|
+
value,
|
|
298
|
+
data: encodeFunctionData({
|
|
299
|
+
abi,
|
|
300
|
+
functionName,
|
|
301
|
+
args,
|
|
302
|
+
}),
|
|
303
|
+
},
|
|
304
|
+
]),
|
|
305
|
+
};
|
|
306
|
+
const opEstimate = await kernelClient.prepareUserOperation(userOperation);
|
|
307
|
+
const callGasLimitMultiplier = estimateExtraGasLimit(opEstimate.callGasLimit);
|
|
308
|
+
const userOperationHash = await kernelClient.sendUserOperation({
|
|
309
|
+
...userOperation,
|
|
310
|
+
callGasLimit: opEstimate.callGasLimit + callGasLimitMultiplier < MAX_GAS_LIMIT
|
|
311
|
+
? opEstimate.callGasLimit + callGasLimitMultiplier
|
|
312
|
+
: MAX_GAS_LIMIT,
|
|
313
|
+
});
|
|
314
|
+
const receipt = await bundlerClient.waitForUserOperationReceipt({ hash: userOperationHash });
|
|
315
|
+
if (!receipt.success) {
|
|
316
|
+
throw new Error(errorMessage);
|
|
317
|
+
}
|
|
318
|
+
return receipt;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Get verifying keys arguments (specially zkey paths)
|
|
322
|
+
* @param signer - the signer
|
|
323
|
+
* @param vkRegistryContract - the deployed vk registry contract
|
|
324
|
+
* @param vkRegistryArgs - the arguments send to the endpoint
|
|
325
|
+
* @param mode - use QV or NON_QV
|
|
326
|
+
* @returns SetVerifyingKeysArgs
|
|
327
|
+
*/
|
|
328
|
+
async getVerifyingKeysArgs(signer, vkRegistryContract, vkRegistryArgs, mode) {
|
|
329
|
+
const pollJoiningZkeyPath = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_POLL_JOINING_ZKEY_NAME, true).zkey;
|
|
330
|
+
const pollJoinedZkeyPath = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_POLL_JOINED_ZKEY_NAME, true).zkey;
|
|
331
|
+
const processMessagesZkeyPath = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME, mode === EMode.QV).zkey;
|
|
332
|
+
const tallyVotesZkeyPath = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_TALLY_ZKEY_NAME, mode === EMode.QV).zkey;
|
|
333
|
+
const { pollJoiningVk, pollJoinedVk, processVk, tallyVk } = await extractAllVks({
|
|
334
|
+
pollJoiningZkeyPath,
|
|
335
|
+
pollJoinedZkeyPath,
|
|
336
|
+
processMessagesZkeyPath,
|
|
337
|
+
tallyVotesZkeyPath,
|
|
338
|
+
});
|
|
339
|
+
const { stateTreeDepth, intStateTreeDepth, voteOptionTreeDepth, messageBatchSize } = vkRegistryArgs;
|
|
340
|
+
return {
|
|
341
|
+
pollJoiningVk: pollJoiningVk,
|
|
342
|
+
pollJoinedVk: pollJoinedVk,
|
|
343
|
+
processMessagesVk: processVk,
|
|
344
|
+
tallyVotesVk: tallyVk,
|
|
345
|
+
stateTreeDepth: Number(stateTreeDepth),
|
|
346
|
+
intStateTreeDepth: Number(intStateTreeDepth),
|
|
347
|
+
voteOptionTreeDepth: Number(voteOptionTreeDepth),
|
|
348
|
+
messageBatchSize: Number(messageBatchSize),
|
|
349
|
+
signer,
|
|
350
|
+
mode,
|
|
351
|
+
vkRegistryAddress: await vkRegistryContract.getAddress(),
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Deploy MACI contracts
|
|
356
|
+
*
|
|
357
|
+
* @param args - deploy maci arguments
|
|
358
|
+
* @param options - ws hooks
|
|
359
|
+
* @returns - deployed maci contract
|
|
360
|
+
* @returns the address of the deployed maci contract
|
|
361
|
+
*/
|
|
362
|
+
async deployMaci({ approval, sessionKeyAddress, chain, config }) {
|
|
363
|
+
const publicClient = getPublicClient(chain);
|
|
364
|
+
const bundlerClient = getBundlerClient(chain);
|
|
365
|
+
const kernelClient = await this.sessionKeysService.generateClientFromSessionKey(sessionKeyAddress, approval, chain);
|
|
366
|
+
let policyAddress = this.storage.getAddress(config.policy.type, chain);
|
|
367
|
+
const policyData = this.getPolicyData(config.policy.type, chain, config.policy.args);
|
|
368
|
+
// if the policy is not already deployed, we need to deploy it
|
|
369
|
+
if (!policyData.alreadyDeployed) {
|
|
370
|
+
policyAddress = await this.deployAndStore(config.policy.type, config.policy.args ? Object.values(config.policy.args) : [], policyData.abi, policyData.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
371
|
+
}
|
|
372
|
+
// deploy all maci contracts
|
|
373
|
+
// (we are not using Promise.all because the write tx nonce should be sequential)
|
|
374
|
+
// 1. verifier
|
|
375
|
+
await this.deployAndStore(EContracts.Verifier, [], VerifierFactory.abi, VerifierFactory.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
376
|
+
// 2. poseidon
|
|
377
|
+
let poseidonT3Address;
|
|
378
|
+
let poseidonT4Address;
|
|
379
|
+
let poseidonT5Address;
|
|
380
|
+
let poseidonT6Address;
|
|
381
|
+
if (config.Poseidon) {
|
|
382
|
+
// Some times the poseidon contracts are already deployed so we don't need to deploy them again
|
|
383
|
+
poseidonT3Address = config.Poseidon.poseidonT3;
|
|
384
|
+
poseidonT4Address = config.Poseidon.poseidonT4;
|
|
385
|
+
poseidonT5Address = config.Poseidon.poseidonT5;
|
|
386
|
+
poseidonT6Address = config.Poseidon.poseidonT6;
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
poseidonT3Address = await this.deployAndStore(EContracts.PoseidonT3, [], PoseidonT3Factory.abi, PoseidonT3Factory.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
390
|
+
poseidonT4Address = await this.deployAndStore(EContracts.PoseidonT4, [], PoseidonT4Factory.abi, PoseidonT4Factory.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
391
|
+
poseidonT5Address = await this.deployAndStore(EContracts.PoseidonT5, [], PoseidonT5Factory.abi, PoseidonT5Factory.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
392
|
+
poseidonT6Address = await this.deployAndStore(EContracts.PoseidonT6, [], PoseidonT6Factory.abi, PoseidonT6Factory.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
393
|
+
}
|
|
394
|
+
// 3. factories
|
|
395
|
+
const pollFactoryAddress = await this.deployAndStore(EContracts.PollFactory, [], PollFactoryFactory.abi, PollFactoryFactory.linkBytecode({
|
|
396
|
+
"contracts/crypto/PoseidonT3.sol:PoseidonT3": poseidonT3Address,
|
|
397
|
+
"contracts/crypto/PoseidonT4.sol:PoseidonT4": poseidonT4Address,
|
|
398
|
+
"contracts/crypto/PoseidonT5.sol:PoseidonT5": poseidonT5Address,
|
|
399
|
+
"contracts/crypto/PoseidonT6.sol:PoseidonT6": poseidonT6Address,
|
|
400
|
+
}), kernelClient, bundlerClient, publicClient, chain);
|
|
401
|
+
const tallyFactoryAddress = await this.deployAndStore(EContracts.TallyFactory, [], TallyFactoryFactory.abi, TallyFactoryFactory.linkBytecode({
|
|
402
|
+
"contracts/crypto/PoseidonT3.sol:PoseidonT3": poseidonT3Address,
|
|
403
|
+
"contracts/crypto/PoseidonT4.sol:PoseidonT4": poseidonT4Address,
|
|
404
|
+
"contracts/crypto/PoseidonT5.sol:PoseidonT5": poseidonT5Address,
|
|
405
|
+
"contracts/crypto/PoseidonT6.sol:PoseidonT6": poseidonT6Address,
|
|
406
|
+
}), kernelClient, bundlerClient, publicClient, chain);
|
|
407
|
+
const messageProcessorFactoryAddress = await this.deployAndStore(EContracts.MessageProcessorFactory, [], MessageProcessorFactoryFactory.abi, MessageProcessorFactoryFactory.linkBytecode({
|
|
408
|
+
"contracts/crypto/PoseidonT3.sol:PoseidonT3": poseidonT3Address,
|
|
409
|
+
"contracts/crypto/PoseidonT4.sol:PoseidonT4": poseidonT4Address,
|
|
410
|
+
"contracts/crypto/PoseidonT5.sol:PoseidonT5": poseidonT5Address,
|
|
411
|
+
"contracts/crypto/PoseidonT6.sol:PoseidonT6": poseidonT6Address,
|
|
412
|
+
}), kernelClient, bundlerClient, publicClient, chain);
|
|
413
|
+
// 4. VkRegistry
|
|
414
|
+
const vkRegistryAddress = await this.deployAndStore(EContracts.VkRegistry, [], VkRegistryFactory.abi, VkRegistryFactory.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
415
|
+
try {
|
|
416
|
+
const processMessagesZkeyPathQv = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME, true);
|
|
417
|
+
const tallyVotesZkeyPathQv = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_TALLY_ZKEY_NAME, true);
|
|
418
|
+
const processMessagesZkeyPathNonQv = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME, false);
|
|
419
|
+
const tallyVotesZkeyPathNonQv = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_TALLY_ZKEY_NAME, false);
|
|
420
|
+
const pollJoiningZkeyPath = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_POLL_JOINING_ZKEY_NAME, true);
|
|
421
|
+
const pollJoinedZkeyPath = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_POLL_JOINED_ZKEY_NAME, true);
|
|
422
|
+
const [qvProcessVk, qvTallyVk, nonQvProcessVk, nonQvTallyVk, pollJoiningVk, pollJoinedVk] = await Promise.all([
|
|
423
|
+
extractVk(processMessagesZkeyPathQv.zkey),
|
|
424
|
+
extractVk(tallyVotesZkeyPathQv.zkey),
|
|
425
|
+
extractVk(processMessagesZkeyPathNonQv.zkey),
|
|
426
|
+
extractVk(tallyVotesZkeyPathNonQv.zkey),
|
|
427
|
+
extractVk(pollJoiningZkeyPath.zkey),
|
|
428
|
+
extractVk(pollJoinedZkeyPath.zkey),
|
|
429
|
+
]).then((vks) => vks.map((vk) => vk && VerifyingKey.fromObj(vk).asContractParam()));
|
|
430
|
+
const processZkeys = [qvProcessVk, nonQvProcessVk].filter(Boolean);
|
|
431
|
+
const tallyZkeys = [qvTallyVk, nonQvTallyVk].filter(Boolean);
|
|
432
|
+
// check if the keys are already set
|
|
433
|
+
const [isProcessVkSet, isProcessNonQvVkSet, isTallyVkSet, isTallyNonQvVkSet] = await Promise.all([
|
|
434
|
+
publicClient.readContract({
|
|
435
|
+
address: vkRegistryAddress,
|
|
436
|
+
abi: VkRegistryFactory.abi,
|
|
437
|
+
functionName: "hasProcessVk",
|
|
438
|
+
args: [
|
|
439
|
+
config.VkRegistry.args.stateTreeDepth,
|
|
440
|
+
config.VkRegistry.args.voteOptionTreeDepth,
|
|
441
|
+
config.VkRegistry.args.messageBatchSize,
|
|
442
|
+
EMode.QV,
|
|
443
|
+
],
|
|
444
|
+
}),
|
|
445
|
+
publicClient.readContract({
|
|
446
|
+
address: vkRegistryAddress,
|
|
447
|
+
abi: VkRegistryFactory.abi,
|
|
448
|
+
functionName: "hasProcessVk",
|
|
449
|
+
args: [
|
|
450
|
+
config.VkRegistry.args.stateTreeDepth,
|
|
451
|
+
config.VkRegistry.args.voteOptionTreeDepth,
|
|
452
|
+
config.VkRegistry.args.messageBatchSize,
|
|
453
|
+
EMode.NON_QV,
|
|
454
|
+
],
|
|
455
|
+
}),
|
|
456
|
+
publicClient.readContract({
|
|
457
|
+
address: vkRegistryAddress,
|
|
458
|
+
abi: VkRegistryFactory.abi,
|
|
459
|
+
functionName: "hasTallyVk",
|
|
460
|
+
args: [
|
|
461
|
+
config.VkRegistry.args.stateTreeDepth,
|
|
462
|
+
config.VkRegistry.args.intStateTreeDepth,
|
|
463
|
+
config.VkRegistry.args.voteOptionTreeDepth,
|
|
464
|
+
EMode.QV,
|
|
465
|
+
],
|
|
466
|
+
}),
|
|
467
|
+
publicClient.readContract({
|
|
468
|
+
address: vkRegistryAddress,
|
|
469
|
+
abi: VkRegistryFactory.abi,
|
|
470
|
+
functionName: "hasTallyVk",
|
|
471
|
+
args: [
|
|
472
|
+
config.VkRegistry.args.stateTreeDepth,
|
|
473
|
+
config.VkRegistry.args.intStateTreeDepth,
|
|
474
|
+
config.VkRegistry.args.voteOptionTreeDepth,
|
|
475
|
+
EMode.NON_QV,
|
|
476
|
+
],
|
|
477
|
+
}),
|
|
478
|
+
]);
|
|
479
|
+
if (isProcessVkSet && isProcessNonQvVkSet && isTallyVkSet && isTallyNonQvVkSet) {
|
|
480
|
+
this.logger.debug("Verifying keys are already set on the vk registry");
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
await this.estimateGasAndSend(vkRegistryAddress, 0n, VkRegistryFactory.abi, "setVerifyingKeysBatch", [
|
|
484
|
+
config.VkRegistry.args.stateTreeDepth,
|
|
485
|
+
config.VkRegistry.args.intStateTreeDepth,
|
|
486
|
+
config.VkRegistry.args.voteOptionTreeDepth,
|
|
487
|
+
config.VkRegistry.args.messageBatchSize,
|
|
488
|
+
[EMode.QV, EMode.NON_QV],
|
|
489
|
+
pollJoiningVk,
|
|
490
|
+
pollJoinedVk,
|
|
491
|
+
processZkeys,
|
|
492
|
+
tallyZkeys,
|
|
493
|
+
], ErrorCodes.FAILED_TO_SET_VERIFYING_KEYS_ON_VK_REGISTRY.toString(), kernelClient, bundlerClient);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
this.logger.error("Failed to set verifying keys on vk registry: ", error);
|
|
498
|
+
throw error;
|
|
499
|
+
}
|
|
500
|
+
// 5. maci (here we don't check whether one is already deployed, we just deploy it)
|
|
501
|
+
const emptyBallotRoots = genEmptyBallotRoots(config.MACI.stateTreeDepth);
|
|
502
|
+
const maciAddress = await this.deployAndStore(EContracts.MACI, [
|
|
503
|
+
pollFactoryAddress,
|
|
504
|
+
messageProcessorFactoryAddress,
|
|
505
|
+
tallyFactoryAddress,
|
|
506
|
+
policyAddress,
|
|
507
|
+
config.MACI.stateTreeDepth,
|
|
508
|
+
emptyBallotRoots,
|
|
509
|
+
], MACIFactory.abi, MACIFactory.linkBytecode({
|
|
510
|
+
"contracts/crypto/PoseidonT3.sol:PoseidonT3": "0x07490eba00dc4ACA6721D052Fa4C5002Aa077233",
|
|
511
|
+
"contracts/crypto/PoseidonT4.sol:PoseidonT4": "0xbb0e724CE02e5E7eDd31e632dc6e59F229a1126d",
|
|
512
|
+
"contracts/crypto/PoseidonT5.sol:PoseidonT5": "0xE0398F7DFAC494c530F6404AfEaC8669ABeD2679",
|
|
513
|
+
"contracts/crypto/PoseidonT6.sol:PoseidonT6": "0xfD77833F10a29c76A6a0ede235Eb651D744d0E2F",
|
|
514
|
+
}), kernelClient, bundlerClient, publicClient, chain);
|
|
515
|
+
// set the gate on the policy
|
|
516
|
+
await this.estimateGasAndSend(policyAddress, 0n, policyData.abi, "setTarget", [maciAddress], ErrorCodes.FAILED_TO_SET_MACI_INSTANCE_ON_POLICY.toString(), kernelClient, bundlerClient);
|
|
517
|
+
return { address: maciAddress };
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Deploy a poll
|
|
521
|
+
*
|
|
522
|
+
* @param args - deploy poll dto
|
|
523
|
+
* @returns poll id
|
|
524
|
+
*/
|
|
525
|
+
async deployPoll({ approval, sessionKeyAddress, chain, config }) {
|
|
526
|
+
const publicClient = getPublicClient(chain);
|
|
527
|
+
const bundlerClient = getBundlerClient(chain);
|
|
528
|
+
const kernelClient = await this.sessionKeysService.generateClientFromSessionKey(sessionKeyAddress, approval, chain);
|
|
529
|
+
const signer = await this.sessionKeysService.getKernelClientSigner(kernelClient);
|
|
530
|
+
// check if there is a maci contract deployed on this chain
|
|
531
|
+
const maciAddress = this.storage.getAddress(EContracts.MACI, chain);
|
|
532
|
+
if (!maciAddress) {
|
|
533
|
+
throw new Error(ErrorCodes.MACI_NOT_DEPLOYED.toString());
|
|
534
|
+
}
|
|
535
|
+
// check if there is a verifier deployed on this chain
|
|
536
|
+
const verifierAddress = this.storage.getAddress(EContracts.Verifier, chain);
|
|
537
|
+
if (!verifierAddress) {
|
|
538
|
+
throw new Error(ErrorCodes.VERIFIER_NOT_DEPLOYED.toString());
|
|
539
|
+
}
|
|
540
|
+
// check if there is a vk registry deployed on this chain
|
|
541
|
+
const vkRegistryAddress = this.storage.getAddress(EContracts.VkRegistry, chain);
|
|
542
|
+
if (!vkRegistryAddress) {
|
|
543
|
+
throw new Error(ErrorCodes.VK_REGISTRY_NOT_DEPLOYED.toString());
|
|
544
|
+
}
|
|
545
|
+
// check if policy address was given
|
|
546
|
+
let policyAddress = config.policy.address;
|
|
547
|
+
if (!policyAddress) {
|
|
548
|
+
const policyData = this.getPolicyData(config.policy.type, chain, config.policy.args);
|
|
549
|
+
policyAddress = policyData.address;
|
|
550
|
+
// if the policy is not already deployed, we need to deploy it
|
|
551
|
+
if (!policyData.alreadyDeployed) {
|
|
552
|
+
policyAddress = await this.deployAndStore(config.policy.type, config.policy.args ? Object.values(config.policy.args) : [], policyData.abi, policyData.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
// check if initial voice credit proxy address was given
|
|
556
|
+
let initialVoiceCreditProxyAddress = config.initialVoiceCreditsProxy.address;
|
|
557
|
+
if (!initialVoiceCreditProxyAddress) {
|
|
558
|
+
const voiceCreditProxyData = this.getVoiceCreditProxyData(config.initialVoiceCreditsProxy.type, chain, config.initialVoiceCreditsProxy.args);
|
|
559
|
+
initialVoiceCreditProxyAddress = voiceCreditProxyData.address;
|
|
560
|
+
// if the voice credit proxy is not already deployed, we need to deploy it
|
|
561
|
+
if (!voiceCreditProxyData.alreadyDeployed) {
|
|
562
|
+
initialVoiceCreditProxyAddress = await this.deployAndStore(config.initialVoiceCreditsProxy.type, Object.values(config.initialVoiceCreditsProxy.args), voiceCreditProxyData.abi, voiceCreditProxyData.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
const mode = config.useQuadraticVoting ? EMode.QV : EMode.NON_QV;
|
|
566
|
+
const deployPollArgs = {
|
|
567
|
+
maciAddress,
|
|
568
|
+
pollStartTimestamp: config.startDate,
|
|
569
|
+
pollEndTimestamp: config.endDate,
|
|
570
|
+
intStateTreeDepth: config.intStateTreeDepth,
|
|
571
|
+
voteOptionTreeDepth: config.voteOptionTreeDepth,
|
|
572
|
+
messageBatchSize: config.messageBatchSize,
|
|
573
|
+
coordinatorPubKey: PubKey.deserialize(config.coordinatorPubkey),
|
|
574
|
+
verifierContractAddress: verifierAddress,
|
|
575
|
+
vkRegistryContractAddress: vkRegistryAddress,
|
|
576
|
+
mode,
|
|
577
|
+
policyContractAddress: policyAddress,
|
|
578
|
+
initialVoiceCreditProxyContractAddress: initialVoiceCreditProxyAddress,
|
|
579
|
+
relayers: config.relayers ? config.relayers.map((address) => address) : [],
|
|
580
|
+
voteOptions: Number(config.voteOptions),
|
|
581
|
+
initialVoiceCredits: Number(config.initialVoiceCreditsProxy.args.amount),
|
|
582
|
+
signer,
|
|
583
|
+
};
|
|
584
|
+
const { pollContractAddress, messageProcessorContractAddress, tallyContractAddress, pollId } = await deployPoll(deployPollArgs);
|
|
585
|
+
const poll = PollFactory.connect(pollContractAddress, signer);
|
|
586
|
+
// read the emptyBallotRoot and extContracts
|
|
587
|
+
const emptyBallotRoot = await poll.emptyBallotRoot();
|
|
588
|
+
const extContracts = await poll.extContracts();
|
|
589
|
+
// store to storage
|
|
590
|
+
await Promise.all([
|
|
591
|
+
this.storage.register({
|
|
592
|
+
id: EContracts.Poll,
|
|
593
|
+
key: `poll-${pollId}`,
|
|
594
|
+
contract: poll,
|
|
595
|
+
args: [
|
|
596
|
+
{
|
|
597
|
+
...deployPollArgs,
|
|
598
|
+
extContracts,
|
|
599
|
+
emptyBallotRoot: emptyBallotRoot.toString(),
|
|
600
|
+
},
|
|
601
|
+
],
|
|
602
|
+
network: chain,
|
|
603
|
+
}),
|
|
604
|
+
this.storage.register({
|
|
605
|
+
id: EContracts.MessageProcessor,
|
|
606
|
+
key: `poll-${pollId}`,
|
|
607
|
+
contract: new BaseContract(messageProcessorContractAddress, MessageProcessorFactory.abi),
|
|
608
|
+
args: [verifierAddress, vkRegistryAddress, pollContractAddress, mode],
|
|
609
|
+
network: chain,
|
|
610
|
+
}),
|
|
611
|
+
this.storage.register({
|
|
612
|
+
id: EContracts.Tally,
|
|
613
|
+
key: `poll-${pollId}`,
|
|
614
|
+
contract: new BaseContract(tallyContractAddress, TallyFactory.abi),
|
|
615
|
+
args: [verifierAddress, vkRegistryAddress, pollContractAddress, messageProcessorContractAddress, mode],
|
|
616
|
+
network: chain,
|
|
617
|
+
}),
|
|
618
|
+
]);
|
|
619
|
+
return { pollId: pollId.toString() };
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
DeployerService = DeployerService_1 = __decorate([
|
|
623
|
+
Injectable(),
|
|
624
|
+
__metadata("design:paramtypes", [SessionKeysService,
|
|
625
|
+
FileService])
|
|
626
|
+
], DeployerService);
|
|
627
|
+
export { DeployerService };
|
|
628
|
+
//# sourceMappingURL=deployer.service.js.map
|